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
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 = ft_utils.get_functest_config("results.test_db_url")
40 ft_utils.get_functest_config("general.directories.dir_repos")
42 ft_utils.get_functest_config("general.directories.dir_functest_conf")
44 ONOSCI_PATH = ONOS_REPO_PATH + "/"
45 starttime = datetime.datetime.now()
47 HOME = os.environ['HOME'] + "/"
48 INSTALLER_TYPE = os.environ['INSTALLER_TYPE']
49 DEPLOY_SCENARIO = os.environ['DEPLOY_SCENARIO']
50 ONOSCI_PATH = ONOS_REPO_PATH + "/"
51 GLANCE_IMAGE_NAME = ft_utils.get_functest_config("onos_sfc.image_name")
52 GLANCE_IMAGE_FILENAME = \
53 ft_utils.get_functest_config("onos_sfc.image_file_name")
55 ft_utils.get_functest_config("general.directories.dir_functest_data") + \
56 "/" + GLANCE_IMAGE_FILENAME
57 SFC_PATH = ft_utils.FUNCTEST_REPO + "/" + \
58 ft_utils.get_functest_config("general.directories.dir_onos_sfc")
61 def RunScript(testname):
65 testname: ONOS Testcase Name
67 runtest = ONOSCI_PATH + "onos/TestON/bin/cli.py run " + testname
68 logger.debug("Run script " + testname)
72 def DownloadCodes(url="https://github.com/wuwenbin2/OnosSystemTest.git"):
74 Download Onos Teston codes
78 downloadcode = "git clone " + url + " " + ONOSCI_PATH + "OnosSystemTest"
79 logger.debug("Download Onos Teston codes " + url)
80 os.system(downloadcode)
84 LOGPATH = ONOSCI_PATH + "onos/TestON/logs"
85 cmd = "grep -rnh " + "Fail" + " " + LOGPATH
86 Resultbuffer = os.popen(cmd).read()
87 # duration = datetime.datetime.now() - starttime
90 if re.search("\s+[1-9]+\s+", Resultbuffer):
91 logger.debug("Testcase Fails\n" + Resultbuffer)
94 logger.debug("Testcases Success")
96 # payload={'timestart': str(starttime),
97 # 'duration': str(duration),
99 cmd = "grep -rnh 'Execution Time' " + LOGPATH
100 Resultbuffer = os.popen(cmd).read()
101 time1 = Resultbuffer[114:128]
102 time2 = Resultbuffer[28:42]
103 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNB_*"
104 Resultbuffer = os.popen(cmd).read()
105 if Resultbuffer.find('100%') >= 0:
109 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNBL3*"
110 Resultbuffer = os.popen(cmd).read()
111 if Resultbuffer.find('100%') >= 0:
117 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNB_*"
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 status1.append({'Case name:': res[i][0] + res[i][1],
125 'Case result': res[i][2]})
127 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNBL3*"
128 Resultbuffer = os.popen(cmd).read()
129 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
130 # res = pattern.search(Resultbuffer).groups()
131 res = pattern.findall(Resultbuffer)
133 for index in range(len(res)):
134 status2.append({'Case name:': res[i][0] + res[i][1],
135 'Case result': res[i][2]})
137 payload = {'timestart': str(starttime),
138 'FUNCvirNet': {'duration': time1,
141 'FUNCvirNetL3': {'duration': time2,
148 cmd = "openstack catalog show network | grep publicURL"
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)
156 def SetOnosIpForJoid():
157 cmd = "env | grep SDN_CONTROLLER"
158 cmd_output = os.popen(cmd).read()
159 OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
160 os.environ['OC1'] = OC1
162 logger.debug("ONOS IP is " + OC1)
166 TESTONPATH = ONOSCI_PATH + "onos/"
167 cmd = "rm -rf " + TESTONPATH
170 logger.debug("Clean ONOS Teston")
174 glance_client = openstack_utils.get_glance_client()
175 image_id = openstack_utils.create_glance_image(glance_client,
180 logger.error("Failed to create a Glance image...")
182 logger.debug("Image '%s' with ID=%s created successfully."
183 % (GLANCE_IMAGE_NAME, image_id))
187 cmd = "python " + SFC_PATH + "Sfc.py"
188 logger.debug("Run sfc tests")
193 cmd = "openstack catalog show " + type + " | grep publicURL"
194 cmd_output = os.popen(cmd).read()
195 ip = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
199 def Replace(before, after):
201 cmd = "sed -i 's/" + before + "/" + after + "/g' " + SFC_PATH + file
206 Replace("keystone_ip", GetIp("keystone"))
207 Replace("neutron_ip", GetIp("neutron"))
208 Replace("nova_ip", GetIp("nova"))
209 Replace("glance_ip", GetIp("glance"))
210 pwd = os.environ['OS_PASSWORD']
211 Replace("console", pwd)
212 creds_neutron = openstack_utils.get_credentials("neutron")
213 neutron_client = neutronclient.Client(**creds_neutron)
214 ext_net = openstack_utils.get_external_net(neutron_client)
215 Replace("admin_floating_net", ext_net)
216 logger.info("Modify configuration for SFC")
220 start_time = time.time()
221 stop_time = start_time
222 if INSTALLER_TYPE == "joid":
223 logger.debug("Installer is Joid")
227 RunScript("FUNCvirNetNB")
228 RunScript("FUNCvirNetNBL3")
230 logger.debug("Push ONOS results into DB")
231 # TODO check path result for the file
233 stop_time = time.time()
235 # ONOS success criteria = all tests OK
236 # i.e. FUNCvirNet & FUNCvirNetL3
239 if (result['FUNCvirNet']['result'] == "Success" and
240 result['FUNCvirNetL3']['result'] == "Success"):
243 logger.error("Unable to set ONOS criteria")
245 ft_utils.push_results_to_db("functest",
253 logger.error("Error pushing results into Database")
262 if args.testcase == "sfc":
269 if __name__ == '__main__':