Make create_user domain-aware for V3CredsClient

Currently create_user is just inherited from CredsClient and, therefore,
does not pass a domain_id to the /v3/users POST API call to create a new
user. As a result a domain with id "default" is used as no domain is
explicitly passed in the API call which results in 404 NOT FOUND and the
following error: "Could not find domain: default.".

The right way is passing a domain from:

1) CONF.auth.admin_domain_name
2) CONF.auth.default_credentials_domain_name

This is already taken into account when a domain_name is passed from
identity_utils during object instantiation and used for in the
create_project method specific to V3CredsClient. The API calls only
accept a domain_id which is why creds_domain field of a V3CredsClient
object is used to store an id of a domain_name domain passed via
constructor. The same can be used for create_user method specific to v3.

Change-Id: I66f22c61d7a8596cafdc415654edfecdc5495d2e
Closes-Bug: #1613819
This commit is contained in:
Dmitrii Shcherbakov 2019-03-09 05:44:01 +03:00 committed by Lukas Piwowarski
parent 06374e2dfd
commit 1ce92bf34d
3 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,9 @@
---
fixes:
- |
[`bug 1613819 <https://bugs.launchpad.net/tempest/+bug/1613819>`_]
admin_domain_name and default_credentials_domain_name parameters
under [auth] now affect a domain used for creating test users just
as they affect it for projects. Previously a domain with an id set
to "default" had to be present in order for test user creation to
succeed with Keystone v3.

View File

@ -173,6 +173,22 @@ class V3CredsClient(CredsClient):
self.domains_client.update_domain(domain_id, enabled=False)
self.domains_client.delete_domain(domain_id)
def create_user(self, username, password, project=None, email=None,
domain_id=None):
params = {'name': username,
'password': password,
'domain_id': domain_id or self.creds_domain['id']}
# with keystone v3, a default project is not required
if project:
params[self.project_id_param] = project['id']
# email is not a first-class attribute of a user
if email:
params['email'] = email
user = self.users_client.create_user(**params)
if 'user' in user:
user = user['user']
return user
def get_credentials(
self, user, project, password, domain=None, system=None):
# User, project and domain already include both ID and name here,

View File

@ -111,3 +111,21 @@ class TestCredClientV3(base.TestCase):
self.assertIsNone(ret.project_name)
self.assertEqual(ret.system, {'system': 'all'})
self.assertEqual(ret.domain_name, 'some_domain')
def test_create_user(self):
self.users_client.create_user.return_value = {
'user': 'a_user'
}
fake_project = {
'id': 'fake_project_id',
}
res = self.creds_client.create_user('fake_username',
'fake_password',
fake_project,
'fake_email')
self.assertEqual('a_user', res)
self.users_client.create_user.assert_called_once_with(
name='fake_username', password='fake_password',
project_id=fake_project['id'],
email='fake_email',
domain_id='fake_domain_id')