Merge "Refresh the Service.service_id after re-spawning children"

This commit is contained in:
Zuul 2019-05-01 03:57:22 +00:00 committed by Gerrit Code Review
commit a0eacd123f
2 changed files with 26 additions and 0 deletions

View File

@ -191,6 +191,7 @@ class Service(service.Service):
service_ref.cluster_name = cluster
service_ref.save()
Service.service_id = service_ref.id
self.origin_service_id = service_ref.id
except exception.NotFound:
self._create_service_ref(ctxt, manager_class.RPC_API_VERSION)
# Service entry Entry didn't exist because it was manually removed
@ -218,6 +219,12 @@ class Service(service.Service):
if self.coordination:
coordination.COORDINATOR.start()
# NOTE(yikun): When re-spawning child process, we should set the class
# attribute back using the origin service_id, otherwise,
# the Service.service_id will be inherited from the parent process,
# and will be recorded as the last started service id by mistaken.
Service.service_id = self.origin_service_id
self.manager.init_host(added_to_cluster=self.added_to_cluster,
service_id=Service.service_id)
@ -342,6 +349,7 @@ class Service(service.Service):
service_ref = objects.Service(context=context, **kwargs)
service_ref.create()
Service.service_id = service_ref.id
self.origin_service_id = service_ref.id
self._ensure_cluster_exists(context, service_ref)
# If we have updated the service_ref with replication data from
# the cluster it will be saved.

View File

@ -99,6 +99,24 @@ class ServiceManagerTestCase(test.TestCase):
self.assertEqual({}, rpc.LAST_OBJ_VERSIONS)
self.assertEqual({}, rpc.LAST_RPC_VERSIONS)
def test_start_refresh_serivce_id(self):
serv = service.Service('test',
'test',
'test',
'cinder.tests.unit.test_service.FakeManager')
# records the original service id
serv_id = serv.service_id
self.assertEqual(serv.origin_service_id, service.Service.service_id)
# update service id to other value
service.Service.service_id = serv_id + 1
# make sure the class attr service_id have been changed
self.assertNotEqual(serv.origin_service_id,
service.Service.service_id)
# call start method
serv.start()
# After start, the service id is refreshed to original service_id
self.assertEqual(serv_id, service.Service.service_id)
class ServiceFlagsTestCase(test.TestCase):
def test_service_enabled_on_create_based_on_flag(self):