Transform instance.resize.error notifications

The instance.resize.error notification
is transformed to the versioned framework.

Change-Id: Ieb4ae4605fee8fbf58de4c5efb3c00083b4bd62c
Implements: bp versioned-notification-transformation-queens
This commit is contained in:
Béla Vancsics 2017-08-21 11:53:21 +02:00 committed by Balazs Gibizer
parent 3f6447120b
commit 804dd877dc
5 changed files with 205 additions and 2 deletions

View File

@ -0,0 +1,90 @@
{
"event_type":"instance.resize.error",
"payload":{
"nova_object.data":{
"architecture":"x86_64",
"auto_disk_config":"MANUAL",
"availability_zone":"nova",
"block_devices":[],
"created_at":"2012-10-29T13:42:11Z",
"deleted_at":null,
"display_description":"some-server",
"display_name":"some-server",
"fault":{
"nova_object.data":{
"exception":"FlavorDiskTooSmall",
"exception_message":"The created instance's disk would be too small.",
"function_name":"_build_resources",
"module_name":"nova.tests.functional.notification_sample_tests.test_instance"
},
"nova_object.name":"ExceptionPayload",
"nova_object.namespace":"nova",
"nova_object.version":"1.0"
},
"flavor":{
"nova_object.data":{
"disabled":false,
"ephemeral_gb":0,
"extra_specs":{
"hw:watchdog_action":"disabled"
},
"flavorid":"a22d5517-147c-4147-a0d1-e698df5cd4e3",
"is_public":true,
"memory_mb":512,
"name":"test_flavor",
"projects":null,
"root_gb":1,
"rxtx_factor":1.0,
"swap":0,
"vcpu_weight":0,
"vcpus":1
},
"nova_object.name":"FlavorPayload",
"nova_object.namespace":"nova",
"nova_object.version":"1.3"
},
"host":"compute",
"host_name":"some-server",
"image_uuid":"155d900f-4e14-4e4c-a73d-069cbf4541e6",
"ip_addresses":[
{
"nova_object.data":{
"address":"192.168.1.3",
"device_name":"tapce531f90-19",
"label":"private-network",
"mac":"fa:16:3e:4c:2c:30",
"meta":{},
"port_uuid":"ce531f90-199f-48c0-816c-13e38010b442",
"version":4
},
"nova_object.name":"IpPayload",
"nova_object.namespace":"nova",
"nova_object.version":"1.0"
}
],
"kernel_id":"",
"key_name":"my-key",
"launched_at":"2012-10-29T13:42:11Z",
"locked":false,
"metadata":{},
"node":"fake-mini",
"os_type":null,
"power_state":"running",
"progress":0,
"ramdisk_id":"",
"reservation_id":"r-fekt9l17",
"state":"active",
"task_state":"resize_prep",
"tenant_id":"6f70656e737461636b20342065766572",
"terminated_at":null,
"user_id":"fake",
"updated_at": "2012-10-29T13:42:11Z",
"uuid":"6db66f8a-0cdc-45b8-a851-41d79536883b"
},
"nova_object.name":"InstanceActionPayload",
"nova_object.namespace":"nova",
"nova_object.version":"1.5"
},
"priority":"ERROR",
"publisher_id":"nova-compute:compute"
}

View File

@ -3849,13 +3849,22 @@ class ComputeManager(manager.Manager):
exc_info=sys.exc_info())
self._notify_about_instance_usage(context, instance,
'resize.error', fault=error)
compute_utils.notify_about_instance_action(
context, instance, self.host,
action=fields.NotificationAction.RESIZE,
phase=fields.NotificationPhase.ERROR,
exception=error)
if rescheduled:
self._log_original_error(exc_info, instance_uuid)
compute_utils.add_instance_fault_from_exc(context,
instance, exc_info[1], exc_info=exc_info)
self._notify_about_instance_usage(context, instance,
'resize.error', fault=exc_info[1])
compute_utils.notify_about_instance_action(
context, instance, self.host,
action=fields.NotificationAction.RESIZE,
phase=fields.NotificationPhase.ERROR,
exception=exc_info[1])
else:
# not re-scheduling
six.reraise(*exc_info)

View File

@ -387,6 +387,7 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase):
@base.notification_sample('instance-unpause-end.json')
@base.notification_sample('instance-resize-start.json')
@base.notification_sample('instance-resize-end.json')
@base.notification_sample('instance-resize-error.json')
@base.notification_sample('instance-suspend-start.json')
@base.notification_sample('instance-suspend-end.json')
@base.notification_sample('instance-power_on-start.json')

View File

@ -644,6 +644,105 @@ class TestInstanceNotificationSample(
post = {'revertResize': None}
self.api.post_server_action(server['id'], post)
@mock.patch('nova.compute.manager.ComputeManager._reschedule',
return_value=True)
@mock.patch('nova.compute.manager.ComputeManager._prep_resize')
def test_resize_server_error_but_reschedule_was_success(
self, mock_prep_resize, mock_reschedule):
"""Test it, when the prep_resize method raise an exception,
but the reschedule_resize_or_reraise was successful and
scheduled the resize. In this case we get a notification
about the exception, which caused the prep_resize error.
"""
def _build_resources(*args, **kwargs):
raise exception.FlavorDiskTooSmall()
server = self._boot_a_server(
extra_params={'networks': [{'port': self.neutron.port_1['id']}]})
self.flags(allow_resize_to_same_host=True)
other_flavor_body = {
'flavor': {
'name': 'other_flavor_error',
'ram': 512,
'vcpus': 1,
'disk': 1,
'id': 'a22d5517-147c-4147-a0d1-e698df5cd4e9'
}
}
other_flavor_id = self.api.post_flavor(other_flavor_body)['id']
post = {
'resize': {
'flavorRef': other_flavor_id
}
}
fake_notifier.reset()
mock_prep_resize.side_effect = _build_resources
self.api.post_server_action(server['id'], post)
self._wait_for_notification('instance.resize.error')
self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS),
'Unexpected number of notifications: %s' %
fake_notifier.VERSIONED_NOTIFICATIONS)
self._verify_notification('instance-resize-error',
replacements={
'reservation_id': server['reservation_id'],
'uuid': server['id']
},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
@mock.patch('nova.compute.manager.ComputeManager._reschedule')
@mock.patch('nova.compute.manager.ComputeManager._prep_resize')
def test_resize_server_error_and_reschedule_was_failed(
self, mock_prep_resize, mock_reschedule):
"""Test it, when the prep_resize method raise an exception,
after trying again with the reschedule_resize_or_reraise method
call, but the rescheduled also was unsuccessful. In this
case called the exception block.
In the exception block send a notification about error.
At end called the six.reraise(*exc_info), which not
send another error.
"""
def _build_resources(*args, **kwargs):
raise exception.FlavorDiskTooSmall()
server = self._boot_a_server(
extra_params={'networks': [{'port': self.neutron.port_1['id']}]})
self.flags(allow_resize_to_same_host=True)
other_flavor_body = {
'flavor': {
'name': 'other_flavor_error',
'ram': 512,
'vcpus': 1,
'disk': 1,
'id': 'a22d5517-147c-4147-a0d1-e698df5cd4e9'
}
}
other_flavor_id = self.api.post_flavor(other_flavor_body)['id']
post = {
'resize': {
'flavorRef': other_flavor_id
}
}
fake_notifier.reset()
mock_prep_resize.side_effect = _build_resources
# This isn't realistic that _reschedule would raise FlavorDiskTooSmall,
# but it's needed for the notification sample to work.
mock_reschedule.side_effect = _build_resources
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.api, server, expected_status='ERROR')
# There should be two notifications, one for the instance.resize.error
# and one for the compute.exception via the wrap_exception decorator on
# the ComputeManager.prep_resize method.
self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS),
'Unexpected number of notifications: %s' %
fake_notifier.VERSIONED_NOTIFICATIONS)
self._verify_notification('instance-resize-error',
replacements={
'reservation_id': server['reservation_id'],
'uuid': server['id']
},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
def _test_snapshot_server(self, server):
post = {'createImage': {'name': 'test-snap'}}
self.api.post_server_action(server['id'], post)

View File

@ -11816,7 +11816,8 @@ class ComputeRescheduleResizeOrReraiseTestCase(BaseTestCase):
self.instance_type, {}, {})
@mock.patch.object(compute_manager.ComputeManager, "_reschedule")
def test_reschedule_fails_with_exception(self, mock_res):
@mock.patch('nova.compute.utils.notify_about_instance_action')
def test_reschedule_fails_with_exception(self, mock_notify, mock_res):
"""Original exception should be raised if the _reschedule method
raises another exception
"""
@ -11837,6 +11838,9 @@ class ComputeRescheduleResizeOrReraiseTestCase(BaseTestCase):
self.context, {}, {}, instance,
self.compute.compute_task_api.resize_instance, method_args,
task_states.RESIZE_PREP, exc_info)
mock_notify.assert_called_once_with(
self.context, instance, 'fake-mini', action='resize',
phase='error', exception=mock_res.side_effect)
@mock.patch.object(compute_manager.ComputeManager, "_reschedule")
def test_reschedule_false(self, mock_res):