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