Make notification publisher_id consistent

The publisher_id of the versioned instance.update notification contains
'conductor' as the source of the notification but every other versioned
notification use names like 'nova-compute', 'nova-api',
'nova-scheduler'. This patch fixes this inconsistency.

Change-Id: I61c1d1676e74e367b4aeef6a6d3a7bb2ffacee23
Closes-Bug: #1702667
This commit is contained in:
Balazs Gibizer 2017-07-06 12:55:37 +02:00
parent dbf5fdb156
commit 427f4ec430
3 changed files with 9 additions and 13 deletions

View File

@ -252,19 +252,15 @@ def send_instance_update_notification(context, instance, old_vm_state=None,
_send_versioned_instance_update(context, instance, payload, host, service)
def _map_service_to_binary(service):
if service == 'api':
binary = 'nova-api'
elif service == 'compute':
binary = 'nova-compute'
else:
binary = service
return binary
@rpc.if_notifications_enabled
def _send_versioned_instance_update(context, instance, payload, host, service):
def _map_legacy_service_to_binary(legacy_service):
if not legacy_service.startswith('nova-'):
return 'nova-' + service
else:
return service
state_update = instance_notification.InstanceStateUpdatePayload(
old_state=payload.get('old_state'),
state=payload.get('state'),
@ -295,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_service_to_binary(service)),
binary=_map_legacy_service_to_binary(service)),
payload=versioned_payload)
notification.emit(context)

View File

@ -173,7 +173,7 @@ class TestInstanceNotificationSample(
# rest is from the nova-compute. To keep the test simpler
# assert this fact and then modify the publisher_id of the
# first and eighth notification to match the template
self.assertEqual('conductor:fake-mini',
self.assertEqual('nova-conductor:fake-mini',
instance_updates[0]['publisher_id'])
self.assertEqual('nova-api:fake-mini',
instance_updates[7]['publisher_id'])

View File

@ -426,7 +426,7 @@ class NotificationsTestCase(test.TestCase):
self.assertEqual('testservice.testhost', notif.publisher_id)
notif = fake_notifier.VERSIONED_NOTIFICATIONS[0]
self.assertEqual('testservice:testhost', notif['publisher_id'])
self.assertEqual('nova-testservice:testhost', notif['publisher_id'])
def test_update_with_host_name(self):
notifications.send_update_with_states(self.context, self.instance,