Merge lp:~twom/conn-check/port-not-none into lp:conn-check

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: 142
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~twom/conn-check/port-not-none
Merge into: lp:conn-check
Diff against target: 70 lines (+32/-6)
2 files modified
conn_check/main.py (+22/-6)
tests.py (+10/-0)
To merge this branch: bzr merge lp:~twom/conn-check/port-not-none
Reviewer Review Type Date Requested Status
Simon Davy (community) Approve
Review via email: mp+347365@code.launchpad.net

Commit message

Handle missing port in checks, suppress traceback of config errors

To post a comment you must log in.
lp:~twom/conn-check/port-not-none updated
139. By Tom Wardill

Test the port that we're using

140. By Tom Wardill

Merge master

141. By Tom Wardill

add default postgres port

142. By Tom Wardill

Can't use a default there, it's not postgres specific

Revision history for this message
Simon Davy (bloodearnest) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'conn_check/main.py'
--- conn_check/main.py 2018-01-29 14:08:16 +0000
+++ conn_check/main.py 2018-06-04 16:14:17 +0000
@@ -1,3 +1,4 @@
1
1from __future__ import print_function2from __future__ import print_function
2from __future__ import unicode_literals3from __future__ import unicode_literals
3from future import standard_library4from future import standard_library
@@ -73,7 +74,15 @@
73 check_description))74 check_description))
7475
75 if 'port' in check_description:76 if 'port' in check_description:
76 check_description['port'] = int(check_description['port'])77 port = check_description.get('port')
78 try:
79 check_description['port'] = int(port)
80 except TypeError:
81 # swap the TypeError for the more generic AssertionError
82 # that we are using for configuration faults
83 # and is caught further up
84 raise AssertionError('Port is invalid for check: {}'.format(
85 check_description))
7786
78 res = check['fn'](**check_description)87 res = check['fn'](**check_description)
79 return res88 return res
@@ -347,11 +356,18 @@
347 def run(self):356 def run(self):
348 """Run/validate/dry-run the given command with options."""357 """Run/validate/dry-run the given command with options."""
349358
350 checks = build_checks(self.descriptions,359 try:
351 self.options.connect_timeout,360 checks = build_checks(self.descriptions,
352 self.options.include_tags,361 self.options.connect_timeout,
353 self.options.exclude_tags,362 self.options.include_tags,
354 self.options.dry_run)363 self.options.exclude_tags,
364 self.options.dry_run)
365 except AssertionError as e:
366 # Configuration fault, suppress traceback
367 # but display message
368 self.output.write(str(e))
369 self.output.flush()
370 return 4
355371
356 if not self.options.validate:372 if not self.options.validate:
357 if not self.options.dry_run:373 if not self.options.dry_run:
358374
=== modified file 'tests.py'
--- tests.py 2018-01-25 20:58:24 +0000
+++ tests.py 2018-06-04 16:14:17 +0000
@@ -300,6 +300,16 @@
300 str(e),300 str(e),
301 "host missing from check: {}".format(description))301 "host missing from check: {}".format(description))
302302
303 def test_check_from_description_port_not_set(self):
304 description = {'type': 'tcp', 'host': 'localhost', 'port': None}
305 e = self.assertRaises(AssertionError,
306 check_from_description,
307 description)
308 self.assertEqual(
309 str(e),
310 "Port is invalid for check: {}".format(description)
311 )
312
303 def test_check_from_description_makes_check(self):313 def test_check_from_description_makes_check(self):
304 description = {'type': 'tcp', 'host': 'localhost', 'port': '8080'}314 description = {'type': 'tcp', 'host': 'localhost', 'port': '8080'}
305 result = check_from_description(description)315 result = check_from_description(description)

Subscribers

People subscribed via source and target branches