Merge "Make notification publisher_id consistent"

This commit is contained in:
Jenkins 2017-07-25 15:48:46 +00:00 committed by Gerrit Code Review
commit 3dd6526137
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

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