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 | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 57 | |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 58 | |
| 59 | self.handle.sendline("cd "+ self.home) |
| 60 | self.handle.expect("\$") |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 61 | if self.handle: |
| 62 | return self.handle |
| 63 | else : |
| 64 | main.log.info("NO ONOS HANDLE") |
| 65 | return main.FALSE |
| 66 | except pexpect.EOF: |
| 67 | main.log.error(self.name + ": EOF exception found") |
| 68 | main.log.error(self.name + ": " + self.handle.before) |
| 69 | main.cleanup() |
| 70 | main.exit() |
| 71 | except: |
| 72 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 73 | main.log.error( traceback.print_exc() ) |
| 74 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 75 | main.cleanup() |
| 76 | main.exit() |
| 77 | |
| 78 | def disconnect(self): |
| 79 | ''' |
| 80 | Called when Test is complete to disconnect the ONOS handle. |
| 81 | ''' |
| 82 | response = '' |
| 83 | try: |
| 84 | self.handle.sendline("exit") |
| 85 | self.handle.expect("closed") |
| 86 | except pexpect.EOF: |
| 87 | main.log.error(self.name + ": EOF exception found") |
| 88 | main.log.error(self.name + ": " + self.handle.before) |
| 89 | except: |
| 90 | main.log.error(self.name + ": Connection failed to the host") |
| 91 | response = main.FALSE |
| 92 | return response |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 93 | |
| 94 | def onos_package(self): |
| 95 | ''' |
| 96 | Produce a self-contained tar.gz file that can be deployed |
| 97 | and executed on any platform with Java 7 JRE. |
| 98 | ''' |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 99 | |
| 100 | try: |
| 101 | self.handle.sendline("onos-package") |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 102 | self.handle.expect("onos-package") |
andrewonlab | 0748d2a | 2014-10-09 13:24:17 -0400 | [diff] [blame] | 103 | self.handle.expect("tar.gz",timeout=10) |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 104 | handle = str(self.handle.before) |
| 105 | main.log.info("onos-package command returned: "+ |
| 106 | handle) |
andrewonlab | 0748d2a | 2014-10-09 13:24:17 -0400 | [diff] [blame] | 107 | #As long as the sendline does not time out, |
| 108 | #return true. However, be careful to interpret |
| 109 | #the results of the onos-package command return |
| 110 | return main.TRUE |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 111 | |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 112 | except pexpect.EOF: |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 113 | main.log.error(self.name + ": EOF exception found") |
| 114 | main.log.error(self.name + ": " + self.handle.before) |
| 115 | except: |
| 116 | main.log.error("Failed to package ONOS") |
| 117 | main.cleanup() |
| 118 | main.exit() |
| 119 | |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 120 | def clean_install(self): |
| 121 | ''' |
| 122 | Runs mvn clean install in the root of the ONOS directory. |
| 123 | This will clean all ONOS artifacts then compile each module |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 124 | |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 125 | Returns: main.TRUE on success |
| 126 | On Failure, exits the test |
| 127 | ''' |
| 128 | try: |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 129 | main.log.info("Running 'mvn clean install' on " + str(self.name) + |
| 130 | ". This may take some time.") |
| 131 | self.handle.sendline("cd "+ self.home) |
| 132 | self.handle.expect("\$") |
| 133 | |
| 134 | self.handle.sendline("\n") |
| 135 | self.handle.expect("\$") |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 136 | self.handle.sendline("mvn clean install") |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 137 | self.handle.expect("mvn clean install") |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 138 | while 1: |
| 139 | i=self.handle.expect([ |
| 140 | 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s\ |
| 141 | Runtime\sEnvironment\sto\scontinue', |
| 142 | 'BUILD\sFAILURE', |
| 143 | 'BUILD\sSUCCESS', |
| 144 | 'ONOS\$', |
| 145 | pexpect.TIMEOUT],timeout=600) |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 146 | #TODO: log the build time |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 147 | if i == 0: |
| 148 | main.log.error(self.name + ":There is insufficient memory \ |
| 149 | for the Java Runtime Environment to continue.") |
| 150 | #return main.FALSE |
| 151 | main.cleanup() |
| 152 | main.exit() |
| 153 | if i == 1: |
| 154 | main.log.error(self.name + ": Build failure!") |
| 155 | #return main.FALSE |
| 156 | main.cleanup() |
| 157 | main.exit() |
| 158 | elif i == 2: |
| 159 | main.log.info(self.name + ": Build success!") |
| 160 | elif i == 3: |
| 161 | main.log.info(self.name + ": Build complete") |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 162 | self.handle.sendline("\n") |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 163 | 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 Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 187 | |
| 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() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 354 | |
| 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 |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 372 | #Get the rest of the handle |
| 373 | self.handle.sendline("") |
| 374 | self.handle.expect("\$") |
| 375 | handle_more = self.handle.before |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 376 | |
| 377 | main.log.info("Cell call returned: "+handle_before+ |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 378 | handle_after + handle_more) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 379 | |
| 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 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 394 | def verify_cell(self): |
| 395 | ''' |
| 396 | Calls 'onos-verify-cell' to check for cell installation |
| 397 | ''' |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 398 | #TODO: Add meaningful expect value |
| 399 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 400 | 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 Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 417 | 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 | |
| 429 | |
| 430 | def onos_install(self, options="-f", node = ""): |
| 431 | ''' |
| 432 | Installs ONOS bits on the designated cell machine. |
| 433 | If -f option is provided, it also forces an uninstall. |
| 434 | Presently, install also includes onos-push-bits and |
| 435 | onos-config within. |
| 436 | The node option allows you to selectively only push the jar |
| 437 | files to certain onos nodes |
| 438 | |
| 439 | Returns: main.TRUE on success and main.FALSE on failure |
| 440 | ''' |
| 441 | try: |
| 442 | self.handle.sendline("onos-install " + options + " " + node) |
| 443 | self.handle.expect("onos-install ") |
| 444 | #NOTE: this timeout may need to change depending on the network and size of ONOS |
| 445 | i=self.handle.expect(["Network\sis\sunreachable", |
| 446 | "onos\sstart/running,\sprocess", |
| 447 | pexpect.TIMEOUT],timeout=60) |
| 448 | |
| 449 | |
| 450 | if i == 0: |
| 451 | main.log.warn("Network is unreachable") |
| 452 | return main.FALSE |
| 453 | elif i == 1: |
| 454 | main.log.info("ONOS was installed on the VM and started") |
| 455 | return main.TRUE |
| 456 | elif i == 2: |
| 457 | main.log.info("Installation of ONOS on the VM timed out") |
| 458 | return main.FALSE |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 459 | |
| 460 | except pexpect.EOF: |
| 461 | main.log.error(self.name + ": EOF exception found") |
| 462 | main.log.error(self.name + ": " + self.handle.before) |
| 463 | main.cleanup() |
| 464 | main.exit() |
| 465 | except: |
| 466 | main.log.info(self.name+" ::::::") |
| 467 | main.log.error( traceback.print_exc()) |
| 468 | main.log.info(self.name+" ::::::") |
| 469 | main.cleanup() |
| 470 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 471 | |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 472 | def onos_start(self, node_ip): |
| 473 | ''' |
| 474 | Calls onos command: 'onos-service [<node-ip>] start' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 475 | This command is a remote management of the ONOS upstart daemon |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 476 | ''' |
| 477 | |
| 478 | try: |
| 479 | self.handle.sendline("") |
| 480 | self.handle.expect("\$") |
| 481 | self.handle.sendline("onos-service "+str(node_ip)+ |
| 482 | " start") |
| 483 | i = self.handle.expect([ |
| 484 | "Job\sis\salready\srunning", |
| 485 | "start/running", |
| 486 | "Unknown\sinstance", |
| 487 | pexpect.TIMEOUT],timeout=60) |
| 488 | |
| 489 | if i == 0: |
| 490 | main.log.info("Service is already running") |
| 491 | return main.TRUE |
| 492 | elif i == 1: |
| 493 | main.log.info("ONOS service started") |
| 494 | return main.TRUE |
| 495 | else: |
| 496 | main.log.error("ONOS service failed to start") |
| 497 | main.cleanup() |
| 498 | main.exit() |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 499 | except pexpect.EOF: |
| 500 | main.log.error(self.name + ": EOF exception found") |
| 501 | main.log.error(self.name + ": " + self.handle.before) |
| 502 | main.cleanup() |
| 503 | main.exit() |
| 504 | except: |
| 505 | main.log.info(self.name+" ::::::") |
| 506 | main.log.error( traceback.print_exc()) |
| 507 | main.log.info(self.name+" ::::::") |
| 508 | main.cleanup() |
| 509 | main.exit() |
| 510 | |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 511 | def onos_stop(self, node_ip): |
| 512 | ''' |
| 513 | Calls onos command: 'onos-service [<node-ip>] stop' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 514 | This command is a remote management of the ONOS upstart daemon |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 515 | ''' |
| 516 | try: |
| 517 | self.handle.sendline("") |
| 518 | self.handle.expect("\$") |
| 519 | self.handle.sendline("onos-service "+str(node_ip)+ |
| 520 | " stop") |
| 521 | i = self.handle.expect([ |
| 522 | "stop/waiting", |
| 523 | "Unknown\sinstance", |
| 524 | pexpect.TIMEOUT],timeout=60) |
| 525 | |
| 526 | if i == 0: |
| 527 | main.log.info("ONOS service stopped") |
| 528 | return main.TRUE |
| 529 | elif i == 1: |
| 530 | main.log.info("Unknown ONOS instance specified: "+ |
| 531 | str(node_ip)) |
| 532 | return main.FALSE |
| 533 | else: |
| 534 | main.log.error("ONOS service failed to stop") |
| 535 | return main.FALSE |
| 536 | |
| 537 | except pexpect.EOF: |
| 538 | main.log.error(self.name + ": EOF exception found") |
| 539 | main.log.error(self.name + ": " + self.handle.before) |
| 540 | main.cleanup() |
| 541 | main.exit() |
| 542 | except: |
| 543 | main.log.info(self.name+" ::::::") |
| 544 | main.log.error( traceback.print_exc()) |
| 545 | main.log.info(self.name+" ::::::") |
| 546 | main.cleanup() |
| 547 | main.exit() |
| 548 | |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 549 | def onos_uninstall(self): |
| 550 | ''' |
| 551 | Calls the command: 'onos-uninstall' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 552 | Uninstalls ONOS from the designated cell machine, stopping |
| 553 | if needed |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 554 | ''' |
| 555 | try: |
| 556 | self.handle.sendline("") |
| 557 | self.handle.expect("\$") |
| 558 | self.handle.sendline("onos-uninstall") |
| 559 | self.handle.expect("\$") |
| 560 | |
| 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() |