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
24 import functest.utils.functest_logger as ft_logger
25 import functest.utils.functest_utils as functest_utils
27 parser = argparse.ArgumentParser()
28 parser.add_argument("-i", "--installer", help="Installer type")
29 args = parser.parse_args()
30 """ logging configuration """
31 logger = ft_logger.Logger("onos").getLogger()
33 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
34 functest_yaml = yaml.safe_load(f)
38 TEST_DB = functest_yaml.get("results").get("test_db_url")
39 ONOS_REPO_PATH = functest_yaml.get("general").get("directories").get(
41 ONOS_CONF_DIR = functest_yaml.get("general").get("directories").get(
43 REPO_PATH = ONOS_REPO_PATH + '/functest/'
44 if not os.path.exists(REPO_PATH):
45 logger.error("Functest repository directory not found '%s'" % REPO_PATH)
48 ONOSCI_PATH = REPO_PATH + 'testcases/Controllers/ONOS/Teston/'
49 starttime = datetime.datetime.now()
51 HOME = os.environ['HOME'] + "/"
54 def RunScript(testname):
58 testname: ONOS Testcase Name
60 runtest = ONOSCI_PATH + "OnosSystemTest/TestON/bin/cli.py run " + testname
61 logger.debug("Run script " + testname)
65 def DownloadCodes(url="https://github.com/sunyulin/OnosSystemTest.git"):
67 Download Onos Teston codes
71 downloadcode = "git clone " + url + " " + ONOSCI_PATH + "OnosSystemTest"
72 logger.debug("Download Onos Teston codes " + url)
73 os.system(downloadcode)
77 LOGPATH = ONOSCI_PATH + "OnosSystemTest/TestON/logs"
78 cmd = "grep -rnh " + "Fail" + " " + LOGPATH
79 Resultbuffer = os.popen(cmd).read()
80 # duration = datetime.datetime.now() - starttime
83 if re.search("\s+[1-9]+\s+", Resultbuffer):
84 logger.debug("Testcase Fails\n" + Resultbuffer)
87 logger.debug("Testcases Success")
89 # payload={'timestart': str(starttime),
90 # 'duration': str(duration),
92 cmd = "grep -rnh 'Execution Time' " + LOGPATH
93 Resultbuffer = os.popen(cmd).read()
94 time1 = Resultbuffer[114:128]
95 time2 = Resultbuffer[28:42]
96 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNB_*"
97 Resultbuffer = os.popen(cmd).read()
98 if Resultbuffer.find('100%') >= 0:
102 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNBL3*"
103 Resultbuffer = os.popen(cmd).read()
104 if Resultbuffer.find('100%') >= 0:
110 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNB_*"
111 Resultbuffer = os.popen(cmd).read()
112 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
113 # res = pattern.search(Resultbuffer).groups()
114 res = pattern.findall(Resultbuffer)
116 for index in range(len(res)):
117 status1.append({'Case name:': res[i][0] + res[i][1],
118 'Case result': res[i][2]})
120 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNBL3*"
121 Resultbuffer = os.popen(cmd).read()
122 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
123 # res = pattern.search(Resultbuffer).groups()
124 res = pattern.findall(Resultbuffer)
126 for index in range(len(res)):
127 status2.append({'Case name:': res[i][0] + res[i][1],
128 'Case result': res[i][2]})
130 payload = {'timestart': str(starttime),
131 'FUNCvirNet': {'duration': time1,
134 'FUNCvirNetL3': {'duration': time2,
141 cmd = "openstack catalog show network | grep publicURL"
142 cmd_output = os.popen(cmd).read()
143 OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
144 os.environ['OC1'] = OC1
146 logger.debug("ONOS IP is " + OC1)
149 def SetOnosIpForJoid():
150 cmd = "env | grep SDN_CONTROLLER"
151 cmd_output = os.popen(cmd).read()
152 OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
153 os.environ['OC1'] = OC1
155 logger.debug("ONOS IP is " + OC1)
159 TESTONPATH = ONOSCI_PATH + "OnosSystemTest/"
160 cmd = "rm -rf " + TESTONPATH
163 logger.debug("Clean ONOS Teston")
167 start_time = time.time()
168 stop_time = start_time
170 if args.installer == "joid":
171 logger.debug("Installer is Joid")
175 RunScript("FUNCvirNetNB")
176 RunScript("FUNCvirNetNBL3")
179 logger.debug("Push ONOS results into DB")
180 # TODO check path result for the file
182 stop_time = time.time()
184 # ONOS success criteria = all tests OK
185 # i.e. FUNCvirNet & FUNCvirNetL3
188 if (result['FUNCvirNet']['result'] == "Success" and
189 result['FUNCvirNetL3']['result'] == "Success"):
192 logger.error("Unable to set ONOS criteria")
194 functest_utils.push_results_to_db("functest",
203 logger.error("Error pushing results into Database")
208 if __name__ == '__main__':