Handle service creation race by service workers
This handle a race where a sibling has already created the service
record in the database. This fix is similar to that of commit
f6c341b4
.
Change-Id: I7975fc632eee34390c5d7dc275b52363ad45475e
Closes-bug: 1326901
This commit is contained in:
parent
0ca98979da
commit
37247aba81
|
@ -170,7 +170,8 @@ class Service(service.Service):
|
|||
except exception.NotFound:
|
||||
try:
|
||||
self.service_ref = self._create_service_ref(ctxt)
|
||||
except exception.ServiceTopicExists:
|
||||
except (exception.ServiceTopicExists,
|
||||
exception.ServiceBinaryExists):
|
||||
# NOTE(danms): If we race to create a record with a sibling
|
||||
# worker, don't fail here.
|
||||
self.service_ref = self.conductor_api.service_get_by_args(ctxt,
|
||||
|
|
|
@ -186,7 +186,7 @@ class ServiceTestCase(test.TestCase):
|
|||
'nova.tests.test_service.FakeManager')
|
||||
serv.start()
|
||||
|
||||
def test_service_check_create_race(self):
|
||||
def _test_service_check_create_race(self, ex):
|
||||
self.manager_mock = self.mox.CreateMock(FakeManager)
|
||||
self.mox.StubOutWithMock(sys.modules[__name__], 'FakeManager',
|
||||
use_mock_anything=True)
|
||||
|
@ -201,7 +201,6 @@ class ServiceTestCase(test.TestCase):
|
|||
|
||||
db.service_get_by_args(mox.IgnoreArg(), self.host, self.binary
|
||||
).AndRaise(exception.NotFound)
|
||||
ex = exception.ServiceTopicExists(host='foo', topic='bar')
|
||||
db.service_create(mox.IgnoreArg(), mox.IgnoreArg()
|
||||
).AndRaise(ex)
|
||||
|
||||
|
@ -219,6 +218,14 @@ class ServiceTestCase(test.TestCase):
|
|||
'nova.tests.test_service.FakeManager')
|
||||
self.assertRaises(TestException, serv.start)
|
||||
|
||||
def test_service_check_create_race_topic_exists(self):
|
||||
ex = exception.ServiceTopicExists(host='foo', topic='bar')
|
||||
self._test_service_check_create_race(ex)
|
||||
|
||||
def test_service_check_create_race_binary_exists(self):
|
||||
ex = exception.ServiceBinaryExists(host='foo', binary='bar')
|
||||
self._test_service_check_create_race(ex)
|
||||
|
||||
def test_parent_graceful_shutdown(self):
|
||||
self.manager_mock = self.mox.CreateMock(FakeManager)
|
||||
self.mox.StubOutWithMock(sys.modules[__name__],
|
||||
|
|
Loading…
Reference in New Issue