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: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 85 | self.handle.sendline("") |
Jon Hall | f8d1098 | 2014-10-22 12:23:38 -0400 | [diff] [blame] | 86 | self.handle.expect("\$") |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 87 | self.handle.sendline("exit") |
| 88 | self.handle.expect("closed") |
| 89 | except pexpect.EOF: |
| 90 | main.log.error(self.name + ": EOF exception found") |
| 91 | main.log.error(self.name + ": " + self.handle.before) |
| 92 | except: |
| 93 | main.log.error(self.name + ": Connection failed to the host") |
| 94 | response = main.FALSE |
| 95 | return response |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 96 | |
| 97 | def onos_package(self): |
| 98 | ''' |
| 99 | Produce a self-contained tar.gz file that can be deployed |
| 100 | and executed on any platform with Java 7 JRE. |
| 101 | ''' |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 102 | |
| 103 | try: |
| 104 | self.handle.sendline("onos-package") |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 105 | self.handle.expect("onos-package") |
andrewonlab | e990790 | 2014-11-25 15:49:06 -0500 | [diff] [blame] | 106 | self.handle.expect("tar.gz",timeout=30) |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 107 | handle = str(self.handle.before) |
| 108 | main.log.info("onos-package command returned: "+ |
| 109 | handle) |
andrewonlab | 0748d2a | 2014-10-09 13:24:17 -0400 | [diff] [blame] | 110 | #As long as the sendline does not time out, |
| 111 | #return true. However, be careful to interpret |
| 112 | #the results of the onos-package command return |
| 113 | return main.TRUE |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 114 | |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 115 | except pexpect.EOF: |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 116 | main.log.error(self.name + ": EOF exception found") |
| 117 | main.log.error(self.name + ": " + self.handle.before) |
| 118 | except: |
| 119 | main.log.error("Failed to package ONOS") |
| 120 | main.cleanup() |
| 121 | main.exit() |
| 122 | |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 123 | def onos_build(self): |
| 124 | ''' |
| 125 | Use the pre defined script to build onos via mvn |
| 126 | ''' |
| 127 | |
| 128 | try: |
| 129 | self.handle.sendline("onos-build") |
| 130 | self.handle.expect("onos-build") |
| 131 | i = self.handle.expect([ |
| 132 | "BUILD SUCCESS", |
| 133 | "ERROR", |
| 134 | "BUILD FAILED"], timeout=120) |
| 135 | handle = str(self.handle.before) |
| 136 | |
| 137 | main.log.info("onos-build command returned: "+ |
| 138 | handle) |
| 139 | |
| 140 | if i == 0: |
| 141 | return main.TRUE |
| 142 | else: |
| 143 | return handle |
| 144 | |
| 145 | except pexpect.EOF: |
| 146 | main.log.error(self.name + ": EOF exception found") |
| 147 | main.log.error(self.name + ": " + self.handle.before) |
| 148 | except: |
| 149 | main.log.error("Failed to build ONOS") |
| 150 | main.cleanup() |
| 151 | main.exit() |
| 152 | |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 153 | def clean_install(self): |
| 154 | ''' |
| 155 | Runs mvn clean install in the root of the ONOS directory. |
| 156 | This will clean all ONOS artifacts then compile each module |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 157 | |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 158 | Returns: main.TRUE on success |
| 159 | On Failure, exits the test |
| 160 | ''' |
| 161 | try: |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 162 | main.log.info("Running 'mvn clean install' on " + str(self.name) + |
| 163 | ". This may take some time.") |
| 164 | self.handle.sendline("cd "+ self.home) |
| 165 | self.handle.expect("\$") |
| 166 | |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 167 | self.handle.sendline("") |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 168 | self.handle.expect("\$") |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 169 | self.handle.sendline("mvn clean install") |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 170 | self.handle.expect("mvn clean install") |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 171 | while 1: |
| 172 | i=self.handle.expect([ |
| 173 | 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s\ |
| 174 | Runtime\sEnvironment\sto\scontinue', |
| 175 | 'BUILD\sFAILURE', |
| 176 | 'BUILD\sSUCCESS', |
| 177 | 'ONOS\$', |
| 178 | pexpect.TIMEOUT],timeout=600) |
| 179 | if i == 0: |
| 180 | main.log.error(self.name + ":There is insufficient memory \ |
| 181 | for the Java Runtime Environment to continue.") |
| 182 | #return main.FALSE |
| 183 | main.cleanup() |
| 184 | main.exit() |
| 185 | if i == 1: |
| 186 | main.log.error(self.name + ": Build failure!") |
| 187 | #return main.FALSE |
| 188 | main.cleanup() |
| 189 | main.exit() |
| 190 | elif i == 2: |
| 191 | main.log.info(self.name + ": Build success!") |
| 192 | elif i == 3: |
| 193 | main.log.info(self.name + ": Build complete") |
Jon Hall | f8ef52c | 2014-10-09 19:37:33 -0400 | [diff] [blame] | 194 | #Print the build time |
| 195 | for line in self.handle.before.splitlines(): |
| 196 | if "Total time:" in line: |
| 197 | main.log.info(line) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 198 | self.handle.sendline("") |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 199 | self.handle.expect("\$", timeout=60) |
| 200 | return main.TRUE |
| 201 | elif i == 4: |
| 202 | main.log.error(self.name + ": mvn clean install TIMEOUT!") |
| 203 | #return main.FALSE |
| 204 | main.cleanup() |
| 205 | main.exit() |
| 206 | else: |
| 207 | main.log.error(self.name + ": unexpected response from \ |
| 208 | mvn clean install") |
| 209 | #return main.FALSE |
| 210 | main.cleanup() |
| 211 | main.exit() |
| 212 | except pexpect.EOF: |
| 213 | main.log.error(self.name + ": EOF exception found") |
| 214 | main.log.error(self.name + ": " + self.handle.before) |
| 215 | main.cleanup() |
| 216 | main.exit() |
| 217 | except: |
| 218 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 219 | main.log.error( traceback.print_exc() ) |
| 220 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 221 | main.cleanup() |
| 222 | main.exit() |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 223 | |
| 224 | def git_pull(self, comp1=""): |
| 225 | ''' |
| 226 | Assumes that "git pull" works without login |
| 227 | |
| 228 | This function will perform a git pull on the ONOS instance. |
| 229 | If used as git_pull("NODE") it will do git pull + NODE. This is |
| 230 | for the purpose of pulling from other nodes if necessary. |
| 231 | |
| 232 | Otherwise, this function will perform a git pull in the |
| 233 | ONOS repository. If it has any problems, it will return main.ERROR |
Shreya Shah | ee15f6c | 2014-10-28 18:12:30 -0400 | [diff] [blame] | 234 | If it successfully does a git_pull, it will return a 1 (main.TRUE) |
| 235 | If it has no updates, it will return 3. |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 236 | |
| 237 | ''' |
| 238 | try: |
| 239 | # main.log.info(self.name + ": Stopping ONOS") |
| 240 | #self.stop() |
| 241 | self.handle.sendline("cd " + self.home) |
| 242 | self.handle.expect("ONOS\$") |
| 243 | if comp1=="": |
| 244 | self.handle.sendline("git pull") |
| 245 | else: |
| 246 | self.handle.sendline("git pull " + comp1) |
| 247 | |
| 248 | uptodate = 0 |
| 249 | i=self.handle.expect(['fatal', |
| 250 | 'Username\sfor\s(.*):\s', |
| 251 | '\sfile(s*) changed,\s', |
| 252 | 'Already up-to-date', |
| 253 | 'Aborting', |
| 254 | 'You\sare\snot\scurrently\son\sa\sbranch', |
| 255 | 'You\sasked\sme\sto\spull\swithout\stelling\sme\swhich\sbranch\syou', |
| 256 | 'Pull\sis\snot\spossible\sbecause\syou\shave\sunmerged\sfiles', |
| 257 | pexpect.TIMEOUT], |
| 258 | timeout=300) |
| 259 | #debug |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 260 | #main.log.report(self.name +": DEBUG: \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after)) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 261 | if i==0: |
| 262 | main.log.error(self.name + ": Git pull had some issue...") |
| 263 | return main.ERROR |
| 264 | elif i==1: |
| 265 | main.log.error(self.name + ": Git Pull Asking for username. ") |
| 266 | return main.ERROR |
| 267 | elif i==2: |
| 268 | main.log.info(self.name + ": Git Pull - pulling repository now") |
| 269 | self.handle.expect("ONOS\$", 120) |
Shreya Shah | ee15f6c | 2014-10-28 18:12:30 -0400 | [diff] [blame] | 270 | return main.TRUE # So that only when git pull is done, we do mvn clean compile |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 271 | elif i==3: |
| 272 | main.log.info(self.name + ": Git Pull - Already up to date") |
Hari Krishna | 78c041f | 2014-12-19 14:04:33 -0800 | [diff] [blame^] | 273 | return i |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 274 | elif i==4: |
| 275 | main.log.info(self.name + ": Git Pull - Aborting... Are there conflicting git files?") |
| 276 | return main.ERROR |
| 277 | elif i==5: |
| 278 | main.log.info(self.name + ": Git Pull - You are not currently on a branch so git pull failed!") |
| 279 | return main.ERROR |
| 280 | elif i==6: |
| 281 | main.log.info(self.name + ": Git Pull - You have not configured an upstream branch to pull from. Git pull failed!") |
| 282 | return main.ERROR |
| 283 | elif i==7: |
| 284 | main.log.info(self.name + ": Git Pull - Pull is not possible because you have unmerged files.") |
| 285 | return main.ERROR |
| 286 | elif i==8: |
| 287 | main.log.error(self.name + ": Git Pull - TIMEOUT") |
| 288 | main.log.error(self.name + " Response was: " + str(self.handle.before)) |
| 289 | return main.ERROR |
| 290 | else: |
| 291 | main.log.error(self.name + ": Git Pull - Unexpected response, check for pull errors") |
| 292 | return main.ERROR |
| 293 | except pexpect.EOF: |
| 294 | main.log.error(self.name + ": EOF exception found") |
| 295 | main.log.error(self.name + ": " + self.handle.before) |
| 296 | main.cleanup() |
| 297 | main.exit() |
| 298 | except: |
| 299 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 300 | main.log.error( traceback.print_exc() ) |
| 301 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 302 | main.cleanup() |
| 303 | main.exit() |
| 304 | |
| 305 | def git_checkout(self, branch="master"): |
| 306 | ''' |
| 307 | Assumes that "git pull" works without login |
| 308 | |
| 309 | This function will perform a git git checkout on the ONOS instance. |
| 310 | If used as git_checkout("branch") it will do git checkout of the "branch". |
| 311 | |
| 312 | Otherwise, this function will perform a git checkout of the master |
| 313 | branch of the ONOS repository. If it has any problems, it will return |
| 314 | main.ERROR. |
| 315 | If the branch was already the specified branch, or the git checkout was |
| 316 | successful then the function will return main.TRUE. |
| 317 | |
| 318 | ''' |
| 319 | try: |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 320 | self.handle.sendline("cd " + self.home) |
| 321 | self.handle.expect("ONOS\$") |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 322 | main.log.info(self.name + ": Checking out git branch: " + branch + "...") |
| 323 | cmd = "git checkout "+branch |
| 324 | self.handle.sendline(cmd) |
| 325 | self.handle.expect(cmd) |
| 326 | i=self.handle.expect(['fatal', |
| 327 | 'Username\sfor\s(.*):\s', |
| 328 | 'Already\son\s\'', |
| 329 | 'Switched\sto\sbranch\s\'' + str(branch), |
| 330 | pexpect.TIMEOUT, |
| 331 | 'error: Your local changes to the following files would be overwritten by checkout:', |
| 332 | 'error: you need to resolve your current index first'],timeout=60) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 333 | |
| 334 | if i==0: |
| 335 | main.log.error(self.name + ": Git checkout had some issue...") |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 336 | main.log.error(self.name + ": " + self.handle.before) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 337 | return main.ERROR |
| 338 | elif i==1: |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 339 | main.log.error(self.name + ": Git checkout asking for username."\ |
| 340 | +" Please configure your local git repository to be able "\ |
| 341 | +"to access your remote repository passwordlessly") |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 342 | return main.ERROR |
| 343 | elif i==2: |
| 344 | main.log.info(self.name + ": Git Checkout %s : Already on this branch" %branch) |
| 345 | self.handle.expect("ONOS\$") |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 346 | #main.log.info("DEBUG: after checkout cmd = "+ self.handle.before) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 347 | return main.TRUE |
| 348 | elif i==3: |
| 349 | main.log.info(self.name + ": Git checkout %s - Switched to this branch" %branch) |
| 350 | self.handle.expect("ONOS\$") |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 351 | #main.log.info("DEBUG: after checkout cmd = "+ self.handle.before) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 352 | return main.TRUE |
| 353 | elif i==4: |
| 354 | main.log.error(self.name + ": Git Checkout- TIMEOUT") |
| 355 | main.log.error(self.name + " Response was: " + str(self.handle.before)) |
| 356 | return main.ERROR |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 357 | elif i==5: |
| 358 | self.handle.expect("Aborting") |
| 359 | main.log.error(self.name + ": Git checkout error: \n" + \ |
| 360 | "Your local changes to the following files would be overwritten by checkout:" + \ |
| 361 | str(self.handle.before)) |
| 362 | self.handle.expect("ONOS\$") |
| 363 | return main.ERROR |
| 364 | elif i==6: |
| 365 | main.log.error(self.name + ": Git checkout error: \n" + \ |
| 366 | "You need to resolve your current index first:" + \ |
| 367 | str(self.handle.before)) |
| 368 | self.handle.expect("ONOS\$") |
| 369 | return main.ERROR |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 370 | else: |
| 371 | main.log.error(self.name + ": Git Checkout - Unexpected response, check for pull errors") |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 372 | main.log.error(self.name + ": " + self.handle.before) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 373 | return main.ERROR |
| 374 | |
| 375 | except pexpect.EOF: |
| 376 | main.log.error(self.name + ": EOF exception found") |
| 377 | main.log.error(self.name + ": " + self.handle.before) |
| 378 | main.cleanup() |
| 379 | main.exit() |
| 380 | except: |
| 381 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 382 | main.log.error( traceback.print_exc() ) |
| 383 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 384 | main.cleanup() |
| 385 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 386 | |
Jon Hall | fd19120 | 2014-11-07 18:36:09 -0500 | [diff] [blame] | 387 | def get_version(self, report=False): |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 388 | ''' |
| 389 | Writes the COMMIT number to the report to be parsed by Jenkins data collecter. |
| 390 | ''' |
| 391 | try: |
| 392 | self.handle.sendline("export TERM=xterm-256color") |
| 393 | self.handle.expect("xterm-256color") |
| 394 | self.handle.expect("\$") |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 395 | self.handle.sendline("") |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 396 | self.handle.expect("\$") |
| 397 | self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller --decorate=short | grep -A 6 \"commit\" --color=never") |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 398 | #NOTE: for some reason there are backspaces inserted in this phrase when run from Jenkins on some tests |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 399 | self.handle.expect("never") |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 400 | self.handle.expect("\$") |
| 401 | response=(self.name +": \n"+ str(self.handle.before + self.handle.after)) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 402 | self.handle.sendline("cd " + self.home) |
| 403 | self.handle.expect("\$") |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 404 | lines=response.splitlines() |
| 405 | for line in lines: |
Jon Hall | fd19120 | 2014-11-07 18:36:09 -0500 | [diff] [blame] | 406 | print line |
| 407 | if report: |
| 408 | for line in lines[2:-1]: |
andrewonlab | ac5810a | 2014-11-18 14:33:03 -0500 | [diff] [blame] | 409 | #Bracket replacement is for Wiki-compliant |
| 410 | #formatting. '<' or '>' are interpreted |
| 411 | #as xml specific tags that cause errors |
| 412 | line = line.replace("<","[") |
| 413 | line = line.replace(">","]") |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 414 | main.log.report("\t" + line) |
Jon Hall | fd19120 | 2014-11-07 18:36:09 -0500 | [diff] [blame] | 415 | return lines[2] |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -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() |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 421 | except pexpect.TIMEOUT: |
| 422 | main.log.error(self.name + ": TIMEOUT exception found") |
| 423 | main.log.error(self.name + ": " + self.handle.before) |
| 424 | main.cleanup() |
| 425 | main.exit() |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 426 | except: |
| 427 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 428 | main.log.error( traceback.print_exc() ) |
| 429 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 430 | main.cleanup() |
| 431 | main.exit() |
| 432 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 433 | def create_cell_file(self, bench_ip, file_name, mn_ip_addrs, |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 434 | extra_feature_string, *onos_ip_addrs): |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 435 | ''' |
| 436 | Creates a cell file based on arguments |
| 437 | Required: |
| 438 | * Bench IP address (bench_ip) |
| 439 | - Needed to copy the cell file over |
| 440 | * File name of the cell file (file_name) |
| 441 | * Mininet IP address (mn_ip_addrs) |
| 442 | - Note that only 1 ip address is |
| 443 | supported currently |
| 444 | * ONOS IP addresses (onos_ip_addrs) |
| 445 | - Must be passed in as last arguments |
| 446 | |
| 447 | NOTE: Assumes cells are located at: |
| 448 | ~/<self.home>/tools/test/cells/ |
| 449 | ''' |
| 450 | |
| 451 | #Variable initialization |
| 452 | cell_directory = self.home + "/tools/test/cells/" |
| 453 | #We want to create the cell file in the dependencies directory |
| 454 | #of TestON first, then copy over to ONOS bench |
| 455 | temp_directory = "/tmp/" |
| 456 | #Create the cell file in the directory for writing (w+) |
| 457 | cell_file = open(temp_directory+file_name , 'w+') |
andrewonlab | d494049 | 2014-10-24 12:21:27 -0400 | [diff] [blame] | 458 | |
| 459 | comment = "" |
| 460 | comment_string = "#"+ comment |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 461 | #Feature string is hardcoded environment variables |
| 462 | #That you may wish to use by default on startup. |
| 463 | #Note that you may not want certain features listed |
| 464 | #on here. |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 465 | core_feature_string = "export ONOS_FEATURES=webconsole,onos-api,"+\ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 466 | "onos-cli,onos-openflow,"+extra_feature_string |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 467 | mn_string = "export OCN=" |
| 468 | onos_string = "export OC" |
| 469 | temp_count = 1 |
| 470 | |
| 471 | #Create ONOS_NIC ip address prefix |
| 472 | temp_onos_ip = onos_ip_addrs[0] |
| 473 | temp_list = [] |
| 474 | temp_list = temp_onos_ip.split(".") |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 475 | #Omit last element of list to format for NIC |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 476 | temp_list = temp_list[:-1] |
| 477 | #Structure the nic string ip |
andrewonlab | d494049 | 2014-10-24 12:21:27 -0400 | [diff] [blame] | 478 | nic_addr = ".".join(temp_list) + ".*" |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 479 | onos_nic_string = "export ONOS_NIC="+nic_addr |
| 480 | |
| 481 | try: |
| 482 | #Start writing to file |
andrewonlab | d494049 | 2014-10-24 12:21:27 -0400 | [diff] [blame] | 483 | cell_file.write(onos_nic_string + "\n") |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 484 | |
| 485 | for arg in onos_ip_addrs: |
| 486 | #For each argument in onos_ip_addrs, write to file |
| 487 | #Output should look like the following: |
andrewonlab | d494049 | 2014-10-24 12:21:27 -0400 | [diff] [blame] | 488 | # export OC1="10.128.20.11" |
| 489 | # export OC2="10.128.20.12" |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 490 | cell_file.write(onos_string + str(temp_count) + |
andrewonlab | d494049 | 2014-10-24 12:21:27 -0400 | [diff] [blame] | 491 | "=" + "\"" + arg + "\"" + "\n" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 492 | temp_count = temp_count + 1 |
| 493 | |
andrewonlab | d494049 | 2014-10-24 12:21:27 -0400 | [diff] [blame] | 494 | cell_file.write(mn_string +"\""+ mn_ip_addrs +"\""+ "\n") |
| 495 | cell_file.write(core_feature_string + "\n") |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 496 | cell_file.close() |
| 497 | |
| 498 | #We use os.system to send the command to TestON cluster |
| 499 | #to account for the case in which TestON is not located |
| 500 | #on the same cluster as the ONOS bench |
| 501 | #Note that even if TestON is located on the same cluster |
| 502 | #as ONOS bench, you must setup passwordless ssh |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 503 | #between TestON and ONOS bench in order to automate the test. |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 504 | os.system("scp "+temp_directory+file_name+ |
| 505 | " admin@"+bench_ip+":"+cell_directory) |
| 506 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 507 | return main.TRUE |
| 508 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 509 | except pexpect.EOF: |
| 510 | main.log.error(self.name + ": EOF exception found") |
| 511 | main.log.error(self.name + ": " + self.handle.before) |
| 512 | main.cleanup() |
| 513 | main.exit() |
| 514 | except: |
| 515 | main.log.info(self.name + ":::::::::") |
| 516 | main.log.error( traceback.print_exc() ) |
| 517 | main.log.info(":::::::") |
| 518 | main.cleanup() |
| 519 | main.exit() |
| 520 | |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 521 | def set_cell(self, cellname): |
| 522 | ''' |
| 523 | Calls 'cell <name>' to set the environment variables on ONOSbench |
| 524 | ''' |
| 525 | try: |
| 526 | if not cellname: |
| 527 | main.log.error("Must define cellname") |
| 528 | main.cleanup() |
| 529 | main.exit() |
| 530 | else: |
| 531 | self.handle.sendline("cell "+str(cellname)) |
| 532 | #Expect the cellname in the ONOS_CELL variable. |
| 533 | #Note that this variable name is subject to change |
| 534 | # and that this driver will have to change accordingly |
| 535 | self.handle.expect("ONOS_CELL="+str(cellname)) |
| 536 | handle_before = self.handle.before |
| 537 | handle_after = self.handle.after |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 538 | #Get the rest of the handle |
| 539 | self.handle.sendline("") |
| 540 | self.handle.expect("\$") |
| 541 | handle_more = self.handle.before |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 542 | |
| 543 | main.log.info("Cell call returned: "+handle_before+ |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 544 | handle_after + handle_more) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 545 | |
| 546 | return main.TRUE |
| 547 | |
| 548 | except pexpect.EOF: |
| 549 | main.log.error(self.name + ": EOF exception found") |
| 550 | main.log.error(self.name + ": " + self.handle.before) |
| 551 | main.cleanup() |
| 552 | main.exit() |
| 553 | except: |
| 554 | main.log.info(self.name+" ::::::") |
| 555 | main.log.error( traceback.print_exc()) |
| 556 | main.log.info(self.name+" ::::::") |
| 557 | main.cleanup() |
| 558 | main.exit() |
| 559 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 560 | def verify_cell(self): |
| 561 | ''' |
| 562 | Calls 'onos-verify-cell' to check for cell installation |
| 563 | ''' |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 564 | #TODO: Add meaningful expect value |
| 565 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 566 | try: |
| 567 | #Clean handle by sending empty and expecting $ |
| 568 | self.handle.sendline("") |
| 569 | self.handle.expect("\$") |
| 570 | self.handle.sendline("onos-verify-cell") |
| 571 | self.handle.expect("\$") |
| 572 | handle_before = self.handle.before |
| 573 | handle_after = self.handle.after |
| 574 | #Get the rest of the handle |
| 575 | self.handle.sendline("") |
| 576 | self.handle.expect("\$") |
| 577 | handle_more = self.handle.before |
| 578 | |
| 579 | main.log.info("Verify cell returned: "+handle_before+ |
| 580 | handle_after + handle_more) |
| 581 | |
| 582 | return main.TRUE |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 583 | except pexpect.EOF: |
| 584 | main.log.error(self.name + ": EOF exception found") |
| 585 | main.log.error(self.name + ": " + self.handle.before) |
| 586 | main.cleanup() |
| 587 | main.exit() |
| 588 | except: |
| 589 | main.log.info(self.name+" ::::::") |
| 590 | main.log.error( traceback.print_exc()) |
| 591 | main.log.info(self.name+" ::::::") |
| 592 | main.cleanup() |
| 593 | main.exit() |
| 594 | |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 595 | def onos_cli(self, ONOS_ip, cmdstr): |
| 596 | ''' |
| 597 | Uses 'onos' command to send various ONOS CLI arguments. |
| 598 | Required: |
| 599 | * ONOS_ip: specify the ip of the cell machine |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 600 | * cmdstr: specify the command string to send |
andrewonlab | 6e20c34 | 2014-10-10 18:08:48 -0400 | [diff] [blame] | 601 | |
| 602 | This function is intended to expose the entire karaf |
| 603 | CLI commands for ONOS. Try to use this function first |
| 604 | before attempting to write a ONOS CLI specific driver |
| 605 | function. |
| 606 | You can see a list of available 'cmdstr' arguments |
| 607 | by starting onos, and typing in 'onos' to enter the |
| 608 | onos> CLI. Then, type 'help' to see the list of |
| 609 | available commands. |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 610 | ''' |
| 611 | try: |
| 612 | if not ONOS_ip: |
| 613 | main.log.error("You must specify the IP address") |
| 614 | return main.FALSE |
| 615 | if not cmdstr: |
| 616 | main.log.error("You must specify the command string") |
| 617 | return main.FALSE |
| 618 | |
| 619 | cmdstr = str(cmdstr) |
| 620 | self.handle.sendline("") |
| 621 | self.handle.expect("\$") |
| 622 | |
| 623 | self.handle.sendline("onos -w " + ONOS_ip + " " + cmdstr) |
| 624 | self.handle.expect("\$") |
| 625 | |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 626 | handle_before = self.handle.before |
| 627 | print "handle_before = ", self.handle.before |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 628 | handle_after = str(self.handle.after) |
| 629 | |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 630 | #self.handle.sendline("") |
| 631 | #self.handle.expect("\$") |
| 632 | #handle_more = str(self.handle.before) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 633 | |
| 634 | main.log.info("Command sent successfully") |
| 635 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 636 | #Obtain return handle that consists of result from |
| 637 | #the onos command. The string may need to be |
| 638 | #configured further. |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 639 | #return_string = handle_before + handle_after |
| 640 | return_string = handle_before |
| 641 | print "return_string = ", return_string |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 642 | return return_string |
| 643 | |
| 644 | except pexpect.EOF: |
| 645 | main.log.error(self.name + ": EOF exception found") |
| 646 | main.log.error(self.name + ": " + self.handle.before) |
| 647 | main.cleanup() |
| 648 | main.exit() |
| 649 | except: |
| 650 | main.log.info(self.name+" ::::::") |
| 651 | main.log.error( traceback.print_exc()) |
| 652 | main.log.info(self.name+" ::::::") |
| 653 | main.cleanup() |
| 654 | main.exit() |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 655 | |
| 656 | def onos_install(self, options="-f", node = ""): |
| 657 | ''' |
| 658 | Installs ONOS bits on the designated cell machine. |
| 659 | If -f option is provided, it also forces an uninstall. |
| 660 | Presently, install also includes onos-push-bits and |
| 661 | onos-config within. |
| 662 | The node option allows you to selectively only push the jar |
| 663 | files to certain onos nodes |
| 664 | |
| 665 | Returns: main.TRUE on success and main.FALSE on failure |
| 666 | ''' |
| 667 | try: |
andrewonlab | 114768a | 2014-11-14 12:44:44 -0500 | [diff] [blame] | 668 | if options: |
| 669 | self.handle.sendline("onos-install " + options + " " + node) |
| 670 | else: |
| 671 | self.handle.sendline("onos-install "+node) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 672 | self.handle.expect("onos-install ") |
| 673 | #NOTE: this timeout may need to change depending on the network and size of ONOS |
| 674 | i=self.handle.expect(["Network\sis\sunreachable", |
| 675 | "onos\sstart/running,\sprocess", |
andrewonlab | d9a73a7 | 2014-11-14 17:28:21 -0500 | [diff] [blame] | 676 | "ONOS\sis\salready\sinstalled", |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 677 | pexpect.TIMEOUT],timeout=60) |
| 678 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 679 | if i == 0: |
| 680 | main.log.warn("Network is unreachable") |
| 681 | return main.FALSE |
| 682 | elif i == 1: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 683 | main.log.info("ONOS was installed on " + node + " and started") |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 684 | return main.TRUE |
andrewonlab | d9a73a7 | 2014-11-14 17:28:21 -0500 | [diff] [blame] | 685 | elif i == 2: |
| 686 | main.log.info("ONOS is already installed on "+node) |
| 687 | return main.TRUE |
| 688 | elif i == 3: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 689 | main.log.info("Installation of ONOS on " + node + " timed out") |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 690 | return main.FALSE |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 691 | |
andrewonlab | d9a73a7 | 2014-11-14 17:28:21 -0500 | [diff] [blame] | 692 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 693 | except pexpect.EOF: |
| 694 | main.log.error(self.name + ": EOF exception found") |
| 695 | main.log.error(self.name + ": " + self.handle.before) |
| 696 | main.cleanup() |
| 697 | main.exit() |
| 698 | except: |
| 699 | main.log.info(self.name+" ::::::") |
| 700 | main.log.error( traceback.print_exc()) |
| 701 | main.log.info(self.name+" ::::::") |
| 702 | main.cleanup() |
| 703 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 704 | |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 705 | def onos_start(self, node_ip): |
| 706 | ''' |
| 707 | Calls onos command: 'onos-service [<node-ip>] start' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 708 | This command is a remote management of the ONOS upstart daemon |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 709 | ''' |
| 710 | |
| 711 | try: |
| 712 | self.handle.sendline("") |
| 713 | self.handle.expect("\$") |
| 714 | self.handle.sendline("onos-service "+str(node_ip)+ |
| 715 | " start") |
| 716 | i = self.handle.expect([ |
| 717 | "Job\sis\salready\srunning", |
| 718 | "start/running", |
| 719 | "Unknown\sinstance", |
Shreya Shah | d01153d | 2014-10-23 15:08:56 -0400 | [diff] [blame] | 720 | pexpect.TIMEOUT],timeout=120) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 721 | |
| 722 | if i == 0: |
| 723 | main.log.info("Service is already running") |
| 724 | return main.TRUE |
| 725 | elif i == 1: |
| 726 | main.log.info("ONOS service started") |
| 727 | return main.TRUE |
| 728 | else: |
| 729 | main.log.error("ONOS service failed to start") |
| 730 | main.cleanup() |
| 731 | main.exit() |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 732 | except pexpect.EOF: |
| 733 | main.log.error(self.name + ": EOF exception found") |
| 734 | main.log.error(self.name + ": " + self.handle.before) |
| 735 | main.cleanup() |
| 736 | main.exit() |
| 737 | except: |
| 738 | main.log.info(self.name+" ::::::") |
| 739 | main.log.error( traceback.print_exc()) |
| 740 | main.log.info(self.name+" ::::::") |
| 741 | main.cleanup() |
| 742 | main.exit() |
| 743 | |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 744 | def onos_stop(self, node_ip): |
| 745 | ''' |
| 746 | Calls onos command: 'onos-service [<node-ip>] stop' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 747 | This command is a remote management of the ONOS upstart daemon |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 748 | ''' |
| 749 | try: |
| 750 | self.handle.sendline("") |
| 751 | self.handle.expect("\$") |
| 752 | self.handle.sendline("onos-service "+str(node_ip)+ |
| 753 | " stop") |
| 754 | i = self.handle.expect([ |
| 755 | "stop/waiting", |
| 756 | "Unknown\sinstance", |
| 757 | pexpect.TIMEOUT],timeout=60) |
| 758 | |
| 759 | if i == 0: |
| 760 | main.log.info("ONOS service stopped") |
| 761 | return main.TRUE |
| 762 | elif i == 1: |
| 763 | main.log.info("Unknown ONOS instance specified: "+ |
| 764 | str(node_ip)) |
| 765 | return main.FALSE |
| 766 | else: |
| 767 | main.log.error("ONOS service failed to stop") |
| 768 | return main.FALSE |
| 769 | |
| 770 | except pexpect.EOF: |
| 771 | main.log.error(self.name + ": EOF exception found") |
| 772 | main.log.error(self.name + ": " + self.handle.before) |
| 773 | main.cleanup() |
| 774 | main.exit() |
| 775 | except: |
| 776 | main.log.info(self.name+" ::::::") |
| 777 | main.log.error( traceback.print_exc()) |
| 778 | main.log.info(self.name+" ::::::") |
| 779 | main.cleanup() |
| 780 | main.exit() |
andrewonlab | 99d3f7f | 2014-11-13 17:45:08 -0500 | [diff] [blame] | 781 | |
andrewonlab | a6f7d88 | 2014-11-13 17:32:24 -0500 | [diff] [blame] | 782 | def onos_uninstall(self, node_ip=""): |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 783 | ''' |
| 784 | Calls the command: 'onos-uninstall' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 785 | Uninstalls ONOS from the designated cell machine, stopping |
| 786 | if needed |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 787 | ''' |
| 788 | try: |
| 789 | self.handle.sendline("") |
| 790 | self.handle.expect("\$") |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 791 | self.handle.sendline( "onos-uninstall "+str(node_ip) ) |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 792 | self.handle.expect("\$") |
| 793 | |
andrewonlab | 9dfd208 | 2014-11-13 17:44:03 -0500 | [diff] [blame] | 794 | main.log.info("ONOS "+node_ip+" was uninstalled") |
| 795 | |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 796 | #onos-uninstall command does not return any text |
| 797 | return main.TRUE |
| 798 | |
| 799 | except pexpect.EOF: |
| 800 | main.log.error(self.name + ": EOF exception found") |
| 801 | main.log.error(self.name + ": " + self.handle.before) |
| 802 | main.cleanup() |
| 803 | main.exit() |
| 804 | except: |
| 805 | main.log.info(self.name+" ::::::") |
| 806 | main.log.error( traceback.print_exc()) |
| 807 | main.log.info(self.name+" ::::::") |
| 808 | main.cleanup() |
| 809 | main.exit() |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 810 | |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 811 | def onos_die(self, node_ip): |
| 812 | ''' |
| 813 | Issues the command 'onos-die <node-ip>' |
| 814 | This command calls onos-kill and also stops the node |
| 815 | ''' |
| 816 | try: |
| 817 | self.handle.sendline("") |
| 818 | self.handle.expect("\$") |
| 819 | cmd_str = "onos-kill "+str(node_ip) |
| 820 | self.handle.sendline(cmd_str) |
| 821 | i = self.handle.expect([ |
| 822 | "Killing\sONOS", |
| 823 | "ONOS\sprocess\sis\snot\srunning", |
| 824 | pexpect.TIMEOUT], timeout=20) |
| 825 | if i == 0: |
| 826 | main.log.info("ONOS instance "+str(node_ip)+ |
| 827 | " was killed and stopped") |
| 828 | return main.TRUE |
| 829 | elif i == 1: |
| 830 | main.log.info("ONOS process was not running") |
| 831 | return main.FALSE |
| 832 | except pexpect.EOF: |
| 833 | main.log.error(self.name + ": EOF exception found") |
| 834 | main.log.error(self.name + ": " + self.handle.before) |
| 835 | main.cleanup() |
| 836 | main.exit() |
| 837 | except: |
| 838 | main.log.info(self.name+" ::::::") |
| 839 | main.log.error( traceback.print_exc()) |
| 840 | main.log.info(self.name+" ::::::") |
| 841 | main.cleanup() |
| 842 | main.exit() |
| 843 | |
| 844 | |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 845 | def onos_kill(self, node_ip): |
| 846 | ''' |
| 847 | Calls the command: 'onos-kill [<node-ip>]' |
| 848 | "Remotely, and unceremoniously kills the ONOS instance running on |
| 849 | the specified cell machine" - Tom V |
| 850 | ''' |
| 851 | |
| 852 | try: |
| 853 | self.handle.sendline("") |
| 854 | self.handle.expect("\$") |
| 855 | self.handle.sendline("onos-kill " + str(node_ip)) |
| 856 | i = self.handle.expect([ |
| 857 | "\$", |
| 858 | "No\sroute\sto\shost", |
| 859 | "password:", |
| 860 | pexpect.TIMEOUT], timeout=20) |
| 861 | |
| 862 | if i == 0: |
| 863 | main.log.info("ONOS instance "+str(node_ip)+" was killed") |
| 864 | return main.TRUE |
| 865 | elif i == 1: |
| 866 | main.log.info("No route to host") |
| 867 | return main.FALSE |
| 868 | elif i == 2: |
| 869 | main.log.info("Passwordless login for host: "+str(node_ip)+ |
| 870 | " not configured") |
| 871 | return main.FALSE |
| 872 | else: |
| 873 | main.log.info("ONOS instasnce was not killed") |
| 874 | return main.FALSE |
| 875 | |
| 876 | except pexpect.EOF: |
| 877 | main.log.error(self.name + ": EOF exception found") |
| 878 | main.log.error(self.name + ": " + self.handle.before) |
| 879 | main.cleanup() |
| 880 | main.exit() |
| 881 | except: |
| 882 | main.log.info(self.name+" ::::::") |
| 883 | main.log.error( traceback.print_exc()) |
| 884 | main.log.info(self.name+" ::::::") |
| 885 | main.cleanup() |
| 886 | main.exit() |
| 887 | |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 888 | def onos_remove_raft_logs(self): |
| 889 | ''' |
| 890 | Removes Raft / Copy cat files from ONOS to ensure |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 891 | a cleaner environment. |
| 892 | |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 893 | Description: |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 894 | Stops all ONOS defined in the cell, |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 895 | wipes the raft / copycat log files |
| 896 | ''' |
| 897 | try: |
| 898 | self.handle.sendline("") |
| 899 | self.handle.expect("\$") |
| 900 | self.handle.sendline("onos-remove-raft-logs") |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 901 | #Sometimes this command hangs |
andrewonlab | eb7b107 | 2014-11-25 15:50:07 -0500 | [diff] [blame] | 902 | i = self.handle.expect(["\$", pexpect.TIMEOUT], |
| 903 | timeout=120) |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 904 | if i == 1: |
andrewonlab | eb7b107 | 2014-11-25 15:50:07 -0500 | [diff] [blame] | 905 | i = self.handle.expect(["\$", pexpect.TIMEOUT], |
| 906 | timeout=120) |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 907 | if i == 1: |
| 908 | return main.FALSE |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 909 | self.handle.sendline("") |
| 910 | self.handle.expect("\$") |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 911 | return main.TRUE |
| 912 | |
| 913 | except pexpect.EOF: |
| 914 | main.log.error(self.name + ": EOF exception found") |
| 915 | main.log.error(self.name + ": " + self.handle.before) |
| 916 | main.cleanup() |
| 917 | main.exit() |
| 918 | except: |
| 919 | main.log.info(self.name+" ::::::") |
| 920 | main.log.error( traceback.print_exc()) |
| 921 | main.log.info(self.name+" ::::::") |
| 922 | main.cleanup() |
| 923 | main.exit() |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 924 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 925 | def onos_start_network(self, mntopo): |
| 926 | ''' |
| 927 | Calls the command 'onos-start-network [<mininet-topo>] |
| 928 | "remotely starts the specified topology on the cell's |
| 929 | mininet machine against all controllers configured in the |
| 930 | cell." |
| 931 | * Specify mininet topology file name for mntopo |
| 932 | * Topo files should be placed at: |
| 933 | ~/<your-onos-directory>/tools/test/topos |
| 934 | |
| 935 | NOTE: This function will take you to the mininet prompt |
| 936 | ''' |
| 937 | try: |
| 938 | if not mntopo: |
| 939 | main.log.error("You must specify a topo file to execute") |
| 940 | return main.FALSE |
| 941 | |
| 942 | mntopo = str(mntopo) |
| 943 | self.handle.sendline("") |
| 944 | self.handle.expect("\$") |
| 945 | |
| 946 | self.handle.sendline("onos-start-network " + mntopo) |
| 947 | self.handle.expect("mininet>") |
| 948 | main.log.info("Network started, entered mininet prompt") |
| 949 | |
| 950 | #TODO: Think about whether return is necessary or not |
| 951 | |
| 952 | except pexpect.EOF: |
| 953 | main.log.error(self.name + ": EOF exception found") |
| 954 | main.log.error(self.name + ": " + self.handle.before) |
| 955 | main.cleanup() |
| 956 | main.exit() |
| 957 | except: |
| 958 | main.log.info(self.name+" ::::::") |
| 959 | main.log.error( traceback.print_exc()) |
| 960 | main.log.info(self.name+" ::::::") |
| 961 | main.cleanup() |
| 962 | main.exit() |
| 963 | |
| 964 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 965 | def isup(self, node = ""): |
| 966 | ''' |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 967 | Run's onos-wait-for-start which only returns once ONOS is at run |
| 968 | level 100(ready for use) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 969 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 970 | Returns: main.TRUE if ONOS is running and main.FALSE on timeout |
| 971 | ''' |
| 972 | try: |
| 973 | self.handle.sendline("onos-wait-for-start " + node ) |
| 974 | self.handle.expect("onos-wait-for-start") |
| 975 | #NOTE: this timeout is arbitrary" |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 976 | i = self.handle.expect(["\$", pexpect.TIMEOUT], timeout = 120) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 977 | if i == 0: |
| 978 | main.log.info(self.name + ": " + node + " is up") |
| 979 | return main.TRUE |
| 980 | elif i == 1: |
| 981 | #NOTE: since this function won't return until ONOS is ready, |
| 982 | # we will kill it on timeout |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 983 | main.log.error("ONOS has not started yet") |
| 984 | self.handle.send("\x03") #Control-C |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 985 | self.handle.expect("\$") |
| 986 | return main.FALSE |
| 987 | except pexpect.EOF: |
| 988 | main.log.error(self.name + ": EOF exception found") |
| 989 | main.log.error(self.name + ": " + self.handle.before) |
| 990 | main.cleanup() |
| 991 | main.exit() |
| 992 | except: |
| 993 | main.log.info(self.name+" ::::::") |
| 994 | main.log.error( traceback.print_exc()) |
| 995 | main.log.info(self.name+" ::::::") |
| 996 | main.cleanup() |
| 997 | main.exit() |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 998 | |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 999 | def push_test_intents_shell(self, dpid_src, dpid_dst, num_intents, |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1000 | dir_file, onos_ip, num_mult="", app_id="", report=True, |
| 1001 | options=""): |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1002 | ''' |
| 1003 | Description: |
| 1004 | Use the linux prompt to push test intents to |
| 1005 | better parallelize the results than the CLI |
| 1006 | Required: |
| 1007 | * dpid_src: specify source dpid |
| 1008 | * dpid_dst: specify destination dpid |
| 1009 | * num_intents: specify number of intents to push |
| 1010 | * dir_file: specify directory and file name to save |
| 1011 | results |
| 1012 | * onos_ip: specify the IP of ONOS to install on |
| 1013 | NOTE: |
| 1014 | You must invoke this command at linux shell prompt |
| 1015 | ''' |
| 1016 | try: |
| 1017 | #Create the string to sendline |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1018 | if options: |
| 1019 | base_cmd = "onos "+str(onos_ip)+" push-test-intents "+\ |
| 1020 | options+" " |
| 1021 | else: |
| 1022 | base_cmd = "onos "+str(onos_ip)+" push-test-intents " |
| 1023 | |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1024 | add_dpid = base_cmd + str(dpid_src) + " " + str(dpid_dst) |
| 1025 | if not num_mult: |
| 1026 | add_intents = add_dpid + " " + str(num_intents) |
| 1027 | elif num_mult: |
| 1028 | add_intents = add_dpid + " " + str(num_intents) + " " +\ |
| 1029 | str(num_mult) |
| 1030 | if app_id: |
| 1031 | add_app = add_intents + " " + str(app_id) |
| 1032 | else: |
| 1033 | add_app = add_intents |
| 1034 | |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1035 | if report: |
| 1036 | send_cmd = add_app + " > " + str(dir_file) + " &" |
| 1037 | else: |
| 1038 | send_cmd = add_app + " &" |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1039 | main.log.info("Send cmd: "+send_cmd) |
| 1040 | |
| 1041 | self.handle.sendline(send_cmd) |
| 1042 | |
| 1043 | except pexpect.EOF: |
| 1044 | main.log.error(self.name + ": EOF exception found") |
| 1045 | main.log.error(self.name + ": " + self.handle.before) |
| 1046 | main.cleanup() |
| 1047 | main.exit() |
| 1048 | except: |
| 1049 | main.log.info(self.name+" ::::::") |
| 1050 | main.log.error( traceback.print_exc()) |
| 1051 | main.log.info(self.name+" ::::::") |
| 1052 | main.cleanup() |
| 1053 | main.exit() |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 1054 | |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 1055 | def get_topology(self,topology_output): |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1056 | ''' |
| 1057 | parses the onos:topology output |
| 1058 | Returns: a topology dict populated by the key values found in |
| 1059 | the cli command. |
| 1060 | ''' |
| 1061 | |
| 1062 | try: |
| 1063 | #call the cli to get the topology summary |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 1064 | #cmdstr = "onos:topology" |
| 1065 | #cli_result = self.onos_cli(ip, cmdstr) |
| 1066 | #print "cli_result = ", cli_result |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1067 | |
| 1068 | #Parse the output |
| 1069 | topology = {} |
| 1070 | #for line in cli_result.split("\n"): |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 1071 | for line in topology_output.splitlines(): |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1072 | if not line.startswith("time="): |
| 1073 | continue |
| 1074 | #else |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1075 | #print line |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1076 | for var in line.split(","): |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 1077 | #print "'"+var+"'" |
| 1078 | #print "'"+var.strip()+"'" |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1079 | key, value = var.strip().split("=") |
| 1080 | topology[key] = value |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1081 | #print "topology = ", topology |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1082 | devices = topology.get('devices', False) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1083 | #print "devices = ", devices |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1084 | links = topology.get('links', False) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1085 | #print "links = ", links |
| 1086 | SCCs = topology.get('SCC(s)', False) |
| 1087 | #print "SCCs = ", SCCs |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1088 | paths = topology.get('paths', False) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1089 | #print "paths = ", paths |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1090 | |
| 1091 | return topology |
| 1092 | except pexpect.EOF: |
| 1093 | main.log.error(self.name + ": EOF exception found") |
| 1094 | main.log.error(self.name + ": " + self.handle.before) |
| 1095 | main.cleanup() |
| 1096 | main.exit() |
| 1097 | except: |
| 1098 | main.log.info(self.name+" ::::::") |
| 1099 | main.log.error( traceback.print_exc()) |
| 1100 | main.log.info(self.name+" ::::::") |
| 1101 | main.cleanup() |
| 1102 | main.exit() |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 1103 | |
| 1104 | |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1105 | |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 1106 | def check_status(self, topology_result, numoswitch, numolink, log_level="info"): |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1107 | ''' |
| 1108 | Checks the number of swithes & links that ONOS sees against the |
| 1109 | supplied values. By default this will report to main.log, but the |
| 1110 | log level can be specifid. |
| 1111 | |
| 1112 | Params: ip = ip used for the onos cli |
| 1113 | numoswitch = expected number of switches |
| 1114 | numlink = expected number of links |
| 1115 | log_level = level to log to. Currently accepts 'info', 'warn' and 'report' |
| 1116 | |
| 1117 | |
| 1118 | log_level can |
| 1119 | |
| 1120 | Returns: main.TRUE if the number of switchs and links are correct, |
| 1121 | main.FALSE if the numer of switches and links is incorrect, |
| 1122 | and main.ERROR otherwise |
| 1123 | ''' |
| 1124 | |
| 1125 | try: |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 1126 | topology = self.get_topology(topology_result) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1127 | if topology == {}: |
| 1128 | return main.ERROR |
| 1129 | output = "" |
| 1130 | #Is the number of switches is what we expected |
| 1131 | devices = topology.get('devices',False) |
| 1132 | links = topology.get('links',False) |
| 1133 | if devices == False or links == False: |
| 1134 | return main.ERROR |
| 1135 | switch_check = ( int(devices) == int(numoswitch) ) |
| 1136 | #Is the number of links is what we expected |
| 1137 | link_check = ( int(links) == int(numolink) ) |
| 1138 | if (switch_check and link_check): |
| 1139 | #We expected the correct numbers |
| 1140 | output = output + "The number of links and switches match "\ |
| 1141 | + "what was expected" |
| 1142 | result = main.TRUE |
| 1143 | else: |
| 1144 | output = output + \ |
| 1145 | "The number of links and switches does not match what was expected" |
| 1146 | result = main.FALSE |
| 1147 | output = output + "\n ONOS sees %i devices (%i expected) and %i links (%i expected)"\ |
| 1148 | % ( int(devices), int(numoswitch), int(links), int(numolink) ) |
| 1149 | if log_level == "report": |
| 1150 | main.log.report(output) |
| 1151 | elif log_level == "warn": |
| 1152 | main.log.warn(output) |
| 1153 | else: |
| 1154 | main.log.info(output) |
| 1155 | return result |
| 1156 | except pexpect.EOF: |
| 1157 | main.log.error(self.name + ": EOF exception found") |
| 1158 | main.log.error(self.name + ": " + self.handle.before) |
| 1159 | main.cleanup() |
| 1160 | main.exit() |
| 1161 | except: |
| 1162 | main.log.info(self.name+" ::::::") |
| 1163 | main.log.error( traceback.print_exc()) |
| 1164 | main.log.info(self.name+" ::::::") |
| 1165 | main.cleanup() |
| 1166 | main.exit() |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1167 | |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1168 | def tshark_pcap(self, interface, dir_file): |
| 1169 | ''' |
| 1170 | Capture all packet activity and store in specified |
| 1171 | directory/file |
| 1172 | |
| 1173 | Required: |
| 1174 | * interface: interface to capture |
| 1175 | * dir: directory/filename to store pcap |
| 1176 | ''' |
| 1177 | self.handle.sendline("") |
| 1178 | self.handle.expect("\$") |
| 1179 | |
| 1180 | self.handle.sendline("tshark -i "+str(interface)+ |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1181 | " -t e -w "+str(dir_file)+ " &") |
| 1182 | self.handle.sendline("\r") |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1183 | self.handle.expect("Capturing on") |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1184 | self.handle.sendline("\r") |
| 1185 | self.handle.expect("\$") |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1186 | |
| 1187 | main.log.info("Tshark started capturing files on "+ |
| 1188 | str(interface)+ " and saving to directory: "+ |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1189 | str(dir_file)) |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 1190 | |
shahshreya | 4d79aab | 2014-11-07 15:20:41 -0800 | [diff] [blame] | 1191 | |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 1192 | def run_onos_topo_cfg(self, instance_name, json_file): |
shahshreya | 4d79aab | 2014-11-07 15:20:41 -0800 | [diff] [blame] | 1193 | ''' |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 1194 | On ONOS bench, run this command: ./~/ONOS/tools/test/bin/onos-topo-cfg $OC1 filename |
shahshreya | 4d79aab | 2014-11-07 15:20:41 -0800 | [diff] [blame] | 1195 | which starts the rest and copies the json file to the onos instance |
| 1196 | ''' |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 1197 | try: |
| 1198 | self.handle.sendline("") |
| 1199 | self.handle.expect("\$") |
| 1200 | self.handle.sendline("cd ~/ONOS/tools/test/bin") |
| 1201 | self.handle.expect("/bin$") |
| 1202 | cmd = "./onos-topo-cfg " +instance_name +" " +json_file |
| 1203 | print "cmd = ", cmd |
| 1204 | self.handle.sendline(cmd) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1205 | self.handle.expect("\$") |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 1206 | self.handle.sendline("cd ~") |
| 1207 | self.handle.expect("\$") |
| 1208 | return main.TRUE |
| 1209 | except: |
| 1210 | return main.FALSE |
| 1211 | |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1212 | def tshark_grep(self, grep, directory, interface='eth0'): |
| 1213 | ''' |
| 1214 | Required: |
| 1215 | * grep string |
| 1216 | * directory to store results |
| 1217 | Optional: |
| 1218 | * interface - default: eth0 |
| 1219 | Description: |
| 1220 | Uses tshark command to grep specific group of packets |
| 1221 | and stores the results to specified directory. |
| 1222 | The timestamp is hardcoded to be in epoch |
| 1223 | ''' |
| 1224 | self.handle.sendline("") |
| 1225 | self.handle.expect("\$") |
andrewonlab | efd7f3d | 2014-10-21 16:02:31 -0400 | [diff] [blame] | 1226 | self.handle.sendline("") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1227 | self.handle.sendline("tshark -i "+str(interface)+ |
andrewonlab | d494049 | 2014-10-24 12:21:27 -0400 | [diff] [blame] | 1228 | " -t e | grep --line-buffered \""+str(grep)+"\" >"+directory+" &") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1229 | self.handle.sendline("\r") |
| 1230 | self.handle.expect("Capturing on") |
| 1231 | self.handle.sendline("\r") |
| 1232 | self.handle.expect("\$") |
| 1233 | |
| 1234 | def tshark_stop(self): |
| 1235 | ''' |
| 1236 | Removes wireshark files from /tmp and kills all tshark processes |
| 1237 | ''' |
andrewonlab | 5ba0d9e | 2014-10-24 13:32:23 -0400 | [diff] [blame] | 1238 | #Remove all pcap from previous captures |
| 1239 | self.execute(cmd="sudo rm /tmp/wireshark*") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1240 | self.handle.sendline("") |
| 1241 | self.handle.sendline("sudo kill -9 `ps -ef | grep \"tshark -i\" |"+ |
| 1242 | " grep -v grep | awk '{print $2}'`") |
| 1243 | self.handle.sendline("") |
| 1244 | main.log.info("Tshark stopped") |
| 1245 | |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1246 | def ptpd(self, args): |
| 1247 | ''' |
| 1248 | Initiate ptp with user-specified args. |
| 1249 | Required: |
| 1250 | * args: specify string of args after command |
| 1251 | 'sudo ptpd' |
| 1252 | ''' |
| 1253 | try: |
| 1254 | self.handle.sendline("sudo ptpd "+str(args)) |
andrewonlab | 978dff6 | 2014-10-29 16:53:35 -0400 | [diff] [blame] | 1255 | i = self.handle.expect([ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1256 | "Multiple", |
| 1257 | "Error", |
| 1258 | "\$"]) |
| 1259 | self.handle.expect("\$") |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1260 | |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1261 | if i == 0: |
| 1262 | handle = self.handle.before |
| 1263 | main.log.info("ptpd returned an error: "+ |
| 1264 | str(handle)) |
| 1265 | return handle |
| 1266 | elif i == 1: |
| 1267 | handle = self.handle.before |
| 1268 | main.log.error("ptpd returned an error: "+ |
| 1269 | str(handle)) |
| 1270 | return handle |
| 1271 | else: |
| 1272 | return main.TRUE |
| 1273 | |
| 1274 | except pexpect.EOF: |
| 1275 | main.log.error(self.name + ": EOF exception found") |
| 1276 | main.log.error(self.name + ": " + self.handle.before) |
| 1277 | main.cleanup() |
| 1278 | main.exit() |
| 1279 | except: |
| 1280 | main.log.info(self.name+" ::::::") |
| 1281 | main.log.error( traceback.print_exc()) |
| 1282 | main.log.info(self.name+" ::::::") |
| 1283 | main.cleanup() |
| 1284 | main.exit() |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1285 | |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1286 | def cp_logs_to_dir(self, log_to_copy, |
| 1287 | dest_dir, copy_file_name=""): |
| 1288 | ''' |
| 1289 | Copies logs to a desired directory. |
| 1290 | Current implementation of ONOS deletes its karaf |
| 1291 | logs on every iteration. For debugging purposes, |
| 1292 | you may want to use this function to capture |
| 1293 | certain karaf logs. (or any other logs if needed) |
| 1294 | Localtime will be attached to the filename |
| 1295 | |
| 1296 | Required: |
| 1297 | * log_to_copy: specify directory and log name to |
| 1298 | copy. |
| 1299 | ex) /opt/onos/log/karaf.log.1 |
| 1300 | For copying multiple files, leave copy_file_name |
| 1301 | empty and only specify dest_dir - |
| 1302 | ex) /opt/onos/log/karaf* |
| 1303 | * dest_dir: specify directory to copy to. |
| 1304 | ex) /tmp/ |
| 1305 | Optional: |
| 1306 | * copy_file_name: If you want to rename the log |
| 1307 | file, specify copy_file_name. This will not work |
| 1308 | with multiple file copying |
| 1309 | ''' |
| 1310 | try: |
| 1311 | localtime = time.strftime('%x %X') |
| 1312 | localtime = localtime.replace("/","") |
| 1313 | localtime = localtime.replace(" ","_") |
| 1314 | localtime = localtime.replace(":","") |
| 1315 | if dest_dir[-1:] != "/": |
| 1316 | dest_dir += "/" |
| 1317 | |
| 1318 | if copy_file_name: |
| 1319 | self.handle.sendline("cp "+str(log_to_copy)+ |
| 1320 | " "+str(dest_dir)+str(copy_file_name)+ |
| 1321 | localtime) |
| 1322 | self.handle.expect("cp") |
| 1323 | self.handle.expect("\$") |
| 1324 | else: |
| 1325 | self.handle.sendline("cp "+str(log_to_copy)+ |
| 1326 | " "+str(dest_dir)) |
| 1327 | self.handle.expect("cp") |
| 1328 | self.handle.expect("\$") |
| 1329 | |
| 1330 | return self.handle.before |
| 1331 | |
| 1332 | except pexpect.EOF: |
| 1333 | main.log.error("Copying files failed") |
| 1334 | main.log.error(self.name + ": EOF exception found") |
| 1335 | main.log.error(self.name + ": " + self.handle.before) |
| 1336 | except: |
| 1337 | main.log.error("Copying files failed") |
| 1338 | main.log.info(self.name+" ::::::") |
| 1339 | main.log.error( traceback.print_exc()) |
| 1340 | main.log.info(self.name+" ::::::") |
| 1341 | |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1342 | def check_logs(self, onos_ip): |
| 1343 | ''' |
| 1344 | runs onos-check-logs on the given onos node |
| 1345 | returns the response |
| 1346 | ''' |
| 1347 | try: |
| 1348 | cmd = "onos-check-logs " + str(onos_ip) |
| 1349 | self.handle.sendline(cmd) |
| 1350 | self.handle.expect(cmd) |
| 1351 | self.handle.expect("\$") |
| 1352 | response = self.handle.before |
| 1353 | return response |
| 1354 | except pexpect.EOF: |
| 1355 | main.log.error("Lost ssh connection") |
| 1356 | main.log.error(self.name + ": EOF exception found") |
| 1357 | main.log.error(self.name + ": " + self.handle.before) |
| 1358 | except: |
| 1359 | main.log.error("Some error in check_logs:") |
| 1360 | main.log.info(self.name+" ::::::") |
| 1361 | main.log.error( traceback.print_exc()) |
| 1362 | main.log.info(self.name+" ::::::") |
| 1363 | |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1364 | def onos_status(self, node=""): |
| 1365 | ''' |
| 1366 | Calls onos command: 'onos-service [<node-ip>] status' |
| 1367 | ''' |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1368 | |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1369 | try: |
| 1370 | self.handle.sendline("") |
| 1371 | self.handle.expect("\$") |
| 1372 | self.handle.sendline("onos-service "+str(node)+ |
| 1373 | " status") |
| 1374 | i = self.handle.expect([ |
| 1375 | "start/running", |
| 1376 | "stop/waiting", |
| 1377 | pexpect.TIMEOUT],timeout=120) |
| 1378 | |
| 1379 | if i == 0: |
| 1380 | main.log.info("ONOS is running") |
| 1381 | return main.TRUE |
| 1382 | elif i == 1: |
| 1383 | main.log.info("ONOS is stopped") |
| 1384 | return main.FALSE |
| 1385 | else: |
| 1386 | main.log.error("ONOS service failed to check the status") |
| 1387 | main.cleanup() |
| 1388 | main.exit() |
| 1389 | except pexpect.EOF: |
| 1390 | main.log.error(self.name + ": EOF exception found") |
| 1391 | main.log.error(self.name + ": " + self.handle.before) |
| 1392 | main.cleanup() |
| 1393 | main.exit() |
| 1394 | except: |
| 1395 | main.log.info(self.name+" ::::::") |
| 1396 | main.log.error( traceback.print_exc()) |
| 1397 | main.log.info(self.name+" ::::::") |
| 1398 | main.cleanup() |
| 1399 | main.exit() |