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
23 from neutronclient.v2_0 import client as neutronclient
25 import functest.utils.functest_logger as ft_logger
26 import functest.utils.functest_utils as ft_utils
27 import functest.utils.openstack_utils as openstack_utils
28 import functest.utils.functest_constants as ft_constants
31 parser = argparse.ArgumentParser()
32 parser.add_argument("-t", "--testcase", help="Testcase name")
33 args = parser.parse_args()
36 """ logging configuration """
37 logger = ft_logger.Logger("onos").getLogger()
40 ONOSCI_PATH = ft_constants.REPOS_DIR + "/"
41 starttime = datetime.datetime.now()
43 INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE
44 ONOS_SFC_IMAGE_NAME = ft_constants.ONOS_SFC_IMAGE_NAME
45 ONOS_SFC_IMAGE_PATH = os.path.join(ft_constants.FUNCTEST_DATA_DIR,
46 ft_constants.ONOS_SFC_IMAGE_FILENAME)
47 ONOS_SFC_PATH = os.path.join(ft_constants.FUNCTEST_REPO_DIR,
48 ft_constants.ONOS_SFC_RELATIVE_PATH)
51 def RunScript(testname):
55 testname: ONOS Testcase Name
57 runtest = ONOSCI_PATH + "onos/TestON/bin/cli.py run " + testname
58 logger.debug("Run script " + testname)
62 def DownloadCodes(url="https://github.com/wuwenbin2/OnosSystemTest.git"):
64 Download Onos Teston codes
68 downloadcode = "git clone " + url + " " + ONOSCI_PATH + "OnosSystemTest"
69 logger.debug("Download Onos Teston codes " + url)
70 os.system(downloadcode)
74 LOGPATH = ONOSCI_PATH + "onos/TestON/logs"
75 cmd = "grep -rnh " + "Fail" + " " + LOGPATH
76 Resultbuffer = os.popen(cmd).read()
77 # duration = datetime.datetime.now() - starttime
80 if re.search("\s+[1-9]+\s+", Resultbuffer):
81 logger.debug("Testcase Fails\n" + Resultbuffer)
84 logger.debug("Testcases Success")
86 # payload={'timestart': str(starttime),
87 # 'duration': str(duration),
89 cmd = "grep -rnh 'Execution Time' " + LOGPATH
90 Resultbuffer = os.popen(cmd).read()
91 time1 = Resultbuffer[114:128]
92 time2 = Resultbuffer[28:42]
93 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNB_*"
94 Resultbuffer = os.popen(cmd).read()
95 if Resultbuffer.find('100%') >= 0:
99 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNBL3*"
100 Resultbuffer = os.popen(cmd).read()
101 if Resultbuffer.find('100%') >= 0:
107 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNB_*"
108 Resultbuffer = os.popen(cmd).read()
109 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
110 # res = pattern.search(Resultbuffer).groups()
111 res = pattern.findall(Resultbuffer)
113 for index in range(len(res)):
114 status1.append({'Case name:': res[i][0] + res[i][1],
115 'Case result': res[i][2]})
117 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNBL3*"
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 status2.append({'Case name:': res[i][0] + res[i][1],
125 'Case result': res[i][2]})
127 payload = {'timestart': str(starttime),
128 'FUNCvirNet': {'duration': time1,
131 'FUNCvirNetL3': {'duration': time2,
138 cmd = "openstack catalog show network | grep publicURL"
139 cmd_output = os.popen(cmd).read()
140 OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
141 os.environ['OC1'] = OC1
143 logger.debug("ONOS IP is " + OC1)
146 def SetOnosIpForJoid():
147 cmd = "env | grep SDN_CONTROLLER"
148 cmd_output = os.popen(cmd).read()
149 OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
150 os.environ['OC1'] = OC1
152 logger.debug("ONOS IP is " + OC1)
156 TESTONPATH = ONOSCI_PATH + "onos/"
157 cmd = "rm -rf " + TESTONPATH
160 logger.debug("Clean ONOS Teston")
164 glance_client = openstack_utils.get_glance_client()
165 image_id = openstack_utils.create_glance_image(glance_client,
170 logger.error("Failed to create a Glance image...")
172 logger.debug("Image '%s' with ID=%s created successfully."
173 % (ONOS_SFC_IMAGE_NAME, image_id))
177 cmd = "python " + ONOS_SFC_PATH + "/Sfc.py"
178 logger.debug("Run sfc tests")
183 cmd = "openstack catalog show " + type + " | grep publicURL"
184 cmd_output = os.popen(cmd).read()
185 ip = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
189 def Replace(before, after):
191 cmd = "sed -i 's/" + before + "/" + after + "/g' " + ONOS_SFC_PATH + file
196 Replace("keystone_ip", GetIp("keystone"))
197 Replace("neutron_ip", GetIp("neutron"))
198 Replace("nova_ip", GetIp("nova"))
199 Replace("glance_ip", GetIp("glance"))
200 pwd = ft_constants.OS_PASSWORD
201 Replace("console", pwd)
202 creds_neutron = openstack_utils.get_credentials("neutron")
203 neutron_client = neutronclient.Client(**creds_neutron)
204 ext_net = openstack_utils.get_external_net(neutron_client)
205 Replace("admin_floating_net", ext_net)
206 logger.info("Modify configuration for SFC")
210 start_time = time.time()
211 stop_time = start_time
212 if INSTALLER_TYPE == "joid":
213 logger.debug("Installer is Joid")
217 RunScript("FUNCvirNetNB")
218 RunScript("FUNCvirNetNBL3")
220 logger.debug("Push ONOS results into DB")
221 # TODO check path result for the file
223 stop_time = time.time()
225 # ONOS success criteria = all tests OK
226 # i.e. FUNCvirNet & FUNCvirNetL3
229 if (result['FUNCvirNet']['result'] == "Success" and
230 result['FUNCvirNetL3']['result'] == "Success"):
233 logger.error("Unable to set ONOS criteria")
235 ft_utils.push_results_to_db("functest",
243 logger.error("Error pushing results into Database")
252 if args.testcase == "sfc":
260 if __name__ == '__main__':