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 | |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 20 | import sys |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 21 | import time |
| 22 | import pexpect |
| 23 | import re |
| 24 | import traceback |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 25 | import os.path |
andrewonlab | 6e20c34 | 2014-10-10 18:08:48 -0400 | [diff] [blame] | 26 | import pydoc |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 27 | sys.path.append("../") |
| 28 | from drivers.common.clidriver import CLI |
| 29 | |
| 30 | class OnosDriver(CLI): |
| 31 | |
| 32 | def __init__(self): |
andrewonlab | 6e20c34 | 2014-10-10 18:08:48 -0400 | [diff] [blame] | 33 | ''' |
| 34 | Initialize client |
| 35 | ''' |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 36 | super(CLI, self).__init__() |
| 37 | |
| 38 | def connect(self,**connectargs): |
| 39 | ''' |
| 40 | Creates ssh handle for ONOS "bench". |
| 41 | ''' |
| 42 | try: |
| 43 | for key in connectargs: |
| 44 | vars(self)[key] = connectargs[key] |
| 45 | self.home = "~/ONOS" |
| 46 | for key in self.options: |
| 47 | if key == "home": |
| 48 | self.home = self.options['home'] |
| 49 | break |
| 50 | |
| 51 | |
| 52 | self.name = self.options['name'] |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 53 | self.handle = super(OnosDriver,self).connect( |
| 54 | user_name = self.user_name, |
| 55 | ip_address = self.ip_address, |
| 56 | port = self.port, |
| 57 | pwd = self.pwd, |
| 58 | home = self.home) |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 59 | |
| 60 | self.handle.sendline("cd "+ self.home) |
| 61 | self.handle.expect("\$") |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 62 | if self.handle: |
| 63 | return self.handle |
| 64 | else : |
| 65 | main.log.info("NO ONOS HANDLE") |
| 66 | return main.FALSE |
| 67 | except pexpect.EOF: |
| 68 | main.log.error(self.name + ": EOF exception found") |
| 69 | main.log.error(self.name + ": " + self.handle.before) |
| 70 | main.cleanup() |
| 71 | main.exit() |
| 72 | except: |
| 73 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 74 | main.log.error( traceback.print_exc() ) |
| 75 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 76 | main.cleanup() |
| 77 | main.exit() |
| 78 | |
| 79 | def disconnect(self): |
| 80 | ''' |
| 81 | Called when Test is complete to disconnect the ONOS handle. |
| 82 | ''' |
| 83 | response = '' |
| 84 | try: |
| 85 | self.handle.sendline("exit") |
| 86 | self.handle.expect("closed") |
| 87 | except pexpect.EOF: |
| 88 | main.log.error(self.name + ": EOF exception found") |
| 89 | main.log.error(self.name + ": " + self.handle.before) |
| 90 | except: |
| 91 | main.log.error(self.name + ": Connection failed to the host") |
| 92 | response = main.FALSE |
| 93 | return response |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 94 | |
| 95 | def onos_package(self): |
| 96 | ''' |
| 97 | Produce a self-contained tar.gz file that can be deployed |
| 98 | and executed on any platform with Java 7 JRE. |
| 99 | ''' |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 100 | |
| 101 | try: |
| 102 | self.handle.sendline("onos-package") |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 103 | self.handle.expect("onos-package") |
andrewonlab | 0748d2a | 2014-10-09 13:24:17 -0400 | [diff] [blame] | 104 | self.handle.expect("tar.gz",timeout=10) |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 105 | handle = str(self.handle.before) |
| 106 | main.log.info("onos-package command returned: "+ |
| 107 | handle) |
andrewonlab | 0748d2a | 2014-10-09 13:24:17 -0400 | [diff] [blame] | 108 | #As long as the sendline does not time out, |
| 109 | #return true. However, be careful to interpret |
| 110 | #the results of the onos-package command return |
| 111 | return main.TRUE |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 112 | |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 113 | except pexpect.EOF: |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 114 | main.log.error(self.name + ": EOF exception found") |
| 115 | main.log.error(self.name + ": " + self.handle.before) |
| 116 | except: |
| 117 | main.log.error("Failed to package ONOS") |
| 118 | main.cleanup() |
| 119 | main.exit() |
| 120 | |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 121 | def clean_install(self): |
| 122 | ''' |
| 123 | Runs mvn clean install in the root of the ONOS directory. |
| 124 | This will clean all ONOS artifacts then compile each module |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 125 | |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 126 | Returns: main.TRUE on success |
| 127 | On Failure, exits the test |
| 128 | ''' |
| 129 | try: |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 130 | main.log.info("Running 'mvn clean install' on " + str(self.name) + |
| 131 | ". This may take some time.") |
| 132 | self.handle.sendline("cd "+ self.home) |
| 133 | self.handle.expect("\$") |
| 134 | |
| 135 | self.handle.sendline("\n") |
| 136 | self.handle.expect("\$") |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 137 | self.handle.sendline("mvn clean install") |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 138 | self.handle.expect("mvn clean install") |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 139 | while 1: |
| 140 | i=self.handle.expect([ |
| 141 | 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s\ |
| 142 | Runtime\sEnvironment\sto\scontinue', |
| 143 | 'BUILD\sFAILURE', |
| 144 | 'BUILD\sSUCCESS', |
| 145 | 'ONOS\$', |
| 146 | pexpect.TIMEOUT],timeout=600) |
| 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 | f8ef52c | 2014-10-09 19:37:33 -0400 | [diff] [blame] | 162 | #Print the build time |
| 163 | for line in self.handle.before.splitlines(): |
| 164 | if "Total time:" in line: |
| 165 | main.log.info(line) |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 166 | self.handle.sendline("\n") |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 167 | self.handle.expect("\$", timeout=60) |
| 168 | return main.TRUE |
| 169 | elif i == 4: |
| 170 | main.log.error(self.name + ": mvn clean install TIMEOUT!") |
| 171 | #return main.FALSE |
| 172 | main.cleanup() |
| 173 | main.exit() |
| 174 | else: |
| 175 | main.log.error(self.name + ": unexpected response from \ |
| 176 | mvn clean install") |
| 177 | #return main.FALSE |
| 178 | main.cleanup() |
| 179 | main.exit() |
| 180 | except pexpect.EOF: |
| 181 | main.log.error(self.name + ": EOF exception found") |
| 182 | main.log.error(self.name + ": " + self.handle.before) |
| 183 | main.cleanup() |
| 184 | main.exit() |
| 185 | except: |
| 186 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 187 | main.log.error( traceback.print_exc() ) |
| 188 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 189 | main.cleanup() |
| 190 | main.exit() |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 191 | |
| 192 | def git_pull(self, comp1=""): |
| 193 | ''' |
| 194 | Assumes that "git pull" works without login |
| 195 | |
| 196 | This function will perform a git pull on the ONOS instance. |
| 197 | If used as git_pull("NODE") it will do git pull + NODE. This is |
| 198 | for the purpose of pulling from other nodes if necessary. |
| 199 | |
| 200 | Otherwise, this function will perform a git pull in the |
| 201 | ONOS repository. If it has any problems, it will return main.ERROR |
| 202 | If it successfully does a git_pull, it will return a 1. |
| 203 | If it has no updates, it will return a 0. |
| 204 | |
| 205 | ''' |
| 206 | try: |
| 207 | # main.log.info(self.name + ": Stopping ONOS") |
| 208 | #self.stop() |
| 209 | self.handle.sendline("cd " + self.home) |
| 210 | self.handle.expect("ONOS\$") |
| 211 | if comp1=="": |
| 212 | self.handle.sendline("git pull") |
| 213 | else: |
| 214 | self.handle.sendline("git pull " + comp1) |
| 215 | |
| 216 | uptodate = 0 |
| 217 | i=self.handle.expect(['fatal', |
| 218 | 'Username\sfor\s(.*):\s', |
| 219 | '\sfile(s*) changed,\s', |
| 220 | 'Already up-to-date', |
| 221 | 'Aborting', |
| 222 | 'You\sare\snot\scurrently\son\sa\sbranch', |
| 223 | 'You\sasked\sme\sto\spull\swithout\stelling\sme\swhich\sbranch\syou', |
| 224 | 'Pull\sis\snot\spossible\sbecause\syou\shave\sunmerged\sfiles', |
| 225 | pexpect.TIMEOUT], |
| 226 | timeout=300) |
| 227 | #debug |
| 228 | #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after)) |
| 229 | if i==0: |
| 230 | main.log.error(self.name + ": Git pull had some issue...") |
| 231 | return main.ERROR |
| 232 | elif i==1: |
| 233 | main.log.error(self.name + ": Git Pull Asking for username. ") |
| 234 | return main.ERROR |
| 235 | elif i==2: |
| 236 | main.log.info(self.name + ": Git Pull - pulling repository now") |
| 237 | self.handle.expect("ONOS\$", 120) |
| 238 | return 0 |
| 239 | elif i==3: |
| 240 | main.log.info(self.name + ": Git Pull - Already up to date") |
| 241 | return 1 |
| 242 | elif i==4: |
| 243 | main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?") |
| 244 | return main.ERROR |
| 245 | elif i==5: |
| 246 | main.log.info(self.name + ": Git Pull - You are not currently on a branch so git pull failed!") |
| 247 | return main.ERROR |
| 248 | elif i==6: |
| 249 | main.log.info(self.name + ": Git Pull - You have not configured an upstream branch to pull from. Git pull failed!") |
| 250 | return main.ERROR |
| 251 | elif i==7: |
| 252 | main.log.info(self.name + ": Git Pull - Pull is not possible because you have unmerged files.") |
| 253 | return main.ERROR |
| 254 | elif i==8: |
| 255 | main.log.error(self.name + ": Git Pull - TIMEOUT") |
| 256 | main.log.error(self.name + " Response was: " + str(self.handle.before)) |
| 257 | return main.ERROR |
| 258 | else: |
| 259 | main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors") |
| 260 | return main.ERROR |
| 261 | except pexpect.EOF: |
| 262 | main.log.error(self.name + ": EOF exception found") |
| 263 | main.log.error(self.name + ": " + self.handle.before) |
| 264 | main.cleanup() |
| 265 | main.exit() |
| 266 | except: |
| 267 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 268 | main.log.error( traceback.print_exc() ) |
| 269 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 270 | main.cleanup() |
| 271 | main.exit() |
| 272 | |
| 273 | def git_checkout(self, branch="master"): |
| 274 | ''' |
| 275 | Assumes that "git pull" works without login |
| 276 | |
| 277 | This function will perform a git git checkout on the ONOS instance. |
| 278 | If used as git_checkout("branch") it will do git checkout of the "branch". |
| 279 | |
| 280 | Otherwise, this function will perform a git checkout of the master |
| 281 | branch of the ONOS repository. If it has any problems, it will return |
| 282 | main.ERROR. |
| 283 | If the branch was already the specified branch, or the git checkout was |
| 284 | successful then the function will return main.TRUE. |
| 285 | |
| 286 | ''' |
| 287 | try: |
| 288 | # main.log.info(self.name + ": Stopping ONOS") |
| 289 | #self.stop() |
| 290 | self.handle.sendline("cd " + self.home) |
| 291 | self.handle.expect("ONOS\$") |
| 292 | if branch != 'master': |
| 293 | #self.handle.sendline('git stash') |
| 294 | #self.handle.expect('ONOS\$') |
| 295 | #print "After issuing git stash cmnd: ", self.handle.before |
| 296 | cmd = "git checkout "+branch |
| 297 | print "checkout cmd = ", cmd |
| 298 | self.handle.sendline(cmd) |
| 299 | uptodate = 0 |
| 300 | i=self.handle.expect(['fatal', |
| 301 | 'Username\sfor\s(.*):\s', |
| 302 | 'Already\son\s\'', |
| 303 | 'Switched\sto\sbranch\s\'', |
| 304 | pexpect.TIMEOUT],timeout=60) |
| 305 | else: |
| 306 | #self.handle.sendline('git stash apply') |
| 307 | #self.handle.expect('ONOS\$') |
| 308 | #print "After issuing git stash apply cmnd: ", self.handle.before |
| 309 | cmd = "git checkout "+branch |
| 310 | print "checkout cmd = ", cmd |
| 311 | self.handle.sendline(cmd) |
| 312 | uptodate = 0 |
| 313 | switchedToMaster = 0 |
| 314 | i=self.handle.expect(['fatal', |
| 315 | 'Username\sfor\s(.*):\s', |
| 316 | 'Already\son\s\'master\'', |
| 317 | 'Switched\sto\sbranch\s\'master\'', |
| 318 | pexpect.TIMEOUT],timeout=60) |
| 319 | |
| 320 | |
| 321 | if i==0: |
| 322 | main.log.error(self.name + ": Git checkout had some issue...") |
| 323 | return main.ERROR |
| 324 | elif i==1: |
| 325 | main.log.error(self.name + ": Git checkout Asking for username!!! Bad!") |
| 326 | return main.ERROR |
| 327 | elif i==2: |
| 328 | main.log.info(self.name + ": Git Checkout %s : Already on this branch" %branch) |
| 329 | self.handle.expect("ONOS\$") |
| 330 | print "after checkout cmd = ", self.handle.before |
| 331 | switchedToMaster = 1 |
| 332 | return main.TRUE |
| 333 | elif i==3: |
| 334 | main.log.info(self.name + ": Git checkout %s - Switched to this branch" %branch) |
| 335 | self.handle.expect("ONOS\$") |
| 336 | print "after checkout cmd = ", self.handle.before |
| 337 | switchedToMaster = 1 |
| 338 | return main.TRUE |
| 339 | elif i==4: |
| 340 | main.log.error(self.name + ": Git Checkout- TIMEOUT") |
| 341 | main.log.error(self.name + " Response was: " + str(self.handle.before)) |
| 342 | return main.ERROR |
| 343 | else: |
| 344 | main.log.error(self.name + ": Git Checkout - Unexpected response, check for pull errors") |
| 345 | return main.ERROR |
| 346 | |
| 347 | except pexpect.EOF: |
| 348 | main.log.error(self.name + ": EOF exception found") |
| 349 | main.log.error(self.name + ": " + self.handle.before) |
| 350 | main.cleanup() |
| 351 | main.exit() |
| 352 | except: |
| 353 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 354 | main.log.error( traceback.print_exc() ) |
| 355 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 356 | main.cleanup() |
| 357 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 358 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 359 | def create_cell_file(self, bench_ip, file_name, mn_ip_addrs, *onos_ip_addrs): |
| 360 | ''' |
| 361 | Creates a cell file based on arguments |
| 362 | Required: |
| 363 | * Bench IP address (bench_ip) |
| 364 | - Needed to copy the cell file over |
| 365 | * File name of the cell file (file_name) |
| 366 | * Mininet IP address (mn_ip_addrs) |
| 367 | - Note that only 1 ip address is |
| 368 | supported currently |
| 369 | * ONOS IP addresses (onos_ip_addrs) |
| 370 | - Must be passed in as last arguments |
| 371 | |
| 372 | NOTE: Assumes cells are located at: |
| 373 | ~/<self.home>/tools/test/cells/ |
| 374 | ''' |
| 375 | |
| 376 | #Variable initialization |
| 377 | cell_directory = self.home + "/tools/test/cells/" |
| 378 | #We want to create the cell file in the dependencies directory |
| 379 | #of TestON first, then copy over to ONOS bench |
| 380 | temp_directory = "/tmp/" |
| 381 | #Create the cell file in the directory for writing (w+) |
| 382 | cell_file = open(temp_directory+file_name , 'w+') |
| 383 | |
| 384 | #Feature string is pre-defined environment variable |
| 385 | #that is required in the file |
| 386 | feature_string = "export ONOS_FEATURES=webconsole,onos-api,"+\ |
| 387 | "onos-core-trivial,onos-cli,onos-openflow,"+\ |
| 388 | "onos-app-fwd,onos-app-mobility,onos-app-tvue,"+\ |
| 389 | "onos-app-proxyarp" |
| 390 | mn_string = "export OCN=" |
| 391 | onos_string = "export OC" |
| 392 | temp_count = 1 |
| 393 | |
| 394 | #Create ONOS_NIC ip address prefix |
| 395 | temp_onos_ip = onos_ip_addrs[0] |
| 396 | temp_list = [] |
| 397 | temp_list = temp_onos_ip.split(".") |
| 398 | #Omit last element of list |
| 399 | temp_list = temp_list[:-1] |
| 400 | #Structure the nic string ip |
| 401 | nic_addr = ".".join(temp_list) + ".*\n" |
| 402 | onos_nic_string = "export ONOS_NIC="+nic_addr |
| 403 | |
| 404 | try: |
| 405 | #Start writing to file |
| 406 | cell_file.write(feature_string + "\n") |
| 407 | cell_file.write(onos_nic_string) |
| 408 | cell_file.write(mn_string +"'"+ mn_ip_addrs +"'"+ "\n") |
| 409 | |
| 410 | for arg in onos_ip_addrs: |
| 411 | #For each argument in onos_ip_addrs, write to file |
| 412 | #Output should look like the following: |
| 413 | # export OC1='10.128.20.11' |
| 414 | # export OC2='10.128.20.12' |
| 415 | cell_file.write(onos_string + str(temp_count) + |
| 416 | "=" + "'" + arg + "'" + "\n" ) |
| 417 | temp_count = temp_count + 1 |
| 418 | |
| 419 | cell_file.close() |
| 420 | |
| 421 | #We use os.system to send the command to TestON cluster |
| 422 | #to account for the case in which TestON is not located |
| 423 | #on the same cluster as the ONOS bench |
| 424 | #Note that even if TestON is located on the same cluster |
| 425 | #as ONOS bench, you must setup passwordless ssh |
| 426 | #in order to automate the test. |
| 427 | os.system("scp "+temp_directory+file_name+ |
| 428 | " admin@"+bench_ip+":"+cell_directory) |
| 429 | |
| 430 | except pexpect.EOF: |
| 431 | main.log.error(self.name + ": EOF exception found") |
| 432 | main.log.error(self.name + ": " + self.handle.before) |
| 433 | main.cleanup() |
| 434 | main.exit() |
| 435 | except: |
| 436 | main.log.info(self.name + ":::::::::") |
| 437 | main.log.error( traceback.print_exc() ) |
| 438 | main.log.info(":::::::") |
| 439 | main.cleanup() |
| 440 | main.exit() |
| 441 | |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 442 | def set_cell(self, cellname): |
| 443 | ''' |
| 444 | Calls 'cell <name>' to set the environment variables on ONOSbench |
| 445 | ''' |
| 446 | try: |
| 447 | if not cellname: |
| 448 | main.log.error("Must define cellname") |
| 449 | main.cleanup() |
| 450 | main.exit() |
| 451 | else: |
| 452 | self.handle.sendline("cell "+str(cellname)) |
| 453 | #Expect the cellname in the ONOS_CELL variable. |
| 454 | #Note that this variable name is subject to change |
| 455 | # and that this driver will have to change accordingly |
| 456 | self.handle.expect("ONOS_CELL="+str(cellname)) |
| 457 | handle_before = self.handle.before |
| 458 | handle_after = self.handle.after |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 459 | #Get the rest of the handle |
| 460 | self.handle.sendline("") |
| 461 | self.handle.expect("\$") |
| 462 | handle_more = self.handle.before |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 463 | |
| 464 | main.log.info("Cell call returned: "+handle_before+ |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 465 | handle_after + handle_more) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 466 | |
| 467 | return main.TRUE |
| 468 | |
| 469 | except pexpect.EOF: |
| 470 | main.log.error(self.name + ": EOF exception found") |
| 471 | main.log.error(self.name + ": " + self.handle.before) |
| 472 | main.cleanup() |
| 473 | main.exit() |
| 474 | except: |
| 475 | main.log.info(self.name+" ::::::") |
| 476 | main.log.error( traceback.print_exc()) |
| 477 | main.log.info(self.name+" ::::::") |
| 478 | main.cleanup() |
| 479 | main.exit() |
| 480 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 481 | def verify_cell(self): |
| 482 | ''' |
| 483 | Calls 'onos-verify-cell' to check for cell installation |
| 484 | ''' |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 485 | #TODO: Add meaningful expect value |
| 486 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 487 | try: |
| 488 | #Clean handle by sending empty and expecting $ |
| 489 | self.handle.sendline("") |
| 490 | self.handle.expect("\$") |
| 491 | self.handle.sendline("onos-verify-cell") |
| 492 | self.handle.expect("\$") |
| 493 | handle_before = self.handle.before |
| 494 | handle_after = self.handle.after |
| 495 | #Get the rest of the handle |
| 496 | self.handle.sendline("") |
| 497 | self.handle.expect("\$") |
| 498 | handle_more = self.handle.before |
| 499 | |
| 500 | main.log.info("Verify cell returned: "+handle_before+ |
| 501 | handle_after + handle_more) |
| 502 | |
| 503 | return main.TRUE |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 504 | except pexpect.EOF: |
| 505 | main.log.error(self.name + ": EOF exception found") |
| 506 | main.log.error(self.name + ": " + self.handle.before) |
| 507 | main.cleanup() |
| 508 | main.exit() |
| 509 | except: |
| 510 | main.log.info(self.name+" ::::::") |
| 511 | main.log.error( traceback.print_exc()) |
| 512 | main.log.info(self.name+" ::::::") |
| 513 | main.cleanup() |
| 514 | main.exit() |
| 515 | |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 516 | def onos_cli(self, ONOS_ip, cmdstr): |
| 517 | ''' |
| 518 | Uses 'onos' command to send various ONOS CLI arguments. |
| 519 | Required: |
| 520 | * ONOS_ip: specify the ip of the cell machine |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 521 | * cmdstr: specify the command string to send |
andrewonlab | 6e20c34 | 2014-10-10 18:08:48 -0400 | [diff] [blame] | 522 | |
| 523 | This function is intended to expose the entire karaf |
| 524 | CLI commands for ONOS. Try to use this function first |
| 525 | before attempting to write a ONOS CLI specific driver |
| 526 | function. |
| 527 | You can see a list of available 'cmdstr' arguments |
| 528 | by starting onos, and typing in 'onos' to enter the |
| 529 | onos> CLI. Then, type 'help' to see the list of |
| 530 | available commands. |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 531 | ''' |
| 532 | try: |
| 533 | if not ONOS_ip: |
| 534 | main.log.error("You must specify the IP address") |
| 535 | return main.FALSE |
| 536 | if not cmdstr: |
| 537 | main.log.error("You must specify the command string") |
| 538 | return main.FALSE |
| 539 | |
| 540 | cmdstr = str(cmdstr) |
| 541 | self.handle.sendline("") |
| 542 | self.handle.expect("\$") |
| 543 | |
| 544 | self.handle.sendline("onos -w " + ONOS_ip + " " + cmdstr) |
| 545 | self.handle.expect("\$") |
| 546 | |
| 547 | handle_before = str(self.handle.before) |
| 548 | handle_after = str(self.handle.after) |
| 549 | |
| 550 | self.handle.sendline("") |
| 551 | self.handle.expect("\$") |
| 552 | handle_more = str(self.handle.before) |
| 553 | |
| 554 | main.log.info("Command sent successfully") |
| 555 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 556 | #Obtain return handle that consists of result from |
| 557 | #the onos command. The string may need to be |
| 558 | #configured further. |
| 559 | #TODO: This function may need to return another |
| 560 | # type of variable depending on its use case |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 561 | return_string = handle_before + handle_after + handle_more |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 562 | return return_string |
| 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() |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 575 | |
| 576 | def onos_install(self, options="-f", node = ""): |
| 577 | ''' |
| 578 | Installs ONOS bits on the designated cell machine. |
| 579 | If -f option is provided, it also forces an uninstall. |
| 580 | Presently, install also includes onos-push-bits and |
| 581 | onos-config within. |
| 582 | The node option allows you to selectively only push the jar |
| 583 | files to certain onos nodes |
| 584 | |
| 585 | Returns: main.TRUE on success and main.FALSE on failure |
| 586 | ''' |
| 587 | try: |
| 588 | self.handle.sendline("onos-install " + options + " " + node) |
| 589 | self.handle.expect("onos-install ") |
| 590 | #NOTE: this timeout may need to change depending on the network and size of ONOS |
| 591 | i=self.handle.expect(["Network\sis\sunreachable", |
| 592 | "onos\sstart/running,\sprocess", |
| 593 | pexpect.TIMEOUT],timeout=60) |
| 594 | |
| 595 | |
| 596 | if i == 0: |
| 597 | main.log.warn("Network is unreachable") |
| 598 | return main.FALSE |
| 599 | elif i == 1: |
| 600 | main.log.info("ONOS was installed on the VM and started") |
| 601 | return main.TRUE |
| 602 | elif i == 2: |
| 603 | main.log.info("Installation of ONOS on the VM timed out") |
| 604 | return main.FALSE |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 605 | |
| 606 | except pexpect.EOF: |
| 607 | main.log.error(self.name + ": EOF exception found") |
| 608 | main.log.error(self.name + ": " + self.handle.before) |
| 609 | main.cleanup() |
| 610 | main.exit() |
| 611 | except: |
| 612 | main.log.info(self.name+" ::::::") |
| 613 | main.log.error( traceback.print_exc()) |
| 614 | main.log.info(self.name+" ::::::") |
| 615 | main.cleanup() |
| 616 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 617 | |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 618 | def onos_start(self, node_ip): |
| 619 | ''' |
| 620 | Calls onos command: 'onos-service [<node-ip>] start' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 621 | This command is a remote management of the ONOS upstart daemon |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 622 | ''' |
| 623 | |
| 624 | try: |
| 625 | self.handle.sendline("") |
| 626 | self.handle.expect("\$") |
| 627 | self.handle.sendline("onos-service "+str(node_ip)+ |
| 628 | " start") |
| 629 | i = self.handle.expect([ |
| 630 | "Job\sis\salready\srunning", |
| 631 | "start/running", |
| 632 | "Unknown\sinstance", |
| 633 | pexpect.TIMEOUT],timeout=60) |
| 634 | |
| 635 | if i == 0: |
| 636 | main.log.info("Service is already running") |
| 637 | return main.TRUE |
| 638 | elif i == 1: |
| 639 | main.log.info("ONOS service started") |
| 640 | return main.TRUE |
| 641 | else: |
| 642 | main.log.error("ONOS service failed to start") |
| 643 | main.cleanup() |
| 644 | main.exit() |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 645 | except pexpect.EOF: |
| 646 | main.log.error(self.name + ": EOF exception found") |
| 647 | main.log.error(self.name + ": " + self.handle.before) |
| 648 | main.cleanup() |
| 649 | main.exit() |
| 650 | except: |
| 651 | main.log.info(self.name+" ::::::") |
| 652 | main.log.error( traceback.print_exc()) |
| 653 | main.log.info(self.name+" ::::::") |
| 654 | main.cleanup() |
| 655 | main.exit() |
| 656 | |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 657 | def onos_stop(self, node_ip): |
| 658 | ''' |
| 659 | Calls onos command: 'onos-service [<node-ip>] stop' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 660 | This command is a remote management of the ONOS upstart daemon |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 661 | ''' |
| 662 | try: |
| 663 | self.handle.sendline("") |
| 664 | self.handle.expect("\$") |
| 665 | self.handle.sendline("onos-service "+str(node_ip)+ |
| 666 | " stop") |
| 667 | i = self.handle.expect([ |
| 668 | "stop/waiting", |
| 669 | "Unknown\sinstance", |
| 670 | pexpect.TIMEOUT],timeout=60) |
| 671 | |
| 672 | if i == 0: |
| 673 | main.log.info("ONOS service stopped") |
| 674 | return main.TRUE |
| 675 | elif i == 1: |
| 676 | main.log.info("Unknown ONOS instance specified: "+ |
| 677 | str(node_ip)) |
| 678 | return main.FALSE |
| 679 | else: |
| 680 | main.log.error("ONOS service failed to stop") |
| 681 | return main.FALSE |
| 682 | |
| 683 | except pexpect.EOF: |
| 684 | main.log.error(self.name + ": EOF exception found") |
| 685 | main.log.error(self.name + ": " + self.handle.before) |
| 686 | main.cleanup() |
| 687 | main.exit() |
| 688 | except: |
| 689 | main.log.info(self.name+" ::::::") |
| 690 | main.log.error( traceback.print_exc()) |
| 691 | main.log.info(self.name+" ::::::") |
| 692 | main.cleanup() |
| 693 | main.exit() |
| 694 | |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 695 | def onos_uninstall(self): |
| 696 | ''' |
| 697 | Calls the command: 'onos-uninstall' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 698 | Uninstalls ONOS from the designated cell machine, stopping |
| 699 | if needed |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 700 | ''' |
| 701 | try: |
| 702 | self.handle.sendline("") |
| 703 | self.handle.expect("\$") |
| 704 | self.handle.sendline("onos-uninstall") |
| 705 | self.handle.expect("\$") |
| 706 | |
andrewonlab | 8472745 | 2014-10-09 18:15:36 -0400 | [diff] [blame] | 707 | main.log.info("ONOS cell machine was uninstalled") |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 708 | #onos-uninstall command does not return any text |
| 709 | return main.TRUE |
| 710 | |
| 711 | except pexpect.EOF: |
| 712 | main.log.error(self.name + ": EOF exception found") |
| 713 | main.log.error(self.name + ": " + self.handle.before) |
| 714 | main.cleanup() |
| 715 | main.exit() |
| 716 | except: |
| 717 | main.log.info(self.name+" ::::::") |
| 718 | main.log.error( traceback.print_exc()) |
| 719 | main.log.info(self.name+" ::::::") |
| 720 | main.cleanup() |
| 721 | main.exit() |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 722 | |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 723 | def onos_kill(self, node_ip): |
| 724 | ''' |
| 725 | Calls the command: 'onos-kill [<node-ip>]' |
| 726 | "Remotely, and unceremoniously kills the ONOS instance running on |
| 727 | the specified cell machine" - Tom V |
| 728 | ''' |
| 729 | |
| 730 | try: |
| 731 | self.handle.sendline("") |
| 732 | self.handle.expect("\$") |
| 733 | self.handle.sendline("onos-kill " + str(node_ip)) |
| 734 | i = self.handle.expect([ |
| 735 | "\$", |
| 736 | "No\sroute\sto\shost", |
| 737 | "password:", |
| 738 | pexpect.TIMEOUT], timeout=20) |
| 739 | |
| 740 | if i == 0: |
| 741 | main.log.info("ONOS instance "+str(node_ip)+" was killed") |
| 742 | return main.TRUE |
| 743 | elif i == 1: |
| 744 | main.log.info("No route to host") |
| 745 | return main.FALSE |
| 746 | elif i == 2: |
| 747 | main.log.info("Passwordless login for host: "+str(node_ip)+ |
| 748 | " not configured") |
| 749 | return main.FALSE |
| 750 | else: |
| 751 | main.log.info("ONOS instasnce was not killed") |
| 752 | return main.FALSE |
| 753 | |
| 754 | except pexpect.EOF: |
| 755 | main.log.error(self.name + ": EOF exception found") |
| 756 | main.log.error(self.name + ": " + self.handle.before) |
| 757 | main.cleanup() |
| 758 | main.exit() |
| 759 | except: |
| 760 | main.log.info(self.name+" ::::::") |
| 761 | main.log.error( traceback.print_exc()) |
| 762 | main.log.info(self.name+" ::::::") |
| 763 | main.cleanup() |
| 764 | main.exit() |
| 765 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 766 | def onos_start_network(self, mntopo): |
| 767 | ''' |
| 768 | Calls the command 'onos-start-network [<mininet-topo>] |
| 769 | "remotely starts the specified topology on the cell's |
| 770 | mininet machine against all controllers configured in the |
| 771 | cell." |
| 772 | * Specify mininet topology file name for mntopo |
| 773 | * Topo files should be placed at: |
| 774 | ~/<your-onos-directory>/tools/test/topos |
| 775 | |
| 776 | NOTE: This function will take you to the mininet prompt |
| 777 | ''' |
| 778 | try: |
| 779 | if not mntopo: |
| 780 | main.log.error("You must specify a topo file to execute") |
| 781 | return main.FALSE |
| 782 | |
| 783 | mntopo = str(mntopo) |
| 784 | self.handle.sendline("") |
| 785 | self.handle.expect("\$") |
| 786 | |
| 787 | self.handle.sendline("onos-start-network " + mntopo) |
| 788 | self.handle.expect("mininet>") |
| 789 | main.log.info("Network started, entered mininet prompt") |
| 790 | |
| 791 | #TODO: Think about whether return is necessary or not |
| 792 | |
| 793 | except pexpect.EOF: |
| 794 | main.log.error(self.name + ": EOF exception found") |
| 795 | main.log.error(self.name + ": " + self.handle.before) |
| 796 | main.cleanup() |
| 797 | main.exit() |
| 798 | except: |
| 799 | main.log.info(self.name+" ::::::") |
| 800 | main.log.error( traceback.print_exc()) |
| 801 | main.log.info(self.name+" ::::::") |
| 802 | main.cleanup() |
| 803 | main.exit() |
| 804 | |
| 805 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 806 | def isup(self, node = ""): |
| 807 | ''' |
| 808 | 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] | 809 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 810 | Returns: main.TRUE if ONOS is running and main.FALSE on timeout |
| 811 | ''' |
| 812 | try: |
| 813 | self.handle.sendline("onos-wait-for-start " + node ) |
| 814 | self.handle.expect("onos-wait-for-start") |
| 815 | #NOTE: this timeout is arbitrary" |
| 816 | i = self.handle.expect(["\$", pexpect.TIMEOUT], timeout = 120) |
| 817 | if i == 0: |
| 818 | main.log.info(self.name + ": " + node + " is up") |
| 819 | return main.TRUE |
| 820 | elif i == 1: |
| 821 | #NOTE: since this function won't return until ONOS is ready, |
| 822 | # we will kill it on timeout |
| 823 | self.handle.sendline("\003") #Control-C |
| 824 | self.handle.expect("\$") |
| 825 | return main.FALSE |
| 826 | except pexpect.EOF: |
| 827 | main.log.error(self.name + ": EOF exception found") |
| 828 | main.log.error(self.name + ": " + self.handle.before) |
| 829 | main.cleanup() |
| 830 | main.exit() |
| 831 | except: |
| 832 | main.log.info(self.name+" ::::::") |
| 833 | main.log.error( traceback.print_exc()) |
| 834 | main.log.info(self.name+" ::::::") |
| 835 | main.cleanup() |
| 836 | main.exit() |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 837 | |
| 838 | |