diff --git a/nova/compute/utils.py b/nova/compute/utils.py index 23ff7a82b9..68945662cc 100644 --- a/nova/compute/utils.py +++ b/nova/compute/utils.py @@ -339,13 +339,13 @@ def _get_fault_and_priority_from_exc(exception): def notify_about_instance_action(context, instance, host, action, phase=None, - binary='nova-compute', exception=None): + source='nova-compute', exception=None): """Send versioned notification about the action made on the instance :param instance: the instance which the action performed on :param host: the host emitting the notification :param action: the name of the action :param phase: the phase of the action - :param binary: the binary emitting the notification + :param source: the source of the notification :param exception: the thrown exception (used in error notifications) """ fault, priority = _get_fault_and_priority_from_exc(exception) @@ -356,7 +356,7 @@ def notify_about_instance_action(context, instance, host, action, phase=None, context=context, priority=priority, publisher=notification_base.NotificationPublisher( - host=host, binary=binary), + host=host, source=source), event_type=notification_base.EventType( object='instance', action=action, @@ -366,14 +366,14 @@ def notify_about_instance_action(context, instance, host, action, phase=None, def notify_about_instance_create(context, instance, host, phase=None, - binary='nova-compute', exception=None): + source='nova-compute', exception=None): """Send versioned notification about instance creation :param context: the request context :param instance: the instance being created :param host: the host emitting the notification :param phase: the phase of the creation - :param binary: the binary emitting the notification + :param source: the source of the notification :param exception: the thrown exception (used in error notifications) """ fault, priority = _get_fault_and_priority_from_exc(exception) @@ -384,7 +384,7 @@ def notify_about_instance_create(context, instance, host, phase=None, context=context, priority=priority, publisher=notification_base.NotificationPublisher( - host=host, binary=binary), + host=host, source=source), event_type=notification_base.EventType( object='instance', action=fields.NotificationAction.CREATE, @@ -394,14 +394,14 @@ def notify_about_instance_create(context, instance, host, phase=None, def notify_about_volume_attach_detach(context, instance, host, action, phase, - binary='nova-compute', volume_id=None, + source='nova-compute', volume_id=None, exception=None): """Send versioned notification about the action made on the instance :param instance: the instance which the action performed on :param host: the host emitting the notification :param action: the name of the action :param phase: the phase of the action - :param binary: the binary emitting the notification + :param source: the source of the notification :param volume_id: id of the volume will be attached :param exception: the thrown exception (used in error notifications) """ @@ -414,7 +414,7 @@ def notify_about_volume_attach_detach(context, instance, host, action, phase, context=context, priority=priority, publisher=notification_base.NotificationPublisher( - host=host, binary=binary), + host=host, source=source), event_type=notification_base.EventType( object='instance', action=action, @@ -435,7 +435,7 @@ def notify_about_keypair_action(context, keypair, action, phase): notification = keypair_notification.KeypairNotification( priority=fields.NotificationPriority.INFO, publisher=notification_base.NotificationPublisher( - host=CONF.host, binary='nova-api'), + host=CONF.host, source='nova-api'), event_type=notification_base.EventType( object='keypair', action=action, @@ -469,7 +469,7 @@ def notify_about_volume_swap(context, instance, host, action, phase, context=context, priority=priority, publisher=notification_base.NotificationPublisher( - host=host, binary='nova-compute'), + host=host, source='nova-compute'), event_type=notification_base.EventType( object='instance', action=action, phase=phase), payload=payload).emit(context) @@ -511,7 +511,7 @@ def notify_about_aggregate_action(context, aggregate, action, phase): notification = aggregate_notification.AggregateNotification( priority=fields.NotificationPriority.INFO, publisher=notification_base.NotificationPublisher( - host=CONF.host, binary='nova-api'), + host=CONF.host, source='nova-api'), event_type=notification_base.EventType( object='aggregate', action=action, diff --git a/nova/exception_wrapper.py b/nova/exception_wrapper.py index 9009b80958..c5d932c6dc 100644 --- a/nova/exception_wrapper.py +++ b/nova/exception_wrapper.py @@ -27,16 +27,16 @@ CONF = nova.conf.CONF def _emit_exception_notification(notifier, context, ex, function_name, args, - binary): + source): _emit_legacy_exception_notification(notifier, context, ex, function_name, args) - _emit_versioned_exception_notification(context, ex, binary) + _emit_versioned_exception_notification(context, ex, source) @rpc.if_notifications_enabled -def _emit_versioned_exception_notification(context, ex, binary): +def _emit_versioned_exception_notification(context, ex, source): versioned_exception_payload = exception.ExceptionPayload.from_exception(ex) - publisher = base.NotificationPublisher(host=CONF.host, binary=binary) + publisher = base.NotificationPublisher(host=CONF.host, source=source) event_type = base.EventType( object='compute', action=fields.NotificationAction.EXCEPTION) diff --git a/nova/notifications/base.py b/nova/notifications/base.py index 7fb340c5ba..b7a01428c0 100644 --- a/nova/notifications/base.py +++ b/nova/notifications/base.py @@ -255,7 +255,7 @@ def send_instance_update_notification(context, instance, old_vm_state=None, @rpc.if_notifications_enabled def _send_versioned_instance_update(context, instance, payload, host, service): - def _map_legacy_service_to_binary(legacy_service): + def _map_legacy_service_to_source(legacy_service): if not legacy_service.startswith('nova-'): return 'nova-' + service else: @@ -291,7 +291,7 @@ def _send_versioned_instance_update(context, instance, payload, host, service): action=fields.NotificationAction.UPDATE), publisher=notification_base.NotificationPublisher( host=host or CONF.host, - binary=_map_legacy_service_to_binary(service)), + source=_map_legacy_service_to_source(service)), payload=versioned_payload) notification.emit(context) diff --git a/nova/notifications/objects/base.py b/nova/notifications/objects/base.py index 948824bff3..02de61d4ac 100644 --- a/nova/notifications/objects/base.py +++ b/nova/notifications/objects/base.py @@ -138,21 +138,22 @@ class NotificationPayloadBase(NotificationObject): @base.NovaObjectRegistry.register_notification class NotificationPublisher(NotificationObject): # Version 1.0: Initial version - VERSION = '1.0' + # 2.0: The binary field has been renamed to source + VERSION = '2.0' fields = { 'host': fields.StringField(nullable=False), - 'binary': fields.StringField(nullable=False), + 'source': fields.StringField(nullable=False), } - def __init__(self, host, binary): + def __init__(self, host, source): super(NotificationPublisher, self).__init__() self.host = host - self.binary = binary + self.source = source @classmethod def from_service_obj(cls, service): - return cls(host=service.host, binary=service.binary) + return cls(host=service.host, source=service.binary) @base.NovaObjectRegistry.register_if(False) @@ -189,7 +190,7 @@ class NotificationBase(NotificationObject): event_type= self.event_type.to_notification_event_type_field(), publisher_id='%s:%s' % - (self.publisher.binary, + (self.publisher.source, self.publisher.host), payload=self.payload.obj_to_primitive()) diff --git a/nova/objects/flavor.py b/nova/objects/flavor.py index f8c1bb570b..3da9be2e0f 100644 --- a/nova/objects/flavor.py +++ b/nova/objects/flavor.py @@ -626,7 +626,7 @@ class Flavor(base.NovaPersistentObject, base.NovaObject, payload = payload_type(self) notification_type( publisher=notification.NotificationPublisher( - host=CONF.host, binary="nova-api"), + host=CONF.host, source="nova-api"), event_type=notification.EventType(object="flavor", action=action), priority=fields.NotificationPriority.INFO, diff --git a/nova/tests/unit/notifications/objects/test_flavor.py b/nova/tests/unit/notifications/objects/test_flavor.py index 95ee1b4a80..bf40aa9853 100644 --- a/nova/tests/unit/notifications/objects/test_flavor.py +++ b/nova/tests/unit/notifications/objects/test_flavor.py @@ -55,7 +55,7 @@ class TestFlavorNotification(test.TestCase): payload = notification.call_args[1]['payload'] self.assertEqual("fake-mini", publisher.host) - self.assertEqual("nova-api", publisher.binary) + self.assertEqual("nova-api", publisher.source) self.assertEqual(fields.NotificationPriority.INFO, priority) self.assertEqual('flavor', event_type.object) self.assertEqual(getattr(fields.NotificationAction, action), diff --git a/nova/tests/unit/notifications/objects/test_notification.py b/nova/tests/unit/notifications/objects/test_notification.py index 70b18607a4..fbb17f02ed 100644 --- a/nova/tests/unit/notifications/objects/test_notification.py +++ b/nova/tests/unit/notifications/objects/test_notification.py @@ -197,7 +197,7 @@ class TestNotificationBase(test.NoDBTestCase): object='test_object', action=fields.NotificationAction.UPDATE), publisher=notification.NotificationPublisher(host='fake-host', - binary='nova-fake'), + source='nova-fake'), priority=fields.NotificationPriority.INFO, payload=self.payload) @@ -390,7 +390,7 @@ notification_object_data = { 'IpPayload': '1.0-8ecf567a99e516d4af094439a7632d34', 'KeypairNotification': '1.0-a73147b93b520ff0061865849d3dfa56', 'KeypairPayload': '1.0-6daebbbde0e1bf35c1556b1ecd9385c1', - 'NotificationPublisher': '1.0-bbbc1402fb0e443a3eb227cc52b61545', + 'NotificationPublisher': '2.0-578ee5fea2922ff32e8917621f140857', 'ServiceStatusNotification': '1.0-a73147b93b520ff0061865849d3dfa56', 'ServiceStatusPayload': '1.1-7b6856bd879db7f3ecbcd0ca9f35f92f', } diff --git a/nova/tests/unit/notifications/objects/test_service.py b/nova/tests/unit/notifications/objects/test_service.py index a04f48cea9..75a6a8626d 100644 --- a/nova/tests/unit/notifications/objects/test_service.py +++ b/nova/tests/unit/notifications/objects/test_service.py @@ -41,7 +41,7 @@ class TestServiceStatusNotification(test.TestCase): payload = mock_notification.call_args[1]['payload'] self.assertEqual(service_obj.host, publisher.host) - self.assertEqual(service_obj.binary, publisher.binary) + self.assertEqual(service_obj.binary, publisher.source) self.assertEqual(fields.NotificationPriority.INFO, priority) self.assertEqual('service', event_type.object) self.assertEqual(fields.NotificationAction.UPDATE,