blob: 9c225f1d517e66a5316a4e97e45e34b72f13292a [file] [log] [blame]
Jon Hall05b2b432014-10-08 19:53:25 -04001#!/usr/bin/env python
andrewonlabe8e56fd2014-10-09 17:12:44 -04002
Jon Hall05b2b432014-10-08 19:53:25 -04003'''
andrewonlabe8e56fd2014-10-09 17:12:44 -04004This driver interacts with ONOS bench, the OSGi platform
5that configures the ONOS nodes. (aka ONOS-next)
6
7Please follow the coding style demonstrated by existing
8functions and document properly.
9
10If you are a contributor to the driver, please
11list your email here for future contact:
12
13jhall@onlab.us
14andrew@onlab.us
15
16OCT 9 2014
17
Jon Hall05b2b432014-10-08 19:53:25 -040018'''
andrewonlabe8e56fd2014-10-09 17:12:44 -040019
andrewonlab7735d852014-10-09 13:02:47 -040020import sys
Jon Hall05b2b432014-10-08 19:53:25 -040021import time
22import pexpect
23import re
24import traceback
andrewonlab7735d852014-10-09 13:02:47 -040025import os.path
Jon Hall05b2b432014-10-08 19:53:25 -040026sys.path.append("../")
27from drivers.common.clidriver import CLI
28
29class OnosDriver(CLI):
30
31 def __init__(self):
32 super(CLI, self).__init__()
33
34 def connect(self,**connectargs):
35 '''
36 Creates ssh handle for ONOS "bench".
37 '''
38 try:
39 for key in connectargs:
40 vars(self)[key] = connectargs[key]
41 self.home = "~/ONOS"
42 for key in self.options:
43 if key == "home":
44 self.home = self.options['home']
45 break
46
47
48 self.name = self.options['name']
Jon Hallea7818b2014-10-09 14:30:59 -040049 self.handle = super(OnosDriver,self).connect(
50 user_name = self.user_name,
51 ip_address = self.ip_address,
52 port = self.port,
53 pwd = self.pwd,
54 home = self.home)
Jon Hallea7818b2014-10-09 14:30:59 -040055
56 self.handle.sendline("cd "+ self.home)
57 self.handle.expect("\$")
Jon Hall05b2b432014-10-08 19:53:25 -040058 if self.handle:
59 return self.handle
60 else :
61 main.log.info("NO ONOS HANDLE")
62 return main.FALSE
63 except pexpect.EOF:
64 main.log.error(self.name + ": EOF exception found")
65 main.log.error(self.name + ": " + self.handle.before)
66 main.cleanup()
67 main.exit()
68 except:
69 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
70 main.log.error( traceback.print_exc() )
71 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
72 main.cleanup()
73 main.exit()
74
75 def disconnect(self):
76 '''
77 Called when Test is complete to disconnect the ONOS handle.
78 '''
79 response = ''
80 try:
81 self.handle.sendline("exit")
82 self.handle.expect("closed")
83 except pexpect.EOF:
84 main.log.error(self.name + ": EOF exception found")
85 main.log.error(self.name + ": " + self.handle.before)
86 except:
87 main.log.error(self.name + ": Connection failed to the host")
88 response = main.FALSE
89 return response
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -040090
91 def onos_package(self):
92 '''
93 Produce a self-contained tar.gz file that can be deployed
94 and executed on any platform with Java 7 JRE.
95 '''
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -040096
97 try:
98 self.handle.sendline("onos-package")
Jon Hallea7818b2014-10-09 14:30:59 -040099 self.handle.expect("onos-package")
andrewonlab0748d2a2014-10-09 13:24:17 -0400100 self.handle.expect("tar.gz",timeout=10)
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400101 handle = str(self.handle.before)
102 main.log.info("onos-package command returned: "+
103 handle)
andrewonlab0748d2a2014-10-09 13:24:17 -0400104 #As long as the sendline does not time out,
105 #return true. However, be careful to interpret
106 #the results of the onos-package command return
107 return main.TRUE
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400108
andrewonlab7735d852014-10-09 13:02:47 -0400109 except pexpect.EOF:
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400110 main.log.error(self.name + ": EOF exception found")
111 main.log.error(self.name + ": " + self.handle.before)
112 except:
113 main.log.error("Failed to package ONOS")
114 main.cleanup()
115 main.exit()
116
Jon Hallde9d9aa2014-10-08 20:36:02 -0400117 def clean_install(self):
118 '''
119 Runs mvn clean install in the root of the ONOS directory.
120 This will clean all ONOS artifacts then compile each module
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400121
Jon Hallde9d9aa2014-10-08 20:36:02 -0400122 Returns: main.TRUE on success
123 On Failure, exits the test
124 '''
125 try:
Jon Hallea7818b2014-10-09 14:30:59 -0400126 main.log.info("Running 'mvn clean install' on " + str(self.name) +
127 ". This may take some time.")
128 self.handle.sendline("cd "+ self.home)
129 self.handle.expect("\$")
130
131 self.handle.sendline("\n")
132 self.handle.expect("\$")
Jon Hallde9d9aa2014-10-08 20:36:02 -0400133 self.handle.sendline("mvn clean install")
Jon Hallea7818b2014-10-09 14:30:59 -0400134 self.handle.expect("mvn clean install")
Jon Hallde9d9aa2014-10-08 20:36:02 -0400135 while 1:
136 i=self.handle.expect([
137 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s\
138 Runtime\sEnvironment\sto\scontinue',
139 'BUILD\sFAILURE',
140 'BUILD\sSUCCESS',
141 'ONOS\$',
142 pexpect.TIMEOUT],timeout=600)
143 if i == 0:
144 main.log.error(self.name + ":There is insufficient memory \
145 for the Java Runtime Environment to continue.")
146 #return main.FALSE
147 main.cleanup()
148 main.exit()
149 if i == 1:
150 main.log.error(self.name + ": Build failure!")
151 #return main.FALSE
152 main.cleanup()
153 main.exit()
154 elif i == 2:
155 main.log.info(self.name + ": Build success!")
156 elif i == 3:
157 main.log.info(self.name + ": Build complete")
Jon Hallf8ef52c2014-10-09 19:37:33 -0400158 #Print the build time
159 for line in self.handle.before.splitlines():
160 if "Total time:" in line:
161 main.log.info(line)
Jon Hallea7818b2014-10-09 14:30:59 -0400162 self.handle.sendline("\n")
Jon Hallde9d9aa2014-10-08 20:36:02 -0400163 self.handle.expect("\$", timeout=60)
164 return main.TRUE
165 elif i == 4:
166 main.log.error(self.name + ": mvn clean install TIMEOUT!")
167 #return main.FALSE
168 main.cleanup()
169 main.exit()
170 else:
171 main.log.error(self.name + ": unexpected response from \
172 mvn clean install")
173 #return main.FALSE
174 main.cleanup()
175 main.exit()
176 except pexpect.EOF:
177 main.log.error(self.name + ": EOF exception found")
178 main.log.error(self.name + ": " + self.handle.before)
179 main.cleanup()
180 main.exit()
181 except:
182 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
183 main.log.error( traceback.print_exc() )
184 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
185 main.cleanup()
186 main.exit()
Jon Hallacabffd2014-10-09 12:36:53 -0400187
188 def git_pull(self, comp1=""):
189 '''
190 Assumes that "git pull" works without login
191
192 This function will perform a git pull on the ONOS instance.
193 If used as git_pull("NODE") it will do git pull + NODE. This is
194 for the purpose of pulling from other nodes if necessary.
195
196 Otherwise, this function will perform a git pull in the
197 ONOS repository. If it has any problems, it will return main.ERROR
198 If it successfully does a git_pull, it will return a 1.
199 If it has no updates, it will return a 0.
200
201 '''
202 try:
203 # main.log.info(self.name + ": Stopping ONOS")
204 #self.stop()
205 self.handle.sendline("cd " + self.home)
206 self.handle.expect("ONOS\$")
207 if comp1=="":
208 self.handle.sendline("git pull")
209 else:
210 self.handle.sendline("git pull " + comp1)
211
212 uptodate = 0
213 i=self.handle.expect(['fatal',
214 'Username\sfor\s(.*):\s',
215 '\sfile(s*) changed,\s',
216 'Already up-to-date',
217 'Aborting',
218 'You\sare\snot\scurrently\son\sa\sbranch',
219 'You\sasked\sme\sto\spull\swithout\stelling\sme\swhich\sbranch\syou',
220 'Pull\sis\snot\spossible\sbecause\syou\shave\sunmerged\sfiles',
221 pexpect.TIMEOUT],
222 timeout=300)
223 #debug
224 #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after))
225 if i==0:
226 main.log.error(self.name + ": Git pull had some issue...")
227 return main.ERROR
228 elif i==1:
229 main.log.error(self.name + ": Git Pull Asking for username. ")
230 return main.ERROR
231 elif i==2:
232 main.log.info(self.name + ": Git Pull - pulling repository now")
233 self.handle.expect("ONOS\$", 120)
234 return 0
235 elif i==3:
236 main.log.info(self.name + ": Git Pull - Already up to date")
237 return 1
238 elif i==4:
239 main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?")
240 return main.ERROR
241 elif i==5:
242 main.log.info(self.name + ": Git Pull - You are not currently on a branch so git pull failed!")
243 return main.ERROR
244 elif i==6:
245 main.log.info(self.name + ": Git Pull - You have not configured an upstream branch to pull from. Git pull failed!")
246 return main.ERROR
247 elif i==7:
248 main.log.info(self.name + ": Git Pull - Pull is not possible because you have unmerged files.")
249 return main.ERROR
250 elif i==8:
251 main.log.error(self.name + ": Git Pull - TIMEOUT")
252 main.log.error(self.name + " Response was: " + str(self.handle.before))
253 return main.ERROR
254 else:
255 main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors")
256 return main.ERROR
257 except pexpect.EOF:
258 main.log.error(self.name + ": EOF exception found")
259 main.log.error(self.name + ": " + self.handle.before)
260 main.cleanup()
261 main.exit()
262 except:
263 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
264 main.log.error( traceback.print_exc() )
265 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
266 main.cleanup()
267 main.exit()
268
269 def git_checkout(self, branch="master"):
270 '''
271 Assumes that "git pull" works without login
272
273 This function will perform a git git checkout on the ONOS instance.
274 If used as git_checkout("branch") it will do git checkout of the "branch".
275
276 Otherwise, this function will perform a git checkout of the master
277 branch of the ONOS repository. If it has any problems, it will return
278 main.ERROR.
279 If the branch was already the specified branch, or the git checkout was
280 successful then the function will return main.TRUE.
281
282 '''
283 try:
284 # main.log.info(self.name + ": Stopping ONOS")
285 #self.stop()
286 self.handle.sendline("cd " + self.home)
287 self.handle.expect("ONOS\$")
288 if branch != 'master':
289 #self.handle.sendline('git stash')
290 #self.handle.expect('ONOS\$')
291 #print "After issuing git stash cmnd: ", self.handle.before
292 cmd = "git checkout "+branch
293 print "checkout cmd = ", cmd
294 self.handle.sendline(cmd)
295 uptodate = 0
296 i=self.handle.expect(['fatal',
297 'Username\sfor\s(.*):\s',
298 'Already\son\s\'',
299 'Switched\sto\sbranch\s\'',
300 pexpect.TIMEOUT],timeout=60)
301 else:
302 #self.handle.sendline('git stash apply')
303 #self.handle.expect('ONOS\$')
304 #print "After issuing git stash apply cmnd: ", self.handle.before
305 cmd = "git checkout "+branch
306 print "checkout cmd = ", cmd
307 self.handle.sendline(cmd)
308 uptodate = 0
309 switchedToMaster = 0
310 i=self.handle.expect(['fatal',
311 'Username\sfor\s(.*):\s',
312 'Already\son\s\'master\'',
313 'Switched\sto\sbranch\s\'master\'',
314 pexpect.TIMEOUT],timeout=60)
315
316
317 if i==0:
318 main.log.error(self.name + ": Git checkout had some issue...")
319 return main.ERROR
320 elif i==1:
321 main.log.error(self.name + ": Git checkout Asking for username!!! Bad!")
322 return main.ERROR
323 elif i==2:
324 main.log.info(self.name + ": Git Checkout %s : Already on this branch" %branch)
325 self.handle.expect("ONOS\$")
326 print "after checkout cmd = ", self.handle.before
327 switchedToMaster = 1
328 return main.TRUE
329 elif i==3:
330 main.log.info(self.name + ": Git checkout %s - Switched to this branch" %branch)
331 self.handle.expect("ONOS\$")
332 print "after checkout cmd = ", self.handle.before
333 switchedToMaster = 1
334 return main.TRUE
335 elif i==4:
336 main.log.error(self.name + ": Git Checkout- TIMEOUT")
337 main.log.error(self.name + " Response was: " + str(self.handle.before))
338 return main.ERROR
339 else:
340 main.log.error(self.name + ": Git Checkout - Unexpected response, check for pull errors")
341 return main.ERROR
342
343 except pexpect.EOF:
344 main.log.error(self.name + ": EOF exception found")
345 main.log.error(self.name + ": " + self.handle.before)
346 main.cleanup()
347 main.exit()
348 except:
349 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
350 main.log.error( traceback.print_exc() )
351 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
352 main.cleanup()
353 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400354
355 def set_cell(self, cellname):
356 '''
357 Calls 'cell <name>' to set the environment variables on ONOSbench
358 '''
359 try:
360 if not cellname:
361 main.log.error("Must define cellname")
362 main.cleanup()
363 main.exit()
364 else:
365 self.handle.sendline("cell "+str(cellname))
366 #Expect the cellname in the ONOS_CELL variable.
367 #Note that this variable name is subject to change
368 # and that this driver will have to change accordingly
369 self.handle.expect("ONOS_CELL="+str(cellname))
370 handle_before = self.handle.before
371 handle_after = self.handle.after
andrewonlabc03bf6c2014-10-09 14:56:18 -0400372 #Get the rest of the handle
373 self.handle.sendline("")
374 self.handle.expect("\$")
375 handle_more = self.handle.before
andrewonlab95ca1462014-10-09 14:04:24 -0400376
377 main.log.info("Cell call returned: "+handle_before+
andrewonlabc03bf6c2014-10-09 14:56:18 -0400378 handle_after + handle_more)
andrewonlab95ca1462014-10-09 14:04:24 -0400379
380 return main.TRUE
381
382 except pexpect.EOF:
383 main.log.error(self.name + ": EOF exception found")
384 main.log.error(self.name + ": " + self.handle.before)
385 main.cleanup()
386 main.exit()
387 except:
388 main.log.info(self.name+" ::::::")
389 main.log.error( traceback.print_exc())
390 main.log.info(self.name+" ::::::")
391 main.cleanup()
392 main.exit()
393
andrewonlabc03bf6c2014-10-09 14:56:18 -0400394 def verify_cell(self):
395 '''
396 Calls 'onos-verify-cell' to check for cell installation
397 '''
andrewonlab8d0d7d72014-10-09 16:33:15 -0400398 #TODO: Add meaningful expect value
399
andrewonlabc03bf6c2014-10-09 14:56:18 -0400400 try:
401 #Clean handle by sending empty and expecting $
402 self.handle.sendline("")
403 self.handle.expect("\$")
404 self.handle.sendline("onos-verify-cell")
405 self.handle.expect("\$")
406 handle_before = self.handle.before
407 handle_after = self.handle.after
408 #Get the rest of the handle
409 self.handle.sendline("")
410 self.handle.expect("\$")
411 handle_more = self.handle.before
412
413 main.log.info("Verify cell returned: "+handle_before+
414 handle_after + handle_more)
415
416 return main.TRUE
Jon Hall7993bfc2014-10-09 16:30:14 -0400417 except pexpect.EOF:
418 main.log.error(self.name + ": EOF exception found")
419 main.log.error(self.name + ": " + self.handle.before)
420 main.cleanup()
421 main.exit()
422 except:
423 main.log.info(self.name+" ::::::")
424 main.log.error( traceback.print_exc())
425 main.log.info(self.name+" ::::::")
426 main.cleanup()
427 main.exit()
428
andrewonlab05e362f2014-10-10 00:40:57 -0400429 def onos_cli(self, ONOS_ip, cmdstr):
430 '''
431 Uses 'onos' command to send various ONOS CLI arguments.
432 Required:
433 * ONOS_ip: specify the ip of the cell machine
434 * cmdstr: specify the command string
435 '''
436 try:
437 if not ONOS_ip:
438 main.log.error("You must specify the IP address")
439 return main.FALSE
440 if not cmdstr:
441 main.log.error("You must specify the command string")
442 return main.FALSE
443
444 cmdstr = str(cmdstr)
445 self.handle.sendline("")
446 self.handle.expect("\$")
447
448 self.handle.sendline("onos -w " + ONOS_ip + " " + cmdstr)
449 self.handle.expect("\$")
450
451 handle_before = str(self.handle.before)
452 handle_after = str(self.handle.after)
453
454 self.handle.sendline("")
455 self.handle.expect("\$")
456 handle_more = str(self.handle.before)
457
458 main.log.info("Command sent successfully")
459
460 return_string = handle_before + handle_after + handle_more
461
462 return return_string
463
464 except pexpect.EOF:
465 main.log.error(self.name + ": EOF exception found")
466 main.log.error(self.name + ": " + self.handle.before)
467 main.cleanup()
468 main.exit()
469 except:
470 main.log.info(self.name+" ::::::")
471 main.log.error( traceback.print_exc())
472 main.log.info(self.name+" ::::::")
473 main.cleanup()
474 main.exit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400475
476 def onos_install(self, options="-f", node = ""):
477 '''
478 Installs ONOS bits on the designated cell machine.
479 If -f option is provided, it also forces an uninstall.
480 Presently, install also includes onos-push-bits and
481 onos-config within.
482 The node option allows you to selectively only push the jar
483 files to certain onos nodes
484
485 Returns: main.TRUE on success and main.FALSE on failure
486 '''
487 try:
488 self.handle.sendline("onos-install " + options + " " + node)
489 self.handle.expect("onos-install ")
490 #NOTE: this timeout may need to change depending on the network and size of ONOS
491 i=self.handle.expect(["Network\sis\sunreachable",
492 "onos\sstart/running,\sprocess",
493 pexpect.TIMEOUT],timeout=60)
494
495
496 if i == 0:
497 main.log.warn("Network is unreachable")
498 return main.FALSE
499 elif i == 1:
500 main.log.info("ONOS was installed on the VM and started")
501 return main.TRUE
502 elif i == 2:
503 main.log.info("Installation of ONOS on the VM timed out")
504 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -0400505
506 except pexpect.EOF:
507 main.log.error(self.name + ": EOF exception found")
508 main.log.error(self.name + ": " + self.handle.before)
509 main.cleanup()
510 main.exit()
511 except:
512 main.log.info(self.name+" ::::::")
513 main.log.error( traceback.print_exc())
514 main.log.info(self.name+" ::::::")
515 main.cleanup()
516 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400517
andrewonlab8d0d7d72014-10-09 16:33:15 -0400518 def onos_start(self, node_ip):
519 '''
520 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400521 This command is a remote management of the ONOS upstart daemon
andrewonlab8d0d7d72014-10-09 16:33:15 -0400522 '''
523
524 try:
525 self.handle.sendline("")
526 self.handle.expect("\$")
527 self.handle.sendline("onos-service "+str(node_ip)+
528 " start")
529 i = self.handle.expect([
530 "Job\sis\salready\srunning",
531 "start/running",
532 "Unknown\sinstance",
533 pexpect.TIMEOUT],timeout=60)
534
535 if i == 0:
536 main.log.info("Service is already running")
537 return main.TRUE
538 elif i == 1:
539 main.log.info("ONOS service started")
540 return main.TRUE
541 else:
542 main.log.error("ONOS service failed to start")
543 main.cleanup()
544 main.exit()
andrewonlab8d0d7d72014-10-09 16:33:15 -0400545 except pexpect.EOF:
546 main.log.error(self.name + ": EOF exception found")
547 main.log.error(self.name + ": " + self.handle.before)
548 main.cleanup()
549 main.exit()
550 except:
551 main.log.info(self.name+" ::::::")
552 main.log.error( traceback.print_exc())
553 main.log.info(self.name+" ::::::")
554 main.cleanup()
555 main.exit()
556
andrewonlab2b30bd32014-10-09 16:48:55 -0400557 def onos_stop(self, node_ip):
558 '''
559 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400560 This command is a remote management of the ONOS upstart daemon
andrewonlab2b30bd32014-10-09 16:48:55 -0400561 '''
562 try:
563 self.handle.sendline("")
564 self.handle.expect("\$")
565 self.handle.sendline("onos-service "+str(node_ip)+
566 " stop")
567 i = self.handle.expect([
568 "stop/waiting",
569 "Unknown\sinstance",
570 pexpect.TIMEOUT],timeout=60)
571
572 if i == 0:
573 main.log.info("ONOS service stopped")
574 return main.TRUE
575 elif i == 1:
576 main.log.info("Unknown ONOS instance specified: "+
577 str(node_ip))
578 return main.FALSE
579 else:
580 main.log.error("ONOS service failed to stop")
581 return main.FALSE
582
583 except pexpect.EOF:
584 main.log.error(self.name + ": EOF exception found")
585 main.log.error(self.name + ": " + self.handle.before)
586 main.cleanup()
587 main.exit()
588 except:
589 main.log.info(self.name+" ::::::")
590 main.log.error( traceback.print_exc())
591 main.log.info(self.name+" ::::::")
592 main.cleanup()
593 main.exit()
594
andrewonlabc8d47972014-10-09 16:52:36 -0400595 def onos_uninstall(self):
596 '''
597 Calls the command: 'onos-uninstall'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400598 Uninstalls ONOS from the designated cell machine, stopping
599 if needed
andrewonlabc8d47972014-10-09 16:52:36 -0400600 '''
601 try:
602 self.handle.sendline("")
603 self.handle.expect("\$")
604 self.handle.sendline("onos-uninstall")
605 self.handle.expect("\$")
606
andrewonlab84727452014-10-09 18:15:36 -0400607 main.log.info("ONOS cell machine was uninstalled")
andrewonlabc8d47972014-10-09 16:52:36 -0400608 #onos-uninstall command does not return any text
609 return main.TRUE
610
611 except pexpect.EOF:
612 main.log.error(self.name + ": EOF exception found")
613 main.log.error(self.name + ": " + self.handle.before)
614 main.cleanup()
615 main.exit()
616 except:
617 main.log.info(self.name+" ::::::")
618 main.log.error( traceback.print_exc())
619 main.log.info(self.name+" ::::::")
620 main.cleanup()
621 main.exit()
andrewonlab2b30bd32014-10-09 16:48:55 -0400622
andrewonlabe8e56fd2014-10-09 17:12:44 -0400623 def onos_kill(self, node_ip):
624 '''
625 Calls the command: 'onos-kill [<node-ip>]'
626 "Remotely, and unceremoniously kills the ONOS instance running on
627 the specified cell machine" - Tom V
628 '''
629
630 try:
631 self.handle.sendline("")
632 self.handle.expect("\$")
633 self.handle.sendline("onos-kill " + str(node_ip))
634 i = self.handle.expect([
635 "\$",
636 "No\sroute\sto\shost",
637 "password:",
638 pexpect.TIMEOUT], timeout=20)
639
640 if i == 0:
641 main.log.info("ONOS instance "+str(node_ip)+" was killed")
642 return main.TRUE
643 elif i == 1:
644 main.log.info("No route to host")
645 return main.FALSE
646 elif i == 2:
647 main.log.info("Passwordless login for host: "+str(node_ip)+
648 " not configured")
649 return main.FALSE
650 else:
651 main.log.info("ONOS instasnce was not killed")
652 return main.FALSE
653
654 except pexpect.EOF:
655 main.log.error(self.name + ": EOF exception found")
656 main.log.error(self.name + ": " + self.handle.before)
657 main.cleanup()
658 main.exit()
659 except:
660 main.log.info(self.name+" ::::::")
661 main.log.error( traceback.print_exc())
662 main.log.info(self.name+" ::::::")
663 main.cleanup()
664 main.exit()
665
Jon Hall7993bfc2014-10-09 16:30:14 -0400666 def isup(self, node = ""):
667 '''
668 Run's onos-wait-for-start which only returns once ONOS is at run level 100(ready for use)
andrewonlab8d0d7d72014-10-09 16:33:15 -0400669
Jon Hall7993bfc2014-10-09 16:30:14 -0400670 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
671 '''
672 try:
673 self.handle.sendline("onos-wait-for-start " + node )
674 self.handle.expect("onos-wait-for-start")
675 #NOTE: this timeout is arbitrary"
676 i = self.handle.expect(["\$", pexpect.TIMEOUT], timeout = 120)
677 if i == 0:
678 main.log.info(self.name + ": " + node + " is up")
679 return main.TRUE
680 elif i == 1:
681 #NOTE: since this function won't return until ONOS is ready,
682 # we will kill it on timeout
683 self.handle.sendline("\003") #Control-C
684 self.handle.expect("\$")
685 return main.FALSE
686 except pexpect.EOF:
687 main.log.error(self.name + ": EOF exception found")
688 main.log.error(self.name + ": " + self.handle.before)
689 main.cleanup()
690 main.exit()
691 except:
692 main.log.info(self.name+" ::::::")
693 main.log.error( traceback.print_exc())
694 main.log.info(self.name+" ::::::")
695 main.cleanup()
696 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -0400697
698