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