diff --git a/doc/notification_samples/instance-reboot-error.json b/doc/notification_samples/instance-reboot-error.json new file mode 100644 index 0000000000..d5e64fab51 --- /dev/null +++ b/doc/notification_samples/instance-reboot-error.json @@ -0,0 +1,84 @@ +{ + "event_type":"instance.reboot.error", + "payload":{ + "nova_object.data":{ + "architecture": null, + "availability_zone":null, + "created_at":"2012-10-29T13:42:11Z", + "deleted_at":null, + "display_name":"some-server", + "display_description":"some-server", + "fault": { + "nova_object.data": { + "exception": "UnsupportedVirtType", + "exception_message": "Virtualization type 'FakeVirt' is not supported by this compute driver", + "function_name": "_hard_reboot", + "module_name": "nova.tests.functional.notification_sample_tests.test_instance" + }, + "nova_object.name": "ExceptionPayload", + "nova_object.namespace": "nova", + "nova_object.version": "1.0" + }, + "host":"compute", + "host_name":"some-server", + "ip_addresses": [{ + "nova_object.name": "IpPayload", + "nova_object.namespace": "nova", + "nova_object.version": "1.0", + "nova_object.data": { + "mac": "fa:16:3e:4c:2c:30", + "address": "192.168.1.3", + "port_uuid": "ce531f90-199f-48c0-816c-13e38010b442", + "meta": {}, + "version": 4, + "label": "private-network", + "device_name": "tapce531f90-19" + } + }], + "kernel_id":"", + "launched_at":"2012-10-29T13:42:11Z", + "image_uuid": "a2459075-d96c-40d5-893e-577ff92e721c", + "metadata":{}, + "locked":false, + "node":"fake-mini", + "os_type":null, + "progress":0, + "ramdisk_id":"", + "reservation_id":"r-npxv0e40", + "state":"active", + "task_state":"reboot_started_hard", + "power_state":"running", + "tenant_id":"6f70656e737461636b20342065766572", + "terminated_at":null, + "flavor": { + "nova_object.name": "FlavorPayload", + "nova_object.data": { + "flavorid": "a22d5517-147c-4147-a0d1-e698df5cd4e3", + "name": "test_flavor", + "projects": null, + "root_gb": 1, + "vcpus": 1, + "ephemeral_gb": 0, + "memory_mb": 512, + "disabled": false, + "rxtx_factor": 1.0, + "extra_specs": { + "hw:watchdog_action": "disabled" + }, + "swap": 0, + "is_public": true, + "vcpu_weight": 0 + }, + "nova_object.version": "1.3", + "nova_object.namespace": "nova" + }, + "user_id":"fake", + "uuid":"178b0921-8f85-4257-88b6-2e743b5a975c" + }, + "nova_object.name":"InstanceActionPayload", + "nova_object.namespace":"nova", + "nova_object.version":"1.1" + }, + "priority":"ERROR", + "publisher_id":"nova-compute:compute" +} \ No newline at end of file diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 38b0e8532f..b1bd1f5a04 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -3044,6 +3044,12 @@ class ComputeManager(manager.Manager): instance, error, exc_info) self._notify_about_instance_usage(context, instance, 'reboot.error', fault=error) + compute_utils.notify_about_instance_action( + context, instance, self.host, + action=fields.NotificationAction.REBOOT, + phase=fields.NotificationPhase.ERROR, + exception=error + ) ctxt.reraise = False else: LOG.error(_LE('Cannot reboot instance: %s'), error, diff --git a/nova/notifications/objects/instance.py b/nova/notifications/objects/instance.py index 81db4d731a..0c079863a4 100644 --- a/nova/notifications/objects/instance.py +++ b/nova/notifications/objects/instance.py @@ -241,6 +241,7 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase): @base.notification_sample('instance-power_off-end.json') @base.notification_sample('instance-reboot-start.json') @base.notification_sample('instance-reboot-end.json') +@base.notification_sample('instance-reboot-error.json') @base.notification_sample('instance-shutdown-start.json') @base.notification_sample('instance-shutdown-end.json') @base.notification_sample('instance-snapshot-start.json') diff --git a/nova/tests/functional/notification_sample_tests/test_instance.py b/nova/tests/functional/notification_sample_tests/test_instance.py index 44d9015df8..9bd4ccf638 100644 --- a/nova/tests/functional/notification_sample_tests/test_instance.py +++ b/nova/tests/functional/notification_sample_tests/test_instance.py @@ -77,6 +77,7 @@ class TestInstanceNotificationSample( self._test_snapshot_server, self._test_rebuild_server, self._test_reboot_server, + self._test_reboot_server_error, ] for action in actions: @@ -647,6 +648,29 @@ class TestInstanceNotificationSample( 'uuid': server['id']}, actual=fake_notifier.VERSIONED_NOTIFICATIONS[1]) + @mock.patch('nova.virt.fake.SmallFakeDriver.reboot') + def _test_reboot_server_error(self, server, mock_reboot): + def _hard_reboot(*args, **kwargs): + raise exception.UnsupportedVirtType(virt="FakeVirt") + mock_reboot.side_effect = _hard_reboot + post = {'reboot': {'type': 'HARD'}} + self.api.post_server_action(server['id'], post) + self._wait_for_notification('instance.reboot.start') + self._wait_for_notification('instance.reboot.error') + self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS)) + self._verify_notification( + 'instance-reboot-start', + replacements={ + 'reservation_id': server['reservation_id'], + 'uuid': server['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[0]) + self._verify_notification( + 'instance-reboot-error', + replacements={ + 'reservation_id': server['reservation_id'], + 'uuid': server['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[1]) + def _attach_volume_to_server(self, server, volume_id): self.api.post_server_volume( server['id'], {"volumeAttachment": {"volumeId": volume_id}}) diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 2814308294..afe05ad07c 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -3018,6 +3018,9 @@ class ComputeTestCase(BaseTestCase): if fail_running: notify_call_list.append(mock.call(econtext, instance, 'reboot.error', fault=fault)) + notify_action_call_list.append( + mock.call(econtext, instance, 'fake-mini', + action='reboot', phase='error', exception=fault)) notify_call_list.append(mock.call(econtext, instance, 'reboot.end')) notify_action_call_list.append(