Merge "rename binary to source in versioned notifications"
This commit is contained in:
@@ -350,13 +350,13 @@ def _get_fault_and_priority_from_exc(exception):
|
||||
|
||||
@rpc.if_notifications_enabled
|
||||
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)
|
||||
@@ -367,7 +367,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,
|
||||
@@ -378,14 +378,14 @@ def notify_about_instance_action(context, instance, host, action, phase=None,
|
||||
|
||||
@rpc.if_notifications_enabled
|
||||
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)
|
||||
@@ -396,7 +396,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,
|
||||
@@ -407,14 +407,14 @@ def notify_about_instance_create(context, instance, host, phase=None,
|
||||
|
||||
@rpc.if_notifications_enabled
|
||||
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)
|
||||
"""
|
||||
@@ -427,7 +427,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,
|
||||
@@ -449,7 +449,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,
|
||||
@@ -484,7 +484,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)
|
||||
@@ -527,7 +527,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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -256,7 +256,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:
|
||||
@@ -292,7 +292,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)
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
|
||||
@@ -625,7 +625,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,
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -199,7 +199,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)
|
||||
|
||||
@@ -393,7 +393,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',
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user