diff options
-rwxr-xr-x | functest/ci/config_functest.yaml | 2 | ||||
-rwxr-xr-x | functest/ci/exec_test.sh | 2 | ||||
-rwxr-xr-x | functest/opnfv_tests/openstack/rally/run_rally-cert.py | 33 | ||||
-rw-r--r-- | functest/opnfv_tests/openstack/tempest/tempest.py | 52 | ||||
-rw-r--r-- | functest/utils/functest_constants.py | 2 | ||||
-rw-r--r-- | functest/utils/functest_utils.py | 5 | ||||
-rwxr-xr-x | functest/utils/openstack_clean.py | 8 | ||||
-rwxr-xr-x | functest/utils/openstack_snapshot.py | 2 | ||||
-rwxr-xr-x | functest/utils/openstack_utils.py | 56 | ||||
-rwxr-xr-x | run_unit_tests.sh | 17 |
10 files changed, 99 insertions, 80 deletions
diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml index fb438842f..15e0d3a1a 100755 --- a/functest/ci/config_functest.yaml +++ b/functest/ci/config_functest.yaml @@ -3,7 +3,7 @@ general: # Relative to the path where the repo is cloned: vping: functest/opnfv_tests/openstack/vping dir_odl: functest/opnfv_tests/sdn/odl - dir_rally: functest/opnfv_tests/openstack/rally + rally: functest/opnfv_tests/openstack/rally tempest_cases: functest/opnfv_tests/openstack/tempest/custom_tests dir_vIMS: functest/opnfv_tests/vnf/ims dir_onos: functest/opnfv_tests/sdn/onos/teston diff --git a/functest/ci/exec_test.sh b/functest/ci/exec_test.sh index 2b4cd8b45..109de078f 100755 --- a/functest/ci/exec_test.sh +++ b/functest/ci/exec_test.sh @@ -114,7 +114,7 @@ function run_test(){ "security_scan") echo "Sourcing Credentials ${FUNCTEST_CONF_DIR}/stackrc for undercloud .." source ${FUNCTEST_CONF_DIR}/stackrc - python ${REPOS_DIR}/securityscanning/security_scan.py --config ${REPOS_DIR}/securityscanning/config.ini + python ${FUNCTEST_TEST_DIR}/security_scan/security_scan.py --config ${FUNCTEST_TEST_DIR}/security_scan/config.ini ;; "copper") python ${FUNCTEST_TEST_DIR}/features/copper.py $report diff --git a/functest/opnfv_tests/openstack/rally/run_rally-cert.py b/functest/opnfv_tests/openstack/rally/run_rally-cert.py index 6d8f01602..ec22b52d8 100755 --- a/functest/opnfv_tests/openstack/rally/run_rally-cert.py +++ b/functest/opnfv_tests/openstack/rally/run_rally-cert.py @@ -15,20 +15,20 @@ # """ tests configuration """ +import argparse import json import os import re import subprocess import time -import argparse import iniparse import yaml +from functest.utils.constants import CONST import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils import functest.utils.openstack_utils as os_utils -import functest.utils.functest_constants as ft_constants tests = ['authenticate', 'glance', 'cinder', 'heat', 'keystone', 'neutron', 'nova', 'quotas', 'requests', 'vm', 'all'] @@ -71,8 +71,7 @@ else: """ logging configuration """ logger = ft_logger.Logger("run_rally-cert").getLogger() -RALLY_DIR = os.path.join(ft_constants.FUNCTEST_REPO_DIR, - ft_constants.RALLY_RELATIVE_PATH) +RALLY_DIR = os.path.join(CONST.dir_repo_functest, CONST.dir_rally) RALLY_SCENARIO_DIR = os.path.join(RALLY_DIR, "scenario") SANITY_MODE_DIR = os.path.join(RALLY_SCENARIO_DIR, "sanity") FULL_MODE_DIR = os.path.join(RALLY_SCENARIO_DIR, "full") @@ -87,19 +86,19 @@ TENANTS_AMOUNT = 3 ITERATIONS_AMOUNT = 10 CONCURRENCY = 4 -RESULTS_DIR = os.path.join(ft_constants.FUNCTEST_RESULTS_DIR, 'rally') -TEMPEST_CONF_FILE = os.path.join(ft_constants.FUNCTEST_RESULTS_DIR, +RESULTS_DIR = os.path.join(CONST.dir_results, 'rally') +TEMPEST_CONF_FILE = os.path.join(CONST.dir_results, 'tempest/tempest.conf') -RALLY_PRIVATE_NET_NAME = ft_constants.RALLY_PRIVATE_NET_NAME -RALLY_PRIVATE_SUBNET_NAME = ft_constants.RALLY_PRIVATE_SUBNET_NAME -RALLY_PRIVATE_SUBNET_CIDR = ft_constants.RALLY_PRIVATE_SUBNET_CIDR -RALLY_ROUTER_NAME = ft_constants.RALLY_ROUTER_NAME +RALLY_PRIVATE_NET_NAME = CONST.rally_network_name +RALLY_PRIVATE_SUBNET_NAME = CONST.rally_subnet_name +RALLY_PRIVATE_SUBNET_CIDR = CONST.rally_subnet_cidr +RALLY_ROUTER_NAME = CONST.rally_router_name -GLANCE_IMAGE_NAME = ft_constants.GLANCE_IMAGE_NAME -GLANCE_IMAGE_FILENAME = ft_constants.GLANCE_IMAGE_FILENAME -GLANCE_IMAGE_FORMAT = ft_constants.GLANCE_IMAGE_FORMAT -GLANCE_IMAGE_PATH = os.path.join(ft_constants.FUNCTEST_DATA_DIR, +GLANCE_IMAGE_NAME = CONST.openstack_image_name +GLANCE_IMAGE_FILENAME = CONST.openstack_image_file_name +GLANCE_IMAGE_FORMAT = CONST.openstack_image_disk_format +GLANCE_IMAGE_PATH = os.path.join(CONST.dir_functest_data, GLANCE_IMAGE_FILENAME) CINDER_VOLUME_TYPE_NAME = "volume_test" @@ -181,7 +180,7 @@ def build_task_args(test_file_name): net_id = GlobalVariables.network_dict['net_id'] task_args['netid'] = str(net_id) - auth_url = ft_constants.OS_AUTH_URL + auth_url = CONST.OS_AUTH_URL if auth_url is not None: task_args['request_url'] = auth_url.rsplit(":", 1)[0] else: @@ -271,8 +270,8 @@ def excl_scenario(): with open(BLACKLIST_FILE, 'r') as black_list_file: black_list_yaml = yaml.safe_load(black_list_file) - installer_type = ft_constants.CI_INSTALLER_TYPE - deploy_scenario = ft_constants.CI_SCENARIO + installer_type = CONST.INSTALLER_TYPE + deploy_scenario = CONST.DEPLOY_SCENARIO if (bool(installer_type) * bool(deploy_scenario)): if 'scenario' in black_list_yaml.keys(): for item in black_list_yaml['scenario']: diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py index 6ad553353..20b1ebb4c 100644 --- a/functest/opnfv_tests/openstack/tempest/tempest.py +++ b/functest/opnfv_tests/openstack/tempest/tempest.py @@ -14,15 +14,14 @@ import shutil import subprocess import time -import opnfv.utils.constants as releng_constants import yaml import conf_utils import functest.core.testcase_base as testcase_base +from functest.utils.constants import CONST import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils import functest.utils.openstack_utils as os_utils -from functest.utils.constants import CONST """ logging configuration """ logger = ft_logger.Logger("Tempest").getLogger() @@ -31,7 +30,7 @@ logger = ft_logger.Logger("Tempest").getLogger() class TempestCommon(testcase_base.TestcaseBase): def __init__(self): - self.case_name = "" + super(TempestCommon, self).__init__() self.MODE = "" self.OPTION = "" self.FLAVOR_ID = None @@ -89,7 +88,7 @@ class TempestCommon(testcase_base.TestcaseBase): CONST.tempest_router_name, CONST.tempest_private_subnet_cidr) if not network_dic: - return releng_constants.EXIT_RUN_ERROR + return testcase_base.TestcaseBase.EX_RUN_ERROR if CONST.tempest_use_custom_images: # adding alternative image should be trivial should we need it @@ -98,7 +97,7 @@ class TempestCommon(testcase_base.TestcaseBase): CONST.openstack_image_name, conf_utils.GLANCE_IMAGE_PATH, CONST.openstack_image_disk_format) if not self.IMAGE_ID: - return releng_constants.EXIT_RUN_ERROR + return testcase_base.TestcaseBase.EX_RUN_ERROR if CONST.tempest_use_custom_flavors: # adding alternative flavor should be trivial should we need it @@ -109,9 +108,9 @@ class TempestCommon(testcase_base.TestcaseBase): CONST.openstack_flavor_disk, CONST.openstack_flavor_vcpus) if not self.FLAVOR_ID: - return releng_constants.EXIT_RUN_ERROR + return testcase_base.TestcaseBase.EX_RUN_ERROR - return releng_constants.EXIT_OK + return testcase_base.TestcaseBase.EX_OK def generate_test_list(self, DEPLOYMENT_DIR): logger.debug("Generating test case list...") @@ -125,7 +124,7 @@ class TempestCommon(testcase_base.TestcaseBase): else: logger.error("Tempest test list file %s NOT found." % conf_utils.TEMPEST_CUSTOM) - return releng_constants.EXIT_RUN_ERROR + return testcase_base.TestcaseBase.EX_RUN_ERROR else: if self.MODE == 'smoke': testr_mode = "smoke" @@ -139,7 +138,7 @@ class TempestCommon(testcase_base.TestcaseBase): testr_mode + ">" + conf_utils.TEMPEST_RAW_LIST + ";cd") ft_utils.execute_command(cmd) - return releng_constants.EXIT_OK + return testcase_base.TestcaseBase.EX_OK def apply_tempest_blacklist(self): logger.debug("Applying tempest blacklist...") @@ -175,30 +174,33 @@ class TempestCommon(testcase_base.TestcaseBase): else: result_file.write(str(cases_line) + '\n') result_file.close() - return releng_constants.EXIT_OK + return testcase_base.TestcaseBase.EX_OK def run(self): + + self.start_time = time.time() + if not os.path.exists(conf_utils.TEMPEST_RESULTS_DIR): os.makedirs(conf_utils.TEMPEST_RESULTS_DIR) # Pre-configuration res = self.create_tempest_resources() - if res != releng_constants.EXIT_OK: + if res != testcase_base.TestcaseBase.EX_OK: return res res = conf_utils.configure_tempest(logger, self.DEPLOYMENT_DIR, self.IMAGE_ID, self.FLAVOR_ID) - if res != releng_constants.EXIT_OK: + if res != testcase_base.TestcaseBase.EX_OK: return res res = self.generate_test_list(self.DEPLOYMENT_DIR) - if res != releng_constants.EXIT_OK: + if res != testcase_base.TestcaseBase.EX_OK: return res res = self.apply_tempest_blacklist() - if res != releng_constants.EXIT_OK: + if res != testcase_base.TestcaseBase.EX_OK: return res self.OPTION += (" --tests-file %s " % conf_utils.TEMPEST_LIST) @@ -271,23 +273,17 @@ class TempestCommon(testcase_base.TestcaseBase): except: success_rate = 0 - if 'smoke' in self.MODE: - self.CASE_NAME = 'tempest_smoke_serial' - elif 'feature' in self.MODE: - self.CASE_NAME = self.MODE.replace( - "feature_", "") - else: - self.CASE_NAME = 'tempest_full_parallel' - - status = ft_utils.check_success_rate( - self.CASE_NAME, success_rate) + self.criteria = ft_utils.check_success_rate( + self.case_name, success_rate) logger.info("Tempest %s success_rate is %s%%, is marked as %s" - % (self.CASE_NAME, success_rate, status)) + % (self.case_name, success_rate, self.criteria)) + + self.stop_time = time.time() - if status == "PASS": - return releng_constants.EXIT_OK + if self.criteria == "PASS": + return testcase_base.TestcaseBase.EX_OK else: - return releng_constants.EXIT_RUN_ERROR + return testcase_base.TestcaseBase.EX_TESTCASE_FAILED class TempestSmokeSerial(TempestCommon): diff --git a/functest/utils/functest_constants.py b/functest/utils/functest_constants.py index e25d6e024..ac9d77c87 100644 --- a/functest/utils/functest_constants.py +++ b/functest/utils/functest_constants.py @@ -103,7 +103,7 @@ 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.dir.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') diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py index 3145f573c..1879e6943 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,9 +23,6 @@ import requests import yaml from git import Repo -import time -import functools - import functest.utils.functest_logger as ft_logger logger = ft_logger.Logger("functest_utils").getLogger() diff --git a/functest/utils/openstack_clean.py b/functest/utils/openstack_clean.py index b1ad9664e..15a8f33d5 100755 --- a/functest/utils/openstack_clean.py +++ b/functest/utils/openstack_clean.py @@ -397,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 " @@ -418,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 c59492cfd..e64030f75 100755 --- a/functest/utils/openstack_snapshot.py +++ b/functest/utils/openstack_snapshot.py @@ -150,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 38a30cb33..64f18504d 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 @@ -1254,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) @@ -1271,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: @@ -1281,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: @@ -1302,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" @@ -1315,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'" @@ -1328,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'" @@ -1338,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" diff --git a/run_unit_tests.sh b/run_unit_tests.sh index 71d21c9db..b098f37b2 100755 --- a/run_unit_tests.sh +++ b/run_unit_tests.sh @@ -2,6 +2,13 @@ set -o errexit set -o pipefail +function clean_results_dir { + if [ -d "/home/opnfv/functest/results" ] + then + sudo rm -rf /home/opnfv/functest/results + fi +} + # ****************************** # prepare the env for the tests # ****************************** @@ -9,10 +16,7 @@ set -o pipefail # should be done at the end # but in case of crash during unit test # clean it anyway -if [ -d "/home/opnfv/functest/results" ] -then - sudo rm -rf /home/opnfv/functest -fi +clean_results_dir # TODO clean that... # Create log dir if needed @@ -67,9 +71,6 @@ deactivate # clean # ******* # Clean useless logs -if [ -d "/home/opnfv/functest/results" ] -then - sudo rm -rf /home/opnfv/functest/results -fi +clean_results_dir exit $rc |