Merge "Replace tenant by project, part 2"

This commit is contained in:
Zuul 2018-06-27 12:44:52 +00:00 committed by Gerrit Code Review
commit ab4e518bab
12 changed files with 82 additions and 80 deletions

View File

@ -64,7 +64,7 @@ class ProjectsClient(object):
if project['name'] == project_name:
return project
raise exceptions.NotFound(
'No such tenant/project (%s) in %s' % (project_name, projects))
'No such project/tenant (%s) in %s' % (project_name, projects))
def create_project(self, name, description):
if self.identity_version == "v2":
@ -99,7 +99,7 @@ class ClientManager(object):
catalog_type,
default_params)
self.tenants = ProjectsClient(
self.projects = ProjectsClient(
self.auth_provider,
conf.get_defaulted('identity', 'catalog_type'),
self.identity_region,
@ -178,10 +178,10 @@ class ClientManager(object):
self.get_nova_net_client = create_nova_network_client
self.get_neutron_client = create_neutron_client
# Set admin tenant id needed for keystone v3 tests.
# Set admin project id needed for keystone v3 tests.
if creds.admin:
tenant = self.tenants.get_project_by_name(creds.tenant_name)
conf.set('auth', 'admin_project_id', tenant['id'])
project = self.projects.get_project_by_name(creds.project_name)
conf.set('auth', 'admin_project_id', project['id'])
def _get_default_params(self, conf):
default_params = {

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('project_name')
self.project_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')
@ -85,11 +85,11 @@ class Credentials(object):
creds_kwargs = {'username': self.username,
'password': self.password}
if self.identity_version == 'v3':
creds_kwargs.update({'project_name': self.tenant_name,
creds_kwargs.update({'project_name': self.project_name,
'domain_name': 'Default',
'user_domain_name': 'Default'})
else:
creds_kwargs.update({'project_name': self.tenant_name})
creds_kwargs.update({'project_name': self.project_name})
return creds_kwargs
def set_credentials(self):

View File

@ -380,7 +380,7 @@ def config_tempest(**kwargs):
services = Services(clients, conf, credentials)
if kwargs.get('create', False) and kwargs.get('test_accounts') is None:
users = Users(clients.tenants, clients.roles, clients.users, conf)
users = Users(clients.projects, clients.roles, clients.users, conf)
users.create_tempest_users(services.is_service('orchestration'))
flavors = Flavors(clients.flavors, kwargs.get('create', False), conf)
flavors.create_tempest_flavors()

View File

@ -41,7 +41,7 @@ class BaseConfigTempestTest(base.BaseTestCase):
conf.set("identity", "uri", uri + V2, priority=True)
conf.set("identity", "uri_v3", uri + V3)
conf.set("auth", "admin_username", "admin")
conf.set("auth", "admin_project_name", "adminTenant")
conf.set("auth", "admin_project_name", "adminProject")
conf.set("auth", "admin_password", "adminPass")
conf.set("auth", "use_dynamic_credentials", "False")
return conf
@ -58,7 +58,7 @@ class BaseConfigTempestTest(base.BaseTestCase):
conf.set("identity", "uri", uri + V2, priority=True)
conf.set("identity", "uri_v3", uri + V3)
conf.set("auth", "admin_username", "admin")
conf.set("auth", "admin_project_name", "adminTenant")
conf.set("auth", "admin_project_name", "adminProject")
conf.set("auth", "admin_password", "adminPass")
conf.set("auth", "use_dynamic_credentials", "True")
return conf

View File

@ -36,7 +36,7 @@ class TestAccounts(BaseConfigTempestTest):
# credentials under auth section
accounts.create_accounts_file(True, path, self.conf)
mock_write.assert_called_with(path, "admin", "adminPass",
"adminTenant")
"adminProject")
self.assertEqual(self.conf.get("auth", "test_accounts_file"),
os.path.abspath(path))

View File

@ -114,9 +114,9 @@ class TestClientManager(BaseConfigTempestTest):
'get_project_by_name')
self.useFixture(MonkeyPatch(func2mock, mock_function))
ClientManager(self.conf, self.creds)
# check if admin tenant id was set
admin_tenant_id = self.conf.get("auth", "admin_project_id")
self.assertEqual(admin_tenant_id, "my_fake_id")
# check if admin project id was set
admin_project_id = self.conf.get("auth", "admin_project_id")
self.assertEqual(admin_project_id, "my_fake_id")
def test_get_service_client(self):
resp = self.client_manager.get_service_client('image')

View File

@ -34,13 +34,14 @@ class TestOsClientConfigSupport(BaseConfigTempestTest):
super(TestOsClientConfigSupport, self).setUp()
self.conf = self._get_conf("v2.0", "v3")
def _check_credentials(self, manager, username, password, tenant_name):
def _check_credentials(self, manager, username, password, project_name):
exp_user = manager.auth_provider.credentials._initial['username']
exp_pass = manager.auth_provider.credentials._initial['password']
exp_tenant = manager.auth_provider.credentials._initial['project_name']
creds = manager.auth_provider.credentials
exp_project = creds._initial['project_name']
self.assertEqual(exp_user, username)
self.assertEqual(exp_pass, password)
self.assertEqual(exp_tenant, tenant_name)
self.assertEqual(exp_project, project_name)
@mock.patch('os_client_config.cloud_config.CloudConfig')
def _override_setup(self, mock_args):

View File

@ -71,7 +71,7 @@ class TestCredentials(BaseConfigTempestTest):
self.useFixture(MonkeyPatch(function2mock, mock_function))
self.creds.username = "name"
self.creds.password = "pass"
self.creds.tenant_name = "Tname"
self.creds.project_name = "Tname"
self.creds.set_credentials()
mock_function.assert_called_with(
auth_url=None, fill_in=False, identity_version='v2',
@ -85,7 +85,7 @@ class TestCredentials(BaseConfigTempestTest):
self.useFixture(MonkeyPatch(function2mock, mock_function))
self.creds.username = "name"
self.creds.password = "pass"
self.creds.tenant_name = "project_name"
self.creds.project_name = "project_name"
self.creds.identity_version = "v3"
self.creds.set_credentials()
mock_function.assert_called_with(

View File

@ -66,7 +66,7 @@ class TestTempestConf(BaseConfigTempestTest):
remove_exts = ["router", "project-id", "dvr"]
remove = {
"identity.username": ["demo"],
"identity.project_name": ["tenant"],
"identity.project_name": ["project"],
"compute.image_ssh_user": ["rhel", "cirros"],
"network-feature-enabled.api_extensions": remove_exts
}

View File

@ -25,15 +25,16 @@ class TestUsers(BaseConfigTempestTest):
def setUp(self):
super(TestUsers, self).setUp()
self.conf = self._get_conf("v2.0", "v3")
tenants_client = self._get_clients(self.conf).tenants
projects_client = self._get_clients(self.conf).projects
users_client = self._get_clients(self.conf).users
roles_client = self._get_clients(self.conf).roles
self.Service = Users(tenants_client, roles_client,
self.Service = Users(projects_client, roles_client,
users_client, self.conf)
self.username = "test_user"
self.password = "cryptic"
self.tenant_name = "project"
self.tenant_description = "Tenant for Tempest %s user" % self.username
self.project_name = "project"
description = "Project for Tempest %s user" % self.username
self.project_description = description
self.role_name = "fake_role"
self.email = "%s@test.com" % self.username
self.users = {'users':
@ -48,18 +49,18 @@ class TestUsers(BaseConfigTempestTest):
'id': "fake_role_id2"}]}
@mock.patch('config_tempest.users.Users.'
'create_user_with_tenant')
'create_user_with_project')
@mock.patch('config_tempest.users.Users.give_role_to_user')
def _test_create_tempest_user(self,
mock_give_role_to_user,
mock_create_user_with_tenant,
mock_create_user_with_project,
orchestration=False):
alt_username = "my_user"
alt_password = "my_pass"
alt_tenant_name = "my_tenant"
alt_project_name = "my_project"
self.conf.set("identity", "alt_username", alt_username)
self.conf.set("identity", "alt_password", alt_password)
self.conf.set("identity", "alt_project_name", alt_tenant_name)
self.conf.set("identity", "alt_project_name", alt_project_name)
self.Service.create_tempest_users(orchestration)
if orchestration:
self.assertEqual(mock_give_role_to_user.mock_calls, [
@ -75,7 +76,7 @@ class TestUsers(BaseConfigTempestTest):
mock_give_role_to_user.assert_called_with(
self.conf.get('auth', 'admin_username'),
role_name='admin')
self.assertEqual(mock_create_user_with_tenant.mock_calls, [
self.assertEqual(mock_create_user_with_project.mock_calls, [
mock.call(self.conf.get('identity', 'username'),
self.conf.get('identity', 'password'),
self.conf.get('identity', 'project_name')),
@ -95,17 +96,17 @@ class TestUsers(BaseConfigTempestTest):
@mock.patch('config_tempest.clients.ProjectsClient.create_project')
@mock.patch('tempest.lib.services.identity.v2.users_client.'
'UsersClient.create_user')
def test_create_user_with_tenant(self,
mock_create_user,
mock_create_project,
mock_get_project_by_name):
def test_create_user_with_project(self,
mock_create_user,
mock_create_project,
mock_get_project_by_name):
mock_get_project_by_name.return_value = {'id': "fake-id"}
self.Service.create_user_with_tenant(
self.Service.create_user_with_project(
username=self.username,
password=self.password,
tenant_name=self.tenant_name)
project_name=self.project_name)
mock_create_project.assert_called_with(
name=self.tenant_name, description=self.tenant_description)
name=self.project_name, description=self.project_description)
mock_create_user.assert_called_with(name=self.username,
password=self.password,
tenantId="fake-id",
@ -116,7 +117,7 @@ class TestUsers(BaseConfigTempestTest):
@mock.patch('config_tempest.clients.ProjectsClient.create_project')
@mock.patch('tempest.lib.services.identity.v2'
'.users_client.UsersClient.create_user')
def test_create_user_with_tenant_tenant_exists(
def test_create_user_with_project_project_exists(
self,
mock_create_user,
mock_create_project,
@ -124,12 +125,12 @@ class TestUsers(BaseConfigTempestTest):
mock_get_project_by_name.return_value = {'id': "fake-id"}
exc = exceptions.Conflict
mock_create_project.side_effect = exc
self.Service.create_user_with_tenant(
self.Service.create_user_with_project(
username=self.username,
password=self.password,
tenant_name=self.tenant_name)
project_name=self.project_name)
mock_create_project.assert_called_with(
name=self.tenant_name, description=self.tenant_description)
name=self.project_name, description=self.project_description)
mock_create_user.assert_called_with(
name=self.username,
password=self.password,
@ -143,8 +144,8 @@ class TestUsers(BaseConfigTempestTest):
'tenants_client.TenantsClient.create_tenant')
@mock.patch('tempest.lib.services.identity.'
'v2.users_client.UsersClient.create_user')
def test_create_user_with_tenant_user_exists(
self, mock_create_user, mock_create_tenant,
def test_create_user_with_project_user_exists(
self, mock_create_user, mock_create_project,
mock_get_project_by_name,
mock_get_user_by_username):
mock_get_project_by_name.return_value = {'id': "fake-id"}
@ -152,11 +153,11 @@ class TestUsers(BaseConfigTempestTest):
mock_create_user.side_effect = exc
fake_user = {'id': "fake_user_id"}
mock_get_user_by_username.return_value = fake_user
self.Service.create_user_with_tenant(
self.Service.create_user_with_project(
username=self.username, password=self.password,
tenant_name=self.tenant_name)
mock_create_tenant.assert_called_with(
name=self.tenant_name, description=self.tenant_description)
project_name=self.project_name)
mock_create_project.assert_called_with(
name=self.project_name, description=self.project_description)
mock_create_user.assert_called_with(name=self.username,
password=self.password,
tenantId="fake-id",
@ -168,7 +169,7 @@ class TestUsers(BaseConfigTempestTest):
@mock.patch('config_tempest.clients.ProjectsClient.create_project')
@mock.patch('tempest.lib.services.identity.v2.'
'users_client.UsersClient.create_user')
def test_create_user_with_tenant_exists_user_exists(
def test_create_user_with_project_exists_user_exists(
self, mock_create_user, mock_create_project,
mock_get_project_by_name,
mock_get_user_by_username):
@ -178,11 +179,11 @@ class TestUsers(BaseConfigTempestTest):
mock_create_user.side_effect = exc
fake_user = {'id': "fake_user_id"}
mock_get_user_by_username.return_value = fake_user
self.Service.create_user_with_tenant(username=self.username,
password=self.password,
tenant_name=self.tenant_name)
self.Service.create_user_with_project(username=self.username,
password=self.password,
project_name=self.project_name)
mock_create_project.assert_called_with(
name=self.tenant_name, description=self.tenant_description)
name=self.project_name, description=self.project_description)
mock_create_user.assert_called_with(name=self.username,
password=self.password,
tenantId="fake-id",

View File

@ -18,15 +18,15 @@ from tempest.lib import exceptions
class Users(object):
def __init__(self, tenants_client, roles_client, users_client, conf):
def __init__(self, projects_client, roles_client, users_client, conf):
"""Init.
:type tenants_client: ProjectsClient object
:type projects_client: ProjectsClient object
:type roles_client: RolesClient object from tempest lib
:type users_client: UsersClient object from tempest lib
:type conf: TempestConf object
"""
self.tenants_client = tenants_client
self.projects_client = projects_client
self.roles_client = roles_client
self.users_client = users_client
self._conf = conf
@ -37,13 +37,13 @@ class Users(object):
:type orchestration: boolean
"""
sec = 'identity'
self.create_user_with_tenant(self._conf.get(sec, 'username'),
self._conf.get(sec, 'password'),
self._conf.get(sec, 'project_name'))
self.create_user_with_project(self._conf.get(sec, 'username'),
self._conf.get(sec, 'password'),
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_project_name'))
self.create_user_with_project(self._conf.get(sec, 'alt_username'),
self._conf.get(sec, 'alt_password'),
self._conf.get(sec, 'alt_project_name'))
username = self._conf.get_defaulted('auth', 'admin_username')
@ -59,14 +59,14 @@ class Users(object):
def give_role_to_user(self, username, role_name,
role_required=True):
"""Give the user a role in the project (tenant).
"""Give the user a role in the project.
:type username: string
:type role_name: string
:type role_required: boolean
"""
tenant_name = self._conf.get('identity', 'project_name')
tenant_id = self.tenants_client.get_project_by_name(tenant_name)['id']
project_name = self._conf.get('identity', 'project_name')
proj_id = self.projects_client.get_project_by_name(project_name)['id']
users = self.users_client.list_users()
user_ids = [u['id'] for u in users['users'] if u['name'] == username]
user_id = user_ids[0]
@ -79,36 +79,36 @@ class Users(object):
return
role_id = role_ids[0]
try:
self.roles_client.create_user_role_on_project(tenant_id, user_id,
self.roles_client.create_user_role_on_project(proj_id, user_id,
role_id)
LOG.debug("User '%s' was given the '%s' role in project '%s'",
username, role_name, tenant_name)
username, role_name, project_name)
except exceptions.Conflict:
LOG.debug("(no change) User '%s' already has the '%s' role in"
" project '%s'", username, role_name, tenant_name)
" project '%s'", username, role_name, project_name)
def create_user_with_tenant(self, username, password, tenant_name):
"""Create a user and a tenant if it doesn't exist.
def create_user_with_project(self, username, password, project_name):
"""Create a user and a project if it doesn't exist.
:type username: string
:type password: string
:type tenant_name: string
:type project_name: string
"""
LOG.info("Creating user '%s' with tenant '%s' and password '%s'",
username, tenant_name, password)
tenant_description = "Tenant for Tempest %s user" % username
LOG.info("Creating user '%s' with project '%s' and password '%s'",
username, project_name, password)
project_description = "Project for Tempest %s user" % username
email = "%s@test.com" % username
# create a tenant
# create a project
try:
self.tenants_client.create_project(name=tenant_name,
description=tenant_description)
self.projects_client.create_project(
name=project_name, description=project_description)
except exceptions.Conflict:
LOG.info("(no change) Tenant '%s' already exists", tenant_name)
LOG.info("(no change) Project '%s' already exists", project_name)
tenant_id = self.tenants_client.get_project_by_name(tenant_name)['id']
proj_id = self.projects_client.get_project_by_name(project_name)['id']
params = {'name': username, 'password': password,
'tenantId': tenant_id, 'email': email}
'tenantId': proj_id, 'email': email}
# create a user
try:
self.users_client.create_user(**params)

View File

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