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 from neutronclient.v2_0 import client as neutronclient
24 import functest.utils.functest_logger as ft_logger
25 import functest.utils.functest_utils as functest_utils
26 import functest.utils.openstack_utils as openstack_utils
28 """ logging configuration """
29 logger = ft_logger.Logger("onos").getLogger()
32 TEST_DB = functest_utils.get_parameter_from_yaml(
33 "results.test_db_url")
34 ONOS_REPO_PATH = functest_utils.get_parameter_from_yaml(
35 "general.directories.dir_repos")
36 ONOS_CONF_DIR = functest_utils.get_parameter_from_yaml(
37 "general.directories.dir_functest_conf")
38 REPO_PATH = ONOS_REPO_PATH + '/functest/'
39 if not os.path.exists(REPO_PATH):
40 logger.error("Functest repository directory not found '%s'" % REPO_PATH)
43 ONOSCI_PATH = ONOS_REPO_PATH + "/"
44 starttime = datetime.datetime.now()
46 HOME = os.environ['HOME'] + "/"
47 INSTALLER_TYPE = os.environ['INSTALLER_TYPE']
48 DEPLOY_SCENARIO = os.environ['DEPLOY_SCENARIO']
49 ONOSCI_PATH = ONOS_REPO_PATH + "/"
50 GLANCE_IMAGE_NAME = functest_utils.get_parameter_from_yaml(
51 "onos_sfc.image_name")
52 GLANCE_IMAGE_FILENAME = functest_utils.get_parameter_from_yaml(
53 "onos_sfc.image_file_name")
54 GLANCE_IMAGE_PATH = functest_utils.get_parameter_from_yaml(
55 "general.directories.dir_functest_data") + "/" + GLANCE_IMAGE_FILENAME
56 SFC_PATH = REPO_PATH + functest_utils.get_parameter_from_yaml(
57 "general.directories.dir_onos_sfc")
60 def RunScript(testname):
64 testname: ONOS Testcase Name
66 runtest = ONOSCI_PATH + "onos/TestON/bin/cli.py run " + testname
67 logger.debug("Run script " + testname)
71 def DownloadCodes(url="https://github.com/wuwenbin2/OnosSystemTest.git"):
73 Download Onos Teston codes
77 downloadcode = "git clone " + url + " " + ONOSCI_PATH + "OnosSystemTest"
78 logger.debug("Download Onos Teston codes " + url)
79 os.system(downloadcode)
83 LOGPATH = ONOSCI_PATH + "onos/TestON/logs"
84 cmd = "grep -rnh " + "Fail" + " " + LOGPATH
85 Resultbuffer = os.popen(cmd).read()
86 # duration = datetime.datetime.now() - starttime
89 if re.search("\s+[1-9]+\s+", Resultbuffer):
90 logger.debug("Testcase Fails\n" + Resultbuffer)
93 logger.debug("Testcases Success")
95 # payload={'timestart': str(starttime),
96 # 'duration': str(duration),
98 cmd = "grep -rnh 'Execution Time' " + LOGPATH
99 Resultbuffer = os.popen(cmd).read()
100 time1 = Resultbuffer[114:128]
101 time2 = Resultbuffer[28:42]
102 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNB_*"
103 Resultbuffer = os.popen(cmd).read()
104 if Resultbuffer.find('100%') >= 0:
108 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNBL3*"
109 Resultbuffer = os.popen(cmd).read()
110 if Resultbuffer.find('100%') >= 0:
116 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNB_*"
117 Resultbuffer = os.popen(cmd).read()
118 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
119 # res = pattern.search(Resultbuffer).groups()
120 res = pattern.findall(Resultbuffer)
122 for index in range(len(res)):
123 status1.append({'Case name:': res[i][0] + res[i][1],
124 '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],
134 'Case result': res[i][2]})
136 payload = {'timestart': str(starttime),
137 'FUNCvirNet': {'duration': time1,
140 'FUNCvirNetL3': {'duration': time2,
147 cmd = "openstack catalog show network | grep publicURL"
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)
155 def SetOnosIpForJoid():
156 cmd = "env | grep SDN_CONTROLLER"
157 cmd_output = os.popen(cmd).read()
158 OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
159 os.environ['OC1'] = OC1
161 logger.debug("ONOS IP is " + OC1)
165 TESTONPATH = ONOSCI_PATH + "onos/"
166 cmd = "rm -rf " + TESTONPATH
169 logger.debug("Clean ONOS Teston")
173 glance_client = openstack_utils.get_glance_client()
174 image_id = openstack_utils.create_glance_image(glance_client,
179 logger.error("Failed to create a Glance image...")
181 logger.debug("Image '%s' with ID=%s created successfully."
182 % (GLANCE_IMAGE_NAME, image_id))
186 cmd = "python " + SFC_PATH + "Sfc.py"
187 logger.debug("Run sfc tests")
192 cmd = "openstack catalog show " + type + " | grep publicURL"
193 cmd_output = os.popen(cmd).read()
194 ip = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
198 def Replace(before, after):
200 cmd = "sed -i 's/" + before + "/" + after + "/g' " + SFC_PATH + file
205 Replace("keystone_ip", GetIp("keystone"))
206 Replace("neutron_ip", GetIp("neutron"))
207 Replace("nova_ip", GetIp("nova"))
208 Replace("glance_ip", GetIp("glance"))
209 pwd = os.environ['OS_PASSWORD']
210 Replace("console", pwd)
211 creds_neutron = openstack_utils.get_credentials("neutron")
212 neutron_client = neutronclient.Client(**creds_neutron)
213 ext_net = openstack_utils.get_external_net(neutron_client)
214 Replace("admin_floating_net", ext_net)
215 logger.info("Modify configuration for SFC")
219 start_time = time.time()
220 stop_time = start_time
222 # if args.installer == "joid":
223 if INSTALLER_TYPE == "joid":
224 logger.debug("Installer is Joid")
228 RunScript("FUNCvirNetNB")
229 RunScript("FUNCvirNetNBL3")
231 logger.debug("Push ONOS results into DB")
232 # TODO check path result for the file
234 stop_time = time.time()
236 # ONOS success criteria = all tests OK
237 # i.e. FUNCvirNet & FUNCvirNetL3
240 if (result['FUNCvirNet']['result'] == "Success" and
241 result['FUNCvirNetL3']['result'] == "Success"):
244 logger.error("Unable to set ONOS criteria")
246 functest_utils.push_results_to_db("functest",
255 logger.error("Error pushing results into Database")
257 if DEPLOY_SCENARIO == "os-onos-sfc-ha":
265 if __name__ == '__main__':