From 3e3c96b2aa15d7757f281ce00518a67e2a1225a9 Mon Sep 17 00:00:00 2001 From: helenyao Date: Mon, 21 Nov 2016 06:50:06 -0500 Subject: 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 --- functest/opnfv_tests/Controllers/ONOS/Sfc/Sfc.py | 18 ++++----- .../ONOS/Teston/adapters/environment.py | 4 +- .../Controllers/ONOS/Teston/adapters/foundation.py | 46 ++++++++++------------ .../Controllers/ONOS/Teston/onosfunctest.py | 43 ++++++++------------ 4 files changed, 48 insertions(+), 63 deletions(-) (limited to 'functest/opnfv_tests/Controllers/ONOS') 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() -- cgit 1.2.3-korg