blob: d3144101beafe0c0736882d40e2435f3bc717b33 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
2'''
James Leec9cacaf2014-04-08 09:17:39 -07003Created on 31-May-2013
adminbae64d82013-08-01 10:50:15 -07004
James Leec9cacaf2014-04-08 09:17:39 -07005@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
adminbae64d82013-08-01 10:50:15 -07006
James Leec9cacaf2014-04-08 09:17:39 -07007TestON is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
adminbae64d82013-08-01 10:50:15 -070011
James Leec9cacaf2014-04-08 09:17:39 -070012TestON is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
adminbae64d82013-08-01 10:50:15 -070016
James Leec9cacaf2014-04-08 09:17:39 -070017You should have received a copy of the GNU General Public License
18along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070019
20
James Leec9cacaf2014-04-08 09:17:39 -070021'''
adminbae64d82013-08-01 10:50:15 -070022import time
23import pexpect
24import struct, fcntl, os, sys, signal
adminbae64d82013-08-01 10:50:15 -070025import re
26import json
Jon Hallf89c8552014-04-02 13:14:06 -070027import traceback
admin2a9548d2014-06-17 14:08:07 -070028import urllib2
29from urllib2 import URLError, HTTPError
adminbae64d82013-08-01 10:50:15 -070030sys.path.append("../")
31from drivers.common.clidriver import CLI
32
33class OnosCliDriver(CLI):
34
35 def __init__(self):
36 super(CLI, self).__init__()
37
38 def connect(self,**connectargs):
Jon Halld8dc5772014-04-08 16:26:29 -070039 '''
40 Creates ssh handle for ONOS.
41 '''
Jon Hallf89c8552014-04-02 13:14:06 -070042 try:
43 for key in connectargs:
admine0eeea22014-04-14 10:22:46 -070044 vars(self)[key] = connectargs[key]
Jon Hallf89c8552014-04-02 13:14:06 -070045 self.home = "~/ONOS"
46 for key in self.options:
admine0eeea22014-04-14 10:22:46 -070047 if key == "home":
48 self.home = self.options['home']
49 break
adminbae64d82013-08-01 10:50:15 -070050
Jon Hallf89c8552014-04-02 13:14:06 -070051
52 self.name = self.options['name']
53 self.handle = super(OnosCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd, home = self.home)
adminbae64d82013-08-01 10:50:15 -070054
Jon Hallf89c8552014-04-02 13:14:06 -070055 if self.handle:
Jon Hallf89c8552014-04-02 13:14:06 -070056 return self.handle
57 else :
58 main.log.info("NO ONOS HANDLE")
59 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -070060 except pexpect.EOF:
61 main.log.error(self.name + ": EOF exception found")
62 main.log.error(self.name + ": " + self.handle.before)
63 main.cleanup()
64 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -070065 except:
66 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
67 main.log.error( traceback.print_exc() )
68 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
69 main.cleanup()
70 main.exit()
admin680b78c2014-08-08 11:46:45 -070071
72 def portKill(self, port):
73 try:
74 self.handle.sendline("")
75 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
76 cmd = "sudo tcpkill -i eth0 port " + str(port) + " 2>/dev/null 1>/dev/null &"
77 self.handle.sendline(cmd)
78 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
79 except pexpect.EOF:
80 main.log.error(self.name + ": EOF exception found")
81 main.log.error(self.name + ": " + self.handle.before)
82 main.cleanup()
83 main.exit()
84 except:
85 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
86 main.log.error( traceback.print_exc() )
87 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
88 main.cleanup()
89 main.exit()
90
91 def endPortKill(self,port):
92 try:
93 self.handle.sendline("")
94 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
95 self.handle.sendline("sudo pkill tcpkill")
96 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
97 except pexpect.EOF:
98 main.log.error(self.name + ": EOF exception found")
99 main.log.error(self.name + ": " + self.handle.before)
100 main.cleanup()
101 main.exit()
102 except:
103 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
104 main.log.error( traceback.print_exc() )
105 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
106 main.cleanup()
107 main.exit()
adminbae64d82013-08-01 10:50:15 -0700108
Jon Hallf0a494f2014-06-23 15:37:40 -0700109 def start(self, env = ''):
Jon Halld8dc5772014-04-08 16:26:29 -0700110 '''
111 Starts ONOS on remote machine.
112 Returns false if any errors were encountered.
113 '''
James Leec9cacaf2014-04-08 09:17:39 -0700114 try:
Jon Hallf89c8552014-04-02 13:14:06 -0700115 self.handle.sendline("")
Jon Hallae05dc22014-04-16 10:56:28 -0700116 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700117 self.handle.sendline("cd "+self.home)
Jon Hallf0a494f2014-06-23 15:37:40 -0700118 self.handle.sendline(env + "./onos.sh core start")
Jon Hallae05dc22014-04-16 10:56:28 -0700119 i=self.handle.expect(["STARTED","FAILED",pexpect.EOF,pexpect.TIMEOUT])
120 response = self.handle.before + str(self.handle.after)
Jon Hallf89c8552014-04-02 13:14:06 -0700121 if i==0:
Jon Hallae05dc22014-04-16 10:56:28 -0700122 j = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], timeout=60)
123 if re.search("Killed",response):
124 main.log.warn(self.name + ": Killed existing process")
125 if j==0:
Jon Hallf89c8552014-04-02 13:14:06 -0700126 main.log.info(self.name + ": ONOS Started ")
Jon Hallae05dc22014-04-16 10:56:28 -0700127 return main.TRUE
128 elif j==1:
129 main.log.error(self.name + ": EOF exception found")
130 main.log.error(self.name + ": " + self.handle.before)
131 main.cleanup()
132 main.exit()
133 elif j==2:
Jon Hallf89c8552014-04-02 13:14:06 -0700134 main.log.info(self.name + ": ONOS NOT Started, stuck while waiting for it to start ")
135 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700136 else:
137 main.log.warn(self.name +": Unexpected response in start")
138 return main.TRUE
Jon Hallf89c8552014-04-02 13:14:06 -0700139 elif i==1:
Jon Hallae05dc22014-04-16 10:56:28 -0700140 main.log.error(self.name + ": ONOS Failed to start")
adminbae64d82013-08-01 10:50:15 -0700141 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700142 elif i==2:
143 main.log.error(self.name + ": EOF exception found")
144 main.log.error(self.name + ": " + self.handle.before)
145 main.cleanup()
146 main.exit()
147 elif i==3:
148 main.log.error(self.name + ": ONOS timedout while starting")
149 return main.FALSE
150 else:
151 main.log.error(self.name + ": ONOS start expect script missed something... ")
adminbae64d82013-08-01 10:50:15 -0700152 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700153 except pexpect.EOF:
154 main.log.error(self.name + ": EOF exception found")
155 main.log.error(self.name + ": " + self.handle.before)
156 main.cleanup()
157 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700158 except:
159 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
160 main.log.error( traceback.print_exc() )
161 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
162 main.cleanup()
163 main.exit()
Jon Halle80ef8c2014-04-29 15:29:13 -0700164
165 def start_all(self):
166 '''
167 starts ZK, RC, and ONOS
168 '''
169 self.handle.sendline("cd "+self.home)
170 self.handle.sendline("./onos.sh start")
171 self.handle.expect("./onos.sh start")
172 self.handle.expect(["\$",pexpect.TIMEOUT])
173
174
175
adminbae64d82013-08-01 10:50:15 -0700176 def start_rest(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700177 '''
178 Starts the rest server on ONOS.
179 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700180 try:
Jon Hall4a2b0482014-04-18 16:29:26 -0700181 self.handle.sendline("cd "+self.home)
182 response = self.execute(cmd= "./start-rest.sh start",prompt="\$",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700183 if re.search("admin",response):
184 main.log.info(self.name + ": Rest Server Started Successfully")
185 time.sleep(5)
186 return main.TRUE
187 else :
James Leec9cacaf2014-04-08 09:17:39 -0700188 main.log.warn(self.name + ": Failed to start Rest Server")
189 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700190 except pexpect.EOF:
191 main.log.error(self.name + ": EOF exception found")
192 main.log.error(self.name + ": " + self.handle.before)
193 main.cleanup()
194 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700195 except:
196 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
197 main.log.error( traceback.print_exc() )
198 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
199 main.cleanup()
200 main.exit()
201
adminbae64d82013-08-01 10:50:15 -0700202 def status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700203 '''
204 Called onos.sh core status and returns TRUE/FALSE accordingly
205 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700206 try:
207 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hall4a2b0482014-04-18 16:29:26 -0700208 self.handle.sendline("cd "+self.home)
209 response = self.execute(cmd="./onos.sh core status ",prompt="\d+\sinstance\sof\sonos\srunning",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700210 self.execute(cmd="\n",prompt="\$",timeout=10)
211 if re.search("1\sinstance\sof\sonos\srunning",response):
212 return main.TRUE
213 elif re.search("0\sinstance\sof\sonos\srunning",response):
214 return main.FALSE
Jon Hallbb650fe2014-07-14 14:54:48 -0700215 elif re.search("Expected\sPrompt\snot found\s,\sTime Out!!",response):
216 return main.ERROR
Jon Hallf89c8552014-04-02 13:14:06 -0700217 else :
Jon Hallf0a494f2014-06-23 15:37:40 -0700218 main.log.warn(self.name + " WARNING: status recieved unknown response")
219 main.log.warn(response)
Jon Hallf89c8552014-04-02 13:14:06 -0700220 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700221 except pexpect.EOF:
222 main.log.error(self.name + ": EOF exception found")
223 main.log.error(self.name + ": " + self.handle.before)
224 main.cleanup()
225 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700226 except:
227 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
228 main.log.error( traceback.print_exc() )
229 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
230 main.cleanup()
231 main.exit()
232
adminbae64d82013-08-01 10:50:15 -0700233
234 def isup(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700235 '''
236 A more complete check to see if ONOS is up and running properly.
237 First, it checks if the process is up.
238 Second, it reads the logs for "Exception: Connection refused"
239 Third, it makes sure the logs are actually moving.
240 returns TRUE/FALSE accordingly.
241 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700242 try:
243 self.execute(cmd="\n",prompt="\$",timeout=10)
Jon Hall4a2b0482014-04-18 16:29:26 -0700244 self.handle.sendline("cd "+self.home)
245 response = self.execute(cmd= "./onos.sh core status ",prompt="running",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700246 self.execute(cmd="\n",prompt="\$",timeout=10)
247 tail1 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
admine8c47d02014-06-03 11:59:16 -0700248 time.sleep(10)
Jon Hallf89c8552014-04-02 13:14:06 -0700249 self.execute(cmd="\n",prompt="\$",timeout=10)
250 tail2 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
251 pattern = '(.*)1 instance(.*)'
252 pattern2 = '(.*)Exception: Connection refused(.*)'
253 # if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."):
admin2a9548d2014-06-17 14:08:07 -0700254 running = self.execute(cmd="cat "+self.home+"/onos-logs/onos.*.log | grep 'Sending LLDP out on all ports'",prompt="\$",timeout=10)
Jon Hallf89c8552014-04-02 13:14:06 -0700255 if re.search(pattern, response):
admin2a9548d2014-06-17 14:08:07 -0700256 if running != "":
Jon Halle80ef8c2014-04-29 15:29:13 -0700257 main.log.info(self.name + ": ONOS process is running...")
258 if tail1 == tail2:
259 main.log.error(self.name + ": ONOS is frozen...")#logs aren't moving
260 return main.FALSE
261 elif re.search( pattern2,tail1 ):
262 main.log.info(self.name + ": Connection Refused found in onos log")
263 return main.FALSE
264 elif re.search( pattern2,tail2 ):
265 main.log.info(self.name + ": Connection Refused found in onos log")
266 return main.FALSE
267 else:
268 main.log.info(self.name + ": Onos log is moving! It's looking good!")
269 return main.TRUE
Jon Hall55c79662014-05-19 15:03:40 -0700270 else:
271 main.log.info(self.name + ": ONOS not yet sending out LLDP messages")
272 return main.FALSE
adminbae64d82013-08-01 10:50:15 -0700273 else:
Jon Hallf89c8552014-04-02 13:14:06 -0700274 main.log.error(self.name + ": ONOS process not running...")
275 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700276 except pexpect.EOF:
277 main.log.error(self.name + ": EOF exception found")
278 main.log.error(self.name + ": " + self.handle.before)
279 main.cleanup()
280 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700281 except:
282 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
283 main.log.error( traceback.print_exc() )
284 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
285 main.cleanup()
286 main.exit()
adminbae64d82013-08-01 10:50:15 -0700287
Jon Hallf89c8552014-04-02 13:14:06 -0700288
289
James Leec9cacaf2014-04-08 09:17:39 -0700290 def rest_status(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700291 '''
292 Checks if the rest server is running.
293 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700294 try:
295 response = self.execute(cmd= self.home + "/start-rest.sh status ",prompt="running",timeout=10)
296 if re.search("rest\sserver\sis\srunning",response):
297 main.log.info(self.name + ": Rest Server is running")
Jon Hallae05dc22014-04-16 10:56:28 -0700298 return main.TRUE
Jon Hallf89c8552014-04-02 13:14:06 -0700299 elif re.search("rest\sserver\sis\snot\srunning",response):
300 main.log.warn(self.name + ": Rest Server is not Running")
Jon Hallae05dc22014-04-16 10:56:28 -0700301 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700302 else :
303 main.log.error(self.name + ": No response" +response)
Jon Hallae05dc22014-04-16 10:56:28 -0700304 return main.FALSE
305 except pexpect.EOF:
306 main.log.error(self.name + ": EOF exception found")
307 main.log.error(self.name + ": " + self.handle.before)
308 main.cleanup()
309 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700310 except:
311 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
312 main.log.error( traceback.print_exc() )
313 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
314 main.cleanup()
315 main.exit()
admine8c47d02014-06-03 11:59:16 -0700316
317 def stop_all(self):
318 '''
319 Runs ./onos.sh stop
320 '''
321 try:
322 self.handle.sendline("")
323 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
324 self.handle.sendline("cd "+self.home)
325 self.handle.sendline("./onos.sh stop")
326 i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT])
327 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60)
328 result = self.handle.before
329 if re.search("Killed", result):
330 main.log.info(self.name + ": ONOS Killed Successfully")
331 return main.TRUE
332 else :
333 main.log.warn(self.name + ": ONOS wasn't running")
334 return main.FALSE
335 except pexpect.EOF:
336 main.log.error(self.name + ": EOF exception found")
337 main.log.error(self.name + ": " + self.handle.before)
338 main.cleanup()
339 main.exit()
340 except:
341 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
342 main.log.error( traceback.print_exc() )
343 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
344 main.cleanup()
345 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700346
347
adminbae64d82013-08-01 10:50:15 -0700348 def stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700349 '''
350 Runs ./onos.sh core stop to stop ONOS
351 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700352 try:
353 self.handle.sendline("")
Jon Hallae05dc22014-04-16 10:56:28 -0700354 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall4a2b0482014-04-18 16:29:26 -0700355 self.handle.sendline("cd "+self.home)
356 self.handle.sendline("./onos.sh core stop")
Jon Hallae05dc22014-04-16 10:56:28 -0700357 i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT])
358 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60)
James Leec9cacaf2014-04-08 09:17:39 -0700359 result = self.handle.before
Jon Hallf89c8552014-04-02 13:14:06 -0700360 if re.search("Killed", result):
361 main.log.info(self.name + ": ONOS Killed Successfully")
362 return main.TRUE
363 else :
364 main.log.warn(self.name + ": ONOS wasn't running")
365 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700366 except pexpect.EOF:
367 main.log.error(self.name + ": EOF exception found")
368 main.log.error(self.name + ": " + self.handle.before)
369 main.cleanup()
370 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700371 except:
372 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
373 main.log.error( traceback.print_exc() )
374 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
375 main.cleanup()
376 main.exit()
admin6903e462014-07-22 15:30:54 -0700377#**********************************************************************************************
378#**********************************************************************************************
379# The purpose of comp_intents is to find if the high level intents have changed. preIntents
380# and postIntents should be the output of curl of the intents. preIntents being the original
381# and postIntents being the later. We are looking at the intents with the same id from both
382# and comparing the dst and src DPIDs and macs, and the state. If any of these are changed
383# we print that there are changes, then return a list of the intents that have changes`
384#**********************************************************************************************
385#**********************************************************************************************
386 def comp_intents(self,preIntents,postIntents):
387 import json
388 preDecoded = json.loads(preIntents)
389 postDecoded = json.loads(postIntents)
390 changes = []
391 if not preDecoded:
392 if postDecoded:
393 print "THERE ARE CHANGES TO THE HIGH LEVEL INTENTS!!!!"
394 return postDecoded
395 for k in preDecoded:
396 for l in postDecoded:
397 if l['id']==k['id']:
398 if k['dstSwitchDpid']==l['dstSwitchDpid'] and k['srcMac']==l['srcMac'] and k['dstMac']==l['dstMac'] and k['srcSwitchDpid']==l['srcSwitchDpid'] and k['state']==l['state']:
399 postDecoded.remove(l)
400 else:
401 changes.append(k)
402 print ("THERE ARE CHANGES TO THE HIGH LEVEL INTENTS!!!")
403 return changes
Jon Hallf89c8552014-04-02 13:14:06 -0700404
admin6903e462014-07-22 15:30:54 -0700405#**********************************************************************************************
406#**********************************************************************************************
407# the purpose of comp_low is to find if the low level intents have changed. The main idea
408# is to determine if the path has changed. Again, like with the comp_intents function, the
409# pre and post Intents variables are the json dumps of wm/onos/intent/low. The variables
410# that will be compared are the state, and the path.
411#**********************************************************************************************
412#**********************************************************************************************
413 def comp_low(self, preIntents,postIntents):
414 import json
415 preDecoded = json.loads(preIntents)
416 postDecoded = json.loads(postIntents)
417 changes = []
418 if not preDecoded:
419 if postDecoded:
420 print "THERE ARE CHANGES TO THE LOW LEVEL INTENTS!!!"
421 return postDecoded
422 for k in preDecoded:
423 for l in postDecoded:
424 if l['id']==k['id']:
425 if l['path']!=k['path']:
426 changes.append(l)
427 print "\n\n\n\nTHERE ARE CHANGES TO THE LOW LEVEL INTENTS!!!"
428 else:
429 if k['state']!=l['state']:
430 changes.append(l)
431 print "\n\n\n\nTHERE ARE CHANGES TO THE LOW LEVEL INTENTS!!!"
432 else:
433 print "NO CHANGES SO FAR\n\n\n"
434
435
436 return changes
437
438
adminbae64d82013-08-01 10:50:15 -0700439 def rest_stop(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700440 '''
441 Runs ./start-rest.sh stop to stop ONOS rest server
442 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700443 try:
444 response = self.execute(cmd= self.home + "/start-rest.sh stop ",prompt="killing",timeout=10)
445 self.execute(cmd="\n",prompt="\$",timeout=10)
446 if re.search("killing", response):
447 main.log.info(self.name + ": Rest Server Stopped")
448 return main.TRUE
449 else :
450 main.log.error(self.name + ": Failed to Stop, Rest Server is not Running")
451 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700452 except pexpect.EOF:
453 main.log.error(self.name + ": EOF exception found")
454 main.log.error(self.name + ": " + self.handle.before)
455 main.cleanup()
456 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700457 except:
458 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
459 main.log.error( traceback.print_exc() )
460 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
461 main.cleanup()
462 main.exit()
463
464
admin680b78c2014-08-08 11:46:45 -0700465 def kill(self):
466 import re
467 try:
468 self.handle.sendline("ps -ef |grep 'ONOS/conf/logback' |awk 'NR==1 {print $2}' |xargs sudo kill -9")
469 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
470 self.handle.sendline("ps -ef |grep 'ONOS/conf/logback' |wc -l")
471 self.handle.expect(["wc -l",pexpect.EOF,pexpect.TIMEOUT])
472 response = self.handle.after
473 if re.search("1",response):
474 return "ONOS Killed!"
475 else:
476 return "ERROR!!! ONOS MAY NOT HAVE BEEN KILLED PROPERLY!!!"
477 except pexpect.EOF:
478 main.log.error(self.name + ": EOF exception found")
479 main.log.error(self.hane + ": " + self.handle.before)
480 main.cleanup()
481 main.exit()
482 except:
483 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
484 main.log.error( traceback.print_exc() )
485 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
486 main.cleanup()
487 main.exit()
488
489
490
adminbae64d82013-08-01 10:50:15 -0700491 def disconnect(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700492 '''
493 Called when Test is complete to disconnect the ONOS handle.
494 '''
adminaeedddd2013-08-02 15:14:15 -0700495 response = ''
496 try:
adminbae64d82013-08-01 10:50:15 -0700497 self.handle.sendline("exit")
adminaeedddd2013-08-02 15:14:15 -0700498 self.handle.expect("closed")
Jon Hallae05dc22014-04-16 10:56:28 -0700499 except pexpect.EOF:
500 main.log.error(self.name + ": EOF exception found")
501 main.log.error(self.name + ": " + self.handle.before)
James Leec9cacaf2014-04-08 09:17:39 -0700502 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700503 main.log.error(self.name + ": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700504 response = main.FALSE
adminaeedddd2013-08-02 15:14:15 -0700505 return response
506
Jon Hall76f2c462014-04-17 11:37:15 -0700507 def print_version(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700508 '''
509 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
510 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700511 try:
512 self.handle.sendline("export TERM=xterm-256color")
513 self.handle.expect("xterm-256color")
James Leec9cacaf2014-04-08 09:17:39 -0700514 self.handle.expect("\$")
Jon Hall09944cd2014-06-25 11:28:43 -0700515 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\" --color=never; cd \.\.")
Jon Hallf89c8552014-04-02 13:14:06 -0700516 self.handle.expect("cd ..")
517 self.handle.expect("\$")
admine0eeea22014-04-14 10:22:46 -0700518 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
519 main.log.report(response)
Jon Hall76f2c462014-04-17 11:37:15 -0700520 except pexpect.EOF:
521 main.log.error(self.name + ": EOF exception found")
522 main.log.error(self.name + ": " + self.handle.before)
523 main.cleanup()
524 main.exit()
525 except:
526 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
527 main.log.error( traceback.print_exc() )
528 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
529 main.cleanup()
530 def get_version(self):
531 '''
532 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
533 '''
534 try:
535 self.handle.sendline("export TERM=xterm-256color")
536 self.handle.expect("xterm-256color")
537 self.handle.expect("\$")
Jon Hall09944cd2014-06-25 11:28:43 -0700538 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\" --color=never; cd \.\.")
Jon Hall76f2c462014-04-17 11:37:15 -0700539 self.handle.expect("cd ..")
540 self.handle.expect("\$")
541 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
admine0eeea22014-04-14 10:22:46 -0700542 lines=response.splitlines()
543 for line in lines:
544 print line
545 return lines[2]
Jon Hallae05dc22014-04-16 10:56:28 -0700546 except pexpect.EOF:
547 main.log.error(self.name + ": EOF exception found")
548 main.log.error(self.name + ": " + self.handle.before)
549 main.cleanup()
550 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700551 except:
552 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
553 main.log.error( traceback.print_exc() )
554 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
555 main.cleanup()
556 main.exit()
adminbae64d82013-08-01 10:50:15 -0700557
admin2a9548d2014-06-17 14:08:07 -0700558
admindc1c5072014-06-24 15:57:19 -0700559
560#*********************************************************************
561#*********************************************************************
562# shortest_path is a command to find the shortest path between two
563# switches. It is called using the IP, port, and source and
564# destination dpids
565#*********************************************************************
566#*********************************************************************
567
568 def shortest_path(self,ONOSIP,ONOSPort,srcDPID,dstDPID):
569 main.log.report("Finding the shortest Path between "+str(srcDPID) + " to " + str(dstDPID))
570 url = "http://%s:%s/wm/onos/intent/path/switch/%s/shortest-path/%s"%(ONOSIP,ONOSPort,srcDPID,dstDPID)
571 parsed_result = []
572 try:
573 response = urllib2.urlopen(url)
574 result = response.read()
575 response.close()
576 if len(result) != 0:
577 parsed_result = json.loads(result)
578 except HTTPError as exc:
579 print "ERROR:"
580 print " REST GET URL: %s" % url
581 # NOTE: exc.fp contains the object with the response payload
582 error_payload = json.loads(exc.fp.read())
583 print " REST Error Code: %s" % (error_payload['code'])
584 print " REST Error Summary: %s" % (error_payload['summary'])
585 print " REST Error Description: %s" % (error_payload['formattedDescription'])
586 print " HTTP Error Code: %s" % exc.code
587 print " HTTP Error Reason: %s" % exc.reason
588 except URLError as exc:
589 print "ERROR:"
590 print " REST GET URL: %s" % url
591 print " URL Error Reason: %s" % exc.reason
592
593 if len(parsed_result)==0:
594 return
595 result = json.dumps(parsed_result,indent=4)
596 print(str(result))
597 return result
598
599
600#*********************************************************************
601#*********************************************************************
602# show_intent is a command to show intents.
603# Parameters include intentIP, intentPort, intentURL, and intent_id
604# Based on the url, it will show either high or low intents
605# If intent_id is left blank, it will show all high or all low intents
606# Else it will show the intent with the id
607#*********************************************************************
608#*********************************************************************
609
610
611
612 def show_intent(self,intentIP,intentPort=8080,intentURL="wm/onos/intent",intent_type="high",intent_id="all"):
613 main.log.report("Getting (an) intent(s)")
614 if intent_id=="all":
615 url = "http://%s:%s/%s/%s"%(intentIP,intentPort,intentURL,intent_type)
616 else:
617 url = "http://%s:%s/%s/%s/%s"%(intentIP,intentPort,intentURL,intent_type,intent_id)
618 print(url)
619 parsed_result = []
620 try:
621 response = urllib2.urlopen(url)
622 result = response.read()
623 response.close()
624 if len(result) != 0:
625 parsed_result = json.loads(result)
626 except HTTPError as exc:
627 print "ERROR:"
628 print " REST GET URL: %s" % url
629 # NOTE: exc.fp contains the object with the response payload
630 error_payload = json.loads(exc.fp.read())
631 print " REST Error Code: %s" % (error_payload['code'])
632 print " REST Error Summary: %s" % (error_payload['summary'])
633 print " REST Error Description: %s" % (error_payload['formattedDescription'])
634 print " HTTP Error Code: %s" % exc.code
635 print " HTTP Error Reason: %s" % exc.reason
636 return str(error_payload['code'])
637 except URLError as exc:
638 print "ERROR:"
639 print " REST GET URL: %s" % url
640 print " URL Error Reason: %s" % exc.reason
641 return str(error_payload['code'])
642
643 if len(parsed_result)==0:
644 return
645 result = json.dumps(parsed_result,indent=4)
646 print(str(result))
647 return result
648
649
650#*********************************************************************
651#*********************************************************************
652# del_intent is to delete either all or some or one intents
653# if intent_id is left blank, it will delete all intents
654# else, intent_id should be of the form "intent_id=1,2,3"
655#*********************************************************************
656#*********************************************************************
657
658 def del_intent(self,intentIP,intentPort=8080,intentURL="wm/onos/intent",intent_id="all"):
659 main.log.report("Deleting (an) intent(s)")
660 if intent_id=="all":
661 url = "http://%s:%s/%s/high"%(intentIP,intentPort,intentURL)
662 else:
663 url = "http://%s:%s/%s/high?%s"%(intentIP,intentPort,intentURL,intent_id)
664
665 print(url)
666
667 parsed_result = []
668 try:
669 request = urllib2.Request(url)
670 request.get_method = lambda: 'DELETE'
671 response = urllib2.urlopen(request)
672 result = response.read()
673 response.close()
674 if len(result) != 0:
675 parsed_result = json.loads(result)
676 print(parsed_result)
677 except HTTPError as exc:
678 print "ERROR:"
679 print " REST DELETE URL: %s" % url
680 # NOTE: exc.fp contains the object with the response payload
681 error_payload = json.loads(exc.fp.read())
682 print " REST Error Code: %s" % (error_payload['code'])
683 print " REST Error Summary: %s" % (error_payload['summary'])
684 print " REST Error Description: %s" % (error_payload['formattedDescription'])
685 print " HTTP Error Code: %s" % exc.code
686 print " HTTP Error Reason: %s" % exc.reason
687 except URLError as exc:
688 print "ERROR:"
689 print " REST DELETE URL: %s" % url
690 print " URL Error Reason: %s" % exc.reason
691 return result
692
693#*********************************************************************
694#*********************************************************************
695# add_intent will add a single intent by using dpids and macs.
696#*********************************************************************
697#*********************************************************************
698
699
700 def add_intent(self, intent_id,src_dpid,dst_dpid,src_mac,dst_mac,intentIP,intentPort=8080,intentURL="wm/onos/intent" , intent_type = 'SHORTEST_PATH', static_path=False, src_port=1,dst_port=1):
admin2a9548d2014-06-17 14:08:07 -0700701 "CLI command callback: set intent"
702
703 intents = []
704 oper = {}
705 # Create the POST payload
706 oper['intentId'] = intent_id
707 oper['intentType'] = intent_type # XXX: Hardcoded
708 oper['staticPath'] = static_path # XXX: Hardcoded
709 oper['srcSwitchDpid'] = src_dpid
710 oper['srcSwitchPort'] = src_port
711 oper['dstSwitchDpid'] = dst_dpid
712 oper['dstSwitchPort'] = dst_port
713 oper['matchSrcMac'] = src_mac
714 oper['matchDstMac'] = dst_mac
715 intents.append(oper)
admindc1c5072014-06-24 15:57:19 -0700716 url = "http://%s:%s/%s/high"%(intentIP,intentPort,intentURL)
admin2a9548d2014-06-17 14:08:07 -0700717 parsed_result = []
718 data_json = json.dumps(intents)
719 try:
720 request = urllib2.Request(url,data_json)
721 request.add_header("Content-Type", "application/json")
722 response=urllib2.urlopen(request)
723 result = response.read()
724 response.close()
725 if len(result) != 0:
726 parsed_result = json.loads(result)
727 except HTTPError as exc:
728 print "ERROR:"
729 print " REST GET URL: %s" % url
730 # NOTE: exc.fp contains the object with the response payload
731 error_payload = json.loads(exc.fp.read())
732 print " REST Error Code: %s" % (error_payload['code'])
733 print " REST Error Summary: %s" % (error_payload['summary'])
734 print " REST Error Description: %s" % (error_payload['formattedDescription'])
735 print " HTTP Error Code: %s" % exc.code
736 print " HTTP Error Reason: %s" % exc.reason
737 except URLError as exc:
738 print "ERROR:"
739 print " REST GET URL: %s" % url
740 print " URL Error Reason: %s" % exc.reason
admindc1c5072014-06-24 15:57:19 -0700741 return result
admin2a9548d2014-06-17 14:08:07 -0700742
743
744
745
746 def add_intents(self):
747 main.log.info("Sending new intents to ONOS")
adminc6cfc1c2014-04-21 13:55:21 -0700748 self.handle.sendline("cd "+self.home+ "/scripts")
749 self.handle.expect("scripts")
admin2a9548d2014-06-17 14:08:07 -0700750 main.log.info("Adding intents")
adminc6cfc1c2014-04-21 13:55:21 -0700751 self.handle.sendline("./pyintents.py")
Jon Hall9c6e2c02014-05-02 10:18:53 -0700752 self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT])
753 response = self.handle.before
adminc6cfc1c2014-04-21 13:55:21 -0700754 self.handle.sendline("cd "+self.home)
755 return main.TRUE
756
admin2a9548d2014-06-17 14:08:07 -0700757 def rm_intents(self):
758 main.log.info("Deleteing Intents from ONOS")
adminc6cfc1c2014-04-21 13:55:21 -0700759 self.handle.sendline("cd "+self.home+ "/scripts")
760 self.handle.expect("scripts")
admin2a9548d2014-06-17 14:08:07 -0700761 main.log.info("Deleting Intnents")
adminc6cfc1c2014-04-21 13:55:21 -0700762 self.handle.sendline("./rmpyintents.py")
Jon Hall9c6e2c02014-05-02 10:18:53 -0700763 self.handle.expect(["$",pexpect.EOF,pexpect.TIMEOUT])
764 response = self.handle.before
adminc6cfc1c2014-04-21 13:55:21 -0700765 self.handle.sendline("cd "+self.home)
766 return main.TRUE
767
admin2a9548d2014-06-17 14:08:07 -0700768 def purge_intents(self):
Jon Hall265149f2014-04-25 13:39:52 -0700769 main.log.info("Purging dead intents")
770 self.handle.sendline("cd "+self.home+ "/scripts")
771 self.handle.expect("scripts")
admin2a9548d2014-06-17 14:08:07 -0700772 main.log.info("Sending Purge Intent Rest call to ONOS")
Jon Hall265149f2014-04-25 13:39:52 -0700773 self.handle.sendline("./purgeintents.py")
774 self.handle.sendline("cd "+self.home)
775 return main.TRUE
adminc6cfc1c2014-04-21 13:55:21 -0700776
777
778
Jon Hall4a2b0482014-04-18 16:29:26 -0700779 def add_flow(self, testONip, user = "admin", password = "", flowDef = "/flowdef.txt"):
Jon Halld8dc5772014-04-08 16:26:29 -0700780 '''
781 Copies the flowdef file from TestStation -> ONOS machine
782 Then runs ./add_flow.py to add the flows to ONOS
783 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700784 try:
785 main.log.info("Adding Flows...")
786 self.handle.sendline("scp %s@%s:%s /tmp/flowtmp" %(user,testONip,flowDef))
787 i=self.handle.expect(['[pP]assword:', '100%', pexpect.TIMEOUT],30)
788 if(i==0):
789 self.handle.sendline("%s" %(password))
790 self.handle.sendline("")
791 self.handle.expect("100%")
792 self.handle.expect("\$", 30)
793 self.handle.sendline(self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
794 self.handle.expect("\$", 1000)
795 main.log.info("Flows added")
796 return main.TRUE
797
798 elif(i==1):
799 self.handle.sendline("")
800 self.handle.expect("\$", 10)
801 self.handle.sendline( self.home + "/web/add_flow.py -m onos -f /tmp/flowtmp")
802 self.handle.expect("\$", 1000)
803 main.log.info("Flows added")
804 return main.TRUE
805
806 elif(i==2):
807 main.log.error("Flow Def file SCP Timed out...")
808 return main.FALSE
809
810 else:
811 main.log.error("Failed to add flows...")
James Leec9cacaf2014-04-08 09:17:39 -0700812 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700813 except pexpect.EOF:
814 main.log.error(self.name + ": EOF exception found")
815 main.log.error(self.name + ": " + self.handle.before)
816 main.cleanup()
817 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700818 except:
819 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
820 main.log.error( traceback.print_exc() )
821 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
822 main.cleanup()
823 main.exit()
824
adminbae64d82013-08-01 10:50:15 -0700825
826 def delete_flow(self, *delParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700827 '''
828 Deletes a specific flow, a range of flows, or all flows.
829 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700830 try:
831 if len(delParams)==1:
832 if str(delParams[0])=="all":
833 main.log.info(self.name + ": Deleting ALL flows...")
834 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150)
835 self.handle.sendline(self.home + "/web/delete_flow.py all")
836 self.handle.expect("delete_flow")
837 self.handle.expect("\$",1000)
838 main.log.info(self.name + ": Flows deleted")
839 else:
840 main.log.info(self.name + ": Deleting flow "+str(delParams[0])+"...")
841 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150)
842 #self.execute(cmd="\n",prompt="\$",timeout=60)
843 self.handle.sendline(self.home +"/web/delete_flow.py %d" % int(delParams[0]))
844 self.handle.expect("delete_flow")
845 self.handle.expect("\$",60)
846 main.log.info(self.name + ": Flow deleted")
847 elif len(delParams)==2:
848 main.log.info(self.name + ": Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...")
849 #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150)
850 #self.execute(cmd="\n",prompt="\$",timeout=60)
851 self.handle.sendline(self.home + "/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1])))
852 self.handle.expect("delete_flow")
853 self.handle.expect("\$",600)
854 main.log.info(self.name + ": Flows deleted")
Jon Hallae05dc22014-04-16 10:56:28 -0700855 except pexpect.EOF:
856 main.log.error(self.name + ": EOF exception found")
857 main.log.error(self.name + ": " + self.handle.before)
858 main.cleanup()
859 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700860 except:
861 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
862 main.log.error( traceback.print_exc() )
863 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
864 main.cleanup()
865 main.exit()
adminbae64d82013-08-01 10:50:15 -0700866
867 def check_flow(self):
Jon Halld8dc5772014-04-08 16:26:29 -0700868 '''
869 Calls the ./get_flow.py all and checks:
870 - If each FlowPath has at least one FlowEntry
871 - That there are no "NOT"s found
872 returns TRUE/FALSE
873 '''
Jon Hallf89c8552014-04-02 13:14:06 -0700874 try:
875 flowEntryDetect = 1
876 count = 0
877 self.handle.sendline("clear")
878 time.sleep(1)
879 self.handle.sendline(self.home + "/web/get_flow.py all")
880 self.handle.expect("get_flow")
Jon Hall3bd7c792014-05-30 09:05:21 -0700881 for x in range(15):
Jon Hallf89c8552014-04-02 13:14:06 -0700882 i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180)
883 if i==0:
884 count = count + 1
885 if flowEntryDetect == 0:
886 main.log.info(self.name + ": FlowPath without FlowEntry")
887 return main.FALSE
888 else:
889 flowEntryDetect = 0
890 elif i==1:
891 flowEntryDetect = 1
892 elif i==2:
893 main.log.error(self.name + ": Found a NOT")
adminbae64d82013-08-01 10:50:15 -0700894 return main.FALSE
Jon Hallf89c8552014-04-02 13:14:06 -0700895 elif i==3:
896 if count == 0:
897 main.log.info(self.name + ": There don't seem to be any flows here...")
898 return main.FALSE
899 else:
900 main.log.info(self.name + ": All flows pass")
901 main.log.info(self.name + ": Number of FlowPaths: "+str(count))
902 return main.TRUE
903 elif i==4:
James Leec9cacaf2014-04-08 09:17:39 -0700904 main.log.error(self.name + ":Check_flow() - Command Timeout!")
Jon Hallf89c8552014-04-02 13:14:06 -0700905 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -0700906 except pexpect.EOF:
907 main.log.error(self.name + ": EOF exception found")
908 main.log.error(self.name + ": " + self.handle.before)
909 main.cleanup()
910 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -0700911 except:
912 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
913 main.log.error( traceback.print_exc() )
914 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
915 main.cleanup()
916 main.exit()
adminbae64d82013-08-01 10:50:15 -0700917
918 def get_flow(self, *flowParams):
Jon Halld8dc5772014-04-08 16:26:29 -0700919 '''
920 Returns verbose output of ./get_flow.py
921 '''
922 try:
923 if len(flowParams)==1:
924 if str(flowParams[0])=="all":
925 self.execute(cmd="\n",prompt="\$",timeout=60)
926 main.log.info(self.name + ": Getting all flow data...")
927 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150)
928 self.execute(cmd="\n",prompt="\$",timeout=60)
929 return data
930 else:
931 main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...")
932 data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150)
933 self.execute(cmd="\n",prompt="\$",timeout=60)
934 return data
935 elif len(flowParams)==5:
936 main.log.info(self.name + ": Retrieving flow installer data...")
937 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh "+str(flowParams[0])+" "+str(flowParams[1])+" "+str(flowParams[2])+" "+str(flowParams[3])+" "+str(flowParams[4]),prompt="done",timeout=150)
938 self.execute(cmd="\n",prompt="\$",timeout=60)
939 return data
940 elif len(flowParams)==4:
941 main.log.info(self.name + ": Retrieving flow endpoints...")
942 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh "+str(flowParams[0])+" "+str(flowParams[1])+" "+str(flowParams[2])+" "+str(flowParams[3]),prompt="done",timeout=150)
943 self.execute(cmd="\n",prompt="\$",timeout=60)
944 return data
Jon Hallae05dc22014-04-16 10:56:28 -0700945 except pexpect.EOF:
946 main.log.error(self.name + ": EOF exception found")
947 main.log.error(self.name + ": " + self.handle.before)
948 main.cleanup()
949 main.exit()
Jon Halld8dc5772014-04-08 16:26:29 -0700950 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700951 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
952 main.log.error( traceback.print_exc() )
953 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
954 main.cleanup()
955 main.exit()
adminbae64d82013-08-01 10:50:15 -0700956
957
Jon Hall2f42a672014-05-28 10:13:18 -0700958# http://localhost:8080/wm/onos/topology/switches
959# http://localhost:8080/wm/onos/topology/links
Jon Hall8060af02014-04-14 14:17:58 -0700960# http://localhost:8080/wm/onos/registry/controllers/json
961# http://localhost:8080/wm/onos/registry/switches/json"
adminbae64d82013-08-01 10:50:15 -0700962
963 def get_json(self, url):
Jon Halld8dc5772014-04-08 16:26:29 -0700964 '''
965 Helper functions used to parse the json output of a rest call
966 '''
adminbae64d82013-08-01 10:50:15 -0700967 try:
Jon Hallf89c8552014-04-02 13:14:06 -0700968 try:
969 command = "curl -s %s" % (url)
970 result = os.popen(command).read()
971 parsedResult = json.loads(result)
972 except:
973 print "REST IF %s has issue" % command
974 parsedResult = ""
975
976 if type(parsedResult) == 'dict' and parsedResult.has_key('code'):
977 print "REST %s returned code %s" % (command, parsedResult['code'])
978 parsedResult = ""
James Leec9cacaf2014-04-08 09:17:39 -0700979 return parsedResult
Jon Hallae05dc22014-04-16 10:56:28 -0700980 except pexpect.EOF:
981 main.log.error(self.name + ": EOF exception found")
982 main.log.error(self.name + ": " + self.handle.before)
983 main.cleanup()
984 main.exit()
adminbae64d82013-08-01 10:50:15 -0700985 except:
Jon Hallf89c8552014-04-02 13:14:06 -0700986 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
987 main.log.error( traceback.print_exc() )
988 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
989 main.cleanup()
990 main.exit()
adminbae64d82013-08-01 10:50:15 -0700991
admin680b78c2014-08-08 11:46:45 -0700992 def num_switch(self,RestIP,RestPort="8080"):
993 url = "http://%s:%s/wm/onos/topology/switches" %(RestIP,RestPort)
994 parsedResult = self.get_json(url)
995 if parsedResult == "":
996 retcode = 1
997 return (retcode, "RestAPI has an issue")
998 url = "http://%s:%s/wm/onos/registry/switches/json" %(RestIP,RestPort)
999 registry = self.get_json(url)
1000 if registry == "":
1001 retcode = 1
1002 return (retcode, "REST API has an Issue")
1003 cnt = 0
1004 active = 0
1005 for s in parsedResult:
1006 cnt +=1
1007 if s['state']=="ACTIVE":
1008 active+=1
1009 return (cnt,active)
1010
1011
Jon Hallf89c8552014-04-02 13:14:06 -07001012 def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ):
Jon Halld8dc5772014-04-08 16:26:29 -07001013 '''
1014 Used by check_status
1015 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001016 try:
1017 buf = ""
1018 retcode = 0
admin2e131ab2014-05-28 10:03:42 -07001019 url="http://%s:%s/wm/onos/topology/switches" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -07001020 parsedResult = self.get_json(url)
1021 if parsedResult == "":
1022 retcode = 1
1023 return (retcode, "Rest API has an issue")
1024 url = "http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort)
1025 registry = self.get_json(url)
1026
1027 if registry == "":
1028 retcode = 1
1029 return (retcode, "Rest API has an issue")
1030
1031 cnt = 0
1032 active = 0
adminbae64d82013-08-01 10:50:15 -07001033
Jon Hallf89c8552014-04-02 13:14:06 -07001034 for s in parsedResult:
1035 cnt += 1
James Leec9cacaf2014-04-08 09:17:39 -07001036 if s['state'] == "ACTIVE":
Jon Hallf89c8552014-04-02 13:14:06 -07001037 active += 1
adminbae64d82013-08-01 10:50:15 -07001038
Jon Hallf89c8552014-04-02 13:14:06 -07001039 buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active)
1040 if correct_nr_switch != cnt:
1041 buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt)
1042 retcode = 1
adminbae64d82013-08-01 10:50:15 -07001043
Jon Hallf89c8552014-04-02 13:14:06 -07001044 if correct_nr_switch != active:
1045 buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active)
1046 retcode = 1
1047
1048 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -07001049 except pexpect.EOF:
1050 main.log.error(self.name + ": EOF exception found")
1051 main.log.error(self.name + ": " + self.handle.before)
1052 main.cleanup()
1053 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001054 except:
1055 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1056 main.log.error( traceback.print_exc() )
1057 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1058 main.cleanup()
1059 main.exit()
adminbae64d82013-08-01 10:50:15 -07001060
admin680b78c2014-08-08 11:46:45 -07001061 def num_link(self,RestIP,RestPort="8080"):
1062 url = "http://%s:%s/wm/onos/topology/links" % (RestIP,RestPort)
1063 parsedResult = self.get_json(url)
1064 if parsedResult == "":
1065 retcode = 1
1066 return (retcode,"RestAPI has an issue")
1067 intra = 0
1068 for s in parsedResult:
1069 intra+=1
1070 return intra
1071
Jon Hallf89c8552014-04-02 13:14:06 -07001072 def check_link(self,RestIP, nr_links, RestPort = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -07001073 '''
1074 Used by check_status
1075 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001076 try:
1077 buf = ""
1078 retcode = 0
1079
admin2e131ab2014-05-28 10:03:42 -07001080 url = "http://%s:%s/wm/onos/topology/links" % (RestIP, RestPort)
Jon Hallf89c8552014-04-02 13:14:06 -07001081 parsedResult = self.get_json(url)
1082
1083 if parsedResult == "":
1084 retcode = 1
1085 return (retcode, "Rest API has an issue")
1086
1087 buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links)
1088 intra = 0
1089 interlink=0
1090
1091 for s in parsedResult:
James Leec9cacaf2014-04-08 09:17:39 -07001092 intra = intra + 1
Jon Hallf89c8552014-04-02 13:14:06 -07001093
1094 if intra != nr_links:
1095 buf += "link fail\n"
1096 retcode = 1
1097
1098 return (retcode, buf)
Jon Hallae05dc22014-04-16 10:56:28 -07001099 except pexpect.EOF:
1100 main.log.error(self.name + ": EOF exception found")
1101 main.log.error(self.name + ": " + self.handle.before)
1102 main.cleanup()
1103 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001104 except:
1105 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1106 main.log.error( traceback.print_exc() )
1107 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1108 main.cleanup()
1109 main.exit()
adminbae64d82013-08-01 10:50:15 -07001110
Jon Hallf89c8552014-04-02 13:14:06 -07001111 def check_status_report(self, ip, numoswitch, numolink, port="8080"):
Jon Halld8dc5772014-04-08 16:26:29 -07001112 '''
1113 Checks the number of swithes & links that ONOS sees against the supplied values.
1114 Writes to the report log.
1115 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001116 try:
James Leec9cacaf2014-04-08 09:17:39 -07001117 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -07001118 switch = self.check_switch(ip, int(numoswitch), port)
1119 link = self.check_link(ip, int(numolink), port)
1120 value = switch[0]
1121 value += link[0]
1122 main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
1123 if value != 0:
1124 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -07001125 else:
Jon Hallf89c8552014-04-02 13:14:06 -07001126 # "PASS"
1127 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -07001128 except pexpect.EOF:
1129 main.log.error(self.name + ": EOF exception found")
1130 main.log.error(self.name + ": " + self.handle.before)
1131 main.cleanup()
1132 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001133 except:
1134 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1135 main.log.error( traceback.print_exc() )
1136 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1137 main.cleanup()
1138 main.exit()
adminbae64d82013-08-01 10:50:15 -07001139
Jon Hallf89c8552014-04-02 13:14:06 -07001140 def check_status(self, ip, numoswitch, numolink, port = "8080"):
Jon Halld8dc5772014-04-08 16:26:29 -07001141 '''
1142 Checks the number of swithes & links that ONOS sees against the supplied values.
1143 Writes to the main log.
1144 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001145 try:
James Leec9cacaf2014-04-08 09:17:39 -07001146 main.log.info(self.name + ": Making some rest calls...")
Jon Hallf89c8552014-04-02 13:14:06 -07001147 switch = self.check_switch(ip, int(numoswitch), port)
1148 link = self.check_link(ip, int(numolink), port)
1149 value = switch[0]
1150 value += link[0]
1151 main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
1152 if value != 0:
1153 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -07001154 else:
Jon Hallf89c8552014-04-02 13:14:06 -07001155 # "PASS"
1156 return main.TRUE
Jon Hallae05dc22014-04-16 10:56:28 -07001157 except pexpect.EOF:
1158 main.log.error(self.name + ": EOF exception found")
1159 main.log.error(self.name + ": " + self.handle.before)
1160 main.cleanup()
1161 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001162 except:
1163 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1164 main.log.error( traceback.print_exc() )
1165 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1166 main.cleanup()
1167 main.exit()
adminbae64d82013-08-01 10:50:15 -07001168
Jon Hallf89c8552014-04-02 13:14:06 -07001169
admine0eeea22014-04-14 10:22:46 -07001170 def git_pull(self, comp1=""):
Jon Halld8dc5772014-04-08 16:26:29 -07001171 '''
Jon Halld8dc5772014-04-08 16:26:29 -07001172 Assumes that "git pull" works without login
admine0eeea22014-04-14 10:22:46 -07001173
1174 This function will perform a git pull on the ONOS instance.
1175 If used as git_pull("NODE") it will do git pull + NODE. This is
1176 for the purpose of pulling from other nodes if necessary.
1177
1178 Otherwise, this function will perform a git pull in the
1179 ONOS repository. If it has any problems, it will return main.ERROR
1180 If it successfully does a git_pull, it will return a 1.
1181 If it has no updates, it will return a 0.
1182
Jon Halld8dc5772014-04-08 16:26:29 -07001183 '''
Jon Hallae05dc22014-04-16 10:56:28 -07001184 try:
Jon Halle80ef8c2014-04-29 15:29:13 -07001185 # main.log.info(self.name + ": Stopping ONOS")
1186 #self.stop()
Jon Hallae05dc22014-04-16 10:56:28 -07001187 self.handle.sendline("cd " + self.home)
1188 self.handle.expect("ONOS\$")
1189 if comp1=="":
1190 self.handle.sendline("git pull")
1191 else:
1192 self.handle.sendline("git pull " + comp1)
1193
1194 uptodate = 0
Jon Hall96983632014-07-17 12:06:12 -07001195 i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','\sfile(s*) changed,\s',pexpect.TIMEOUT,'Already up-to-date','Aborting','You\sare\snot\scurrently\son\sa\sbranch'],timeout=1700)
Jon Hallae05dc22014-04-16 10:56:28 -07001196 #debug
1197 #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after))
1198 if i==0:
1199 main.log.error(self.name + ": Git pull had some issue...")
1200 return main.ERROR
1201 elif i==1:
1202 main.log.error(self.name + ": Git Pull Asking for username!!! BADD!")
1203 return main.ERROR
1204 elif i==2:
1205 main.log.info(self.name + ": Git Pull - pulling repository now")
1206 self.handle.expect("ONOS\$", 120)
1207 return 0
1208 elif i==3:
1209 main.log.error(self.name + ": Git Pull - TIMEOUT")
Jon Hall96983632014-07-17 12:06:12 -07001210 main.log.error(self.name + " Response was: " + str(self.handle.before))
Jon Hallae05dc22014-04-16 10:56:28 -07001211 return main.ERROR
1212 elif i==4:
1213 main.log.info(self.name + ": Git Pull - Already up to date")
1214 return 1
1215 elif i==5:
1216 main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?")
1217 return main.ERROR
Jon Hall5a8aac62014-06-03 09:30:21 -07001218 elif i==6:
1219 main.log.info(self.name + ": Git Pull - You are not currently on a branch so git pull failed!")
1220 return main.ERROR
Jon Hallae05dc22014-04-16 10:56:28 -07001221 else:
1222 main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors")
1223 return main.ERROR
1224 except pexpect.EOF:
1225 main.log.error(self.name + ": EOF exception found")
1226 main.log.error(self.name + ": " + self.handle.before)
1227 main.cleanup()
1228 main.exit()
1229 except:
1230 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1231 main.log.error( traceback.print_exc() )
1232 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1233 main.cleanup()
1234 main.exit()
admine0eeea22014-04-14 10:22:46 -07001235#********************************************************
1236
1237
admin680b78c2014-08-08 11:46:45 -07001238
1239
1240 def git_checkout(self, branch="onos13integration"):
1241 '''
1242 Assumes that "git pull" works without login
1243
1244 This function will perform a git pull on the ONOS instance.
1245 If used as git_pull("NODE") it will do git pull + NODE. This is
1246 for the purpose of pulling from other nodes if necessary.
1247
1248 Otherwise, this function will perform a git pull in the
1249 ONOS repository. If it has any problems, it will return main.ERROR
1250 If it successfully does a git_pull, it will return a 1.
1251 If it has no updates, it will return a 0.
1252
1253 '''
1254 try:
1255 # main.log.info(self.name + ": Stopping ONOS")
1256 #self.stop()
1257 self.handle.sendline("cd " + self.home)
1258 self.handle.expect("ONOS\$")
1259 if branch != 'master':
1260 #self.handle.sendline('git stash')
1261 #self.handle.expect('ONOS\$')
1262 #print "After issuing git stash cmnd: ", self.handle.before
1263 cmd = "git checkout "+branch
1264 print "checkout cmd = ", cmd
1265 self.handle.sendline(cmd)
1266 uptodate = 0
1267 i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Already\son\s\'onos13integration\'','Switched\sto\sbranch\s\'onos13integration\'', pexpect.TIMEOUT],timeout=60)
1268 else:
1269 #self.handle.sendline('git stash apply')
1270 #self.handle.expect('ONOS\$')
1271 #print "After issuing git stash apply cmnd: ", self.handle.before
1272 cmd = "git checkout "+branch
1273 print "checkout cmd = ", cmd
1274 self.handle.sendline(cmd)
1275 uptodate = 0
1276 switchedToMaster = 0
1277 i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Already\son\s\'master\'','Switched\sto\sbranch\s\'master\'', pexpect.TIMEOUT],timeout=60)
1278
1279
1280 if i==0:
1281 main.log.error(self.name + ": Git checkout had some issue...")
1282 return main.ERROR
1283 elif i==1:
1284 main.log.error(self.name + ": Git checkout Asking for username!!! BADD!")
1285 return main.ERROR
1286 elif i==2:
1287 main.log.info(self.name + ": Git Checkout %s : Already on this branch" %branch)
1288 self.handle.expect("ONOS\$")
1289 print "after checkout cmd = ", self.handle.before
1290 switchedToMaster = 1
1291 return 1
1292 elif i==3:
1293 main.log.info(self.name + ": Git checkout %s - Switched to this branch" %branch)
1294 self.handle.expect("ONOS\$")
1295 print "after checkout cmd = ", self.handle.before
1296 switchedToMaster = 1
1297 return 1
1298 elif i==4:
1299 main.log.error(self.name + ": Git Checkout- TIMEOUT")
1300 main.log.error(self.name + " Response was: " + str(self.handle.before))
1301 return main.ERROR
1302 else:
1303 main.log.error(self.name + ": Git Checkout - Unexpected response, check for pull errors")
1304 return main.ERROR
1305
1306 except pexpect.EOF:
1307 main.log.error(self.name + ": EOF exception found")
1308 main.log.error(self.name + ": " + self.handle.before)
1309 main.cleanup()
1310 main.exit()
1311 except:
1312 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1313 main.log.error( traceback.print_exc() )
1314 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1315 main.cleanup()
1316 main.exit()
1317#********************************************************
1318 self.handle.sendline("git branch")
1319 self.handle.expect("ONOS\$")
1320 print "git branch output = ", self.handle.before
1321 print "*****************************************"
1322 self.handle.sendline('cd\.\.')
1323 self.handle.expect("\$")
1324
1325
1326
1327
1328
1329
1330
1331
admin7373a812014-04-16 09:49:02 -07001332 def git_compile(self):
Jon Hallae05dc22014-04-16 10:56:28 -07001333 '''
1334 Compiles ONOS
1335 First runs mvn clean then mvn compile
1336 '''
1337 try:
1338 main.log.info(self.name + ": mvn clean")
admin8fc02822014-04-16 13:31:23 -07001339 self.handle.sendline("cd " + self.home)
Jon Hallae05dc22014-04-16 10:56:28 -07001340 self.handle.sendline("mvn clean")
1341 while 1:
Jon Hall1636f942014-04-17 10:07:23 -07001342 i=self.handle.expect(['There\sis\sinsufficient\smemory\sfor\sthe\sJava\sRuntime\sEnvironment\sto\scontinue','BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=30)
Jon Hallae05dc22014-04-16 10:56:28 -07001343 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -07001344 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
Jon Hallae05dc22014-04-16 10:56:28 -07001345 return main.FALSE
1346 elif i == 1:
Jon Hall1636f942014-04-17 10:07:23 -07001347 main.log.error(self.name + ": Clean failure!")
1348 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -07001349 elif i == 2:
Jon Hall1636f942014-04-17 10:07:23 -07001350 main.log.info(self.name + ": Clean success!")
1351 elif i == 3:
admin8fc02822014-04-16 13:31:23 -07001352 main.log.info(self.name + ": Clean complete")
Jon Hallae05dc22014-04-16 10:56:28 -07001353 break;
Jon Hall1636f942014-04-17 10:07:23 -07001354 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -07001355 main.log.error(self.name + ": mvn clean TIMEOUT!")
1356 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -07001357 else:
1358 main.log.error(self.name + ": unexpected response from mvn clean")
1359 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -07001360
1361 main.log.info(self.name + ": mvn compile")
1362 self.handle.sendline("mvn compile")
1363 while 1:
Jon Hall1636f942014-04-17 10:07:23 -07001364 i=self.handle.expect(['There\sis\sinsufficient\smemory\sfor\sthe\sJava\sRuntime\sEnvironment\sto\scontinue','BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=60)
Jon Hallae05dc22014-04-16 10:56:28 -07001365 if i == 0:
Jon Hall1636f942014-04-17 10:07:23 -07001366 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
1367 return main.FALSE
1368 if i == 1:
Jon Hallae05dc22014-04-16 10:56:28 -07001369 main.log.error(self.name + ": Build failure!")
1370 return main.FALSE
Jon Hall1636f942014-04-17 10:07:23 -07001371 elif i == 2:
Jon Hallae05dc22014-04-16 10:56:28 -07001372 main.log.info(self.name + ": Build success!")
Jon Hall1636f942014-04-17 10:07:23 -07001373 elif i == 3:
Jon Hallae05dc22014-04-16 10:56:28 -07001374 main.log.info(self.name + ": Build complete")
Jon Hall010f5412014-05-21 15:10:12 -07001375 self.handle.expect("\$", timeout=60)
Jon Hallae05dc22014-04-16 10:56:28 -07001376 return main.TRUE
Jon Hall1636f942014-04-17 10:07:23 -07001377 elif i == 4:
Jon Hallae05dc22014-04-16 10:56:28 -07001378 main.log.error(self.name + ": mvn compile TIMEOUT!")
1379 return main.FALSE
1380 else:
Jon Hall1636f942014-04-17 10:07:23 -07001381 main.log.error(self.name + ": unexpected response from mvn compile")
1382 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -07001383 except pexpect.EOF:
1384 main.log.error(self.name + ": EOF exception found")
1385 main.log.error(self.name + ": " + self.handle.before)
1386 main.cleanup()
1387 main.exit()
1388 except:
1389 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1390 main.log.error( traceback.print_exc() )
1391 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1392 main.cleanup()
1393 main.exit()
admin4a58db92013-09-30 12:04:54 -07001394
Jon Hallf89c8552014-04-02 13:14:06 -07001395 def tcpdump(self, intf = "eth0"):
Jon Hallae05dc22014-04-16 10:56:28 -07001396 '''
1397 Runs tpdump on an intferface and saves in onos-logs under the ONOS home directory
1398 intf can be specified, or the default eth0 is used
1399 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001400 try:
1401 self.handle.sendline("")
1402 self.handle.expect("\$")
Jon Hall26f316b2014-04-11 11:21:25 -07001403 self.handle.sendline("sudo tcpdump -n -i "+ intf + " -s0 -w " + self.home +"/onos-logs/tcpdump &")
Jon Hallf89c8552014-04-02 13:14:06 -07001404 i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10)
1405 if i == 0:
1406 main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf)
1407 return main.FALSE
James Leec9cacaf2014-04-08 09:17:39 -07001408 elif i == 1:
Jon Hallf89c8552014-04-02 13:14:06 -07001409 main.log.info(self.name + ": tcpdump started on " + intf)
1410 return main.TRUE
James Leec9cacaf2014-04-08 09:17:39 -07001411 elif i == 2:
Jon Hallf89c8552014-04-02 13:14:06 -07001412 main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf)
1413 return main.FALSE
1414 else:
1415 main.log.error(self.name + ": tcpdump - unexpected response")
1416 return main.FALSE
Jon Hallae05dc22014-04-16 10:56:28 -07001417 except pexpect.EOF:
1418 main.log.error(self.name + ": EOF exception found")
1419 main.log.error(self.name + ": " + self.handle.before)
1420 main.cleanup()
1421 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001422 except:
1423 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1424 main.log.error( traceback.print_exc() )
1425 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1426 main.cleanup()
1427 main.exit()
1428
admin4a58db92013-09-30 12:04:54 -07001429 def kill_tcpdump(self):
Jon Hallae05dc22014-04-16 10:56:28 -07001430 '''
1431 Kills any tcpdump processes running
1432 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001433 try:
1434 self.handle.sendline("")
1435 self.handle.expect("\$")
1436 self.handle.sendline("sudo kill -9 `ps -ef | grep \"tcpdump -n\" | grep -v grep | awk '{print $2}'`")
Jon Hallae05dc22014-04-16 10:56:28 -07001437 except pexpect.EOF:
1438 main.log.error(self.name + ": EOF exception found")
1439 main.log.error(self.name + ": " + self.handle.before)
1440 main.cleanup()
1441 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001442 except:
1443 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1444 main.log.error( traceback.print_exc() )
1445 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1446 main.cleanup()
1447 main.exit()
1448
Jon Hallf15f7852014-05-20 10:37:23 -07001449 def find_host(self,RestIP,RestPort,RestAPI,hostMAC):
admin2a9548d2014-06-17 14:08:07 -07001450 retcode = 0 # number of hosts found with given MAC
1451 retswitch = [] # Switch DPID's of hosts found with MAC
1452 retport = [] # Switch port connected to to hosts found with MAC
Jon Hallf15f7852014-05-20 10:37:23 -07001453 foundHost = []
Jon Hallf89c8552014-04-02 13:14:06 -07001454 try:
Jon Hall2f42a672014-05-28 10:13:18 -07001455 ##### device rest API is: 'host:8080/wm/onos/topology/switches' ###
Jon Hallf89c8552014-04-02 13:14:06 -07001456 url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI)
1457
1458 try:
1459 command = "curl -s %s" % (url)
1460 result = os.popen(command).read()
1461 parsedResult = json.loads(result)
1462 # print parsedResult
1463 except:
1464 print "REST IF %s has issue" % command
1465 parsedResult = ""
1466
1467 if parsedResult == "":
Jon Hallf15f7852014-05-20 10:37:23 -07001468 return (retcode, "Rest API has an error", retport)
Jon Hallf89c8552014-04-02 13:14:06 -07001469 else:
Jon Hallf15f7852014-05-20 10:37:23 -07001470 for host in enumerate(parsedResult):
1471 print host
1472 if (host[1] != []):
1473 try:
1474 foundHost = host[1]['mac']
1475 except:
1476 print "Error in detecting MAC address."
1477 print foundHost
1478 print hostMAC
1479 if foundHost == hostMAC:
1480 for switch in enumerate(host[1]['attachmentPoints']):
1481 retswitch.append(switch[1]['dpid'])
Jon Hallbb650fe2014-07-14 14:54:48 -07001482 retport.append(switch[1]['portNumber'])
Jon Hallf15f7852014-05-20 10:37:23 -07001483 retcode = retcode +1
1484 foundHost =''
1485 '''
Jon Hallf89c8552014-04-02 13:14:06 -07001486 for switch in enumerate(parsedResult):
1487 for port in enumerate(switch[1]['ports']):
admin2a9548d2014-06-17 14:08:07 -07001488 if ( port[1]['hosts'] != [] ):
Jon Hallf89c8552014-04-02 13:14:06 -07001489 try:
admin2a9548d2014-06-17 14:08:07 -07001490 foundHost = port[1]['hosts'][0]['ipv4addresses'][0]['ipv4']
Jon Hallf89c8552014-04-02 13:14:06 -07001491 except:
Jon Hallf15f7852014-05-20 10:37:23 -07001492 print "Error in detecting MAC address."
1493 if foundHost == hostMAC:
Jon Hallf89c8552014-04-02 13:14:06 -07001494 retswitch.append(switch[1]['dpid'])
1495 retport.append(port[1]['desc'])
admin2a9548d2014-06-17 14:08:07 -07001496 retmac.append(port[1]['hosts'][0]['mac'])
Jon Hallf89c8552014-04-02 13:14:06 -07001497 retcode = retcode +1
Jon Hallf15f7852014-05-20 10:37:23 -07001498 foundHost =''
1499 '''
1500 return(retcode, retswitch, retport)
Jon Hallae05dc22014-04-16 10:56:28 -07001501 except pexpect.EOF:
1502 main.log.error(self.name + ": EOF exception found")
1503 main.log.error(self.name + ": " + self.handle.before)
1504 main.cleanup()
1505 main.exit()
Jon Hallf89c8552014-04-02 13:14:06 -07001506 except:
1507 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1508 main.log.error( traceback.print_exc() )
1509 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1510 main.cleanup()
1511 main.exit()
SeanCorcoran29b70542014-05-14 14:53:42 -07001512
1513 def check_exceptions(self):
1514 '''
1515 Greps the logs for "xception"
1516 '''
1517 try:
1518 output = ''
1519 self.handle.sendline("")
Jon Halla78cf9a2014-05-16 10:49:30 -07001520 i = self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
Jon Hall2c4f5542014-08-05 13:45:29 -07001521 main.log.warn("first expect response: " +str(i))
SeanCorcoran29b70542014-05-14 14:53:42 -07001522 self.handle.sendline("cd "+self.home+"/onos-logs")
Jon Hall2c4f5542014-08-05 13:45:29 -07001523 i = self.handle.expect(["onos-logs\$",pexpect.EOF,pexpect.TIMEOUT])
1524 main.log.warn("second expect response: " +str(i))
1525
1526 self.handle.sendline("zgrep \"xception\" *.log *.log.gz *.stderr")
1527 #i = self.handle.expect(["\*.stdout",pexpect.EOF,pexpect.TIMEOUT])
Jon Halla78cf9a2014-05-16 10:49:30 -07001528 #main.log.warn("third expect response: " +str(i))
Jon Hall2c4f5542014-08-05 13:45:29 -07001529 print self.handle.before
1530 print
1531 print self.handle.after
1532 i = self.handle.expect(["ONOS/onos-logs\$",pexpect.EOF,pexpect.TIMEOUT],timeout=120)
1533 main.log.warn("fourth expect response: " +str(i))
SeanCorcoran29b70542014-05-14 14:53:42 -07001534 response = self.handle.before
admin6903e462014-07-22 15:30:54 -07001535 print response
Jon Halla78cf9a2014-05-16 10:49:30 -07001536 count = 0
Jon Hallbb650fe2014-07-14 14:54:48 -07001537 print response
SeanCorcoran29b70542014-05-14 14:53:42 -07001538 for line in response.splitlines():
Jon Hallbb650fe2014-07-14 14:54:48 -07001539 if re.search("gzip: \*\.log\.gz:", line):
Jon Hall2c4f5542014-08-05 13:45:29 -07001540 #gzip complaining about file not found
Jon Hallbb650fe2014-07-14 14:54:48 -07001541 pass
Jon Hall724a2f42014-06-23 16:04:22 -07001542 elif re.search("log\.gz:",line):
1543 output+="Exceptions found in " + line + "\n"
1544 count +=1
Jon Hall2c4f5542014-08-05 13:45:29 -07001545 elif re.search("log:", line):
1546 output +="Exceptions found in " + line + "\n"
1547 count +=1
SeanCorcoran29b70542014-05-14 14:53:42 -07001548 elif re.search("std...:",line):
1549 output+="Exceptions found in " + line + "\n"
Jon Halla78cf9a2014-05-16 10:49:30 -07001550 count +=1
SeanCorcoran29b70542014-05-14 14:53:42 -07001551 else:
1552 pass
1553 #these should be the old logs
admin1723f1c2014-05-19 16:08:39 -07001554 main.log.report(str(count) + " Exceptions were found on "+self.name)
SeanCorcoran29b70542014-05-14 14:53:42 -07001555 return output
1556 except pexpect.TIMEOUT:
1557 main.log.error(self.name + ": Timeout exception found in check_exceptions function")
1558 except pexpect.EOF:
1559 main.log.error(self.name + ": EOF exception found")
1560 main.log.error(self.name + ": " + self.handle.before)
1561 main.cleanup()
1562 main.exit()
1563 except:
1564 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1565 main.log.error( traceback.print_exc() )
1566 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1567 main.cleanup()
1568 main.exit()