diff options
Diffstat (limited to 'functest')
44 files changed, 1173 insertions, 898 deletions
diff --git a/functest/ci/__init__.py b/functest/ci/__init__.py index e69de29b..e69de29b 100644..100755 --- a/functest/ci/__init__.py +++ b/functest/ci/__init__.py diff --git a/functest/ci/check_os.sh b/functest/ci/check_os.sh index 053796d9..053796d9 100644..100755 --- a/functest/ci/check_os.sh +++ b/functest/ci/check_os.sh diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml index de019486..a19139c0 100644..100755 --- a/functest/ci/config_functest.yaml +++ b/functest/ci/config_functest.yaml @@ -1,199 +1,206 @@ -general: - directories: - # Relative to the path where the repo is cloned: - dir_vping: functest/opnfv_tests/OpenStack/vPing/ - dir_odl: functest/opnfv_tests/Controllers/ODL/ - dir_rally: functest/opnfv_tests/OpenStack/rally/ - dir_tempest_cases: functest/opnfv_tests/OpenStack/tempest/custom_tests/ - dir_vIMS: functest/opnfv_tests/vnf/vIMS/ - dir_onos: functest/opnfv_tests/Controllers/ONOS/Teston/ - dir_onos_sfc: functest/opnfv_tests/Controllers/ONOS/Sfc/ - - # Absolute path - dir_repos: /home/opnfv/repos - dir_repo_functest: /home/opnfv/repos/functest - dir_repo_rally: /home/opnfv/repos/rally - dir_repo_tempest: /home/opnfv/repos/tempest - dir_repo_releng: /home/opnfv/repos/releng - dir_repo_vims_test: /home/opnfv/repos/vims-test - dir_repo_bgpvpn: /home/opnfv/repos/bgpvpn - dir_repo_onos: /home/opnfv/repos/onos - dir_repo_promise: /home/opnfv/repos/promise - dir_repo_doctor: /home/opnfv/repos/doctor - dir_repo_copper: /home/opnfv/repos/copper - dir_repo_ovno: /home/opnfv/repos/ovno - dir_repo_parser: /home/opnfv/repos/parser - dir_repo_domino: /home/opnfv/repos/domino - dir_functest: /home/opnfv/functest - dir_results: /home/opnfv/functest/results - dir_functest_conf: /home/opnfv/functest/conf - dir_rally_res: /home/opnfv/functest/results/rally/ - dir_functest_data: /home/opnfv/functest/data - dir_vIMS_data: /home/opnfv/functest/data/vIMS - dir_rally_inst: /home/opnfv/.rally - - openstack: - snapshot_file: /home/opnfv/functest/conf/openstack_snapshot.yaml - - image_name: Cirros-0.3.4 - image_file_name: cirros-0.3.4-x86_64-disk.img - image_disk_format: qcow2 - - flavor_name: opnfv_flavor - flavor_ram: 512 - flavor_disk: 1 - flavor_vcpus: 1 - - # Private network for functest. Will be created by config_functest.py - neutron_private_net_name: functest-net - neutron_private_subnet_name: functest-subnet - neutron_private_subnet_cidr: 192.168.120.0/24 - neutron_private_subnet_start: 192.168.120.2 - neutron_private_subnet_end: 192.168.120.254 - neutron_private_subnet_gateway: 192.168.120.254 - neutron_router_name: functest-router - -healthcheck: - disk_image: /home/opnfv/functest/data/cirros-0.3.4-x86_64-disk.img - disk_format: qcow2 - wait_time: 60 - -vping: - ping_timeout: 200 - vm_flavor: m1.tiny # adapt to your environment - vm_name_1: opnfv-vping-1 - vm_name_2: opnfv-vping-2 - image_name: functest-vping - vping_private_net_name: vping-net - vping_private_subnet_name: vping-subnet - vping_private_subnet_cidr: 192.168.130.0/24 - vping_router_name: vping-router - vping_sg_name: vPing-sg - vping_sg_descr: Security group for vPing test case - -onos_sfc: - image_name: TestSfcVm - image_file_name: firewall_block_image.img - -tempest: - identity: - tenant_name: tempest - tenant_description: Tenant for Tempest test suite - user_name: tempest - user_password: tempest - validation: - ssh_timeout: 130 - private_net_name: tempest-net - private_subnet_name: tempest-subnet - private_subnet_cidr: 192.168.150.0/24 - router_name: tempest-router - use_custom_images: False - use_custom_flavors: False - -rally: - deployment_name: opnfv-rally - network_name: rally-net - subnet_name: rally-subnet - subnet_cidr: 192.168.140.0/24 - router_name: rally-router - -vIMS: - general: - tenant_name: vIMS - tenant_description: vIMS Functionality Testing - images: - ubuntu: - image_url: 'http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img' - image_name: ubuntu_14.04 - centos: - image_url: 'http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1510.qcow2' - image_name: centos_7 - cloudify: - blueprint: - url: https://github.com/boucherv-orange/cloudify-manager-blueprints.git - branch: "3.3.1-build" - requierments: - ram_min: 3000 - os_image: centos_7 - inputs: - keystone_username: "" - keystone_password: "" - keystone_tenant_name: "" - keystone_url: "" - manager_public_key_name: 'manager-kp' - agent_public_key_name: 'agent-kp' - image_id: "" - flavor_id: "3" - external_network_name: "" - ssh_user: centos - agents_user: ubuntu - clearwater: - blueprint: - file_name: 'openstack-blueprint.yaml' - name: "clearwater-opnfv" - destination_folder: "opnfv-cloudify-clearwater" - url: 'https://github.com/Orange-OpenSource/opnfv-cloudify-clearwater.git' - branch: "stable" - deployment-name: 'clearwater-opnfv' - requierments: - ram_min: 1700 - os_image: ubuntu_14.04 - inputs: - image_id: '' - flavor_id: '' - agent_user: 'ubuntu' - external_network_name: '' - public_domain: clearwater.opnfv -ONOS: - general: - onosbench_username: 'root' - onosbench_password: 'root' - onoscli_username: 'root' - onoscli_password: 'root' - runtimeout: 300 - environment: - OCT: '10.20.0.1' - OC1: '10.20.0.7' - OC2: '10.20.0.7' - OC3: '10.20.0.7' - OCN: '10.20.0.4' - OCN2: '10.20.0.5' - installer_master: '10.20.0.2' - installer_master_username: 'root' - installer_master_password: 'r00tme' -multisite: - fuel_environment: - installer_username: 'root' - installer_password: 'r00tme' - compass_environment: - installer_username: 'root' - installer_password: 'root' - multisite_controller_ip: '10.1.0.50' -promise: - tenant_name: promise - tenant_description: promise Functionality Testing - user_name: promiser - user_pwd: test - image_name: promise-img - flavor_name: promise-flavor - flavor_vcpus: 1 - flavor_ram: 128 - flavor_disk: 0 - network_name: promise-net - subnet_name: promise-subnet - subnet_cidr: 192.168.121.0/24 - router_name: promise-router - -example: - example_vm_name: example-vm - example_flavor: m1.small - example_image_name: functest-example-vm - example_private_net_name: example-net - example_private_subnet_name: example-subnet - example_private_subnet_cidr: 192.168.170.0/24 - example_router_name: example-router - example_sg_name: example-sg - example_sg_descr: Example Security group - -results: - test_db_url: http://testresults.opnfv.org/test/api/v1 +general:
+ directories:
+ # Relative to the path where the repo is cloned:
+ dir_vping: functest/opnfv_tests/OpenStack/vPing
+ dir_odl: functest/opnfv_tests/Controllers/ODL
+ dir_rally: functest/opnfv_tests/OpenStack/rally
+ dir_tempest_cases: functest/opnfv_tests/OpenStack/tempest/custom_tests
+ dir_vIMS: functest/opnfv_tests/vnf/vIMS
+ dir_onos: functest/opnfv_tests/Controllers/ONOS/Teston
+ dir_onos_sfc: functest/opnfv_tests/Controllers/ONOS/Sfc
+
+ # Absolute path
+ dir_home: /home/opnfv
+ dir_repos: /home/opnfv/repos
+ dir_repo_functest: /home/opnfv/repos/functest
+ dir_repo_rally: /home/opnfv/repos/rally
+ dir_repo_tempest: /home/opnfv/repos/tempest
+ dir_repo_releng: /home/opnfv/repos/releng
+ dir_repo_vims_test: /home/opnfv/repos/vims-test
+ dir_repo_sdnvpn: /home/opnfv/repos/sdnvpn
+ dir_repo_sfc: /home/opnfv/repos/sfc
+ dir_repo_onos: /home/opnfv/repos/onos
+ dir_repo_promise: /home/opnfv/repos/promise
+ dir_repo_doctor: /home/opnfv/repos/doctor
+ dir_repo_copper: /home/opnfv/repos/copper
+ dir_repo_ovno: /home/opnfv/repos/ovno
+ dir_repo_parser: /home/opnfv/repos/parser
+ dir_repo_domino: /home/opnfv/repos/domino
+ dir_functest: /home/opnfv/functest
+ dir_functest_test: /home/opnfv/repos/functest/functest/opnfv_tests
+ dir_results: /home/opnfv/functest/results
+ dir_functest_conf: /home/opnfv/functest/conf
+ dir_functest_data: /home/opnfv/functest/data
+ dir_vIMS_data: /home/opnfv/functest/data/vIMS/
+ dir_rally_inst: /home/opnfv/.rally
+
+ openstack:
+ creds: /home/opnfv/functest/conf/openstack.creds
+ snapshot_file: /home/opnfv/functest/conf/openstack_snapshot.yaml
+
+ image_name: Cirros-0.3.4
+ image_file_name: cirros-0.3.4-x86_64-disk.img
+ image_disk_format: qcow2
+
+ flavor_name: opnfv_flavor
+ flavor_ram: 512
+ flavor_disk: 1
+ flavor_vcpus: 1
+
+ # Private network for functest. Will be created by config_functest.py
+ neutron_private_net_name: functest-net
+ neutron_private_subnet_name: functest-subnet
+ neutron_private_subnet_cidr: 192.168.120.0/24
+ neutron_private_subnet_start: 192.168.120.2
+ neutron_private_subnet_end: 192.168.120.254
+ neutron_private_subnet_gateway: 192.168.120.254
+ neutron_router_name: functest-router
+
+ functest:
+ testcases_yaml: /home/opnfv/repos/functest/functest/ci/testcases.yaml
+
+healthcheck:
+ disk_image: /home/opnfv/functest/data/cirros-0.3.4-x86_64-disk.img
+ disk_format: qcow2
+ wait_time: 60
+
+vping:
+ ping_timeout: 200
+ vm_flavor: m1.tiny # adapt to your environment
+ vm_name_1: opnfv-vping-1
+ vm_name_2: opnfv-vping-2
+ image_name: functest-vping
+ vping_private_net_name: vping-net
+ vping_private_subnet_name: vping-subnet
+ vping_private_subnet_cidr: 192.168.130.0/24
+ vping_router_name: vping-router
+ vping_sg_name: vPing-sg
+ vping_sg_descr: Security group for vPing test case
+
+onos_sfc:
+ image_base_url: http://artifacts.opnfv.org/sfc/demo
+ image_name: TestSfcVm
+ image_file_name: firewall_block_image.img
+
+tempest:
+ identity:
+ tenant_name: tempest
+ tenant_description: Tenant for Tempest test suite
+ user_name: tempest
+ user_password: tempest
+ validation:
+ ssh_timeout: 130
+ private_net_name: tempest-net
+ private_subnet_name: tempest-subnet
+ private_subnet_cidr: 192.168.150.0/24
+ router_name: tempest-router
+ use_custom_images: False
+ use_custom_flavors: False
+
+rally:
+ deployment_name: opnfv-rally
+ network_name: rally-net
+ subnet_name: rally-subnet
+ subnet_cidr: 192.168.140.0/24
+ router_name: rally-router
+
+vIMS:
+ general:
+ tenant_name: vIMS
+ tenant_description: vIMS Functionality Testing
+ images:
+ ubuntu:
+ image_url: http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
+ image_name: ubuntu_14.04
+ centos:
+ image_url: http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1510.qcow2
+ image_name: centos_7
+ cloudify:
+ blueprint:
+ url: https://github.com/boucherv-orange/cloudify-manager-blueprints.git
+ branch: "3.3.1-build"
+ requierments:
+ ram_min: 3000
+ os_image: centos_7
+ inputs:
+ keystone_username: ""
+ keystone_password: ""
+ keystone_tenant_name: ""
+ keystone_url: ""
+ manager_public_key_name: 'manager-kp'
+ agent_public_key_name: 'agent-kp'
+ image_id: ""
+ flavor_id: "3"
+ external_network_name: ""
+ ssh_user: centos
+ agents_user: ubuntu
+ clearwater:
+ blueprint:
+ file_name: 'openstack-blueprint.yaml'
+ name: "clearwater-opnfv"
+ destination_folder: "opnfv-cloudify-clearwater"
+ url: https://github.com/Orange-OpenSource/opnfv-cloudify-clearwater.git
+ branch: "stable"
+ deployment-name: 'clearwater-opnfv'
+ requierments:
+ ram_min: 1700
+ os_image: ubuntu_14.04
+ inputs:
+ image_id: ''
+ flavor_id: ''
+ agent_user: 'ubuntu'
+ external_network_name: ''
+ public_domain: clearwater.opnfv
+ONOS:
+ general:
+ onosbench_username: 'root'
+ onosbench_password: 'root'
+ onoscli_username: 'root'
+ onoscli_password: 'root'
+ runtimeout: 300
+ environment:
+ OCT: '10.20.0.1'
+ OC1: '10.20.0.7'
+ OC2: '10.20.0.7'
+ OC3: '10.20.0.7'
+ OCN: '10.20.0.4'
+ OCN2: '10.20.0.5'
+ installer_master: '10.20.0.2'
+ installer_master_username: 'root'
+ installer_master_password: 'r00tme'
+multisite:
+ fuel_environment:
+ installer_username: 'root'
+ installer_password: 'r00tme'
+ compass_environment:
+ installer_username: 'root'
+ installer_password: 'root'
+ multisite_controller_ip: '10.1.0.50'
+promise:
+ tenant_name: promise
+ tenant_description: promise Functionality Testing
+ user_name: promiser
+ user_pwd: test
+ image_name: promise-img
+ flavor_name: promise-flavor
+ flavor_vcpus: 1
+ flavor_ram: 128
+ flavor_disk: 0
+ network_name: promise-net
+ subnet_name: promise-subnet
+ subnet_cidr: 192.168.121.0/24
+ router_name: promise-router
+
+example:
+ example_vm_name: example-vm
+ example_flavor: m1.small
+ example_image_name: functest-example-vm
+ example_private_net_name: example-net
+ example_private_subnet_name: example-subnet
+ example_private_subnet_cidr: 192.168.170.0/24
+ example_router_name: example-router
+ example_sg_name: example-sg
+ example_sg_descr: Example Security group
+
+results:
+ test_db_url: http://testresults.opnfv.org/test/api/v1
diff --git a/functest/ci/config_patch.yaml b/functest/ci/config_patch.yaml index 46064a07..46064a07 100644..100755 --- a/functest/ci/config_patch.yaml +++ b/functest/ci/config_patch.yaml diff --git a/functest/ci/exec_test.sh b/functest/ci/exec_test.sh index f7b96af2..a71079e3 100644 --- a/functest/ci/exec_test.sh +++ b/functest/ci/exec_test.sh @@ -127,18 +127,18 @@ function run_test(){ "ovno") # suite under rewritting for colorado # no need to run anything until refactoring done - # ${repos_dir}/ovno/Testcases/RunTests.sh + # ${REPOS_DIR}/ovno/Testcases/RunTests.sh ;; "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 ${REPOS_DIR}/securityscanning/security_scan.py --config ${REPOS_DIR}/securityscanning/config.ini ;; "copper") python ${FUNCTEST_TEST_DIR}/features/copper.py $report ;; "moon") - python ${repos_dir}/moon/tests/run_tests.py $report + python ${REPOS_DIR}/moon/tests/run_tests.py $report ;; "multisite") python ${FUNCTEST_TEST_DIR}/OpenStack/tempest/gen_tempest_conf.py @@ -147,7 +147,8 @@ function run_test(){ -c ${FUNCTEST_TEST_DIR}/OpenStack/tempest/tempest_multisite.conf ;; "odl-sfc") - ODL_SFC_DIR=${repos_dir}/sfc/tests/functest/odl-sfc + ODL_SFC_DIR=${REPOS_DIR}/sfc/tests/functest/odl-sfc + # pass FUNCTEST_REPO_DIR inside prepare_odl_sfc.bash FUNCTEST_REPO_DIR=${FUNCTEST_REPO_DIR} python ${ODL_SFC_DIR}/prepare_odl_sfc.py || exit $? source ${ODL_SFC_DIR}/tackerc python ${ODL_SFC_DIR}/sfc.py $report @@ -196,8 +197,8 @@ done # Source credentials -echo "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the test.." -source ${FUNCTEST_CONF_DIR}/openstack.creds +echo "Sourcing Credentials ${creds} to run the test.." +source ${creds} # ODL Boron workaround to create additional flow rules to allow port 22 TCP if [[ $DEPLOY_SCENARIO == *"odl_l2-sfc"* ]]; then diff --git a/functest/ci/generate_report.py b/functest/ci/generate_report.py index c9343729..9ae9dca5 100644..100755 --- a/functest/ci/generate_report.py +++ b/functest/ci/generate_report.py @@ -1,10 +1,10 @@ import json -import os import re import urllib2 import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils +import functest.utils.functest_constants as ft_constants COL_1_LEN = 25 @@ -15,8 +15,15 @@ COL_5_LEN = 75 # If we run from CI (Jenkins) we will push the results to the DB # and then we can print the url to the specific test result -IS_CI_RUN = False -BUILD_TAG = None + + +class GlobalVariables: + IS_CI_RUN = ft_constants.IS_CI_RUN + BUILD_TAG = ft_constants.CI_BUILD_TAG + INSTALLER = ft_constants.CI_INSTALLER_TYPE + CI_LOOP = ft_constants.CI_LOOP + SCENARIO = ft_constants.CI_SCENARIO + logger = ft_logger.Logger("generate_report").getLogger() @@ -34,7 +41,8 @@ def init(tiers_to_run): def get_results_from_db(): - url = ft_utils.get_db_url() + '/results?build_tag=' + BUILD_TAG + url = ft_utils.get_db_url() + '/results?build_tag=' \ + + GlobalVariables.BUILD_TAG logger.debug("Query to rest api: %s" % url) try: data = json.load(urllib2.urlopen(url)) @@ -61,7 +69,7 @@ def print_line(w1, w2='', w3='', w4='', w5=''): '| ' + w2.ljust(COL_2_LEN - 1) + '| ' + w3.ljust(COL_3_LEN - 1) + '| ' + w4.ljust(COL_4_LEN - 1)) - if IS_CI_RUN: + if GlobalVariables.IS_CI_RUN: str += ('| ' + w5.ljust(COL_5_LEN - 1)) str += '|\n' return str @@ -69,7 +77,7 @@ def print_line(w1, w2='', w3='', w4='', w5=''): def print_line_no_columns(str): TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN + 2 - if IS_CI_RUN: + if GlobalVariables.IS_CI_RUN: TOTAL_LEN += COL_5_LEN + 1 return ('| ' + str.ljust(TOTAL_LEN) + "|\n") @@ -79,21 +87,16 @@ def print_separator(char="=", delimiter="+"): delimiter + char * COL_2_LEN + delimiter + char * COL_3_LEN + delimiter + char * COL_4_LEN) - if IS_CI_RUN: + if GlobalVariables.IS_CI_RUN: str += (delimiter + char * COL_5_LEN) str += '+\n' return str def main(args): - global BUILD_TAG, IS_CI_RUN executed_test_cases = args - BUILD_TAG = os.getenv("BUILD_TAG") - if BUILD_TAG is not None: - IS_CI_RUN = True - - if IS_CI_RUN: + if GlobalVariables.IS_CI_RUN: results = get_results_from_db() if results is not None: for test in executed_test_cases: @@ -102,19 +105,15 @@ def main(args): "result": data['result']}) TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN - if IS_CI_RUN: + if GlobalVariables.IS_CI_RUN: TOTAL_LEN += COL_5_LEN MID = TOTAL_LEN / 2 - INSTALLER = os.getenv('INSTALLER_TYPE', 'unknown') - CI_LOOP = os.getenv('CI_LOOP') - SCENARIO = os.getenv('DEPLOY_SCENARIO') - CI_LOOP = None - if BUILD_TAG is not None: - if re.search("daily", BUILD_TAG) is not None: - CI_LOOP = "daily" + if GlobalVariables.BUILD_TAG is not None: + if re.search("daily", GlobalVariables.BUILD_TAG) is not None: + GlobalVariables.CI_LOOP = "daily" else: - CI_LOOP = "weekly" + GlobalVariables.CI_LOOP = "weekly" str = '' str += print_separator('=', delimiter="=") @@ -122,16 +121,20 @@ def main(args): str += print_separator('=', delimiter="=") str += print_line_no_columns(' ') str += print_line_no_columns(" Deployment description:") - str += print_line_no_columns(" INSTALLER: %s" % INSTALLER) - if SCENARIO is not None: - str += print_line_no_columns(" SCENARIO: %s" % SCENARIO) - if BUILD_TAG is not None: - str += print_line_no_columns(" BUILD TAG: %s" % BUILD_TAG) - if CI_LOOP is not None: - str += print_line_no_columns(" CI LOOP: %s" % CI_LOOP) + str += print_line_no_columns(" INSTALLER: %s" + % GlobalVariables.INSTALLER) + if GlobalVariables.SCENARIO is not None: + str += print_line_no_columns(" SCENARIO: %s" + % GlobalVariables.SCENARIO) + if GlobalVariables.BUILD_TAG is not None: + str += print_line_no_columns(" BUILD TAG: %s" + % GlobalVariables.BUILD_TAG) + if GlobalVariables.CI_LOOP is not None: + str += print_line_no_columns(" CI LOOP: %s" + % GlobalVariables.CI_LOOP) str += print_line_no_columns(' ') str += print_separator('=') - if IS_CI_RUN: + if GlobalVariables.IS_CI_RUN: str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT', 'URL') else: str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT') diff --git a/functest/ci/prepare_env.py b/functest/ci/prepare_env.py index e5c24cc3..246a02a8 100644..100755 --- a/functest/ci/prepare_env.py +++ b/functest/ci/prepare_env.py @@ -25,6 +25,7 @@ import yaml 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 actions = ['start', 'check'] parser = argparse.ArgumentParser() @@ -38,34 +39,13 @@ args = parser.parse_args() logger = ft_logger.Logger("prepare_env").getLogger() -""" global variables """ -INSTALLERS = ['fuel', 'compass', 'apex', 'joid'] -CI_INSTALLER_TYPE = "" -CI_INSTALLER_IP = "" -CI_SCENARIO = "" -CI_DEBUG = False -CONFIG_FUNCTEST_PATH = os.environ["CONFIG_FUNCTEST_YAML"] +CONFIG_FUNCTEST_PATH = ft_constants.CONFIG_FUNCTEST_YAML CONFIG_PATCH_PATH = os.path.join(os.path.dirname( CONFIG_FUNCTEST_PATH), "config_patch.yaml") with open(CONFIG_PATCH_PATH) as f: functest_patch_yaml = yaml.safe_load(f) -FUNCTEST_CONF_DIR = \ - ft_utils.get_functest_config('general.directories.dir_functest_conf') - - -FUNCTEST_DATA_DIR = \ - ft_utils.get_functest_config('general.directories.dir_functest_data') -FUNCTEST_RESULTS_DIR = \ - ft_utils.get_functest_config('general.directories.dir_results') -DEPLOYMENT_MAME = \ - ft_utils.get_functest_config('rally.deployment_name') -TEMPEST_REPO_DIR = \ - ft_utils.get_functest_config('general.directories.dir_repo_tempest') - -ENV_FILE = FUNCTEST_CONF_DIR + "/env_active" - def print_separator(): logger.info("==============================================") @@ -74,97 +54,97 @@ def print_separator(): def check_env_variables(): print_separator() logger.info("Checking environment variables...") - global CI_INSTALLER_TYPE - global CI_INSTALLER_IP - global CI_DEBUG - global CI_SCENARIO - CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') - CI_INSTALLER_IP = os.getenv('INSTALLER_IP') - CI_SCENARIO = os.getenv('DEPLOY_SCENARIO') - CI_NODE = os.getenv('NODE_NAME') - CI_BUILD_TAG = os.getenv('BUILD_TAG') - CI_DEBUG = os.getenv('CI_DEBUG') - - if CI_INSTALLER_TYPE is None: + + if ft_constants.CI_INSTALLER_TYPE is None: logger.warning("The env variable 'INSTALLER_TYPE' is not defined.") - CI_INSTALLER_TYPE = "undefined" + ft_constants.CI_INSTALLER_TYPE = "undefined" else: - if CI_INSTALLER_TYPE not in INSTALLERS: + if ft_constants.CI_INSTALLER_TYPE not in ft_constants.INSTALLERS: logger.warning("INSTALLER_TYPE=%s is not a valid OPNFV installer. " "Available OPNFV Installers are : %s. " "Setting INSTALLER_TYPE=undefined." - % (CI_INSTALLER_TYPE, INSTALLERS)) - CI_INSTALLER_TYPE = "undefined" + % (ft_constants.CI_INSTALLER_TYPE, + ft_constants.INSTALLERS)) + ft_constants.CI_INSTALLER_TYPE = "undefined" else: - logger.info(" INSTALLER_TYPE=%s" % CI_INSTALLER_TYPE) + logger.info(" INSTALLER_TYPE=%s" + % ft_constants.CI_INSTALLER_TYPE) - if CI_INSTALLER_IP is None: + if ft_constants.CI_INSTALLER_IP is None: logger.warning("The env variable 'INSTALLER_IP' is not defined. " "It is needed to fetch the OpenStack credentials. " "If the credentials are not provided to the " "container as a volume, please add this env variable " "to the 'docker run' command.") else: - logger.info(" INSTALLER_IP=%s" % CI_INSTALLER_IP) + logger.info(" INSTALLER_IP=%s" % ft_constants.CI_INSTALLER_IP) - if CI_SCENARIO is None: + if ft_constants.CI_SCENARIO is None: logger.warning("The env variable 'DEPLOY_SCENARIO' is not defined. " "Setting CI_SCENARIO=undefined.") - CI_SCENARIO = "undefined" + ft_constants.CI_SCENARIO = "undefined" else: - logger.info(" DEPLOY_SCENARIO=%s" % CI_SCENARIO) - if CI_DEBUG: - logger.info(" CI_DEBUG=%s" % CI_DEBUG) + logger.info(" DEPLOY_SCENARIO=%s" % ft_constants.CI_SCENARIO) + if ft_constants.CI_DEBUG: + logger.info(" CI_DEBUG=%s" % ft_constants.CI_DEBUG) - if CI_NODE: - logger.info(" NODE_NAME=%s" % CI_NODE) + if ft_constants.CI_NODE: + logger.info(" NODE_NAME=%s" % ft_constants.CI_NODE) - if CI_BUILD_TAG: - logger.info(" BUILD_TAG=%s" % CI_BUILD_TAG) + if ft_constants.CI_BUILD_TAG: + logger.info(" BUILD_TAG=%s" % ft_constants.CI_BUILD_TAG) + + if ft_constants.IS_CI_RUN: + logger.info(" IS_CI_RUN=%s" % ft_constants.IS_CI_RUN) def create_directories(): print_separator() logger.info("Creating needed directories...") - if not os.path.exists(FUNCTEST_CONF_DIR): - os.makedirs(FUNCTEST_CONF_DIR) - logger.info(" %s created." % FUNCTEST_CONF_DIR) + if not os.path.exists(ft_constants.FUNCTEST_CONF_DIR): + os.makedirs(ft_constants.FUNCTEST_CONF_DIR) + logger.info(" %s created." % ft_constants.FUNCTEST_CONF_DIR) else: - logger.debug(" %s already exists." % FUNCTEST_CONF_DIR) + logger.debug(" %s already exists." + % ft_constants.FUNCTEST_CONF_DIR) - if not os.path.exists(FUNCTEST_DATA_DIR): - os.makedirs(FUNCTEST_DATA_DIR) - logger.info(" %s created." % FUNCTEST_DATA_DIR) + if not os.path.exists(ft_constants.FUNCTEST_DATA_DIR): + os.makedirs(ft_constants.FUNCTEST_DATA_DIR) + logger.info(" %s created." % ft_constants.FUNCTEST_DATA_DIR) else: - logger.debug(" %s already exists." % FUNCTEST_DATA_DIR) + logger.debug(" %s already exists." + % ft_constants.FUNCTEST_DATA_DIR) def source_rc_file(): print_separator() logger.info("Fetching RC file...") - rc_file = os.getenv('creds') - if rc_file is None: + + if ft_constants.OPENSTACK_CREDS is None: logger.warning("The environment variable 'creds' must be set and" "pointing to the local RC file. Using default: " "/home/opnfv/functest/conf/openstack.creds ...") - rc_file = "/home/opnfv/functest/conf/openstack.creds" + ft_constants.OPENSTACK_CREDS = \ + "/home/opnfv/functest/conf/openstack.creds" - if not os.path.isfile(rc_file): + if not os.path.isfile(ft_constants.OPENSTACK_CREDS): logger.info("RC file not provided. " "Fetching it from the installer...") - if CI_INSTALLER_IP is None: + if ft_constants.CI_INSTALLER_IP is None: logger.error("The env variable CI_INSTALLER_IP must be provided in" " order to fetch the credentials from the installer.") sys.exit("Missing CI_INSTALLER_IP.") - if CI_INSTALLER_TYPE not in INSTALLERS: + if ft_constants.CI_INSTALLER_TYPE not in ft_constants.INSTALLERS: logger.error("Cannot fetch credentials. INSTALLER_TYPE=%s is " "not a valid OPNFV installer. Available " - "installers are : %s." % INSTALLERS) + "installers are : %s." % ft_constants.INSTALLERS) sys.exit("Wrong INSTALLER_TYPE.") cmd = ("/home/opnfv/repos/releng/utils/fetch_os_creds.sh " "-d %s -i %s -a %s" - % (rc_file, CI_INSTALLER_TYPE, CI_INSTALLER_IP)) + % (ft_constants.OPENSTACK_CREDS, + ft_constants.CI_INSTALLER_TYPE, + ft_constants.CI_INSTALLER_IP)) logger.debug("Executing command: %s" % cmd) p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) output = p.communicate()[0] @@ -173,24 +153,39 @@ def source_rc_file(): logger.error("Failed to fetch credentials from installer.") sys.exit(1) else: - logger.info("RC file provided in %s." % rc_file) - if os.path.getsize(rc_file) == 0: - logger.error("The file %s is empty." % rc_file) + logger.info("RC file provided in %s." + % ft_constants.OPENSTACK_CREDS) + if os.path.getsize(ft_constants.OPENSTACK_CREDS) == 0: + logger.error("The file %s is empty." + % ft_constants.OPENSTACK_CREDS) sys.exit(1) logger.info("Sourcing the OpenStack RC file...") - creds = os_utils.source_credentials(rc_file) + creds = os_utils.source_credentials( + ft_constants.OPENSTACK_CREDS) str = "" for key, value in creds.iteritems(): if re.search("OS_", key): str += "\n\t\t\t\t\t\t " + key + "=" + value + if key == 'OS_AUTH_URL': + ft_constants.OS_AUTH_URL = value + elif key == 'OS_USERNAME': + ft_constants.OS_USERNAME = value + elif key == 'OS_TENANT_NAME': + ft_constants.OS_TENANT_NAME = value + elif key == 'OS_PASSWORD': + ft_constants.OS_PASSWORD = value logger.debug("Used credentials: %s" % str) + logger.debug("OS_AUTH_URL:%s" % ft_constants.OS_AUTH_URL) + logger.debug("OS_USERNAME:%s" % ft_constants.OS_USERNAME) + logger.debug("OS_TENANT_NAME:%s" % ft_constants.OS_TENANT_NAME) + logger.debug("OS_PASSWORD:%s" % ft_constants.OS_PASSWORD) def patch_config_file(): updated = False for key in functest_patch_yaml: - if key in CI_SCENARIO: + if key in ft_constants.CI_SCENARIO: new_functest_yaml = dict(ft_utils.merge_dicts( ft_utils.get_functest_yaml(), functest_patch_yaml[key])) updated = True @@ -205,7 +200,7 @@ def patch_config_file(): def verify_deployment(): print_separator() logger.info("Verifying OpenStack services...") - cmd = ("%s/functest/ci/check_os.sh" % ft_utils.FUNCTEST_REPO) + cmd = ("%s/functest/ci/check_os.sh" % ft_constants.FUNCTEST_REPO_DIR) logger.debug("Executing command: %s" % cmd) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) @@ -223,19 +218,21 @@ def install_rally(): logger.info("Creating Rally environment...") cmd = "rally deployment destroy opnfv-rally" - ft_utils.execute_command(cmd, - error_msg=("Deployment %s does not exist." - % DEPLOYMENT_MAME), verbose=False) + ft_utils.execute_command(cmd, error_msg=( + "Deployment %s does not exist." + % ft_constants.RALLY_DEPLOYMENT_NAME), + verbose=False) rally_conf = os_utils.get_credentials_for_rally() with open('rally_conf.json', 'w') as fp: json.dump(rally_conf, fp) cmd = "rally deployment create --file=rally_conf.json --name=" - cmd += DEPLOYMENT_MAME + cmd += ft_constants.RALLY_DEPLOYMENT_NAME ft_utils.execute_command(cmd, error_msg="Problem creating Rally deployment") logger.info("Installing tempest from existing repo...") - cmd = ("rally verify install --source " + TEMPEST_REPO_DIR + + cmd = ("rally verify install --source " + + ft_constants.TEMPEST_REPO_DIR + " --system-wide") ft_utils.execute_command(cmd, error_msg="Problem installing Tempest.") @@ -258,11 +255,11 @@ def install_rally(): def check_environment(): msg_not_active = "The Functest environment is not installed." - if not os.path.isfile(ENV_FILE): + if not os.path.isfile(ft_constants.ENV_FILE): logger.error(msg_not_active) sys.exit(1) - with open(ENV_FILE, "r") as env_file: + with open(ft_constants.ENV_FILE, "r") as env_file: s = env_file.read() if not re.search("1", s): logger.error(msg_not_active) @@ -285,7 +282,7 @@ def main(): verify_deployment() install_rally() - with open(ENV_FILE, "w") as env_file: + with open(ft_constants.ENV_FILE, "w") as env_file: env_file.write("1") check_environment() @@ -295,5 +292,6 @@ def main(): exit(0) + if __name__ == '__main__': main() diff --git a/functest/ci/run_tests.py b/functest/ci/run_tests.py index 015b5840..da9d28a9 100644 --- a/functest/ci/run_tests.py +++ b/functest/ci/run_tests.py @@ -21,6 +21,7 @@ import functest.ci.tier_builder as tb import functest.core.TestCasesBase as TestCasesBase import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils +import functest.utils.functest_constants as ft_constants import functest.utils.openstack_clean as os_clean import functest.utils.openstack_snapshot as os_snapshot import functest.utils.openstack_utils as os_utils @@ -43,14 +44,17 @@ logger = ft_logger.Logger("run_tests").getLogger() """ global variables """ -EXEC_SCRIPT = ("%s/functest/ci/exec_test.sh" % ft_utils.FUNCTEST_REPO) -CLEAN_FLAG = True -REPORT_FLAG = False -EXECUTED_TEST_CASES = [] +EXEC_SCRIPT = ("%s/functest/ci/exec_test.sh" % ft_constants.FUNCTEST_REPO_DIR) # This will be the return code of this script. If any of the tests fails, # this variable will change to -1 -OVERALL_RESULT = 0 + + +class GlobalVariables: + EXECUTED_TEST_CASES = [] + OVERALL_RESULT = 0 + CLEAN_FLAG = True + REPORT_FLAG = False def print_separator(str, count=45): @@ -61,12 +65,26 @@ def print_separator(str, count=45): def source_rc_file(): - rc_file = os.getenv('creds') + rc_file = ft_constants.OPENSTACK_CREDS if not os.path.isfile(rc_file): logger.error("RC file %s does not exist..." % rc_file) sys.exit(1) logger.debug("Sourcing the OpenStack RC file...") - os_utils.source_credentials(rc_file) + creds = os_utils.source_credentials(rc_file) + for key, value in creds.iteritems(): + if re.search("OS_", key): + if key == 'OS_AUTH_URL': + ft_constants.OS_AUTH_URL = value + elif key == 'OS_USERNAME': + ft_constants.OS_USERNAME = value + elif key == 'OS_TENANT_NAME': + ft_constants.OS_TENANT_NAME = value + elif key == 'OS_PASSWORD': + ft_constants.OS_PASSWORD = value + logger.debug("OS_AUTH_URL:%s" % ft_constants.OS_AUTH_URL) + logger.debug("OS_USERNAME:%s" % ft_constants.OS_USERNAME) + logger.debug("OS_TENANT_NAME:%s" % ft_constants.OS_TENANT_NAME) + logger.debug("OS_PASSWORD:%s" % ft_constants.OS_PASSWORD) def generate_os_snapshot(): @@ -78,7 +96,7 @@ def cleanup(): def update_test_info(test_name, result, duration): - for test in EXECUTED_TEST_CASES: + for test in GlobalVariables.EXECUTED_TEST_CASES: if test['test_name'] == test_name: test.update({"result": result, "duration": duration}) @@ -98,7 +116,6 @@ def get_run_dict_if_defined(testname): def run_test(test, tier_name): - global OVERALL_RESULT, EXECUTED_TEST_CASES result_str = "PASS" start = datetime.datetime.now() test_name = test.get_name() @@ -108,11 +125,11 @@ def run_test(test, tier_name): print_separator("=") logger.debug("\n%s" % test) - if CLEAN_FLAG: + if GlobalVariables.CLEAN_FLAG: generate_os_snapshot() flags = (" -t %s" % (test_name)) - if REPORT_FLAG: + if GlobalVariables.REPORT_FLAG: flags += " -r" result = TestCasesBase.TestCasesBase.EX_RUN_ERROR @@ -123,7 +140,9 @@ def run_test(test, tier_name): cls = getattr(module, run_dict['class']) test_case = cls() result = test_case.run() - if result != TestCasesBase.TestCasesBase.EX_SKIP and REPORT_FLAG: + + if result != TestCasesBase.TestCasesBase.EX_SKIP and \ + GlobalVariables.REPORT_FLAG: test_case.push_to_db() except ImportError: logger.exception("Cannot import module {}".format( @@ -138,7 +157,7 @@ def run_test(test, tier_name): cmd, test_name)) result = ft_utils.execute_command(cmd) - if CLEAN_FLAG: + if GlobalVariables.CLEAN_FLAG: cleanup() end = datetime.datetime.now() duration = (end - start).seconds @@ -156,7 +175,7 @@ def run_test(test, tier_name): "execution.") # if it is a single test we don't print the whole results table update_test_info(test_name, result_str, duration_str) - generate_report.main(EXECUTED_TEST_CASES) + generate_report.main(GlobalVariables.EXECUTED_TEST_CASES) logger.info("Execution exit value: %s" % OVERALL_RESULT) sys.exit(OVERALL_RESULT) @@ -180,9 +199,8 @@ def run_tier(tier): def run_all(tiers): - global EXECUTED_TEST_CASES summary = "" - BUILD_TAG = os.getenv('BUILD_TAG') + BUILD_TAG = ft_constants.CI_BUILD_TAG if BUILD_TAG is not None and re.search("daily", BUILD_TAG) is not None: CI_LOOP = "daily" else: @@ -199,28 +217,26 @@ def run_all(tiers): tier.get_test_names())) logger.info("Tests to be executed:%s" % summary) - EXECUTED_TEST_CASES = generate_report.init(tiers_to_run) + GlobalVariables.EXECUTED_TEST_CASES = generate_report.init(tiers_to_run) for tier in tiers_to_run: run_tier(tier) - generate_report.main(EXECUTED_TEST_CASES) + generate_report.main(GlobalVariables.EXECUTED_TEST_CASES) def main(): - global CLEAN_FLAG - global REPORT_FLAG - CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') - CI_SCENARIO = os.getenv('DEPLOY_SCENARIO') + CI_INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE + CI_SCENARIO = ft_constants.CI_SCENARIO - file = ft_utils.get_testcases_file() + file = ft_constants.FUNCTEST_TESTCASES_YAML _tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, file) if args.noclean: - CLEAN_FLAG = False + GlobalVariables.CLEAN_FLAG = False if args.report: - REPORT_FLAG = True + GlobalVariables.REPORT_FLAG = True if args.test: source_rc_file() @@ -242,8 +258,9 @@ def main(): else: run_all(_tiers) - logger.info("Execution exit value: %s" % OVERALL_RESULT) - sys.exit(OVERALL_RESULT) + logger.info("Execution exit value: %s" % GlobalVariables.OVERALL_RESULT) + sys.exit(GlobalVariables.OVERALL_RESULT) + if __name__ == '__main__': main() diff --git a/functest/ci/testcases.yaml b/functest/ci/testcases.yaml index 195108b4..a5ddcf23 100644..100755 --- a/functest/ci/testcases.yaml +++ b/functest/ci/testcases.yaml @@ -151,7 +151,7 @@ tiers: dependencies: installer: '(fuel)|(apex)' scenario: 'bgpvpn' - run: + run: module: 'functest.opnfv_tests.features.sdnvpn' class: 'SDNVPN' diff --git a/functest/ci/tier_builder.py b/functest/ci/tier_builder.py index e1c3e49e..e1c3e49e 100644..100755 --- a/functest/ci/tier_builder.py +++ b/functest/ci/tier_builder.py diff --git a/functest/ci/tier_handler.py b/functest/ci/tier_handler.py index 1eadfba5..1eadfba5 100644..100755 --- a/functest/ci/tier_handler.py +++ b/functest/ci/tier_handler.py diff --git a/functest/cli/cli_base.py b/functest/cli/cli_base.py index 827f8a4b..3b14fa33 100644 --- a/functest/cli/cli_base.py +++ b/functest/cli/cli_base.py @@ -22,6 +22,7 @@ CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) def cli(): pass + _env = CliEnv() _openstack = CliOpenStack() _testcase = CliTestcase() diff --git a/functest/cli/commands/cli_env.py b/functest/cli/commands/cli_env.py index d331cc15..9f793e71 100644 --- a/functest/cli/commands/cli_env.py +++ b/functest/cli/commands/cli_env.py @@ -13,9 +13,7 @@ import click import git import functest.utils.functest_utils as ft_utils - -ENV_FILE = "/home/opnfv/functest/conf/env_active" -FUNCTEST_REPO = ft_utils.FUNCTEST_REPO +import functest.utils.functest_constants as ft_constants class CliEnv: @@ -30,44 +28,45 @@ class CliEnv: "it again? [y|n]\n") while True: if answer.lower() in ["y", "yes"]: - os.remove(ENV_FILE) + os.remove(ft_constants.ENV_FILE) break elif answer.lower() in ["n", "no"]: return else: answer = raw_input("Invalid answer. Please type [y|n]\n") - cmd = ("python %s/functest/ci/prepare_env.py start" % FUNCTEST_REPO) + cmd = ("python %s/functest/ci/prepare_env.py start" % + ft_constants.FUNCTEST_REPO_DIR) ft_utils.execute_command(cmd) def show(self): - CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') + CI_INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE if CI_INSTALLER_TYPE is None: CI_INSTALLER_TYPE = "Unknown" - CI_INSTALLER_IP = os.getenv('INSTALLER_IP') + CI_INSTALLER_IP = ft_constants.CI_INSTALLER_IP if CI_INSTALLER_IP is None: CI_INSTALLER_IP = "Unknown" CI_INSTALLER = ("%s, %s" % (CI_INSTALLER_TYPE, CI_INSTALLER_IP)) - CI_SCENARIO = os.getenv('DEPLOY_SCENARIO') + CI_SCENARIO = ft_constants.CI_SCENARIO if CI_SCENARIO is None: CI_SCENARIO = "Unknown" - CI_NODE = os.getenv('NODE_NAME') + CI_NODE = ft_constants.CI_NODE if CI_NODE is None: CI_NODE = "Unknown" - repo = git.Repo(FUNCTEST_REPO) + repo = git.Repo(ft_constants.FUNCTEST_REPO_DIR) branch = repo.head.reference GIT_BRANCH = branch.name GIT_HASH = branch.commit.hexsha - CI_BUILD_TAG = os.getenv('BUILD_TAG') + CI_BUILD_TAG = ft_constants.CI_BUILD_TAG if CI_BUILD_TAG is not None: CI_BUILD_TAG = CI_BUILD_TAG.lstrip( "jenkins-").lstrip("functest").lstrip("-") - CI_DEBUG = os.getenv('CI_DEBUG') + CI_DEBUG = ft_constants.CI_DEBUG if CI_DEBUG is None: CI_DEBUG = "false" @@ -93,7 +92,7 @@ class CliEnv: def status(self, verbose=True): ret_val = 0 - if not os.path.isfile(ENV_FILE): + if not os.path.isfile(ft_constants.ENV_FILE): if verbose: click.echo("Functest environment is not installed.\n") ret_val = 1 diff --git a/functest/cli/commands/cli_os.py b/functest/cli/commands/cli_os.py index 2530b5f2..140be191 100644 --- a/functest/cli/commands/cli_os.py +++ b/functest/cli/commands/cli_os.py @@ -15,19 +15,17 @@ import click import functest.utils.functest_utils as ft_utils import functest.utils.openstack_clean as os_clean import functest.utils.openstack_snapshot as os_snapshot +import functest.utils.functest_constants as ft_constants -FUNCTEST_CONF_DIR = \ - ft_utils.get_functest_config('general.directories.dir_functest_conf') -RC_FILE = os.getenv('creds') -OS_SNAPSHOT_FILE = \ - ft_utils.get_functest_config("general.openstack.snapshot_file") +OPENSTACK_RC_FILE = ft_constants.OPENSTACK_CREDS +OPENSTACK_SNAPSHOT_FILE = ft_constants.OPENSTACK_SNAPSHOT_FILE class CliOpenStack: def __init__(self): - self.os_auth_url = os.getenv('OS_AUTH_URL') + self.os_auth_url = ft_constants.OS_AUTH_URL self.endpoint_ip = None self.endpoint_port = None if self.os_auth_url is not None: @@ -51,7 +49,7 @@ class CliOpenStack: click.echo("{}={}".format(key, value)) def fetch_credentials(self): - if os.path.isfile(RC_FILE): + if os.path.isfile(OPENSTACK_RC_FILE): answer = raw_input("It seems the RC file is already present. " "Do you want to overwrite it? [y|n]\n") while True: @@ -62,29 +60,30 @@ class CliOpenStack: else: answer = raw_input("Invalid answer. Please type [y|n]\n") - CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') + CI_INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE if CI_INSTALLER_TYPE is None: click.echo("The environment variable 'INSTALLER_TYPE' is not" "defined. Please export it") - CI_INSTALLER_IP = os.getenv('INSTALLER_IP') + CI_INSTALLER_IP = ft_constants.CI_INSTALLER_IP if CI_INSTALLER_IP is None: click.echo("The environment variable 'INSTALLER_IP' is not" "defined. Please export it") - cmd = ("/home/opnfv/repos/releng/utils/fetch_os_creds.sh " - "-d %s -i %s -a %s" - % (RC_FILE, CI_INSTALLER_TYPE, CI_INSTALLER_IP)) + cmd = ft_constants.REPOS_DIR + \ + ("/releng/utils/fetch_os_creds.sh " + "-d %s -i %s -a %s" + % (OPENSTACK_RC_FILE, CI_INSTALLER_TYPE, CI_INSTALLER_IP)) click.echo("Fetching credentials from installer node '%s' with IP=%s.." % (CI_INSTALLER_TYPE, CI_INSTALLER_IP)) ft_utils.execute_command(cmd, verbose=False) def check(self): self.ping_endpoint() - cmd = ft_utils.FUNCTEST_REPO + "/functest/ci/check_os.sh" + cmd = ft_constants.FUNCTEST_REPO_DIR + "/functest/ci/check_os.sh" ft_utils.execute_command(cmd, verbose=False) def snapshot_create(self): self.ping_endpoint() - if os.path.isfile(OS_SNAPSHOT_FILE): + if os.path.isfile(OPENSTACK_SNAPSHOT_FILE): answer = raw_input("It seems there is already an OpenStack " "snapshot. Do you want to overwrite it with " "the current OpenStack status? [y|n]\n") @@ -100,18 +99,18 @@ class CliOpenStack: os_snapshot.main() def snapshot_show(self): - if not os.path.isfile(OS_SNAPSHOT_FILE): + if not os.path.isfile(OPENSTACK_SNAPSHOT_FILE): click.echo("There is no OpenStack snapshot created. To create " "one run the command " "'functest openstack snapshot-create'") return - with open(OS_SNAPSHOT_FILE, 'r') as yaml_file: + with open(OPENSTACK_SNAPSHOT_FILE, 'r') as yaml_file: click.echo("\n%s" % yaml_file.read()) def clean(self): self.ping_endpoint() - if not os.path.isfile(OS_SNAPSHOT_FILE): + if not os.path.isfile(OPENSTACK_SNAPSHOT_FILE): click.echo("Not possible to clean OpenStack without a snapshot. " "This could cause problems. " "Run first the command " diff --git a/functest/cli/commands/cli_testcase.py b/functest/cli/commands/cli_testcase.py index da78ae9c..efe177d5 100644 --- a/functest/cli/commands/cli_testcase.py +++ b/functest/cli/commands/cli_testcase.py @@ -16,20 +16,16 @@ import click import functest.ci.tier_builder as tb import functest.utils.functest_utils as ft_utils import functest.utils.functest_vacation as vacation - - -FUNCTEST_CONF_DIR = \ - ft_utils.get_functest_config('general.directories.dir_functest_conf') -ENV_FILE = FUNCTEST_CONF_DIR + "/env_active" -FUNCTEST_REPO = ft_utils.FUNCTEST_REPO +import functest.utils.functest_constants as ft_constants class CliTestcase: def __init__(self): - CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') - CI_SCENARIO = os.getenv('DEPLOY_SCENARIO') - testcases = ft_utils.get_testcases_file() + CI_INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE + CI_SCENARIO = ft_constants.CI_SCENARIO + testcases = ft_constants.FUNCTEST_TESTCASES_YAML + self.tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, testcases) def list(self): @@ -50,14 +46,14 @@ class CliTestcase: def run(self, testname, noclean=False): if testname == 'vacation': vacation.main() - elif not os.path.isfile(ENV_FILE): + elif not os.path.isfile(ft_constants.ENV_FILE): click.echo("Functest environment is not ready. " "Run first 'functest env prepare'") else: if noclean: cmd = ("python %s/functest/ci/run_tests.py " - "-n -t %s" % (FUNCTEST_REPO, testname)) + "-n -t %s" % (ft_constants.FUNCTEST_REPO_DIR, testname)) else: cmd = ("python %s/functest/ci/run_tests.py " - "-t %s" % (FUNCTEST_REPO, testname)) + "-t %s" % (ft_constants.FUNCTEST_REPO_DIR, testname)) ft_utils.execute_command(cmd) diff --git a/functest/cli/commands/cli_tier.py b/functest/cli/commands/cli_tier.py index fa2de587..9da51072 100644 --- a/functest/cli/commands/cli_tier.py +++ b/functest/cli/commands/cli_tier.py @@ -15,20 +15,15 @@ import click import functest.ci.tier_builder as tb import functest.utils.functest_utils as ft_utils - - -FUNCTEST_CONF_DIR = \ - ft_utils.get_functest_config('general.directories.dir_functest_conf') -ENV_FILE = FUNCTEST_CONF_DIR + "/env_active" -FUNCTEST_REPO = ft_utils.FUNCTEST_REPO +import functest.utils.functest_constants as ft_constants class CliTier: def __init__(self): - CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') - CI_SCENARIO = os.getenv('DEPLOY_SCENARIO') - testcases = ft_utils.get_testcases_file() + CI_INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE + CI_SCENARIO = ft_constants.CI_SCENARIO + testcases = ft_constants.FUNCTEST_TESTCASES_YAML self.tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, testcases) def list(self): @@ -60,14 +55,14 @@ class CliTier: click.echo("Test cases in tier '%s':\n %s\n" % (tiername, tests)) def run(self, tiername, noclean=False): - if not os.path.isfile(ENV_FILE): + if not os.path.isfile(ft_constants.ENV_FILE): click.echo("Functest environment is not ready. " "Run first 'functest env prepare'") else: if noclean: cmd = ("python %s/functest/ci/run_tests.py " - "-n -t %s" % (FUNCTEST_REPO, tiername)) + "-n -t %s" % (ft_constants.FUNCTEST_REPO_DIR, tiername)) else: cmd = ("python %s/functest/ci/run_tests.py " - "-t %s" % (FUNCTEST_REPO, tiername)) + "-t %s" % (ft_constants.FUNCTEST_REPO_DIR, tiername)) ft_utils.execute_command(cmd) diff --git a/functest/core/TestCasesBase.py b/functest/core/TestCasesBase.py index ab1ad0d5..e1c002d4 100644 --- a/functest/core/TestCasesBase.py +++ b/functest/core/TestCasesBase.py @@ -11,6 +11,7 @@ import os import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils +import functest.utils.functest_constants as ft_constants class TestCasesBase(object): @@ -23,7 +24,7 @@ class TestCasesBase(object): logger = ft_logger.Logger(__name__).getLogger() def __init__(self): - self.functest_repo = ft_utils.FUNCTEST_REPO + self.functest_repo = ft_constants.FUNCTEST_REPO_DIR self.details = {} self.project_name = "functest" self.case_name = "" diff --git a/functest/opnfv_tests/Controllers/ODL/OpenDaylightTesting.py b/functest/opnfv_tests/Controllers/ODL/OpenDaylightTesting.py index 8c003abf..0ddb58cd 100755 --- a/functest/opnfv_tests/Controllers/ODL/OpenDaylightTesting.py +++ b/functest/opnfv_tests/Controllers/ODL/OpenDaylightTesting.py @@ -23,6 +23,7 @@ from robot.utils.robottime import timestamp_to_secs from functest.core import TestCasesBase import functest.utils.functest_logger as ft_logger import functest.utils.openstack_utils as op_utils +import functest.utils.functest_constants as ft_constants class ODLResultVisitor(ResultVisitor): @@ -48,11 +49,14 @@ class ODLResultVisitor(ResultVisitor): class ODLTestCases(TestCasesBase.TestCasesBase): - repos = "/home/opnfv/repos/" - odl_test_repo = repos + "odl_test/" - neutron_suite_dir = odl_test_repo + "csit/suites/openstack/neutron/" - basic_suite_dir = odl_test_repo + "csit/suites/integration/basic/" - res_dir = '/home/opnfv/functest/results/odl/' + repos = ft_constants.REPOS_DIR + odl_test_repo = os.path.join(repos, "odl_test") + neutron_suite_dir = os.path.join(odl_test_repo, + "csit/suites/openstack/neutron") + basic_suite_dir = os.path.join(odl_test_repo, + "csit/suites/integration/basic") + res_dir = os.path.join(ft_constants.FUNCTEST_RESULTS_DIR, "odl") + logger = ft_logger.Logger("opendaylight").getLogger() def __init__(self): @@ -60,7 +64,8 @@ class ODLTestCases(TestCasesBase.TestCasesBase): @classmethod def set_robotframework_vars(cls, odlusername="admin", odlpassword="admin"): - odl_variables_files = cls.odl_test_repo + 'csit/variables/Variables.py' + odl_variables_files = os.path.join(cls.odl_test_repo, + 'csit/variables/Variables.py') try: for line in fileinput.input(odl_variables_files, inplace=True): @@ -74,7 +79,8 @@ class ODLTestCases(TestCasesBase.TestCasesBase): return False def parse_results(self): - result = ExecutionResult(self.res_dir + 'output.xml') + output_dir = os.path.join(self.res_dir, 'output.xml') + result = ExecutionResult(output_dir) visitor = ODLResultVisitor() result.visit(visitor) self.criteria = result.suite.status @@ -109,10 +115,11 @@ class ODLTestCases(TestCasesBase.TestCasesBase): self.logger.exception( "Cannot create {}".format(self.res_dir)) return self.EX_RUN_ERROR - stdout_file = self.res_dir + 'stdout.txt' + stdout_file = os.path.join(self.res_dir, 'stdout.txt') + output_dir = os.path.join(self.res_dir, 'output.xml') with open(stdout_file, 'w+') as stdout: robot.run(*dirs, variable=variables, - output=self.res_dir + 'output.xml', + output=output_dir, log='NONE', report='NONE', stdout=stdout) @@ -148,23 +155,29 @@ class ODLTestCases(TestCasesBase.TestCasesBase): kwargs['odlrestconfport'] = '8181' kwargs['odlusername'] = 'admin' kwargs['odlpassword'] = 'admin' - installer_type = None - if 'INSTALLER_TYPE' in os.environ: - installer_type = os.environ['INSTALLER_TYPE'] - kwargs['osusername'] = os.environ['OS_USERNAME'] - kwargs['ostenantname'] = os.environ['OS_TENANT_NAME'] - kwargs['ospassword'] = os.environ['OS_PASSWORD'] + + installer_type = ft_constants.CI_INSTALLER_TYPE + kwargs['osusername'] = ft_constants.OS_USERNAME + kwargs['ostenantname'] = ft_constants.OS_TENANT_NAME + kwargs['ospassword'] = ft_constants.OS_PASSWORD + if installer_type == 'fuel': kwargs['odlwebport'] = '8282' elif installer_type == 'apex': - kwargs['odlip'] = os.environ['SDN_CONTROLLER_IP'] + if ft_constants.SDN_CONTROLLER_IP is None: + return self.EX_RUN_ERROR + kwargs['odlip'] = ft_constants.SDN_CONTROLLER_IP kwargs['odlwebport'] = '8181' elif installer_type == 'joid': - kwargs['odlip'] = os.environ['SDN_CONTROLLER'] + if ft_constants.SDN_CONTROLLER is None: + return self.EX_RUN_ERROR + kwargs['odlip'] = ft_constants.SDN_CONTROLLER elif installer_type == 'compass': kwargs['odlwebport'] = '8181' else: - kwargs['odlip'] = os.environ['SDN_CONTROLLER_IP'] + if ft_constants.SDN_CONTROLLER_IP is None: + return self.EX_RUN_ERROR + kwargs['odlip'] = ft_constants.SDN_CONTROLLER_IP except KeyError as e: self.logger.error("Cannot run ODL testcases. " "Please check env var: " @@ -176,6 +189,7 @@ class ODLTestCases(TestCasesBase.TestCasesBase): return self.main(**kwargs) + if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-k', '--keystoneip', diff --git a/functest/opnfv_tests/Controllers/ONOS/Sfc/Sfc.py b/functest/opnfv_tests/Controllers/ONOS/Sfc/Sfc.py index bea2828d..e3f08041 100755 --- a/functest/opnfv_tests/Controllers/ONOS/Sfc/Sfc.py +++ b/functest/opnfv_tests/Controllers/ONOS/Sfc/Sfc.py @@ -25,7 +25,7 @@ import time import functest.utils.functest_logger as ft_logger -import functest.utils.functest_utils as functest_utils +import functest.utils.functest_utils as ft_utils from Sfc_fun import Sfc_fun logger = ft_logger.Logger("sfc").getLogger() @@ -81,7 +81,7 @@ def ConfigSfc(): logger.info( "Testcase 4 : Configure Port Chain and verify flows are added") logger.info("4.1 Creation of Port Chain") - check(Sfc_obj.createPortChain, CREATED, "Creation of Port Chain") + check(Sfc_obj.createPortChain, CREATED, "Creation of Port Chain") def VerifySfcTraffic(): @@ -152,13 +152,13 @@ def PushDB(status, info): # ONOS SFC success criteria = all tests OK duration = round(stop_time - start_time, 1) logger.info("Result is " + status) - functest_utils.push_results_to_db("functest", - "onos_sfc", - start_time, - stop_time, - status, - details={'duration': duration, - 'error': info}) + ft_utils.push_results_to_db("functest", + "onos_sfc", + start_time, + stop_time, + status, + details={'duration': duration, + 'error': info}) except: logger.error("Error pushing results into Database") diff --git a/functest/opnfv_tests/Controllers/ONOS/Teston/adapters/environment.py b/functest/opnfv_tests/Controllers/ONOS/Teston/adapters/environment.py index f2755b66..01f70b85 100644 --- a/functest/opnfv_tests/Controllers/ONOS/Teston/adapters/environment.py +++ b/functest/opnfv_tests/Controllers/ONOS/Teston/adapters/environment.py @@ -141,8 +141,8 @@ class environment(connection): result = self.CheckSshNoPasswd(host) if not result: self.logger.info( - "ssh login failed,try to copy master publickey" + - "to agent " + str(host)) + "ssh login failed,try to copy master publickey" + + "to agent " + str(host)) self.CopyPublicKey(host) self.OnosPushKeys(handle, "onos-push-keys " + self.OCT, masterpass) self.OnosPushKeys(handle, "onos-push-keys " + self.OC1, agentpass) diff --git a/functest/opnfv_tests/Controllers/ONOS/Teston/adapters/foundation.py b/functest/opnfv_tests/Controllers/ONOS/Teston/adapters/foundation.py index 603e9933..6f7a40ff 100644 --- a/functest/opnfv_tests/Controllers/ONOS/Teston/adapters/foundation.py +++ b/functest/opnfv_tests/Controllers/ONOS/Teston/adapters/foundation.py @@ -17,6 +17,7 @@ import os import re import time +import functest.utils.functest_constants as ft_constants import functest.utils.functest_utils as ft_utils @@ -25,8 +26,8 @@ class foundation: def __init__(self): # currentpath = os.getcwd() - REPO_PATH = ft_utils.FUNCTEST_REPO + '/' - currentpath = REPO_PATH + 'opnfv_tests/Controllers/ONOS/Teston/CI' + currentpath = \ + ft_constants.FUNCTEST_TEST_DIR + '/Controllers/ONOS/Teston/CI' self.cipath = currentpath self.logdir = os.path.join(currentpath, 'log') self.workhome = currentpath[0: currentpath.rfind('opnfv_tests') - 1] @@ -54,30 +55,23 @@ class foundation: """ Get Default Parameters value """ - self.Result_DB = str( - ft_utils.get_functest_config('results.test_db_url')) - self.masterusername = str( - ft_utils.get_functest_config('ONOS.general.onosbench_username')) - self.masterpassword = str( - ft_utils.get_functest_config('ONOS.general.onosbench_password')) - self.agentusername = str( - ft_utils.get_functest_config('ONOS.general.onoscli_username')) - self.agentpassword = str( - ft_utils.get_functest_config('ONOS.general.onoscli_password')) - self.runtimeout = \ - ft_utils.get_functest_config('ONOS.general.runtimeout') - self.OCT = str(ft_utils.get_functest_config('ONOS.environment.OCT')) - self.OC1 = str(ft_utils.get_functest_config('ONOS.environment.OC1')) - self.OC2 = str(ft_utils.get_functest_config('ONOS.environment.OC2')) - self.OC3 = str(ft_utils.get_functest_config('ONOS.environment.OC3')) - self.OCN = str(ft_utils.get_functest_config('ONOS.environment.OCN')) - self.OCN2 = str(ft_utils.get_functest_config('ONOS.environment.OCN2')) - self.installer_master = str( - ft_utils.get_functest_config('ONOS.environment.installer_master')) - self.installer_master_username = str(ft_utils.get_functest_config( - 'ONOS.environment.installer_master_username')) - self.installer_master_password = str(ft_utils.get_functest_config( - 'ONOS.environment.installer_master_password')) + self.Result_DB = str(ft_utils.get_db_url()) + self.masterusername = str(ft_constants.ONOSBENCH_USERNAME) + self.masterpassword = str(ft_constants.ONOSBENCH_PASSWORD) + self.agentusername = str(ft_constants.ONOSCLI_USERNAME) + self.agentpassword = str(ft_constants.ONOSCLI_PASSWORD) + self.runtimeout = ft_constants.ONOS_RUNTIMEOUT + self.OCT = str(ft_constants.ONOS_OCT) + self.OC1 = str(ft_constants.ONOS_OC1) + self.OC2 = str(ft_constants.ONOS_OC2) + self.OC3 = str(ft_constants.ONOS_OC3) + self.OCN = str(ft_constants.ONOS_OCN) + self.OCN2 = str(ft_constants.ONOS_OCN2) + self.installer_master = str(ft_constants.ONOS_INSTALLER_MASTER) + self.installer_master_username = \ + str(ft_constants.ONOS_INSTALLER_MASTER_USERNAME) + self.installer_master_password = \ + ft_constants.ONOS_INSTALLER_MASTER_PASSWORD self.hosts = [self.OC1, self.OCN, self.OCN2] self.localhost = self.OCT diff --git a/functest/opnfv_tests/Controllers/ONOS/Teston/onosfunctest.py b/functest/opnfv_tests/Controllers/ONOS/Teston/onosfunctest.py index c8045fd1..300f56d1 100755 --- a/functest/opnfv_tests/Controllers/ONOS/Teston/onosfunctest.py +++ b/functest/opnfv_tests/Controllers/ONOS/Teston/onosfunctest.py @@ -25,6 +25,8 @@ from neutronclient.v2_0 import client as neutronclient import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils import functest.utils.openstack_utils as openstack_utils +import functest.utils.functest_constants as ft_constants + parser = argparse.ArgumentParser() parser.add_argument("-t", "--testcase", help="Testcase name") @@ -35,27 +37,15 @@ args = parser.parse_args() logger = ft_logger.Logger("onos").getLogger() # onos parameters -TEST_DB = ft_utils.get_functest_config("results.test_db_url") -ONOS_REPO_PATH = \ - ft_utils.get_functest_config("general.directories.dir_repos") -ONOS_CONF_DIR = \ - ft_utils.get_functest_config("general.directories.dir_functest_conf") - -ONOSCI_PATH = ONOS_REPO_PATH + "/" +ONOSCI_PATH = ft_constants.REPOS_DIR + "/" starttime = datetime.datetime.now() -HOME = os.environ['HOME'] + "/" -INSTALLER_TYPE = os.environ['INSTALLER_TYPE'] -DEPLOY_SCENARIO = os.environ['DEPLOY_SCENARIO'] -ONOSCI_PATH = ONOS_REPO_PATH + "/" -GLANCE_IMAGE_NAME = ft_utils.get_functest_config("onos_sfc.image_name") -GLANCE_IMAGE_FILENAME = \ - ft_utils.get_functest_config("onos_sfc.image_file_name") -GLANCE_IMAGE_PATH = \ - ft_utils.get_functest_config("general.directories.dir_functest_data") + \ - "/" + GLANCE_IMAGE_FILENAME -SFC_PATH = ft_utils.FUNCTEST_REPO + "/" + \ - ft_utils.get_functest_config("general.directories.dir_onos_sfc") +INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE +ONOS_SFC_IMAGE_NAME = ft_constants.ONOS_SFC_IMAGE_NAME +ONOS_SFC_IMAGE_PATH = os.path.join(ft_constants.FUNCTEST_DATA_DIR, + ft_constants.ONOS_SFC_IMAGE_FILENAME) +ONOS_SFC_PATH = os.path.join(ft_constants.FUNCTEST_REPO_DIR, + ft_constants.ONOS_SFC_RELATIVE_PATH) def RunScript(testname): @@ -173,18 +163,18 @@ def CleanOnosTest(): def CreateImage(): glance_client = openstack_utils.get_glance_client() image_id = openstack_utils.create_glance_image(glance_client, - GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH) + ONOS_SFC_IMAGE_NAME, + ONOS_SFC_IMAGE_PATH) EXIT_CODE = -1 if not image_id: logger.error("Failed to create a Glance image...") return(EXIT_CODE) logger.debug("Image '%s' with ID=%s created successfully." - % (GLANCE_IMAGE_NAME, image_id)) + % (ONOS_SFC_IMAGE_NAME, image_id)) def SfcTest(): - cmd = "python " + SFC_PATH + "Sfc.py" + cmd = "python " + ONOS_SFC_PATH + "/Sfc.py" logger.debug("Run sfc tests") os.system(cmd) @@ -197,8 +187,8 @@ def GetIp(type): def Replace(before, after): - file = "Sfc_fun.py" - cmd = "sed -i 's/" + before + "/" + after + "/g' " + SFC_PATH + file + file = "/Sfc_fun.py" + cmd = "sed -i 's/" + before + "/" + after + "/g' " + ONOS_SFC_PATH + file os.system(cmd) @@ -207,7 +197,7 @@ def SetSfcConf(): Replace("neutron_ip", GetIp("neutron")) Replace("nova_ip", GetIp("nova")) Replace("glance_ip", GetIp("glance")) - pwd = os.environ['OS_PASSWORD'] + pwd = ft_constants.OS_PASSWORD Replace("console", pwd) creds_neutron = openstack_utils.get_credentials("neutron") neutron_client = neutronclient.Client(**creds_neutron) @@ -266,5 +256,6 @@ def main(): else: OnosTest() + if __name__ == '__main__': main() diff --git a/functest/opnfv_tests/OpenStack/examples/create_instance_and_ip.py b/functest/opnfv_tests/OpenStack/examples/create_instance_and_ip.py index 50cdf8a5..6a2abe60 100755 --- a/functest/opnfv_tests/OpenStack/examples/create_instance_and_ip.py +++ b/functest/opnfv_tests/OpenStack/examples/create_instance_and_ip.py @@ -11,11 +11,10 @@ # import argparse -import os import sys 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 parser = argparse.ArgumentParser() @@ -28,34 +27,27 @@ args = parser.parse_args() """ logging configuration """ logger = ft_logger.Logger("create_instance_and_ip").getLogger() -HOME = os.environ['HOME'] + "/" +HOME = ft_constants.HOME + "/" VM_BOOT_TIMEOUT = 180 -INSTANCE_NAME = ft_utils.get_functest_config("example.example_vm_name") -FLAVOR = ft_utils.get_functest_config("example.example_flavor") -IMAGE_NAME = ft_utils.get_functest_config("example.example_image_name") -IMAGE_FILENAME = \ - ft_utils.get_functest_config("general.openstack.image_file_name") -IMAGE_FORMAT = \ - ft_utils.get_functest_config("general.openstack.image_disk_format") -IMAGE_PATH = \ - ft_utils.get_functest_config("general.directories.dir_functest_data") + \ +EXAMPLE_INSTANCE_NAME = ft_constants.EXAMPLE_INSTANCE_NAME +EXAMPLE_FLAVOR = ft_constants.EXAMPLE_FLAVOR +EXAMPLE_IMAGE_NAME = ft_constants.EXAMPLE_IMAGE_NAME +IMAGE_FILENAME = ft_constants.GLANCE_IMAGE_FILENAME +IMAGE_FORMAT = ft_constants.GLANCE_IMAGE_FORMAT +IMAGE_PATH = ft_constants.FUNCTEST_DATA_DIR + \ "/" + IMAGE_FILENAME # NEUTRON Private Network parameters -NET_NAME = ft_utils.get_functest_config("example.example_private_net_name") -SUBNET_NAME = \ - ft_utils.get_functest_config("example.example_private_subnet_name") -SUBNET_CIDR = \ - ft_utils.get_functest_config("example.example_private_subnet_cidr") -ROUTER_NAME = ft_utils.get_functest_config("example.example_router_name") +EXAMPLE_PRIVATE_NET_NAME = ft_constants.EXAMPLE_PRIVATE_NET_NAME +EXAMPLE_PRIVATE_SUBNET_NAME = ft_constants.EXAMPLE_PRIVATE_SUBNET_NAME +EXAMPLE_PRIVATE_SUBNET_CIDR = ft_constants.EXAMPLE_PRIVATE_SUBNET_CIDR +EXAMPLE_ROUTER_NAME = ft_constants.EXAMPLE_ROUTER_NAME -SECGROUP_NAME = ft_utils.get_functest_config("example.example_sg_name") -SECGROUP_DESCR = ft_utils.get_functest_config("example.example_sg_descr") - -TEST_DB = ft_utils.get_functest_config("results.test_db_url") +EXAMPLE_SECGROUP_NAME = ft_constants.EXAMPLE_SECGROUP_NAME +EXAMPLE_SECGROUP_DESCR = ft_constants.EXAMPLE_SECGROUP_DESCR def main(): @@ -65,17 +57,17 @@ def main(): glance_client = os_utils.get_glance_client() image_id = os_utils.create_glance_image(glance_client, - IMAGE_NAME, + EXAMPLE_IMAGE_NAME, IMAGE_PATH, disk=IMAGE_FORMAT, container="bare", public=True) network_dic = os_utils.create_network_full(neutron_client, - NET_NAME, - SUBNET_NAME, - ROUTER_NAME, - SUBNET_CIDR) + EXAMPLE_PRIVATE_NET_NAME, + EXAMPLE_PRIVATE_SUBNET_NAME, + EXAMPLE_ROUTER_NAME, + EXAMPLE_PRIVATE_SUBNET_CIDR) if not network_dic: logger.error( "There has been a problem when creating the neutron network") @@ -84,31 +76,34 @@ def main(): network_id = network_dic["net_id"] sg_id = os_utils.create_security_group_full(neutron_client, - SECGROUP_NAME, SECGROUP_DESCR) + EXAMPLE_SECGROUP_NAME, + EXAMPLE_SECGROUP_DESCR) # boot INTANCE - logger.info("Creating instance '%s'..." % INSTANCE_NAME) + logger.info("Creating instance '%s'..." % EXAMPLE_INSTANCE_NAME) logger.debug( "Configuration:\n name=%s \n flavor=%s \n image=%s \n " - "network=%s \n" % (INSTANCE_NAME, FLAVOR, image_id, network_id)) - instance = os_utils.create_instance_and_wait_for_active(FLAVOR, - image_id, - network_id, - INSTANCE_NAME) + "network=%s \n" + % (EXAMPLE_INSTANCE_NAME, EXAMPLE_FLAVOR, image_id, network_id)) + instance = \ + os_utils.create_instance_and_wait_for_active(EXAMPLE_FLAVOR, + image_id, + network_id, + EXAMPLE_INSTANCE_NAME) if instance is None: logger.error("Error while booting instance.") sys.exit(-1) # Retrieve IP of INSTANCE - instance_ip = instance.networks.get(NET_NAME)[0] + instance_ip = instance.networks.get(EXAMPLE_PRIVATE_NET_NAME)[0] logger.debug("Instance '%s' got private ip '%s'." % - (INSTANCE_NAME, instance_ip)) + (EXAMPLE_INSTANCE_NAME, instance_ip)) logger.info("Adding '%s' to security group '%s'..." - % (INSTANCE_NAME, SECGROUP_NAME)) + % (EXAMPLE_INSTANCE_NAME, EXAMPLE_SECGROUP_NAME)) os_utils.add_secgroup_to_instance(nova_client, instance.id, sg_id) - logger.info("Creating floating IP for VM '%s'..." % INSTANCE_NAME) + logger.info("Creating floating IP for VM '%s'..." % EXAMPLE_INSTANCE_NAME) floatip_dic = os_utils.create_floating_ip(neutron_client) floatip = floatip_dic['fip_addr'] # floatip_id = floatip_dic['fip_id'] @@ -119,12 +114,13 @@ def main(): logger.info("Floating IP created: '%s'" % floatip) logger.info("Associating floating ip: '%s' to VM '%s' " - % (floatip, INSTANCE_NAME)) + % (floatip, EXAMPLE_INSTANCE_NAME)) if not os_utils.add_floating_ip(nova_client, instance.id, floatip): logger.error("Cannot associate floating IP to VM.") sys.exit(-1) sys.exit(0) + if __name__ == '__main__': main() diff --git a/functest/opnfv_tests/OpenStack/rally/run_rally-cert.py b/functest/opnfv_tests/OpenStack/rally/run_rally-cert.py index 8b8adce4..6d8f0160 100755 --- a/functest/opnfv_tests/OpenStack/rally/run_rally-cert.py +++ b/functest/opnfv_tests/OpenStack/rally/run_rally-cert.py @@ -28,6 +28,7 @@ import yaml 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'] @@ -61,7 +62,6 @@ parser.add_argument("-z", "--sanity", args = parser.parse_args() -network_dict = {} if args.verbose: RALLY_STDERR = subprocess.STDOUT @@ -69,18 +69,17 @@ else: RALLY_STDERR = open(os.devnull, 'w') """ logging configuration """ -logger = ft_logger.Logger("run_rally").getLogger() - - -HOME = os.environ['HOME'] + "/" -RALLY_DIR = ft_utils.FUNCTEST_REPO + '/' + \ - ft_utils.get_functest_config('general.directories.dir_rally') -SANITY_MODE_DIR = RALLY_DIR + "scenario/sanity" -FULL_MODE_DIR = RALLY_DIR + "scenario/full" -TEMPLATE_DIR = RALLY_DIR + "scenario/templates" -SUPPORT_DIR = RALLY_DIR + "scenario/support" -TEMP_DIR = RALLY_DIR + "var" -BLACKLIST_FILE = RALLY_DIR + "blacklist.txt" +logger = ft_logger.Logger("run_rally-cert").getLogger() + +RALLY_DIR = os.path.join(ft_constants.FUNCTEST_REPO_DIR, + ft_constants.RALLY_RELATIVE_PATH) +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") +TEMPLATE_DIR = os.path.join(RALLY_SCENARIO_DIR, "templates") +SUPPORT_DIR = os.path.join(RALLY_SCENARIO_DIR, "support") +TEMP_DIR = os.path.join(RALLY_DIR, "var") +BLACKLIST_FILE = os.path.join(RALLY_DIR, "blacklist.txt") FLAVOR_NAME = "m1.tiny" USERS_AMOUNT = 2 @@ -88,33 +87,27 @@ TENANTS_AMOUNT = 3 ITERATIONS_AMOUNT = 10 CONCURRENCY = 4 -RESULTS_DIR = \ - ft_utils.get_functest_config('general.directories.dir_rally_res') -TEMPEST_CONF_FILE = \ - ft_utils.get_functest_config('general.directories.dir_results') + \ - '/tempest/tempest.conf' -TEST_DB = ft_utils.get_functest_config('results.test_db_url') - -PRIVATE_NET_NAME = ft_utils.get_functest_config('rally.network_name') -PRIVATE_SUBNET_NAME = ft_utils.get_functest_config('rally.subnet_name') -PRIVATE_SUBNET_CIDR = ft_utils.get_functest_config('rally.subnet_cidr') -ROUTER_NAME = ft_utils.get_functest_config('rally.router_name') - -GLANCE_IMAGE_NAME = \ - ft_utils.get_functest_config('general.openstack.image_name') -GLANCE_IMAGE_FILENAME = \ - ft_utils.get_functest_config('general.openstack.image_file_name') -GLANCE_IMAGE_FORMAT = \ - ft_utils.get_functest_config('general.openstack.image_disk_format') -GLANCE_IMAGE_PATH = \ - ft_utils.get_functest_config('general.directories.dir_functest_data') + \ - "/" + GLANCE_IMAGE_FILENAME +RESULTS_DIR = os.path.join(ft_constants.FUNCTEST_RESULTS_DIR, 'rally') +TEMPEST_CONF_FILE = os.path.join(ft_constants.FUNCTEST_RESULTS_DIR, + '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 + +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_FILENAME) CINDER_VOLUME_TYPE_NAME = "volume_test" -SUMMARY = [] -neutron_client = None +class GlobalVariables: + SUMMARY = [] + neutron_client = None + network_dict = {} def get_task_id(cmd_raw): @@ -179,16 +172,16 @@ def build_task_args(test_file_name): else: task_args['smoke'] = args.smoke - ext_net = os_utils.get_external_net(neutron_client) + ext_net = os_utils.get_external_net(GlobalVariables.neutron_client) if ext_net: task_args['floating_network'] = str(ext_net) else: task_args['floating_network'] = '' - net_id = network_dict['net_id'] + net_id = GlobalVariables.network_dict['net_id'] task_args['netid'] = str(net_id) - auth_url = os.getenv('OS_AUTH_URL') + auth_url = ft_constants.OS_AUTH_URL if auth_url is not None: task_args['request_url'] = auth_url.rsplit(":", 1)[0] else: @@ -198,7 +191,6 @@ def build_task_args(test_file_name): def get_output(proc, test_name): - global SUMMARY result = "" nb_tests = 0 overall_duration = 0.0 @@ -255,7 +247,7 @@ def get_output(proc, test_name): 'overall_duration': overall_duration, 'nb_tests': nb_tests, 'success': success_avg} - SUMMARY.append(scenario_summary) + GlobalVariables.SUMMARY.append(scenario_summary) logger.debug("\n" + result) @@ -279,8 +271,8 @@ def excl_scenario(): with open(BLACKLIST_FILE, 'r') as black_list_file: black_list_yaml = yaml.safe_load(black_list_file) - installer_type = os.getenv('INSTALLER_TYPE') - deploy_scenario = os.getenv('DEPLOY_SCENARIO') + installer_type = ft_constants.CI_INSTALLER_TYPE + deploy_scenario = ft_constants.CI_SCENARIO if (bool(installer_type) * bool(deploy_scenario)): if 'scenario' in black_list_yaml.keys(): for item in black_list_yaml['scenario']: @@ -345,22 +337,24 @@ def apply_blacklist(case_file_name, result_file_name): def prepare_test_list(test_name): - scenario_file_name = '{}opnfv-{}.yaml'.format(RALLY_DIR + "scenario/", - test_name) + test_yaml_file_name = 'opnfv-{}.yaml'.format(test_name) + scenario_file_name = os.path.join(RALLY_SCENARIO_DIR, test_yaml_file_name) + if not os.path.exists(scenario_file_name): if args.sanity: - scenario_file_name = '{}opnfv-{}.yaml'.format(SANITY_MODE_DIR + - "/", test_name) + scenario_file_name = os.path.join(SANITY_MODE_DIR, + test_yaml_file_name) else: - scenario_file_name = '{}opnfv-{}.yaml'.format(FULL_MODE_DIR + - "/", test_name) + scenario_file_name = os.path.join(FULL_MODE_DIR, + test_yaml_file_name) + if not os.path.exists(scenario_file_name): logger.info("The scenario '%s' does not exist." % scenario_file_name) exit(-1) logger.debug('Scenario fetched from : {}'.format(scenario_file_name)) - test_file_name = '{}opnfv-{}.yaml'.format(TEMP_DIR + "/", test_name) + test_file_name = os.path.join(TEMP_DIR, test_yaml_file_name) if not os.path.exists(TEMP_DIR): os.makedirs(TEMP_DIR) @@ -385,11 +379,10 @@ def run_task(test_name): # :param test_name: name for the rally test # :return: void # - global SUMMARY logger.info('Starting test scenario "{}" ...'.format(test_name)) start_time = time.time() - task_file = '{}task.yaml'.format(RALLY_DIR) + task_file = os.path.join(RALLY_DIR, 'task.yaml') if not os.path.exists(task_file): logger.error("Task file '%s' does not exist." % task_file) exit(-1) @@ -428,9 +421,10 @@ def run_task(test_name): os.makedirs(RESULTS_DIR) # write html report file - report_file_name = '{}opnfv-{}.html'.format(RESULTS_DIR, test_name) + report_html_name = 'opnfv-{}.html'.format(test_name) + report_html_dir = os.path.join(RESULTS_DIR, report_html_name) cmd_line = "rally task report {} --out {}".format(task_id, - report_file_name) + report_html_dir) logger.debug('running command line : {}'.format(cmd_line)) os.popen(cmd_line) @@ -440,12 +434,13 @@ def run_task(test_name): logger.debug('running command line : {}'.format(cmd_line)) cmd = os.popen(cmd_line) json_results = cmd.read() - with open('{}opnfv-{}.json'.format(RESULTS_DIR, test_name), 'w') as f: + report_json_name = 'opnfv-{}.json'.format(test_name) + report_json_dir = os.path.join(RESULTS_DIR, report_json_name) + with open(report_json_dir, 'w') as f: logger.debug('saving json file') f.write(json_results) - with open('{}opnfv-{}.json' - .format(RESULTS_DIR, test_name)) as json_file: + with open(report_json_dir) as json_file: json_data = json.load(json_file) """ parse JSON operation result """ @@ -469,12 +464,9 @@ def run_task(test_name): def main(): - global SUMMARY - global network_dict - global neutron_client - nova_client = os_utils.get_nova_client() - neutron_client = os_utils.get_neutron_client() + GlobalVariables.nova_client = os_utils.get_nova_client() + GlobalVariables.neutron_client = os_utils.get_neutron_client() cinder_client = os_utils.get_cinder_client() start_time = time.time() @@ -484,7 +476,7 @@ def main(): logger.error('argument not valid') exit(-1) - SUMMARY = [] + GlobalVariables.SUMMARY = [] volume_types = os_utils.list_volume_types(cinder_client, private=False) @@ -506,12 +498,13 @@ def main(): if not image_id: exit(-1) - logger.debug("Creating network '%s'..." % PRIVATE_NET_NAME) - network_dict = os_utils.create_shared_network_full(PRIVATE_NET_NAME, - PRIVATE_SUBNET_NAME, - ROUTER_NAME, - PRIVATE_SUBNET_CIDR) - if not network_dict: + logger.debug("Creating network '%s'..." % RALLY_PRIVATE_NET_NAME) + GlobalVariables.network_dict = \ + os_utils.create_shared_network_full(RALLY_PRIVATE_NET_NAME, + RALLY_PRIVATE_SUBNET_NAME, + RALLY_ROUTER_NAME, + RALLY_PRIVATE_SUBNET_CIDR) + if not GlobalVariables.network_dict: exit(1) if args.test_name == "all": @@ -541,7 +534,7 @@ def main(): total_duration = 0.0 total_nb_tests = 0 total_success = 0.0 - for s in SUMMARY: + for s in GlobalVariables.SUMMARY: name = "{0:<17}".format(s['test_name']) duration = float(s['overall_duration']) total_duration += duration @@ -565,8 +558,8 @@ def main(): total_duration_str2 = "{0:<10}".format(total_duration_str) total_nb_tests_str = "{0:<13}".format(total_nb_tests) - if len(SUMMARY): - success_rate = total_success / len(SUMMARY) + if len(GlobalVariables.SUMMARY): + success_rate = total_success / len(GlobalVariables.SUMMARY) else: success_rate = 100 success_rate = "{:0.2f}".format(success_rate) @@ -609,7 +602,8 @@ def main(): if not image_exists: logger.debug("Deleting image '%s' with ID '%s'..." % (GLANCE_IMAGE_NAME, image_id)) - if not os_utils.delete_glance_image(nova_client, image_id): + if not os_utils.delete_glance_image(GlobalVariables.nova_client, + image_id): logger.error("Error deleting the glance image") if not volume_types: diff --git a/functest/opnfv_tests/OpenStack/tempest/gen_tempest_conf.py b/functest/opnfv_tests/OpenStack/tempest/gen_tempest_conf.py index ca671d00..8e298d36 100755 --- a/functest/opnfv_tests/OpenStack/tempest/gen_tempest_conf.py +++ b/functest/opnfv_tests/OpenStack/tempest/gen_tempest_conf.py @@ -18,8 +18,12 @@ import functest.utils.functest_utils as ft_utils import functest.utils.functest_logger as ft_logger from run_tempest import configure_tempest from run_tempest import TEMPEST_RESULTS_DIR +import functest.utils.functest_constants as ft_constants -logger = ft_logger.Logger("multisite").getLogger() +logger = ft_logger.Logger("gen_tempest_conf").getLogger() + +CI_INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE +CI_INSTALLER_IP = ft_constants.CI_INSTALLER_IP def configure_tempest_multisite(deployment_dir): @@ -30,16 +34,16 @@ def configure_tempest_multisite(deployment_dir): configure_tempest(deployment_dir) logger.debug("Finding tempest.conf file...") - tempest_conf_file = deployment_dir + "/tempest.conf" - if not os.path.isfile(tempest_conf_file): + tempest_conf_old = os.path.join(deployment_dir, '/tempest.conf') + if not os.path.isfile(tempest_conf_old): logger.error("Tempest configuration file %s NOT found." - % tempest_conf_file) + % tempest_conf_old) exit(-1) # Copy tempest.conf to /home/opnfv/functest/results/tempest/ cur_path = os.path.split(os.path.realpath(__file__))[0] - shutil.copyfile(tempest_conf_file, cur_path + '/tempest_multisite.conf') - tempest_conf_file = cur_path + "/tempest_multisite.conf" + tempest_conf_file = os.path.join(cur_path, '/tempest_multisite.conf') + shutil.copyfile(tempest_conf_old, tempest_conf_file) logger.debug("Updating selected tempest.conf parameters...") config = ConfigParser.RawConfigParser() @@ -49,12 +53,12 @@ def configure_tempest_multisite(deployment_dir): cmd = "openstack endpoint show kingbird | grep publicurl |\ awk '{print $4}' | awk -F '/' '{print $4}'" kingbird_api_version = os.popen(cmd).read() - if os.environ.get("INSTALLER_TYPE") == 'fuel': + if CI_INSTALLER_TYPE == 'fuel': # For MOS based setup, the service is accessible # via bind host kingbird_conf_path = "/etc/kingbird/kingbird.conf" - installer_type = os.getenv('INSTALLER_TYPE', 'Unknown') - installer_ip = os.getenv('INSTALLER_IP', 'Unknown') + installer_type = CI_INSTALLER_TYPE + installer_ip = CI_INSTALLER_IP installer_username = ft_utils.get_functest_config( "multisite." + installer_type + "_environment.installer_username") diff --git a/functest/opnfv_tests/OpenStack/tempest/run_tempest.py b/functest/opnfv_tests/OpenStack/tempest/run_tempest.py index d2c01c60..cbf92c1f 100755 --- a/functest/opnfv_tests/OpenStack/tempest/run_tempest.py +++ b/functest/opnfv_tests/OpenStack/tempest/run_tempest.py @@ -27,6 +27,7 @@ import yaml 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 modes = ['full', 'smoke', 'baremetal', 'compute', 'data_processing', 'identity', 'image', 'network', 'object_storage', 'orchestration', @@ -58,69 +59,50 @@ args = parser.parse_args() """ logging configuration """ logger = ft_logger.Logger("run_tempest").getLogger() -TEST_DB = ft_utils.get_functest_config('results.test_db_url') - -MODE = "smoke" -GLANCE_IMAGE_NAME = \ - ft_utils.get_functest_config('general.openstack.image_name') -GLANCE_IMAGE_FILENAME = \ - ft_utils.get_functest_config('general.openstack.image_file_name') -GLANCE_IMAGE_FORMAT = \ - ft_utils.get_functest_config('general.openstack.image_disk_format') -GLANCE_IMAGE_PATH = \ - ft_utils.get_functest_config('general.directories.dir_functest_data') + \ +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 = ft_constants.FUNCTEST_DATA_DIR + \ "/" + GLANCE_IMAGE_FILENAME -IMAGE_ID = None IMAGE_ID_ALT = None -FLAVOR_NAME = \ - ft_utils.get_functest_config('general.openstack.flavor_name') -FLAVOR_RAM = ft_utils.get_functest_config('general.openstack.flavor_ram') -FLAVOR_DISK = ft_utils.get_functest_config('general.openstack.flavor_disk') -FLAVOR_VCPUS = ft_utils.get_functest_config('general.openstack.flavor_vcpus') -FLAVOR_ID = None +FLAVOR_NAME = ft_constants.FLAVOR_NAME +FLAVOR_RAM = ft_constants.FLAVOR_RAM +FLAVOR_DISK = ft_constants.FLAVOR_DISK +FLAVOR_VCPUS = ft_constants.FLAVOR_VCPUS FLAVOR_ID_ALT = None -PRIVATE_NET_NAME = \ - ft_utils.get_functest_config('tempest.private_net_name') -PRIVATE_SUBNET_NAME = \ - ft_utils.get_functest_config('tempest.private_subnet_name') -PRIVATE_SUBNET_CIDR = \ - ft_utils.get_functest_config('tempest.private_subnet_cidr') -ROUTER_NAME = \ - ft_utils.get_functest_config('tempest.router_name') -TENANT_NAME = \ - ft_utils.get_functest_config('tempest.identity.tenant_name') -TENANT_DESCRIPTION = \ - ft_utils.get_functest_config('tempest.identity.tenant_description') -USER_NAME = \ - ft_utils.get_functest_config('tempest.identity.user_name') -USER_PASSWORD = \ - ft_utils.get_functest_config('tempest.identity.user_password') -SSH_TIMEOUT = \ - ft_utils.get_functest_config('tempest.validation.ssh_timeout') -USE_CUSTOM_IMAGES = \ - ft_utils.get_functest_config('tempest.use_custom_images') -USE_CUSTOM_FLAVORS = \ - ft_utils.get_functest_config('tempest.use_custom_flavors') - -DEPLOYMENT_MAME = \ - ft_utils.get_functest_config('rally.deployment_name') -RALLY_INSTALLATION_DIR = \ - ft_utils.get_functest_config('general.directories.dir_rally_inst') - -RESULTS_DIR = \ - ft_utils.get_functest_config('general.directories.dir_results') -TEMPEST_RESULTS_DIR = RESULTS_DIR + '/tempest' - -REPO_PATH = ft_utils.FUNCTEST_REPO + '/' -TEST_LIST_DIR = \ - ft_utils.get_functest_config('general.directories.dir_tempest_cases') -TEMPEST_CUSTOM = REPO_PATH + TEST_LIST_DIR + 'test_list.txt' -TEMPEST_BLACKLIST = REPO_PATH + TEST_LIST_DIR + 'blacklist.txt' -TEMPEST_DEFCORE = REPO_PATH + TEST_LIST_DIR + 'defcore_req.txt' -TEMPEST_RAW_LIST = TEMPEST_RESULTS_DIR + '/test_raw_list.txt' -TEMPEST_LIST = TEMPEST_RESULTS_DIR + '/test_list.txt' +TEMPEST_PRIVATE_NET_NAME = ft_constants.TEMPEST_PRIVATE_NET_NAME +TEMPEST_PRIVATE_SUBNET_NAME = ft_constants.TEMPEST_PRIVATE_SUBNET_NAME +TEMPEST_PRIVATE_SUBNET_CIDR = ft_constants.TEMPEST_PRIVATE_SUBNET_CIDR +TEMPEST_ROUTER_NAME = ft_constants.TEMPEST_ROUTER_NAME +TEMPEST_TENANT_NAME = ft_constants.TEMPEST_TENANT_NAME +TEMPEST_TENANT_DESCRIPTION = ft_constants.TEMPEST_TENANT_DESCRIPTION +TEMPEST_USER_NAME = ft_constants.TEMPEST_USER_NAME +TEMPEST_USER_PASSWORD = ft_constants.TEMPEST_USER_PASSWORD +TEMPEST_SSH_TIMEOUT = ft_constants.TEMPEST_SSH_TIMEOUT +TEMPEST_USE_CUSTOM_IMAGES = ft_constants.TEMPEST_USE_CUSTOM_IMAGES +TEMPEST_USE_CUSTOM_FLAVORS = ft_constants.TEMPEST_USE_CUSTOM_FLAVORS + +RESULTS_DIR = ft_constants.FUNCTEST_RESULTS_DIR +TEMPEST_RESULTS_DIR = os.path.join(RESULTS_DIR, 'tempest') + +REPO_PATH = ft_constants.FUNCTEST_REPO_DIR +TEMPEST_TEST_LIST_DIR = ft_constants.TEMPEST_TEST_LIST_DIR +TEMPEST_CUSTOM = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR, + 'test_list.txt') +TEMPEST_BLACKLIST = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR, + 'blacklist.txt') +TEMPEST_DEFCORE = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR, + 'defcore_req.txt') +TEMPEST_RAW_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_raw_list.txt') +TEMPEST_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_list.txt') + + +class GlobalVariables: + IMAGE_ID = None + FLAVOR_ID = None + MODE = "smoke" def get_info(file_result): @@ -150,43 +132,41 @@ def create_tempest_resources(): logger.debug("Creating tenant and user for Tempest suite") tenant_id = os_utils.create_tenant(keystone_client, - TENANT_NAME, - TENANT_DESCRIPTION) + TEMPEST_TENANT_NAME, + TEMPEST_TENANT_DESCRIPTION) if not tenant_id: - logger.error("Error : Failed to create %s tenant" % TENANT_NAME) + logger.error("Error : Failed to create %s tenant" + % TEMPEST_TENANT_NAME) - user_id = os_utils.create_user(keystone_client, USER_NAME, USER_PASSWORD, + user_id = os_utils.create_user(keystone_client, TEMPEST_USER_NAME, + TEMPEST_USER_PASSWORD, None, tenant_id) if not user_id: - logger.error("Error : Failed to create %s user" % USER_NAME) + logger.error("Error : Failed to create %s user" % TEMPEST_USER_NAME) logger.debug("Creating private network for Tempest suite") - network_dic = os_utils.create_shared_network_full(PRIVATE_NET_NAME, - PRIVATE_SUBNET_NAME, - ROUTER_NAME, - PRIVATE_SUBNET_CIDR) + network_dic = \ + os_utils.create_shared_network_full(TEMPEST_PRIVATE_NET_NAME, + TEMPEST_PRIVATE_SUBNET_NAME, + TEMPEST_ROUTER_NAME, + TEMPEST_PRIVATE_SUBNET_CIDR) if not network_dic: exit(1) - if USE_CUSTOM_IMAGES: + if TEMPEST_USE_CUSTOM_IMAGES: # adding alternative image should be trivial should we need it logger.debug("Creating image for Tempest suite") - global IMAGE_ID - _, IMAGE_ID = os_utils.get_or_create_image(GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH, - GLANCE_IMAGE_FORMAT) - if not IMAGE_ID: + _, GlobalVariables.IMAGE_ID = os_utils.get_or_create_image( + GLANCE_IMAGE_NAME, GLANCE_IMAGE_PATH, GLANCE_IMAGE_FORMAT) + if not GlobalVariables.IMAGE_ID: exit(-1) - if USE_CUSTOM_FLAVORS: + if TEMPEST_USE_CUSTOM_FLAVORS: # adding alternative flavor should be trivial should we need it logger.debug("Creating flavor for Tempest suite") - global FLAVOR_ID - _, FLAVOR_ID = os_utils.get_or_create_flavor(FLAVOR_NAME, - FLAVOR_RAM, - FLAVOR_DISK, - FLAVOR_VCPUS) - if not FLAVOR_ID: + _, GlobalVariables.FLAVOR_ID = os_utils.get_or_create_flavor( + FLAVOR_NAME, FLAVOR_RAM, FLAVOR_DISK, FLAVOR_VCPUS) + if not GlobalVariables.FLAVOR_ID: exit(-1) @@ -213,23 +193,23 @@ def configure_tempest(deployment_dir): logger.debug("Updating selected tempest.conf parameters...") config = ConfigParser.RawConfigParser() config.read(tempest_conf_file) - config.set('compute', 'fixed_network_name', PRIVATE_NET_NAME) - if USE_CUSTOM_IMAGES: - if IMAGE_ID is not None: - config.set('compute', 'image_ref', IMAGE_ID) + config.set('compute', 'fixed_network_name', TEMPEST_PRIVATE_NET_NAME) + if TEMPEST_USE_CUSTOM_IMAGES: + if GlobalVariables.IMAGE_ID is not None: + config.set('compute', 'image_ref', GlobalVariables.IMAGE_ID) if IMAGE_ID_ALT is not None: config.set('compute', 'image_ref_alt', IMAGE_ID_ALT) - if USE_CUSTOM_FLAVORS: - if FLAVOR_ID is not None: - config.set('compute', 'flavor_ref', FLAVOR_ID) + if TEMPEST_USE_CUSTOM_FLAVORS: + if GlobalVariables.FLAVOR_ID is not None: + config.set('compute', 'flavor_ref', GlobalVariables.FLAVOR_ID) if FLAVOR_ID_ALT is not None: config.set('compute', 'flavor_ref_alt', FLAVOR_ID_ALT) - config.set('identity', 'tenant_name', TENANT_NAME) - config.set('identity', 'username', USER_NAME) - config.set('identity', 'password', USER_PASSWORD) - config.set('validation', 'ssh_timeout', SSH_TIMEOUT) + config.set('identity', 'tenant_name', TEMPEST_TENANT_NAME) + config.set('identity', 'username', TEMPEST_USER_NAME) + config.set('identity', 'password', TEMPEST_USER_PASSWORD) + config.set('validation', 'ssh_timeout', TEMPEST_SSH_TIMEOUT) - if os.getenv('OS_ENDPOINT_TYPE') is not None: + if ft_constants.OS_ENDPOINT_TYPE is not None: services_list = ['compute', 'volume', 'image', 'network', 'data-processing', 'object-storage', 'orchestration'] sections = config.sections() @@ -237,7 +217,7 @@ def configure_tempest(deployment_dir): if service not in sections: config.add_section(service) config.set(service, 'endpoint_type', - os.environ.get("OS_ENDPOINT_TYPE")) + ft_constants.OS_ENDPOINT_TYPE) with open(tempest_conf_file, 'wb') as config_file: config.write(config_file) @@ -283,8 +263,8 @@ def apply_tempest_blacklist(): result_file = open(TEMPEST_LIST, 'w') black_tests = [] try: - installer_type = os.getenv('INSTALLER_TYPE') - deploy_scenario = os.getenv('DEPLOY_SCENARIO') + installer_type = ft_constants.CI_INSTALLER_TYPE + deploy_scenario = ft_constants.CI_SCENARIO if (bool(installer_type) * bool(deploy_scenario)): # if INSTALLER_TYPE and DEPLOY_SCENARIO are set we read the file black_list_file = open(TEMPEST_BLACKLIST) @@ -325,9 +305,9 @@ def run_tempest(OPTION): header = ("Tempest environment:\n" " Installer: %s\n Scenario: %s\n Node: %s\n Date: %s\n" % - (os.getenv('INSTALLER_TYPE', 'Unknown'), - os.getenv('DEPLOY_SCENARIO', 'Unknown'), - os.getenv('NODE_NAME', 'Unknown'), + (ft_constants.CI_INSTALLER_TYPE, + ft_constants.CI_SCENARIO, + ft_constants.CI_NODE, time.strftime("%a %b %d %H:%M:%S %Z %Y"))) f_stdout = open(TEMPEST_RESULTS_DIR + "/tempest.log", 'w+') @@ -434,7 +414,6 @@ def run_tempest(OPTION): def main(): - global MODE if not (args.mode in modes): logger.error("Tempest mode not valid. " @@ -448,19 +427,19 @@ def main(): create_tempest_resources() if "" == args.conf: - MODE = "" + GlobalVariables.MODE = "" configure_tempest(deployment_dir) else: - MODE = " --tempest-config " + args.conf + GlobalVariables.MODE = " --tempest-config " + args.conf generate_test_list(deployment_dir, args.mode) apply_tempest_blacklist() - MODE += " --tests-file " + TEMPEST_LIST + GlobalVariables.MODE += " --tests-file " + TEMPEST_LIST if args.serial: - MODE += " --concur 1" + GlobalVariables.MODE += " --concur 1" - ret_val = run_tempest(MODE) + ret_val = run_tempest(GlobalVariables.MODE) if ret_val != 0: sys.exit(-1) diff --git a/functest/opnfv_tests/features/copper.py b/functest/opnfv_tests/features/copper.py index ab016262..d003779e 100755 --- a/functest/opnfv_tests/features/copper.py +++ b/functest/opnfv_tests/features/copper.py @@ -20,7 +20,7 @@ import time import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as functest_utils - +import functest.utils.functest_constants as ft_constants parser = argparse.ArgumentParser() parser.add_argument("-r", "--report", @@ -28,16 +28,14 @@ parser.add_argument("-r", "--report", action="store_true") args = parser.parse_args() -COPPER_REPO = \ - functest_utils.get_functest_config('general.directories.dir_repo_copper') -RESULTS_DIR = \ - functest_utils.get_functest_config('general.directories.dir_results') +COPPER_REPO_DIR = ft_constants.COPPER_REPO_DIR +RESULTS_DIR = ft_constants.FUNCTEST_RESULTS_DIR logger = ft_logger.Logger("copper").getLogger() def main(): - cmd = "%s/tests/run.sh %s/tests" % (COPPER_REPO, COPPER_REPO) + cmd = "%s/tests/run.sh %s/tests" % (COPPER_REPO_DIR, COPPER_REPO_DIR) start_time = time.time() @@ -80,5 +78,6 @@ def main(): sys.exit(0) + if __name__ == '__main__': main() diff --git a/functest/opnfv_tests/features/doctor.py b/functest/opnfv_tests/features/doctor.py index 00e5c1d6..dbd803a6 100755 --- a/functest/opnfv_tests/features/doctor.py +++ b/functest/opnfv_tests/features/doctor.py @@ -19,7 +19,7 @@ import time import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as functest_utils - +import functest.utils.functest_constants as ft_constants parser = argparse.ArgumentParser() parser.add_argument("-r", "--report", @@ -29,10 +29,8 @@ args = parser.parse_args() functest_yaml = functest_utils.get_functest_yaml() -DOCTOR_REPO = \ - functest_utils.get_functest_config('general.directories.dir_repo_doctor') -RESULTS_DIR = \ - functest_utils.get_functest_config('general.directories.dir_results') +DOCTOR_REPO_DIR = ft_constants.DOCTOR_REPO_DIR +RESULTS_DIR = ft_constants.FUNCTEST_RESULTS_DIR logger = ft_logger.Logger("doctor").getLogger() @@ -45,7 +43,7 @@ def main(): if 'doctor' in functest_yaml and 'image_name' in functest_yaml['doctor']: os.environ["IMAGE_NAME"] = functest_yaml['doctor']['image_name'] - cmd = 'cd %s/tests && ./run.sh' % DOCTOR_REPO + cmd = 'cd %s/tests && ./run.sh' % DOCTOR_REPO_DIR log_file = RESULTS_DIR + "/doctor.log" start_time = time.time() @@ -86,5 +84,6 @@ def main(): exit(exit_code) + if __name__ == '__main__': main() diff --git a/functest/opnfv_tests/features/domino.py b/functest/opnfv_tests/features/domino.py index be3dd549..2deeb4c4 100755 --- a/functest/opnfv_tests/features/domino.py +++ b/functest/opnfv_tests/features/domino.py @@ -21,13 +21,12 @@ import time from functest.core import TestCasesBase import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils +import functest.utils.functest_constants as ft_constants class DominoCases(TestCasesBase.TestCasesBase): - DOMINO_REPO = \ - ft_utils.get_functest_config('general.directories.dir_repo_domino') - RESULTS_DIR = \ - ft_utils.get_functest_config('general.directories.dir_results') + DOMINO_REPO = ft_constants.DOMINO_REPO + RESULTS_DIR = ft_constants.FUNCTEST_RESULTS_DIR logger = ft_logger.Logger("domino").getLogger() def __init__(self): @@ -66,6 +65,7 @@ class DominoCases(TestCasesBase.TestCasesBase): kwargs = {} return self.main(**kwargs) + if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-r", "--report", diff --git a/functest/opnfv_tests/features/multisite.py b/functest/opnfv_tests/features/multisite.py index 6d492182..15cfe2a4 100755 --- a/functest/opnfv_tests/features/multisite.py +++ b/functest/opnfv_tests/features/multisite.py @@ -17,5 +17,6 @@ logger = ft_logger.Logger("multisite").getLogger() def main(): logger.info("multisite OK") + if __name__ == '__main__': main() diff --git a/functest/opnfv_tests/features/promise.py b/functest/opnfv_tests/features/promise.py index e198bde2..0a30e3a1 100755 --- a/functest/opnfv_tests/features/promise.py +++ b/functest/opnfv_tests/features/promise.py @@ -21,7 +21,7 @@ import functest.utils.openstack_utils as openstack_utils import keystoneclient.v2_0.client as ksclient from neutronclient.v2_0 import client as ntclient import novaclient.client as nvclient - +import functest.utils.functest_constants as ft_constants parser = argparse.ArgumentParser() @@ -32,34 +32,29 @@ parser.add_argument("-r", "--report", args = parser.parse_args() -dirs = ft_utils.get_functest_config('general.directories') -PROMISE_REPO = dirs.get('dir_repo_promise') -RESULTS_DIR = ft_utils.get_functest_config('general.directories.dir_results') +PROMISE_REPO_DIR = ft_constants.PROMISE_REPO_DIR +RESULTS_DIR = ft_constants.FUNCTEST_RESULTS_DIR -TENANT_NAME = ft_utils.get_functest_config('promise.tenant_name') -TENANT_DESCRIPTION = \ - ft_utils.get_functest_config('promise.tenant_description') -USER_NAME = ft_utils.get_functest_config('promise.user_name') -USER_PWD = ft_utils.get_functest_config('promise.user_pwd') -IMAGE_NAME = ft_utils.get_functest_config('promise.image_name') -FLAVOR_NAME = ft_utils.get_functest_config('promise.flavor_name') -FLAVOR_VCPUS = ft_utils.get_functest_config('promise.flavor_vcpus') -FLAVOR_RAM = ft_utils.get_functest_config('promise.flavor_ram') -FLAVOR_DISK = ft_utils.get_functest_config('promise.flavor_disk') +PROMISE_TENANT_NAME = ft_constants.PROMISE_TENANT_NAME +TENANT_DESCRIPTION = ft_constants.TENANT_DESCRIPTION +PROMISE_USER_NAME = ft_constants.PROMISE_USER_NAME +PROMISE_USER_PWD = ft_constants.PROMISE_USER_PWD +PROMISE_IMAGE_NAME = ft_constants.PROMISE_IMAGE_NAME +PROMISE_FLAVOR_NAME = ft_constants.PROMISE_FLAVOR_NAME +PROMISE_FLAVOR_VCPUS = ft_constants.PROMISE_FLAVOR_VCPUS +PROMISE_FLAVOR_RAM = ft_constants.PROMISE_FLAVOR_RAM +PROMISE_FLAVOR_DISK = ft_constants.PROMISE_FLAVOR_DISK -GLANCE_IMAGE_FILENAME = \ - ft_utils.get_functest_config('general.openstack.image_file_name') -GLANCE_IMAGE_FORMAT = \ - ft_utils.get_functest_config('general.openstack.image_disk_format') -GLANCE_IMAGE_PATH = \ - ft_utils.get_functest_config('general.directories.dir_functest_data') + \ - "/" + GLANCE_IMAGE_FILENAME +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_FILENAME) -NET_NAME = ft_utils.get_functest_config('promise.network_name') -SUBNET_NAME = ft_utils.get_functest_config('promise.subnet_name') -SUBNET_CIDR = ft_utils.get_functest_config('promise.subnet_cidr') -ROUTER_NAME = ft_utils.get_functest_config('promise.router_name') +PROMISE_NET_NAME = ft_constants.PROMISE_NET_NAME +PROMISE_SUBNET_NAME = ft_constants.PROMISE_SUBNET_NAME +PROMISE_SUBNET_CIDR = ft_constants.PROMISE_SUBNET_CIDR +PROMISE_ROUTER_NAME = ft_constants.PROMISE_ROUTER_NAME """ logging configuration """ @@ -81,13 +76,14 @@ def main(): ks_creds['username']) exit(-1) - logger.info("Creating tenant '%s'..." % TENANT_NAME) + logger.info("Creating tenant '%s'..." % PROMISE_TENANT_NAME) tenant_id = openstack_utils.create_tenant( - keystone, TENANT_NAME, TENANT_DESCRIPTION) + keystone, PROMISE_TENANT_NAME, TENANT_DESCRIPTION) if not tenant_id: - logger.error("Error : Failed to create %s tenant" % TENANT_NAME) + logger.error("Error : Failed to create %s tenant" + % PROMISE_TENANT_NAME) exit(-1) - logger.debug("Tenant '%s' created successfully." % TENANT_NAME) + logger.debug("Tenant '%s' created successfully." % PROMISE_TENANT_NAME) roles_name = ["admin", "Admin"] role_id = '' @@ -99,90 +95,91 @@ def main(): logger.error("Error : Failed to get id for %s role" % role_name) exit(-1) - logger.info("Adding role '%s' to tenant '%s'..." % (role_id, TENANT_NAME)) + logger.info("Adding role '%s' to tenant '%s'..." + % (role_id, PROMISE_TENANT_NAME)) if not openstack_utils.add_role_user(keystone, user_id, role_id, tenant_id): logger.error("Error : Failed to add %s on tenant %s" % - (ks_creds['username'], TENANT_NAME)) + (ks_creds['username'], PROMISE_TENANT_NAME)) exit(-1) logger.debug("Role added successfully.") - logger.info("Creating user '%s'..." % USER_NAME) + logger.info("Creating user '%s'..." % PROMISE_USER_NAME) user_id = openstack_utils.create_user( - keystone, USER_NAME, USER_PWD, None, tenant_id) + keystone, PROMISE_USER_NAME, PROMISE_USER_PWD, None, tenant_id) if not user_id: - logger.error("Error : Failed to create %s user" % USER_NAME) + logger.error("Error : Failed to create %s user" % PROMISE_USER_NAME) exit(-1) - logger.debug("User '%s' created successfully." % USER_NAME) + logger.debug("User '%s' created successfully." % PROMISE_USER_NAME) logger.info("Updating OpenStack credentials...") ks_creds.update({ - "username": TENANT_NAME, - "password": TENANT_NAME, - "tenant_name": TENANT_NAME, + "username": PROMISE_TENANT_NAME, + "password": PROMISE_TENANT_NAME, + "tenant_name": PROMISE_TENANT_NAME, }) nt_creds.update({ - "tenant_name": TENANT_NAME, + "tenant_name": PROMISE_TENANT_NAME, }) nv_creds.update({ - "project_id": TENANT_NAME, + "project_id": PROMISE_TENANT_NAME, }) glance = openstack_utils.get_glance_client() nova = nvclient.Client("2", **nv_creds) - logger.info("Creating image '%s' from '%s'..." % (IMAGE_NAME, + logger.info("Creating image '%s' from '%s'..." % (PROMISE_IMAGE_NAME, GLANCE_IMAGE_PATH)) image_id = openstack_utils.create_glance_image(glance, - IMAGE_NAME, + PROMISE_IMAGE_NAME, GLANCE_IMAGE_PATH) if not image_id: logger.error("Failed to create the Glance image...") exit(-1) - logger.debug("Image '%s' with ID '%s' created successfully." % (IMAGE_NAME, - image_id)) - flavor_id = openstack_utils.get_flavor_id(nova, FLAVOR_NAME) + logger.debug("Image '%s' with ID '%s' created successfully." + % (PROMISE_IMAGE_NAME, image_id)) + flavor_id = openstack_utils.get_flavor_id(nova, PROMISE_FLAVOR_NAME) if flavor_id == '': - logger.info("Creating flavor '%s'..." % FLAVOR_NAME) + logger.info("Creating flavor '%s'..." % PROMISE_FLAVOR_NAME) flavor_id = openstack_utils.create_flavor(nova, - FLAVOR_NAME, - FLAVOR_RAM, - FLAVOR_DISK, - FLAVOR_VCPUS) + PROMISE_FLAVOR_NAME, + PROMISE_FLAVOR_RAM, + PROMISE_FLAVOR_DISK, + PROMISE_FLAVOR_VCPUS) if not flavor_id: logger.error("Failed to create the Flavor...") exit(-1) logger.debug("Flavor '%s' with ID '%s' created successfully." % - (FLAVOR_NAME, flavor_id)) + (PROMISE_FLAVOR_NAME, flavor_id)) else: logger.debug("Using existing flavor '%s' with ID '%s'..." - % (FLAVOR_NAME, flavor_id)) + % (PROMISE_FLAVOR_NAME, flavor_id)) neutron = ntclient.Client(**nt_creds) network_dic = openstack_utils.create_network_full(neutron, - NET_NAME, - SUBNET_NAME, - ROUTER_NAME, - SUBNET_CIDR) + PROMISE_NET_NAME, + PROMISE_SUBNET_NAME, + PROMISE_ROUTER_NAME, + PROMISE_SUBNET_CIDR) if not network_dic: logger.error("Failed to create the private network...") exit(-1) logger.info("Exporting environment variables...") os.environ["NODE_ENV"] = "functest" - os.environ["OS_TENANT_NAME"] = TENANT_NAME - os.environ["OS_USERNAME"] = USER_NAME - os.environ["OS_PASSWORD"] = USER_PWD + os.environ["OS_PASSWORD"] = PROMISE_USER_PWD os.environ["OS_TEST_IMAGE"] = image_id os.environ["OS_TEST_FLAVOR"] = flavor_id os.environ["OS_TEST_NETWORK"] = network_dic["net_id"] + os.environ["OS_TENANT_NAME"] = PROMISE_TENANT_NAME + os.environ["OS_USERNAME"] = PROMISE_USER_NAME - os.chdir(PROMISE_REPO + '/source/') - results_file_name = RESULTS_DIR + '/' + 'promise-results.json' + os.chdir(PROMISE_REPO_DIR + '/source/') + results_file_name = os.path.join(RESULTS_DIR, 'promise-results.json') results_file = open(results_file_name, 'w+') cmd = 'npm run -s test -- --reporter json' diff --git a/functest/opnfv_tests/security_scan/connect.py b/functest/opnfv_tests/security_scan/connect.py index 18ca96d8..3d5456c5 100644 --- a/functest/opnfv_tests/security_scan/connect.py +++ b/functest/opnfv_tests/security_scan/connect.py @@ -15,9 +15,10 @@ import socket import paramiko import functest.utils.functest_logger as ft_logger +import functest.utils.functest_constants as ft_constants # add installer IP from env -INSTALLER_IP = os.getenv('INSTALLER_IP') +INSTALLER_IP = ft_constants.CI_INSTALLER_IP # Set up loggers logger = ft_logger.Logger("security_scan").getLogger() diff --git a/functest/opnfv_tests/security_scan/scripts/internet_check.py b/functest/opnfv_tests/security_scan/scripts/internet_check.py index 1bed50a7..d417d174 100644 --- a/functest/opnfv_tests/security_scan/scripts/internet_check.py +++ b/functest/opnfv_tests/security_scan/scripts/internet_check.py @@ -22,4 +22,6 @@ def is_connected(): return True except: return False + + print is_connected() diff --git a/functest/opnfv_tests/security_scan/security_scan.py b/functest/opnfv_tests/security_scan/security_scan.py index 4e0407fb..f0673924 100755 --- a/functest/opnfv_tests/security_scan/security_scan.py +++ b/functest/opnfv_tests/security_scan/security_scan.py @@ -24,23 +24,23 @@ from keystoneclient.auth.identity import v2 from novaclient import client import connect -import functest.utils.functest_utils as ft_utils +import functest.utils.functest_constants as ft_constants __version__ = 0.1 __author__ = 'Luke Hinds (lhinds@redhat.com)' __url__ = 'https://wiki.opnfv.org/display/functest/Functest+Security' # Global vars -INSTALLER_IP = os.getenv('INSTALLER_IP') +INSTALLER_IP = ft_constants.CI_INSTALLER_IP oscapbin = 'sudo /bin/oscap' -functest_dir = '%s/opnfv_tests/security_scan/' % ft_utils.FUNCTEST_REPO +functest_dir = '%s/security_scan/' % ft_constants.FUNCTEST_TEST_DIR # Apex Spefic var needed to query Undercloud -if os.getenv('OS_AUTH_URL') is None: +if ft_constants.OS_AUTH_URL is None: connect.logger.error(" Enviroment variable OS_AUTH_URL is not set") sys.exit(0) else: - OS_AUTH_URL = os.getenv('OS_AUTH_URL') + OS_AUTH_URL = ft_constants.OS_AUTH_URL # args parser = argparse.ArgumentParser(description='OPNFV OpenSCAP Scanner') @@ -71,6 +71,10 @@ sess = session.Session(auth=auth) nova = client.Client(2, session=sess) +class GlobalVariables: + tmpdir = "" + + def run_tests(host, nodetype): user = cfgparse.get(nodetype, 'user') port = cfgparse.get(nodetype, 'port') @@ -133,13 +137,12 @@ def internet_check(host, nodetype): def createfiles(host, port, user, localkey): import connect - global tmpdir localpath = functest_dir + 'scripts/createfiles.py' remotepath = '/tmp/createfiles.py' com = 'python /tmp/createfiles.py' connect = connect.ConnectionManager(host, port, user, localkey, localpath, remotepath, com) - tmpdir = connect.remotescript() + GlobalVariables.tmpdir = connect.remotescript() def install_pkg(host, port, user, localkey): @@ -160,18 +163,20 @@ def run_scanner(host, port, user, localkey, nodetype): if scantype == 'xccdf': cpe = cfgparse.get(nodetype, 'cpe') com = '{0} xccdf eval --profile {1} --results {2}/{3}' \ - ' --report {2}/{4} --cpe {5} {6}'.format(oscapbin, - profile, - tmpdir.rstrip(), - results, - report, - cpe, - secpolicy) + ' --report {2}/{4}' \ + ' --cpe {5} {6}'.format(oscapbin, + profile, + GlobalVariables.tmpdir.rstrip(), + results, + report, + cpe, + secpolicy) connect = connect.ConnectionManager(host, port, user, localkey, com) connect.remotecmd() elif scantype == 'oval': com = '{0} oval eval --results {1}/{2} ' - '--report {1}/{3} {4}'.format(oscapbin, tmpdir.rstrip(), + '--report {1}/{3} {4}'.format(oscapbin, + GlobalVariables.tmpdir.rstrip(), results, report, secpolicy) connect = connect.ConnectionManager(host, port, user, localkey, com) connect.remotecmd() @@ -191,7 +196,7 @@ def post_tasks(host, port, user, localkey, nodetype): os.makedirs(dl_folder, 0755) report = cfgparse.get(nodetype, 'report') results = cfgparse.get(nodetype, 'results') - reportfile = '{0}/{1}'.format(tmpdir.rstrip(), report) + reportfile = '{0}/{1}'.format(GlobalVariables.tmpdir.rstrip(), report) connect = connect.ConnectionManager(host, port, user, localkey, dl_folder, reportfile, report, results) connect.download_reports() @@ -206,7 +211,7 @@ def removepkg(host, port, user, localkey, nodetype): def cleandir(host, port, user, localkey, nodetype): import connect - com = 'sudo rm -r {0}'.format(tmpdir.rstrip()) + com = 'sudo rm -r {0}'.format(GlobalVariables.tmpdir.rstrip()) connect = connect.ConnectionManager(host, port, user, localkey, com) connect.remotecmd() diff --git a/functest/opnfv_tests/vnf/vIMS/vIMS.py b/functest/opnfv_tests/vnf/vIMS/vIMS.py index 50aa715f..4cc8ce30 100755 --- a/functest/opnfv_tests/vnf/vIMS/vIMS.py +++ b/functest/opnfv_tests/vnf/vIMS/vIMS.py @@ -29,6 +29,7 @@ import functest.utils.functest_utils as ft_utils import functest.utils.openstack_utils as os_utils from clearwater import clearwater from orchestrator import orchestrator +import functest.utils.functest_constants as ft_constants pp = pprint.PrettyPrinter(indent=4) @@ -48,39 +49,21 @@ logger = ft_logger.Logger("vIMS").getLogger() # Cloudify parameters -VIMS_DIR = ft_utils.FUNCTEST_REPO + '/' + \ - ft_utils.get_functest_config('general.directories.dir_vIMS') - -VIMS_DATA_DIR = \ - ft_utils.get_functest_config('general.directories.dir_vIMS_data') + \ - '/' -VIMS_TEST_DIR = \ - ft_utils.get_functest_config('general.directories.dir_repo_vims_test') + \ - '/' -DB_URL = \ - ft_utils.get_functest_config('results.test_db_url') - -TENANT_NAME = \ - ft_utils.get_functest_config('vIMS.general.tenant_name') -TENANT_DESCRIPTION = \ - ft_utils.get_functest_config('vIMS.general.tenant_description') -IMAGES = \ - ft_utils.get_functest_config('vIMS.general.images') - -CFY_MANAGER_BLUEPRINT = \ - ft_utils.get_functest_config('vIMS.cloudify.blueprint') -CFY_MANAGER_REQUIERMENTS = \ - ft_utils.get_functest_config('vIMS.cloudify.requierments') -CFY_INPUTS = ft_utils.get_functest_config('vIMS.cloudify.inputs') - -CW_BLUEPRINT = \ - ft_utils.get_functest_config('vIMS.clearwater.blueprint') -CW_DEPLOYMENT_NAME = \ - ft_utils.get_functest_config('vIMS.clearwater.deployment-name') -CW_INPUTS = \ - ft_utils.get_functest_config('vIMS.clearwater.inputs') -CW_REQUIERMENTS = \ - ft_utils.get_functest_config('vIMS.clearwater.requierments') +VIMS_DIR = os.path.join(ft_constants.FUNCTEST_TEST_DIR, 'vnf/vIMS/') +VIMS_DATA_DIR = ft_constants.VIMS_DATA_DIR +VIMS_TEST_DIR = ft_constants.VIMS_TEST_DIR +VIMS_TENANT_NAME = ft_constants.VIMS_TENANT_NAME +VIMS_TENANT_DESCRIPTION = ft_constants.VIMS_TENANT_DESCRIPTION +VIMS_IMAGES = ft_constants.VIMS_IMAGES + +CFY_MANAGER_BLUEPRINT = ft_constants.CFY_MANAGER_BLUEPRINT +CFY_MANAGER_REQUIERMENTS = ft_constants.CFY_MANAGER_REQUIERMENTS +CFY_INPUTS = ft_constants.CFY_INPUTS + +CW_BLUEPRINT = ft_constants.CW_BLUEPRINT +CW_DEPLOYMENT_NAME = ft_constants.CW_DEPLOYMENT_NAME +CW_INPUTS = ft_constants.CW_INPUTS +CW_REQUIERMENTS = ft_constants.CW_REQUIERMENTS CFY_DEPLOYMENT_DURATION = 0 CW_DEPLOYMENT_DURATION = 0 @@ -92,7 +75,7 @@ RESULTS = {'orchestrator': {'duration': 0, 'result': ''}, def download_and_add_image_on_glance(glance, image_name, image_url): - dest_path = VIMS_DATA_DIR + "tmp/" + dest_path = os.path.join(VIMS_DATA_DIR, "tmp/") if not os.path.exists(dest_path): os.makedirs(dest_path) file_name = image_url.rsplit('/')[-1] @@ -216,9 +199,10 @@ def test_clearwater(): logger.debug(result) vims_test_result = "" + tempFile = os.path.join(VIMS_TEST_DIR, "temp.json") try: logger.debug("Trying to load test results") - with open(VIMS_TEST_DIR + "temp.json") as f: + with open(tempFile) as f: vims_test_result = json.load(f) f.close() except: @@ -246,7 +230,7 @@ def test_clearwater(): RESULTS) try: - os.remove(VIMS_TEST_DIR + "temp.json") + os.remove(tempFile) except: logger.error("Deleting file failed") @@ -271,10 +255,10 @@ def main(): ks_creds['username']) tenant_id = os_utils.create_tenant( - keystone, TENANT_NAME, TENANT_DESCRIPTION) + keystone, VIMS_TENANT_NAME, VIMS_TENANT_DESCRIPTION) if not tenant_id: step_failure("init", "Error : Failed to create " + - TENANT_NAME + " tenant") + VIMS_TENANT_NAME + " tenant") roles_name = ["admin", "Admin"] role_id = '' @@ -290,31 +274,31 @@ def main(): ks_creds['username']) user_id = os_utils.create_user( - keystone, TENANT_NAME, TENANT_NAME, None, tenant_id) + keystone, VIMS_TENANT_NAME, VIMS_TENANT_NAME, None, tenant_id) if not user_id: - logger.error("Error : Failed to create %s user" % TENANT_NAME) + logger.error("Error : Failed to create %s user" % VIMS_TENANT_NAME) logger.info("Update OpenStack creds informations") ks_creds.update({ - "username": TENANT_NAME, - "password": TENANT_NAME, - "tenant_name": TENANT_NAME, + "username": VIMS_TENANT_NAME, + "password": VIMS_TENANT_NAME, + "tenant_name": VIMS_TENANT_NAME, }) nt_creds.update({ - "tenant_name": TENANT_NAME, + "tenant_name": VIMS_TENANT_NAME, }) nv_creds.update({ - "project_id": TENANT_NAME, + "project_id": VIMS_TENANT_NAME, }) logger.info("Upload some OS images if it doesn't exist") glance = os_utils.get_glance_client() - for img in IMAGES.keys(): - image_name = IMAGES[img]['image_name'] - image_url = IMAGES[img]['image_url'] + for img in VIMS_IMAGES.keys(): + image_name = VIMS_IMAGES[img]['image_name'] + image_url = VIMS_IMAGES[img]['image_url'] image_id = os_utils.get_image_id(glance, image_name) @@ -337,7 +321,8 @@ def main(): if not os_utils.update_sg_quota(neutron, tenant_id, 50, 100): step_failure( "init", - "Failed to update security group quota for tenant " + TENANT_NAME) + "Failed to update security group quota for tenant " + + VIMS_TENANT_NAME) # ###############Â CLOUDIFY INITIALISATION ################ public_auth_url = keystone.service_catalog.url_for( diff --git a/functest/opnfv_tests/vnf/vRNC/parser.py b/functest/opnfv_tests/vnf/vRNC/parser.py index 0381fd64..33d4d50c 100755 --- a/functest/opnfv_tests/vnf/vRNC/parser.py +++ b/functest/opnfv_tests/vnf/vRNC/parser.py @@ -19,7 +19,7 @@ import time import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as functest_utils - +import functest.utils.functest_constants as ft_constants parser = argparse.ArgumentParser() parser.add_argument("-r", "--report", @@ -27,10 +27,8 @@ parser.add_argument("-r", "--report", action="store_true") args = parser.parse_args() -PARSER_REPO = \ - functest_utils.get_functest_config('general.directories.dir_repo_parser') -RESULTS_DIR = \ - functest_utils.get_functest_config('general.directories.dir_results') +PARSER_REPO = ft_constants.PARSER_REPO +RESULTS_DIR = ft_constants.FUNCTEST_RESULTS_DIR logger = ft_logger.Logger("parser").getLogger() @@ -67,5 +65,6 @@ def main(): details) exit(ret) + if __name__ == '__main__': main() diff --git a/functest/tests/unit/core/test_base.py b/functest/tests/unit/core/test_base.py index 25faca0a..154cc78a 100644 --- a/functest/tests/unit/core/test_base.py +++ b/functest/tests/unit/core/test_base.py @@ -25,7 +25,7 @@ class TestCasesBaseTesting(unittest.TestCase): self.test.start_time = "1" self.test.stop_time = "2" self.test.criteria = "100" - self.test.details = {"Hello": "World"} + self.test.details = {"Hello": "World"} def test_run_unimplemented(self): self.assertEqual(self.test.run(), diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py index 3f33dc88..065298d6 100644 --- a/functest/tests/unit/odl/test_odl.py +++ b/functest/tests/unit/odl/test_odl.py @@ -17,6 +17,7 @@ from robot.errors import RobotError from functest.core import TestCasesBase from functest.opnfv_tests.Controllers.ODL import OpenDaylightTesting +from functest.utils import functest_constants as ft_constants class ODLTestCasesTesting(unittest.TestCase): @@ -35,12 +36,9 @@ class ODLTestCasesTesting(unittest.TestCase): _odl_password = "admin" def setUp(self): - for var in ("INSTALLER_TYPE", "SDN_CONTROLLER", "SDN_CONTROLLER_IP"): - if var in os.environ: - del os.environ[var] - os.environ["OS_USERNAME"] = self._os_username - os.environ["OS_PASSWORD"] = self._os_password - os.environ["OS_TENANT_NAME"] = self._os_tenantname + ft_constants.OS_USERNAME = self._os_username + ft_constants.OS_PASSWORD = self._os_password + ft_constants.OS_TENANT_NAME = self._os_tenantname self.test = OpenDaylightTesting.ODLTestCases() @mock.patch('fileinput.input', side_effect=Exception()) @@ -87,9 +85,9 @@ class ODLTestCasesTesting(unittest.TestCase): def _test_main(self, status, *args): kwargs = self._get_main_kwargs() self.assertEqual(self.test.main(**kwargs), status) + odl_res_dir = OpenDaylightTesting.ODLTestCases.res_dir if len(args) > 0: - args[0].assert_called_once_with( - OpenDaylightTesting.ODLTestCases.res_dir) + args[0].assert_called_once_with(odl_res_dir) if len(args) > 1: variable = ['KEYSTONE:{}'.format(self._keystone_ip), 'NEUTRON:{}'.format(self._neutron_ip), @@ -99,17 +97,18 @@ class ODLTestCasesTesting(unittest.TestCase): 'ODL_SYSTEM_IP:{}'.format(self._sdn_controller_ip), 'PORT:{}'.format(self._odl_webport), 'RESTCONFPORT:{}'.format(self._odl_restconfport)] + output_file = os.path.join(odl_res_dir, 'output.xml') args[1].assert_called_once_with( OpenDaylightTesting.ODLTestCases.basic_suite_dir, OpenDaylightTesting.ODLTestCases.neutron_suite_dir, log='NONE', - output=OpenDaylightTesting.ODLTestCases.res_dir + 'output.xml', + output=output_file, report='NONE', stdout=mock.ANY, variable=variable) if len(args) > 2: - args[2].assert_called_with( - OpenDaylightTesting.ODLTestCases.res_dir + 'stdout.txt') + stdout_file = os.path.join(odl_res_dir, 'stdout.txt') + args[2].assert_called_with(stdout_file) def _test_main_missing_keyword(self, key): kwargs = self._get_main_kwargs(key) @@ -232,7 +231,13 @@ class ODLTestCasesTesting(unittest.TestCase): self._test_main(TestCasesBase.TestCasesBase.EX_OK, *args) def _test_run_missing_env_var(self, var): - del os.environ[var] + if var == 'OS_USERNAME': + ft_constants.OS_USERNAME = None + elif var == 'OS_PASSWORD': + ft_constants.OS_PASSWORD = None + elif var == 'OS_TENANT_NAME': + ft_constants.OS_TENANT_NAME = None + self.assertEqual(self.test.run(), TestCasesBase.TestCasesBase.EX_RUN_ERROR) @@ -263,13 +268,15 @@ class ODLTestCasesTesting(unittest.TestCase): self._test_run_missing_env_var("OS_TENANT_NAME") def test_run_main_false(self): - os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip + ft_constants.CI_INSTALLER_TYPE = None + ft_constants.SDN_CONTROLLER_IP = self._sdn_controller_ip self._test_run(TestCasesBase.TestCasesBase.EX_RUN_ERROR, odlip=self._sdn_controller_ip, odlwebport=self._odl_webport) def test_run_main_exception(self): - os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip + ft_constants.CI_INSTALLER_TYPE = None + ft_constants.SDN_CONTROLLER_IP = self._sdn_controller_ip with self.assertRaises(Exception): self._test_run(status=TestCasesBase.TestCasesBase.EX_RUN_ERROR, exception=Exception(), @@ -279,49 +286,54 @@ class ODLTestCasesTesting(unittest.TestCase): def test_run_missing_sdn_controller_ip(self): with mock.patch('functest.utils.openstack_utils.get_keystone_client', return_value=self._get_fake_keystone_client()): + ft_constants.CI_INSTALLER_TYPE = None + ft_constants.SDN_CONTROLLER_IP = None self.assertEqual(self.test.run(), TestCasesBase.TestCasesBase.EX_RUN_ERROR) def test_run_without_installer_type(self): - os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip + ft_constants.SDN_CONTROLLER_IP = self._sdn_controller_ip + ft_constants.CI_INSTALLER_TYPE = None self._test_run(TestCasesBase.TestCasesBase.EX_OK, odlip=self._sdn_controller_ip, odlwebport=self._odl_webport) def test_run_fuel(self): - os.environ["INSTALLER_TYPE"] = "fuel" + ft_constants.CI_INSTALLER_TYPE = "fuel" self._test_run(TestCasesBase.TestCasesBase.EX_OK, odlip=self._neutron_ip, odlwebport='8282') def test_run_apex_missing_sdn_controller_ip(self): with mock.patch('functest.utils.openstack_utils.get_keystone_client', return_value=self._get_fake_keystone_client()): - os.environ["INSTALLER_TYPE"] = "apex" + ft_constants.CI_INSTALLER_TYPE = "apex" + ft_constants.SDN_CONTROLLER_IP = None self.assertEqual(self.test.run(), TestCasesBase.TestCasesBase.EX_RUN_ERROR) def test_run_apex(self): - os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip - os.environ["INSTALLER_TYPE"] = "apex" + ft_constants.SDN_CONTROLLER_IP = self._sdn_controller_ip + ft_constants.CI_INSTALLER_TYPE = "apex" self._test_run(TestCasesBase.TestCasesBase.EX_OK, odlip=self._sdn_controller_ip, odlwebport='8181') def test_run_joid_missing_sdn_controller(self): with mock.patch('functest.utils.openstack_utils.get_keystone_client', return_value=self._get_fake_keystone_client()): - os.environ["INSTALLER_TYPE"] = "joid" + ft_constants.CI_INSTALLER_TYPE = "joid" + ft_constants.SDN_CONTROLLER = None self.assertEqual(self.test.run(), TestCasesBase.TestCasesBase.EX_RUN_ERROR) def test_run_joid(self): - os.environ["SDN_CONTROLLER"] = self._sdn_controller_ip - os.environ["INSTALLER_TYPE"] = "joid" + ft_constants.SDN_CONTROLLER = self._sdn_controller_ip + ft_constants.CI_INSTALLER_TYPE = "joid" self._test_run(TestCasesBase.TestCasesBase.EX_OK, odlip=self._sdn_controller_ip, odlwebport=self._odl_webport) def test_run_compass(self, *args): - os.environ["INSTALLER_TYPE"] = "compass" + ft_constants.CI_INSTALLER_TYPE = "compass" self._test_run(TestCasesBase.TestCasesBase.EX_OK, odlip=self._neutron_ip, odlwebport='8181') diff --git a/functest/tests/unit/utils/test_utils.py b/functest/tests/unit/utils/test_utils.py index 36313d25..835797f7 100644 --- a/functest/tests/unit/utils/test_utils.py +++ b/functest/tests/unit/utils/test_utils.py @@ -25,5 +25,6 @@ class FunctestUtilsTesting(unittest.TestCase): # TODO # ... + if __name__ == "__main__": unittest.main(verbosity=2) diff --git a/functest/utils/functest_constants.py b/functest/utils/functest_constants.py new file mode 100644 index 00000000..81763cbe --- /dev/null +++ b/functest/utils/functest_constants.py @@ -0,0 +1,287 @@ +#!/usr/bin/env python +# +# yaohelan@huawei.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# 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 + +logger = ft_logger.Logger("functest_constants").getLogger() + + +""" global variables """ +INSTALLERS = ['fuel', 'compass', 'apex', 'joid'] +CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') +CI_INSTALLER_IP = os.getenv('INSTALLER_IP') +CI_SCENARIO = os.getenv('DEPLOY_SCENARIO') +CI_NODE = os.getenv('NODE_NAME') +CI_BUILD_TAG = os.getenv('BUILD_TAG') +CI_DEBUG = os.getenv('CI_DEBUG') +CI_LOOP = os.getenv('CI_LOOP') +OS_AUTH_URL = os.getenv('OS_AUTH_URL') +OS_USERNAME = os.getenv('OS_USERNAME') +OS_TENANT_NAME = os.getenv('OS_TENANT_NAME') +OS_PASSWORD = os.getenv('OS_PASSWORD') +OS_ENDPOINT_TYPE = os.getenv('OS_ENDPOINT_TYPE') +OS_REGION_NAME = os.getenv('OS_REGION_NAME') +OS_CACERT = os.getenv('OS_CACERT') +FUEL_ENV = os.getenv('FUEL_ENV') +SDN_CONTROLLER_IP = os.getenv('SDN_CONTROLLER_IP') +SDN_CONTROLLER = os.getenv('SDN_CONTROLLER') + +if CI_BUILD_TAG is not None: + IS_CI_RUN = True +else: + IS_CI_RUN = False + +CONFIG_FUNCTEST_YAML = os.getenv("CONFIG_FUNCTEST_YAML") + + +def get_value(functest_config_key, env_variable): + try: + constant = ft_utils.get_functest_config(functest_config_key) + # logger.debug("%s is defined in config_functest.yaml as [%s]" + # % (env_variable, constant)) + return constant + except ValueError: + logger.warning("%s is not defined in config_functest.yaml" + % functest_config_key) + constant = os.getenv(env_variable) + if constant is None: + raise ValueError("%s is neither defined in config_functest.yaml" + " nor environment variable" % env_variable) + else: + logger.debug("%s is defined as environment variable as [%s]" + % (env_variable, constant)) + 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', 'FUNCTEST_BASE_DIR') +FUNCTEST_REPO_DIR = \ + get_value('general.directories.dir_repo_functest', 'FUNCTEST_REPO_DIR') +FUNCTEST_TEST_DIR = \ + get_value('general.directories.dir_functest_test', 'FUNCTEST_TEST_DIR') +FUNCTEST_CONF_DIR = \ + get_value('general.directories.dir_functest_conf', 'FUNCTEST_CONF_DIR') +FUNCTEST_DATA_DIR = \ + get_value('general.directories.dir_functest_data', 'FUNCTEST_DATA_DIR') +FUNCTEST_RESULTS_DIR = \ + get_value('general.directories.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') + +ENV_FILE = os.path.join(FUNCTEST_CONF_DIR, "env_active") + +OPENSTACK_CREDS = \ + get_value('general.openstack.creds', 'creds') +OPENSTACK_SNAPSHOT_FILE = \ + get_value('general.openstack.snapshot_file', 'OPENSTACK_SNAPSHOT_FILE') + +DOMINO_REPO = \ + get_value('general.directories.dir_repo_domino', 'DOMINO_REPO') +SDNVPN_REPO = \ + get_value('general.directories.dir_repo_sdnvpn', 'SDNVPN_REPO') +SFC_REPO = \ + get_value('general.directories.dir_repo_sfc', 'SFC_REPO') + +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') +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') +RALLY_PRIVATE_NET_NAME = \ + get_value('rally.network_name', 'RALLY_PRIVATE_NET_NAME') +RALLY_PRIVATE_SUBNET_NAME = \ + get_value('rally.subnet_name', 'RALLY_PRIVATE_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') +GLANCE_IMAGE_NAME = \ + get_value('general.openstack.image_name', 'GLANCE_IMAGE_NAME') +GLANCE_IMAGE_FILENAME = \ + get_value('general.openstack.image_file_name', 'GLANCE_IMAGE_FILENAME') +GLANCE_IMAGE_FORMAT = \ + get_value('general.openstack.image_disk_format', 'GLANCE_IMAGE_FORMAT') +FLAVOR_NAME = \ + get_value('general.openstack.flavor_name', 'FLAVOR_NAME') +FLAVOR_RAM = \ + get_value('general.openstack.flavor_ram', 'FLAVOR_RAM') +FLAVOR_DISK = \ + get_value('general.openstack.flavor_disk', 'FLAVOR_DISK') +FLAVOR_VCPUS = \ + get_value('general.openstack.flavor_vcpus', 'FLAVOR_VCPUS') +TEMPEST_PRIVATE_NET_NAME = \ + get_value('tempest.private_net_name', 'TEMPEST_PRIVATE_NET_NAME') +TEMPEST_PRIVATE_SUBNET_NAME = \ + get_value('tempest.private_subnet_name', 'TEMPEST_PRIVATE_SUBNET_NAME') +TEMPEST_PRIVATE_SUBNET_CIDR = \ + get_value('tempest.private_subnet_cidr', 'TEMPEST_PRIVATE_SUBNET_CIDR') +TEMPEST_ROUTER_NAME = \ + get_value('tempest.router_name', 'TEMPEST_ROUTER_NAME') +TEMPEST_TENANT_NAME = \ + get_value('tempest.identity.tenant_name', 'TEMPEST_TENANT_NAME') +TEMPEST_TENANT_DESCRIPTION = \ + get_value('tempest.identity.tenant_description', + 'TEMPEST_TENANT_DESCRIPTION') +TEMPEST_USER_NAME = \ + get_value('tempest.identity.user_name', 'TEMPEST_USER_NAME') +TEMPEST_USER_PASSWORD = \ + get_value('tempest.identity.user_password', 'TEMPEST_USER_PASSWORD') +TEMPEST_SSH_TIMEOUT = \ + get_value('tempest.validation.ssh_timeout', 'TEMPEST_SSH_TIMEOUT') +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') +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') +VPING_PRIVATE_SUBNET_NAME = \ + get_value('vping.vping_private_subnet_name', 'VPING_PRIVATE_SUBNET_NAME') +VPING_PRIVATE_SUBNET_CIDR = \ + get_value('vping.vping_private_subnet_cidr', 'VPING_PRIVATE_SUBNET_CIDR') +VPING_ROUTER_NAME = \ + get_value('vping.vping_router_name', 'VPING_ROUTER_NAME') +VPING_SECGROUP_NAME = \ + get_value('vping.vping_sg_name', 'VPING_SECGROUP_NAME') +VPING_SECGROUP_DESCR = \ + get_value('vping.vping_sg_descr', 'VPING_SECGROUP_DESCR') +ONOSBENCH_USERNAME = \ + get_value('ONOS.general.onosbench_username', 'ONOSBENCH_USERNAME') +ONOSBENCH_PASSWORD = \ + get_value('ONOS.general.onosbench_password', 'ONOSBENCH_PASSWORD') +ONOSCLI_USERNAME = \ + get_value('ONOS.general.onoscli_username', 'ONOSCLI_USERNAME') +ONOSCLI_PASSWORD = \ + get_value('ONOS.general.onoscli_password', 'ONOSCLI_PASSWORD') +ONOS_RUNTIMEOUT = \ + get_value('ONOS.general.runtimeout', 'ONOS_RUNTIMEOUT') +ONOS_OCT = \ + get_value('ONOS.environment.OCT', 'ONOS_OCT') +ONOS_OC1 = \ + get_value('ONOS.environment.OC1', 'ONOS_OC1') +ONOS_OC2 = \ + get_value('ONOS.environment.OC2', 'ONOS_OC2') +ONOS_OC3 = \ + get_value('ONOS.environment.OC3', 'ONOS_OC3') +ONOS_OCN = \ + get_value('ONOS.environment.OCN', 'ONOS_OCN') +ONOS_OCN2 = \ + get_value('ONOS.environment.OCN2', 'ONOS_OCN2') +ONOS_INSTALLER_MASTER = \ + get_value('ONOS.environment.installer_master', 'ONOS_INSTALLER_MASTER') +ONOS_INSTALLER_MASTER_USERNAME = \ + get_value('ONOS.environment.installer_master_username', + 'ONOS_INSTALLER_MASTER_USERNAME') +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') +PROMISE_TENANT_NAME = \ + get_value('promise.tenant_name', 'PROMISE_TENANT_NAME') +TENANT_DESCRIPTION = \ + get_value('promise.tenant_description', 'TENANT_DESCRIPTION') +PROMISE_USER_NAME = \ + get_value('promise.user_name', 'PROMISE_USER_NAME') +PROMISE_USER_PWD = \ + get_value('promise.user_pwd', 'PROMISE_USER_PWD') +PROMISE_IMAGE_NAME = \ + get_value('promise.image_name', 'PROMISE_IMAGE_NAME') +PROMISE_FLAVOR_NAME = \ + get_value('promise.flavor_name', 'PROMISE_FLAVOR_NAME') +PROMISE_FLAVOR_VCPUS = \ + get_value('promise.flavor_vcpus', 'PROMISE_FLAVOR_VCPUS') +PROMISE_FLAVOR_RAM = \ + get_value('promise.flavor_ram', 'PROMISE_FLAVOR_RAM') +PROMISE_FLAVOR_DISK = \ + get_value('promise.flavor_disk', 'PROMISE_FLAVOR_DISK') +PROMISE_NET_NAME = \ + get_value('promise.network_name', 'PROMISE_NET_NAME') +PROMISE_SUBNET_NAME = \ + get_value('promise.subnet_name', 'PROMISE_SUBNET_NAME') +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') +COPPER_REPO_DIR = \ + get_value('general.directories.dir_repo_copper', 'COPPER_REPO_DIR') +EXAMPLE_INSTANCE_NAME = \ + get_value('example.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_IMAGE_NAME') +EXAMPLE_PRIVATE_NET_NAME = \ + get_value('example.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_CIDR = \ + get_value('example.example_private_subnet_cidr', + 'EXAMPLE_PRIVATE_SUBNET_CIDR') +EXAMPLE_ROUTER_NAME = \ + get_value('example.example_router_name', 'EXAMPLE_ROUTER_NAME') +EXAMPLE_SECGROUP_NAME = \ + get_value('example.example_sg_name', 'EXAMPLE_SECGROUP_NAME') +EXAMPLE_SECGROUP_DESCR = \ + get_value('example.example_sg_descr', '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 = \ + get_value('general.directories.dir_repo_parser', 'PARSER_REPO') diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py index 2d4a652d..a25967b6 100644 --- a/functest/utils/functest_utils.py +++ b/functest/utils/functest_utils.py @@ -25,9 +25,6 @@ import functest.utils.functest_logger as ft_logger logger = ft_logger.Logger("functest_utils").getLogger() -REPOS_DIR = os.getenv('repos_dir') -FUNCTEST_REPO = ("%s/functest" % REPOS_DIR) - # ---------------------------------------------------------- # @@ -342,7 +339,7 @@ def get_deployment_dir(): def get_dict_by_test(testname): - with open(get_testcases_file()) as f: + with open(get_testcases_file_dir()) as f: testcases_yaml = yaml.safe_load(f) for dic_tier in testcases_yaml.get("tiers"): @@ -438,8 +435,8 @@ def check_test_result(test_name, ret, start_time, stop_time): return status, details -def get_testcases_file(): - return FUNCTEST_REPO + "/functest/ci/testcases.yaml" +def get_testcases_file_dir(): + return "/home/opnfv/repos/functest/functest/ci/testcases.yaml" def get_functest_yaml(): @@ -447,3 +444,7 @@ def get_functest_yaml(): functest_yaml = yaml.safe_load(f) f.close() return functest_yaml + + +def print_separator(): + logger.info("==============================================") diff --git a/functest/utils/functest_vacation.py b/functest/utils/functest_vacation.py index 0ba09447..6c7312fa 100644 --- a/functest/utils/functest_vacation.py +++ b/functest/utils/functest_vacation.py @@ -22,16 +22,16 @@ def main(): body = '~FUNTEST' ind = 0 while key != 27: - win.addstr(0, 44, ' Score: '+str(len(snake)-len(body))+' ') + win.addstr(0, 44, ' Score: ' + str(len(snake) - len(body)) + ' ') win.timeout(140 - 2 * len(snake)) getkey = win.getch() key = key if getkey == -1 else getkey snake.insert( - 0, [snake[0][0]+(key == KEY_RIGHT and 1 or - key == KEY_LEFT and -1), - snake[0][1]+(key == KEY_DOWN and 1 or - key == KEY_UP and -1)]) - win.addch(snake[len(snake)-1][1], snake[len(snake)-1][0], ' ') + 0, [snake[0][0] + (key == KEY_RIGHT and 1 or + key == KEY_LEFT and -1), + snake[0][1] + (key == KEY_DOWN and 1 or + key == KEY_UP and -1)]) + win.addch(snake[len(snake) - 1][1], snake[len(snake) - 1][0], ' ') if win.inch(snake[0][1], snake[0][0]) & 255 == 32: snake.pop() elif win.inch(snake[0][1], snake[0][0]) & 255 == ord('@'): @@ -48,5 +48,6 @@ def main(): print '\nSnake.PY-26lines by Kris Cieslak (defaultset.blogspot.com).' print 'OPNFV adaptation by Functest dream team.' - print 'Thanks for playing, your score: '+str(len(snake)-len(body)-1)+'.' + print 'Thanks for playing, your score: ' + \ + str(len(snake) - len(body) - 1) + '.' print 'Find and fix more bugs in your real OPNFV setup!\n' diff --git a/functest/utils/openstack_clean.py b/functest/utils/openstack_clean.py index bf582dea..949eee90 100755 --- a/functest/utils/openstack_clean.py +++ b/functest/utils/openstack_clean.py @@ -22,15 +22,13 @@ import time 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 yaml - +import functest.utils.functest_constants as ft_constants logger = ft_logger.Logger("openstack_clean").getLogger() -OS_SNAPSHOT_FILE = \ - ft_utils.get_functest_config("general.openstack.snapshot_file") +OS_SNAPSHOT_FILE = ft_constants.OPENSTACK_SNAPSHOT_FILE def separator(): diff --git a/functest/utils/openstack_snapshot.py b/functest/utils/openstack_snapshot.py index 560cadbd..4be1af44 100755 --- a/functest/utils/openstack_snapshot.py +++ b/functest/utils/openstack_snapshot.py @@ -21,16 +21,14 @@ # 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 yaml - +import functest.utils.functest_constants as ft_constants logger = ft_logger.Logger("openstack_snapshot").getLogger() -OS_SNAPSHOT_FILE = \ - ft_utils.get_functest_config("general.openstack.snapshot_file") +OS_SNAPSHOT_FILE = ft_constants.OPENSTACK_SNAPSHOT_FILE def separator(): |