blob: 24502ae6901f0be0dd94f7cd6eeb79d6b9e6ac19 [file] [log] [blame]
admin2a9548d2014-06-17 14:08:07 -07001#!/usr/bin/env python
2'''
3'''
4
5import pexpect
6import struct
7import fcntl
8import os
9import signal
10import re
11import sys
12import core.teston
13import time
14import json
15import traceback
16import requests
17
18sys.path.append("../")
19from drivers.common.clidriver import CLI
20
21class onossanityclidriver(CLI):
22 '''
23 '''
24 def __init__(self):
25 super(CLI, self).__init__()
26
27 def connect(self,**connectargs):
28 '''
29 Creates ssh handle for ONOS.
30 '''
31 try:
32 for key in connectargs:
33 vars(self)[key] = connectargs[key]
34 self.home = "~/ONOS"
35 for key in self.options:
36 if key == "home":
37 self.home = self.options['home']
38 break
39
40
41 self.name = self.options['name']
42 self.handle = super(onossanityclidriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd, home = self.home)
43
44 if self.handle:
45 return self.handle
46 else :
47 main.log.info("NO ONOS HANDLE")
48 return main.FALSE
49 except pexpect.EOF:
50 main.log.error(self.name + ": EOF exception found")
51 main.log.error(self.name + ": " + self.handle.before)
52 main.cleanup()
53 main.exit()
54 except:
55 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
56 main.log.error( traceback.print_exc() )
57 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
58 main.cleanup()
59 main.exit()
60
61 def start(self):
62 '''
63 Starts ONOS on remote machine.
64 Returns false if any errors were encountered.
65 '''
66 try:
67 self.handle.sendline("")
68 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
69 self.handle.sendline("cd "+self.home)
70 self.handle.sendline("./onos.sh zk start")
71 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
72 self.handle.sendline("./onos.sh rc deldb")
73 self.handle.sendline("y")
74 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
75 #Send a confirmation to delete ramcloud
76 #self.handle.sendline("y")
77 main.log.info("Ramcloud db deleted")
78 #self.handle.sendline("./onos.sh zk start")
79 #Check if zookeeper is running
80 #delete database ./onos.sh rc deldb
81 #main.log.info(self.name + ": ZooKeeper Started Separately")
82 time.sleep(2)
83 self.handle.sendline("./onos.sh start")
84 i=self.handle.expect(["STARTED","FAILED","running",pexpect.EOF,pexpect.TIMEOUT])
85 if i==0:
86 main.log.info(self.name + ": ZooKeeper, Ramcloud and ONOS Started ")
87 return main.TRUE
88 elif i==1:
89 main.log.error(self.name + ": Failed to start")
90 return main.FALSE
91 elif i==2:
92 main.log.info(self.name + ": Already running, so Restarting ONOS")
93 self.handle.sendline("./onos.sh restart")
94 j=self.handle.expect(["STARTED","FAILED",pexpect.EOF,pexpect.TIMEOUT])
95 if j==0:
96 main.log.info(self.name + ": ZooKeeper, Ramcloud and ONOS Started ")
97 return main.TRUE
98 else:
99 main.log.error(self.name + ": ONOS Failed to Start")
100 elif i==3:
101 main.log.error(self.name + ": EOF exception found")
102 main.log.error(self.name + ": " + self.handle.before)
103 main.cleanup()
104 elif i==2:
105 main.log.info(self.name + ": Already running, so Restarting ONOS")
106 self.handle.sendline("./onos.sh restart")
107 j=self.handle.expect(["STARTED","FAILED",pexpect.EOF,pexpect.TIMEOUT])
108 if j==0:
109 main.log.info(self.name + ": ZooKeeper, Ramcloud and ONOS Started ")
110 return main.TRUE
111 elif j==1:
112 main.log.error(self.name + ": ONOS Failed to Start")
113 main.log.info(self.name + ": cleaning up and exiting...")
114 main.cleanup()
115 main.exit()
116 elif j==2:
117 main.log.error(self.name + ": EOF exception found")
118 main.log.error(self.name + ": " + self.handle.before)
119 main.log.info(self.name + ": cleaning up and exiting...")
120 main.cleanup()
121 main.exit()
122 elif i==3:
123 main.log.error(self.name + ": EOF exception found")
124 main.log.error(self.name + ": " + self.handle.before)
125 main.cleanup()
126 main.exit()
127 elif i==4:
128 main.log.error(self.name + ": ONOS timedout while starting")
129 return main.FALSE
130 else:
131 main.log.error(self.name + ": ONOS start expect script missed something... ")
132 return main.FALSE
133 except pexpect.EOF:
134 main.log.error(self.name + ": EOF exception found")
135 main.log.error(self.name + ": " + self.handle.before)
136 main.cleanup()
137 main.exit()
138 except:
139 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
140 main.log.error( traceback.print_exc() )
141 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
142 main.cleanup()
143 main.exit()
144
145 def status(self):
146 '''
147 Calls onos.sh core status and returns TRUE/FALSE accordingly
148 '''
149 try:
150 self.execute(cmd="\n",prompt="\$",timeout=10)
151 self.handle.sendline("cd "+self.home)
152 response = self.execute(cmd="./onos.sh core status ",prompt="\d+\sinstance\sof\sonos\srunning",timeout=10)
153 self.execute(cmd="\n",prompt="\$",timeout=10)
154 if re.search("1\sinstance\sof\sonos\srunning",response):
155 return main.TRUE
156 elif re.search("0\sinstance\sof\sonos\srunning",response):
157 return main.FALSE
158 else :
159 main.log.info( self.name + " WARNING: status recieved unknown response")
160 main.log.info( self.name + " For details: check onos core status manually")
161 return main.FALSE
162 except pexpect.EOF:
163 main.log.error(self.name + ": EOF exception found")
164 main.log.error(self.name + ": " + self.handle.before)
165 main.cleanup()
166 main.exit()
167 except:
168 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
169 main.log.error( traceback.print_exc() )
170 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
171 main.cleanup()
172 main.exit()
173
174 def zk_status(self):
175 '''
176 Calls the zookeeper status and returns TRUE if it has an assigned Mode to it.
177 '''
178 try:
179 self.execute(cmd="\n",prompt="\$",timeout=10)
180 self.handle.sendline("cd "+self.home)
181 self.handle.sendline("./onos.sh zk status")
182 i=self.handle.expect(["standalone","Error",pexpect.EOF,pexpect.TIMEOUT])
183 if i==0:
184 main.log.info(self.name + ": Zookeeper is running.")
185 return main.TRUE
186 elif i==1:
187 main.log.error(self.name + ": Error with zookeeper")
188 main.log.info(self.name + ": Directory used: "+self.home)
189 return main.FALSE
190 elif i==3:
191 main.log.error(self.name + ": Zookeeper timed out")
192 main.log.info(self.name + ": Directory used: "+self.home)
193 return main.FALSE
194 except pexpect.EOF:
195 main.log.error(self.name + ": EOF exception found")
196 main.log.error(self.name + ": " + self.handle.before)
197 main.cleanup()
198 main.exit()
199 except:
200 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
201 main.log.error( traceback.print_exc() )
202 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
203 main.cleanup()
204 main.exit()
205
206 def rcs_status(self):
207 '''
208 This Function will return the Status of the RAMCloud Server
209 '''
210 main.log.info(self.name + ": Getting RC-Server Status")
211 self.handle.sendline("")
212 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
213 self.handle.sendline("cd "+self.home)
214 self.handle.sendline("./onos.sh rc-server status")
215 self.handle.expect(["onos.sh rc-server status",pexpect.EOF,pexpect.TIMEOUT])
216 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
217 response = self.handle.before + self.handle.after
218
219 if re.search("0\sRAMCloud\sserver\srunning", response) :
220 main.log.info(self.name+": RAMCloud not running")
221 return main.TRUE
222 elif re.search("1\sRAMCloud\sserver\srunning",response):
223 main.log.warn(self.name+": RAMCloud Running")
224 return main.TRUE
225 else:
226 main.log.info( self.name+": WARNING: status recieved unknown response")
227 return main.FALSE
228
229 def rcc_status(self):
230 '''
231 This Function will return the Status of the RAMCloud Coord
232 '''
233 main.log.info(self.name + ": Getting RC-Coord Status")
234 self.handle.sendline("")
235 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
236 self.handle.sendline("cd "+self.home)
237 self.handle.sendline("./onos.sh rc-coord status")
238 i=self.handle.expect(["onos.sh rc-coord status",pexpect.EOF,pexpect.TIMEOUT])
239 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
240 response = self.handle.before + self.handle.after
241 #return response
242
243 if re.search("0\sRAMCloud\scoordinator\srunning", response) :
244 main.log.warn(self.name+": RAMCloud Coordinator not running")
245 return main.TRUE
246 elif re.search("1\sRAMCloud\scoordinator\srunning", response):
247 main.log.info(self.name+": RAMCloud Coordinator Running")
248 return main.TRUE
249 else:
250 main.log.warn( self.name+": coordinator status recieved unknown response")
251 return main.FALSE
252
253 def stop(self):
254 '''
255 Runs ./onos.sh core stop to stop ONOS
256 '''
257 try:
258 self.handle.sendline("")
259 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT])
260 self.handle.sendline("cd "+self.home)
261 self.handle.sendline("./onos.sh stop")
262 i=self.handle.expect(["Stop",pexpect.EOF,pexpect.TIMEOUT])
263 self.handle.expect(["\$",pexpect.EOF,pexpect.TIMEOUT], 60)
264 result = self.handle.before
265 if re.search("Killed", result):
266 main.log.info(self.name + ": ONOS Killed Successfully")
267 return main.TRUE
268 else :
269 main.log.warn(self.name + ": ONOS wasn't running")
270 return main.FALSE
271 except pexpect.EOF:
272 main.log.error(self.name + ": EOF exception found")
273 main.log.error(self.name + ": " + self.handle.before)
274 main.cleanup()
275 main.exit()
276 except:
277 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
278 main.log.error( traceback.print_exc() )
279 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
280 main.cleanup()
281 main.exit()
282
283 def start_rest(self):
284 '''
285 Starts the rest server on ONOS.
286 '''
287 try:
288 self.handle.sendline("cd "+self.home)
289 response = self.execute(cmd= "./start-rest.sh start",prompt="\$",timeout=10)
290 if re.search(self.user_name,response):
291 main.log.info(self.name + ": Rest Server Started Successfully")
292 time.sleep(5)
293 return main.TRUE
294 else :
295 main.log.warn(self.name + ": Failed to start Rest Server")
296 main.log.info(self.name + ": Directory used: "+self.home )
297 main.log.info(self.name + ": Rest server response: "+response)
298 return main.FALSE
299 except pexpect.EOF:
300 main.log.error(self.name + ": EOF exception found")
301 main.log.error(self.name + ": " + self.handle.before)
302 main.cleanup()
303 main.exit()
304 except:
305 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
306 main.log.error( traceback.print_exc() )
307 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
308 main.cleanup()
309 main.exit()
310
311 def rest_stop(self):
312 '''
313 Runs ./start-rest.sh stop to stop ONOS rest server
314 '''
315 try:
316 response = self.execute(cmd= self.home + "./start-rest.sh stop ",prompt="killing",timeout=10)
317 self.execute(cmd="\n",prompt="\$",timeout=10)
318 if re.search("killing", response):
319 main.log.info(self.name + ": Rest Server Stopped")
320 return main.TRUE
321 else :
322 main.log.error(self.name + ": Failed to Stop, Rest Server is not Running")
323 main.log.info(self.name + ": Directory used: "+self.home)
324 main.log.info(self.name + ": Rest server response: " + response)
325 return main.FALSE
326 except pexpect.EOF:
327 main.log.error(self.name + ": EOF exception found")
328 main.log.error(self.name + ": " + self.handle.before)
329 main.cleanup()
330 main.exit()
331 except:
332 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
333 main.log.error( traceback.print_exc() )
334 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
335 main.cleanup()
336 main.exit()
337
338 def rest_status(self):
339 '''
340 Checks if the rest server is running.
341 '''
342 #this function does not capture the status response correctly...
343 #when cmd is executed, the prompt expected should be a string containing
344 #status message, but instead returns the user@user$ Therefore prompt="running"
345 #was changed to prompt="\$"
346 try:
347 response = self.execute(cmd= self.home + "./start-rest.sh status ",prompt="\$",timeout=10)
348 if re.search(self.user_name,response):
349 main.log.info(self.name + ": Rest Server is running")
350 return main.TRUE
351 elif re.search("rest\sserver\sis\snot\srunning",response):
352 main.log.warn(self.name + ": Rest Server is not Running")
353 return main.FALSE
354 else :
355 main.log.error(self.name + ": No response" +response)
356 return main.FALSE
357 except pexpect.EOF:
358 main.log.error(self.name + ": EOF exception found")
359 main.log.error(self.name + ": " + self.handle.before)
360 main.cleanup()
361 main.exit()
362 except:
363 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
364 main.log.error( traceback.print_exc() )
365 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
366 main.cleanup()
367 main.exit()
368
369 def disconnect(self):
370 '''
371 Called when Test is complete to disconnect the ONOS handle.
372 '''
373 response = ''
374 try:
375 self.handle.sendline("exit")
376 self.handle.expect("closed")
377 except pexpect.EOF:
378 main.log.error(self.name + ": EOF exception found")
379 main.log.error(self.name + ": " + self.handle.before)
380 except:
381 main.log.error(self.name + ": Connection failed to the host")
382 response = main.FALSE
383 return response
384
385 def print_version(self):
386 '''
387 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
388 '''
389 try:
390 self.handle.sendline("export TERM=xterm-256color")
391 self.handle.expect("xterm-256color")
392 self.handle.expect("\$")
393 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.")
394 self.handle.expect("cd ..")
395 self.handle.expect("\$")
396 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
397 main.log.report(response)
398 except pexpect.EOF:
399 main.log.error(self.name + ": EOF exception found")
400 main.log.error(self.name + ": " + self.handle.before)
401 main.cleanup()
402 main.exit()
403 except:
404 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
405 main.log.error( traceback.print_exc() )
406 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
407 main.cleanup()
408 def get_version(self):
409 '''
410 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
411 '''
412 try:
413 self.handle.sendline("export TERM=xterm-256color")
414 self.handle.expect("xterm-256color")
415 self.handle.expect("\$")
416 self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller | grep -A 5 \"commit\"; cd \.\.")
417 self.handle.expect("cd ..")
418 self.handle.expect("\$")
419 response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
420 lines=response.splitlines()
421 for line in lines:
422 print line
423 return lines[2]
424 except pexpect.EOF:
425 main.log.error(self.name + ": EOF exception found")
426 main.log.error(self.name + ": " + self.handle.before)
427 main.cleanup()
428 main.exit()
429 except:
430 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
431 main.log.error( traceback.print_exc() )
432 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
433 main.cleanup()
434 main.exit()
435
436 def add_flow(self, intentFile, path):
437 try:
438 main.log.info("add_flow running...")
439 main.log.info("using directory: "+path)
440 time.sleep(10)
441 self.handle.sendline("cd " + path)
442 self.handle.expect("tests")
443 self.handle.sendline("./"+intentFile)
444 time.sleep(10)
445 self.handle.sendline("cd "+self.home)
446 return main.TRUE
447 except pexepct.EOF:
448 main.log.error(self.name + ": EOF exception found")
449 main.log.error(self.name + ": " + self.handle.before)
450 main.cleanup()
451 main.exit()
452 except:
453 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
454 main.log.error( traceback.print_exc() )
455 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
456 main.cleanup()
457 main.exit()
458
459 def delete_flow(self, intentFile, path):
460 try:
461 main.log.info("delete_flow running...")
462 main.log.info("using directory: " + path)
463 main.log.info("using file: " + intentFile)
464 self.handle.sendline("cd " + path)
465 self.handle.expect("tests")
466 self.handle.sendline("./" + intentFile)
467 time.sleep(10)
468 self.handle.sendline("cd "+self.home)
469 return main.TRUE
470 except pexepct.EOF:
471 main.log.error(self.name + ": EOF exception found")
472 main.log.error(self.name + ": " + self.handle.before)
473 main.cleanup()
474 main.exit()
475 except:
476 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
477 main.log.error( traceback.print_exc() )
478 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
479 main.cleanup()
480 main.exit()
481
482 def check_flow(self):
483 '''
484 Calls the ./get_flow.py all and checks:
485 - If each FlowPath has at least one FlowEntry
486 - That there are no "NOT"s found
487 returns TRUE/FALSE
488 '''
489 try:
490 flowEntryDetect = 1
491 count = 0
492 self.handle.sendline("clear")
493 time.sleep(1)
494 self.handle.sendline(self.home + "/web/get_flow.py all")
495 self.handle.expect("get_flow")
496 while 1:
497 i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180)
498 if i==0:
499 count = count + 1
500 if flowEntryDetect == 0:
501 main.log.info(self.name + ": FlowPath without FlowEntry")
502 return main.FALSE
503 else:
504 flowEntryDetect = 0
505 elif i==1:
506 flowEntryDetect = 1
507 elif i==2:
508 main.log.error(self.name + ": Found a NOT")
509 return main.FALSE
510 elif i==3:
511 if count == 0:
512 main.log.info(self.name + ": There don't seem to be any flows here...")
513 return main.FALSE
514 else:
515 main.log.info(self.name + ": All flows pass")
516 main.log.info(self.name + ": Number of FlowPaths: "+str(count))
517 return main.TRUE
518 elif i==4:
519 main.log.error(self.name + ":Check_flow() - Command Timeout!")
520 return main.FALSE
521 except pexpect.EOF:
522 main.log.error(self.name + ": EOF exception found")
523 main.log.error(self.name + ": " + self.handle.before)
524 main.cleanup()
525 main.exit()
526 except:
527 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
528 main.log.error( traceback.print_exc() )
529 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
530 main.cleanup()
531 main.exit()
532
533 def get_flow(self, *flowParams):
534 '''
535 Returns verbose output of ./get_flow.py
536 '''
537 try:
538 if len(flowParams)==1:
539 if str(flowParams[0])=="all":
540 self.execute(cmd="\n",prompt="\$",timeout=60)
541 main.log.info(self.name + ": Getting all flow data...")
542 data = self.execute(cmd=self.home + "/scripts/TestON_get_flow.sh all",prompt="done",timeout=150)
543 self.execute(cmd="\n",prompt="\$",timeout=60)
544 return data
545 else:
546 main.log.info(self.name + ": Retrieving flow "+str(flowParams[0])+" data...")
547 data = self.execute(cmd=self.home +"/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150)
548 self.execute(cmd="\n",prompt="\$",timeout=60)
549 return data
550 elif len(flowParams)==5:
551 main.log.info(self.name + ": Retrieving flow installer data...")
552 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)
553 self.execute(cmd="\n",prompt="\$",timeout=60)
554 return data
555 elif len(flowParams)==4:
556 main.log.info(self.name + ": Retrieving flow endpoints...")
557 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)
558 self.execute(cmd="\n",prompt="\$",timeout=60)
559 return data
560 except pexpect.EOF:
561 main.log.error(self.name + ": EOF exception found")
562 main.log.error(self.name + ": " + self.handle.before)
563 main.cleanup()
564 main.exit()
565 except:
566 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
567 main.log.error( traceback.print_exc() )
568 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
569 main.cleanup()
570 main.exit()
571
572
573# http://localhost:8080/wm/onos/ng/switches/json
574# http://localhost:8080/wm/onos/ng/links/json
575# http://localhost:8080/wm/onos/registry/controllers/json
576# http://localhost:8080/wm/onos/registry/switches/json"
577
578 def get_json(self, url):
579 '''
580 Helper functions used to parse the json output of a rest call
581 '''
582 try:
583 try:
584 command = "curl -s %s" % (url)
585 result = os.popen(command).read()
586 parsedResult = json.loads(result)
587 except:
588 print "REST IF %s has issue" % command
589 parsedResult = ""
590
591 if type(parsedResult) == 'dict' and parsedResult.has_key('code'):
592 print "REST %s returned code %s" % (command, parsedResult['code'])
593 parsedResult = ""
594 return parsedResult
595 except pexpect.EOF:
596 main.log.error(self.name + ": EOF exception found")
597 main.log.error(self.name + ": " + self.handle.before)
598 main.cleanup()
599 main.exit()
600 except:
601 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
602 main.log.error( traceback.print_exc() )
603 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
604 main.cleanup()
605 main.exit()
606
607 def check_switch(self,RestIP,correct_nr_switch, RestPort ="8080" ):
608 '''
609 Used by check_status
610 '''
611 try:
612 buf = ""
613 retcode = 0
614 url="http://%s:%s/wm/onos/topology/switches" % (RestIP, RestPort)
615 parsedResult = self.get_json(url)
616 if parsedResult == "":
617 retcode = 1
618 return (retcode, "Rest API has an issue")
619 url = "http://%s:%s/wm/onos/registry/switches" % (RestIP, RestPort)
620 registry = self.get_json(url)
621
622 if registry == "":
623 retcode = 1
624 return (retcode, "Rest API has an issue")
625
626 cnt = 0
627 active = 0
628
629 for s in parsedResult:
630 cnt += 1
631 if s['state'] == "ACTIVE":
632 active += 1
633
634 buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active)
635 if correct_nr_switch != cnt:
636 buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt)
637 retcode = 1
638
639 if correct_nr_switch != active:
640 buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active)
641 retcode = 1
642
643 return (retcode, buf)
644 except pexpect.EOF:
645 main.log.error(self.name + ": EOF exception found")
646 main.log.error(self.name + ": " + self.handle.before)
647 main.cleanup()
648 main.exit()
649 except:
650 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
651 main.log.error( traceback.print_exc() )
652 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
653 main.cleanup()
654 main.exit()
655
656 def check_link(self,RestIP, nr_links, RestPort = "8080"):
657 '''
658 Used by check_status
659 '''
660 try:
661 buf = ""
662 retcode = 0
663
664 url = "http://%s:%s/wm/onos/topology/links" % (RestIP, RestPort)
665 parsedResult = self.get_json(url)
666
667 if parsedResult == "":
668 retcode = 1
669 return (retcode, "Rest API has an issue")
670
671 buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links)
672 intra = 0
673 interlink=0
674
675 for s in parsedResult:
676 intra = intra + 1
677
678 if intra != nr_links:
679 buf += "link fail\n"
680 retcode = 1
681
682 return (retcode, buf)
683 except pexpect.EOF:
684 main.log.error(self.name + ": EOF exception found")
685 main.log.error(self.name + ": " + self.handle.before)
686 main.cleanup()
687 main.exit()
688 except:
689 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
690 main.log.error( traceback.print_exc() )
691 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
692 main.cleanup()
693 main.exit()
694
695 def check_status_report(self, ip, numoswitch, numolink, port="8080"):
696 '''
697 Checks the number of swithes & links that ONOS sees against the supplied values.
698 Writes to the report log.
699 '''
700 try:
701 main.log.info(self.name + ": Making some rest calls...")
702 switch = self.check_switch(ip, int(numoswitch), port)
703 link = self.check_link(ip, int(numolink), port)
704 value = switch[0]
705 value += link[0]
706 main.log.report( self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
707 if value != 0:
708 return main.FALSE
709 else:
710 # "PASS"
711 return main.TRUE
712 except pexpect.EOF:
713 main.log.error(self.name + ": EOF exception found")
714 main.log.error(self.name + ": " + self.handle.before)
715 main.cleanup()
716 main.exit()
717 except:
718 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
719 main.log.error( traceback.print_exc() )
720 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
721 main.cleanup()
722 main.exit()
723
724 def check_status(self, ip, numoswitch, numolink, port = "8080"):
725 '''
726 Checks the number of swithes & links that ONOS sees against the supplied values.
727 Writes to the main log.
728 '''
729 try:
730 main.log.info(self.name + ": Making some rest calls...")
731 switch = self.check_switch(ip, int(numoswitch), port)
732 link = self.check_link(ip, int(numolink), port)
733 value = switch[0]
734 value += link[0]
735 main.log.info(self.name + ": \n-----\n%s%s-----\n" % ( switch[1], link[1]) )
736 if value != 0:
737 return main.FALSE
738 else:
739 # "PASS"
740 return main.TRUE
741 except pexpect.EOF:
742 main.log.error(self.name + ": EOF exception found")
743 main.log.error(self.name + ": " + self.handle.before)
744 main.cleanup()
745 main.exit()
746 except:
747 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
748 main.log.error( traceback.print_exc() )
749 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
750 main.cleanup()
751 main.exit()
752
753 def check_for_no_exceptions(self):
754 '''
755 TODO: Rewrite
756 Used by CassndraCheck.py to scan ONOS logs for Exceptions
757 '''
758 try:
759 self.handle.sendline("dsh 'grep Exception ~/ONOS/onos-logs/onos.*.log'")
760 self.handle.expect("\$ dsh")
761 self.handle.expect("\$")
762 output = self.handle.before
763 main.log.info(self.name + ": " + output )
764 if re.search("Exception",output):
765 return main.FALSE
766 else :
767 return main.TRUE
768 except pexpect.EOF:
769 main.log.error(self.name + ": EOF exception found")
770 main.log.error(self.name + ": " + self.handle.before)
771 main.cleanup()
772 main.exit()
773 except:
774 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
775 main.log.error( traceback.print_exc() )
776 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
777 main.cleanup()
778 main.exit()
779
780
781 def git_pull(self, comp1=""):
782 '''
783 Assumes that "git pull" works without login
784
785 This function will perform a git pull on the ONOS instance.
786 If used as git_pull("NODE") it will do git pull + NODE. This is
787 for the purpose of pulling from other nodes if necessary.
788
789 Otherwise, this function will perform a git pull in the
790 ONOS repository. If it has any problems, it will return main.ERROR
791 If it successfully does a git_pull, it will return a 1.
792 If it has no updates, it will return a 0.
793
794 '''
795 try:
796 main.log.info(self.name + ": Stopping ONOS")
797 self.stop()
798 self.handle.sendline("cd " + self.home)
799 self.handle.expect("ONOS\$")
800 if comp1=="":
801 self.handle.sendline("git pull")
802 else:
803 self.handle.sendline("git pull " + comp1)
804
805 uptodate = 0
806 i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Unpacking\sobjects',pexpect.TIMEOUT,'Already up-to-date','Aborting'],timeout=1800)
807 #debug
808 #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after))
809 if i==0:
810 main.log.error(self.name + ": Git pull had some issue...")
811 return main.ERROR
812 elif i==1:
813 main.log.error(self.name + ": Git Pull Asking for username!!! BADD!")
814 return main.ERROR
815 elif i==2:
816 main.log.info(self.name + ": Git Pull - pulling repository now")
817 self.handle.expect("ONOS\$", 120)
818 return 0
819 elif i==3:
820 main.log.error(self.name + ": Git Pull - TIMEOUT")
821 return main.ERROR
822 elif i==4:
823 main.log.info(self.name + ": Git Pull - Already up to date")
824 return 1
825 elif i==5:
826 main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?")
827 return main.ERROR
828 else:
829 main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors")
830 return main.ERROR
831 except pexpect.EOF:
832 main.log.error(self.name + ": EOF exception found")
833 main.log.error(self.name + ": " + self.handle.before)
834 main.cleanup()
835 main.exit()
836 except:
837 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
838 main.log.error( traceback.print_exc() )
839 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
840 main.cleanup()
841 main.exit()
842#********************************************************
843
844
845 def git_compile(self):
846 '''
847 Compiles ONOS
848 First runs mvn clean then mvn compile
849 '''
850 try:
851 main.log.info(self.name + ": mvn clean")
852 self.handle.sendline("cd " + self.home)
853 self.handle.sendline("mvn clean")
854 while 1:
855 i=self.handle.expect(['There\sis\sinsufficient\smemory\sfor\sthe\sJava\sRuntime\sEnvironment\sto\scontinue','BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=30)
856 if i == 0:
857 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
858 return main.FALSE
859 elif i == 1:
860 main.log.error(self.name + ": Clean failure!")
861 return main.FALSE
862 elif i == 2:
863 main.log.info(self.name + ": Clean success!")
864 elif i == 3:
865 main.log.info(self.name + ": Clean complete")
866 break;
867 elif i == 4:
868 main.log.error(self.name + ": mvn clean TIMEOUT!")
869 return main.FALSE
870 else:
871 main.log.error(self.name + ": unexpected response from mvn clean")
872 return main.FALSE
873
874 main.log.info(self.name + ": mvn compile")
875 self.handle.sendline("mvn compile")
876 while 1:
877 i=self.handle.expect(['There\sis\sinsufficient\smemory\sfor\sthe\sJava\sRuntime\sEnvironment\sto\scontinue','BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=60)
878 if i == 0:
879 main.log.error(self.name + ":There is insufficient memory for the Java Runtime Environment to continue.")
880 return main.FALSE
881 if i == 1:
882 main.log.error(self.name + ": Build failure!")
883 return main.FALSE
884 elif i == 2:
885 main.log.info(self.name + ": Build success!")
886 return main.TRUE
887 elif i == 3:
888 main.log.info(self.name + ": Build complete")
889 return main.TRUE
890 elif i == 4:
891 main.log.error(self.name + ": mvn compile TIMEOUT!")
892 return main.FALSE
893 else:
894 main.log.error(self.name + ": unexpected response from mvn compile")
895 return main.FALSE
896 except pexpect.EOF:
897 main.log.error(self.name + ": EOF exception found")
898 main.log.error(self.name + ": " + self.handle.before)
899 main.cleanup()
900 main.exit()
901 except:
902 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
903 main.log.error( traceback.print_exc() )
904 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
905 main.cleanup()
906 main.exit()
907
908 def tcpdump(self, intf = "eth0"):
909 '''
910 Runs tpdump on an intferface and saves in onos-logs under the ONOS home directory
911 intf can be specified, or the default eth0 is used
912 '''
913 try:
914 self.handle.sendline("")
915 self.handle.expect("\$")
916 self.handle.sendline("sudo tcpdump -n -i "+ intf + " -s0 -w " + self.home +"/onos-logs/tcpdump &")
917 i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT],timeout=10)
918 if i == 0:
919 main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf)
920 return main.FALSE
921 elif i == 1:
922 main.log.info(self.name + ": tcpdump started on " + intf)
923 return main.TRUE
924 elif i == 2:
925 main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf)
926 return main.FALSE
927 else:
928 main.log.error(self.name + ": tcpdump - unexpected response")
929 return main.FALSE
930 except pexpect.EOF:
931 main.log.error(self.name + ": EOF exception found")
932 main.log.error(self.name + ": " + self.handle.before)
933 main.cleanup()
934 main.exit()
935 except:
936 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
937 main.log.error( traceback.print_exc() )
938 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
939 main.cleanup()
940 main.exit()
941
942 def kill_tcpdump(self):
943 '''
944 Kills any tcpdump processes running
945 '''
946 try:
947 self.handle.sendline("")
948 self.handle.expect("\$")
949 self.handle.sendline("sudo kill -9 `ps -ef | grep \"tcpdump -n\" | grep -v grep | awk '{print $2}'`")
950 except pexpect.EOF:
951 main.log.error(self.name + ": EOF exception found")
952 main.log.error(self.name + ": " + self.handle.before)
953 main.cleanup()
954 main.exit()
955 except:
956 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
957 main.log.error( traceback.print_exc() )
958 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
959 main.cleanup()
960 main.exit()
961
962 def find_host(self,RestIP,RestPort,RestAPI,hostIP):
963 retcode = 0
964 retswitch = []
965 retport = []
966 retmac = []
967 foundIP = []
968 try:
969 ##### device rest API is: 'host:8080/wm/onos/ng/switches/json' ###
970 url ="http://%s:%s%s" %(RestIP,RestPort,RestAPI)
971 print url
972
973 try:
974 command = "curl -s %s" % (url)
975 result = os.popen(command).read()
976 parsedResult = json.loads(result)
977 print parsedResult
978 except:
979 print "REST IF %s has issue" % command
980 parsedResult = ""
981
982 if parsedResult == "":
983 return (retcode, "Rest API has an error", retport, retmac)
984 else:
985 for switch in enumerate(parsedResult):
986 #print switch
987 for port in enumerate(switch[1]['ports']):
988 if ( port[1]['devices'] != [] ):
989 try:
990 foundIP = port[1]['devices'][0]['ipv4addresses'][0]['ipv4']
991 except:
992 print "Error in detecting IP address."
993 if foundIP == hostIP:
994 retswitch.append(switch[1]['dpid'])
995 retport.append(port[1]['desc'])
996 retmac.append(port[1]['devices'][0]['mac'])
997 retcode = retcode +1
998 foundIP =''
999 return(retcode, retswitch, retport, retmac)
1000 except pexpect.EOF:
1001 main.log.error(self.name + ": EOF exception found")
1002 main.log.error(self.name + ": " + self.handle.before)
1003 main.cleanup()
1004 main.exit()
1005 except:
1006 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1007 main.log.error( traceback.print_exc() )
1008 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1009 main.cleanup()
1010 main.exit()
1011
1012#Perf test related functions
1013
1014 def addPerfFlows(self, flowdef, numflows):
1015 main.log.info("ADD_FLOW RUNNING!!!! ")
1016 startTime=time.time()
1017 self.execute(cmd="/home/admin/ONOS/scripts"+"/add_"+str(numflows)+".py",prompt="\$",timeout=10)
1018 elapsedTime=time.time()-startTime
1019 main.log.info("AddFlows script run time: " + str(elapsedTime) + " seconds")
1020 time.sleep(15)
1021 return main.TRUE
1022
1023 def removePerfFlows(self, flowdef, numflows):
1024 main.log.info("REMOVE_FLOW RUNNING!!!! ")
1025 startTime=time.time()
1026 self.execute(cmd="/home/admin/ONOS/scripts"+"/remove_"+str(numflows)+".py",prompt="\$",timeout=10)
1027 elapsedTime=time.time()-startTime
1028 main.log.info("RemoveFlows script run time: " + str(elapsedTime) + " seconds")
1029 time.sleep(15)
1030 return main.TRUE
1031
1032 def start_tshark(self,flowtype, numflows):
1033 self.handle.sendline("")
1034 self.handle.expect("\$")
1035 self.execute(cmd='''rm /tmp/wireshark*''')
1036 self.handle.sendline("y")
1037 self.handle.expect("\$")
1038 self.execute(cmd='''tshark -i lo -t e | grep --color=auto CSM | grep --color=auto -E 'Flow|Barrier' > /tmp/tdump_'''+flowtype+"_"+str(numflows)+".txt &",prompt="Capturing",timeout=10)
1039 self.handle.sendline("")
1040 self.handle.expect("\$")
1041 main.log.info("TSHARK STARTED!!!")
1042 return main.TRUE
1043
1044 def stop_tshark(self):
1045 self.handle.sendline("")
1046 self.handle.expect("\$")
1047 self.handle.sendline("sudo kill -9 `ps -ef | grep \"tshark -i\" | grep -v grep | awk '{print $2}'`")
1048 self.handle.sendline("")
1049 self.handle.expect("\$")
1050 main.log.info("TSHARK STOPPED!!!")
1051 return main.TRUE
1052
1053 def generateFlows(self, flowdef, flowtype, numflows, ip):
1054 main.log.info("GENERATE FLOWS RUNNING!!!")
1055 #main.log.info("Test" + flowdef+"/"+flowtype+"_"+str(numflows)+".py")
1056 f = open(flowdef+"/"+flowtype+"_"+str(numflows)+".py", 'w')
1057 f.write('''#! /usr/bin/python\n''')
1058 f.write('import json\n')
1059 f.write('import requests\n')
1060 f.write('''url = 'http://'''+ip+''':8080/wm/onos/datagrid/add/intents/json'\n''')
1061 f.write('''headers = {'Content-type': 'application/json', 'Accept': 'application/json'}\n''')
1062
1063 intents = []
1064 idx = 0
1065 for i in range(6,(numflows+6)):
1066 mac3 = idx / 255
1067 mac4 = idx % 255
1068 str_mac3 = "%0.2x" % mac3
1069 str_mac4 = "%0.2x" % mac4
1070 srcMac = '00:01:'+str_mac3+':'+str_mac4+':00:00'
1071 dstMac = '00:02:'+str_mac3+':'+str_mac4+':00:00'
1072 srcSwitch = '00:00:00:00:00:00:10:00'
1073 dstSwitch = '00:00:00:00:00:00:10:00'
1074 srcPort = 1
1075 dstPort = 2
1076
1077 intent = {'intent_id': '%d' %(i),'intent_type':'shortest_intent_type','intent_op':flowtype,'srcSwitch':srcSwitch,'srcPort':srcPort,'srcMac':srcMac,'dstSwitch':dstSwitch,'dstPort':dstPort,'dstMac':dstMac}
1078 intents.append(intent)
1079 idx = idx + 1
1080 f.write('''s=''')
1081 f.write(json.dumps(intents, sort_keys = True))
1082 f.write('''\nr = requests.post(url, data=json.dumps(s), headers = headers)''')
1083 #f.flush()
1084 #subprocess.Popen(flowdef, stdout=f, stderr=f, shell=True)
1085 #f.close()
1086 os.system("chmod a+x "+flowdef+"/"+flowtype+"_"+str(numflows)+".py")
1087
1088 return main.TRUE
1089
1090 def getFile(self, numflows, ip, directory, flowparams):
1091 main.log.info("GETTING FILES FROM TEST STATION: "+str(ip))
1092 #for i in range(0,3):
1093 print str(numflows) + " "+str(flowparams[numflows])
1094 self.handle.sendline("scp admin@10.128.7.7:/home/admin/TestON/tests/OnosFlowPerf/add_"+str(flowparams[numflows])+".py admin@10.128.5.51:/home/admin/ONOS/scripts/" )
1095
1096 self.handle.sendline("scp admin@10.128.7.7:/home/admin/TestON/tests/OnosFlowPerf/remove_"+str(flowparams[numflows])+".py admin@10.128.5.51:/home/admin/ONOS/scripts/" )
1097
1098 return main.TRUE
1099
1100 def printPerfResults(self, flowtype, numflows, stime):
1101 import datetime
1102 self.handle.sendline("")
1103 self.handle.expect("\$")
1104 for (i,j) in zip(numflows,stime):
1105 startTime=datetime.datetime.fromtimestamp(j)
1106 tshark_file=open("/tmp/tdump_"+flowtype+"_"+str(i)+".txt",'r')
1107 allFlowmods=tshark_file.readlines()
1108 time.sleep(5)
1109 firstFlowmod=allFlowmods[0]
1110 lastBarrierReply=allFlowmods[-1]
1111 #self.handle.sendline("")
1112 #self.handle.expect("\$")
1113 #self.handle.sendline("head -1 /tmp/tdump_"+flowtype+"_"+str(i)+".txt")
1114 #self.handle.expect("\(CSM\)")
1115 #firstFlowmod=self.handle.before
1116 #firstFlowmod=self.execute(cmd="head -1 /tmp/tdump_"+flowtype+"_"+str(i)+".txt",prompt="\$",timeout=10)
1117 #lastBarrierReply=self.execute(cmd="tail -n 1 /tmp/tdump_"+flowtype+"_"+str(i)+".txt",prompt="\$",timeout=10)
1118 firstFlowmodSplit=firstFlowmod.split()
1119 firstFlowmodTS=datetime.datetime.fromtimestamp(float(firstFlowmodSplit[0]))
1120 lastBarrierSplit=lastBarrierReply.split()
1121 lastBarrierTS=datetime.datetime.fromtimestamp(float(lastBarrierSplit[0]))
1122 main.log.report("Number of Flows: " + str(i))
1123 #main.log.info("Add Flow Start Time: " + str(startTime))
1124 main.log.report("First Flow mod seen after: " + str(float(datetime.timedelta.total_seconds(firstFlowmodTS-startTime)*1000))+"ms")
1125 main.log.report("Last Barrier Reply seen after: " + str(float(datetime.timedelta.total_seconds(lastBarrierTS-startTime)*1000))+"ms\n")
1126 main.log.report("Total Flow Setup Delay(from first flowmod): " + str(float(datetime.timedelta.total_seconds(lastBarrierTS-firstFlowmodTS)*1000))+"ms")
1127 main.log.report("Total Flow Setup Delay(from start): " + str(float(datetime.timedelta.total_seconds(lastBarrierTS-startTime)*1000))+"ms\n")
1128 main.log.report("Flow Setup Rate (using first flowmod TS): " + str(int(1000/datetime.timedelta.total_seconds(lastBarrierTS-firstFlowmodTS)))+" flows/sec")
1129 main.log.report("Flow Setup Rate (using start time): " + str(int(1000/datetime.timedelta.total_seconds(lastBarrierTS-startTime)))+" flows/sec")
1130 print "*****************************************************************"
1131 #main.log.info("first: " + str(firstFlowmod))
1132 #main.log.info(firstFlowmodSplit)
1133 #main.log.info("last: " + str(lastBarrierReply))
1134 tshark_file.close()
1135 return main.TRUE
1136
1137 def isup(self):
1138 '''
1139 A more complete check to see if ONOS is up and running properly.
1140 First, it checks if the process is up.
1141 Second, it reads the logs for "Exception: Connection refused"
1142 Third, it makes sure the logs are actually moving.
1143 returns TRUE/FALSE accordingly.
1144 '''
1145 try:
1146 self.execute(cmd="\n",prompt="\$",timeout=10)
1147 self.handle.sendline("cd "+self.home)
1148 response = self.execute(cmd= "./onos.sh core status ",prompt="running",timeout=10)
1149 self.execute(cmd="\n",prompt="\$",timeout=10)
1150 tail1 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
1151 time.sleep(10)
1152 self.execute(cmd="\n",prompt="\$",timeout=10)
1153 tail2 = self.execute(cmd="tail " + self.home + "/onos-logs/onos.*.log",prompt="\$",timeout=10)
1154 pattern = '(.*)1 instance(.*)'
1155 patternUp = 'Sending LLDP out'
1156 pattern2 = '(.*)Exception: Connection refused(.*)'
1157 # if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."):
1158
1159 if re.search(pattern, response):
1160 if re.search(patternUp,tail2):
1161 main.log.info(self.name + ": ONOS process is running...")
1162 if tail1 == tail2:
1163 main.log.error(self.name + ": ONOS is frozen...")#logs aren't moving
1164 return main.FALSE
1165 elif re.search( pattern2,tail1 ):
1166 main.log.info(self.name + ": Connection Refused found in onos log")
1167 return main.FALSE
1168 elif re.search( pattern2,tail2 ):
1169 main.log.info(self.name + ": Connection Refused found in onos log")
1170 return main.FALSE
1171 else:
1172 main.log.info(self.name + ": Onos log is moving! It's looking good!")
1173 return main.TRUE
1174 else:
1175 main.log.info(self.name + ": ONOS not yet sending out LLDP messages")
1176 return main.FALSE
1177 else:
1178 main.log.error(self.name + ": ONOS process not running...")
1179 return main.FALSE
1180 except pexpect.EOF:
1181 main.log.error(self.name + ": EOF exception found")
1182 main.log.error(self.name + ": " + self.handle.before)
1183 main.cleanup()
1184 main.exit()
1185 except:
1186 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1187 main.log.error( traceback.print_exc() )
1188 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
1189 main.cleanup()
1190 main.exit()
1191
1192 def sendline(self, cmd):
1193 self.handle.sendline(cmd)