Skip to content

Commit

Permalink
Make missing SSL key/cert files non-fatal, set test to UNKNOWN instead
Browse files Browse the repository at this point in the history
  • Loading branch information
marineam committed Dec 12, 2011
1 parent aef72cc commit d3ef95f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
18 changes: 12 additions & 6 deletions python/nagcat/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def __init__(self, nagcat, conf):
# extra pieces of metadata such as Request ID/URL.
self.saved = {}

# Semi-fatal init errors, forces query to UNKNOWN
self.init_errors = []

# All queries should handle timeouts
try:
interval = util.Interval(
Expand All @@ -102,7 +105,11 @@ def __init__(self, nagcat, conf):

def _start_self(self):
self.saved.clear()
return super(Query, self)._start_self()
if self.init_errors:
msg = '\n'.join(self.init_errors)
return defer.fail(errors.Failure(errors.TestUnknown(msg)))
else:
return super(Query, self)._start_self()

@errors.callback
def _failure_tcp(self, result):
Expand Down Expand Up @@ -171,10 +178,8 @@ def __init__(self, nagcat, conf):
self.conf['ssl_%s_type'%opt] = key_type

def maybe_read(key, private=False):
# Only support PEM for now
filetype = crypto.FILETYPE_PEM
path = self.conf[key]
filetype = self.conf[key+'_type']
path = self.conf[key]
if not path:
return None

Expand All @@ -187,8 +192,9 @@ def maybe_read(key, private=False):
finally:
fd.close()
except IOError, ex:
raise errors.InitError("Failed to read %s file %s: %s" %
(path, key, ex.strerror))
self.init_errors.append("Failed to read %s file %s: %s" %
(key, path, ex.strerror))
return None

log.trace("Loaded %s:\n%s", key, data)

Expand Down
17 changes: 17 additions & 0 deletions python/nagcat/unittests/queries/test_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,20 @@ def testVerifyServerGood(self):

def tearDown(self):
return self.server.loseConnection()

class MissingSSLTestCase(QueryTestCase):

def testMissingFiles(self):
config = {'type': "ssl",
'host': "localhost",
'port': 9,
'ssl_cacert': "xyzfnothere"}

def check(result):
self.assertIsInstance(result, errors.Failure)
self.assertIsInstance(result.value, errors.TestUnknown)
self.assertIn("xyzfnothere", str(result.value))

d = self.startQuery(config)
d.addBoth(check)
return d

0 comments on commit d3ef95f

Please sign in to comment.