Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | ''' |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 3 | ''' |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 4 | #TODO: Document |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 5 | |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 6 | import sys |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 7 | import time |
| 8 | import pexpect |
| 9 | import re |
| 10 | import traceback |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 11 | import os.path |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 12 | sys.path.append("../") |
| 13 | from drivers.common.clidriver import CLI |
| 14 | |
| 15 | class OnosDriver(CLI): |
| 16 | |
| 17 | def __init__(self): |
| 18 | super(CLI, self).__init__() |
| 19 | |
| 20 | def connect(self,**connectargs): |
| 21 | ''' |
| 22 | Creates ssh handle for ONOS "bench". |
| 23 | ''' |
| 24 | try: |
| 25 | for key in connectargs: |
| 26 | vars(self)[key] = connectargs[key] |
| 27 | self.home = "~/ONOS" |
| 28 | for key in self.options: |
| 29 | if key == "home": |
| 30 | self.home = self.options['home'] |
| 31 | break |
| 32 | |
| 33 | |
| 34 | self.name = self.options['name'] |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 35 | self.handle = super(OnosDriver,self).connect( |
| 36 | user_name = self.user_name, |
| 37 | ip_address = self.ip_address, |
| 38 | port = self.port, |
| 39 | pwd = self.pwd, |
| 40 | home = self.home) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 41 | |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 42 | |
| 43 | self.handle.sendline("cd "+ self.home) |
| 44 | self.handle.expect("\$") |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 45 | if self.handle: |
| 46 | return self.handle |
| 47 | else : |
| 48 | main.log.info("NO ONOS HANDLE") |
| 49 | return main.FALSE |
| 50 | except pexpect.EOF: |
| 51 | main.log.error(self.name + ": EOF exception found") |
| 52 | main.log.error(self.name + ": " + self.handle.before) |
| 53 | main.cleanup() |
| 54 | main.exit() |
| 55 | except: |
| 56 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 57 | main.log.error( traceback.print_exc() ) |
| 58 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 59 | main.cleanup() |
| 60 | main.exit() |
| 61 | |
| 62 | def disconnect(self): |
| 63 | ''' |
| 64 | Called when Test is complete to disconnect the ONOS handle. |
| 65 | ''' |
| 66 | response = '' |
| 67 | try: |
| 68 | self.handle.sendline("exit") |
| 69 | self.handle.expect("closed") |
| 70 | except pexpect.EOF: |
| 71 | main.log.error(self.name + ": EOF exception found") |
| 72 | main.log.error(self.name + ": " + self.handle.before) |
| 73 | except: |
| 74 | main.log.error(self.name + ": Connection failed to the host") |
| 75 | response = main.FALSE |
| 76 | return response |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 77 | |
| 78 | def onos_package(self): |
| 79 | ''' |
| 80 | Produce a self-contained tar.gz file that can be deployed |
| 81 | and executed on any platform with Java 7 JRE. |
| 82 | ''' |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 83 | |
| 84 | try: |
| 85 | self.handle.sendline("onos-package") |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 86 | self.handle.expect("onos-package") |
andrewonlab | 0748d2a | 2014-10-09 13:24:17 -0400 | [diff] [blame] | 87 | self.handle.expect("tar.gz",timeout=10) |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 88 | handle = str(self.handle.before) |
| 89 | main.log.info("onos-package command returned: "+ |
| 90 | handle) |
andrewonlab | 0748d2a | 2014-10-09 13:24:17 -0400 | [diff] [blame] | 91 | #As long as the sendline does not time out, |
| 92 | #return true. However, be careful to interpret |
| 93 | #the results of the onos-package command return |
| 94 | return main.TRUE |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 95 | |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 96 | except pexpect.EOF: |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 97 | main.log.error(self.name + ": EOF exception found") |
| 98 | main.log.error(self.name + ": " + self.handle.before) |
| 99 | except: |
| 100 | main.log.error("Failed to package ONOS") |
| 101 | main.cleanup() |
| 102 | main.exit() |
| 103 | |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 104 | def clean_install(self): |
| 105 | ''' |
| 106 | Runs mvn clean install in the root of the ONOS directory. |
| 107 | This will clean all ONOS artifacts then compile each module |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 108 | |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 109 | Returns: main.TRUE on success |
| 110 | On Failure, exits the test |
| 111 | ''' |
| 112 | try: |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 113 | main.log.info("Running 'mvn clean install' on " + str(self.name) + |
| 114 | ". This may take some time.") |
| 115 | self.handle.sendline("cd "+ self.home) |
| 116 | self.handle.expect("\$") |
| 117 | |
| 118 | self.handle.sendline("\n") |
| 119 | self.handle.expect("\$") |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 120 | self.handle.sendline("mvn clean install") |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 121 | self.handle.expect("mvn clean install") |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 122 | while 1: |
| 123 | i=self.handle.expect([ |
| 124 | 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s\ |
| 125 | Runtime\sEnvironment\sto\scontinue', |
| 126 | 'BUILD\sFAILURE', |
| 127 | 'BUILD\sSUCCESS', |
| 128 | 'ONOS\$', |
| 129 | pexpect.TIMEOUT],timeout=600) |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 130 | #TODO: log the build time |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 131 | if i == 0: |
| 132 | main.log.error(self.name + ":There is insufficient memory \ |
| 133 | for the Java Runtime Environment to continue.") |
| 134 | #return main.FALSE |
| 135 | main.cleanup() |
| 136 | main.exit() |
| 137 | if i == 1: |
| 138 | main.log.error(self.name + ": Build failure!") |
| 139 | #return main.FALSE |
| 140 | main.cleanup() |
| 141 | main.exit() |
| 142 | elif i == 2: |
| 143 | main.log.info(self.name + ": Build success!") |
| 144 | elif i == 3: |
| 145 | main.log.info(self.name + ": Build complete") |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 146 | self.handle.sendline("\n") |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 147 | self.handle.expect("\$", timeout=60) |
| 148 | return main.TRUE |
| 149 | elif i == 4: |
| 150 | main.log.error(self.name + ": mvn clean install TIMEOUT!") |
| 151 | #return main.FALSE |
| 152 | main.cleanup() |
| 153 | main.exit() |
| 154 | else: |
| 155 | main.log.error(self.name + ": unexpected response from \ |
| 156 | mvn clean install") |
| 157 | #return main.FALSE |
| 158 | main.cleanup() |
| 159 | main.exit() |
| 160 | except pexpect.EOF: |
| 161 | main.log.error(self.name + ": EOF exception found") |
| 162 | main.log.error(self.name + ": " + self.handle.before) |
| 163 | main.cleanup() |
| 164 | main.exit() |
| 165 | except: |
| 166 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 167 | main.log.error( traceback.print_exc() ) |
| 168 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 169 | main.cleanup() |
| 170 | main.exit() |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 171 | |
| 172 | def git_pull(self, comp1=""): |
| 173 | ''' |
| 174 | Assumes that "git pull" works without login |
| 175 | |
| 176 | This function will perform a git pull on the ONOS instance. |
| 177 | If used as git_pull("NODE") it will do git pull + NODE. This is |
| 178 | for the purpose of pulling from other nodes if necessary. |
| 179 | |
| 180 | Otherwise, this function will perform a git pull in the |
| 181 | ONOS repository. If it has any problems, it will return main.ERROR |
| 182 | If it successfully does a git_pull, it will return a 1. |
| 183 | If it has no updates, it will return a 0. |
| 184 | |
| 185 | ''' |
| 186 | try: |
| 187 | # main.log.info(self.name + ": Stopping ONOS") |
| 188 | #self.stop() |
| 189 | self.handle.sendline("cd " + self.home) |
| 190 | self.handle.expect("ONOS\$") |
| 191 | if comp1=="": |
| 192 | self.handle.sendline("git pull") |
| 193 | else: |
| 194 | self.handle.sendline("git pull " + comp1) |
| 195 | |
| 196 | uptodate = 0 |
| 197 | i=self.handle.expect(['fatal', |
| 198 | 'Username\sfor\s(.*):\s', |
| 199 | '\sfile(s*) changed,\s', |
| 200 | 'Already up-to-date', |
| 201 | 'Aborting', |
| 202 | 'You\sare\snot\scurrently\son\sa\sbranch', |
| 203 | 'You\sasked\sme\sto\spull\swithout\stelling\sme\swhich\sbranch\syou', |
| 204 | 'Pull\sis\snot\spossible\sbecause\syou\shave\sunmerged\sfiles', |
| 205 | pexpect.TIMEOUT], |
| 206 | timeout=300) |
| 207 | #debug |
| 208 | #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after)) |
| 209 | if i==0: |
| 210 | main.log.error(self.name + ": Git pull had some issue...") |
| 211 | return main.ERROR |
| 212 | elif i==1: |
| 213 | main.log.error(self.name + ": Git Pull Asking for username. ") |
| 214 | return main.ERROR |
| 215 | elif i==2: |
| 216 | main.log.info(self.name + ": Git Pull - pulling repository now") |
| 217 | self.handle.expect("ONOS\$", 120) |
| 218 | return 0 |
| 219 | elif i==3: |
| 220 | main.log.info(self.name + ": Git Pull - Already up to date") |
| 221 | return 1 |
| 222 | elif i==4: |
| 223 | main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?") |
| 224 | return main.ERROR |
| 225 | elif i==5: |
| 226 | main.log.info(self.name + ": Git Pull - You are not currently on a branch so git pull failed!") |
| 227 | return main.ERROR |
| 228 | elif i==6: |
| 229 | main.log.info(self.name + ": Git Pull - You have not configured an upstream branch to pull from. Git pull failed!") |
| 230 | return main.ERROR |
| 231 | elif i==7: |
| 232 | main.log.info(self.name + ": Git Pull - Pull is not possible because you have unmerged files.") |
| 233 | return main.ERROR |
| 234 | elif i==8: |
| 235 | main.log.error(self.name + ": Git Pull - TIMEOUT") |
| 236 | main.log.error(self.name + " Response was: " + str(self.handle.before)) |
| 237 | return main.ERROR |
| 238 | else: |
| 239 | main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors") |
| 240 | return main.ERROR |
| 241 | except pexpect.EOF: |
| 242 | main.log.error(self.name + ": EOF exception found") |
| 243 | main.log.error(self.name + ": " + self.handle.before) |
| 244 | main.cleanup() |
| 245 | main.exit() |
| 246 | except: |
| 247 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 248 | main.log.error( traceback.print_exc() ) |
| 249 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 250 | main.cleanup() |
| 251 | main.exit() |
| 252 | |
| 253 | def git_checkout(self, branch="master"): |
| 254 | ''' |
| 255 | Assumes that "git pull" works without login |
| 256 | |
| 257 | This function will perform a git git checkout on the ONOS instance. |
| 258 | If used as git_checkout("branch") it will do git checkout of the "branch". |
| 259 | |
| 260 | Otherwise, this function will perform a git checkout of the master |
| 261 | branch of the ONOS repository. If it has any problems, it will return |
| 262 | main.ERROR. |
| 263 | If the branch was already the specified branch, or the git checkout was |
| 264 | successful then the function will return main.TRUE. |
| 265 | |
| 266 | ''' |
| 267 | try: |
| 268 | # main.log.info(self.name + ": Stopping ONOS") |
| 269 | #self.stop() |
| 270 | self.handle.sendline("cd " + self.home) |
| 271 | self.handle.expect("ONOS\$") |
| 272 | if branch != 'master': |
| 273 | #self.handle.sendline('git stash') |
| 274 | #self.handle.expect('ONOS\$') |
| 275 | #print "After issuing git stash cmnd: ", self.handle.before |
| 276 | cmd = "git checkout "+branch |
| 277 | print "checkout cmd = ", cmd |
| 278 | self.handle.sendline(cmd) |
| 279 | uptodate = 0 |
| 280 | i=self.handle.expect(['fatal', |
| 281 | 'Username\sfor\s(.*):\s', |
| 282 | 'Already\son\s\'', |
| 283 | 'Switched\sto\sbranch\s\'', |
| 284 | pexpect.TIMEOUT],timeout=60) |
| 285 | else: |
| 286 | #self.handle.sendline('git stash apply') |
| 287 | #self.handle.expect('ONOS\$') |
| 288 | #print "After issuing git stash apply cmnd: ", self.handle.before |
| 289 | cmd = "git checkout "+branch |
| 290 | print "checkout cmd = ", cmd |
| 291 | self.handle.sendline(cmd) |
| 292 | uptodate = 0 |
| 293 | switchedToMaster = 0 |
| 294 | i=self.handle.expect(['fatal', |
| 295 | 'Username\sfor\s(.*):\s', |
| 296 | 'Already\son\s\'master\'', |
| 297 | 'Switched\sto\sbranch\s\'master\'', |
| 298 | pexpect.TIMEOUT],timeout=60) |
| 299 | |
| 300 | |
| 301 | if i==0: |
| 302 | main.log.error(self.name + ": Git checkout had some issue...") |
| 303 | return main.ERROR |
| 304 | elif i==1: |
| 305 | main.log.error(self.name + ": Git checkout Asking for username!!! Bad!") |
| 306 | return main.ERROR |
| 307 | elif i==2: |
| 308 | main.log.info(self.name + ": Git Checkout %s : Already on this branch" %branch) |
| 309 | self.handle.expect("ONOS\$") |
| 310 | print "after checkout cmd = ", self.handle.before |
| 311 | switchedToMaster = 1 |
| 312 | return main.TRUE |
| 313 | elif i==3: |
| 314 | main.log.info(self.name + ": Git checkout %s - Switched to this branch" %branch) |
| 315 | self.handle.expect("ONOS\$") |
| 316 | print "after checkout cmd = ", self.handle.before |
| 317 | switchedToMaster = 1 |
| 318 | return main.TRUE |
| 319 | elif i==4: |
| 320 | main.log.error(self.name + ": Git Checkout- TIMEOUT") |
| 321 | main.log.error(self.name + " Response was: " + str(self.handle.before)) |
| 322 | return main.ERROR |
| 323 | else: |
| 324 | main.log.error(self.name + ": Git Checkout - Unexpected response, check for pull errors") |
| 325 | return main.ERROR |
| 326 | |
| 327 | except pexpect.EOF: |
| 328 | main.log.error(self.name + ": EOF exception found") |
| 329 | main.log.error(self.name + ": " + self.handle.before) |
| 330 | main.cleanup() |
| 331 | main.exit() |
| 332 | except: |
| 333 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 334 | main.log.error( traceback.print_exc() ) |
| 335 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 336 | main.cleanup() |
| 337 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 338 | |
| 339 | def set_cell(self, cellname): |
| 340 | ''' |
| 341 | Calls 'cell <name>' to set the environment variables on ONOSbench |
| 342 | ''' |
| 343 | try: |
| 344 | if not cellname: |
| 345 | main.log.error("Must define cellname") |
| 346 | main.cleanup() |
| 347 | main.exit() |
| 348 | else: |
| 349 | self.handle.sendline("cell "+str(cellname)) |
| 350 | #Expect the cellname in the ONOS_CELL variable. |
| 351 | #Note that this variable name is subject to change |
| 352 | # and that this driver will have to change accordingly |
| 353 | self.handle.expect("ONOS_CELL="+str(cellname)) |
| 354 | handle_before = self.handle.before |
| 355 | handle_after = self.handle.after |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 356 | #Get the rest of the handle |
| 357 | self.handle.sendline("") |
| 358 | self.handle.expect("\$") |
| 359 | handle_more = self.handle.before |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 360 | |
| 361 | main.log.info("Cell call returned: "+handle_before+ |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 362 | handle_after + handle_more) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 363 | |
| 364 | return main.TRUE |
| 365 | |
| 366 | except pexpect.EOF: |
| 367 | main.log.error(self.name + ": EOF exception found") |
| 368 | main.log.error(self.name + ": " + self.handle.before) |
| 369 | main.cleanup() |
| 370 | main.exit() |
| 371 | except: |
| 372 | main.log.info(self.name+" ::::::") |
| 373 | main.log.error( traceback.print_exc()) |
| 374 | main.log.info(self.name+" ::::::") |
| 375 | main.cleanup() |
| 376 | main.exit() |
| 377 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 378 | def verify_cell(self): |
| 379 | ''' |
| 380 | Calls 'onos-verify-cell' to check for cell installation |
| 381 | ''' |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 382 | #TODO: Add meaningful expect value |
| 383 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 384 | try: |
| 385 | #Clean handle by sending empty and expecting $ |
| 386 | self.handle.sendline("") |
| 387 | self.handle.expect("\$") |
| 388 | self.handle.sendline("onos-verify-cell") |
| 389 | self.handle.expect("\$") |
| 390 | handle_before = self.handle.before |
| 391 | handle_after = self.handle.after |
| 392 | #Get the rest of the handle |
| 393 | self.handle.sendline("") |
| 394 | self.handle.expect("\$") |
| 395 | handle_more = self.handle.before |
| 396 | |
| 397 | main.log.info("Verify cell returned: "+handle_before+ |
| 398 | handle_after + handle_more) |
| 399 | |
| 400 | return main.TRUE |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 401 | except pexpect.EOF: |
| 402 | main.log.error(self.name + ": EOF exception found") |
| 403 | main.log.error(self.name + ": " + self.handle.before) |
| 404 | main.cleanup() |
| 405 | main.exit() |
| 406 | except: |
| 407 | main.log.info(self.name+" ::::::") |
| 408 | main.log.error( traceback.print_exc()) |
| 409 | main.log.info(self.name+" ::::::") |
| 410 | main.cleanup() |
| 411 | main.exit() |
| 412 | |
| 413 | |
| 414 | def onos_install(self, options="-f", node = ""): |
| 415 | ''' |
| 416 | Installs ONOS bits on the designated cell machine. |
| 417 | If -f option is provided, it also forces an uninstall. |
| 418 | Presently, install also includes onos-push-bits and |
| 419 | onos-config within. |
| 420 | The node option allows you to selectively only push the jar |
| 421 | files to certain onos nodes |
| 422 | |
| 423 | Returns: main.TRUE on success and main.FALSE on failure |
| 424 | ''' |
| 425 | try: |
| 426 | self.handle.sendline("onos-install " + options + " " + node) |
| 427 | self.handle.expect("onos-install ") |
| 428 | #NOTE: this timeout may need to change depending on the network and size of ONOS |
| 429 | i=self.handle.expect(["Network\sis\sunreachable", |
| 430 | "onos\sstart/running,\sprocess", |
| 431 | pexpect.TIMEOUT],timeout=60) |
| 432 | |
| 433 | |
| 434 | if i == 0: |
| 435 | main.log.warn("Network is unreachable") |
| 436 | return main.FALSE |
| 437 | elif i == 1: |
| 438 | main.log.info("ONOS was installed on the VM and started") |
| 439 | return main.TRUE |
| 440 | elif i == 2: |
| 441 | main.log.info("Installation of ONOS on the VM timed out") |
| 442 | return main.FALSE |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 443 | |
| 444 | except pexpect.EOF: |
| 445 | main.log.error(self.name + ": EOF exception found") |
| 446 | main.log.error(self.name + ": " + self.handle.before) |
| 447 | main.cleanup() |
| 448 | main.exit() |
| 449 | except: |
| 450 | main.log.info(self.name+" ::::::") |
| 451 | main.log.error( traceback.print_exc()) |
| 452 | main.log.info(self.name+" ::::::") |
| 453 | main.cleanup() |
| 454 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 455 | |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 456 | def onos_start(self, node_ip): |
| 457 | ''' |
| 458 | Calls onos command: 'onos-service [<node-ip>] start' |
| 459 | ''' |
| 460 | |
| 461 | try: |
| 462 | self.handle.sendline("") |
| 463 | self.handle.expect("\$") |
| 464 | self.handle.sendline("onos-service "+str(node_ip)+ |
| 465 | " start") |
| 466 | i = self.handle.expect([ |
| 467 | "Job\sis\salready\srunning", |
| 468 | "start/running", |
| 469 | "Unknown\sinstance", |
| 470 | pexpect.TIMEOUT],timeout=60) |
| 471 | |
| 472 | if i == 0: |
| 473 | main.log.info("Service is already running") |
| 474 | return main.TRUE |
| 475 | elif i == 1: |
| 476 | main.log.info("ONOS service started") |
| 477 | return main.TRUE |
| 478 | else: |
| 479 | main.log.error("ONOS service failed to start") |
| 480 | main.cleanup() |
| 481 | main.exit() |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 482 | except pexpect.EOF: |
| 483 | main.log.error(self.name + ": EOF exception found") |
| 484 | main.log.error(self.name + ": " + self.handle.before) |
| 485 | main.cleanup() |
| 486 | main.exit() |
| 487 | except: |
| 488 | main.log.info(self.name+" ::::::") |
| 489 | main.log.error( traceback.print_exc()) |
| 490 | main.log.info(self.name+" ::::::") |
| 491 | main.cleanup() |
| 492 | main.exit() |
| 493 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 494 | def isup(self, node = ""): |
| 495 | ''' |
| 496 | Run's onos-wait-for-start which only returns once ONOS is at run level 100(ready for use) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 497 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 498 | Returns: main.TRUE if ONOS is running and main.FALSE on timeout |
| 499 | ''' |
| 500 | try: |
| 501 | self.handle.sendline("onos-wait-for-start " + node ) |
| 502 | self.handle.expect("onos-wait-for-start") |
| 503 | #NOTE: this timeout is arbitrary" |
| 504 | i = self.handle.expect(["\$", pexpect.TIMEOUT], timeout = 120) |
| 505 | if i == 0: |
| 506 | main.log.info(self.name + ": " + node + " is up") |
| 507 | return main.TRUE |
| 508 | elif i == 1: |
| 509 | #NOTE: since this function won't return until ONOS is ready, |
| 510 | # we will kill it on timeout |
| 511 | self.handle.sendline("\003") #Control-C |
| 512 | self.handle.expect("\$") |
| 513 | return main.FALSE |
| 514 | except pexpect.EOF: |
| 515 | main.log.error(self.name + ": EOF exception found") |
| 516 | main.log.error(self.name + ": " + self.handle.before) |
| 517 | main.cleanup() |
| 518 | main.exit() |
| 519 | except: |
| 520 | main.log.info(self.name+" ::::::") |
| 521 | main.log.error( traceback.print_exc()) |
| 522 | main.log.info(self.name+" ::::::") |
| 523 | main.cleanup() |
| 524 | main.exit() |