summaryrefslogtreecommitdiffstats
path: root/doctor_tests
diff options
context:
space:
mode:
Diffstat (limited to 'doctor_tests')
-rw-r--r--doctor_tests/identity_auth.py4
-rw-r--r--doctor_tests/inspector/vitrage.py3
-rw-r--r--doctor_tests/os_clients.py8
-rw-r--r--doctor_tests/user.py70
4 files changed, 58 insertions, 27 deletions
diff --git a/doctor_tests/identity_auth.py b/doctor_tests/identity_auth.py
index 2586720c..eb046986 100644
--- a/doctor_tests/identity_auth.py
+++ b/doctor_tests/identity_auth.py
@@ -16,11 +16,11 @@ def get_identity_auth(username=None, password=None, project=None):
auth_url = os.environ['OS_AUTH_URL']
username = username or os.environ['OS_USERNAME']
password = password or os.environ['OS_PASSWORD']
- user_domain_name = os.environ.get('OS_USER_DOMAIN_NAME') or 'default'
+ user_domain_name = os.environ.get('OS_USER_DOMAIN_NAME') or 'Default'
user_domain_id = os.environ.get('OS_USER_DOMAIN_ID') or 'default'
project_name = project or os.environ.get('OS_PROJECT_NAME') \
or os.environ.get('OS_TENANT_NAME')
- project_domain_name = os.environ.get('OS_PROJECT_DOMAIN_NAME') or 'default'
+ project_domain_name = os.environ.get('OS_PROJECT_DOMAIN_NAME') or 'Default'
project_domain_id = os.environ.get('OS_PROJECT_DOMAIN_ID') or 'default'
loader = loading.get_plugin_loader('password')
diff --git a/doctor_tests/inspector/vitrage.py b/doctor_tests/inspector/vitrage.py
index 7d1dbc1c..0452d9b1 100644
--- a/doctor_tests/inspector/vitrage.py
+++ b/doctor_tests/inspector/vitrage.py
@@ -19,7 +19,8 @@ class VitrageInspector(BaseInspector):
def __init__(self, conf, log):
super(VitrageInspector, self).__init__(conf, log)
self.auth = get_identity_auth()
- self.keystone = keystone_client(get_session(auth=self.auth))
+ self.keystone = keystone_client(self.conf.keystone_version,
+ get_session(auth=self.auth))
self.vitrage = vitrage_client(self.conf.vitrage_version,
get_session(auth=self.auth))
self.inspector_url = self.get_inspector_url()
diff --git a/doctor_tests/os_clients.py b/doctor_tests/os_clients.py
index 5606d40a..640281df 100644
--- a/doctor_tests/os_clients.py
+++ b/doctor_tests/os_clients.py
@@ -11,7 +11,7 @@ from oslo_config import cfg
import aodhclient.client as aodhclient
from congressclient.v1 import client as congressclient
import glanceclient.client as glanceclient
-from keystoneclient.v2_0 import client as ks_client
+from keystoneclient import client as ks_client
from neutronclient.v2_0 import client as neutronclient
import novaclient.client as novaclient
import vitrageclient.client as vitrageclient
@@ -22,6 +22,7 @@ OPTS = [
cfg.StrOpt('nova_version', default='2.34', help='Nova version'),
cfg.StrOpt('aodh_version', default='2', help='aodh version'),
cfg.StrOpt('vitrage_version', default='1', help='vitrage version'),
+ cfg.StrOpt('keystone_version', default='v3', help='keystone version'),
]
@@ -30,8 +31,9 @@ def glance_client(version, session):
session=session)
-def keystone_client(session):
- return ks_client.Client(session=session)
+def keystone_client(version, session):
+ return ks_client.Client(version=version,
+ session=session)
def nova_client(version, session):
diff --git a/doctor_tests/user.py b/doctor_tests/user.py
index 33f995e7..5598a2d5 100644
--- a/doctor_tests/user.py
+++ b/doctor_tests/user.py
@@ -32,6 +32,10 @@ OPTS = [
default='_member_',
help='the role of test user',
required=True),
+ cfg.StrOpt('doctor_domain_id',
+ default=os.environ.get('OS_PROJECT_DOMAIN_ID', 'default'),
+ help='the domain id of the doctor project',
+ required=True),
cfg.IntOpt('quota_instances',
default=os.environ.get('VM_COUNT', 1),
help='the quota of instances in test user',
@@ -48,13 +52,14 @@ class User(object):
def __init__(self, conf, log):
self.conf = conf
self.log = log
- self.keystone = \
- keystone_client(get_session())
+ self.keystone = keystone_client(
+ self.conf.keystone_version, get_session())
self.nova = \
nova_client(conf.nova_version, get_session())
self.users = {}
self.projects = {}
self.roles = {}
+ self.use_exist_role = False
self.roles_for_user = {}
self.roles_for_admin = {}
@@ -72,33 +77,54 @@ class User(object):
def _create_project(self):
"""create test project"""
- self.projects = {project.name: project
- for project in self.keystone.tenants.list()}
+ self.projects = {project.name: project for project in
+ self.keystone.projects.list(
+ domain=self.conf.doctor_domain_id)}
if self.conf.doctor_project not in self.projects:
+ self.log.info('create project......')
test_project = \
- self.keystone.tenants.create(self.conf.doctor_project)
+ self.keystone.projects.create(
+ self.conf.doctor_project,
+ self.conf.doctor_domain_id)
self.projects[test_project.name] = test_project
+ else:
+ self.log.info('project %s already created......' % self.conf.doctor_project)
+ self.log.info('test project %s' % str(self.projects[self.conf.doctor_project]))
def _create_user(self):
"""create test user"""
project = self.projects.get(self.conf.doctor_project)
- self.users = {user.name: user for user in self.keystone.users.list()}
+ self.users = {user.name: user for user in
+ self.keystone.users.list(
+ domain=self.conf.doctor_domain_id)}
if self.conf.doctor_user not in self.users:
+ self.log.info('create user......')
test_user = self.keystone.users.create(
self.conf.doctor_user,
password=self.conf.doctor_passwd,
- tenant_id=project.id)
+ domain=self.conf.doctor_domain_id)
self.users[test_user.name] = test_user
+ else:
+ self.log.info('user %s already created......' % self.conf.doctor_user)
+ self.log.info('test user %s' % str(self.users[self.conf.doctor_user]))
def _create_role(self):
"""create test role"""
- self.roles = {role.name: role for role in self.keystone.roles.list()}
+ self.roles = {role.name: role for role in
+ self.keystone.roles.list()}
if self.conf.doctor_role not in self.roles:
- test_role = self.keystone.roles.create(self.conf.doctor_role)
+ self.log.info('create role......')
+ test_role = self.keystone.roles.create(
+ self.conf.doctor_role)
self.roles[test_role.name] = test_role
+ else:
+ self.use_exist_role = True
+ self.log.info('role %s already created......' % self.conf.doctor_role)
+ self.log.info('test role %s' % str(self.roles[self.conf.doctor_role]))
def _add_user_role_in_project(self, is_admin=False):
"""add test user with test role in test project"""
+
project = self.projects.get(self.conf.doctor_project)
user_name = 'admin' if is_admin else self.conf.doctor_user
@@ -110,12 +136,12 @@ class User(object):
roles_for_user = self.roles_for_admin \
if is_admin else self.roles_for_user
- roles_for_user = \
- {role.name: role for role in
- self.keystone.roles.roles_for_user(user, tenant=project)}
- if role_name not in roles_for_user:
- self.keystone.roles.add_user_role(user, role, tenant=project)
+ if not self.keystone.roles.check(role, user=user, project=project):
+ self.keystone.roles.grant(role, user=user, project=project)
roles_for_user[role_name] = role
+ else:
+ self.log.info('Already grant a role:%s to user: %s on project: %s'
+ % (role_name, user_name, self.conf.doctor_project))
def delete(self):
"""delete the test user, project and role"""
@@ -127,19 +153,20 @@ class User(object):
if project:
if 'admin' in self.roles_for_admin:
- self.keystone.roles.remove_user_role(
- self.users['admin'],
+ self.keystone.roles.revoke(
self.roles['admin'],
- tenant=project)
+ user=self.users['admin'],
+ project=project)
if user:
if role and self.conf.doctor_role in self.roles_for_user:
- self.keystone.roles.remove_user_role(
- user, role, tenant=project)
- self.keystone.roles.delete(role)
+ self.keystone.roles.revoke(
+ role, user=user, project=project)
+ if not self.use_exist_role:
+ self.keystone.roles.delete(role)
self.keystone.users.delete(user)
- self.keystone.tenants.delete(project)
+ self.keystone.projects.delete(project)
self.log.info('user delete end......')
def update_quota(self):
@@ -161,3 +188,4 @@ class User(object):
self.log.info('user quota update end......')
else:
raise Exception('No project or role for update quota')
+