Replace tenant by project, part 1

Replace use of tenant when it's setting to or reading from
tempest.conf (conf object).
The change is needed for correct reading of that value in
dependent patches - need to count on that it's project not
tenant anymore.

Change-Id: Ic2987ce322a0cd4a92d35b06a86aec95226f981e
Story: 2002116
Task: 19795
This commit is contained in:
Martin Kopec 2018-06-06 21:53:42 +00:00
parent 154fe8878d
commit 283de20574
13 changed files with 47 additions and 45 deletions

View File

@ -174,7 +174,7 @@ class ClientManager(object):
# Set admin tenant id needed for keystone v3 tests.
if creds.admin:
tenant = self.tenants.get_project_by_name(creds.tenant_name)
conf.set('identity', 'admin_tenant_id', tenant['id'])
conf.set('identity', 'admin_project_id', tenant['id'])
def _get_default_params(self, conf):
default_params = {

View File

@ -38,13 +38,13 @@ ALL_CREDENTIALS_KEYS = {
"auth.admin_domain_name": [],
"identity.username": [],
"identity.password": [],
"identity.tenant_name": [],
"identity.project_name": [],
"identity.alt_username": [],
"identity.alt_password": [],
"identity.alt_tenant_name": [],
"identity.alt_project_name": [],
"identity.admin_username": [],
"identity.admin_password": [],
"identity.admin_tenant_name": [],
"identity.admin_project_name": [],
"identity.admin_domain_name": [],
}

View File

@ -33,7 +33,7 @@ class Credentials(object):
self._conf = conf
self.username = self.get_credential('username')
self.password = self.get_credential('password')
self.tenant_name = self.get_credential('tenant_name')
self.tenant_name = self.get_credential('project_name')
self.identity_version = self._get_identity_version()
self.api_version = 3 if self.identity_version == "v3" else 2
self.identity_region = self._conf.get_defaulted('identity', 'region')
@ -61,17 +61,13 @@ class Credentials(object):
The function is providing the backwards compatibility for looking up
the credentials, because admin credentials were moved from identity
to auth section and admin_tenant_name was renamed to
admin_project_name.
to auth section.
:param key: name of the credential e.g. username, passsword ...
:type key: string
:returns: credential
:rtype: string
"""
if key == 'admin_tenant_name':
value = self._conf.get_defaulted('auth', 'admin_project_name')
else:
value = self._conf.get_defaulted('auth', key)
value = self._conf.get_defaulted('auth', key)
if value is None:
return self._conf.get_defaulted('identity', key)
return value
@ -103,7 +99,7 @@ class Credentials(object):
'domain_name': 'Default',
'user_domain_name': 'Default'})
else:
creds_kwargs.update({'tenant_name': self.tenant_name})
creds_kwargs.update({'project_name': self.tenant_name})
return creds_kwargs
def set_credentials(self):

View File

@ -78,10 +78,10 @@ def load_basic_defaults(conf):
"identity": [
("username", "demo"),
("password", "secrete"),
("tenant_name", "demo"),
("project_name", "demo"),
("alt_username", "alt_demo"),
("alt_password", "secrete"),
("alt_tenant_name", "alt_demo")
("alt_project_name", "alt_demo")
],
"scenario": [
("img_dir", "etc")
@ -167,7 +167,7 @@ def set_options(conf, deployer_input, non_admin, overrides=[],
conf.set("identity", "admin_username", "")
# To maintain backward compatibility
# renamed as admin_project_name in auth section
conf.set("identity", "admin_tenant_name", "")
conf.set("identity", "admin_project_name", "")
# To maintain backward compatibility
# Moved to auth
conf.set("identity", "admin_password", "")
@ -327,13 +327,13 @@ def set_cloud_config_values(non_admin, cloud_creds, conf):
if non_admin:
conf.set('identity', 'username', cloud_creds['username'])
conf.set('identity',
'tenant_name',
'project_name',
cloud_creds['project_name'])
conf.set('identity', 'password', cloud_creds['password'])
else:
conf.set('identity', 'admin_username', cloud_creds['username'])
conf.set('identity',
'admin_tenant_name',
'admin_project_name',
cloud_creds['project_name'])
conf.set('identity', 'admin_password', cloud_creds['password'])
conf.set('identity', 'uri', cloud_creds['auth_url'])

View File

@ -35,13 +35,13 @@ class BaseConfigTempestTest(base.BaseTestCase):
uri = "http://172.16.52.151:5000/"
conf.set("identity", "username", "demo")
conf.set("identity", "password", "secret")
conf.set("identity", "tenant_name", "demo")
conf.set("identity", "project_name", "demo")
conf.set("identity", "disable_ssl_certificate_validation", "true")
conf.set("identity", "auth_version", "v3")
conf.set("identity", "uri", uri + V2, priority=True)
conf.set("identity", "uri_v3", uri + V3)
conf.set("identity", "admin_username", "admin")
conf.set("identity", "admin_tenant_name", "adminTenant")
conf.set("identity", "admin_project_name", "adminTenant")
conf.set("identity", "admin_password", "adminPass")
conf.set("auth", "use_dynamic_credentials", "False")
return conf
@ -52,7 +52,7 @@ class BaseConfigTempestTest(base.BaseTestCase):
uri = "http://172.16.52.151:5000/"
conf.set("identity", "username", "demo")
conf.set("identity", "password", "secret")
conf.set("identity", "tenant_name", "demo")
conf.set("identity", "project_name", "demo")
conf.set("identity", "disable_ssl_certificate_validation", "true")
conf.set("identity", "auth_version", "v3")
conf.set("identity", "uri", uri + V2, priority=True)

View File

@ -115,7 +115,7 @@ class TestClientManager(BaseConfigTempestTest):
self.useFixture(MonkeyPatch(func2mock, mock_function))
ClientManager(self.conf, self.creds)
# check if admin tenant id was set
admin_tenant_id = self.conf.get("identity", "admin_tenant_id")
admin_tenant_id = self.conf.get("identity", "admin_project_id")
self.assertEqual(admin_tenant_id, "my_fake_id")
def test_get_service_client(self):

View File

@ -37,7 +37,7 @@ class TestOsClientConfigSupport(BaseConfigTempestTest):
def _check_credentials(self, manager, username, password, tenant_name):
exp_user = manager.auth_provider.credentials._initial['username']
exp_pass = manager.auth_provider.credentials._initial['password']
exp_tenant = manager.auth_provider.credentials._initial['tenant_name']
exp_tenant = manager.auth_provider.credentials._initial['project_name']
self.assertEqual(exp_user, username)
self.assertEqual(exp_pass, password)
self.assertEqual(exp_tenant, tenant_name)
@ -75,14 +75,14 @@ class TestOsClientConfigSupport(BaseConfigTempestTest):
self.assertEqual(cloud_args['password'],
conf.get('identity', 'password'))
self.assertEqual(cloud_args['project_name'],
conf.get('identity', 'tenant_name'))
conf.get('identity', 'project_name'))
else:
self.assertEqual(cloud_args['username'],
conf.get('identity', 'admin_username'))
self.assertEqual(cloud_args['password'],
conf.get('identity', 'admin_password'))
self.assertEqual(cloud_args['project_name'],
conf.get('identity', 'admin_tenant_name'))
conf.get('identity', 'admin_project_name'))
def test_init_manager_client_config(self):
self._obtain_client_config_data(True)
@ -100,7 +100,7 @@ class TestOsClientConfigSupport(BaseConfigTempestTest):
self._check_credentials(manager,
self.conf.get('identity', 'username'),
self.conf.get('identity', 'password'),
self.conf.get('identity', 'tenant_name'))
self.conf.get('identity', 'project_name'))
def test_init_manager_client_config_override(self):
self._override_setup()
@ -109,7 +109,7 @@ class TestOsClientConfigSupport(BaseConfigTempestTest):
self._check_credentials(manager,
self.conf.get('identity', 'username'),
self.conf.get('identity', 'password'),
self.conf.get('identity', 'tenant_name'))
self.conf.get('identity', 'project_name'))
def test_init_manager_client_config_admin_override(self):
self._override_setup()
@ -119,4 +119,5 @@ class TestOsClientConfigSupport(BaseConfigTempestTest):
self._check_credentials(manager,
self.conf.get('identity', 'admin_username'),
self.conf.get('identity', 'admin_password'),
self.conf.get('identity', 'admin_tenant_name'))
self.conf.get('identity',
'admin_project_name'))

View File

@ -64,7 +64,7 @@ class TestCredentials(BaseConfigTempestTest):
expected_resp = {
'username': 'demo',
'password': 'secret',
'tenant_name': 'demo'
'project_name': 'demo'
}
self.assertEqual(self.creds._get_creds_kwargs(), expected_resp)
self.creds.identity_version = 'v3'
@ -88,7 +88,7 @@ class TestCredentials(BaseConfigTempestTest):
mock_function.assert_called_with(
auth_url=None, fill_in=False, identity_version='v2',
disable_ssl_certificate_validation='true',
ca_certs=None, password='pass', tenant_name='Tname',
ca_certs=None, password='pass', project_name='Tname',
username='name')
def test_set_credentials_v3(self):

View File

@ -66,7 +66,7 @@ class TestTempestConf(BaseConfigTempestTest):
remove_exts = ["router", "project-id", "dvr"]
remove = {
"identity.username": ["demo"],
"identity.tenant_name": ["tenant"],
"identity.project_name": ["tenant"],
"compute.image_ssh_user": ["rhel", "cirros"],
"network-feature-enabled.api_extensions": remove_exts
}
@ -75,7 +75,7 @@ class TestTempestConf(BaseConfigTempestTest):
self.conf.set("network-feature-enabled", "api_extensions", api_exts)
self.conf.remove_values(remove)
self.assertFalse(self.conf.has_option("identity", "username"))
self.assertTrue(self.conf.has_option("identity", "tenant_name"))
self.assertTrue(self.conf.has_option("identity", "project_name"))
self.assertFalse(self.conf.has_option("compute", "image_ssh_user"))
conf_exts = self.conf.get("network-feature-enabled", "api_extensions")
conf_exts = conf_exts.split(',')

View File

@ -59,7 +59,7 @@ class TestUsers(BaseConfigTempestTest):
alt_tenant_name = "my_tenant"
self.conf.set("identity", "alt_username", alt_username)
self.conf.set("identity", "alt_password", alt_password)
self.conf.set("identity", "alt_tenant_name", alt_tenant_name)
self.conf.set("identity", "alt_project_name", alt_tenant_name)
self.Service.create_tempest_users(orchestration)
if orchestration:
self.assertEqual(mock_give_role_to_user.mock_calls, [
@ -78,10 +78,10 @@ class TestUsers(BaseConfigTempestTest):
self.assertEqual(mock_create_user_with_tenant.mock_calls, [
mock.call(self.conf.get('identity', 'username'),
self.conf.get('identity', 'password'),
self.conf.get('identity', 'tenant_name')),
self.conf.get('identity', 'project_name')),
mock.call(self.conf.get('identity', 'alt_username'),
self.conf.get('identity', 'alt_password'),
self.conf.get('identity', 'alt_tenant_name')),
self.conf.get('identity', 'alt_project_name')),
])
def test_create_tempest_user(self):
@ -206,14 +206,14 @@ class TestUsers(BaseConfigTempestTest):
mock_get_project_by_name):
mock_get_project_by_name.return_value = \
{'id': "fake_tenant_id"}
{'id': "fake_project_id"}
mock_list_users.return_value = self.users
mock_list_roles.return_value = self.roles
self.Service.give_role_to_user(
username=self.username,
role_name=self.role_name)
mock_create_user_role_on_project.assert_called_with(
"fake_tenant_id", "fake_user_id", "fake_role_id")
"fake_project_id", "fake_user_id", "fake_role_id")
@mock.patch('config_tempest.clients.ProjectsClient.'
'get_project_by_name')
@ -234,7 +234,7 @@ class TestUsers(BaseConfigTempestTest):
mock_get_project_by_name):
role_name = "fake_role_that_does_not_exist"
mock_get_project_by_name.return_value = \
{'id': "fake_tenant_id"}
{'id': "fake_project_id"}
mock_list_users.return_value = self.users
mock_list_roles.return_value = self.roles
exc = Exception
@ -262,7 +262,7 @@ class TestUsers(BaseConfigTempestTest):
mock_get_project_by_name):
mock_get_project_by_name.return_value = \
{'id': "fake_tenant_id"}
{'id': "fake_project_id"}
mock_list_users.return_value = self.users
mock_list_roles.return_value = self.roles
self.Service.give_role_to_user(
@ -289,7 +289,7 @@ class TestUsers(BaseConfigTempestTest):
mock_get_project_by_name):
exc = exceptions.Conflict
mock_create_user_role_on_project.side_effect = exc
mock_get_project_by_name.return_value = {'id': "fake_tenant_id"}
mock_get_project_by_name.return_value = {'id': "fake_project_id"}
mock_list_users.return_value = self.users
mock_list_roles.return_value = self.roles
self.Service.give_role_to_user(

View File

@ -39,11 +39,11 @@ class Users(object):
sec = 'identity'
self.create_user_with_tenant(self._conf.get(sec, 'username'),
self._conf.get(sec, 'password'),
self._conf.get(sec, 'tenant_name'))
self._conf.get(sec, 'project_name'))
self.create_user_with_tenant(self._conf.get(sec, 'alt_username'),
self._conf.get(sec, 'alt_password'),
self._conf.get(sec, 'alt_tenant_name'))
self._conf.get(sec, 'alt_project_name'))
username = self._conf.get_defaulted('auth', 'admin_username')
if username is None:
@ -67,7 +67,7 @@ class Users(object):
:type role_name: string
:type role_required: boolean
"""
tenant_name = self._conf.get('identity', 'tenant_name')
tenant_name = self._conf.get('identity', 'project_name')
tenant_id = self.tenants_client.get_project_by_name(tenant_name)['id']
users = self.users_client.list_users()
user_ids = [u['id'] for u in users['users'] if u['name'] == username]

View File

@ -37,7 +37,7 @@ admin_domain_name=Default
username=demo
# Tenant name to use for Nova API requests. (string value)
tenant_name=demo
project_name=demo
# API key to use when authenticating. (string value)
password=secrete
@ -48,7 +48,7 @@ alt_username=alt_demo
# Alternate user's Tenant name to use for Nova API requests.
# (string value)
alt_tenant_name=alt_demo
alt_project_name=alt_demo
# API key to use when authenticating as alternate user.
# (string value)
@ -64,7 +64,7 @@ admin_username=admin
# (string value)
# Parameter moved to auth section as admin_project_name. Would
# be deprecated in future releases
admin_tenant_name=admin
admin_project_name=admin
admin_domain_name=Default

View File

@ -0,0 +1,5 @@
---
other:
- |
Use of 'tenant' wherever it's set to tempest.conf, is replaced
by 'project'. This is part 1 of the tenant->project transition.