Add error notification for instance.interface_attach

Change-Id: Idde2e36658d2fd98444fb0780899bfca32dd2d6e
Implements: bp versioned-notification-transformation-queens
This commit is contained in:
Előd Illés 2017-09-22 15:00:20 +02:00 committed by Balazs Gibizer
parent f1317c016c
commit 06231be9ed
4 changed files with 150 additions and 1 deletions

View File

@ -0,0 +1,103 @@
{
"priority": "ERROR",
"event_type": "instance.interface_attach.error",
"payload": {
"nova_object.name": "InstanceActionPayload",
"nova_object.version": "1.5",
"nova_object.namespace": "nova",
"nova_object.data": {
"power_state": "running",
"host_name": "some-server",
"reservation_id": "r-f8grvm0d",
"metadata": {},
"os_type": null,
"display_description": "some-server",
"ramdisk_id": "",
"deleted_at": null,
"launched_at": "2012-10-29T13:42:11Z",
"updated_at": "2012-10-29T13:42:11Z",
"key_name": "my-key",
"auto_disk_config": "MANUAL",
"block_devices": [
{
"nova_object.data": {
"boot_index": null,
"delete_on_termination": false,
"device_name": "/dev/sdb",
"tag": null,
"volume_id": "a07f71dc-8151-4e7d-a0cc-cd24a3f11113"
},
"nova_object.name": "BlockDevicePayload",
"nova_object.namespace": "nova",
"nova_object.version": "1.0"
}
],
"availability_zone": "nova",
"display_name": "some-server",
"fault": {
"nova_object.data": {
"exception": "InterfaceAttachFailed",
"exception_message": "dummy",
"function_name": "_unsuccessful_attach_interface",
"module_name": "nova.tests.functional.notification_sample_tests.test_instance"
},
"nova_object.name": "ExceptionPayload",
"nova_object.namespace": "nova",
"nova_object.version": "1.0"
},
"locked": false,
"ip_addresses": [
{
"nova_object.name": "IpPayload",
"nova_object.version": "1.0",
"nova_object.namespace": "nova",
"nova_object.data": {
"label": "private-network",
"mac": "fa:16:3e:4c:2c:30",
"version": 4,
"address": "192.168.1.3",
"meta": {},
"port_uuid": "ce531f90-199f-48c0-816c-13e38010b442",
"device_name": "tapce531f90-19"
}
}
],
"kernel_id": "",
"progress": 0,
"tenant_id": "6f70656e737461636b20342065766572",
"state": "active",
"task_state": null,
"uuid": "edbe0f81-b150-4fce-9258-4e03bb2ecb41",
"user_id": "fake",
"created_at": "2012-10-29T13:42:11Z",
"image_uuid": "155d900f-4e14-4e4c-a73d-069cbf4541e6",
"node": "fake-mini",
"flavor": {
"nova_object.name": "FlavorPayload",
"nova_object.version": "1.3",
"nova_object.namespace": "nova",
"nova_object.data": {
"vcpu_weight": 0,
"memory_mb": 512,
"name": "test_flavor",
"root_gb": 1,
"extra_specs": {
"hw:watchdog_action": "disabled"
},
"disabled": false,
"rxtx_factor": 1.0,
"vcpus": 1,
"is_public": true,
"swap": 0,
"flavorid": "a22d5517-147c-4147-a0d1-e698df5cd4e3",
"projects": null,
"ephemeral_gb": 0
}
},
"host": "compute",
"terminated_at": null,
"architecture": "x86_64"
}
},
"publisher_id": "nova-compute:compute"
}

View File

@ -5342,6 +5342,8 @@ class ComputeManager(manager.Manager):
if len(network_info) != 1:
LOG.error('allocate_port_for_instance returned %(ports)s '
'ports', {'ports': len(network_info)})
# TODO(elod.illes): an instance.interface_attach.error notification
# should be sent here
raise exception.InterfaceAttachFailed(
instance_uuid=instance.uuid)
image_meta = objects.ImageMeta.from_instance(instance)
@ -5361,6 +5363,13 @@ class ComputeManager(manager.Manager):
except Exception:
LOG.warning("deallocate port %(port_id)s failed",
{'port_id': port_id}, instance=instance)
compute_utils.notify_about_instance_action(
context, instance, self.host,
action=fields.NotificationAction.INTERFACE_ATTACH,
phase=fields.NotificationPhase.ERROR,
exception=ex)
raise exception.InterfaceAttachFailed(
instance_uuid=instance.uuid)

View File

@ -17,6 +17,7 @@ import mock
from nova import context
from nova import exception
from nova.tests import fixtures
from nova.tests.functional.api import client
from nova.tests.functional.notification_sample_tests \
import notification_sample_base
from nova.tests.unit import fake_notifier
@ -150,6 +151,7 @@ class TestInstanceNotificationSample(
self._test_soft_delete_server,
self._test_attach_volume_error,
self._test_interface_attach_and_detach,
self._test_interface_attach_error,
]
for action in actions:
@ -1187,3 +1189,34 @@ class TestInstanceNotificationSample(
'reservation_id': server['reservation_id'],
'uuid': server['id']},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
@mock.patch('nova.virt.fake.SmallFakeDriver.attach_interface')
def _test_interface_attach_error(self, server, mock_driver):
def _unsuccessful_attach_interface(*args, **kwargs):
raise exception.InterfaceAttachFailed("dummy")
mock_driver.side_effect = _unsuccessful_attach_interface
post = {
'interfaceAttachment': {
'net_id': fixtures.NeutronFixture.network_1['id']
}
}
self.assertRaises(
client.OpenStackApiException,
self.api.attach_interface, server['id'], post)
self._wait_for_notification('instance.interface_attach.error')
# 0. instance.interface_attach.start
# 1. instance.interface_attach.error
# 2. compute.exception
self.assertLessEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
self._verify_notification(
'instance-interface_attach-start',
replacements={
'reservation_id': server['reservation_id'],
'uuid': server['id']},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
self._verify_notification(
'instance-interface_attach-error',
replacements={
'reservation_id': server['reservation_id'],
'uuid': server['id']},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])

View File

@ -9954,7 +9954,11 @@ class ComputeAPITestCase(BaseTestCase):
port_id)
mock_notify.assert_has_calls([
mock.call(self.context, instance, self.compute.host,
action='interface_attach', phase='start')])
action='interface_attach', phase='start'),
mock.call(self.context, instance, self.compute.host,
action='interface_attach',
exception=mock_attach.side_effect,
phase='error')])
@mock.patch.object(compute_utils, 'notify_about_instance_action')
def test_detach_interface(self, mock_notify):