Merge "Correctly unlock amphora health on failover revert"

This commit is contained in:
Jenkins 2017-10-07 04:05:25 +00:00 committed by Gerrit Code Review
commit 6a54f6ac37
3 changed files with 28 additions and 2 deletions

View File

@ -38,6 +38,23 @@ class TaskUtils(object):
self.l7rule_repo = repo.L7RuleRepository()
super(TaskUtils, self).__init__(**kwargs)
def unmark_amphora_health_busy(self, amphora_id):
"""Unmark the amphora_health record busy for an amphora.
NOTE: This should only be called from revert methods.
:param amphora_id: The amphora id to unmark busy
"""
LOG.debug('Unmarking health monitoring busy on amphora: %s',
amphora_id)
try:
self.amp_health_repo.update(db_apis.get_session(),
amphora_id=amphora_id,
busy=False)
except Exception as e:
LOG.debug('Failed to update amphora health record %(amp)s '
'due to: %(except)s', {'amp': amphora_id, 'except': e})
def mark_amphora_status_error(self, amphora_id):
"""Sets an amphora status to ERROR.

View File

@ -33,6 +33,7 @@ class AmphoraIDToErrorOnRevertTask(BaseLifecycleTask):
def revert(self, amphora_id, *args, **kwargs):
self.task_utils.mark_amphora_status_error(amphora_id)
self.task_utils.unmark_amphora_health_busy(amphora_id)
class AmphoraToErrorOnRevertTask(AmphoraIDToErrorOnRevertTask):

View File

@ -52,9 +52,12 @@ class TestLifecycleTasks(base.TestCase):
super(TestLifecycleTasks, self).setUp()
@mock.patch('octavia.controller.worker.task_utils.TaskUtils.'
'unmark_amphora_health_busy')
@mock.patch('octavia.controller.worker.task_utils.TaskUtils.'
'mark_amphora_status_error')
def test_AmphoraIDToErrorOnRevertTask(self, mock_amp_status_error):
def test_AmphoraIDToErrorOnRevertTask(self, mock_amp_status_error,
mock_amp_health_busy):
amp_id_to_error_on_revert = (lifecycle_tasks.
AmphoraIDToErrorOnRevertTask())
@ -68,10 +71,14 @@ class TestLifecycleTasks(base.TestCase):
amp_id_to_error_on_revert.revert(self.AMPHORA_ID)
mock_amp_status_error.assert_called_once_with(self.AMPHORA_ID)
mock_amp_health_busy.assert_called_once_with(self.AMPHORA_ID)
@mock.patch('octavia.controller.worker.task_utils.TaskUtils.'
'unmark_amphora_health_busy')
@mock.patch('octavia.controller.worker.task_utils.TaskUtils.'
'mark_amphora_status_error')
def test_AmphoraToErrorOnRevertTask(self, mock_amp_status_error):
def test_AmphoraToErrorOnRevertTask(self, mock_amp_status_error,
mock_amp_health_busy):
amp_to_error_on_revert = lifecycle_tasks.AmphoraToErrorOnRevertTask()
@ -84,6 +91,7 @@ class TestLifecycleTasks(base.TestCase):
amp_to_error_on_revert.revert(self.AMPHORA)
mock_amp_status_error.assert_called_once_with(self.AMPHORA_ID)
mock_amp_health_busy.assert_called_once_with(self.AMPHORA_ID)
@mock.patch('octavia.controller.worker.task_utils.TaskUtils.'
'mark_health_mon_prov_status_error')