only rollback DB when we have a connection to the DB
Story: 2006062 Task: 34775 Change-Id: I728a9aa82986edef8128907a48c9df87d119fa8f
This commit is contained in:
parent
520f1d0c7d
commit
feaa1ce021
@ -85,6 +85,7 @@ class HealthManager(object):
|
||||
futs = []
|
||||
while not self.dead.is_set():
|
||||
amp_health = None
|
||||
lock_session = None
|
||||
try:
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
amp = None
|
||||
@ -123,7 +124,8 @@ class HealthManager(object):
|
||||
time.sleep(CONF.health_manager.heartbeat_timeout)
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
lock_session.rollback()
|
||||
if lock_session:
|
||||
lock_session.rollback()
|
||||
|
||||
if amp_health is None:
|
||||
break
|
||||
|
@ -117,3 +117,21 @@ class TestHealthManager(base.TestCase):
|
||||
|
||||
session_mock.assert_called_once_with(autocommit=False)
|
||||
self.assertFalse(failover_mock.called)
|
||||
|
||||
@mock.patch('octavia.controller.worker.v1.controller_worker.'
|
||||
'ControllerWorker.failover_amphora')
|
||||
@mock.patch('octavia.db.repositories.AmphoraHealthRepository.'
|
||||
'get_stale_amphora', return_value=None)
|
||||
@mock.patch('octavia.db.api.get_session')
|
||||
def test_health_check_db_error(self, session_mock, get_stale_amp_mock,
|
||||
failover_mock):
|
||||
get_stale_amp_mock.return_value = None
|
||||
|
||||
mock_session = mock.MagicMock()
|
||||
session_mock.return_value = mock_session
|
||||
session_mock.side_effect = TestException('DB Error')
|
||||
exit_event = threading.Event()
|
||||
hm = healthmanager.HealthManager(exit_event)
|
||||
|
||||
self.assertRaises(TestException, hm.health_check)
|
||||
self.assertEqual(0, mock_session.rollback.call_count)
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixed an issue with the health manager reporting an UnboundLocalError if
|
||||
it gets an exception attempting to get a database connection.
|
Loading…
Reference in New Issue
Block a user