Merge "Address nits from service create/destroy notification review"

This commit is contained in:
Zuul 2017-12-11 21:24:09 +00:00 committed by Gerrit Code Review
commit 2cbe6820e4
4 changed files with 19 additions and 5 deletions

View File

@ -162,11 +162,7 @@ class NotificationPublisher(NotificationObject):
@classmethod
def from_service_obj(cls, service):
# nova-osapi_compute binary name needs to be translated to nova-api
# notification source enum value.
source = ("nova-api"
if service.binary == "nova-osapi_compute"
else service.binary)
source = fields.NotificationSource.get_source_by_binary(service.binary)
return cls(host=service.host, source=source)

View File

@ -809,6 +809,12 @@ class NotificationSource(BaseNovaEnum):
ALL = (API, COMPUTE, CONDUCTOR, SCHEDULER,
NETWORK, CONSOLEAUTH, CELLS, CONSOLE, METADATA)
@staticmethod
def get_source_by_binary(binary):
# nova-osapi_compute binary name needs to be translated to nova-api
# notification source enum value.
return "nova-api" if binary == "nova-osapi_compute" else binary
class NotificationAction(BaseNovaEnum):
UPDATE = 'update'

View File

@ -151,6 +151,8 @@ class TestServiceNotificationSample(TestServiceNotificationBase):
def test_service_destroy(self):
self.compute2 = self.start_service('compute', host='host2')
# This test runs with the latest microversion by default so we get the
# service uuid back from the REST API.
compute2_service_id = self.admin_api.get_services(
host=self.compute2.host, binary='nova-compute')[0]['id']
self.admin_api.api_delete('os-services/%s' % compute2_service_id)

View File

@ -736,3 +736,13 @@ class TestSchemaGeneration(test.NoDBTestCase):
expected = {'type': ['string'], 'pattern': '[a-z]+[0-9]+',
'readonly': False}
self.assertEqual(expected, field.get_schema())
class TestNotificationSource(test.NoDBTestCase):
def test_get_source_by_binary(self):
self.assertEqual('nova-api',
fields.NotificationSource.get_source_by_binary(
'nova-osapi_compute'))
self.assertEqual('nova-metadata',
fields.NotificationSource.get_source_by_binary(
'nova-metadata'))