Merge "Fix AttributeError in exception handler" into stable/victoria

This commit is contained in:
Zuul 2022-04-27 16:47:13 +00:00 committed by Gerrit Code Review
commit 1f5329474a
2 changed files with 13 additions and 2 deletions

View File

@ -156,6 +156,5 @@ class HAProxyQuery(object):
except Exception as e:
# Catch any exception - may be socket issue, or write permission
# issue as well.
LOG.warning("Unable to save state: %(err)s %(output)s",
{'err': e, 'output': e.output})
LOG.warning("Unable to save state: %r", e)
return False

View File

@ -159,3 +159,15 @@ class QueryTestCase(base.TestCase):
self.q.save_state(filename)
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)