Always using domain id to create domain project or user
Add a function to get domain id from a domain name, and use domain id to create domain project or user. Change-Id: Ie97c179e62311406201476c0d4c43a731c48908c Partial-Bug: #1376213
This commit is contained in:
parent
c1b3eb22f7
commit
f4998edf93
|
@ -312,6 +312,21 @@ class KeystoneClientV3(object):
|
|||
#get the last 64 characters of the username
|
||||
return username[-64:]
|
||||
|
||||
def _get_domain_id_from_name(self, domain_name):
|
||||
domains = self.domain_admin_client.domains.list(name=domain_name)
|
||||
if len(domains) == 1:
|
||||
return domains[0].id
|
||||
elif len(domains) == 0:
|
||||
LOG.error(_LE("Can't find domain id for %(domain)s!"), {
|
||||
'domain': domain_name})
|
||||
raise exception.Error(_("Failed to find domain %s")
|
||||
% domain_name)
|
||||
else:
|
||||
LOG.error(_LE("Unexpected response looking for %(domain)s!"), {
|
||||
'domain': domain_name})
|
||||
raise exception.Error(_("Unexpected response looking for "
|
||||
"domain %s") % domain_name)
|
||||
|
||||
def create_stack_user(self, username, password=''):
|
||||
"""Create a user defined as part of a stack.
|
||||
|
||||
|
@ -419,7 +434,7 @@ class KeystoneClientV3(object):
|
|||
# Create user
|
||||
user = self.domain_admin_client.users.create(
|
||||
name=self._get_username(username), password=password,
|
||||
default_project=project_id, domain=self.stack_domain)
|
||||
default_project=project_id, domain=self.stack_domain_id)
|
||||
# Add to stack user role
|
||||
LOG.debug("Adding user %(user)s to role %(role)s" % {
|
||||
'user': user.id, 'role': role_id})
|
||||
|
@ -441,9 +456,8 @@ class KeystoneClientV3(object):
|
|||
if self._stack_domain_is_id:
|
||||
self._stack_domain_id = self.stack_domain
|
||||
else:
|
||||
domain = self.domain_admin_client.domains.get(
|
||||
self.stack_domain)
|
||||
self._stack_domain_id = domain.id
|
||||
domain_id = self._get_domain_id_from_name(self.stack_domain)
|
||||
self._stack_domain_id = domain_id
|
||||
return self._stack_domain_id
|
||||
|
||||
def _check_stack_domain_user(self, user_id, project_id, action):
|
||||
|
@ -489,7 +503,7 @@ class KeystoneClientV3(object):
|
|||
desc = "Heat stack user project"
|
||||
domain_project = self.domain_admin_client.projects.create(
|
||||
name=project_name,
|
||||
domain=self.stack_domain,
|
||||
domain=self.stack_domain_id,
|
||||
description=desc)
|
||||
return domain_project.id
|
||||
|
||||
|
|
|
@ -1470,7 +1470,7 @@ class KeystoneClientTest(common.HeatTestCase):
|
|||
|
||||
class KeystoneClientTestDomainName(KeystoneClientTest):
|
||||
def setUp(self):
|
||||
cfg.CONF.set_override('stack_user_domain_name', 'adomain123')
|
||||
cfg.CONF.set_override('stack_user_domain_name', 'fake_domain_name')
|
||||
super(KeystoneClientTestDomainName, self).setUp()
|
||||
cfg.CONF.clear_override('stack_user_domain_id')
|
||||
|
||||
|
@ -1480,8 +1480,8 @@ class KeystoneClientTestDomainName(KeystoneClientTest):
|
|||
def _stub_domain_admin_client_domain_get(self):
|
||||
dummy_domain = self.m.CreateMockAnything()
|
||||
dummy_domain.id = 'adomain123'
|
||||
self.mock_ks_v3_client_domain_mngr.get('adomain123').AndReturn(
|
||||
dummy_domain)
|
||||
self.mock_ks_v3_client_domain_mngr.list(
|
||||
name='fake_domain_name').AndReturn([dummy_domain])
|
||||
|
||||
def _stub_domain_admin_client(self, auth_ok=True):
|
||||
kc_v3.Client(
|
||||
|
@ -1492,11 +1492,11 @@ class KeystoneClientTestDomainName(KeystoneClientTest):
|
|||
insecure=False,
|
||||
key=None,
|
||||
password='adminsecret',
|
||||
user_domain_name='adomain123',
|
||||
user_domain_name='fake_domain_name',
|
||||
username='adminuser123').AndReturn(self.mock_admin_client)
|
||||
self.mock_admin_client.domains = self.mock_ks_v3_client_domain_mngr
|
||||
self.mock_admin_client.authenticate(
|
||||
domain_name='adomain123').AndReturn(auth_ok)
|
||||
domain_name='fake_domain_name').AndReturn(auth_ok)
|
||||
if auth_ok:
|
||||
self.mock_admin_client.auth_ref = self.m.CreateMockAnything()
|
||||
self.mock_admin_client.auth_ref.user_id = '1234'
|
||||
|
@ -1507,7 +1507,7 @@ class KeystoneClientTestDomainName(KeystoneClientTest):
|
|||
username='duser',
|
||||
password='apassw',
|
||||
project_id='aproject',
|
||||
user_domain_name='adomain123'
|
||||
user_domain_name='fake_domain_name'
|
||||
).AndReturn('dummyauth')
|
||||
|
||||
def test_enable_stack_domain_user_error_project(self):
|
||||
|
@ -1584,3 +1584,13 @@ class KeystoneClientTestDomainName(KeystoneClientTest):
|
|||
self._stub_domain_admin_client_domain_get()
|
||||
p = super(KeystoneClientTestDomainName, self)
|
||||
p.test_delete_stack_domain_project_wrongdomain()
|
||||
|
||||
def test_create_stack_domain_project(self):
|
||||
self._stub_domain_admin_client_domain_get()
|
||||
p = super(KeystoneClientTestDomainName, self)
|
||||
p.test_create_stack_domain_project()
|
||||
|
||||
def test_create_stack_domain_user(self):
|
||||
self._stub_domain_admin_client_domain_get()
|
||||
p = super(KeystoneClientTestDomainName, self)
|
||||
p.test_create_stack_domain_user()
|
||||
|
|
Loading…
Reference in New Issue