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