Merge "Delete the failure host from reserved_host"

This commit is contained in:
Jenkins 2017-04-03 16:59:16 +00:00 committed by Gerrit Code Review
commit 805da5ad50
2 changed files with 68 additions and 7 deletions

View File

@ -142,6 +142,11 @@ class MasakariManager(manager.Manager):
update_data = {
'on_maintenance': True,
}
# Set reserved flag to False if this host is reserved
if host_obj.reserved:
update_data['reserved'] = False
host_obj.update(update_data)
host_obj.save()

View File

@ -216,13 +216,14 @@ class EngineManagerUnitTestCase(test.NoDBTestCase):
@mock.patch.object(host_obj.Host, "get_by_uuid")
@mock.patch.object(host_obj.Host, "save")
@mock.patch.object(host_obj.Host, "update")
@mock.patch.object(host_obj.HostList, "get_all")
@mock.patch("masakari.engine.drivers.taskflow."
"TaskFlowDriver.execute_host_failure")
@mock.patch.object(notification_obj.Notification, "save")
def test_process_notification_type_compute_host_event_stopped(
self, mock_notification_save, mock_host_failure, mock_get_all,
mock_host_save, mock_host_obj):
mock_host_update, mock_host_save, mock_host_obj):
notification = self._get_compute_host_type_notification()
mock_host_failure.side_effect = self._fake_notification_workflow()
fake_host = fakes.create_fake_host()
@ -231,6 +232,11 @@ class EngineManagerUnitTestCase(test.NoDBTestCase):
mock_host_obj.return_value = fake_host
self.engine.process_notification(self.context,
notification=notification)
update_data_by_host_failure = {
'on_maintenance': True,
}
mock_host_update.assert_called_once_with(update_data_by_host_failure)
self.assertEqual("finished", notification.status)
mock_host_failure.assert_called_once_with(
self.context,
@ -239,11 +245,12 @@ class EngineManagerUnitTestCase(test.NoDBTestCase):
@mock.patch.object(host_obj.Host, "get_by_uuid")
@mock.patch.object(host_obj.Host, "save")
@mock.patch.object(host_obj.Host, "update")
@mock.patch.object(host_obj.HostList, "get_all")
@mock.patch.object(notification_obj.Notification, "save")
def test_process_notification_host_failure_without_reserved_hosts(
self, mock_notification_save, mock_get_all,
mock_host_save, mock_host_obj):
mock_host_update, mock_host_save, mock_host_obj):
reserved_host_list = []
mock_get_all.return_value = reserved_host_list
@ -257,23 +264,27 @@ class EngineManagerUnitTestCase(test.NoDBTestCase):
self.engine.process_notification(self.context,
notification=notification)
update_data_by_host_failure = {
'on_maintenance': True,
}
mock_host_update.assert_called_once_with(update_data_by_host_failure)
self.assertEqual("error", notification.status)
@mock.patch.object(host_obj.Host, "get_by_uuid")
@mock.patch.object(host_obj.Host, "save")
@mock.patch.object(host_obj.Host, "update")
@mock.patch.object(host_obj.HostList, "get_all")
@mock.patch("masakari.engine.drivers.taskflow."
"TaskFlowDriver.execute_host_failure")
@mock.patch.object(notification_obj.Notification, "save")
def test_process_notification_host_failure_with_reserved_hosts(
self, mock_notification_save, mock_host_failure, mock_get_all,
mock_host_save, mock_host_obj):
reserved_host_list = [fakes.create_fake_host(reserved=True)]
mock_get_all.return_value = reserved_host_list
mock_host_update, mock_host_save, mock_host_obj):
fake_host = fakes.create_fake_host()
fake_host.failover_segment = fakes.create_fake_failover_segment(
recovery_method='reserved_host')
reserved_host_list = [fake_host]
mock_get_all.return_value = reserved_host_list
mock_host_obj.return_value = fake_host
notification = self._get_compute_host_type_notification()
@ -282,6 +293,10 @@ class EngineManagerUnitTestCase(test.NoDBTestCase):
self.engine.process_notification(self.context,
notification=notification)
update_data_by_host_failure = {
'on_maintenance': True,
}
mock_host_update.assert_called_once_with(update_data_by_host_failure)
self.assertEqual("finished", notification.status)
mock_host_failure.assert_called_once_with(
self.context,
@ -291,13 +306,49 @@ class EngineManagerUnitTestCase(test.NoDBTestCase):
@mock.patch.object(host_obj.Host, "get_by_uuid")
@mock.patch.object(host_obj.Host, "save")
@mock.patch.object(host_obj.Host, "update")
@mock.patch.object(host_obj.HostList, "get_all")
@mock.patch("masakari.engine.drivers.taskflow."
"TaskFlowDriver.execute_host_failure")
@mock.patch.object(notification_obj.Notification, "save")
def test_process_notification_reserved_host_failure(
self, mock_notification_save, mock_host_failure, mock_get_all,
mock_host_update, mock_host_save, mock_host_obj):
fake_host = fakes.create_fake_host(reserved=True)
fake_host.failover_segment = fakes.create_fake_failover_segment(
recovery_method='reserved_host')
reserved_host_list = [fake_host]
mock_get_all.return_value = reserved_host_list
mock_host_obj.return_value = fake_host
notification = self._get_compute_host_type_notification()
mock_host_failure.side_effect = self._fake_notification_workflow()
self.engine.process_notification(self.context,
notification=notification)
update_data_by_host_failure = {
'on_maintenance': True,
'reserved': False,
}
mock_host_update.assert_called_once_with(update_data_by_host_failure)
self.assertEqual("finished", notification.status)
mock_host_failure.assert_called_once_with(
self.context,
fake_host.name, fake_host.failover_segment.recovery_method,
notification.notification_uuid,
reserved_host_list=reserved_host_list)
@mock.patch.object(host_obj.Host, "get_by_uuid")
@mock.patch.object(host_obj.Host, "save")
@mock.patch.object(host_obj.Host, "update")
@mock.patch.object(host_obj.HostList, "get_all")
@mock.patch("masakari.engine.drivers.taskflow."
"TaskFlowDriver.execute_host_failure")
@mock.patch.object(notification_obj.Notification, "save")
def test_process_notification_type_compute_host_recovery_exception(
self, mock_notification_save, mock_host_failure, mock_get_all,
mock_host_save, mock_host_obj):
mock_host_update, mock_host_save, mock_host_obj):
notification = self._get_compute_host_type_notification()
fake_host = fakes.create_fake_host()
mock_get_all.return_value = None
@ -307,6 +358,11 @@ class EngineManagerUnitTestCase(test.NoDBTestCase):
exc=exception.HostRecoveryFailureException)
self.engine.process_notification(self.context,
notification=notification)
update_data_by_host_failure = {
'on_maintenance': True,
}
mock_host_update.assert_called_once_with(update_data_by_host_failure)
self.assertEqual("error", notification.status)
@mock.patch.object(notification_obj.Notification, "save")