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 keystoneclient.v2_0 import client as keystoneclient
25 from glanceclient import client as glanceclient
27 import functest.utils.functest_logger as ft_logger
28 import functest.utils.functest_utils as functest_utils
29 import functest.utils.openstack_utils as openstack_utils
31 # parser = argparse.ArgumentParser()
32 # parser.add_argument("-i", "--installer", help="Installer type")
33 # args = parser.parse_args()
34 """ logging configuration """
35 logger = ft_logger.Logger("onos").getLogger()
37 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
38 functest_yaml = yaml.safe_load(f)
42 TEST_DB = functest_yaml.get("results").get("test_db_url")
43 ONOS_REPO_PATH = functest_yaml.get("general").get("directories").get(
45 ONOS_CONF_DIR = functest_yaml.get("general").get("directories").get(
47 REPO_PATH = ONOS_REPO_PATH + '/functest/'
48 if not os.path.exists(REPO_PATH):
49 logger.error("Functest repository directory not found '%s'" % REPO_PATH)
52 ONOSCI_PATH = ONOS_REPO_PATH + "/"
53 starttime = datetime.datetime.now()
55 HOME = os.environ['HOME'] + "/"
56 INSTALLER_TYPE = os.environ['INSTALLER_TYPE']
57 DEPLOY_SCENARIO = os.environ['DEPLOY_SCENARIO']
58 ONOSCI_PATH = ONOS_REPO_PATH + "/"
59 GLANCE_IMAGE_NAME = functest_yaml.get("onos_sfc").get("image_name")
60 GLANCE_IMAGE_FILENAME = functest_yaml.get("onos_sfc").get("image_file_name")
61 GLANCE_IMAGE_FORMAT = functest_yaml.get("general").get("openstack").get(
63 GLANCE_IMAGE_PATH = functest_yaml.get("general").get("directories").get(
64 "dir_functest_data") + "/" + GLANCE_IMAGE_FILENAME
65 SFC_PATH = REPO_PATH + functest_yaml.get("general").get("directories").get(
69 def RunScript(testname):
73 testname: ONOS Testcase Name
75 runtest = ONOSCI_PATH + "onos/TestON/bin/cli.py run " + testname
76 logger.debug("Run script " + testname)
80 def DownloadCodes(url="https://github.com/wuwenbin2/OnosSystemTest.git"):
82 Download Onos Teston codes
86 downloadcode = "git clone " + url + " " + ONOSCI_PATH + "OnosSystemTest"
87 logger.debug("Download Onos Teston codes " + url)
88 os.system(downloadcode)
92 LOGPATH = ONOSCI_PATH + "onos/TestON/logs"
93 cmd = "grep -rnh " + "Fail" + " " + LOGPATH
94 Resultbuffer = os.popen(cmd).read()
95 # duration = datetime.datetime.now() - starttime
98 if re.search("\s+[1-9]+\s+", Resultbuffer):
99 logger.debug("Testcase Fails\n" + Resultbuffer)
102 logger.debug("Testcases Success")
104 # payload={'timestart': str(starttime),
105 # 'duration': str(duration),
107 cmd = "grep -rnh 'Execution Time' " + LOGPATH
108 Resultbuffer = os.popen(cmd).read()
109 time1 = Resultbuffer[114:128]
110 time2 = Resultbuffer[28:42]
111 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNB_*"
112 Resultbuffer = os.popen(cmd).read()
113 if Resultbuffer.find('100%') >= 0:
117 cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNBL3*"
118 Resultbuffer = os.popen(cmd).read()
119 if Resultbuffer.find('100%') >= 0:
125 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNB_*"
126 Resultbuffer = os.popen(cmd).read()
127 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
128 # res = pattern.search(Resultbuffer).groups()
129 res = pattern.findall(Resultbuffer)
131 for index in range(len(res)):
132 status1.append({'Case name:': res[i][0] + res[i][1],
133 'Case result': res[i][2]})
135 cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNBL3*"
136 Resultbuffer = os.popen(cmd).read()
137 pattern = re.compile("<h3>([^-]+) - ([^-]+) - (\S*)</h3>")
138 # res = pattern.search(Resultbuffer).groups()
139 res = pattern.findall(Resultbuffer)
141 for index in range(len(res)):
142 status2.append({'Case name:': res[i][0] + res[i][1],
143 'Case result': res[i][2]})
145 payload = {'timestart': str(starttime),
146 'FUNCvirNet': {'duration': time1,
149 'FUNCvirNetL3': {'duration': time2,
156 cmd = "openstack catalog show network | grep publicURL"
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)
164 def SetOnosIpForJoid():
165 cmd = "env | grep SDN_CONTROLLER"
166 cmd_output = os.popen(cmd).read()
167 OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
168 os.environ['OC1'] = OC1
170 logger.debug("ONOS IP is " + OC1)
174 TESTONPATH = ONOSCI_PATH + "onos/"
175 cmd = "rm -rf " + TESTONPATH
178 logger.debug("Clean ONOS Teston")
182 creds_keystone = openstack_utils.get_credentials("keystone")
183 keystone_client = keystoneclient.Client(**creds_keystone)
184 glance_endpoint = keystone_client.service_catalog.url_for(
185 service_type='image', endpoint_type='publicURL')
186 glance_client = glanceclient.Client(1, glance_endpoint,
187 token=keystone_client.auth_token)
189 # Check if the given image exists
190 image_id = openstack_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME)
192 logger.info("Using existing image '%s'..." % GLANCE_IMAGE_NAME)
196 logger.info("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME,
198 image_id = openstack_utils.create_glance_image(glance_client,
202 logger.error("Failed to create a Glance image...")
204 logger.debug("Image '%s' with ID=%s created successfully."
205 % (GLANCE_IMAGE_NAME, image_id))
209 cmd = "python " + SFC_PATH + "Sfc.py"
210 logger.debug("Run sfc tests")
215 cmd = "openstack catalog show network | grep publicURL"
216 cmd_output = os.popen(cmd).read()
217 ip = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group()
218 cmd_onos_ip = "sed -i 's/onos_ip/" + ip + "/g' " + SFC_PATH + "Sfc_fun.py"
219 cmd_openstack_ip = "sed -i 's/openstack_ip/" + ip\
220 + "/g' " + SFC_PATH + "Sfc_fun.py"
221 logger.info("Modify ip for SFC")
222 os.system(cmd_onos_ip)
223 os.system(cmd_openstack_ip)
227 start_time = time.time()
228 stop_time = start_time
230 # if args.installer == "joid":
231 if INSTALLER_TYPE == "joid":
232 logger.debug("Installer is Joid")
236 RunScript("FUNCvirNetNB")
237 RunScript("FUNCvirNetNBL3")
238 if DEPLOY_SCENARIO == "os-onos-sfc-ha":
243 logger.debug("Push ONOS results into DB")
244 # TODO check path result for the file
246 stop_time = time.time()
248 # ONOS success criteria = all tests OK
249 # i.e. FUNCvirNet & FUNCvirNetL3
252 if (result['FUNCvirNet']['result'] == "Success" and
253 result['FUNCvirNetL3']['result'] == "Success"):
256 logger.error("Unable to set ONOS criteria")
258 functest_utils.push_results_to_db("functest",
267 logger.error("Error pushing results into Database")
272 if __name__ == '__main__':