Fix race on default role creation

In add_user_to_project() it checks if the default role exists before
trying to add the role to the user and project. If it doesn't exist it
will attempt to create the role. However if 2 requests happen at
roughly the same time the 2 role creations will race causing one to
fail with a conflict error. This patch addresses this issue by catching
the conflict exception and treating it as the create succeeded (which it
did just elsewhere)

Change-Id: Iab95ed8b3913c020eafa919231d764ba8b780571
Closes-Bug: #1419043
This commit is contained in:
Matthew Treinish 2015-02-06 13:52:00 -05:00
parent 16a6c9c3df
commit 0b1027886a
1 changed files with 6 additions and 1 deletions

View File

@ -253,7 +253,12 @@ class Manager(manager.Manager):
config.CONF.member_role_id)
role = {'id': CONF.member_role_id,
'name': CONF.member_role_name}
self.role_api.create_role(config.CONF.member_role_id, role)
try:
self.role_api.create_role(config.CONF.member_role_id, role)
except exception.Conflict:
LOG.info(_LI("Creating the default role %s failed because it "
"was already created"),
config.CONF.member_role_id)
# now that default role exists, the add should succeed
self.driver.add_role_to_user_and_project(
user_id,