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