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