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 |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 22 | import os |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 23 | import os.path |
pingping-lin | 6d23d9e | 2015-02-02 16:54:24 -0800 | [diff] [blame] | 24 | from requests.models import Response |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 25 | sys.path.append( "../" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 26 | from drivers.common.clidriver import CLI |
| 27 | |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 28 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 29 | class OnosDriver( CLI ): |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 30 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 31 | def __init__( self ): |
| 32 | """ |
| 33 | Initialize client |
| 34 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 35 | self.name = None |
| 36 | self.home = None |
| 37 | self.handle = None |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 38 | super( CLI, self ).__init__() |
| 39 | |
| 40 | def connect( self, **connectargs ): |
| 41 | """ |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 42 | Creates ssh handle for ONOS "bench". |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 43 | NOTE: |
| 44 | The ip_address would come from the topo file using the host tag, the |
| 45 | value can be an environment variable as well as a "localhost" to get |
| 46 | the ip address needed to ssh to the "bench" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 47 | """ |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 48 | try: |
| 49 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 50 | vars( self )[ key ] = connectargs[ key ] |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 51 | self.home = "~/onos" |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 52 | for key in self.options: |
| 53 | if key == "home": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 54 | self.home = self.options[ 'home' ] |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 55 | break |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 56 | if self.home is None or self.home == "": |
Jon Hall | e94919c | 2015-03-23 11:42:57 -0700 | [diff] [blame] | 57 | self.home = "~/onos" |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 58 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 59 | self.name = self.options[ 'name' ] |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 60 | |
| 61 | for key in self.options: |
| 62 | if key == "nodes": |
| 63 | # Maximum number of ONOS nodes to run |
| 64 | self.maxNodes = int( self.options[ 'nodes' ] ) |
| 65 | break |
| 66 | self.maxNodes = None |
| 67 | |
| 68 | |
| 69 | # Grabs all OC environment variables |
| 70 | self.onosIps = {} # Dictionary of all possible ONOS ip |
| 71 | |
| 72 | try: |
| 73 | if self.maxNodes: |
| 74 | main.log.info( self.name + ": Creating cluster data with " + |
| 75 | str( self.maxNodes ) + " maximum number" + |
| 76 | " of nodes" ) |
| 77 | |
| 78 | for i in range( self.maxNodes ): |
| 79 | envString = "OC" + str( i + 1 ) |
| 80 | self.onosIps[ envString ] = os.getenv( envString ) |
| 81 | |
| 82 | if not self.onosIps: |
| 83 | main.log.info( "Could not read any environment variable" |
| 84 | + " please load a cell file with all" + |
| 85 | " onos IP" ) |
| 86 | else: |
| 87 | main.log.info( self.name + ": Found " + |
| 88 | str( self.onosIps.values() ) + |
| 89 | " ONOS IPs" ) |
| 90 | |
| 91 | except KeyError: |
| 92 | main.log.info( "Invalid environment variable" ) |
| 93 | except Exception as inst: |
| 94 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 95 | |
| 96 | try: |
| 97 | if os.getenv( str( self.ip_address ) ) != None: |
| 98 | self.ip_address = os.getenv( str( self.ip_address ) ) |
| 99 | else: |
| 100 | main.log.info( self.name + |
| 101 | ": Trying to connect to " + |
| 102 | self.ip_address ) |
| 103 | |
| 104 | except KeyError: |
| 105 | main.log.info( "Invalid host name," + |
| 106 | " connecting to local host instead" ) |
| 107 | self.ip_address = 'localhost' |
| 108 | except Exception as inst: |
| 109 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 110 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 111 | self.handle = super( OnosDriver, self ).connect( |
| 112 | user_name=self.user_name, |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 113 | ip_address=self.ip_address, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 114 | port=self.port, |
| 115 | pwd=self.pwd, |
| 116 | home=self.home ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 117 | |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 118 | if self.handle: |
Jon Hall | 0fc0d45 | 2015-07-14 09:49:58 -0700 | [diff] [blame] | 119 | self.handle.sendline( "cd " + self.home ) |
| 120 | self.handle.expect( "\$" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 121 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 122 | else: |
Jon Hall | 0fc0d45 | 2015-07-14 09:49:58 -0700 | [diff] [blame] | 123 | main.log.info( "Failed to create ONOS handle" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 124 | return main.FALSE |
| 125 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 126 | main.log.error( self.name + ": EOF exception found" ) |
| 127 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 128 | main.cleanup() |
| 129 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 130 | except Exception: |
| 131 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 132 | main.cleanup() |
| 133 | main.exit() |
| 134 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 135 | def disconnect( self ): |
| 136 | """ |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 137 | Called when Test is complete to disconnect the ONOS handle. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 138 | """ |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 139 | response = main.TRUE |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 140 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 141 | if self.handle: |
| 142 | self.handle.sendline( "" ) |
| 143 | self.handle.expect( "\$" ) |
| 144 | self.handle.sendline( "exit" ) |
| 145 | self.handle.expect( "closed" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 146 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 147 | main.log.error( self.name + ": EOF exception found" ) |
| 148 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 149 | except ValueError: |
Jon Hall | 1a77a1e | 2015-04-06 10:41:13 -0700 | [diff] [blame] | 150 | main.log.exception( "Exception in disconnect of " + self.name ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 151 | response = main.TRUE |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 152 | except Exception: |
| 153 | main.log.exception( self.name + ": Connection failed to the host" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 154 | response = main.FALSE |
| 155 | return response |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 156 | |
andrew@onlab.us | aee415a | 2015-06-05 14:38:58 -0400 | [diff] [blame] | 157 | def getEpochMs( self ): |
| 158 | """ |
| 159 | Returns milliseconds since epoch |
| 160 | |
| 161 | When checking multiple nodes in a for loop, |
| 162 | around a hundred milliseconds of difference (ascending) is |
| 163 | generally acceptable due to calltime of the function. |
| 164 | Few seconds, however, is not and it means clocks |
| 165 | are off sync. |
| 166 | """ |
| 167 | try: |
| 168 | self.handle.sendline( 'date +%s.%N' ) |
| 169 | self.handle.expect( 'date \+\%s\.\%N' ) |
| 170 | self.handle.expect( '\$' ) |
| 171 | epochMs = self.handle.before |
| 172 | return epochMs |
| 173 | except Exception: |
| 174 | main.log.exception( 'Uncaught exception getting epoch time' ) |
| 175 | main.cleanup() |
| 176 | main.exit() |
| 177 | |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 178 | def onosPackage( self, opTimeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 179 | """ |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 180 | Produce a self-contained tar.gz file that can be deployed |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 181 | and executed on any platform with Java 7 JRE. |
| 182 | """ |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 183 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 184 | self.handle.sendline( "onos-package" ) |
| 185 | self.handle.expect( "onos-package" ) |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 186 | self.handle.expect( "tar.gz", opTimeout ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 187 | handle = str( self.handle.before ) |
| 188 | main.log.info( "onos-package command returned: " + |
| 189 | handle ) |
| 190 | # As long as the sendline does not time out, |
| 191 | # return true. However, be careful to interpret |
| 192 | # the results of the onos-package command return |
andrewonlab | 0748d2a | 2014-10-09 13:24:17 -0400 | [diff] [blame] | 193 | return main.TRUE |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 194 | |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 195 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 196 | main.log.error( self.name + ": EOF exception found" ) |
| 197 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 198 | except Exception: |
| 199 | main.log.exception( "Failed to package ONOS" ) |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 200 | main.cleanup() |
| 201 | main.exit() |
| 202 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 203 | def onosBuild( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 204 | """ |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 205 | Use the pre defined script to build onos via mvn |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 206 | """ |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 207 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 208 | self.handle.sendline( "onos-build" ) |
| 209 | self.handle.expect( "onos-build" ) |
| 210 | i = self.handle.expect( [ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 211 | "BUILD SUCCESS", |
| 212 | "ERROR", |
| 213 | "BUILD FAILED" ], |
| 214 | timeout=120 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 215 | handle = str( self.handle.before ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 216 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 217 | main.log.info( "onos-build command returned: " + |
| 218 | handle ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 219 | |
| 220 | if i == 0: |
| 221 | return main.TRUE |
| 222 | else: |
| 223 | return handle |
| 224 | |
| 225 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 226 | main.log.error( self.name + ": EOF exception found" ) |
| 227 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 228 | except Exception: |
| 229 | main.log.exception( "Failed to build ONOS" ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 230 | main.cleanup() |
| 231 | main.exit() |
| 232 | |
shahshreya | 9f531fe | 2015-06-10 12:03:51 -0700 | [diff] [blame] | 233 | def cleanInstall( self, skipTest=False, mciTimeout=600 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 234 | """ |
| 235 | Runs mvn clean install in the root of the ONOS directory. |
| 236 | This will clean all ONOS artifacts then compile each module |
shahshreya | 9f531fe | 2015-06-10 12:03:51 -0700 | [diff] [blame] | 237 | Optional: |
| 238 | skipTest - Does "-DskipTests -Dcheckstyle.skip -U -T 1C" which |
| 239 | skip the test. This will make the building faster. |
| 240 | Disregarding the credibility of the build |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 241 | Returns: main.TRUE on success |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 242 | On Failure, exits the test |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 243 | """ |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 244 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 245 | main.log.info( "Running 'mvn clean install' on " + |
| 246 | str( self.name ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 247 | ". This may take some time." ) |
| 248 | self.handle.sendline( "cd " + self.home ) |
| 249 | self.handle.expect( "\$" ) |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 250 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 251 | self.handle.sendline( "" ) |
| 252 | self.handle.expect( "\$" ) |
shahshreya | 9f531fe | 2015-06-10 12:03:51 -0700 | [diff] [blame] | 253 | |
| 254 | if not skipTest: |
| 255 | self.handle.sendline( "mvn clean install" ) |
| 256 | self.handle.expect( "mvn clean install" ) |
| 257 | else: |
| 258 | self.handle.sendline( "mvn clean install -DskipTests" + |
| 259 | " -Dcheckstyle.skip -U -T 1C" ) |
| 260 | self.handle.expect( "mvn clean install -DskipTests" + |
| 261 | " -Dcheckstyle.skip -U -T 1C" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 262 | while True: |
| 263 | i = self.handle.expect( [ |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 264 | 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s' + |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 265 | 'Runtime\sEnvironment\sto\scontinue', |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 266 | 'BUILD\sFAILURE', |
| 267 | 'BUILD\sSUCCESS', |
Jon Hall | e94919c | 2015-03-23 11:42:57 -0700 | [diff] [blame] | 268 | 'onos\$', #TODO: fix this to be more generic? |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 269 | 'ONOS\$', |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 270 | pexpect.TIMEOUT ], mciTimeout ) |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 271 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 272 | main.log.error( self.name + ":There is insufficient memory \ |
| 273 | for the Java Runtime Environment to continue." ) |
| 274 | # return main.FALSE |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 275 | main.cleanup() |
| 276 | main.exit() |
| 277 | if i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 278 | main.log.error( self.name + ": Build failure!" ) |
| 279 | # return main.FALSE |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 280 | main.cleanup() |
| 281 | main.exit() |
| 282 | elif i == 2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 283 | main.log.info( self.name + ": Build success!" ) |
Jon Hall | e94919c | 2015-03-23 11:42:57 -0700 | [diff] [blame] | 284 | elif i == 3 or i == 4: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 285 | main.log.info( self.name + ": Build complete" ) |
| 286 | # Print the build time |
Jon Hall | f8ef52c | 2014-10-09 19:37:33 -0400 | [diff] [blame] | 287 | for line in self.handle.before.splitlines(): |
| 288 | if "Total time:" in line: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 289 | main.log.info( line ) |
| 290 | self.handle.sendline( "" ) |
| 291 | self.handle.expect( "\$", timeout=60 ) |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 292 | return main.TRUE |
Jon Hall | e94919c | 2015-03-23 11:42:57 -0700 | [diff] [blame] | 293 | elif i == 5: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 294 | main.log.error( |
| 295 | self.name + |
| 296 | ": mvn clean install TIMEOUT!" ) |
| 297 | # return main.FALSE |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 298 | main.cleanup() |
| 299 | main.exit() |
| 300 | else: |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 301 | main.log.error( self.name + ": unexpected response from " + |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 302 | "mvn clean install" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 303 | # return main.FALSE |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 304 | main.cleanup() |
| 305 | main.exit() |
| 306 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 307 | main.log.error( self.name + ": EOF exception found" ) |
| 308 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 309 | main.cleanup() |
| 310 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 311 | except Exception: |
| 312 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 313 | main.cleanup() |
| 314 | main.exit() |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 315 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 316 | def gitPull( self, comp1="", fastForward=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 317 | """ |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 318 | Assumes that "git pull" works without login |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 319 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 320 | If the fastForward boolean is set to true, only git pulls that can |
| 321 | be fast forwarded will be performed. IE if you have not local commits |
| 322 | in your branch. |
| 323 | |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 324 | This function will perform a git pull on the ONOS instance. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 325 | If used as gitPull( "NODE" ) it will do git pull + NODE. This is |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 326 | for the purpose of pulling from other nodes if necessary. |
| 327 | |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 328 | Otherwise, this function will perform a git pull in the |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 329 | ONOS repository. If it has any problems, it will return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 330 | If it successfully does a gitPull, it will return a 1 ( main.TRUE ) |
Shreya Shah | ee15f6c | 2014-10-28 18:12:30 -0400 | [diff] [blame] | 331 | If it has no updates, it will return 3. |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 332 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 333 | """ |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 334 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 335 | # main.log.info( self.name + ": Stopping ONOS" ) |
| 336 | # self.stop() |
| 337 | self.handle.sendline( "cd " + self.home ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 338 | self.handle.expect( self.home + "\$" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 339 | cmd = "git pull" |
| 340 | if comp1 != "": |
| 341 | cmd += ' ' + comp1 |
| 342 | if fastForward: |
| 343 | cmd += ' ' + " --ff-only" |
| 344 | self.handle.sendline( cmd ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 345 | i = self.handle.expect( |
| 346 | [ |
| 347 | 'fatal', |
| 348 | 'Username\sfor\s(.*):\s', |
| 349 | '\sfile(s*) changed,\s', |
| 350 | 'Already up-to-date', |
| 351 | 'Aborting', |
| 352 | 'You\sare\snot\scurrently\son\sa\sbranch', |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 353 | 'You asked me to pull without telling me which branch you', |
| 354 | 'Pull is not possible because you have unmerged files', |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 355 | 'Please enter a commit message to explain why this merge', |
| 356 | 'Found a swap file by the name', |
| 357 | 'Please, commit your changes before you can merge.', |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 358 | pexpect.TIMEOUT ], |
| 359 | timeout=300 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 360 | # debug |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 361 | # main.log.report( self.name +": DEBUG: \n"+ |
| 362 | # "git pull response: " + |
| 363 | # str( self.handle.before ) + str( self.handle.after ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 364 | if i == 0: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 365 | main.log.error( self.name + ": Git pull had some issue" ) |
| 366 | output = self.handle.after |
| 367 | self.handle.expect( '\$' ) |
| 368 | output += self.handle.before |
| 369 | main.log.warn( output ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 370 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 371 | elif i == 1: |
| 372 | main.log.error( |
| 373 | self.name + |
| 374 | ": Git Pull Asking for username. " ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 375 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 376 | elif i == 2: |
| 377 | main.log.info( |
| 378 | self.name + |
| 379 | ": Git Pull - pulling repository now" ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 380 | self.handle.expect( self.home + "\$", 120 ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 381 | # So that only when git pull is done, we do mvn clean compile |
| 382 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 383 | elif i == 3: |
| 384 | main.log.info( self.name + ": Git Pull - Already up to date" ) |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 385 | return i |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 386 | elif i == 4: |
| 387 | main.log.info( |
| 388 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 389 | ": Git Pull - Aborting..." + |
| 390 | "Are there conflicting git files?" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 391 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 392 | elif i == 5: |
| 393 | main.log.info( |
| 394 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 395 | ": Git Pull - You are not currently " + |
| 396 | "on a branch so git pull failed!" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 397 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 398 | elif i == 6: |
| 399 | main.log.info( |
| 400 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 401 | ": Git Pull - You have not configured an upstream " + |
| 402 | "branch to pull from. Git pull failed!" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 403 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 404 | elif i == 7: |
| 405 | main.log.info( |
| 406 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 407 | ": Git Pull - Pull is not possible because " + |
| 408 | "you have unmerged files." ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 409 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 410 | elif i == 8: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 411 | # NOTE: abandoning test since we can't reliably handle this |
| 412 | # there could be different default text editors and we |
| 413 | # also don't know if we actually want to make the commit |
| 414 | main.log.error( "Git pull resulted in a merge commit message" + |
| 415 | ". Exiting test!" ) |
| 416 | main.cleanup() |
| 417 | main.exit() |
| 418 | elif i == 9: # Merge commit message but swap file exists |
| 419 | main.log.error( "Git pull resulted in a merge commit message" + |
| 420 | " but a swap file exists." ) |
| 421 | try: |
| 422 | self.handle.send( 'A' ) # Abort |
| 423 | self.handle.expect( "\$" ) |
| 424 | return main.ERROR |
| 425 | except Exception: |
| 426 | main.log.exception( "Couldn't exit editor prompt!") |
| 427 | main.cleanup() |
| 428 | main.exit() |
| 429 | elif i == 10: # In the middle of a merge commit |
| 430 | main.log.error( "Git branch is in the middle of a merge. " ) |
| 431 | main.log.warn( self.handle.before + self.handle.after ) |
| 432 | return main.ERROR |
| 433 | elif i == 11: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 434 | main.log.error( self.name + ": Git Pull - TIMEOUT" ) |
| 435 | main.log.error( |
| 436 | self.name + " Response was: " + str( |
| 437 | self.handle.before ) ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 438 | return main.ERROR |
| 439 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 440 | main.log.error( |
| 441 | self.name + |
| 442 | ": Git Pull - Unexpected response, check for pull errors" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 443 | return main.ERROR |
| 444 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 445 | main.log.error( self.name + ": EOF exception found" ) |
| 446 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 447 | main.cleanup() |
| 448 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 449 | except Exception: |
| 450 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 451 | main.cleanup() |
| 452 | main.exit() |
| 453 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 454 | def gitCheckout( self, branch="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 455 | """ |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 456 | Assumes that "git pull" works without login |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 457 | |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 458 | This function will perform a git git checkout on the ONOS instance. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 459 | If used as gitCheckout( "branch" ) it will do git checkout |
| 460 | of the "branch". |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 461 | |
| 462 | Otherwise, this function will perform a git checkout of the master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 463 | branch of the ONOS repository. If it has any problems, it will return |
| 464 | main.ERROR. |
| 465 | 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] | 466 | successful then the function will return main.TRUE. |
| 467 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 468 | """ |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 469 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 470 | self.handle.sendline( "cd " + self.home ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 471 | self.handle.expect( self.home + "\$" ) |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 472 | main.log.info( self.name + |
| 473 | ": Checking out git branch/ref: " + branch + "..." ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 474 | cmd = "git checkout " + branch |
| 475 | self.handle.sendline( cmd ) |
| 476 | self.handle.expect( cmd ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 477 | i = self.handle.expect( |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 478 | [ 'fatal', |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 479 | 'Username for (.*): ', |
| 480 | 'Already on \'', |
Jon Hall | 7a8354f | 2015-06-10 15:37:00 -0700 | [diff] [blame] | 481 | 'Switched to (a new )?branch \'' + str( branch ), |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 482 | pexpect.TIMEOUT, |
| 483 | 'error: Your local changes to the following files' + |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 484 | 'would be overwritten by checkout:', |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 485 | 'error: you need to resolve your current index first', |
| 486 | "You are in 'detached HEAD' state.", |
| 487 | "HEAD is now at " ], |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 488 | timeout=60 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 489 | if i == 0: |
| 490 | main.log.error( |
| 491 | self.name + |
| 492 | ": Git checkout had some issue..." ) |
| 493 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 494 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 495 | elif i == 1: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 496 | main.log.error( |
| 497 | self.name + |
| 498 | ": Git checkout asking for username." + |
| 499 | " Please configure your local git repository to be able " + |
| 500 | "to access your remote repository passwordlessly" ) |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 501 | # TODO add support for authenticating |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 502 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 503 | elif i == 2: |
| 504 | main.log.info( |
| 505 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 506 | ": Git Checkout %s : Already on this branch" % branch ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 507 | self.handle.expect( self.home + "\$" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 508 | # main.log.info( "DEBUG: after checkout cmd = "+ |
| 509 | # self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 510 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 511 | elif i == 3: |
| 512 | main.log.info( |
| 513 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 514 | ": Git checkout %s - Switched to this branch" % branch ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 515 | self.handle.expect( self.home + "\$" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 516 | # main.log.info( "DEBUG: after checkout cmd = "+ |
| 517 | # self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 518 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 519 | elif i == 4: |
| 520 | main.log.error( self.name + ": Git Checkout- TIMEOUT" ) |
| 521 | main.log.error( |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 522 | self.name + " Response was: " + str( self.handle.before ) ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 523 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 524 | elif i == 5: |
| 525 | self.handle.expect( "Aborting" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 526 | main.log.error( |
| 527 | self.name + |
| 528 | ": Git checkout error: \n" + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 529 | "Your local changes to the following files would" + |
| 530 | " be overwritten by checkout:" + |
| 531 | str( self.handle.before ) ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 532 | self.handle.expect( self.home + "\$" ) |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 533 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 534 | elif i == 6: |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 535 | main.log.error( |
| 536 | self.name + |
| 537 | ": Git checkout error: \n" + |
| 538 | "You need to resolve your current index first:" + |
| 539 | str( self.handle.before ) ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 540 | self.handle.expect( self.home + "\$" ) |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 541 | return main.ERROR |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 542 | elif i == 7: |
| 543 | main.log.info( |
| 544 | self.name + |
| 545 | ": Git checkout " + str( branch ) + |
| 546 | " - You are in 'detached HEAD' state. HEAD is now at " + |
| 547 | str( branch ) ) |
| 548 | self.handle.expect( self.home + "\$" ) |
| 549 | return main.TRUE |
| 550 | elif i == 8: # Already in detached HEAD on the specified commit |
| 551 | main.log.info( |
| 552 | self.name + |
| 553 | ": Git Checkout %s : Already on commit" % branch ) |
| 554 | self.handle.expect( self.home + "\$" ) |
| 555 | return main.TRUE |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 556 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 557 | main.log.error( |
| 558 | self.name + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 559 | ": Git Checkout - Unexpected response, " + |
| 560 | "check for pull errors" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 561 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 562 | return main.ERROR |
| 563 | |
| 564 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 565 | main.log.error( self.name + ": EOF exception found" ) |
| 566 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 567 | main.cleanup() |
| 568 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 569 | except Exception: |
| 570 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 571 | main.cleanup() |
| 572 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 573 | |
pingping-lin | 6d23d9e | 2015-02-02 16:54:24 -0800 | [diff] [blame] | 574 | def getBranchName( self ): |
pingping-lin | f30cf27 | 2015-05-29 15:54:07 -0700 | [diff] [blame] | 575 | main.log.info( "self.home = " ) |
| 576 | main.log.info( self.home ) |
pingping-lin | 6d23d9e | 2015-02-02 16:54:24 -0800 | [diff] [blame] | 577 | self.handle.sendline( "cd " + self.home ) |
pingping-lin | 9bf3d8f | 2015-05-29 16:05:28 -0700 | [diff] [blame] | 578 | self.handle.expect( self.home + "\$" ) |
pingping-lin | 6d23d9e | 2015-02-02 16:54:24 -0800 | [diff] [blame] | 579 | self.handle.sendline( "git name-rev --name-only HEAD" ) |
| 580 | self.handle.expect( "git name-rev --name-only HEAD" ) |
| 581 | self.handle.expect( "\$" ) |
| 582 | |
| 583 | lines = self.handle.before.splitlines() |
| 584 | if lines[1] == "master": |
| 585 | return "master" |
| 586 | elif lines[1] == "onos-1.0": |
| 587 | return "onos-1.0" |
| 588 | else: |
| 589 | main.log.info( lines[1] ) |
| 590 | return "unexpected ONOS branch for SDN-IP test" |
| 591 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 592 | def getVersion( self, report=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 593 | """ |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 594 | Writes the COMMIT number to the report to be parsed |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 595 | by Jenkins data collector. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 596 | """ |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 597 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 598 | self.handle.sendline( "" ) |
| 599 | self.handle.expect( "\$" ) |
| 600 | self.handle.sendline( |
| 601 | "cd " + |
| 602 | self.home + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 603 | "; git log -1 --pretty=fuller --decorate=short | grep -A 6 " + |
| 604 | " \"commit\" --color=never" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 605 | # NOTE: for some reason there are backspaces inserted in this |
| 606 | # phrase when run from Jenkins on some tests |
| 607 | self.handle.expect( "never" ) |
| 608 | self.handle.expect( "\$" ) |
| 609 | response = ( self.name + ": \n" + str( |
| 610 | self.handle.before + self.handle.after ) ) |
| 611 | self.handle.sendline( "cd " + self.home ) |
| 612 | self.handle.expect( "\$" ) |
| 613 | lines = response.splitlines() |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 614 | for line in lines: |
Jon Hall | fd19120 | 2014-11-07 18:36:09 -0500 | [diff] [blame] | 615 | print line |
| 616 | if report: |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 617 | main.log.wiki( "<blockquote>" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 618 | for line in lines[ 2:-1 ]: |
| 619 | # Bracket replacement is for Wiki-compliant |
| 620 | # formatting. '<' or '>' are interpreted |
| 621 | # as xml specific tags that cause errors |
| 622 | line = line.replace( "<", "[" ) |
| 623 | line = line.replace( ">", "]" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 624 | #main.log.wiki( "\t" + line ) |
| 625 | main.log.wiki( line + "<br /> " ) |
| 626 | main.log.summary( line ) |
| 627 | main.log.wiki( "</blockquote>" ) |
| 628 | main.log.summary("\n") |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 629 | return lines[ 2 ] |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -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 | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 633 | main.cleanup() |
| 634 | main.exit() |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 635 | except pexpect.TIMEOUT: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 636 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 637 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 638 | main.cleanup() |
| 639 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 640 | except Exception: |
| 641 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 642 | main.cleanup() |
| 643 | main.exit() |
| 644 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 645 | def createCellFile( self, benchIp, fileName, mnIpAddrs, |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 646 | appString, onosIpAddrs ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 647 | """ |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 648 | Creates a cell file based on arguments |
| 649 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 650 | * Bench IP address ( benchIp ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 651 | - Needed to copy the cell file over |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 652 | * File name of the cell file ( fileName ) |
| 653 | * Mininet IP address ( mnIpAddrs ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 654 | - Note that only 1 ip address is |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 655 | supported currently |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 656 | * ONOS IP addresses ( onosIpAddrs ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 657 | - Must be passed in as last arguments |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 658 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 659 | NOTE: Assumes cells are located at: |
| 660 | ~/<self.home>/tools/test/cells/ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 661 | """ |
| 662 | # Variable initialization |
Jon Hall | f57a5ef | 2015-07-07 17:56:16 -0700 | [diff] [blame] | 663 | cellDirectory = os.environ["ONOS_ROOT"] + "/tools/test/cells/" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 664 | # We want to create the cell file in the dependencies directory |
| 665 | # of TestON first, then copy over to ONOS bench |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 666 | tempDirectory = "/tmp/" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 667 | # Create the cell file in the directory for writing ( w+ ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 668 | cellFile = open( tempDirectory + fileName, 'w+' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 669 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 670 | # App string is hardcoded environment variables |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 671 | # That you may wish to use by default on startup. |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 672 | # Note that you may not want certain apps listed |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 673 | # on here. |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 674 | appString = "export ONOS_APPS=" + appString |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 675 | mnString = "export OCN=" |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 676 | if mnIpAddrs == "": |
| 677 | mnString = "" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 678 | onosString = "export OC" |
| 679 | tempCount = 1 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 680 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 681 | # Create ONOSNIC ip address prefix |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 682 | tempOnosIp = str( onosIpAddrs[ 0 ] ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 683 | tempList = [] |
| 684 | tempList = tempOnosIp.split( "." ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 685 | # Omit last element of list to format for NIC |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 686 | tempList = tempList[ :-1 ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 687 | # Structure the nic string ip |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 688 | nicAddr = ".".join( tempList ) + ".*" |
| 689 | onosNicString = "export ONOS_NIC=" + nicAddr |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 690 | |
| 691 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 692 | # Start writing to file |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 693 | cellFile.write( onosNicString + "\n" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 694 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 695 | for arg in onosIpAddrs: |
| 696 | # For each argument in onosIpAddrs, write to file |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 697 | # Output should look like the following: |
andrewonlab | d494049 | 2014-10-24 12:21:27 -0400 | [diff] [blame] | 698 | # export OC1="10.128.20.11" |
| 699 | # export OC2="10.128.20.12" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 700 | cellFile.write( onosString + str( tempCount ) + |
| 701 | "=" + "\"" + arg + "\"" + "\n" ) |
| 702 | tempCount = tempCount + 1 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 703 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 704 | cellFile.write( mnString + "\"" + mnIpAddrs + "\"" + "\n" ) |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 705 | cellFile.write( appString + "\n" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 706 | cellFile.close() |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 707 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 708 | # We use os.system to send the command to TestON cluster |
| 709 | # to account for the case in which TestON is not located |
| 710 | # on the same cluster as the ONOS bench |
| 711 | # Note that even if TestON is located on the same cluster |
| 712 | # as ONOS bench, you must setup passwordless ssh |
| 713 | # between TestON and ONOS bench in order to automate the test. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 714 | os.system( "scp " + tempDirectory + fileName + |
| 715 | " admin@" + benchIp + ":" + cellDirectory ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 716 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 717 | return main.TRUE |
| 718 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 719 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 720 | main.log.error( self.name + ": EOF exception found" ) |
| 721 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 722 | main.cleanup() |
| 723 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 724 | except Exception: |
| 725 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 726 | main.cleanup() |
| 727 | main.exit() |
| 728 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 729 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 730 | """ |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 731 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 732 | """ |
Hari Krishna | 03f530e | 2015-07-10 17:28:27 -0700 | [diff] [blame] | 733 | import re |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 734 | try: |
| 735 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 736 | main.log.error( "Must define cellname" ) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 737 | main.cleanup() |
| 738 | main.exit() |
| 739 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 740 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 741 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 742 | # Note that this variable name is subject to change |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 743 | # and that this driver will have to change accordingly |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 744 | self.handle.expect(str(cellname)) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 745 | handleBefore = self.handle.before |
| 746 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 747 | # Get the rest of the handle |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 748 | self.handle.sendline("") |
| 749 | self.handle.expect("\$") |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 750 | handleMore = self.handle.before |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 751 | |
Hari Krishna | 03f530e | 2015-07-10 17:28:27 -0700 | [diff] [blame] | 752 | cell_result = handleBefore + handleAfter + handleMore |
| 753 | print cell_result |
| 754 | if( re.search( "No such cell", cell_result ) ): |
| 755 | main.log.error( "Cell call returned: " + handleBefore + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 756 | handleAfter + handleMore ) |
Hari Krishna | 03f530e | 2015-07-10 17:28:27 -0700 | [diff] [blame] | 757 | main.cleanup() |
| 758 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 759 | return main.TRUE |
| 760 | |
| 761 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 762 | main.log.error( self.name + ": EOF exception found" ) |
| 763 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 764 | main.cleanup() |
| 765 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 766 | except Exception: |
| 767 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 768 | main.cleanup() |
| 769 | main.exit() |
| 770 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 771 | def verifyCell( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 772 | """ |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 773 | Calls 'onos-verify-cell' to check for cell installation |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 774 | """ |
| 775 | # TODO: Add meaningful expect value |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 776 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 777 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 778 | # Clean handle by sending empty and expecting $ |
| 779 | self.handle.sendline( "" ) |
| 780 | self.handle.expect( "\$" ) |
| 781 | self.handle.sendline( "onos-verify-cell" ) |
| 782 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 783 | handleBefore = self.handle.before |
| 784 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 785 | # Get the rest of the handle |
| 786 | self.handle.sendline( "" ) |
| 787 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 788 | handleMore = self.handle.before |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 789 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 790 | main.log.info( "Verify cell returned: " + handleBefore + |
| 791 | handleAfter + handleMore ) |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 792 | |
| 793 | return main.TRUE |
Jon Hall | a5cb617 | 2015-02-23 09:28:28 -0800 | [diff] [blame] | 794 | except pexpect.ExceptionPexpect as e: |
| 795 | main.log.error( self.name + ": Pexpect exception found of type " + |
| 796 | str( type( e ) ) ) |
| 797 | main.log.error ( e.get_trace() ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 798 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 799 | main.cleanup() |
| 800 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 801 | except Exception: |
| 802 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 803 | main.cleanup() |
| 804 | main.exit() |
| 805 | |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 806 | def onosCfgSet( self, ONOSIp, configName, configParam ): |
| 807 | """ |
| 808 | Uses 'onos <node-ip> cfg set' to change a parameter value of an |
| 809 | application. |
| 810 | |
| 811 | ex) |
| 812 | onos 10.0.0.1 cfg set org.onosproject.myapp appSetting 1 |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 813 | ONOSIp = '10.0.0.1' |
| 814 | configName = 'org.onosproject.myapp' |
| 815 | configParam = 'appSetting 1' |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 816 | """ |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 817 | for i in range(5): |
| 818 | try: |
| 819 | cfgStr = ( "onos "+str(ONOSIp)+" cfg set "+ |
| 820 | str(configName) + " " + |
| 821 | str(configParam) |
| 822 | ) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 823 | |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 824 | self.handle.sendline( "" ) |
| 825 | self.handle.expect( ":~" ) |
| 826 | self.handle.sendline( cfgStr ) |
| 827 | self.handle.expect("cfg set") |
| 828 | self.handle.expect( ":~" ) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 829 | |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 830 | paramValue = configParam.split(" ")[1] |
| 831 | paramName = configParam.split(" ")[0] |
| 832 | |
| 833 | checkStr = ( "onos " + str(ONOSIp) + """ cfg get " """ + str(configName) + " " + paramName + """ " """) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 834 | |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 835 | self.handle.sendline( checkStr ) |
| 836 | self.handle.expect( ":~" ) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 837 | |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 838 | if "value=" + paramValue + "," in self.handle.before: |
| 839 | main.log.info("cfg " + configName + " successfully set to " + configParam) |
| 840 | return main.TRUE |
| 841 | |
| 842 | except pexpect.ExceptionPexpect as e: |
| 843 | main.log.error( self.name + ": Pexpect exception found of type " + |
| 844 | str( type( e ) ) ) |
| 845 | main.log.error ( e.get_trace() ) |
| 846 | main.log.error( self.name + ": " + self.handle.before ) |
| 847 | main.cleanup() |
| 848 | main.exit() |
| 849 | except Exception: |
| 850 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 851 | main.cleanup() |
| 852 | main.exit() |
| 853 | |
| 854 | time.sleep(5) |
| 855 | |
| 856 | main.log.error("CFG SET FAILURE: " + configName + " " + configParam ) |
| 857 | main.ONOSbench.handle.sendline("onos $OC1 cfg get") |
| 858 | main.ONOSbench.handle.expect("\$") |
| 859 | print main.ONOSbench.handle.before |
| 860 | main.ONOSbench.logReport( ONOSIp, ["ERROR","WARN","EXCEPT"], "d") |
| 861 | return main.FALSE |
| 862 | |
| 863 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 864 | def onosCli( self, ONOSIp, cmdstr ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 865 | """ |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 866 | Uses 'onos' command to send various ONOS CLI arguments. |
| 867 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 868 | * ONOSIp: specify the ip of the cell machine |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 869 | * cmdstr: specify the command string to send |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 870 | |
| 871 | This function is intended to expose the entire karaf |
andrewonlab | 6e20c34 | 2014-10-10 18:08:48 -0400 | [diff] [blame] | 872 | CLI commands for ONOS. Try to use this function first |
| 873 | before attempting to write a ONOS CLI specific driver |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 874 | function. |
| 875 | You can see a list of available 'cmdstr' arguments |
andrewonlab | 6e20c34 | 2014-10-10 18:08:48 -0400 | [diff] [blame] | 876 | by starting onos, and typing in 'onos' to enter the |
| 877 | onos> CLI. Then, type 'help' to see the list of |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 878 | available commands. |
| 879 | """ |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 880 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 881 | if not ONOSIp: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 882 | main.log.error( "You must specify the IP address" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 883 | return main.FALSE |
| 884 | if not cmdstr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 885 | main.log.error( "You must specify the command string" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 886 | return main.FALSE |
| 887 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 888 | cmdstr = str( cmdstr ) |
| 889 | self.handle.sendline( "" ) |
| 890 | self.handle.expect( "\$" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 891 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 892 | self.handle.sendline( "onos -w " + ONOSIp + " " + cmdstr ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 893 | self.handle.expect( "\$" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 894 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 895 | handleBefore = self.handle.before |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 896 | print "handle_before = ", self.handle.before |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 897 | # handleAfter = str( self.handle.after ) |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 898 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 899 | # self.handle.sendline( "" ) |
| 900 | # self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 901 | # handleMore = str( self.handle.before ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 902 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 903 | main.log.info( "Command sent successfully" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 904 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 905 | # Obtain return handle that consists of result from |
| 906 | # the onos command. The string may need to be |
| 907 | # configured further. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 908 | # returnString = handleBefore + handleAfter |
| 909 | returnString = handleBefore |
| 910 | print "return_string = ", returnString |
| 911 | return returnString |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 912 | |
| 913 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 914 | main.log.error( self.name + ": EOF exception found" ) |
| 915 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 916 | main.cleanup() |
| 917 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 918 | except Exception: |
| 919 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 920 | main.cleanup() |
| 921 | main.exit() |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 922 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 923 | def onosInstall( self, options="-f", node="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 924 | """ |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 925 | Installs ONOS bits on the designated cell machine. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 926 | If -f option is provided, it also forces an uninstall. |
| 927 | Presently, install also includes onos-push-bits and |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 928 | onos-config within. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 929 | The node option allows you to selectively only push the jar |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 930 | files to certain onos nodes |
| 931 | |
| 932 | Returns: main.TRUE on success and main.FALSE on failure |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 933 | """ |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 934 | try: |
andrewonlab | 114768a | 2014-11-14 12:44:44 -0500 | [diff] [blame] | 935 | if options: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 936 | self.handle.sendline( "onos-install " + options + " " + node ) |
andrewonlab | 114768a | 2014-11-14 12:44:44 -0500 | [diff] [blame] | 937 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 938 | self.handle.sendline( "onos-install " + node ) |
| 939 | self.handle.expect( "onos-install " ) |
| 940 | # NOTE: this timeout may need to change depending on the network |
| 941 | # and size of ONOS |
| 942 | i = self.handle.expect( [ "Network\sis\sunreachable", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 943 | "onos\sstart/running,\sprocess", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 944 | "ONOS\sis\salready\sinstalled", |
| 945 | pexpect.TIMEOUT ], timeout=60 ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 946 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 947 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 948 | main.log.warn( "Network is unreachable" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 949 | return main.FALSE |
| 950 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 951 | main.log.info( |
| 952 | "ONOS was installed on " + |
| 953 | node + |
| 954 | " and started" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 955 | return main.TRUE |
andrewonlab | d9a73a7 | 2014-11-14 17:28:21 -0500 | [diff] [blame] | 956 | elif i == 2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 957 | main.log.info( "ONOS is already installed on " + node ) |
andrewonlab | d9a73a7 | 2014-11-14 17:28:21 -0500 | [diff] [blame] | 958 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 959 | elif i == 3: |
| 960 | main.log.info( |
| 961 | "Installation of ONOS on " + |
| 962 | node + |
| 963 | " timed out" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 964 | return main.FALSE |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 965 | |
| 966 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 967 | main.log.error( self.name + ": EOF exception found" ) |
| 968 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 969 | main.cleanup() |
| 970 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 971 | except Exception: |
| 972 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 973 | main.cleanup() |
| 974 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 975 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 976 | def onosStart( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 977 | """ |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 978 | Calls onos command: 'onos-service [<node-ip>] start' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 979 | This command is a remote management of the ONOS upstart daemon |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 980 | """ |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 981 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 982 | self.handle.sendline( "" ) |
| 983 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 984 | self.handle.sendline( "onos-service " + str( nodeIp ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 985 | " start" ) |
| 986 | i = self.handle.expect( [ |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 987 | "Job\sis\salready\srunning", |
| 988 | "start/running", |
| 989 | "Unknown\sinstance", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 990 | pexpect.TIMEOUT ], timeout=120 ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 991 | |
| 992 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 993 | main.log.info( "Service is already running" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 994 | return main.TRUE |
| 995 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 996 | main.log.info( "ONOS service started" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 997 | return main.TRUE |
| 998 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 999 | main.log.error( "ONOS service failed to start" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1000 | main.cleanup() |
| 1001 | main.exit() |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1002 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1003 | main.log.error( self.name + ": EOF exception found" ) |
| 1004 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1005 | main.cleanup() |
| 1006 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1007 | except Exception: |
| 1008 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1009 | main.cleanup() |
| 1010 | main.exit() |
| 1011 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1012 | def onosStop( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1013 | """ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1014 | Calls onos command: 'onos-service [<node-ip>] stop' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1015 | This command is a remote management of the ONOS upstart daemon |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1016 | """ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1017 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1018 | self.handle.sendline( "" ) |
| 1019 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1020 | self.handle.sendline( "onos-service " + str( nodeIp ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1021 | " stop" ) |
| 1022 | i = self.handle.expect( [ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1023 | "stop/waiting", |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1024 | "Could not resolve hostname", |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1025 | "Unknown\sinstance", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1026 | pexpect.TIMEOUT ], timeout=60 ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1027 | |
| 1028 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1029 | main.log.info( "ONOS service stopped" ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1030 | return main.TRUE |
| 1031 | elif i == 1: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1032 | main.log.info( "onosStop() Unknown ONOS instance specified: " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1033 | str( nodeIp ) ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1034 | return main.FALSE |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1035 | elif i == 2: |
| 1036 | main.log.warn( "ONOS wasn't running" ) |
| 1037 | return main.TRUE |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1038 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1039 | main.log.error( "ONOS service failed to stop" ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1040 | return main.FALSE |
| 1041 | |
| 1042 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1043 | main.log.error( self.name + ": EOF exception found" ) |
| 1044 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1045 | main.cleanup() |
| 1046 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1047 | except Exception: |
| 1048 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1049 | main.cleanup() |
| 1050 | main.exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1051 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1052 | def onosUninstall( self, nodeIp="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1053 | """ |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1054 | Calls the command: 'onos-uninstall' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1055 | Uninstalls ONOS from the designated cell machine, stopping |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1056 | if needed |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1057 | """ |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1058 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1059 | self.handle.sendline( "" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 1060 | self.handle.expect( "\$", timeout=60 ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1061 | self.handle.sendline( "onos-uninstall " + str( nodeIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1062 | self.handle.expect( "\$" ) |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1063 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1064 | main.log.info( "ONOS " + nodeIp + " was uninstalled" ) |
andrewonlab | 9dfd208 | 2014-11-13 17:44:03 -0500 | [diff] [blame] | 1065 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1066 | # onos-uninstall command does not return any text |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1067 | return main.TRUE |
| 1068 | |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 1069 | except pexpect.TIMEOUT: |
| 1070 | main.log.exception( self.name + ": Timeout in onosUninstall" ) |
| 1071 | return main.FALSE |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1072 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1073 | main.log.error( self.name + ": EOF exception found" ) |
| 1074 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1075 | main.cleanup() |
| 1076 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1077 | except Exception: |
| 1078 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1079 | main.cleanup() |
| 1080 | main.exit() |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1081 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1082 | def onosDie( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1083 | """ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1084 | Issues the command 'onos-die <node-ip>' |
| 1085 | This command calls onos-kill and also stops the node |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1086 | """ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1087 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1088 | self.handle.sendline( "" ) |
| 1089 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1090 | cmdStr = "onos-kill " + str( nodeIp ) |
| 1091 | self.handle.sendline( cmdStr ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1092 | i = self.handle.expect( [ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1093 | "Killing\sONOS", |
| 1094 | "ONOS\sprocess\sis\snot\srunning", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1095 | pexpect.TIMEOUT ], timeout=20 ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1096 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1097 | main.log.info( "ONOS instance " + str( nodeIp ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1098 | " was killed and stopped" ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1099 | return main.TRUE |
| 1100 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1101 | main.log.info( "ONOS process was not running" ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1102 | return main.FALSE |
| 1103 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1104 | main.log.error( self.name + ": EOF exception found" ) |
| 1105 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1106 | main.cleanup() |
| 1107 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1108 | except Exception: |
| 1109 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1110 | main.cleanup() |
| 1111 | main.exit() |
| 1112 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1113 | def onosKill( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1114 | """ |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1115 | Calls the command: 'onos-kill [<node-ip>]' |
| 1116 | "Remotely, and unceremoniously kills the ONOS instance running on |
| 1117 | the specified cell machine" - Tom V |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1118 | """ |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1119 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1120 | self.handle.sendline( "" ) |
| 1121 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1122 | self.handle.sendline( "onos-kill " + str( nodeIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1123 | i = self.handle.expect( [ |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1124 | "\$", |
| 1125 | "No\sroute\sto\shost", |
| 1126 | "password:", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1127 | pexpect.TIMEOUT ], timeout=20 ) |
| 1128 | |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1129 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1130 | main.log.info( |
| 1131 | "ONOS instance " + str( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1132 | nodeIp ) + " was killed" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1133 | return main.TRUE |
| 1134 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1135 | main.log.info( "No route to host" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1136 | return main.FALSE |
| 1137 | elif i == 2: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1138 | main.log.info( |
| 1139 | "Passwordless login for host: " + |
| 1140 | str( nodeIp ) + |
| 1141 | " not configured" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1142 | return main.FALSE |
| 1143 | else: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1144 | main.log.info( "ONOS instance was not killed" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1145 | return main.FALSE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1146 | |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1147 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1148 | main.log.error( self.name + ": EOF exception found" ) |
| 1149 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1150 | main.cleanup() |
| 1151 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1152 | except Exception: |
| 1153 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1154 | main.cleanup() |
| 1155 | main.exit() |
| 1156 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1157 | def onosRemoveRaftLogs( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1158 | """ |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1159 | Removes Raft / Copy cat files from ONOS to ensure |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1160 | a cleaner environment. |
| 1161 | |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1162 | Description: |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1163 | Stops all ONOS defined in the cell, |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1164 | wipes the raft / copycat log files |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1165 | """ |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1166 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1167 | self.handle.sendline( "" ) |
| 1168 | self.handle.expect( "\$" ) |
| 1169 | self.handle.sendline( "onos-remove-raft-logs" ) |
| 1170 | # Sometimes this command hangs |
| 1171 | i = self.handle.expect( [ "\$", pexpect.TIMEOUT ], |
| 1172 | timeout=120 ) |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1173 | if i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1174 | i = self.handle.expect( [ "\$", pexpect.TIMEOUT ], |
| 1175 | timeout=120 ) |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1176 | if i == 1: |
| 1177 | return main.FALSE |
shahshreya | 957feaa | 2015-03-23 16:08:29 -0700 | [diff] [blame] | 1178 | #self.handle.sendline( "" ) |
| 1179 | #self.handle.expect( "\$" ) |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1180 | return main.TRUE |
| 1181 | |
| 1182 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1183 | main.log.error( self.name + ": EOF exception found" ) |
| 1184 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1185 | main.cleanup() |
| 1186 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1187 | except Exception: |
| 1188 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1189 | main.cleanup() |
| 1190 | main.exit() |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1191 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1192 | def onosStartNetwork( self, mntopo ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1193 | """ |
| 1194 | Calls the command 'onos-start-network [ <mininet-topo> ] |
| 1195 | "remotely starts the specified topology on the cell's |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1196 | mininet machine against all controllers configured in the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1197 | cell." |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1198 | * Specify mininet topology file name for mntopo |
| 1199 | * Topo files should be placed at: |
| 1200 | ~/<your-onos-directory>/tools/test/topos |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1201 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1202 | NOTE: This function will take you to the mininet prompt |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1203 | """ |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1204 | try: |
| 1205 | if not mntopo: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1206 | main.log.error( "You must specify a topo file to execute" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1207 | return main.FALSE |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1208 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1209 | mntopo = str( mntopo ) |
| 1210 | self.handle.sendline( "" ) |
| 1211 | self.handle.expect( "\$" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1212 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1213 | self.handle.sendline( "onos-start-network " + mntopo ) |
| 1214 | self.handle.expect( "mininet>" ) |
| 1215 | main.log.info( "Network started, entered mininet prompt" ) |
| 1216 | |
| 1217 | # TODO: Think about whether return is necessary or not |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1218 | |
| 1219 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1220 | main.log.error( self.name + ": EOF exception found" ) |
| 1221 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1222 | main.cleanup() |
| 1223 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1224 | except Exception: |
| 1225 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1226 | main.cleanup() |
| 1227 | main.exit() |
| 1228 | |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 1229 | def isup(self, node = "", timeout = 120): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1230 | """ |
| 1231 | Run's onos-wait-for-start which only returns once ONOS is at run |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 1232 | level 100(ready for use) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1233 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1234 | Returns: main.TRUE if ONOS is running and main.FALSE on timeout |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1235 | """ |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1236 | try: |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 1237 | self.handle.sendline("onos-wait-for-start " + node ) |
| 1238 | self.handle.expect("onos-wait-for-start") |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1239 | # NOTE: this timeout is arbitrary" |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 1240 | i = self.handle.expect(["\$", pexpect.TIMEOUT], timeout) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1241 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1242 | main.log.info( self.name + ": " + node + " is up" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1243 | return main.TRUE |
| 1244 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1245 | # NOTE: since this function won't return until ONOS is ready, |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1246 | # we will kill it on timeout |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1247 | main.log.error( "ONOS has not started yet" ) |
| 1248 | self.handle.send( "\x03" ) # Control-C |
| 1249 | self.handle.expect( "\$" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1250 | return main.FALSE |
| 1251 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1252 | main.log.error( self.name + ": EOF exception found" ) |
| 1253 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1254 | main.cleanup() |
| 1255 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1256 | except Exception: |
| 1257 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1258 | main.cleanup() |
| 1259 | main.exit() |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 1260 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1261 | def pushTestIntentsShell( |
| 1262 | self, |
| 1263 | dpidSrc, |
| 1264 | dpidDst, |
| 1265 | numIntents, |
| 1266 | dirFile, |
| 1267 | onosIp, |
| 1268 | numMult="", |
| 1269 | appId="", |
| 1270 | report=True, |
| 1271 | options="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1272 | """ |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1273 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1274 | Use the linux prompt to push test intents to |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1275 | better parallelize the results than the CLI |
| 1276 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1277 | * dpidSrc: specify source dpid |
| 1278 | * dpidDst: specify destination dpid |
| 1279 | * numIntents: specify number of intents to push |
| 1280 | * dirFile: specify directory and file name to save |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1281 | results |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1282 | * onosIp: specify the IP of ONOS to install on |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1283 | NOTE: |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1284 | You must invoke this command at linux shell prompt |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1285 | """ |
| 1286 | try: |
| 1287 | # Create the string to sendline |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1288 | if options: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1289 | baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1290 | options + " " |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1291 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1292 | baseCmd = "onos " + str( onosIp ) + " push-test-intents " |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1293 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1294 | addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst ) |
| 1295 | if not numMult: |
| 1296 | addIntents = addDpid + " " + str( numIntents ) |
| 1297 | elif numMult: |
| 1298 | addIntents = addDpid + " " + str( numIntents ) + " " +\ |
| 1299 | str( numMult ) |
| 1300 | if appId: |
| 1301 | addApp = addIntents + " " + str( appId ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1302 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1303 | addApp = addIntents |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1304 | |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1305 | if report: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1306 | sendCmd = addApp + " > " + str( dirFile ) + " &" |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1307 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1308 | sendCmd = addApp + " &" |
| 1309 | main.log.info( "Send cmd: " + sendCmd ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1310 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1311 | self.handle.sendline( sendCmd ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1312 | |
| 1313 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1314 | main.log.error( self.name + ": EOF exception found" ) |
| 1315 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1316 | main.cleanup() |
| 1317 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1318 | except Exception: |
| 1319 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1320 | main.cleanup() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1321 | main.exit() |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 1322 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1323 | def getTopology( self, topologyOutput ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1324 | """ |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 1325 | Definition: |
| 1326 | Loads a json topology output |
| 1327 | Return: |
| 1328 | topology = current ONOS topology |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1329 | """ |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 1330 | import json |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1331 | try: |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 1332 | # either onos:topology or 'topology' will work in CLI |
| 1333 | topology = json.loads(topologyOutput) |
| 1334 | print topology |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1335 | return topology |
| 1336 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1337 | main.log.error( self.name + ": EOF exception found" ) |
| 1338 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1339 | main.cleanup() |
| 1340 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1341 | except Exception: |
| 1342 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1343 | main.cleanup() |
| 1344 | main.exit() |
| 1345 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1346 | def checkStatus( |
| 1347 | self, |
| 1348 | topologyResult, |
| 1349 | numoswitch, |
| 1350 | numolink, |
| 1351 | logLevel="info" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1352 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1353 | Checks the number of switches & links that ONOS sees against the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1354 | supplied values. By default this will report to main.log, but the |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1355 | log level can be specific. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1356 | |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1357 | Params: ip = ip used for the onos cli |
| 1358 | numoswitch = expected number of switches |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1359 | numolink = expected number of links |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1360 | logLevel = level to log to. |
| 1361 | Currently accepts 'info', 'warn' and 'report' |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1362 | |
| 1363 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1364 | logLevel can |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1365 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1366 | Returns: main.TRUE if the number of switches and links are correct, |
| 1367 | main.FALSE if the number of switches and links is incorrect, |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1368 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1369 | """ |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1370 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1371 | topology = self.getTopology( topologyResult ) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1372 | if topology == {}: |
| 1373 | return main.ERROR |
| 1374 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1375 | # Is the number of switches is what we expected |
shahshreya | 234a168 | 2015-05-27 15:41:56 -0700 | [diff] [blame] | 1376 | devices = topology.get( 'devices', False ) |
| 1377 | links = topology.get( 'links', False ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1378 | if not devices or not links: |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1379 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1380 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1381 | # Is the number of links is what we expected |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1382 | linkCheck = ( int( links ) == int( numolink ) ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1383 | if switchCheck and linkCheck: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1384 | # We expected the correct numbers |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1385 | output = output + "The number of links and switches match "\ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1386 | + "what was expected" |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1387 | result = main.TRUE |
| 1388 | else: |
| 1389 | output = output + \ |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 1390 | "The number of links and switches does not match " + \ |
| 1391 | "what was expected" |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1392 | result = main.FALSE |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1393 | output = output + "\n ONOS sees %i devices" % int( devices ) |
| 1394 | output = output + " (%i expected) " % int( numoswitch ) |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 1395 | output = output + "and %i links " % int( links ) |
| 1396 | output = output + "(%i expected)" % int( numolink ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1397 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1398 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1399 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1400 | main.log.warn( output ) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1401 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1402 | main.log.info( output ) |
| 1403 | return result |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1404 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1405 | main.log.error( self.name + ": EOF exception found" ) |
| 1406 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1407 | main.cleanup() |
| 1408 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1409 | except Exception: |
| 1410 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1411 | main.cleanup() |
| 1412 | main.exit() |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1413 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1414 | def tsharkPcap( self, interface, dirFile ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1415 | """ |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1416 | Capture all packet activity and store in specified |
| 1417 | directory/file |
| 1418 | |
| 1419 | Required: |
| 1420 | * interface: interface to capture |
| 1421 | * dir: directory/filename to store pcap |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1422 | """ |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1423 | try: |
| 1424 | self.handle.sendline( "" ) |
| 1425 | self.handle.expect( "\$" ) |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1426 | |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1427 | self.handle.sendline( "tshark -i " + str( interface ) + |
| 1428 | " -t e -w " + str( dirFile ) + " &" ) |
| 1429 | self.handle.sendline( "\r" ) |
| 1430 | self.handle.expect( "Capturing on" ) |
| 1431 | self.handle.sendline( "\r" ) |
| 1432 | self.handle.expect( "\$" ) |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1433 | |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1434 | main.log.info( "Tshark started capturing files on " + |
| 1435 | str( interface ) + " and saving to directory: " + |
| 1436 | str( dirFile ) ) |
| 1437 | except pexpect.EOF: |
| 1438 | main.log.error( self.name + ": EOF exception found" ) |
| 1439 | main.log.error( self.name + ": " + self.handle.before ) |
| 1440 | main.cleanup() |
| 1441 | main.exit() |
| 1442 | except Exception: |
| 1443 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1444 | main.cleanup() |
| 1445 | main.exit() |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 1446 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1447 | def runOnosTopoCfg( self, instanceName, jsonFile ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1448 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1449 | On ONOS bench, run this command: |
Jon Hall | e94919c | 2015-03-23 11:42:57 -0700 | [diff] [blame] | 1450 | {ONOS_HOME}/tools/test/bin/onos-topo-cfg $OC1 filename |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1451 | which starts the rest and copies |
| 1452 | the json file to the onos instance |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1453 | """ |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 1454 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1455 | self.handle.sendline( "" ) |
| 1456 | self.handle.expect( "\$" ) |
Jon Hall | e94919c | 2015-03-23 11:42:57 -0700 | [diff] [blame] | 1457 | self.handle.sendline( "cd " + self.home + "/tools/test/bin" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1458 | self.handle.expect( "/bin$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1459 | cmd = "./onos-topo-cfg " + instanceName + " " + jsonFile |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 1460 | print "cmd = ", cmd |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1461 | self.handle.sendline( cmd ) |
| 1462 | self.handle.expect( "\$" ) |
| 1463 | self.handle.sendline( "cd ~" ) |
| 1464 | self.handle.expect( "\$" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 1465 | return main.TRUE |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1466 | except pexpect.EOF: |
| 1467 | main.log.error( self.name + ": EOF exception found" ) |
| 1468 | main.log.error( self.name + ": " + self.handle.before ) |
| 1469 | main.cleanup() |
| 1470 | main.exit() |
| 1471 | except Exception: |
| 1472 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1473 | main.cleanup() |
| 1474 | main.exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1475 | |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 1476 | def tsharkGrep( self, grep, directory, interface='eth0', grepOptions='' ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1477 | """ |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1478 | Required: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1479 | * grep string |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1480 | * directory to store results |
| 1481 | Optional: |
| 1482 | * interface - default: eth0 |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 1483 | * grepOptions - options for grep |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1484 | Description: |
| 1485 | Uses tshark command to grep specific group of packets |
| 1486 | and stores the results to specified directory. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1487 | The timestamp is hardcoded to be in epoch |
| 1488 | """ |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1489 | try: |
| 1490 | self.handle.sendline( "" ) |
| 1491 | self.handle.expect( "\$" ) |
| 1492 | self.handle.sendline( "" ) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 1493 | if grepOptions: |
| 1494 | grepStr = "grep "+str(grepOptions) |
| 1495 | else: |
| 1496 | grepStr = "grep" |
| 1497 | |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1498 | self.handle.sendline( |
| 1499 | "tshark -i " + |
| 1500 | str( interface ) + |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 1501 | " -t e | " + |
| 1502 | grepStr + " --line-buffered \"" + |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1503 | str(grep) + |
| 1504 | "\" >" + |
| 1505 | directory + |
| 1506 | " &" ) |
| 1507 | self.handle.sendline( "\r" ) |
| 1508 | self.handle.expect( "Capturing on" ) |
| 1509 | self.handle.sendline( "\r" ) |
| 1510 | self.handle.expect( "\$" ) |
| 1511 | except pexpect.EOF: |
| 1512 | main.log.error( self.name + ": EOF exception found" ) |
| 1513 | main.log.error( self.name + ": " + self.handle.before ) |
| 1514 | main.cleanup() |
| 1515 | main.exit() |
| 1516 | except Exception: |
| 1517 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1518 | main.cleanup() |
| 1519 | main.exit() |
| 1520 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1521 | def tsharkStop( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1522 | """ |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1523 | Removes wireshark files from /tmp and kills all tshark processes |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1524 | """ |
| 1525 | # Remove all pcap from previous captures |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1526 | try: |
| 1527 | self.execute( cmd="sudo rm /tmp/wireshark*" ) |
| 1528 | self.handle.sendline( "" ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1529 | self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\"" + |
| 1530 | " | grep -v grep | awk '{print $2}'`" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1531 | self.handle.sendline( "" ) |
| 1532 | main.log.info( "Tshark stopped" ) |
| 1533 | except pexpect.EOF: |
| 1534 | main.log.error( self.name + ": EOF exception found" ) |
| 1535 | main.log.error( self.name + ": " + self.handle.before ) |
| 1536 | main.cleanup() |
| 1537 | main.exit() |
| 1538 | except Exception: |
| 1539 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1540 | main.cleanup() |
| 1541 | main.exit() |
| 1542 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1543 | def ptpd( self, args ): |
| 1544 | """ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1545 | Initiate ptp with user-specified args. |
| 1546 | Required: |
| 1547 | * args: specify string of args after command |
| 1548 | 'sudo ptpd' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1549 | """ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1550 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1551 | self.handle.sendline( "sudo ptpd " + str( args ) ) |
| 1552 | i = self.handle.expect( [ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1553 | "Multiple", |
| 1554 | "Error", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1555 | "\$" ] ) |
| 1556 | self.handle.expect( "\$" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1557 | |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1558 | if i == 0: |
| 1559 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1560 | main.log.info( "ptpd returned an error: " + |
| 1561 | str( handle ) ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1562 | return handle |
| 1563 | elif i == 1: |
| 1564 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1565 | main.log.error( "ptpd returned an error: " + |
| 1566 | str( handle ) ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1567 | return handle |
| 1568 | else: |
| 1569 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1570 | |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1571 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1572 | main.log.error( self.name + ": EOF exception found" ) |
| 1573 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1574 | main.cleanup() |
| 1575 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1576 | except Exception: |
| 1577 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1578 | main.cleanup() |
| 1579 | main.exit() |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1580 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1581 | def cpLogsToDir( self, logToCopy, |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1582 | destDir, copyFileName="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1583 | """ |
| 1584 | Copies logs to a desired directory. |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1585 | Current implementation of ONOS deletes its karaf |
| 1586 | logs on every iteration. For debugging purposes, |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1587 | you may want to use this function to capture |
| 1588 | certain karaf logs. ( or any other logs if needed ) |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1589 | Localtime will be attached to the filename |
| 1590 | |
| 1591 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1592 | * logToCopy: specify directory and log name to |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1593 | copy. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1594 | ex ) /opt/onos/log/karaf.log.1 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1595 | For copying multiple files, leave copyFileName |
| 1596 | empty and only specify destDir - |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1597 | ex ) /opt/onos/log/karaf* |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1598 | * destDir: specify directory to copy to. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1599 | ex ) /tmp/ |
| 1600 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1601 | * copyFileName: If you want to rename the log |
| 1602 | file, specify copyFileName. This will not work |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1603 | with multiple file copying |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1604 | """ |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1605 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1606 | localtime = time.strftime( '%x %X' ) |
| 1607 | localtime = localtime.replace( "/", "" ) |
| 1608 | localtime = localtime.replace( " ", "_" ) |
| 1609 | localtime = localtime.replace( ":", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1610 | if destDir[ -1: ] != "/": |
| 1611 | destDir += "/" |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1612 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1613 | if copyFileName: |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1614 | self.handle.sendline( "cp " + str( logToCopy ) + " " + |
| 1615 | str( destDir ) + str( copyFileName ) + |
| 1616 | localtime ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1617 | self.handle.expect( "cp" ) |
| 1618 | self.handle.expect( "\$" ) |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1619 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1620 | self.handle.sendline( "cp " + str( logToCopy ) + |
| 1621 | " " + str( destDir ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1622 | self.handle.expect( "cp" ) |
| 1623 | self.handle.expect( "\$" ) |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1624 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1625 | return self.handle.before |
| 1626 | |
| 1627 | except pexpect.EOF: |
| 1628 | main.log.error( "Copying files failed" ) |
| 1629 | main.log.error( self.name + ": EOF exception found" ) |
| 1630 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1631 | except Exception: |
| 1632 | main.log.exception( "Copying files failed" ) |
| 1633 | |
Jon Hall | 16b72c4 | 2015-05-20 10:23:36 -0700 | [diff] [blame] | 1634 | def checkLogs( self, onosIp, restart=False): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1635 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1636 | runs onos-check-logs on the given onos node |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 1637 | If restart is True, use the old version of onos-check-logs which |
| 1638 | does not print the full stacktrace, but shows the entire log file, |
| 1639 | including across restarts |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1640 | returns the response |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1641 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1642 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1643 | cmd = "onos-check-logs " + str( onosIp ) |
Jon Hall | 16b72c4 | 2015-05-20 10:23:36 -0700 | [diff] [blame] | 1644 | if restart: |
| 1645 | cmd += " old" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1646 | self.handle.sendline( cmd ) |
| 1647 | self.handle.expect( cmd ) |
| 1648 | self.handle.expect( "\$" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1649 | response = self.handle.before |
| 1650 | return response |
| 1651 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1652 | main.log.error( "Lost ssh connection" ) |
| 1653 | main.log.error( self.name + ": EOF exception found" ) |
| 1654 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1655 | except Exception: |
| 1656 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1657 | main.cleanup() |
| 1658 | main.exit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1659 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1660 | def onosStatus( self, node="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1661 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1662 | Calls onos command: 'onos-service [<node-ip>] status' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1663 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1664 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1665 | self.handle.sendline( "" ) |
| 1666 | self.handle.expect( "\$" ) |
| 1667 | self.handle.sendline( "onos-service " + str( node ) + |
| 1668 | " status" ) |
| 1669 | i = self.handle.expect( [ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1670 | "start/running", |
| 1671 | "stop/waiting", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1672 | pexpect.TIMEOUT ], timeout=120 ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1673 | |
| 1674 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1675 | main.log.info( "ONOS is running" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1676 | return main.TRUE |
| 1677 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1678 | main.log.info( "ONOS is stopped" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1679 | main.log.error( "ONOS service failed to check the status" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1680 | main.cleanup() |
| 1681 | main.exit() |
| 1682 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1683 | main.log.error( self.name + ": EOF exception found" ) |
| 1684 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1685 | main.cleanup() |
| 1686 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1687 | except Exception: |
| 1688 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1689 | main.cleanup() |
| 1690 | main.exit() |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1691 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1692 | def setIpTables( self, ip, port='', action='add', packet_type='', |
| 1693 | direction='INPUT', rule='DROP', states=True ): |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1694 | """ |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1695 | Description: |
| 1696 | add or remove iptables rule to DROP (default) packets from |
| 1697 | specific IP and PORT |
| 1698 | Usage: |
| 1699 | * specify action ('add' or 'remove') |
| 1700 | when removing, pass in the same argument as you would add. It will |
| 1701 | delete that specific rule. |
| 1702 | * specify the ip to block |
| 1703 | * specify the destination port to block (defaults to all ports) |
| 1704 | * optional packet type to block (default tcp) |
| 1705 | * optional iptables rule (default DROP) |
| 1706 | * optional direction to block (default 'INPUT') |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1707 | * States boolean toggles adding all supported tcp states to the |
| 1708 | firewall rule |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1709 | Returns: |
| 1710 | main.TRUE on success or |
| 1711 | main.FALSE if given invalid input or |
| 1712 | main.ERROR if there is an error in response from iptables |
| 1713 | WARNING: |
| 1714 | * This function uses root privilege iptables command which may result |
| 1715 | in unwanted network errors. USE WITH CAUTION |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1716 | """ |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1717 | import time |
| 1718 | |
| 1719 | # NOTE********* |
| 1720 | # The strict checking methods of this driver function is intentional |
| 1721 | # to discourage any misuse or error of iptables, which can cause |
| 1722 | # severe network errors |
| 1723 | # ************* |
| 1724 | |
| 1725 | # NOTE: Sleep needed to give some time for rule to be added and |
| 1726 | # registered to the instance. If you are calling this function |
| 1727 | # multiple times this sleep will prevent any errors. |
| 1728 | # DO NOT REMOVE |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1729 | # time.sleep( 5 ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1730 | try: |
| 1731 | # input validation |
| 1732 | action_type = action.lower() |
| 1733 | rule = rule.upper() |
| 1734 | direction = direction.upper() |
| 1735 | if action_type != 'add' and action_type != 'remove': |
| 1736 | main.log.error( "Invalid action type. Use 'add' or " |
| 1737 | "'remove' table rule" ) |
| 1738 | if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG': |
| 1739 | # NOTE Currently only supports rules DROP, ACCEPT, and LOG |
| 1740 | main.log.error( "Invalid rule. Valid rules are 'DROP' or " |
| 1741 | "'ACCEPT' or 'LOG' only." ) |
| 1742 | if direction != 'INPUT' and direction != 'OUTPUT': |
| 1743 | # NOTE currently only supports rules INPUT and OUPTUT |
| 1744 | main.log.error( "Invalid rule. Valid directions are" |
| 1745 | " 'OUTPUT' or 'INPUT'" ) |
| 1746 | return main.FALSE |
| 1747 | return main.FALSE |
| 1748 | return main.FALSE |
| 1749 | if action_type == 'add': |
| 1750 | # -A is the 'append' action of iptables |
| 1751 | actionFlag = '-A' |
| 1752 | elif action_type == 'remove': |
| 1753 | # -D is the 'delete' rule of iptables |
| 1754 | actionFlag = '-D' |
| 1755 | self.handle.sendline( "" ) |
| 1756 | self.handle.expect( "\$" ) |
| 1757 | cmd = "sudo iptables " + actionFlag + " " +\ |
| 1758 | direction +\ |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1759 | " -s " + str( ip ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1760 | # " -p " + str( packet_type ) +\ |
| 1761 | if packet_type: |
| 1762 | cmd += " -p " + str( packet_type ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1763 | if port: |
| 1764 | cmd += " --dport " + str( port ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1765 | if states: |
| 1766 | cmd += " -m state --state=" |
| 1767 | #FIXME- Allow user to configure which states to block |
| 1768 | cmd += "INVALID,ESTABLISHED,NEW,RELATED,UNTRACKED" |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1769 | cmd += " -j " + str( rule ) |
| 1770 | |
| 1771 | self.handle.sendline( cmd ) |
| 1772 | self.handle.expect( "\$" ) |
| 1773 | main.log.warn( self.handle.before ) |
| 1774 | |
| 1775 | info_string = "On " + str( self.name ) |
| 1776 | info_string += " " + str( action_type ) |
| 1777 | info_string += " iptable rule [ " |
| 1778 | info_string += " IP: " + str( ip ) |
| 1779 | info_string += " Port: " + str( port ) |
| 1780 | info_string += " Rule: " + str( rule ) |
| 1781 | info_string += " Direction: " + str( direction ) + " ]" |
| 1782 | main.log.info( info_string ) |
| 1783 | return main.TRUE |
| 1784 | except pexpect.TIMEOUT: |
| 1785 | main.log.exception( self.name + ": Timeout exception in " |
| 1786 | "setIpTables function" ) |
| 1787 | return main.ERROR |
| 1788 | except pexpect.EOF: |
| 1789 | main.log.error( self.name + ": EOF exception found" ) |
| 1790 | main.log.error( self.name + ": " + self.handle.before ) |
| 1791 | main.cleanup() |
| 1792 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1793 | except Exception: |
| 1794 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1795 | main.cleanup() |
| 1796 | main.exit() |
| 1797 | |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1798 | def detailed_status(self, log_filename): |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1799 | """ |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1800 | This method is used by STS to check the status of the controller |
| 1801 | Reports RUNNING, STARTING, STOPPED, FROZEN, ERROR (and reason) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1802 | """ |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1803 | import re |
| 1804 | try: |
| 1805 | self.handle.sendline( "" ) |
| 1806 | self.handle.expect( "\$" ) |
| 1807 | self.handle.sendline( "cd " + self.home ) |
| 1808 | self.handle.expect( "\$" ) |
| 1809 | self.handle.sendline( "service onos status" ) |
| 1810 | self.handle.expect( "\$" ) |
| 1811 | response = self.handle.before |
| 1812 | if re.search( "onos start/running", response ): |
| 1813 | # onos start/running, process 10457 |
| 1814 | return 'RUNNING' |
| 1815 | # FIXME: Implement this case |
| 1816 | # elif re.search( pattern, response ): |
| 1817 | # return 'STARTING' |
| 1818 | elif re.search( "onos stop/", response ): |
| 1819 | # onos stop/waiting |
| 1820 | # FIXME handle this differently?: onos stop/pre-stop |
| 1821 | return 'STOPPED' |
| 1822 | # FIXME: Implement this case |
| 1823 | # elif re.search( pattern, response ): |
| 1824 | # return 'FROZEN' |
| 1825 | else: |
| 1826 | main.log.warn( self.name + |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1827 | " WARNING: status received unknown response" ) |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1828 | main.log.warn( response ) |
| 1829 | return 'ERROR', "Unknown response: %s" % response |
| 1830 | except pexpect.TIMEOUT: |
| 1831 | main.log.exception( self.name + ": Timeout exception in " |
| 1832 | "setIpTables function" ) |
| 1833 | return 'ERROR', "Pexpect Timeout" |
| 1834 | except pexpect.EOF: |
| 1835 | main.log.error( self.name + ": EOF exception found" ) |
| 1836 | main.log.error( self.name + ": " + self.handle.before ) |
| 1837 | main.cleanup() |
| 1838 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1839 | except Exception: |
| 1840 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1841 | main.cleanup() |
| 1842 | main.exit() |
| 1843 | |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1844 | def createLinkGraphFile( self, benchIp, ONOSIpList, deviceCount): |
| 1845 | ''' |
| 1846 | Create/formats the LinkGraph.cfg file based on arguments |
| 1847 | -only creates a linear topology and connects islands |
| 1848 | -evenly distributes devices |
| 1849 | -must be called by ONOSbench |
| 1850 | |
| 1851 | ONOSIpList - list of all of the node IPs to be used |
| 1852 | |
| 1853 | deviceCount - number of switches to be assigned |
| 1854 | ''' |
| 1855 | main.log.step("Creating link graph configuration file." ) |
| 1856 | linkGraphPath = self.home + "/tools/package/etc/linkGraph.cfg" |
| 1857 | tempFile = "/tmp/linkGraph.cfg" |
| 1858 | |
| 1859 | linkGraph = open(tempFile, 'w+') |
| 1860 | linkGraph.write("# NullLinkProvider topology description (config file).\n") |
| 1861 | linkGraph.write("# The NodeId is only added if the destination is another node's device.\n") |
| 1862 | linkGraph.write("# Bugs: Comments cannot be appended to a line to be read.\n") |
| 1863 | |
| 1864 | clusterCount = len(ONOSIpList) |
| 1865 | |
| 1866 | if type(deviceCount) is int or type(deviceCount) is str: |
| 1867 | deviceCount = int(deviceCount) |
| 1868 | switchList = [0]*(clusterCount+1) |
| 1869 | baselineSwitchCount = deviceCount/clusterCount |
| 1870 | |
| 1871 | for node in range(1, clusterCount + 1): |
| 1872 | switchList[node] = baselineSwitchCount |
| 1873 | |
| 1874 | for node in range(1, (deviceCount%clusterCount)+1): |
| 1875 | switchList[node] += 1 |
| 1876 | |
| 1877 | if type(deviceCount) is list: |
| 1878 | main.log.info("Using provided device distribution") |
| 1879 | switchList = [0] |
| 1880 | for i in deviceCount: |
| 1881 | switchList.append(int(i)) |
| 1882 | |
| 1883 | tempList = ['0'] |
| 1884 | tempList.extend(ONOSIpList) |
| 1885 | ONOSIpList = tempList |
| 1886 | |
| 1887 | myPort = 6 |
| 1888 | lastSwitch = 0 |
| 1889 | for node in range(1, clusterCount+1): |
| 1890 | if switchList[node] == 0: |
| 1891 | continue |
| 1892 | |
| 1893 | linkGraph.write("graph " + ONOSIpList[node] + " {\n") |
| 1894 | |
| 1895 | if node > 1: |
| 1896 | #connect to last device on previous node |
| 1897 | line = ("\t0:5 -> " + str(lastSwitch) + ":6:" + lastIp + "\n") #ONOSIpList[node-1] |
| 1898 | linkGraph.write(line) |
| 1899 | |
| 1900 | lastSwitch = 0 |
| 1901 | for switch in range (0, switchList[node]-1): |
| 1902 | line = "" |
| 1903 | line = ("\t" + str(switch) + ":" + str(myPort)) |
| 1904 | line += " -- " |
| 1905 | line += (str(switch+1) + ":" + str(myPort-1) + "\n") |
| 1906 | linkGraph.write(line) |
| 1907 | lastSwitch = switch+1 |
| 1908 | lastIp = ONOSIpList[node] |
| 1909 | |
| 1910 | #lastSwitch += 1 |
| 1911 | if node < (clusterCount): |
| 1912 | #connect to first device on the next node |
| 1913 | line = ("\t" + str(lastSwitch) + ":6 -> 0:5:" + ONOSIpList[node+1] + "\n") |
| 1914 | linkGraph.write(line) |
| 1915 | |
| 1916 | linkGraph.write("}\n") |
| 1917 | linkGraph.close() |
| 1918 | |
| 1919 | #SCP |
| 1920 | os.system( "scp " + tempFile + " admin@" + benchIp + ":" + linkGraphPath) |
| 1921 | main.log.info("linkGraph.cfg creation complete") |
| 1922 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 1923 | def configNullDev( self, ONOSIpList, deviceCount, numPorts=10): |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1924 | |
| 1925 | ''' |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1926 | ONOSIpList = list of Ip addresses of nodes switches will be devided amongst |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 1927 | deviceCount = number of switches to distribute, or list of values to use as custom distribution |
| 1928 | numPorts = number of ports per device. Defaults to 10 both in this function and in ONOS. Optional arg |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1929 | ''' |
| 1930 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 1931 | main.log.step("Configuring Null Device Provider" ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1932 | clusterCount = len(ONOSIpList) |
| 1933 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 1934 | try: |
| 1935 | |
| 1936 | if type(deviceCount) is int or type(deviceCount) is str: |
| 1937 | main.log.step("Creating device distribution") |
| 1938 | deviceCount = int(deviceCount) |
| 1939 | switchList = [0]*(clusterCount+1) |
| 1940 | baselineSwitchCount = deviceCount/clusterCount |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1941 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 1942 | for node in range(1, clusterCount + 1): |
| 1943 | switchList[node] = baselineSwitchCount |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1944 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 1945 | for node in range(1, (deviceCount%clusterCount)+1): |
| 1946 | switchList[node] += 1 |
| 1947 | |
| 1948 | if type(deviceCount) is list: |
| 1949 | main.log.info("Using provided device distribution") |
| 1950 | |
| 1951 | if len(deviceCount) == clusterCount: |
| 1952 | switchList = ['0'] |
| 1953 | switchList.extend(deviceCount) |
| 1954 | |
| 1955 | if len(deviceCount) == (clusterCount + 1): |
| 1956 | if deviceCount[0] == '0' or deviceCount[0] == 0: |
| 1957 | switchList = deviceCount |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1958 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 1959 | assert len(switchList) == (clusterCount + 1) |
| 1960 | |
| 1961 | except AssertionError: |
| 1962 | main.log.error( "Bad device/Ip list match") |
| 1963 | except TypeError: |
| 1964 | main.log.exception( self.name + ": Object not as expected" ) |
| 1965 | return None |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 1966 | except Exception: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 1967 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1968 | main.cleanup() |
| 1969 | main.exit() |
| 1970 | |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1971 | |
| 1972 | ONOSIp = [0] |
| 1973 | ONOSIp.extend(ONOSIpList) |
| 1974 | |
| 1975 | devicesString = "devConfigs = " |
| 1976 | for node in range(1, len(ONOSIp)): |
| 1977 | devicesString += (ONOSIp[node] + ":" + str(switchList[node] )) |
| 1978 | if node < clusterCount: |
| 1979 | devicesString += (",") |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 1980 | |
| 1981 | try: |
| 1982 | self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider devConfigs " + devicesString ) |
| 1983 | self.handle.expect(":~") |
| 1984 | self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider numPorts " + str(numPorts) ) |
| 1985 | self.handle.expect(":~") |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1986 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 1987 | for i in range(10): |
| 1988 | self.handle.sendline("onos $OC1 cfg get org.onosproject.provider.nil.device.impl.NullDeviceProvider") |
| 1989 | self.handle.expect(":~") |
| 1990 | verification = self.handle.before |
| 1991 | if (" value=" + str(numPorts)) in verification and (" value=" + devicesString) in verification: |
| 1992 | break |
| 1993 | else: |
| 1994 | time.sleep(1) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1995 | |
cameron@onlab.us | 2cc8bf1 | 2015-04-02 14:12:30 -0700 | [diff] [blame] | 1996 | assert ("value=" + str(numPorts)) in verification and (" value=" + devicesString) in verification |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 1997 | |
| 1998 | except AssertionError: |
| 1999 | main.log.error("Incorrect Config settings: " + verification) |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2000 | except Exception: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2001 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2002 | main.cleanup() |
| 2003 | main.exit() |
| 2004 | |
cameron@onlab.us | c80a8c8 | 2015-04-15 14:57:37 -0700 | [diff] [blame] | 2005 | def configNullLink( self,fileName="/opt/onos/apache-karaf-3.0.3/etc/linkGraph.cfg", eventRate=0): |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2006 | ''' |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2007 | fileName default is currently the same as the default on ONOS, specify alternate file if |
| 2008 | you want to use a different topology file than linkGraph.cfg |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2009 | ''' |
| 2010 | |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2011 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2012 | try: |
| 2013 | self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider eventRate " + str(eventRate)) |
| 2014 | self.handle.expect(":~") |
| 2015 | self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider cfgFile " + fileName ) |
| 2016 | self.handle.expect(":~") |
| 2017 | |
| 2018 | for i in range(10): |
| 2019 | self.handle.sendline("onos $OC1 cfg get org.onosproject.provider.nil.link.impl.NullLinkProvider") |
| 2020 | self.handle.expect(":~") |
| 2021 | verification = self.handle.before |
| 2022 | if (" value=" + str(eventRate)) in verification and (" value=" + fileName) in verification: |
| 2023 | break |
| 2024 | else: |
| 2025 | time.sleep(1) |
| 2026 | |
| 2027 | assert ("value=" + str(eventRate)) in verification and (" value=" + fileName) in verification |
| 2028 | |
| 2029 | except pexpect.EOF: |
| 2030 | main.log.error( self.name + ": EOF exception found" ) |
| 2031 | main.log.error( self.name + ": " + self.handle.before ) |
| 2032 | main.cleanup() |
| 2033 | main.exit() |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2034 | except AssertionError: |
| 2035 | main.log.info("Settings did not post to ONOS") |
| 2036 | main.log.error(varification) |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2037 | except Exception: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2038 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2039 | main.log.error(varification) |
| 2040 | main.cleanup() |
| 2041 | main.exit() |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2042 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 2043 | def getOnosIps( self ): |
| 2044 | """ |
| 2045 | Get all onos IPs stored in |
| 2046 | """ |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 2047 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 2048 | return sorted( self.onosIps.values() ) |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 2049 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 2050 | def logReport( self, nodeIp, searchTerms, outputMode="s" ): |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 2051 | ''' |
| 2052 | - accepts either a list or a string for "searchTerms" these |
| 2053 | terms will be searched for in the log and have their |
| 2054 | instances counted |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2055 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 2056 | - nodeIp is the ip of the node whos log is to be scanned |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2057 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 2058 | - output modes: |
| 2059 | "s" - Simple. Quiet output mode that just prints |
cameron@onlab.us | 2e16621 | 2015-05-19 14:28:25 -0700 | [diff] [blame] | 2060 | the occurences of each search term |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2061 | |
cameron@onlab.us | 2e16621 | 2015-05-19 14:28:25 -0700 | [diff] [blame] | 2062 | "d" - Detailed. Prints number of occurences as well as the entire |
| 2063 | line for each of the last 5 occurences |
| 2064 | |
| 2065 | - returns total of the number of instances of all search terms |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 2066 | ''' |
| 2067 | main.log.info("========================== Log Report ===========================\n") |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2068 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 2069 | if type(searchTerms) is str: |
| 2070 | searchTerms = [searchTerms] |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2071 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 2072 | logLines = [ [" "] for i in range(len(searchTerms)) ] |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2073 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 2074 | for term in range(len(searchTerms)): |
| 2075 | logLines[term][0] = searchTerms[term] |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2076 | |
cameron@onlab.us | 2e16621 | 2015-05-19 14:28:25 -0700 | [diff] [blame] | 2077 | totalHits = 0 |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 2078 | for term in range(len(searchTerms)): |
| 2079 | cmd = "onos-ssh " + nodeIp + " cat /opt/onos/log/karaf.log | grep " + searchTerms[term] |
| 2080 | self.handle.sendline(cmd) |
| 2081 | self.handle.expect(":~") |
| 2082 | before = (self.handle.before).splitlines() |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2083 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 2084 | count = [searchTerms[term],0] |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2085 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 2086 | for line in before: |
| 2087 | if searchTerms[term] in line and "grep" not in line: |
| 2088 | count[1] += 1 |
| 2089 | if before.index(line) > ( len(before) - 7 ): |
| 2090 | logLines[term].append(line) |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2091 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 2092 | main.log.info( str(count[0]) + ": " + str(count[1]) ) |
| 2093 | if term == len(searchTerms)-1: |
| 2094 | print("\n") |
cameron@onlab.us | 2e16621 | 2015-05-19 14:28:25 -0700 | [diff] [blame] | 2095 | totalHits += int(count[1]) |
| 2096 | |
cameron@onlab.us | 966d1be | 2015-05-15 14:54:09 -0700 | [diff] [blame] | 2097 | if outputMode != "s" and outputMode != "S": |
| 2098 | outputString = "" |
| 2099 | for i in logLines: |
| 2100 | outputString = i[0] + ": \n" |
| 2101 | for x in range(1,len(i)): |
| 2102 | outputString += ( i[x] + "\n" ) |
| 2103 | |
| 2104 | if outputString != (i[0] + ": \n"): |
| 2105 | main.log.info(outputString) |
| 2106 | |
| 2107 | main.log.info("================================================================\n") |
cameron@onlab.us | 2e16621 | 2015-05-19 14:28:25 -0700 | [diff] [blame] | 2108 | return totalHits |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 2109 | |
Hari Krishna | ade11a7 | 2015-07-01 17:06:46 -0700 | [diff] [blame] | 2110 | def getOnosIPfromCell(self): |
| 2111 | ''' |
| 2112 | Returns the ONOS node names and their IP addresses as defined in the cell and applied to shell environment |
Hari Krishna | a25104c | 2015-07-09 22:34:01 -0700 | [diff] [blame] | 2113 | Example output return: ['10.128.40.41','10.128.40.42','10.128.40.43']. This will work even if the Mininet is |
| 2114 | not part of the cell definition and also if there are multiple mininets, just by using static hostname |
| 2115 | in TOPO file. |
| 2116 | ''' |
Hari Krishna | ade11a7 | 2015-07-01 17:06:46 -0700 | [diff] [blame] | 2117 | import re |
| 2118 | try: |
| 2119 | # Clean handle by sending empty and expecting $ |
| 2120 | self.handle.sendline( "" ) |
| 2121 | self.handle.expect( "\$" ) |
| 2122 | self.handle.sendline( "cell" ) |
| 2123 | self.handle.expect( "\$" ) |
| 2124 | handleBefore = self.handle.before |
| 2125 | handleAfter = self.handle.after |
| 2126 | # Get the rest of the handle |
| 2127 | self.handle.sendline( "" ) |
| 2128 | self.handle.expect( "\$" ) |
| 2129 | handleMore = self.handle.before |
| 2130 | ipList = [] |
| 2131 | cellOutput = handleBefore + handleAfter + handleMore |
| 2132 | cellOutput = cellOutput.replace("\r\r","") |
| 2133 | cellOutput = cellOutput.splitlines() |
| 2134 | for i in range( len(cellOutput) ): |
| 2135 | if( re.match( "OC", cellOutput[i] ) ): |
| 2136 | if( re.match( "OCI", cellOutput[i] ) or re.match( "OCN", cellOutput[i] ) ): |
| 2137 | continue |
| 2138 | else: |
| 2139 | onosIP = cellOutput[i].split("=") |
Hari Krishna | c195f3b | 2015-07-08 20:02:24 -0700 | [diff] [blame] | 2140 | ipList.append(onosIP[1]) |
Hari Krishna | ade11a7 | 2015-07-01 17:06:46 -0700 | [diff] [blame] | 2141 | return ipList |
| 2142 | except pexpect.ExceptionPexpect as e: |
| 2143 | main.log.error( self.name + ": Pexpect exception found of type " + |
| 2144 | str( type( e ) ) ) |
| 2145 | main.log.error ( e.get_trace() ) |
| 2146 | main.log.error( self.name + ": " + self.handle.before ) |
| 2147 | main.cleanup() |
| 2148 | main.exit() |
| 2149 | except Exception: |
| 2150 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2151 | main.cleanup() |
| 2152 | main.exit() |
kelvin-onlab | 7a719bb | 2015-07-08 11:09:51 -0700 | [diff] [blame] | 2153 | |
| 2154 | def copyMininetFile( self, fileName, localPath, userName, ip, |
| 2155 | mnPath='~/mininet/custom/', timeout = 60 ): |
| 2156 | """ |
| 2157 | Description: |
| 2158 | Copy mininet topology file from dependency folder in the test folder |
| 2159 | and paste it to the mininet machine's mininet/custom folder |
| 2160 | Required: |
| 2161 | fileName - Name of the topology file to copy |
| 2162 | localPath - File path of the mininet topology file |
| 2163 | userName - User name of the mininet machine to send the file to |
| 2164 | ip - Ip address of the mininet machine |
| 2165 | Optional: |
| 2166 | mnPath - of the mininet directory to send the file to |
| 2167 | Return: |
| 2168 | Return main.TRUE if successfully copied the file otherwise |
| 2169 | return main.FALSE |
| 2170 | """ |
| 2171 | |
| 2172 | try: |
| 2173 | cmd = "scp " + localPath + fileName + " " + userName + "@" + \ |
| 2174 | str( ip ) + ":" + mnPath + fileName |
| 2175 | |
| 2176 | self.handle.sendline( "" ) |
| 2177 | self.handle.expect( "\$" ) |
| 2178 | |
| 2179 | main.log.info( self.name + ": Execute: " + cmd ) |
| 2180 | |
| 2181 | self.handle.sendline( cmd ) |
| 2182 | |
| 2183 | i = self.handle.expect( [ 'No such file', |
| 2184 | "100%", |
| 2185 | pexpect.TIMEOUT ] ) |
| 2186 | |
| 2187 | if i == 0: |
| 2188 | main.log.error( self.name + ": File " + fileName + |
| 2189 | " does not exist!" ) |
| 2190 | return main.FALSE |
| 2191 | |
| 2192 | if i == 1: |
| 2193 | main.log.info( self.name + ": File " + fileName + |
| 2194 | " has been copied!" ) |
| 2195 | self.handle.sendline( "" ) |
| 2196 | self.handle.expect( "\$" ) |
| 2197 | return main.TRUE |
| 2198 | |
| 2199 | except pexpect.EOF: |
| 2200 | main.log.error( self.name + ": EOF exception found" ) |
| 2201 | main.log.error( self.name + ": " + self.handle.before ) |
| 2202 | main.cleanup() |
| 2203 | main.exit() |
| 2204 | except pexpect.TIMEOUT: |
| 2205 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 2206 | main.log.error( self.name + ": " + self.handle.before ) |
| 2207 | main.cleanup() |
| 2208 | main.exit() |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2209 | |
| 2210 | def jvmSet(self, memory=8): |
| 2211 | |
| 2212 | import os |
| 2213 | |
| 2214 | homeDir = os.path.expanduser('~') |
| 2215 | filename = "/onos/tools/package/bin/onos-service" |
| 2216 | |
| 2217 | serviceConfig = open(homeDir + filename, 'w+') |
| 2218 | serviceConfig.write("#!/bin/bash\n ") |
| 2219 | serviceConfig.write("#------------------------------------- \n ") |
| 2220 | serviceConfig.write("# Starts ONOS Apache Karaf container\n ") |
| 2221 | serviceConfig.write("#------------------------------------- \n ") |
| 2222 | serviceConfig.write("#export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-openjdk-amd64/}\n ") |
| 2223 | serviceConfig.write("""export JAVA_OPTS="${JAVA_OPTS:--Xms""" + str(memory) + "G -Xmx" + str(memory) + """G}" \n """) |
| 2224 | serviceConfig.write("[ -d $ONOS_HOME ] && cd $ONOS_HOME || ONOS_HOME=$(dirname $0)/..\n") |
| 2225 | serviceConfig.write("""${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/karaf "$@" \n """) |
| 2226 | serviceConfig.close() |
| 2227 | |
| 2228 | def createDBFile(self, testData): |
| 2229 | |
| 2230 | filename = main.TEST + "DB" |
| 2231 | DBString = "" |
| 2232 | |
| 2233 | for item in testData: |
| 2234 | if type(item) is string: |
| 2235 | item = "'" + item + "'" |
| 2236 | if testData.index(item) < len(testData-1): |
| 2237 | item += "," |
| 2238 | DBString += str(item) |
| 2239 | |
| 2240 | DBFile = open(filename, "a") |
| 2241 | DBFile.write(DBString) |
| 2242 | DBFile.close() |
| 2243 | |
| 2244 | def verifySummary(self, ONOSIp,*deviceCount): |
| 2245 | |
| 2246 | self.handle.sendline("onos " + ONOSIp + " summary") |
| 2247 | self.handle.expect(":~") |
| 2248 | |
| 2249 | summaryStr = self.handle.before |
| 2250 | print "\nSummary\n==============\n" + summaryStr + "\n\n" |
| 2251 | |
| 2252 | #passed = "SCC(s)=1" in summaryStr |
| 2253 | #if deviceCount: |
| 2254 | # passed = "devices=" + str(deviceCount) + "," not in summaryStr |
| 2255 | |
| 2256 | |
| 2257 | if "SCC(s)=1," in summaryStr: |
| 2258 | passed = True |
| 2259 | print("Summary is verifed") |
| 2260 | else: |
| 2261 | print("Summary failed") |
| 2262 | |
| 2263 | if deviceCount: |
| 2264 | print" =============================" |
| 2265 | checkStr = "devices=" + str(deviceCount[0]) + "," |
| 2266 | print "Checkstr: " + checkStr |
| 2267 | if checkStr not in summaryStr: |
| 2268 | passed = False |
| 2269 | print("Device count failed") |
| 2270 | else: |
| 2271 | print "device count verified" |
| 2272 | |
| 2273 | return passed |