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 functest_utils
27 import functest.utils.openstack_utils as openstack_utils
29 parser = argparse.ArgumentParser()
30 parser.add_argument("-t", "--testcase", help="Testcase name")
31 args = parser.parse_args()
34 """ logging configuration """
35 logger = ft_logger.Logger("onos").getLogger()
38 TEST_DB = functest_utils.get_parameter_from_yaml(
39 "results.test_db_url")
40 ONOS_REPO_PATH = functest_utils.get_parameter_from_yaml(
41 "general.directories.dir_repos")
42 ONOS_CONF_DIR = functest_utils.get_parameter_from_yaml(
43 "general.directories.dir_functest_conf")
44 REPO_PATH = ONOS_REPO_PATH + '/functest/'
45 if not os.path.exists(REPO_PATH):
46 logger.error("Functest repository directory not found '%s'" % REPO_PATH)
49 ONOSCI_PATH = ONOS_REPO_PATH + "/"
50 starttime = datetime.datetime.now()
52 HOME = os.environ['HOME'] + "/"
53 INSTALLER_TYPE = os.environ['INSTALLER_TYPE']
54 DEPLOY_SCENARIO = os.environ['DEPLOY_SCENARIO']
55 ONOSCI_PATH = ONOS_REPO_PATH + "/"
56 GLANCE_IMAGE_NAME = functest_utils.get_parameter_from_yaml(
57 "onos_sfc.image_name")
58 GLANCE_IMAGE_FILENAME = functest_utils.get_parameter_from_yaml(
59 "onos_sfc.image_file_name")
60 GLANCE_IMAGE_PATH = functest_utils.get_parameter_from_yaml(
61 "general.directories.dir_functest_data") + "/" + GLANCE_IMAGE_FILENAME
62 SFC_PATH = REPO_PATH + functest_utils.get_parameter_from_yaml(
63 "general.directories.dir_onos_sfc")
66 def RunScript(testname):
70 testname: ONOS Testcase Name
72 runtest = ONOSCI_PATH + "onos/TestON/bin/cli.py run " + testname
73 logger.debug("Run script " + testname)
77 def DownloadCodes(url="https://github.com/wuwenbin2/OnosSystemTest.git"):
79 Download Onos Teston codes
83 downloadcode = "git clone " + url + " " + ONOSCI_PATH + "OnosSystemTest"
84 logger.debug("Download Onos Teston codes " + url)
85 os.system(downloadcode)
89 LOGPATH = ONOSCI_PATH + "onos/TestON/logs"
90 cmd = "grep -rnh " + "Fail" + " " + LOGPATH
91 Resultbuffer = os.popen(cmd).read()
92 # duration = datetime.datetime.now() - starttime
95 if re.search("\s+[1-9]+\s+", Resultbuffer):
96 logger.debug("Testcase Fails\n" + Resultbuffer)
99 logger.debug("Testcases Success")
101 # payload={'timestart': str(starttime),
102 # 'duration': str(duration),
104 cmd = "grep -rnh 'Execution Time' " + LOGPATH
105 Resultbuffer = os.popen(cmd).read()
106 time1 = Resultbuffer[114:128]
107 time2 = Resultbuffer[28:42]
108 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNB_*"
109 Resultbuffer = os.popen(cmd).read()
110 if Resultbuffer.find('100%') >= 0:
114 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNBL3*"
115 Resultbuffer = os.popen(cmd).read()
116 if Resultbuffer.find('100%') >= 0:
122 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNB_*"
123 Resultbuffer = os.popen(cmd).read()
124 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
125 # res = pattern.search(Resultbuffer).groups()
126 res = pattern.findall(Resultbuffer)
128 for index in range(len(res)):
129 status1.append({'Case name:': res[i][0] + res[i][1],
130 'Case result': res[i][2]})
132 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNBL3*"
133 Resultbuffer = os.popen(cmd).read()
134 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
135 # res = pattern.search(Resultbuffer).groups()
136 res = pattern.findall(Resultbuffer)
138 for index in range(len(res)):
139 status2.append({'Case name:': res[i][0] + res[i][1],
140 'Case result': res[i][2]})
142 payload = {'timestart': str(starttime),
143 'FUNCvirNet': {'duration': time1,
146 'FUNCvirNetL3': {'duration': time2,
153 cmd = "openstack catalog show network | grep publicURL"
154 cmd_output = os.popen(cmd).read()
155 OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
156 os.environ['OC1'] = OC1
158 logger.debug("ONOS IP is " + OC1)
161 def SetOnosIpForJoid():
162 cmd = "env | grep SDN_CONTROLLER"
163 cmd_output = os.popen(cmd).read()
164 OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
165 os.environ['OC1'] = OC1
167 logger.debug("ONOS IP is " + OC1)
171 TESTONPATH = ONOSCI_PATH + "onos/"
172 cmd = "rm -rf " + TESTONPATH
175 logger.debug("Clean ONOS Teston")
179 glance_client = openstack_utils.get_glance_client()
180 image_id = openstack_utils.create_glance_image(glance_client,
185 logger.error("Failed to create a Glance image...")
187 logger.debug("Image '%s' with ID=%s created successfully."
188 % (GLANCE_IMAGE_NAME, image_id))
192 cmd = "python " + SFC_PATH + "Sfc.py"
193 logger.debug("Run sfc tests")
198 cmd = "openstack catalog show " + type + " | grep publicURL"
199 cmd_output = os.popen(cmd).read()
200 ip = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
204 def Replace(before, after):
206 cmd = "sed -i 's/" + before + "/" + after + "/g' " + SFC_PATH + file
211 Replace("keystone_ip", GetIp("keystone"))
212 Replace("neutron_ip", GetIp("neutron"))
213 Replace("nova_ip", GetIp("nova"))
214 Replace("glance_ip", GetIp("glance"))
215 pwd = os.environ['OS_PASSWORD']
216 Replace("console", pwd)
217 creds_neutron = openstack_utils.get_credentials("neutron")
218 neutron_client = neutronclient.Client(**creds_neutron)
219 ext_net = openstack_utils.get_external_net(neutron_client)
220 Replace("admin_floating_net", ext_net)
221 logger.info("Modify configuration for SFC")
225 start_time = time.time()
226 stop_time = start_time
227 if INSTALLER_TYPE == "joid":
228 logger.debug("Installer is Joid")
232 RunScript("FUNCvirNetNB")
233 RunScript("FUNCvirNetNBL3")
235 logger.debug("Push ONOS results into DB")
236 # TODO check path result for the file
238 stop_time = time.time()
240 # ONOS success criteria = all tests OK
241 # i.e. FUNCvirNet & FUNCvirNetL3
244 if (result['FUNCvirNet']['result'] == "Success" and
245 result['FUNCvirNetL3']['result'] == "Success"):
248 logger.error("Unable to set ONOS criteria")
250 functest_utils.push_results_to_db("functest",
259 logger.error("Error pushing results into Database")
268 if args.testcase == "sfc":
275 if __name__ == '__main__':