2 Description: This test is to run onos Teston VTN scripts
5 CASE1 - Northbound NBI test network/subnet/ports
6 CASE2 - Ovsdb test&Default configuration&Vm go online
10 # All rights reserved. This program and the accompanying materials
11 # are made available under the terms of the Apache License, Version 2.0
12 # which accompanies this distribution, and is available at
13 # http://www.apache.org/licenses/LICENSE-2.0
26 parser = argparse.ArgumentParser()
27 parser.add_argument("-i", "--installer", help="Installer type")
28 args = parser.parse_args()
29 """ logging configuration """
31 logger = logging.getLogger('onos')
32 logger.setLevel(logging.DEBUG)
34 ch = logging.StreamHandler()
37 formatter = logging.Formatter('%(asctime)s - %(name)s'
38 '- %(levelname)s - %(message)s')
40 ch.setFormatter(formatter)
43 with open("/home/opnfv/functest/conf/config_functest.yaml") as f:
44 functest_yaml = yaml.safe_load(f)
48 TEST_DB = functest_yaml.get("results").get("test_db_url")
49 ONOS_REPO_PATH = functest_yaml.get("general").get("directories").get("dir_repos")
50 ONOS_CONF_DIR = functest_yaml.get("general").get("directories").get("dir_functest_conf")
51 REPO_PATH = ONOS_REPO_PATH + '/functest/'
52 if not os.path.exists(REPO_PATH):
53 logger.error("Functest repository directory not found '%s'" % REPO_PATH)
55 sys.path.append(REPO_PATH + "testcases/")
58 ONOSCI_PATH= REPO_PATH+'testcases/Controllers/ONOS/Teston/CI/'
59 starttime = datetime.datetime.now()
61 HOME = os.environ['HOME'] + "/"
63 def RunScript(testname):
67 testname: ONOS Testcase Name
69 runtest = ONOSCI_PATH + "OnosSystemTest/TestON/bin/cli.py run " + testname
70 logger.debug( "Run script " + testname )
73 def DownloadCodes(url="https://github.com/sunyulin/OnosSystemTest.git"):
75 Download Onos Teston codes
79 downloadcode = "git clone " + url + " " + ONOSCI_PATH + "OnosSystemTest"
80 logger.debug( "Download Onos Teston codes " + url)
81 os.system(downloadcode)
84 LOGPATH = ONOSCI_PATH + "OnosSystemTest/TestON/logs"
85 cmd = "grep -rnh " + "Fail" + " " + LOGPATH
86 Resultbuffer = os.popen(cmd).read()
87 duration = datetime.datetime.now() - starttime
90 if re.search("\s+[1-9]+\s+", Resultbuffer):
91 logger.debug("Testcase Fails\n" + Resultbuffer)
94 logger.debug("Testcases Success")
96 #payload={'timestart': str(starttime),
97 # 'duration': str(duration),
99 cmd = "grep -rnh 'Execution Time' " + LOGPATH
100 Resultbuffer = os.popen(cmd).read()
101 time1 = Resultbuffer[114:128]
102 time2 = Resultbuffer[28:42]
103 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNB_*"
104 Resultbuffer = os.popen(cmd).read()
105 if Resultbuffer.find('100%') >= 0:
109 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNBL3*"
110 Resultbuffer = os.popen(cmd).read()
111 if Resultbuffer.find('100%') >= 0:
117 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNB_*"
118 Resultbuffer = os.popen(cmd).read()
119 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
120 #res = pattern.search(Resultbuffer).groups()
121 res = pattern.findall(Resultbuffer)
123 for index in range(len(res)):
124 status1.append({'Case name:':res[i][0] + res[i][1],'Case result':res[i][2]})
126 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNBL3*"
127 Resultbuffer = os.popen(cmd).read()
128 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
129 #res = pattern.search(Resultbuffer).groups()
130 res = pattern.findall(Resultbuffer)
132 for index in range(len(res)):
133 status2.append({'Case name:':res[i][0] + res[i][1],'Case result':res[i][2]})
135 payload={'timestart': str(starttime),
136 'FUNCvirNet':{'duration': time1,
139 'FUNCvirNetL3':{'duration': time2,
145 cmd = "keystone catalog --service network | grep publicURL"
146 cmd_output = os.popen(cmd).read()
147 OC1=re.search(r"\d+\.\d+\.\d+\.\d+",cmd_output).group()
148 os.environ['OC1'] = OC1
150 logger.debug( "ONOS IP is " + OC1)
152 def SetOnosIpForJoid():
153 cmd = "env | grep SDN_CONTROLLER"
154 cmd_output = os.popen(cmd).read()
155 OC1=re.search(r"\d+\.\d+\.\d+\.\d+",cmd_output).group()
156 os.environ['OC1'] = OC1
158 logger.debug( "ONOS IP is " + OC1)
161 TESTONPATH = ONOSCI_PATH + "OnosSystemTest/"
162 cmd = "rm -rf " + TESTONPATH
165 logger.debug( "Clean ONOS Teston" )
170 if args.installer == "joid":
171 logger.debug( "Installer is Joid")
175 RunScript("FUNCvirNetNB")
176 RunScript("FUNCvirNetNBL3")
179 logger.debug("Push result into DB")
180 # TODO check path result for the file
181 git_version = functest_utils.get_git_branch(REPO_PATH)
182 pod_name = functest_utils.get_pod_name(logger)
184 functest_utils.push_results_to_db(TEST_DB,
186 logger, pod_name, git_version,
189 logger.error("Error pushing results into Database")
194 if __name__ == '__main__':