diff --git a/octavia/controller/worker/task_utils.py b/octavia/controller/worker/task_utils.py index ca66818008..affaf0b9c4 100644 --- a/octavia/controller/worker/task_utils.py +++ b/octavia/controller/worker/task_utils.py @@ -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. diff --git a/octavia/controller/worker/tasks/lifecycle_tasks.py b/octavia/controller/worker/tasks/lifecycle_tasks.py index a784ca827e..c8cdaa2061 100644 --- a/octavia/controller/worker/tasks/lifecycle_tasks.py +++ b/octavia/controller/worker/tasks/lifecycle_tasks.py @@ -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): diff --git a/octavia/tests/unit/controller/worker/tasks/test_lifecycle_tasks.py b/octavia/tests/unit/controller/worker/tasks/test_lifecycle_tasks.py index d57a29d303..3ced60dcd3 100644 --- a/octavia/tests/unit/controller/worker/tasks/test_lifecycle_tasks.py +++ b/octavia/tests/unit/controller/worker/tasks/test_lifecycle_tasks.py @@ -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')