diff options
author | helenyao <yaohelan@huawei.com> | 2016-11-21 06:50:06 -0500 |
---|---|---|
committer | jose.lausuch <jose.lausuch@ericsson.com> | 2016-11-24 15:14:45 +0100 |
commit | 3e3c96b2aa15d7757f281ce00518a67e2a1225a9 (patch) | |
tree | 9b15e0ceab33a9301ca7cde1a0a36e05f2347584 /functest/opnfv_tests/Controllers | |
parent | 7a776398ef8b17bd9af5367d712707a903c1c86a (diff) |
Extracted all global parameters into functest_constants.py
JIRA: FUNCTEST-533
1. Extracted all global variables into functest_constants.py and updated all affected areas accordingly
2. Used os.path.join to replace '/' to come up with the path for better cross-platform support and improve the path accuracy
3. Removed unused variables
4. Updated the hardcoded path in Dockerfile by using variable reference
5. Removed "/" ending from all path variables
6. Updated the unit test
Change-Id: Ib30a81d1f0c83fbaef042d63c187c27bd18301bb
Signed-off-by: helenyao <yaohelan@huawei.com>
Diffstat (limited to 'functest/opnfv_tests/Controllers')
5 files changed, 80 insertions, 81 deletions
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() |