Fix AttributeError in exception handler
The exception handler of save_state() caused an AttributeError because it tried to get the output attribute of the Exception, which does not exist in general. Added a test to cover this scenario. Change-Id: I36acdee1f8782b17c234f6b250facc5c8d0aaf87
This commit is contained in:
@@ -165,6 +165,5 @@ class HAProxyQuery(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Catch any exception - may be socket issue, or write permission
|
# Catch any exception - may be socket issue, or write permission
|
||||||
# issue as well.
|
# issue as well.
|
||||||
LOG.warning("Unable to save state: %(err)s %(output)s",
|
LOG.warning("Unable to save state: %r", e)
|
||||||
{'err': e, 'output': e.output})
|
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -159,3 +159,15 @@ class QueryTestCase(base.TestCase):
|
|||||||
self.q.save_state(filename)
|
self.q.save_state(filename)
|
||||||
|
|
||||||
mock_fh.write.assert_called_once_with('DATA')
|
mock_fh.write.assert_called_once_with('DATA')
|
||||||
|
|
||||||
|
def test_save_state_error(self):
|
||||||
|
"""save_state() should swallow exceptions"""
|
||||||
|
filename = 'state_file'
|
||||||
|
|
||||||
|
query_mock = mock.Mock(side_effect=OSError())
|
||||||
|
self.q._query = query_mock
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.q.save_state(filename)
|
||||||
|
except Exception as ex:
|
||||||
|
self.fail("save_state() raised %r unexpectedly!" % ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user