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