Transform instance-evacuate notification

Co-Authored-By: Takashi Natsume <natsume.takashi@lab.ntt.co.jp>
Co-Authored-By: Gábor Antal <antal@inf.u-szeged.hu>
Change-Id: Ie1914b1f5f71c23dd441dafaea9e4261541d338d
Implements: bp versioned-notification-transformation-queens
This commit is contained in:
Alex Szarka 2017-07-10 15:40:47 +02:00 committed by Takashi NATSUME
parent a40c00957e
commit 575fd9bbd2
6 changed files with 55 additions and 3 deletions

View File

@ -0,0 +1,14 @@
{
"event_type": "instance.evacuate",
"payload": {
"$ref": "common_payloads/InstanceActionPayload.json#",
"nova_object.data": {
"host": "host2",
"node": "host2",
"power_state": "pending",
"task_state": "rebuilding"
}
},
"priority": "INFO",
"publisher_id": "nova-api:host2"
}

View File

@ -4194,6 +4194,10 @@ class API(base.Base):
compute_utils.notify_about_instance_usage(
self.notifier, context, instance, "evacuate")
compute_utils.notify_about_instance_action(
context, instance, CONF.host,
action=fields_obj.NotificationAction.EVACUATE,
source=fields_obj.NotificationSource.API)
try:
request_spec = objects.RequestSpec.get_by_instance_uuid(

View File

@ -435,7 +435,7 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase):
@base.notification_sample('instance-resume-end.json')
@base.notification_sample('instance-restore-start.json')
@base.notification_sample('instance-restore-end.json')
# @base.notification_sample('instance-evacuate.json')
@base.notification_sample('instance-evacuate.json')
@base.notification_sample('instance-resize_finish-start.json')
@base.notification_sample('instance-resize_finish-end.json')
@base.notification_sample('instance-live_migration_pre-start.json')

View File

@ -42,7 +42,7 @@ class TestInstanceNotificationSampleWithMultipleCompute(
self.useFixture(self.cinder)
self.useFixture(fixtures.AllServicesCurrent())
def test_live_migration_actions(self):
def test_multiple_compute_actions(self):
server = self._boot_a_server(
extra_params={'networks': [{'port': self.neutron.port_1['id']}]})
self._wait_for_notification('instance.create.end')
@ -56,6 +56,7 @@ class TestInstanceNotificationSampleWithMultipleCompute(
self._test_live_migration_rollback,
self._test_live_migration_abort,
self._test_live_migration_pre,
self._test_evacuate_server
]
for action in actions:
@ -184,6 +185,34 @@ class TestInstanceNotificationSampleWithMultipleCompute(
'uuid': server['id']},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[5])
def _test_evacuate_server(self, server):
services = self.admin_api.get_services(host='host2',
binary='nova-compute')
service_id = services[0]['id']
self.admin_api.put_service(service_id, {'forced_down': True})
evacuate = {
'evacuate': {
'host': 'compute',
'force': True
}
}
self.admin_api.post_server_action(server['id'], evacuate)
self._wait_for_state_change(self.api, server,
expected_status='REBUILD')
self._wait_for_state_change(self.api, server,
expected_status='ACTIVE')
notifications = self._get_notifications('instance.evacuate')
self.assertEqual(1, len(notifications))
self._verify_notification(
'instance-evacuate',
replacements={
'reservation_id': server['reservation_id'],
'uuid': server['id']},
actual=notifications[0])
self.admin_api.put_service(service_id, {'forced_down': False})
class TestInstanceNotificationSampleWithMultipleComputeOldAttachFlow(
TestInstanceNotificationSampleWithMultipleCompute):

View File

@ -11078,7 +11078,8 @@ class ComputeAPITestCase(BaseTestCase):
host_name='fake_dest_host',
force=False)
def _test_evacuate(self, force=None):
@mock.patch('nova.compute.utils.notify_about_instance_action')
def _test_evacuate(self, mock_notify, force=None):
instance = self._create_fake_instance_obj(services=True)
self.assertIsNone(instance.task_state)
@ -11146,6 +11147,9 @@ class ComputeAPITestCase(BaseTestCase):
self.assertEqual('accepted', migs[0].status)
self.assertEqual('compute.instance.evacuate',
fake_notifier.NOTIFICATIONS[0].event_type)
mock_notify.assert_called_once_with(
ctxt, instance, self.compute.host, action='evacuate',
source='nova-api')
if force is False:
req_dest = fake_spec.requested_destination
self.assertIsNotNone(req_dest)

View File

@ -703,6 +703,7 @@ class FakeLiveMigrateDriver(FakeDriver):
def live_migration_force_complete(self, instance):
self._migrating = False
del self.instances[instance.uuid]
def live_migration_abort(self, instance):
self._abort_migration = True