blob: 263bc1f8451d2cbd0610188e1d79eb39d85ae3d4 [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
andrewonlab94282092014-10-10 13:00:11 -0400355 def create_cell_file(self, bench_ip, file_name, mn_ip_addrs, *onos_ip_addrs):
356 '''
357 Creates a cell file based on arguments
358 Required:
359 * Bench IP address (bench_ip)
360 - Needed to copy the cell file over
361 * File name of the cell file (file_name)
362 * Mininet IP address (mn_ip_addrs)
363 - Note that only 1 ip address is
364 supported currently
365 * ONOS IP addresses (onos_ip_addrs)
366 - Must be passed in as last arguments
367
368 NOTE: Assumes cells are located at:
369 ~/<self.home>/tools/test/cells/
370 '''
371
372 #Variable initialization
373 cell_directory = self.home + "/tools/test/cells/"
374 #We want to create the cell file in the dependencies directory
375 #of TestON first, then copy over to ONOS bench
376 temp_directory = "/tmp/"
377 #Create the cell file in the directory for writing (w+)
378 cell_file = open(temp_directory+file_name , 'w+')
379
380 #Feature string is pre-defined environment variable
381 #that is required in the file
382 feature_string = "export ONOS_FEATURES=webconsole,onos-api,"+\
383 "onos-core-trivial,onos-cli,onos-openflow,"+\
384 "onos-app-fwd,onos-app-mobility,onos-app-tvue,"+\
385 "onos-app-proxyarp"
386 mn_string = "export OCN="
387 onos_string = "export OC"
388 temp_count = 1
389
390 #Create ONOS_NIC ip address prefix
391 temp_onos_ip = onos_ip_addrs[0]
392 temp_list = []
393 temp_list = temp_onos_ip.split(".")
394 #Omit last element of list
395 temp_list = temp_list[:-1]
396 #Structure the nic string ip
397 nic_addr = ".".join(temp_list) + ".*\n"
398 onos_nic_string = "export ONOS_NIC="+nic_addr
399
400 try:
401 #Start writing to file
402 cell_file.write(feature_string + "\n")
403 cell_file.write(onos_nic_string)
404 cell_file.write(mn_string +"'"+ mn_ip_addrs +"'"+ "\n")
405
406 for arg in onos_ip_addrs:
407 #For each argument in onos_ip_addrs, write to file
408 #Output should look like the following:
409 # export OC1='10.128.20.11'
410 # export OC2='10.128.20.12'
411 cell_file.write(onos_string + str(temp_count) +
412 "=" + "'" + arg + "'" + "\n" )
413 temp_count = temp_count + 1
414
415 cell_file.close()
416
417 #We use os.system to send the command to TestON cluster
418 #to account for the case in which TestON is not located
419 #on the same cluster as the ONOS bench
420 #Note that even if TestON is located on the same cluster
421 #as ONOS bench, you must setup passwordless ssh
422 #in order to automate the test.
423 os.system("scp "+temp_directory+file_name+
424 " admin@"+bench_ip+":"+cell_directory)
425
426 except pexpect.EOF:
427 main.log.error(self.name + ": EOF exception found")
428 main.log.error(self.name + ": " + self.handle.before)
429 main.cleanup()
430 main.exit()
431 except:
432 main.log.info(self.name + ":::::::::")
433 main.log.error( traceback.print_exc() )
434 main.log.info(":::::::")
435 main.cleanup()
436 main.exit()
437
andrewonlab95ca1462014-10-09 14:04:24 -0400438 def set_cell(self, cellname):
439 '''
440 Calls 'cell <name>' to set the environment variables on ONOSbench
441 '''
442 try:
443 if not cellname:
444 main.log.error("Must define cellname")
445 main.cleanup()
446 main.exit()
447 else:
448 self.handle.sendline("cell "+str(cellname))
449 #Expect the cellname in the ONOS_CELL variable.
450 #Note that this variable name is subject to change
451 # and that this driver will have to change accordingly
452 self.handle.expect("ONOS_CELL="+str(cellname))
453 handle_before = self.handle.before
454 handle_after = self.handle.after
andrewonlabc03bf6c2014-10-09 14:56:18 -0400455 #Get the rest of the handle
456 self.handle.sendline("")
457 self.handle.expect("\$")
458 handle_more = self.handle.before
andrewonlab95ca1462014-10-09 14:04:24 -0400459
460 main.log.info("Cell call returned: "+handle_before+
andrewonlabc03bf6c2014-10-09 14:56:18 -0400461 handle_after + handle_more)
andrewonlab95ca1462014-10-09 14:04:24 -0400462
463 return main.TRUE
464
465 except pexpect.EOF:
466 main.log.error(self.name + ": EOF exception found")
467 main.log.error(self.name + ": " + self.handle.before)
468 main.cleanup()
469 main.exit()
470 except:
471 main.log.info(self.name+" ::::::")
472 main.log.error( traceback.print_exc())
473 main.log.info(self.name+" ::::::")
474 main.cleanup()
475 main.exit()
476
andrewonlabc03bf6c2014-10-09 14:56:18 -0400477 def verify_cell(self):
478 '''
479 Calls 'onos-verify-cell' to check for cell installation
480 '''
andrewonlab8d0d7d72014-10-09 16:33:15 -0400481 #TODO: Add meaningful expect value
482
andrewonlabc03bf6c2014-10-09 14:56:18 -0400483 try:
484 #Clean handle by sending empty and expecting $
485 self.handle.sendline("")
486 self.handle.expect("\$")
487 self.handle.sendline("onos-verify-cell")
488 self.handle.expect("\$")
489 handle_before = self.handle.before
490 handle_after = self.handle.after
491 #Get the rest of the handle
492 self.handle.sendline("")
493 self.handle.expect("\$")
494 handle_more = self.handle.before
495
496 main.log.info("Verify cell returned: "+handle_before+
497 handle_after + handle_more)
498
499 return main.TRUE
Jon Hall7993bfc2014-10-09 16:30:14 -0400500 except pexpect.EOF:
501 main.log.error(self.name + ": EOF exception found")
502 main.log.error(self.name + ": " + self.handle.before)
503 main.cleanup()
504 main.exit()
505 except:
506 main.log.info(self.name+" ::::::")
507 main.log.error( traceback.print_exc())
508 main.log.info(self.name+" ::::::")
509 main.cleanup()
510 main.exit()
511
andrewonlab05e362f2014-10-10 00:40:57 -0400512 def onos_cli(self, ONOS_ip, cmdstr):
513 '''
514 Uses 'onos' command to send various ONOS CLI arguments.
515 Required:
516 * ONOS_ip: specify the ip of the cell machine
andrewonlab94282092014-10-10 13:00:11 -0400517 * cmdstr: specify the command string to send
andrewonlab05e362f2014-10-10 00:40:57 -0400518 '''
519 try:
520 if not ONOS_ip:
521 main.log.error("You must specify the IP address")
522 return main.FALSE
523 if not cmdstr:
524 main.log.error("You must specify the command string")
525 return main.FALSE
526
527 cmdstr = str(cmdstr)
528 self.handle.sendline("")
529 self.handle.expect("\$")
530
531 self.handle.sendline("onos -w " + ONOS_ip + " " + cmdstr)
532 self.handle.expect("\$")
533
534 handle_before = str(self.handle.before)
535 handle_after = str(self.handle.after)
536
537 self.handle.sendline("")
538 self.handle.expect("\$")
539 handle_more = str(self.handle.before)
540
541 main.log.info("Command sent successfully")
542
andrewonlab94282092014-10-10 13:00:11 -0400543 #Obtain return handle that consists of result from
544 #the onos command. The string may need to be
545 #configured further.
546 #TODO: This function may need to return another
547 # type of variable depending on its use case
andrewonlab05e362f2014-10-10 00:40:57 -0400548 return_string = handle_before + handle_after + handle_more
andrewonlab05e362f2014-10-10 00:40:57 -0400549 return return_string
550
551 except pexpect.EOF:
552 main.log.error(self.name + ": EOF exception found")
553 main.log.error(self.name + ": " + self.handle.before)
554 main.cleanup()
555 main.exit()
556 except:
557 main.log.info(self.name+" ::::::")
558 main.log.error( traceback.print_exc())
559 main.log.info(self.name+" ::::::")
560 main.cleanup()
561 main.exit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400562
563 def onos_install(self, options="-f", node = ""):
564 '''
565 Installs ONOS bits on the designated cell machine.
566 If -f option is provided, it also forces an uninstall.
567 Presently, install also includes onos-push-bits and
568 onos-config within.
569 The node option allows you to selectively only push the jar
570 files to certain onos nodes
571
572 Returns: main.TRUE on success and main.FALSE on failure
573 '''
574 try:
575 self.handle.sendline("onos-install " + options + " " + node)
576 self.handle.expect("onos-install ")
577 #NOTE: this timeout may need to change depending on the network and size of ONOS
578 i=self.handle.expect(["Network\sis\sunreachable",
579 "onos\sstart/running,\sprocess",
580 pexpect.TIMEOUT],timeout=60)
581
582
583 if i == 0:
584 main.log.warn("Network is unreachable")
585 return main.FALSE
586 elif i == 1:
587 main.log.info("ONOS was installed on the VM and started")
588 return main.TRUE
589 elif i == 2:
590 main.log.info("Installation of ONOS on the VM timed out")
591 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -0400592
593 except pexpect.EOF:
594 main.log.error(self.name + ": EOF exception found")
595 main.log.error(self.name + ": " + self.handle.before)
596 main.cleanup()
597 main.exit()
598 except:
599 main.log.info(self.name+" ::::::")
600 main.log.error( traceback.print_exc())
601 main.log.info(self.name+" ::::::")
602 main.cleanup()
603 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400604
andrewonlab8d0d7d72014-10-09 16:33:15 -0400605 def onos_start(self, node_ip):
606 '''
607 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400608 This command is a remote management of the ONOS upstart daemon
andrewonlab8d0d7d72014-10-09 16:33:15 -0400609 '''
610
611 try:
612 self.handle.sendline("")
613 self.handle.expect("\$")
614 self.handle.sendline("onos-service "+str(node_ip)+
615 " start")
616 i = self.handle.expect([
617 "Job\sis\salready\srunning",
618 "start/running",
619 "Unknown\sinstance",
620 pexpect.TIMEOUT],timeout=60)
621
622 if i == 0:
623 main.log.info("Service is already running")
624 return main.TRUE
625 elif i == 1:
626 main.log.info("ONOS service started")
627 return main.TRUE
628 else:
629 main.log.error("ONOS service failed to start")
630 main.cleanup()
631 main.exit()
andrewonlab8d0d7d72014-10-09 16:33:15 -0400632 except pexpect.EOF:
633 main.log.error(self.name + ": EOF exception found")
634 main.log.error(self.name + ": " + self.handle.before)
635 main.cleanup()
636 main.exit()
637 except:
638 main.log.info(self.name+" ::::::")
639 main.log.error( traceback.print_exc())
640 main.log.info(self.name+" ::::::")
641 main.cleanup()
642 main.exit()
643
andrewonlab2b30bd32014-10-09 16:48:55 -0400644 def onos_stop(self, node_ip):
645 '''
646 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400647 This command is a remote management of the ONOS upstart daemon
andrewonlab2b30bd32014-10-09 16:48:55 -0400648 '''
649 try:
650 self.handle.sendline("")
651 self.handle.expect("\$")
652 self.handle.sendline("onos-service "+str(node_ip)+
653 " stop")
654 i = self.handle.expect([
655 "stop/waiting",
656 "Unknown\sinstance",
657 pexpect.TIMEOUT],timeout=60)
658
659 if i == 0:
660 main.log.info("ONOS service stopped")
661 return main.TRUE
662 elif i == 1:
663 main.log.info("Unknown ONOS instance specified: "+
664 str(node_ip))
665 return main.FALSE
666 else:
667 main.log.error("ONOS service failed to stop")
668 return main.FALSE
669
670 except pexpect.EOF:
671 main.log.error(self.name + ": EOF exception found")
672 main.log.error(self.name + ": " + self.handle.before)
673 main.cleanup()
674 main.exit()
675 except:
676 main.log.info(self.name+" ::::::")
677 main.log.error( traceback.print_exc())
678 main.log.info(self.name+" ::::::")
679 main.cleanup()
680 main.exit()
681
andrewonlabc8d47972014-10-09 16:52:36 -0400682 def onos_uninstall(self):
683 '''
684 Calls the command: 'onos-uninstall'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400685 Uninstalls ONOS from the designated cell machine, stopping
686 if needed
andrewonlabc8d47972014-10-09 16:52:36 -0400687 '''
688 try:
689 self.handle.sendline("")
690 self.handle.expect("\$")
691 self.handle.sendline("onos-uninstall")
692 self.handle.expect("\$")
693
andrewonlab84727452014-10-09 18:15:36 -0400694 main.log.info("ONOS cell machine was uninstalled")
andrewonlabc8d47972014-10-09 16:52:36 -0400695 #onos-uninstall command does not return any text
696 return main.TRUE
697
698 except pexpect.EOF:
699 main.log.error(self.name + ": EOF exception found")
700 main.log.error(self.name + ": " + self.handle.before)
701 main.cleanup()
702 main.exit()
703 except:
704 main.log.info(self.name+" ::::::")
705 main.log.error( traceback.print_exc())
706 main.log.info(self.name+" ::::::")
707 main.cleanup()
708 main.exit()
andrewonlab2b30bd32014-10-09 16:48:55 -0400709
andrewonlabe8e56fd2014-10-09 17:12:44 -0400710 def onos_kill(self, node_ip):
711 '''
712 Calls the command: 'onos-kill [<node-ip>]'
713 "Remotely, and unceremoniously kills the ONOS instance running on
714 the specified cell machine" - Tom V
715 '''
716
717 try:
718 self.handle.sendline("")
719 self.handle.expect("\$")
720 self.handle.sendline("onos-kill " + str(node_ip))
721 i = self.handle.expect([
722 "\$",
723 "No\sroute\sto\shost",
724 "password:",
725 pexpect.TIMEOUT], timeout=20)
726
727 if i == 0:
728 main.log.info("ONOS instance "+str(node_ip)+" was killed")
729 return main.TRUE
730 elif i == 1:
731 main.log.info("No route to host")
732 return main.FALSE
733 elif i == 2:
734 main.log.info("Passwordless login for host: "+str(node_ip)+
735 " not configured")
736 return main.FALSE
737 else:
738 main.log.info("ONOS instasnce was not killed")
739 return main.FALSE
740
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(self.name+" ::::::")
750 main.cleanup()
751 main.exit()
752
andrewonlab94282092014-10-10 13:00:11 -0400753 def onos_start_network(self, mntopo):
754 '''
755 Calls the command 'onos-start-network [<mininet-topo>]
756 "remotely starts the specified topology on the cell's
757 mininet machine against all controllers configured in the
758 cell."
759 * Specify mininet topology file name for mntopo
760 * Topo files should be placed at:
761 ~/<your-onos-directory>/tools/test/topos
762
763 NOTE: This function will take you to the mininet prompt
764 '''
765 try:
766 if not mntopo:
767 main.log.error("You must specify a topo file to execute")
768 return main.FALSE
769
770 mntopo = str(mntopo)
771 self.handle.sendline("")
772 self.handle.expect("\$")
773
774 self.handle.sendline("onos-start-network " + mntopo)
775 self.handle.expect("mininet>")
776 main.log.info("Network started, entered mininet prompt")
777
778 #TODO: Think about whether return is necessary or not
779
780 except pexpect.EOF:
781 main.log.error(self.name + ": EOF exception found")
782 main.log.error(self.name + ": " + self.handle.before)
783 main.cleanup()
784 main.exit()
785 except:
786 main.log.info(self.name+" ::::::")
787 main.log.error( traceback.print_exc())
788 main.log.info(self.name+" ::::::")
789 main.cleanup()
790 main.exit()
791
792
Jon Hall7993bfc2014-10-09 16:30:14 -0400793 def isup(self, node = ""):
794 '''
795 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 -0400796
Jon Hall7993bfc2014-10-09 16:30:14 -0400797 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
798 '''
799 try:
800 self.handle.sendline("onos-wait-for-start " + node )
801 self.handle.expect("onos-wait-for-start")
802 #NOTE: this timeout is arbitrary"
803 i = self.handle.expect(["\$", pexpect.TIMEOUT], timeout = 120)
804 if i == 0:
805 main.log.info(self.name + ": " + node + " is up")
806 return main.TRUE
807 elif i == 1:
808 #NOTE: since this function won't return until ONOS is ready,
809 # we will kill it on timeout
810 self.handle.sendline("\003") #Control-C
811 self.handle.expect("\$")
812 return main.FALSE
813 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()
818 except:
819 main.log.info(self.name+" ::::::")
820 main.log.error( traceback.print_exc())
821 main.log.info(self.name+" ::::::")
822 main.cleanup()
823 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -0400824
825