diff options
Diffstat (limited to 'functest/utils')
-rw-r--r-- | functest/utils/config.py | 15 | ||||
-rw-r--r-- | functest/utils/env.py | 25 | ||||
-rw-r--r-- | functest/utils/functest_constants.py | 93 | ||||
-rw-r--r-- | functest/utils/functest_logger.py | 2 | ||||
-rw-r--r-- | functest/utils/functest_utils.py | 59 | ||||
-rwxr-xr-x | functest/utils/openstack_clean.py | 16 | ||||
-rwxr-xr-x | functest/utils/openstack_snapshot.py | 9 | ||||
-rwxr-xr-x | functest/utils/openstack_utils.py | 96 |
8 files changed, 187 insertions, 128 deletions
diff --git a/functest/utils/config.py b/functest/utils/config.py index 4cee6349..84166c1d 100644 --- a/functest/utils/config.py +++ b/functest/utils/config.py @@ -11,20 +11,25 @@ class Config(object): try: with open(self.config_functest) as f: self.functest_yaml = yaml.safe_load(f) - self.parse(None, self.functest_yaml) + self._parse(None, self.functest_yaml) except: raise Exception('Parse {} failed'.format(self.config_functest)) + self._set_others() - def parse(self, attr_now, left_parametes): + def _parse(self, attr_now, left_parametes): for param_n, param_v in left_parametes.iteritems(): - attr_further = self.get_attr_further(attr_now, param_n) + attr_further = self._get_attr_further(attr_now, param_n) if not isinstance(param_v, dict): self.__setattr__(attr_further, param_v) else: - self.parse(attr_further, param_v) + self._parse(attr_further, param_v) - def get_attr_further(self, attr_now, next): + def _get_attr_further(self, attr_now, next): return attr_now if next == 'general' else ( '{}_{}'.format(attr_now, next) if attr_now else next) + def _set_others(self): + self.env_active = os.path.join(self.dir_functest_conf, "env_active") + + CONF = Config() diff --git a/functest/utils/env.py b/functest/utils/env.py index b6af767d..fa5245fb 100644 --- a/functest/utils/env.py +++ b/functest/utils/env.py @@ -1,18 +1,41 @@ import os +import re default_envs = { 'NODE_NAME': 'unknown_pod', - 'CI_DEBUG': 'true' + 'CI_DEBUG': 'true', + 'DEPLOY_SCENARIO': 'os-nosdn-nofeature-noha', + 'DEPLOY_TYPE': 'virt', + 'INSTALLER_TYPE': None, + 'INSTALLER_IP': None, + 'BUILD_TAG': None, + 'OS_ENDPOINT_TYPE': None, + 'OS_AUTH_URL': None } class Environment(object): + def __init__(self): for k, v in os.environ.iteritems(): self.__setattr__(k, v) for k, v in default_envs.iteritems(): if k not in os.environ: self.__setattr__(k, v) + self._set_ci_run() + self._set_ci_loop() + + def _set_ci_run(self): + if self.BUILD_TAG: + self.IS_CI_RUN = True + else: + self.IS_CI_RUN = False + + def _set_ci_loop(self): + if self.BUILD_TAG and re.search("daily", self.BUILD_TAG): + self.CI_LOOP = "daily" + else: + self.CI_LOOP = "weekly" ENV = Environment() diff --git a/functest/utils/functest_constants.py b/functest/utils/functest_constants.py index 2664ace1..7fb03e8a 100644 --- a/functest/utils/functest_constants.py +++ b/functest/utils/functest_constants.py @@ -7,8 +7,9 @@ # http://www.apache.org/licenses/LICENSE-2.0 # import os -import functest.utils.functest_utils as ft_utils + import functest.utils.functest_logger as ft_logger +import functest.utils.functest_utils as ft_utils logger = ft_logger.Logger("functest_constants").getLogger() @@ -60,25 +61,25 @@ def get_value(functest_config_key, env_variable): return constant -HOME = get_value('general.directories.dir_home', 'HOME') -REPOS_DIR = get_value('general.directories.dir_repos', 'REPOS_DIR') -FUNCTEST_BASE_DIR = get_value('general.directories.dir_functest', +HOME = get_value('general.dir.home', 'HOME') +REPOS_DIR = get_value('general.dir.repos', 'REPOS_DIR') +FUNCTEST_BASE_DIR = get_value('general.dir.functest', 'FUNCTEST_BASE_DIR') -FUNCTEST_REPO_DIR = get_value('general.directories.dir_repo_functest', +FUNCTEST_REPO_DIR = get_value('general.dir.repo_functest', 'FUNCTEST_REPO_DIR') -FUNCTEST_TEST_DIR = get_value('general.directories.dir_functest_test', +FUNCTEST_TEST_DIR = get_value('general.dir.functest_test', 'FUNCTEST_TEST_DIR') -FUNCTEST_CONF_DIR = get_value('general.directories.dir_functest_conf', +FUNCTEST_CONF_DIR = get_value('general.dir.functest_conf', 'FUNCTEST_CONF_DIR') -FUNCTEST_DATA_DIR = get_value('general.directories.dir_functest_data', +FUNCTEST_DATA_DIR = get_value('general.dir.functest_data', 'FUNCTEST_DATA_DIR') -FUNCTEST_RESULTS_DIR = get_value('general.directories.dir_results', +FUNCTEST_RESULTS_DIR = get_value('general.dir.results', 'FUNCTEST_RESULTS_DIR') FUNCTEST_TESTCASES_YAML = get_value('general.functest.testcases_yaml', 'FUNCTEST_TESTCASES_YAML') RALLY_DEPLOYMENT_NAME = get_value('rally.deployment_name', 'RALLY_DEPLOYMENT_NAME') -TEMPEST_REPO_DIR = get_value('general.directories.dir_repo_tempest', +TEMPEST_REPO_DIR = get_value('general.dir.repo_tempest', 'TEMPEST_REPO_DIR') ENV_FILE = os.path.join(FUNCTEST_CONF_DIR, "env_active") @@ -87,22 +88,22 @@ OPENSTACK_CREDS = get_value('general.openstack.creds', 'creds') OPENSTACK_SNAPSHOT_FILE = get_value('general.openstack.snapshot_file', 'OPENSTACK_SNAPSHOT_FILE') -DOMINO_REPO_DIR = get_value('general.directories.dir_repo_domino', +DOMINO_REPO_DIR = get_value('general.dir.repo_domino', 'DOMINO_REPO_DIR') -SDNVPN_REPO_DIR = get_value('general.directories.dir_repo_sdnvpn', +SDNVPN_REPO_DIR = get_value('general.dir.repo_sdnvpn', 'SDNVPN_REPO_DIR') -SFC_REPO_DIR = get_value('general.directories.dir_repo_sfc', +SFC_REPO_DIR = get_value('general.dir.repo_sfc', 'SFC_REPO_DIR') ONOS_SFC_IMAGE_NAME = get_value('onos_sfc.image_name', 'ONOS_SFC_IMAGE_NAME') ONOS_SFC_IMAGE_FILENAME = get_value('onos_sfc.image_file_name', 'ONOS_SFC_IMAGE_FILENAME') -ONOS_SFC_RELATIVE_PATH = get_value('general.directories.dir_onos_sfc', +ONOS_SFC_RELATIVE_PATH = get_value('general.dir.dir_onos_sfc', 'ONOS_SFC_RELATIVE_PATH') ONOS_SFC_IMAGE_BASE_URL = get_value('onos_sfc.image_base_url', 'ONOS_SFC_IMAGE_BASE_URL') -RALLY_RELATIVE_PATH = get_value('general.directories.dir_rally', +RALLY_RELATIVE_PATH = get_value('general.dir.rally', 'RALLY_RELATIVE_PATH') RALLY_PRIVATE_NET_NAME = get_value('rally.network_name', 'RALLY_PRIVATE_NET_NAME') @@ -111,7 +112,7 @@ RALLY_PRIVATE_SUBNET_NAME = get_value('rally.subnet_name', RALLY_PRIVATE_SUBNET_CIDR = get_value('rally.subnet_cidr', 'RALLY_PRIVATE_SUBNET_CIDR') RALLY_ROUTER_NAME = get_value('rally.router_name', 'RALLY_ROUTER_NAME') -RALLY_INSTALLATION_DIR = get_value('general.directories.dir_rally_inst', +RALLY_INSTALLATION_DIR = get_value('general.dir.rally_inst', 'RALLY_INSTALLATION_DIR') GLANCE_IMAGE_NAME = get_value('general.openstack.image_name', 'GLANCE_IMAGE_NAME') @@ -149,24 +150,24 @@ TEMPEST_USE_CUSTOM_IMAGES = get_value('tempest.use_custom_images', 'TEMPEST_USE_CUSTOM_IMAGES') TEMPEST_USE_CUSTOM_FLAVORS = get_value('tempest.use_custom_flavors', 'TEMPEST_USE_CUSTOM_FLAVORS') -TEMPEST_TEST_LIST_DIR = get_value('general.directories.dir_tempest_cases', +TEMPEST_TEST_LIST_DIR = get_value('general.dir.tempest_cases', 'TEMPEST_TEST_LIST_DIR') NAME_VM_1 = get_value('vping.vm_name_1', 'NAME_VM_1') NAME_VM_2 = get_value('vping.vm_name_2', 'NAME_VM_2') PING_TIMEOUT = get_value('vping.ping_timeout', 'PING_TIMEOUT') VPING__IMAGE_NAME = get_value('vping.image_name', 'VPING__IMAGE_NAME') VPING_VM_FLAVOR = get_value('vping.vm_flavor', 'VPING_VM_FLAVOR') -VPING_PRIVATE_NET_NAME = get_value('vping.vping_private_net_name', +VPING_PRIVATE_NET_NAME = get_value('vping.private_net_name', 'VPING_PRIVATE_NET_NAME') -VPING_PRIVATE_SUBNET_NAME = get_value('vping.vping_private_subnet_name', +VPING_PRIVATE_SUBNET_NAME = get_value('vping.private_subnet_name', 'VPING_PRIVATE_SUBNET_NAME') -VPING_PRIVATE_SUBNET_CIDR = get_value('vping.vping_private_subnet_cidr', +VPING_PRIVATE_SUBNET_CIDR = get_value('vping.private_subnet_cidr', 'VPING_PRIVATE_SUBNET_CIDR') -VPING_ROUTER_NAME = get_value('vping.vping_router_name', +VPING_ROUTER_NAME = get_value('vping.router_name', 'VPING_ROUTER_NAME') -VPING_SECGROUP_NAME = get_value('vping.vping_sg_name', +VPING_SECGROUP_NAME = get_value('vping.sg_name', 'VPING_SECGROUP_NAME') -VPING_SECGROUP_DESCR = get_value('vping.vping_sg_descr', +VPING_SECGROUP_DESCR = get_value('vping.sg_desc', 'VPING_SECGROUP_DESCR') ONOSBENCH_USERNAME = get_value('ONOS.general.onosbench_username', 'ONOSBENCH_USERNAME') @@ -192,7 +193,7 @@ ONOS_INSTALLER_MASTER_USERNAME = get_value( ONOS_INSTALLER_MASTER_PASSWORD = get_value( 'ONOS.environment.installer_master_password', 'ONOS_INSTALLER_MASTER_PASSWORD') -PROMISE_REPO_DIR = get_value('general.directories.dir_repo_promise', +PROMISE_REPO_DIR = get_value('general.dir.dir_repo_promise', 'PROMISE_REPO_DIR') PROMISE_TENANT_NAME = get_value('promise.tenant_name', 'PROMISE_TENANT_NAME') @@ -217,48 +218,28 @@ PROMISE_SUBNET_CIDR = get_value('promise.subnet_cidr', 'PROMISE_SUBNET_CIDR') PROMISE_ROUTER_NAME = get_value('promise.router_name', 'PROMISE_ROUTER_NAME') -DOCTOR_REPO_DIR = get_value('general.directories.dir_repo_doctor', +DOCTOR_REPO_DIR = get_value('general.dir.dir_repo_doctor', 'DOCTOR_REPO_DIR') -COPPER_REPO_DIR = get_value('general.directories.dir_repo_copper', +COPPER_REPO_DIR = get_value('general.dir.repo_copper', 'COPPER_REPO_DIR') -EXAMPLE_INSTANCE_NAME = get_value('example.example_vm_name', +EXAMPLE_INSTANCE_NAME = get_value('example.vm_name', 'EXAMPLE_INSTANCE_NAME') -EXAMPLE_FLAVOR = get_value('example.example_flavor', 'EXAMPLE_FLAVOR') -EXAMPLE_IMAGE_NAME = get_value('example.example_image_name', +EXAMPLE_FLAVOR = get_value('example.flavor', 'EXAMPLE_FLAVOR') +EXAMPLE_IMAGE_NAME = get_value('example.image_name', 'EXAMPLE_IMAGE_NAME') -EXAMPLE_PRIVATE_NET_NAME = get_value('example.example_private_net_name', +EXAMPLE_PRIVATE_NET_NAME = get_value('example.private_net_name', 'EXAMPLE_PRIVATE_NET_NAME') EXAMPLE_PRIVATE_SUBNET_NAME = get_value( - 'example.example_private_subnet_name', + 'example.private_subnet_name', 'EXAMPLE_PRIVATE_SUBNET_NAME') EXAMPLE_PRIVATE_SUBNET_CIDR = get_value( - 'example.example_private_subnet_cidr', + 'example.private_subnet_cidr', 'EXAMPLE_PRIVATE_SUBNET_CIDR') -EXAMPLE_ROUTER_NAME = get_value('example.example_router_name', +EXAMPLE_ROUTER_NAME = get_value('example.router_name', 'EXAMPLE_ROUTER_NAME') -EXAMPLE_SECGROUP_NAME = get_value('example.example_sg_name', +EXAMPLE_SECGROUP_NAME = get_value('example.sg_name', 'EXAMPLE_SECGROUP_NAME') -EXAMPLE_SECGROUP_DESCR = get_value('example.example_sg_descr', +EXAMPLE_SECGROUP_DESCR = get_value('example.sg_desc', 'EXAMPLE_SECGROUP_DESCR') -VIMS_DATA_DIR = get_value('general.directories.dir_vIMS_data', - 'VIMS_DATA_DIR') -VIMS_TEST_DIR = get_value('general.directories.dir_repo_vims_test', - 'VIMS_TEST_DIR') -VIMS_TENANT_NAME = get_value('vIMS.general.tenant_name', - 'VIMS_TENANT_NAME') -VIMS_TENANT_DESCRIPTION = get_value('vIMS.general.tenant_description', - 'VIMS_TENANT_DESCRIPTION') -VIMS_IMAGES = get_value('vIMS.general.images', 'VIMS_IMAGES') -CFY_MANAGER_BLUEPRINT = get_value('vIMS.cloudify.blueprint', - 'CFY_MANAGER_BLUEPRINT') -CFY_MANAGER_REQUIERMENTS = get_value('vIMS.cloudify.requierments', - 'CFY_MANAGER_REQUIERMENTS') -CFY_INPUTS = get_value('vIMS.cloudify.inputs', 'CFY_INPUTS') -CW_BLUEPRINT = get_value('vIMS.clearwater.blueprint', 'CW_BLUEPRINT') -CW_DEPLOYMENT_NAME = get_value('vIMS.clearwater.deployment-name', - 'CW_DEPLOYMENT_NAME') -CW_INPUTS = get_value('vIMS.clearwater.inputs', 'CW_INPUTS') -CW_REQUIERMENTS = get_value('vIMS.clearwater.requierments', - 'CW_REQUIERMENTS') -PARSER_REPO_DIR = get_value('general.directories.dir_repo_parser', +PARSER_REPO_DIR = get_value('general.dir.repo_parser', 'PARSER_REPO_DIR') diff --git a/functest/utils/functest_logger.py b/functest/utils/functest_logger.py index b154f563..c0fba082 100644 --- a/functest/utils/functest_logger.py +++ b/functest/utils/functest_logger.py @@ -40,8 +40,10 @@ class Logger: ch.setFormatter(formatter) if CI_DEBUG is not None and CI_DEBUG.lower() == "true": ch.setLevel(logging.DEBUG) + self.logger.parent.level = logging.DEBUG else: ch.setLevel(logging.INFO) + self.logger.parent.level = logging.INFO self.logger.addHandler(ch) hdlr = logging.FileHandler('/home/opnfv/functest/results/functest.log') diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py index b1e4d3cd..2bf87a05 100644 --- a/functest/utils/functest_utils.py +++ b/functest/utils/functest_utils.py @@ -7,12 +7,14 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 # +import functools import json import os import re import shutil import subprocess import sys +import time import urllib2 from datetime import datetime as dt @@ -21,11 +23,10 @@ import requests import yaml from git import Repo -import time -import functools - +from functest.utils.constants import CONST import functest.utils.functest_logger as ft_logger + logger = ft_logger.Logger("functest_utils").getLogger() @@ -182,13 +183,43 @@ def logger_test_results(project, case_name, status, details): 'd': details}) +def write_results_to_file(project, case_name, start_date, + stop_date, criteria, details): + file_path = re.split(r'://', CONST.results_test_db_url)[1] + + try: + installer = os.environ['INSTALLER_TYPE'] + scenario = os.environ['DEPLOY_SCENARIO'] + pod_name = os.environ['NODE_NAME'] + except KeyError as e: + logger.error("Please set env var: " + str(e)) + return False + + test_start = dt.fromtimestamp(start_date).strftime('%Y-%m-%d %H:%M:%S') + test_stop = dt.fromtimestamp(stop_date).strftime('%Y-%m-%d %H:%M:%S') + + params = {"project_name": project, "case_name": case_name, + "pod_name": pod_name, "installer": installer, + "scenario": scenario, "criteria": criteria, + "start_date": test_start, "stop_date": test_stop, + "details": details} + try: + with open(file_path, "a+w") as outfile: + json.dump(params, outfile) + outfile.write("\n") + return True + except Exception as e: + logger.error("write result data into a file failed: %s" % e) + return False + + def push_results_to_db(project, case_name, start_date, stop_date, criteria, details): """ POST results to the Result target DB """ # Retrieve params from CI and conf - url = get_db_url() + "/results" + url = CONST.results_test_db_url + "/results" try: installer = os.environ['INSTALLER_TYPE'] @@ -321,26 +352,6 @@ def execute_command(cmd, info=False, error_msg="", return returncode -def get_deployment_dir(): - """ - Returns current Rally deployment directory - """ - deployment_name = get_functest_config('rally.deployment_name') - rally_dir = get_functest_config('general.directories.dir_rally_inst') - cmd = ("rally deployment list | awk '/" + deployment_name + - "/ {print $2}'") - p = subprocess.Popen(cmd, shell=True, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) - deployment_uuid = p.stdout.readline().rstrip() - if deployment_uuid == "": - logger.error("Rally deployment not found.") - exit(-1) - deployment_dir = (rally_dir + "/tempest/for-deployment-" + - deployment_uuid) - return deployment_dir - - def get_dict_by_test(testname): with open(get_testcases_file_dir()) as f: testcases_yaml = yaml.safe_load(f) diff --git a/functest/utils/openstack_clean.py b/functest/utils/openstack_clean.py index c08568bd..15a8f33d 100755 --- a/functest/utils/openstack_clean.py +++ b/functest/utils/openstack_clean.py @@ -23,14 +23,16 @@ # import time + +import yaml + import functest.utils.functest_logger as ft_logger import functest.utils.openstack_utils as os_utils -import yaml -import functest.utils.functest_constants as ft_constants +from functest.utils.constants import CONST logger = ft_logger.Logger("openstack_clean").getLogger() -OS_SNAPSHOT_FILE = ft_constants.OPENSTACK_SNAPSHOT_FILE +OS_SNAPSHOT_FILE = CONST.openstack_snapshot_file def separator(): @@ -395,7 +397,7 @@ def main(): default_security_groups = snapshot_yaml.get('secgroups') default_floatingips = snapshot_yaml.get('floatingips') default_users = snapshot_yaml.get('users') - # default_tenants = snapshot_yaml.get('tenants') + default_tenants = snapshot_yaml.get('tenants') if not os_utils.check_credentials(): logger.error("Please source the openrc credentials and run " @@ -416,10 +418,8 @@ def main(): separator() remove_users(keystone_client, default_users) separator() - # TODO (Helen) tenant does not exist in V3 - # need to figure our anohter general verification point - # remove_tenants(keystone_client, default_tenants) - # separator() + remove_tenants(keystone_client, default_tenants) + separator() if __name__ == '__main__': diff --git a/functest/utils/openstack_snapshot.py b/functest/utils/openstack_snapshot.py index 5b50ffa5..e64030f7 100755 --- a/functest/utils/openstack_snapshot.py +++ b/functest/utils/openstack_snapshot.py @@ -20,15 +20,16 @@ # http://www.apache.org/licenses/LICENSE-2.0 # +import yaml + import functest.utils.functest_logger as ft_logger import functest.utils.openstack_utils as os_utils -import yaml -import functest.utils.functest_constants as ft_constants +from functest.utils.constants import CONST logger = ft_logger.Logger("openstack_snapshot").getLogger() -OS_SNAPSHOT_FILE = ft_constants.OPENSTACK_SNAPSHOT_FILE +OS_SNAPSHOT_FILE = CONST.openstack_snapshot_file def separator(): @@ -149,7 +150,7 @@ def main(): snapshot.update(get_security_groups(neutron_client)) snapshot.update(get_floatinips(nova_client)) snapshot.update(get_users(keystone_client)) - # snapshot.update(get_tenants(keystone_client)) + snapshot.update(get_tenants(keystone_client)) with open(OS_SNAPSHOT_FILE, 'w+') as yaml_file: yaml_file.write(yaml.safe_dump(snapshot, default_flow_style=False)) diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py index ec784121..64f18504 100755 --- a/functest/utils/openstack_utils.py +++ b/functest/utils/openstack_utils.py @@ -52,14 +52,13 @@ def is_keystone_v3(): def get_rc_env_vars(): - keystone_v3 = is_keystone_v3() env_vars = ['OS_AUTH_URL', 'OS_USERNAME', 'OS_PASSWORD'] - if keystone_v3 is False: - env_vars.extend(['OS_TENANT_NAME']) - else: + if is_keystone_v3(): env_vars.extend(['OS_PROJECT_NAME', 'OS_USER_DOMAIN_NAME', 'OS_PROJECT_DOMAIN_NAME']) + else: + env_vars.extend(['OS_TENANT_NAME']) return env_vars @@ -86,7 +85,7 @@ def get_env_cred_dict(): return env_cred_dict -def get_credentials(): +def get_credentials(other_creds={}): """Returns a creds dictionary filled with parsed from env """ creds = {} @@ -99,6 +98,16 @@ def get_credentials(): else: creds_key = env_cred_dict.get(envvar) creds.update({creds_key: os.getenv(envvar)}) + + if 'tenant' in other_creds.keys(): + if is_keystone_v3(): + tenant = 'project_name' + else: + tenant = 'tenant_name' + other_creds[tenant] = other_creds.pop('tenant') + + creds.update(other_creds) + return creds @@ -138,9 +147,9 @@ def get_credentials_for_rally(): return rally_conf -def get_session_auth(): +def get_session_auth(other_creds={}): loader = loading.get_plugin_loader('password') - creds = get_credentials() + creds = get_credentials(other_creds) auth = loader.load_from_options(**creds) return auth @@ -152,8 +161,8 @@ def get_endpoint(service_type, endpoint_type='publicURL'): endpoint_type=endpoint_type) -def get_session(): - auth = get_session_auth() +def get_session(other_creds={}): + auth = get_session_auth(other_creds) return session.Session(auth=auth) @@ -169,8 +178,8 @@ def get_keystone_client_version(): return DEFAULT_API_VERSION -def get_keystone_client(): - sess = get_session() +def get_keystone_client(other_creds={}): + sess = get_session(other_creds) return keystoneclient.Client(get_keystone_client_version(), session=sess) @@ -183,8 +192,8 @@ def get_nova_client_version(): return DEFAULT_API_VERSION -def get_nova_client(): - sess = get_session() +def get_nova_client(other_creds={}): + sess = get_session(other_creds) return novaclient.Client(get_nova_client_version(), session=sess) @@ -197,8 +206,8 @@ def get_cinder_client_version(): return DEFAULT_API_VERSION -def get_cinder_client(): - sess = get_session() +def get_cinder_client(other_creds={}): + sess = get_session(other_creds) return cinderclient.Client(get_cinder_client_version(), session=sess) @@ -211,8 +220,8 @@ def get_neutron_client_version(): return DEFAULT_API_VERSION -def get_neutron_client(): - sess = get_session() +def get_neutron_client(other_creds={}): + sess = get_session(other_creds) return neutronclient.Client(get_neutron_client_version(), session=sess) @@ -224,8 +233,8 @@ def get_glance_client_version(): return DEFAULT_API_VERSION -def get_glance_client(): - sess = get_session() +def get_glance_client(other_creds={}): + sess = get_session(other_creds) return glanceclient.Client(get_glance_client_version(), session=sess) @@ -1244,7 +1253,10 @@ def delete_volume_type(cinder_client, volume_type): # ********************************************* def get_tenants(keystone_client): try: - tenants = keystone_client.tenants.list() + if is_keystone_v3(): + tenants = keystone_client.projects.list() + else: + tenants = keystone_client.tenants.list() return tenants except Exception, e: logger.error("Error [get_tenants(keystone_client)]: %s" % e) @@ -1261,7 +1273,7 @@ def get_users(keystone_client): def get_tenant_id(keystone_client, tenant_name): - tenants = keystone_client.tenants.list() + tenants = get_tenants(keystone_client) id = '' for t in tenants: if t.name == tenant_name: @@ -1271,7 +1283,7 @@ def get_tenant_id(keystone_client, tenant_name): def get_user_id(keystone_client, user_name): - users = keystone_client.users.list() + users = get_users(keystone_client) id = '' for u in users: if u.name == user_name: @@ -1292,9 +1304,16 @@ def get_role_id(keystone_client, role_name): def create_tenant(keystone_client, tenant_name, tenant_description): try: - tenant = keystone_client.tenants.create(tenant_name, - tenant_description, - enabled=True) + if is_keystone_v3(): + tenant = keystone_client.projects.create( + name=tenant_name, + description=tenant_description, + domain="default", + enabled=True) + else: + tenant = keystone_client.tenants.create(tenant_name, + tenant_description, + enabled=True) return tenant.id except Exception, e: logger.error("Error [create_tenant(keystone_client, '%s', '%s')]: %s" @@ -1305,9 +1324,18 @@ def create_tenant(keystone_client, tenant_name, tenant_description): def create_user(keystone_client, user_name, user_password, user_email, tenant_id): try: - user = keystone_client.users.create(user_name, user_password, - user_email, tenant_id, - enabled=True) + if is_keystone_v3(): + user = keystone_client.users.create(name=user_name, + password=user_password, + email=user_email, + project_id=tenant_id, + enabled=True) + else: + user = keystone_client.users.create(user_name, + user_password, + user_email, + tenant_id, + enabled=True) return user.id except Exception, e: logger.error("Error [create_user(keystone_client, '%s', '%s', '%s'" @@ -1318,7 +1346,12 @@ def create_user(keystone_client, user_name, user_password, def add_role_user(keystone_client, user_id, role_id, tenant_id): try: - keystone_client.roles.add_user_role(user_id, role_id, tenant_id) + if is_keystone_v3(): + keystone_client.roles.grant(role=role_id, + user=user_id, + project=tenant_id) + else: + keystone_client.roles.add_user_role(user_id, role_id, tenant_id) return True except Exception, e: logger.error("Error [add_role_user(keystone_client, '%s', '%s'" @@ -1328,7 +1361,10 @@ def add_role_user(keystone_client, user_id, role_id, tenant_id): def delete_tenant(keystone_client, tenant_id): try: - keystone_client.tenants.delete(tenant_id) + if is_keystone_v3(): + keystone_client.projects.delete(tenant_id) + else: + keystone_client.tenants.delete(tenant_id) return True except Exception, e: logger.error("Error [delete_tenant(keystone_client, '%s')]: %s" |