Make sure the assignment creation use the right arguments

`keystone-manage bootstrap` will fail to create the assignment if
project or role exists, this is because the assignment creation
is not using the right role id or project id.

This patch will fix this issue.

Change-Id: I7359cfe8f573ae56556654f1eafcc75079e69ccc
Closes-Bug: #1534140
bp: bootstrap
This commit is contained in:
Dave Chen 2016-01-17 15:45:30 +08:00 committed by Steve Martinelli
parent 3198b67ced
commit cda3853c41
2 changed files with 55 additions and 2 deletions

View File

@ -150,6 +150,9 @@ class BootStrap(BaseApp):
except exception.Conflict:
LOG.info(_LI('Project %s already exists, skipping creation.'),
self.project_name)
project = self.resource_manager.get_project_by_name(
self.project_name, default_domain['id'])
self.tenant_id = project['id']
# NOTE(morganfainberg): Do not create the user if it already exists.
try:
@ -177,6 +180,13 @@ class BootStrap(BaseApp):
LOG.info(_LI('Created Role %s'), self.role_name)
except exception.Conflict:
LOG.info(_LI('Role %s exists, skipping creation.'), self.role_name)
# NOTE(davechen): There is no backend method to get the role
# by name, so build the hints to list the roles and filter by
# name instead.
hints = driver_hints.Hints()
hints.add_filter('name', self.role_name)
role = self.role_manager.list_roles(hints)
self.role_id = role[0]['id']
# NOTE(morganfainberg): Handle the case that the role assignment has
# already occured.

View File

@ -22,6 +22,7 @@ from six.moves import range
from keystone.cmd import cli
from keystone.common import dependency
from keystone.common.sql import migration_helpers
from keystone.i18n import _
from keystone import resource
from keystone.tests import unit
@ -102,12 +103,54 @@ class CliBootStrapTestCaseWithEnvironment(CliBootStrapTestCase):
def setUp(self):
super(CliBootStrapTestCaseWithEnvironment, self).setUp()
self.password = uuid.uuid4().hex
self.username = uuid.uuid4().hex
self.project_name = uuid.uuid4().hex
self.role_name = uuid.uuid4().hex
self.default_domain = migration_helpers.get_default_domain()
self.useFixture(
fixtures.EnvironmentVariable('OS_BOOTSTRAP_PASSWORD',
newvalue=uuid.uuid4().hex))
newvalue=self.password))
self.useFixture(
fixtures.EnvironmentVariable('OS_BOOTSTRAP_USERNAME',
newvalue=uuid.uuid4().hex))
newvalue=self.username))
self.useFixture(
fixtures.EnvironmentVariable('OS_BOOTSTRAP_PROJECT_NAME',
newvalue=self.project_name))
self.useFixture(
fixtures.EnvironmentVariable('OS_BOOTSTRAP_ROLE_NAME',
newvalue=self.role_name))
def test_assignment_created_with_user_exists(self):
# test assignment can be created if user already exists.
bootstrap = cli.BootStrap()
bootstrap.resource_manager.create_domain(self.default_domain['id'],
self.default_domain)
user_ref = unit.new_user_ref(self.default_domain['id'],
name=self.username,
password=self.password)
bootstrap.identity_manager.create_user(user_ref)
self._do_test_bootstrap(bootstrap)
def test_assignment_created_with_project_exists(self):
# test assignment can be created if project already exists.
bootstrap = cli.BootStrap()
bootstrap.resource_manager.create_domain(self.default_domain['id'],
self.default_domain)
project_ref = unit.new_project_ref(self.default_domain['id'],
name=self.project_name)
bootstrap.resource_manager.create_project(project_ref['id'],
project_ref)
self._do_test_bootstrap(bootstrap)
def test_assignment_created_with_role_exists(self):
# test assignment can be created if role already exists.
bootstrap = cli.BootStrap()
bootstrap.resource_manager.create_domain(self.default_domain['id'],
self.default_domain)
role = unit.new_role_ref(name=self.role_name)
bootstrap.role_manager.create_role(role['id'], role)
self._do_test_bootstrap(bootstrap)
class CliDomainConfigAllTestCase(unit.SQLDriverOverrides, unit.TestCase):