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