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
22 import functest.utils.functest_logger as ft_logger
23 import functest.utils.functest_utils as functest_utils
24 import functest.utils.openstack_utils as openstack_utils
26 """ logging configuration """
27 logger = ft_logger.Logger("onos").getLogger()
30 TEST_DB = functest_utils.get_parameter_from_yaml(
31 "results.test_db_url")
32 ONOS_REPO_PATH = functest_utils.get_parameter_from_yaml(
33 "general.directories.dir_repos")
34 ONOS_CONF_DIR = functest_utils.get_parameter_from_yaml(
35 "general.directories.dir_functest_conf")
36 REPO_PATH = ONOS_REPO_PATH + '/functest/'
37 if not os.path.exists(REPO_PATH):
38 logger.error("Functest repository directory not found '%s'" % REPO_PATH)
41 ONOSCI_PATH = ONOS_REPO_PATH + "/"
42 starttime = datetime.datetime.now()
44 HOME = os.environ['HOME'] + "/"
45 INSTALLER_TYPE = os.environ['INSTALLER_TYPE']
46 DEPLOY_SCENARIO = os.environ['DEPLOY_SCENARIO']
47 ONOSCI_PATH = ONOS_REPO_PATH + "/"
48 GLANCE_IMAGE_NAME = functest_utils.get_parameter_from_yaml(
49 "onos_sfc.image_name")
50 GLANCE_IMAGE_FILENAME = functest_utils.get_parameter_from_yaml(
51 "onos_sfc.image_file_name")
52 GLANCE_IMAGE_PATH = functest_utils.get_parameter_from_yaml(
53 "general.directories.dir_functest_data") + "/" + GLANCE_IMAGE_FILENAME
54 SFC_PATH = REPO_PATH + functest_utils.get_parameter_from_yaml(
55 "general.directories.dir_onos_sfc")
58 def RunScript(testname):
62 testname: ONOS Testcase Name
64 runtest = ONOSCI_PATH + "onos/TestON/bin/cli.py run " + testname
65 logger.debug("Run script " + testname)
69 def DownloadCodes(url="https://github.com/wuwenbin2/OnosSystemTest.git"):
71 Download Onos Teston codes
75 downloadcode = "git clone " + url + " " + ONOSCI_PATH + "OnosSystemTest"
76 logger.debug("Download Onos Teston codes " + url)
77 os.system(downloadcode)
81 LOGPATH = ONOSCI_PATH + "onos/TestON/logs"
82 cmd = "grep -rnh " + "Fail" + " " + LOGPATH
83 Resultbuffer = os.popen(cmd).read()
84 # duration = datetime.datetime.now() - starttime
87 if re.search("\s+[1-9]+\s+", Resultbuffer):
88 logger.debug("Testcase Fails\n" + Resultbuffer)
91 logger.debug("Testcases Success")
93 # payload={'timestart': str(starttime),
94 # 'duration': str(duration),
96 cmd = "grep -rnh 'Execution Time' " + LOGPATH
97 Resultbuffer = os.popen(cmd).read()
98 time1 = Resultbuffer[114:128]
99 time2 = Resultbuffer[28:42]
100 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNB_*"
101 Resultbuffer = os.popen(cmd).read()
102 if Resultbuffer.find('100%') >= 0:
106 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNBL3*"
107 Resultbuffer = os.popen(cmd).read()
108 if Resultbuffer.find('100%') >= 0:
114 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNB_*"
115 Resultbuffer = os.popen(cmd).read()
116 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
117 # res = pattern.search(Resultbuffer).groups()
118 res = pattern.findall(Resultbuffer)
120 for index in range(len(res)):
121 status1.append({'Case name:': res[i][0] + res[i][1],
122 'Case result': res[i][2]})
124 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNBL3*"
125 Resultbuffer = os.popen(cmd).read()
126 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
127 # res = pattern.search(Resultbuffer).groups()
128 res = pattern.findall(Resultbuffer)
130 for index in range(len(res)):
131 status2.append({'Case name:': res[i][0] + res[i][1],
132 'Case result': res[i][2]})
134 payload = {'timestart': str(starttime),
135 'FUNCvirNet': {'duration': time1,
138 'FUNCvirNetL3': {'duration': time2,
145 cmd = "openstack catalog show 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)
153 def SetOnosIpForJoid():
154 cmd = "env | grep SDN_CONTROLLER"
155 cmd_output = os.popen(cmd).read()
156 OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
157 os.environ['OC1'] = OC1
159 logger.debug("ONOS IP is " + OC1)
163 TESTONPATH = ONOSCI_PATH + "onos/"
164 cmd = "rm -rf " + TESTONPATH
167 logger.debug("Clean ONOS Teston")
171 glance_client = openstack_utils.get_glance_client()
172 image_id = openstack_utils.create_glance_image(glance_client,
177 logger.error("Failed to create a Glance image...")
179 logger.debug("Image '%s' with ID=%s created successfully."
180 % (GLANCE_IMAGE_NAME, image_id))
184 cmd = "python " + SFC_PATH + "Sfc.py"
185 logger.debug("Run sfc tests")
190 cmd = "openstack catalog show network | grep publicURL"
191 cmd_output = os.popen(cmd).read()
192 ip = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
193 cmd_onos_ip = "sed -i 's/onos_ip/" + ip + "/g' " + SFC_PATH + "Sfc_fun.py"
194 cmd_openstack_ip = "sed -i 's/openstack_ip/" + ip\
195 + "/g' " + SFC_PATH + "Sfc_fun.py"
196 logger.info("Modify ip for SFC")
197 os.system(cmd_onos_ip)
198 os.system(cmd_openstack_ip)
202 start_time = time.time()
203 stop_time = start_time
205 # if args.installer == "joid":
206 if INSTALLER_TYPE == "joid":
207 logger.debug("Installer is Joid")
211 RunScript("FUNCvirNetNB")
212 RunScript("FUNCvirNetNBL3")
213 if DEPLOY_SCENARIO == "os-onos-sfc-ha":
218 logger.debug("Push ONOS results into DB")
219 # TODO check path result for the file
221 stop_time = time.time()
223 # ONOS success criteria = all tests OK
224 # i.e. FUNCvirNet & FUNCvirNetL3
227 if (result['FUNCvirNet']['result'] == "Success" and
228 result['FUNCvirNetL3']['result'] == "Success"):
231 logger.error("Unable to set ONOS criteria")
233 functest_utils.push_results_to_db("functest",
242 logger.error("Error pushing results into Database")
247 if __name__ == '__main__':