rename binary to source in versioned notifications

In the nova notification code path the nova service / binary names
are hardcoded. There is a possible confusion as the REST API uses
'nova-osapi_compute' while the notifications use 'nova-api'
as the name of the nova compute service binary.

To make it clear that these names used in the notifications
are not the official service names the field storing it is renamed
from 'binary' to 'source'. This renaming means that the version of
NotificationPublisher ovo needed a major version bump. However this
does not effect the consumers of the notifications as the
NotificationPublisher is not directly serialized to the payload wire
format. Instead the value  of the 'source' and 'host' fields are
dumped into the publisher_id field of the notification envelope.
Therefore this patch does not introduce a backward incompatible
change from the notification consumer perspective.

A subsequent patch will change this field to an enum to furter clarify
the possible values for notifications.

Change-Id: I95b5b0826190d396efe7bfc017f6081a6356da65
Related-Bug: #1696152
This commit is contained in:
Balazs Gibizer 2017-07-25 16:46:26 +02:00
parent 427f4ec430
commit f468dae28a
8 changed files with 30 additions and 29 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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)

View File

@ -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())

View File

@ -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,

View File

@ -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),

View File

@ -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',
}

View File

@ -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,