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 from neutronclient.v2_0 import client as neutronclient
26 import functest.utils.functest_constants as ft_constants
27 import functest.utils.functest_logger as ft_logger
28 import functest.utils.functest_utils as ft_utils
29 import functest.utils.openstack_utils as openstack_utils
32 parser = argparse.ArgumentParser()
33 parser.add_argument("-t", "--testcase", help="Testcase name")
34 args = parser.parse_args()
37 """ logging configuration """
38 logger = ft_logger.Logger("onos").getLogger()
41 ONOSCI_PATH = ft_constants.REPOS_DIR + "/"
42 starttime = datetime.datetime.now()
44 INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE
45 ONOS_SFC_IMAGE_NAME = ft_constants.ONOS_SFC_IMAGE_NAME
46 ONOS_SFC_IMAGE_PATH = os.path.join(ft_constants.FUNCTEST_DATA_DIR,
47 ft_constants.ONOS_SFC_IMAGE_FILENAME)
48 ONOS_SFC_PATH = os.path.join(ft_constants.FUNCTEST_REPO_DIR,
49 ft_constants.ONOS_SFC_RELATIVE_PATH)
52 def RunScript(testname):
56 testname: ONOS Testcase Name
58 runtest = ONOSCI_PATH + "onos/TestON/bin/cli.py run " + testname
59 logger.debug("Run script " + testname)
63 def DownloadCodes(url="https://github.com/wuwenbin2/OnosSystemTest.git"):
65 Download Onos Teston codes
69 downloadcode = "git clone " + url + " " + ONOSCI_PATH + "OnosSystemTest"
70 logger.debug("Download Onos Teston codes " + url)
71 os.system(downloadcode)
75 LOGPATH = ONOSCI_PATH + "onos/TestON/logs"
76 cmd = "grep -rnh " + "Fail" + " " + LOGPATH
77 Resultbuffer = os.popen(cmd).read()
78 # duration = datetime.datetime.now() - starttime
81 if re.search("\s+[1-9]+\s+", Resultbuffer):
82 logger.debug("Testcase Fails\n" + Resultbuffer)
85 logger.debug("Testcases Success")
87 # payload={'timestart': str(starttime),
88 # 'duration': str(duration),
90 cmd = "grep -rnh 'Execution Time' " + LOGPATH
91 Resultbuffer = os.popen(cmd).read()
92 time1 = Resultbuffer[114:128]
93 time2 = Resultbuffer[28:42]
94 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNB_*"
95 Resultbuffer = os.popen(cmd).read()
96 if Resultbuffer.find('100%') >= 0:
100 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNBL3*"
101 Resultbuffer = os.popen(cmd).read()
102 if Resultbuffer.find('100%') >= 0:
108 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNB_*"
109 Resultbuffer = os.popen(cmd).read()
110 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
111 # res = pattern.search(Resultbuffer).groups()
112 res = pattern.findall(Resultbuffer)
114 for index in range(len(res)):
115 status1.append({'Case name:': res[i][0] + res[i][1],
116 'Case result': res[i][2]})
118 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNBL3*"
119 Resultbuffer = os.popen(cmd).read()
120 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
121 # res = pattern.search(Resultbuffer).groups()
122 res = pattern.findall(Resultbuffer)
124 for index in range(len(res)):
125 status2.append({'Case name:': res[i][0] + res[i][1],
126 'Case result': res[i][2]})
128 payload = {'timestart': str(starttime),
129 'FUNCvirNet': {'duration': time1,
132 'FUNCvirNetL3': {'duration': time2,
139 # cmd = "openstack catalog show network | grep publicURL"
140 neutron_url = openstack_utils.get_endpoint(service_type='network')
141 OC1 = urlparse.urlparse(neutron_url).hostname
142 os.environ['OC1'] = OC1
144 logger.debug("ONOS IP is " + OC1)
147 def SetOnosIpForJoid():
148 cmd = "env | grep SDN_CONTROLLER"
149 cmd_output = os.popen(cmd).read()
150 OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
151 os.environ['OC1'] = OC1
153 logger.debug("ONOS IP is " + OC1)
157 TESTONPATH = ONOSCI_PATH + "onos/"
158 cmd = "rm -rf " + TESTONPATH
161 logger.debug("Clean ONOS Teston")
165 glance_client = openstack_utils.get_glance_client()
166 image_id = openstack_utils.create_glance_image(glance_client,
171 logger.error("Failed to create a Glance image...")
173 logger.debug("Image '%s' with ID=%s created successfully."
174 % (ONOS_SFC_IMAGE_NAME, image_id))
178 cmd = "python " + ONOS_SFC_PATH + "/Sfc.py"
179 logger.debug("Run sfc tests")
184 # cmd = "openstack catalog show " + type + " | grep publicURL"
185 url = openstack_utils.get_endpoint(service_type=type)
186 return urlparse.urlparse(url).hostname
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__':