Skip to content

Commit

Permalink
Handle service creation race by service workers
Browse files Browse the repository at this point in the history
This handle a race where a sibling has already created the service
record in the database.  This fix is similar to that of commit
f6c341b.

Change-Id: I7975fc632eee34390c5d7dc275b52363ad45475e
Closes-bug: 1326901
(cherry picked from commit 37247ab)
  • Loading branch information
Corey Bryant authored and javacruft committed Jul 21, 2014
1 parent a4cf7c1 commit 72cc37d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion nova/service.py
Expand Up @@ -170,7 +170,8 @@ def start(self):
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,
Expand Down
11 changes: 9 additions & 2 deletions nova/tests/test_service.py
Expand Up @@ -186,7 +186,7 @@ def test_init_and_start_hooks(self):
'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)
Expand All @@ -201,7 +201,6 @@ def test_service_check_create_race(self):

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)

Expand All @@ -219,6 +218,14 @@ class TestException(Exception):
'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__],
Expand Down

0 comments on commit 72cc37d

Please sign in to comment.