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 ): |
You Wang | 9cdf9a2 | 2017-05-01 13:44:18 -0700 | [diff] [blame] | 659 | import re |
| 660 | try: |
| 661 | main.log.info( "self.home = " ) |
| 662 | main.log.info( self.home ) |
| 663 | self.handle.sendline( "cd " + self.home ) |
| 664 | self.handle.expect( self.home + "\$" ) |
| 665 | self.handle.sendline( "git name-rev --name-only HEAD" ) |
| 666 | self.handle.expect( "git name-rev --name-only HEAD" ) |
| 667 | self.handle.expect( "\$" ) |
| 668 | lines = self.handle.before.splitlines() |
| 669 | if lines[1] == "master" or re.search( "^onos-\d+(\.\d+)+$", lines[1] ): |
| 670 | return lines[1] |
| 671 | else: |
| 672 | main.log.info( lines[1] ) |
| 673 | return "unexpected ONOS branch" |
| 674 | except pexpect.EOF: |
| 675 | main.log.error( self.name + ": EOF exception found" ) |
| 676 | main.log.error( self.name + ": " + self.handle.before ) |
| 677 | main.cleanup() |
| 678 | main.exit() |
| 679 | except pexpect.TIMEOUT: |
| 680 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 681 | main.log.error( self.name + ": " + self.handle.before ) |
| 682 | main.cleanup() |
| 683 | main.exit() |
| 684 | except Exception: |
| 685 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 686 | main.cleanup() |
| 687 | main.exit() |
pingping-lin | 6d23d9e | 2015-02-02 16:54:24 -0800 | [diff] [blame] | 688 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 689 | def getVersion( self, report=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 690 | """ |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 691 | Writes the COMMIT number to the report to be parsed |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 692 | by Jenkins data collector. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 693 | """ |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 694 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 695 | self.handle.sendline( "" ) |
| 696 | self.handle.expect( "\$" ) |
| 697 | self.handle.sendline( |
| 698 | "cd " + |
| 699 | self.home + |
Jon Hall | 274b664 | 2015-02-17 11:57:17 -0800 | [diff] [blame] | 700 | "; git log -1 --pretty=fuller --decorate=short | grep -A 6 " + |
| 701 | " \"commit\" --color=never" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 702 | # NOTE: for some reason there are backspaces inserted in this |
| 703 | # phrase when run from Jenkins on some tests |
| 704 | self.handle.expect( "never" ) |
| 705 | self.handle.expect( "\$" ) |
| 706 | response = ( self.name + ": \n" + str( |
| 707 | self.handle.before + self.handle.after ) ) |
| 708 | self.handle.sendline( "cd " + self.home ) |
| 709 | self.handle.expect( "\$" ) |
| 710 | lines = response.splitlines() |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 711 | for line in lines: |
Jon Hall | fd19120 | 2014-11-07 18:36:09 -0500 | [diff] [blame] | 712 | print line |
| 713 | if report: |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 714 | main.log.wiki( "<blockquote>" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 715 | for line in lines[ 2:-1 ]: |
| 716 | # Bracket replacement is for Wiki-compliant |
| 717 | # formatting. '<' or '>' are interpreted |
| 718 | # as xml specific tags that cause errors |
| 719 | line = line.replace( "<", "[" ) |
| 720 | line = line.replace( ">", "]" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 721 | #main.log.wiki( "\t" + line ) |
| 722 | main.log.wiki( line + "<br /> " ) |
| 723 | main.log.summary( line ) |
| 724 | main.log.wiki( "</blockquote>" ) |
| 725 | main.log.summary("\n") |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 726 | return lines[ 2 ] |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 727 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 728 | main.log.error( self.name + ": EOF exception found" ) |
| 729 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 730 | main.cleanup() |
| 731 | main.exit() |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 732 | except pexpect.TIMEOUT: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 733 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 734 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 735 | main.cleanup() |
| 736 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 737 | except Exception: |
| 738 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 739 | main.cleanup() |
| 740 | main.exit() |
| 741 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 742 | def createCellFile( self, benchIp, fileName, mnIpAddrs, |
Jon Hall | 810b67d | 2016-12-05 10:19:01 -0800 | [diff] [blame] | 743 | appString, onosIpAddrs, onosUser="sdn", useSSH=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 744 | """ |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 745 | Creates a cell file based on arguments |
| 746 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 747 | * Bench IP address ( benchIp ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 748 | - Needed to copy the cell file over |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 749 | * File name of the cell file ( fileName ) |
| 750 | * Mininet IP address ( mnIpAddrs ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 751 | - Note that only 1 ip address is |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 752 | supported currently |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 753 | * ONOS IP addresses ( onosIpAddrs ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 754 | - Must be passed in as last arguments |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 755 | * ONOS USER (onosUser) |
| 756 | - optional argument to set ONOS_USER environment variable |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 757 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 758 | NOTE: Assumes cells are located at: |
| 759 | ~/<self.home>/tools/test/cells/ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 760 | """ |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 761 | try: |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 762 | # Variable initialization |
| 763 | cellDirectory = self.home + "/tools/test/cells/" |
| 764 | # We want to create the cell file in the dependencies directory |
| 765 | # of TestON first, then copy over to ONOS bench |
| 766 | tempDirectory = "/tmp/" |
| 767 | # Create the cell file in the directory for writing ( w+ ) |
| 768 | cellFile = open( tempDirectory + fileName, 'w+' ) |
| 769 | if isinstance( onosIpAddrs, types.StringType ): |
| 770 | onosIpAddrs = [ onosIpAddrs ] |
| 771 | |
| 772 | # App string is hardcoded environment variables |
| 773 | # That you may wish to use by default on startup. |
| 774 | # Note that you may not want certain apps listed |
| 775 | # on here. |
| 776 | appString = "export ONOS_APPS=" + appString |
| 777 | onosGroup = "export ONOS_GROUP=" + onosUser |
| 778 | onosUser = "export ONOS_USER=" + onosUser |
| 779 | if useSSH: |
| 780 | onosUseSSH = "export ONOS_USE_SSH=true" |
| 781 | mnString = "export OCN=" |
| 782 | if mnIpAddrs == "": |
| 783 | mnString = "" |
| 784 | onosString = "export OC" |
| 785 | tempCount = 1 |
| 786 | |
| 787 | # Create ONOSNIC ip address prefix |
| 788 | tempOnosIp = str( onosIpAddrs[ 0 ] ) |
| 789 | tempList = [] |
| 790 | tempList = tempOnosIp.split( "." ) |
| 791 | # Omit last element of list to format for NIC |
| 792 | tempList = tempList[ :-1 ] |
| 793 | # Structure the nic string ip |
| 794 | nicAddr = ".".join( tempList ) + ".*" |
| 795 | self.nicAddr = nicAddr |
| 796 | onosNicString = "export ONOS_NIC=" + nicAddr |
| 797 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 798 | # Start writing to file |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 799 | cellFile.write( onosNicString + "\n" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 800 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 801 | for arg in onosIpAddrs: |
| 802 | # For each argument in onosIpAddrs, write to file |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 803 | # Output should look like the following: |
andrewonlab | d494049 | 2014-10-24 12:21:27 -0400 | [diff] [blame] | 804 | # export OC1="10.128.20.11" |
| 805 | # export OC2="10.128.20.12" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 806 | cellFile.write( onosString + str( tempCount ) + |
Jon Hall | 6f66565 | 2015-09-18 10:08:07 -0700 | [diff] [blame] | 807 | "=\"" + arg + "\"\n" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 808 | tempCount = tempCount + 1 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 809 | |
Jon Hall | 6f66565 | 2015-09-18 10:08:07 -0700 | [diff] [blame] | 810 | cellFile.write( "export OCI=$OC1\n" ) |
| 811 | cellFile.write( mnString + "\"" + mnIpAddrs + "\"\n" ) |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 812 | cellFile.write( appString + "\n" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 813 | cellFile.write( onosGroup + "\n" ) |
| 814 | cellFile.write( onosUser + "\n" ) |
Pier | 88189b6 | 2016-09-07 17:01:53 -0700 | [diff] [blame] | 815 | if useSSH: |
| 816 | cellFile.write( onosUseSSH + "\n" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 817 | cellFile.close() |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 818 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 819 | # We use os.system to send the command to TestON cluster |
| 820 | # to account for the case in which TestON is not located |
| 821 | # on the same cluster as the ONOS bench |
| 822 | # Note that even if TestON is located on the same cluster |
| 823 | # as ONOS bench, you must setup passwordless ssh |
| 824 | # between TestON and ONOS bench in order to automate the test. |
kelvin-onlab | c2b7910 | 2015-07-14 11:41:20 -0700 | [diff] [blame] | 825 | os.system( "scp " + tempDirectory + fileName + " " + |
| 826 | self.user_name + "@" + self.ip_address + ":" + cellDirectory ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 827 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 828 | return main.TRUE |
| 829 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 830 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 831 | main.log.error( self.name + ": EOF exception found" ) |
| 832 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 833 | main.cleanup() |
| 834 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 835 | except Exception: |
| 836 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 837 | main.cleanup() |
| 838 | main.exit() |
| 839 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 840 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 841 | """ |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 842 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 843 | """ |
Hari Krishna | 03f530e | 2015-07-10 17:28:27 -0700 | [diff] [blame] | 844 | import re |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 845 | try: |
| 846 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 847 | main.log.error( "Must define cellname" ) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 848 | main.cleanup() |
| 849 | main.exit() |
| 850 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 851 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 852 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 853 | # Note that this variable name is subject to change |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 854 | # and that this driver will have to change accordingly |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 855 | self.handle.expect( str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 856 | handleBefore = self.handle.before |
| 857 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 858 | # Get the rest of the handle |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 859 | self.handle.expect( "\$" ) |
Jon Hall | 439c891 | 2016-04-15 02:22:03 -0700 | [diff] [blame] | 860 | time.sleep(10) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 861 | handleMore = self.handle.before |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 862 | |
Hari Krishna | 03f530e | 2015-07-10 17:28:27 -0700 | [diff] [blame] | 863 | cell_result = handleBefore + handleAfter + handleMore |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 864 | #print cell_result |
Hari Krishna | 03f530e | 2015-07-10 17:28:27 -0700 | [diff] [blame] | 865 | if( re.search( "No such cell", cell_result ) ): |
| 866 | main.log.error( "Cell call returned: " + handleBefore + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 867 | handleAfter + handleMore ) |
Hari Krishna | 03f530e | 2015-07-10 17:28:27 -0700 | [diff] [blame] | 868 | main.cleanup() |
| 869 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 870 | return main.TRUE |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 871 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 872 | main.log.error( self.name + ": EOF exception found" ) |
| 873 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 874 | main.cleanup() |
| 875 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 876 | except Exception: |
| 877 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 878 | main.cleanup() |
| 879 | main.exit() |
| 880 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 881 | def verifyCell( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 882 | """ |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 883 | Calls 'onos-verify-cell' to check for cell installation |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 884 | """ |
| 885 | # TODO: Add meaningful expect value |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 886 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 887 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 888 | # Clean handle by sending empty and expecting $ |
| 889 | self.handle.sendline( "" ) |
| 890 | self.handle.expect( "\$" ) |
| 891 | self.handle.sendline( "onos-verify-cell" ) |
| 892 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 893 | handleBefore = self.handle.before |
| 894 | handleAfter = self.handle.after |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 895 | main.log.info( "Verify cell returned: " + handleBefore + |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 896 | handleAfter ) |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 897 | return main.TRUE |
Jon Hall | a5cb617 | 2015-02-23 09:28:28 -0800 | [diff] [blame] | 898 | except pexpect.ExceptionPexpect as e: |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 899 | main.log.exception( self.name + ": Pexpect exception found: " ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 900 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 901 | main.cleanup() |
| 902 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 903 | except Exception: |
| 904 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 905 | main.cleanup() |
| 906 | main.exit() |
| 907 | |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 908 | def onosCfgSet( self, ONOSIp, configName, configParam ): |
| 909 | """ |
| 910 | 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] | 911 | application. |
| 912 | |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 913 | ex) |
| 914 | onos 10.0.0.1 cfg set org.onosproject.myapp appSetting 1 |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 915 | ONOSIp = '10.0.0.1' |
| 916 | configName = 'org.onosproject.myapp' |
| 917 | configParam = 'appSetting 1' |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 918 | """ |
Jon Hall | 72280bc | 2016-01-25 14:29:05 -0800 | [diff] [blame] | 919 | try: |
| 920 | cfgStr = "onos {} cfg set {} {}".format( ONOSIp, |
| 921 | configName, |
| 922 | configParam ) |
| 923 | self.handle.sendline( "" ) |
| 924 | self.handle.expect( ":~" ) |
| 925 | self.handle.sendline( cfgStr ) |
| 926 | self.handle.expect("cfg set") |
| 927 | self.handle.expect( ":~" ) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 928 | |
Jon Hall | 72280bc | 2016-01-25 14:29:05 -0800 | [diff] [blame] | 929 | paramValue = configParam.split(" ")[1] |
| 930 | paramName = configParam.split(" ")[0] |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 931 | |
Jon Hall | 72280bc | 2016-01-25 14:29:05 -0800 | [diff] [blame] | 932 | checkStr = 'onos {} cfg get " {} {} " '.format( ONOSIp, configName, paramName ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 933 | |
Jon Hall | 72280bc | 2016-01-25 14:29:05 -0800 | [diff] [blame] | 934 | self.handle.sendline( checkStr ) |
| 935 | self.handle.expect( ":~" ) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 936 | |
Jon Hall | 72280bc | 2016-01-25 14:29:05 -0800 | [diff] [blame] | 937 | if "value=" + paramValue + "," in self.handle.before: |
| 938 | main.log.info("cfg " + configName + " successfully set to " + configParam) |
| 939 | return main.TRUE |
| 940 | except pexpect.ExceptionPexpect as e: |
| 941 | main.log.exception( self.name + ": Pexpect exception found: " ) |
| 942 | main.log.error( self.name + ": " + self.handle.before ) |
| 943 | main.cleanup() |
| 944 | main.exit() |
| 945 | except Exception: |
| 946 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 947 | main.cleanup() |
| 948 | main.exit() |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 949 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 950 | def onosCli( self, ONOSIp, cmdstr ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 951 | """ |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 952 | Uses 'onos' command to send various ONOS CLI arguments. |
| 953 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 954 | * ONOSIp: specify the ip of the cell machine |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 955 | * cmdstr: specify the command string to send |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 956 | |
| 957 | This function is intended to expose the entire karaf |
andrewonlab | 6e20c34 | 2014-10-10 18:08:48 -0400 | [diff] [blame] | 958 | CLI commands for ONOS. Try to use this function first |
| 959 | before attempting to write a ONOS CLI specific driver |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 960 | function. |
| 961 | You can see a list of available 'cmdstr' arguments |
andrewonlab | 6e20c34 | 2014-10-10 18:08:48 -0400 | [diff] [blame] | 962 | by starting onos, and typing in 'onos' to enter the |
| 963 | onos> CLI. Then, type 'help' to see the list of |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 964 | available commands. |
| 965 | """ |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 966 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 967 | if not ONOSIp: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 968 | main.log.error( "You must specify the IP address" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 969 | return main.FALSE |
| 970 | if not cmdstr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 971 | main.log.error( "You must specify the command string" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 972 | return main.FALSE |
| 973 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 974 | cmdstr = str( cmdstr ) |
| 975 | self.handle.sendline( "" ) |
| 976 | self.handle.expect( "\$" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 977 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 978 | self.handle.sendline( "onos -w " + ONOSIp + " " + cmdstr ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 979 | self.handle.expect( "\$" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 980 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 981 | handleBefore = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 982 | main.log.info( "Command sent successfully" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 983 | # Obtain return handle that consists of result from |
| 984 | # the onos command. The string may need to be |
| 985 | # configured further. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 986 | returnString = handleBefore |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 987 | return returnString |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 988 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 989 | main.log.error( self.name + ": EOF exception found" ) |
| 990 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 991 | main.cleanup() |
| 992 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 993 | except Exception: |
| 994 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 995 | main.cleanup() |
| 996 | main.exit() |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 997 | |
Pier | 88189b6 | 2016-09-07 17:01:53 -0700 | [diff] [blame] | 998 | def onosSecureSSH( self, userName="onos", userPWD="rocks", node=""): |
| 999 | """ |
| 1000 | Enables secure access to ONOS console |
| 1001 | by removing default users & keys. |
| 1002 | |
| 1003 | onos-secure-ssh -u onos -p rocks node |
| 1004 | |
| 1005 | Returns: main.TRUE on success and main.FALSE on failure |
| 1006 | """ |
| 1007 | |
| 1008 | try: |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 1009 | self.handle.sendline( "" ) |
| 1010 | self.handle.expect( "\$" ) |
Pier | 88189b6 | 2016-09-07 17:01:53 -0700 | [diff] [blame] | 1011 | self.handle.sendline( " onos-secure-ssh -u " + userName + " -p " + userPWD + " " + node ) |
| 1012 | |
| 1013 | # NOTE: this timeout may need to change depending on the network |
| 1014 | # and size of ONOS |
| 1015 | # TODO: Handle the other possible error |
| 1016 | i = self.handle.expect([ "Network\sis\sunreachable", |
| 1017 | "\$", |
| 1018 | pexpect.TIMEOUT ], timeout=180 ) |
| 1019 | if i == 0: |
| 1020 | # can't reach ONOS node |
| 1021 | main.log.warn( "Network is unreachable" ) |
| 1022 | self.handle.expect( "\$" ) |
| 1023 | return main.FALSE |
| 1024 | elif i == 1: |
| 1025 | # Process started |
| 1026 | main.log.info( |
| 1027 | "Secure SSH performed on " + |
| 1028 | node) |
| 1029 | return main.TRUE |
| 1030 | except pexpect.EOF: |
| 1031 | main.log.error( self.name + ": EOF exception found" ) |
| 1032 | main.log.error( self.name + ": " + self.handle.before ) |
| 1033 | main.cleanup() |
| 1034 | main.exit() |
| 1035 | except Exception: |
| 1036 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1037 | main.cleanup() |
| 1038 | main.exit() |
| 1039 | |
| 1040 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1041 | def onosInstall( self, options="-f", node="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1042 | """ |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1043 | Installs ONOS bits on the designated cell machine. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1044 | If -f option is provided, it also forces an uninstall. |
| 1045 | Presently, install also includes onos-push-bits and |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1046 | onos-config within. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1047 | The node option allows you to selectively only push the jar |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1048 | files to certain onos nodes |
| 1049 | |
| 1050 | Returns: main.TRUE on success and main.FALSE on failure |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1051 | """ |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1052 | try: |
andrewonlab | 114768a | 2014-11-14 12:44:44 -0500 | [diff] [blame] | 1053 | if options: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1054 | self.handle.sendline( "onos-install " + options + " " + node ) |
andrewonlab | 114768a | 2014-11-14 12:44:44 -0500 | [diff] [blame] | 1055 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1056 | self.handle.sendline( "onos-install " + node ) |
| 1057 | self.handle.expect( "onos-install " ) |
| 1058 | # NOTE: this timeout may need to change depending on the network |
| 1059 | # and size of ONOS |
| 1060 | i = self.handle.expect( [ "Network\sis\sunreachable", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1061 | "onos\sstart/running,\sprocess", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1062 | "ONOS\sis\salready\sinstalled", |
Jeremy | c72b258 | 2016-02-26 18:27:38 -0800 | [diff] [blame] | 1063 | "already\sup-to-date", |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1064 | "does not exist", |
Jeremy | c72b258 | 2016-02-26 18:27:38 -0800 | [diff] [blame] | 1065 | "\$", |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 1066 | pexpect.TIMEOUT ], timeout=180 ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1067 | if i == 0: |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1068 | # can't reach ONOS node |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1069 | main.log.warn( "Network is unreachable" ) |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 1070 | self.handle.expect( "\$" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1071 | return main.FALSE |
| 1072 | elif i == 1: |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1073 | # Process started |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1074 | main.log.info( |
| 1075 | "ONOS was installed on " + |
| 1076 | node + |
| 1077 | " and started" ) |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 1078 | self.handle.expect( "\$" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1079 | return main.TRUE |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1080 | elif i == 2 or i == 3: |
| 1081 | # same bits are already on ONOS node |
Jeremy | c72b258 | 2016-02-26 18:27:38 -0800 | [diff] [blame] | 1082 | main.log.info( "ONOS is already installed on " + node ) |
| 1083 | self.handle.expect( "\$" ) |
| 1084 | return main.TRUE |
| 1085 | elif i == 4: |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1086 | # onos not packaged |
| 1087 | main.log.error( "ONOS package not found." ) |
| 1088 | self.handle.expect( "\$" ) |
| 1089 | return main.FALSE |
| 1090 | elif i == 5: |
| 1091 | # prompt |
Jeremy | c72b258 | 2016-02-26 18:27:38 -0800 | [diff] [blame] | 1092 | main.log.info( "ONOS was installed on " + node ) |
| 1093 | return main.TRUE |
Jon Hall | 3576f57 | 2016-08-23 10:01:07 -0700 | [diff] [blame] | 1094 | elif i == 6: |
| 1095 | # timeout |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1096 | main.log.info( |
| 1097 | "Installation of ONOS on " + |
| 1098 | node + |
| 1099 | " timed out" ) |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 1100 | self.handle.expect( "\$" ) |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 1101 | main.log.warn( self.handle.before ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1102 | return main.FALSE |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 1103 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1104 | main.log.error( self.name + ": EOF exception found" ) |
| 1105 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 1106 | main.cleanup() |
| 1107 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1108 | except Exception: |
| 1109 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 1110 | main.cleanup() |
| 1111 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 1112 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1113 | def onosStart( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1114 | """ |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1115 | Calls onos command: 'onos-service [<node-ip>] start' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1116 | This command is a remote management of the ONOS upstart daemon |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1117 | """ |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1118 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1119 | self.handle.sendline( "" ) |
| 1120 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1121 | self.handle.sendline( "onos-service " + str( nodeIp ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1122 | " start" ) |
| 1123 | i = self.handle.expect( [ |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1124 | "Job\sis\salready\srunning", |
| 1125 | "start/running", |
Jeremy | d0e9a6d | 2016-03-02 11:28:52 -0800 | [diff] [blame] | 1126 | "\$", |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1127 | "Unknown\sinstance", |
Jeremy Songster | 14c1357 | 2016-04-21 17:34:03 -0700 | [diff] [blame] | 1128 | pexpect.TIMEOUT ], timeout=180 ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1129 | if i == 0: |
Jon Hall | eab7a24 | 2016-03-04 10:20:43 -0800 | [diff] [blame] | 1130 | self.handle.expect( "\$" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1131 | main.log.info( "Service is already running" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1132 | return main.TRUE |
| 1133 | elif i == 1: |
Jon Hall | eab7a24 | 2016-03-04 10:20:43 -0800 | [diff] [blame] | 1134 | self.handle.expect( "\$" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1135 | main.log.info( "ONOS service started" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1136 | return main.TRUE |
Jeremy | d0e9a6d | 2016-03-02 11:28:52 -0800 | [diff] [blame] | 1137 | elif i == 2: |
| 1138 | main.log.info( "ONOS service started" ) |
| 1139 | return main.TRUE |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1140 | else: |
Jon Hall | eab7a24 | 2016-03-04 10:20:43 -0800 | [diff] [blame] | 1141 | self.handle.expect( "\$" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1142 | main.log.error( "ONOS service failed to start" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1143 | main.cleanup() |
| 1144 | main.exit() |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1145 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1146 | main.log.error( self.name + ": EOF exception found" ) |
| 1147 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1148 | main.cleanup() |
| 1149 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1150 | except Exception: |
| 1151 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1152 | main.cleanup() |
| 1153 | main.exit() |
| 1154 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1155 | def onosStop( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1156 | """ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1157 | Calls onos command: 'onos-service [<node-ip>] stop' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1158 | This command is a remote management of the ONOS upstart daemon |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1159 | """ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1160 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1161 | self.handle.sendline( "" ) |
| 1162 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1163 | self.handle.sendline( "onos-service " + str( nodeIp ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1164 | " stop" ) |
| 1165 | i = self.handle.expect( [ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1166 | "stop/waiting", |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1167 | "Could not resolve hostname", |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1168 | "Unknown\sinstance", |
YPZhang | 77badfc | 2016-03-09 10:28:59 -0800 | [diff] [blame] | 1169 | "\$", |
Jeremy Songster | 14c1357 | 2016-04-21 17:34:03 -0700 | [diff] [blame] | 1170 | pexpect.TIMEOUT ], timeout=180 ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1171 | if i == 0: |
YPZhang | 77badfc | 2016-03-09 10:28:59 -0800 | [diff] [blame] | 1172 | self.handle.expect( "\$" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1173 | main.log.info( "ONOS service stopped" ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1174 | return main.TRUE |
| 1175 | elif i == 1: |
YPZhang | 77badfc | 2016-03-09 10:28:59 -0800 | [diff] [blame] | 1176 | self.handle.expect( "\$" ) |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 1177 | main.log.info( "onosStop() Unknown ONOS instance specified: " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1178 | str( nodeIp ) ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1179 | return main.FALSE |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1180 | elif i == 2: |
YPZhang | 77badfc | 2016-03-09 10:28:59 -0800 | [diff] [blame] | 1181 | self.handle.expect( "\$" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1182 | main.log.warn( "ONOS wasn't running" ) |
| 1183 | return main.TRUE |
YPZhang | 77badfc | 2016-03-09 10:28:59 -0800 | [diff] [blame] | 1184 | elif i == 3: |
| 1185 | main.log.info( "ONOS service stopped" ) |
| 1186 | return main.TRUE |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1187 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1188 | main.log.error( "ONOS service failed to stop" ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1189 | return main.FALSE |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1190 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1191 | main.log.error( self.name + ": EOF exception found" ) |
| 1192 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1193 | main.cleanup() |
| 1194 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1195 | except Exception: |
| 1196 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1197 | main.cleanup() |
| 1198 | main.exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1199 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1200 | def onosUninstall( self, nodeIp="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1201 | """ |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1202 | Calls the command: 'onos-uninstall' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1203 | Uninstalls ONOS from the designated cell machine, stopping |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1204 | if needed |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1205 | """ |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1206 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1207 | self.handle.sendline( "" ) |
Jeremy Songster | 14c1357 | 2016-04-21 17:34:03 -0700 | [diff] [blame] | 1208 | self.handle.expect( "\$", timeout=180 ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1209 | self.handle.sendline( "onos-uninstall " + str( nodeIp ) ) |
Jeremy Songster | 14c1357 | 2016-04-21 17:34:03 -0700 | [diff] [blame] | 1210 | self.handle.expect( "\$", timeout=180 ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1211 | main.log.info( "ONOS " + nodeIp + " was uninstalled" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1212 | # onos-uninstall command does not return any text |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1213 | return main.TRUE |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 1214 | except pexpect.TIMEOUT: |
| 1215 | main.log.exception( self.name + ": Timeout in onosUninstall" ) |
| 1216 | return main.FALSE |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1217 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1218 | main.log.error( self.name + ": EOF exception found" ) |
| 1219 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1220 | main.cleanup() |
| 1221 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1222 | except Exception: |
| 1223 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 1224 | main.cleanup() |
| 1225 | main.exit() |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 1226 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1227 | def onosDie( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1228 | """ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1229 | Issues the command 'onos-die <node-ip>' |
| 1230 | This command calls onos-kill and also stops the node |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1231 | """ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1232 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1233 | self.handle.sendline( "" ) |
| 1234 | self.handle.expect( "\$" ) |
Jeremy | f0aecdb | 2016-03-30 13:19:57 -0700 | [diff] [blame] | 1235 | cmdStr = "onos-die " + str( nodeIp ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1236 | self.handle.sendline( cmdStr ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1237 | i = self.handle.expect( [ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1238 | "Killing\sONOS", |
| 1239 | "ONOS\sprocess\sis\snot\srunning", |
Jeremy Songster | 14c1357 | 2016-04-21 17:34:03 -0700 | [diff] [blame] | 1240 | pexpect.TIMEOUT ], timeout=60 ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1241 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1242 | main.log.info( "ONOS instance " + str( nodeIp ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1243 | " was killed and stopped" ) |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 1244 | self.handle.sendline( "" ) |
| 1245 | self.handle.expect( "\$" ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1246 | return main.TRUE |
| 1247 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1248 | main.log.info( "ONOS process was not running" ) |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 1249 | self.handle.sendline( "" ) |
| 1250 | self.handle.expect( "\$" ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1251 | return main.FALSE |
| 1252 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1253 | main.log.error( self.name + ": EOF exception found" ) |
| 1254 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1255 | main.cleanup() |
| 1256 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1257 | except Exception: |
| 1258 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1259 | main.cleanup() |
| 1260 | main.exit() |
| 1261 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1262 | def onosKill( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1263 | """ |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1264 | Calls the command: 'onos-kill [<node-ip>]' |
| 1265 | "Remotely, and unceremoniously kills the ONOS instance running on |
| 1266 | the specified cell machine" - Tom V |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1267 | """ |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1268 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1269 | self.handle.sendline( "" ) |
| 1270 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1271 | self.handle.sendline( "onos-kill " + str( nodeIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1272 | i = self.handle.expect( [ |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1273 | "\$", |
| 1274 | "No\sroute\sto\shost", |
| 1275 | "password:", |
Jeremy Songster | 14c1357 | 2016-04-21 17:34:03 -0700 | [diff] [blame] | 1276 | pexpect.TIMEOUT ], timeout=60 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1277 | |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1278 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1279 | main.log.info( |
| 1280 | "ONOS instance " + str( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1281 | nodeIp ) + " was killed" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1282 | return main.TRUE |
| 1283 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1284 | main.log.info( "No route to host" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1285 | return main.FALSE |
| 1286 | elif i == 2: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1287 | main.log.info( |
| 1288 | "Passwordless login for host: " + |
| 1289 | str( nodeIp ) + |
| 1290 | " not configured" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1291 | return main.FALSE |
| 1292 | else: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1293 | main.log.info( "ONOS instance was not killed" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1294 | return main.FALSE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1295 | |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1296 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1297 | main.log.error( self.name + ": EOF exception found" ) |
| 1298 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1299 | main.cleanup() |
| 1300 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1301 | except Exception: |
| 1302 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 1303 | main.cleanup() |
| 1304 | main.exit() |
| 1305 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1306 | def onosRemoveRaftLogs( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1307 | """ |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1308 | Removes Raft / Copy cat files from ONOS to ensure |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1309 | a cleaner environment. |
| 1310 | |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1311 | Description: |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1312 | Stops all ONOS defined in the cell, |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1313 | wipes the raft / copycat log files |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1314 | """ |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1315 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1316 | self.handle.sendline( "" ) |
| 1317 | self.handle.expect( "\$" ) |
| 1318 | self.handle.sendline( "onos-remove-raft-logs" ) |
| 1319 | # Sometimes this command hangs |
| 1320 | i = self.handle.expect( [ "\$", pexpect.TIMEOUT ], |
| 1321 | timeout=120 ) |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1322 | if i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1323 | i = self.handle.expect( [ "\$", pexpect.TIMEOUT ], |
| 1324 | timeout=120 ) |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1325 | if i == 1: |
| 1326 | return main.FALSE |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1327 | return main.TRUE |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1328 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1329 | main.log.error( self.name + ": EOF exception found" ) |
| 1330 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1331 | main.cleanup() |
| 1332 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1333 | except Exception: |
| 1334 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 1335 | main.cleanup() |
| 1336 | main.exit() |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 1337 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1338 | def onosStartNetwork( self, mntopo ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1339 | """ |
| 1340 | Calls the command 'onos-start-network [ <mininet-topo> ] |
| 1341 | "remotely starts the specified topology on the cell's |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1342 | mininet machine against all controllers configured in the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1343 | cell." |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1344 | * Specify mininet topology file name for mntopo |
| 1345 | * Topo files should be placed at: |
| 1346 | ~/<your-onos-directory>/tools/test/topos |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1347 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1348 | NOTE: This function will take you to the mininet prompt |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1349 | """ |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1350 | try: |
| 1351 | if not mntopo: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1352 | main.log.error( "You must specify a topo file to execute" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1353 | return main.FALSE |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1354 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1355 | mntopo = str( mntopo ) |
| 1356 | self.handle.sendline( "" ) |
| 1357 | self.handle.expect( "\$" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1358 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1359 | self.handle.sendline( "onos-start-network " + mntopo ) |
| 1360 | self.handle.expect( "mininet>" ) |
| 1361 | main.log.info( "Network started, entered mininet prompt" ) |
| 1362 | |
| 1363 | # TODO: Think about whether return is necessary or not |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1364 | |
| 1365 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1366 | main.log.error( self.name + ": EOF exception found" ) |
| 1367 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1368 | main.cleanup() |
| 1369 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1370 | except Exception: |
| 1371 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1372 | main.cleanup() |
| 1373 | main.exit() |
| 1374 | |
Jeremy Songster | 14c1357 | 2016-04-21 17:34:03 -0700 | [diff] [blame] | 1375 | def isup( self, node="", timeout=240 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1376 | """ |
| 1377 | 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] | 1378 | level 100(ready for use) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1379 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1380 | Returns: main.TRUE if ONOS is running and main.FALSE on timeout |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1381 | """ |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1382 | try: |
Jon Hall | 3b489db | 2015-10-05 14:38:37 -0700 | [diff] [blame] | 1383 | self.handle.sendline( "onos-wait-for-start " + node ) |
| 1384 | self.handle.expect( "onos-wait-for-start" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1385 | # NOTE: this timeout is arbitrary" |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 1386 | i = self.handle.expect(["\$", pexpect.TIMEOUT], timeout) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1387 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1388 | main.log.info( self.name + ": " + node + " is up" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1389 | return main.TRUE |
| 1390 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1391 | # NOTE: since this function won't return until ONOS is ready, |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1392 | # we will kill it on timeout |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1393 | main.log.error( "ONOS has not started yet" ) |
| 1394 | self.handle.send( "\x03" ) # Control-C |
| 1395 | self.handle.expect( "\$" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1396 | return main.FALSE |
| 1397 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1398 | main.log.error( self.name + ": EOF exception found" ) |
| 1399 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1400 | main.cleanup() |
| 1401 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1402 | except Exception: |
| 1403 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1404 | main.cleanup() |
| 1405 | main.exit() |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 1406 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1407 | def pushTestIntentsShell( |
| 1408 | self, |
| 1409 | dpidSrc, |
| 1410 | dpidDst, |
| 1411 | numIntents, |
| 1412 | dirFile, |
| 1413 | onosIp, |
| 1414 | numMult="", |
| 1415 | appId="", |
| 1416 | report=True, |
| 1417 | options="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1418 | """ |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1419 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1420 | Use the linux prompt to push test intents to |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1421 | better parallelize the results than the CLI |
| 1422 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1423 | * dpidSrc: specify source dpid |
| 1424 | * dpidDst: specify destination dpid |
| 1425 | * numIntents: specify number of intents to push |
| 1426 | * dirFile: specify directory and file name to save |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1427 | results |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1428 | * onosIp: specify the IP of ONOS to install on |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1429 | NOTE: |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1430 | You must invoke this command at linux shell prompt |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1431 | """ |
| 1432 | try: |
| 1433 | # Create the string to sendline |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1434 | if options: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1435 | baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1436 | options + " " |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1437 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1438 | baseCmd = "onos " + str( onosIp ) + " push-test-intents " |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1439 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1440 | addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst ) |
| 1441 | if not numMult: |
| 1442 | addIntents = addDpid + " " + str( numIntents ) |
| 1443 | elif numMult: |
| 1444 | addIntents = addDpid + " " + str( numIntents ) + " " +\ |
| 1445 | str( numMult ) |
| 1446 | if appId: |
| 1447 | addApp = addIntents + " " + str( appId ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1448 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1449 | addApp = addIntents |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1450 | |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1451 | if report: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1452 | sendCmd = addApp + " > " + str( dirFile ) + " &" |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1453 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1454 | sendCmd = addApp + " &" |
| 1455 | main.log.info( "Send cmd: " + sendCmd ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1456 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1457 | self.handle.sendline( sendCmd ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1458 | |
| 1459 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1460 | main.log.error( self.name + ": EOF exception found" ) |
| 1461 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1462 | main.cleanup() |
| 1463 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1464 | except Exception: |
| 1465 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1466 | main.cleanup() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1467 | main.exit() |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 1468 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1469 | def tsharkPcap( self, interface, dirFile ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1470 | """ |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1471 | Capture all packet activity and store in specified |
| 1472 | directory/file |
| 1473 | |
| 1474 | Required: |
| 1475 | * interface: interface to capture |
| 1476 | * dir: directory/filename to store pcap |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1477 | """ |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1478 | try: |
| 1479 | self.handle.sendline( "" ) |
| 1480 | self.handle.expect( "\$" ) |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1481 | |
cameron@onlab.us | 21106ea | 2015-07-23 15:32:51 -0700 | [diff] [blame] | 1482 | self.handle.sendline( "tshark -i " + str( interface ) + " -t e -w " + str( dirFile ) + " &" ) |
Jon Hall | 5ec6b1b | 2015-09-17 18:20:14 -0700 | [diff] [blame] | 1483 | self.handle.sendline( "\n" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1484 | self.handle.expect( "Capturing on" ) |
Jon Hall | 5ec6b1b | 2015-09-17 18:20:14 -0700 | [diff] [blame] | 1485 | self.handle.sendline( "\n" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1486 | self.handle.expect( "\$" ) |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1487 | |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1488 | main.log.info( "Tshark started capturing files on " + |
| 1489 | str( interface ) + " and saving to directory: " + |
| 1490 | str( dirFile ) ) |
| 1491 | except pexpect.EOF: |
| 1492 | main.log.error( self.name + ": EOF exception found" ) |
| 1493 | main.log.error( self.name + ": " + self.handle.before ) |
| 1494 | main.cleanup() |
| 1495 | main.exit() |
| 1496 | except Exception: |
| 1497 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1498 | main.cleanup() |
| 1499 | main.exit() |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 1500 | |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 1501 | def onosTopoCfg( self, onosIp, jsonFile ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1502 | """ |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 1503 | Description: |
| 1504 | Execute onos-topo-cfg command |
| 1505 | Required: |
| 1506 | onosIp - IP of the onos node you want to send the json to |
| 1507 | jsonFile - File path of the json file |
| 1508 | Return: |
| 1509 | Returns main.TRUE if the command is successfull; Returns |
| 1510 | main.FALSE if there was an error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1511 | """ |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 1512 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1513 | self.handle.sendline( "" ) |
| 1514 | self.handle.expect( "\$" ) |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 1515 | cmd = "onos-topo-cfg " |
| 1516 | self.handle.sendline( cmd + str( onosIp ) + " " + jsonFile ) |
| 1517 | handle = self.handle.before |
| 1518 | print handle |
| 1519 | if "Error" in handle: |
| 1520 | main.log.error( self.name + ": " + self.handle.before ) |
| 1521 | return main.FALSE |
| 1522 | else: |
| 1523 | self.handle.expect( "\$" ) |
| 1524 | return main.TRUE |
| 1525 | |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1526 | except pexpect.EOF: |
| 1527 | main.log.error( self.name + ": EOF exception found" ) |
| 1528 | main.log.error( self.name + ": " + self.handle.before ) |
| 1529 | main.cleanup() |
| 1530 | main.exit() |
| 1531 | except Exception: |
| 1532 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1533 | main.cleanup() |
| 1534 | main.exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1535 | |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 1536 | def tsharkGrep( self, grep, directory, interface='eth0', grepOptions='' ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1537 | """ |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1538 | Required: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1539 | * grep string |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1540 | * directory to store results |
| 1541 | Optional: |
| 1542 | * interface - default: eth0 |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1543 | * grepOptions - options for grep |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1544 | Description: |
| 1545 | Uses tshark command to grep specific group of packets |
| 1546 | and stores the results to specified directory. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1547 | The timestamp is hardcoded to be in epoch |
| 1548 | """ |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1549 | try: |
| 1550 | self.handle.sendline( "" ) |
| 1551 | self.handle.expect( "\$" ) |
| 1552 | self.handle.sendline( "" ) |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 1553 | if grepOptions: |
| 1554 | grepStr = "grep "+str(grepOptions) |
| 1555 | else: |
| 1556 | grepStr = "grep" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1557 | |
cameron@onlab.us | 21106ea | 2015-07-23 15:32:51 -0700 | [diff] [blame] | 1558 | cmd = ( |
| 1559 | "sudo tshark -i " + |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1560 | str( interface ) + |
jenkins | 1e99e7b | 2015-04-02 18:15:39 -0700 | [diff] [blame] | 1561 | " -t e | " + |
| 1562 | grepStr + " --line-buffered \"" + |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1563 | str(grep) + |
| 1564 | "\" >" + |
| 1565 | directory + |
| 1566 | " &" ) |
cameron@onlab.us | 21106ea | 2015-07-23 15:32:51 -0700 | [diff] [blame] | 1567 | self.handle.sendline(cmd) |
| 1568 | main.log.info(cmd) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1569 | self.handle.expect( "Capturing on" ) |
cameron@onlab.us | 21106ea | 2015-07-23 15:32:51 -0700 | [diff] [blame] | 1570 | self.handle.sendline( "\n" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1571 | self.handle.expect( "\$" ) |
| 1572 | except pexpect.EOF: |
| 1573 | main.log.error( self.name + ": EOF exception found" ) |
| 1574 | main.log.error( self.name + ": " + self.handle.before ) |
| 1575 | main.cleanup() |
| 1576 | main.exit() |
| 1577 | except Exception: |
| 1578 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1579 | main.cleanup() |
| 1580 | main.exit() |
| 1581 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1582 | def tsharkStop( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1583 | """ |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1584 | Removes wireshark files from /tmp and kills all tshark processes |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1585 | """ |
| 1586 | # Remove all pcap from previous captures |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1587 | try: |
| 1588 | self.execute( cmd="sudo rm /tmp/wireshark*" ) |
| 1589 | self.handle.sendline( "" ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1590 | self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\"" + |
| 1591 | " | grep -v grep | awk '{print $2}'`" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1592 | self.handle.sendline( "" ) |
| 1593 | main.log.info( "Tshark stopped" ) |
| 1594 | except pexpect.EOF: |
| 1595 | main.log.error( self.name + ": EOF exception found" ) |
| 1596 | main.log.error( self.name + ": " + self.handle.before ) |
| 1597 | main.cleanup() |
| 1598 | main.exit() |
| 1599 | except Exception: |
| 1600 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1601 | main.cleanup() |
| 1602 | main.exit() |
| 1603 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1604 | def ptpd( self, args ): |
| 1605 | """ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1606 | Initiate ptp with user-specified args. |
| 1607 | Required: |
| 1608 | * args: specify string of args after command |
| 1609 | 'sudo ptpd' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1610 | """ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1611 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1612 | self.handle.sendline( "sudo ptpd " + str( args ) ) |
| 1613 | i = self.handle.expect( [ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1614 | "Multiple", |
| 1615 | "Error", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1616 | "\$" ] ) |
| 1617 | self.handle.expect( "\$" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1618 | |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1619 | if i == 0: |
| 1620 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1621 | main.log.info( "ptpd returned an error: " + |
| 1622 | str( handle ) ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1623 | return handle |
| 1624 | elif i == 1: |
| 1625 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1626 | main.log.error( "ptpd returned an error: " + |
| 1627 | str( handle ) ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1628 | return handle |
| 1629 | else: |
| 1630 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1631 | |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1632 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1633 | main.log.error( self.name + ": EOF exception found" ) |
| 1634 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1635 | main.cleanup() |
| 1636 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1637 | except Exception: |
| 1638 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1639 | main.cleanup() |
| 1640 | main.exit() |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1641 | |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 1642 | def dumpONOSCmd(self, ONOSIp, CMD, destDir, filename, options=""): |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1643 | """ |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 1644 | Dump Cmd to a desired directory. |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1645 | For debugging purposes, you may want to use |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 1646 | this function to capture Cmd at a given point in time. |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1647 | Localtime will be attached to the filename |
| 1648 | |
| 1649 | Required: |
| 1650 | * ONOSIp: the IP of the target ONOS instance |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 1651 | * CMD: the command to dump; |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1652 | * destDir: specify directory to copy to. |
| 1653 | ex ) /tmp/ |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1654 | * fileName: Name of the file |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 1655 | * options: Options for ONOS command |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 1656 | """ |
| 1657 | |
| 1658 | localtime = time.strftime( '%x %X' ) |
| 1659 | localtime = localtime.replace( "/", "" ) |
| 1660 | localtime = localtime.replace( " ", "_" ) |
| 1661 | localtime = localtime.replace( ":", "" ) |
| 1662 | if destDir[ -1: ] != "/": |
| 1663 | destDir += "/" |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 1664 | cmd=CMD + " " + options + " > " + str( destDir ) + str( filename ) + localtime |
| 1665 | return self.onosCli(ONOSIp, cmd) |
Flavio Castro | b771895 | 2016-05-18 08:53:41 -0700 | [diff] [blame] | 1666 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1667 | def cpLogsToDir( self, logToCopy, |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1668 | destDir, copyFileName="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1669 | """ |
| 1670 | Copies logs to a desired directory. |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1671 | Current implementation of ONOS deletes its karaf |
| 1672 | logs on every iteration. For debugging purposes, |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1673 | you may want to use this function to capture |
| 1674 | certain karaf logs. ( or any other logs if needed ) |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1675 | Localtime will be attached to the filename |
| 1676 | |
| 1677 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1678 | * logToCopy: specify directory and log name to |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1679 | copy. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1680 | ex ) /opt/onos/log/karaf.log.1 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1681 | For copying multiple files, leave copyFileName |
| 1682 | empty and only specify destDir - |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1683 | ex ) /opt/onos/log/karaf* |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1684 | * destDir: specify directory to copy to. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1685 | ex ) /tmp/ |
| 1686 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1687 | * copyFileName: If you want to rename the log |
| 1688 | file, specify copyFileName. This will not work |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1689 | with multiple file copying |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1690 | """ |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1691 | try: |
Flavio Castro | 09ab59d | 2016-05-25 17:01:35 -0700 | [diff] [blame] | 1692 | localtime = time.strftime( '%H %M' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1693 | localtime = localtime.replace( "/", "" ) |
| 1694 | localtime = localtime.replace( " ", "_" ) |
| 1695 | localtime = localtime.replace( ":", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1696 | if destDir[ -1: ] != "/": |
| 1697 | destDir += "/" |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1698 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1699 | if copyFileName: |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1700 | self.handle.sendline( "cp " + str( logToCopy ) + " " + |
| 1701 | str( destDir ) + str( copyFileName ) + |
| 1702 | localtime ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1703 | self.handle.expect( "cp" ) |
| 1704 | self.handle.expect( "\$" ) |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1705 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1706 | self.handle.sendline( "cp " + str( logToCopy ) + |
| 1707 | " " + str( destDir ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1708 | self.handle.expect( "cp" ) |
| 1709 | self.handle.expect( "\$" ) |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1710 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1711 | return self.handle.before |
| 1712 | |
| 1713 | except pexpect.EOF: |
| 1714 | main.log.error( "Copying files failed" ) |
| 1715 | main.log.error( self.name + ": EOF exception found" ) |
| 1716 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1717 | except Exception: |
| 1718 | main.log.exception( "Copying files failed" ) |
| 1719 | |
Jon Hall | 16b72c4 | 2015-05-20 10:23:36 -0700 | [diff] [blame] | 1720 | def checkLogs( self, onosIp, restart=False): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1721 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1722 | runs onos-check-logs on the given onos node |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 1723 | If restart is True, use the old version of onos-check-logs which |
| 1724 | does not print the full stacktrace, but shows the entire log file, |
| 1725 | including across restarts |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1726 | returns the response |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1727 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1728 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1729 | cmd = "onos-check-logs " + str( onosIp ) |
Jon Hall | 16b72c4 | 2015-05-20 10:23:36 -0700 | [diff] [blame] | 1730 | if restart: |
| 1731 | cmd += " old" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1732 | self.handle.sendline( cmd ) |
| 1733 | self.handle.expect( cmd ) |
Jon Hall | 5ec6b1b | 2015-09-17 18:20:14 -0700 | [diff] [blame] | 1734 | self.handle.expect( "\$ " ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1735 | response = self.handle.before |
| 1736 | return response |
| 1737 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1738 | main.log.error( "Lost ssh connection" ) |
| 1739 | main.log.error( self.name + ": EOF exception found" ) |
| 1740 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1741 | except Exception: |
| 1742 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1743 | main.cleanup() |
| 1744 | main.exit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1745 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1746 | def onosStatus( self, node="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1747 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1748 | Calls onos command: 'onos-service [<node-ip>] status' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1749 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1750 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1751 | self.handle.sendline( "" ) |
| 1752 | self.handle.expect( "\$" ) |
| 1753 | self.handle.sendline( "onos-service " + str( node ) + |
| 1754 | " status" ) |
| 1755 | i = self.handle.expect( [ |
You Wang | ef1e657 | 2016-03-08 12:53:18 -0800 | [diff] [blame] | 1756 | "start/running", |
You Wang | 7bd8306 | 2016-03-01 11:50:00 -0800 | [diff] [blame] | 1757 | "Running ...", |
You Wang | ef1e657 | 2016-03-08 12:53:18 -0800 | [diff] [blame] | 1758 | "stop/waiting", |
You Wang | 7bd8306 | 2016-03-01 11:50:00 -0800 | [diff] [blame] | 1759 | "Not Running ...", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1760 | pexpect.TIMEOUT ], timeout=120 ) |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1761 | self.handle.sendline( "" ) |
| 1762 | self.handle.expect( "\$" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1763 | |
You Wang | ef1e657 | 2016-03-08 12:53:18 -0800 | [diff] [blame] | 1764 | if i == 0 or i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1765 | main.log.info( "ONOS is running" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1766 | return main.TRUE |
You Wang | ef1e657 | 2016-03-08 12:53:18 -0800 | [diff] [blame] | 1767 | elif i == 2 or i == 3: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1768 | main.log.info( "ONOS is stopped" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1769 | main.log.error( "ONOS service failed to check the status" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1770 | main.cleanup() |
| 1771 | main.exit() |
| 1772 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1773 | main.log.error( self.name + ": EOF exception found" ) |
| 1774 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1775 | main.cleanup() |
| 1776 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1777 | except Exception: |
| 1778 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1779 | main.cleanup() |
| 1780 | main.exit() |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1781 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1782 | def setIpTables( self, ip, port='', action='add', packet_type='', |
| 1783 | direction='INPUT', rule='DROP', states=True ): |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1784 | """ |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1785 | Description: |
| 1786 | add or remove iptables rule to DROP (default) packets from |
| 1787 | specific IP and PORT |
| 1788 | Usage: |
| 1789 | * specify action ('add' or 'remove') |
| 1790 | when removing, pass in the same argument as you would add. It will |
| 1791 | delete that specific rule. |
| 1792 | * specify the ip to block |
| 1793 | * specify the destination port to block (defaults to all ports) |
| 1794 | * optional packet type to block (default tcp) |
| 1795 | * optional iptables rule (default DROP) |
| 1796 | * optional direction to block (default 'INPUT') |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1797 | * States boolean toggles adding all supported tcp states to the |
| 1798 | firewall rule |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1799 | Returns: |
| 1800 | main.TRUE on success or |
| 1801 | main.FALSE if given invalid input or |
| 1802 | main.ERROR if there is an error in response from iptables |
| 1803 | WARNING: |
| 1804 | * This function uses root privilege iptables command which may result |
| 1805 | in unwanted network errors. USE WITH CAUTION |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1806 | """ |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1807 | |
| 1808 | # NOTE********* |
| 1809 | # The strict checking methods of this driver function is intentional |
| 1810 | # to discourage any misuse or error of iptables, which can cause |
| 1811 | # severe network errors |
| 1812 | # ************* |
| 1813 | |
| 1814 | # NOTE: Sleep needed to give some time for rule to be added and |
| 1815 | # registered to the instance. If you are calling this function |
| 1816 | # multiple times this sleep will prevent any errors. |
| 1817 | # DO NOT REMOVE |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1818 | # time.sleep( 5 ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1819 | try: |
| 1820 | # input validation |
| 1821 | action_type = action.lower() |
| 1822 | rule = rule.upper() |
| 1823 | direction = direction.upper() |
| 1824 | if action_type != 'add' and action_type != 'remove': |
| 1825 | main.log.error( "Invalid action type. Use 'add' or " |
| 1826 | "'remove' table rule" ) |
| 1827 | if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG': |
| 1828 | # NOTE Currently only supports rules DROP, ACCEPT, and LOG |
| 1829 | main.log.error( "Invalid rule. Valid rules are 'DROP' or " |
| 1830 | "'ACCEPT' or 'LOG' only." ) |
| 1831 | if direction != 'INPUT' and direction != 'OUTPUT': |
| 1832 | # NOTE currently only supports rules INPUT and OUPTUT |
| 1833 | main.log.error( "Invalid rule. Valid directions are" |
| 1834 | " 'OUTPUT' or 'INPUT'" ) |
| 1835 | return main.FALSE |
| 1836 | return main.FALSE |
| 1837 | return main.FALSE |
| 1838 | if action_type == 'add': |
| 1839 | # -A is the 'append' action of iptables |
| 1840 | actionFlag = '-A' |
| 1841 | elif action_type == 'remove': |
| 1842 | # -D is the 'delete' rule of iptables |
| 1843 | actionFlag = '-D' |
| 1844 | self.handle.sendline( "" ) |
| 1845 | self.handle.expect( "\$" ) |
| 1846 | cmd = "sudo iptables " + actionFlag + " " +\ |
| 1847 | direction +\ |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1848 | " -s " + str( ip ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1849 | # " -p " + str( packet_type ) +\ |
| 1850 | if packet_type: |
| 1851 | cmd += " -p " + str( packet_type ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1852 | if port: |
| 1853 | cmd += " --dport " + str( port ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1854 | if states: |
| 1855 | cmd += " -m state --state=" |
| 1856 | #FIXME- Allow user to configure which states to block |
| 1857 | cmd += "INVALID,ESTABLISHED,NEW,RELATED,UNTRACKED" |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1858 | cmd += " -j " + str( rule ) |
| 1859 | |
| 1860 | self.handle.sendline( cmd ) |
| 1861 | self.handle.expect( "\$" ) |
| 1862 | main.log.warn( self.handle.before ) |
| 1863 | |
| 1864 | info_string = "On " + str( self.name ) |
| 1865 | info_string += " " + str( action_type ) |
| 1866 | info_string += " iptable rule [ " |
| 1867 | info_string += " IP: " + str( ip ) |
| 1868 | info_string += " Port: " + str( port ) |
| 1869 | info_string += " Rule: " + str( rule ) |
| 1870 | info_string += " Direction: " + str( direction ) + " ]" |
| 1871 | main.log.info( info_string ) |
| 1872 | return main.TRUE |
| 1873 | except pexpect.TIMEOUT: |
| 1874 | main.log.exception( self.name + ": Timeout exception in " |
| 1875 | "setIpTables function" ) |
| 1876 | return main.ERROR |
| 1877 | except pexpect.EOF: |
| 1878 | main.log.error( self.name + ": EOF exception found" ) |
| 1879 | main.log.error( self.name + ": " + self.handle.before ) |
| 1880 | main.cleanup() |
| 1881 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1882 | except Exception: |
| 1883 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1884 | main.cleanup() |
| 1885 | main.exit() |
| 1886 | |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1887 | def detailed_status(self, log_filename): |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1888 | """ |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1889 | This method is used by STS to check the status of the controller |
| 1890 | Reports RUNNING, STARTING, STOPPED, FROZEN, ERROR (and reason) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1891 | """ |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1892 | import re |
| 1893 | try: |
| 1894 | self.handle.sendline( "" ) |
| 1895 | self.handle.expect( "\$" ) |
| 1896 | self.handle.sendline( "cd " + self.home ) |
| 1897 | self.handle.expect( "\$" ) |
| 1898 | self.handle.sendline( "service onos status" ) |
| 1899 | self.handle.expect( "\$" ) |
| 1900 | response = self.handle.before |
| 1901 | if re.search( "onos start/running", response ): |
| 1902 | # onos start/running, process 10457 |
| 1903 | return 'RUNNING' |
| 1904 | # FIXME: Implement this case |
| 1905 | # elif re.search( pattern, response ): |
| 1906 | # return 'STARTING' |
| 1907 | elif re.search( "onos stop/", response ): |
| 1908 | # onos stop/waiting |
| 1909 | # FIXME handle this differently?: onos stop/pre-stop |
| 1910 | return 'STOPPED' |
| 1911 | # FIXME: Implement this case |
| 1912 | # elif re.search( pattern, response ): |
| 1913 | # return 'FROZEN' |
| 1914 | else: |
| 1915 | main.log.warn( self.name + |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1916 | " WARNING: status received unknown response" ) |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1917 | main.log.warn( response ) |
| 1918 | return 'ERROR', "Unknown response: %s" % response |
| 1919 | except pexpect.TIMEOUT: |
| 1920 | main.log.exception( self.name + ": Timeout exception in " |
| 1921 | "setIpTables function" ) |
| 1922 | return 'ERROR', "Pexpect Timeout" |
| 1923 | except pexpect.EOF: |
| 1924 | main.log.error( self.name + ": EOF exception found" ) |
| 1925 | main.log.error( self.name + ": " + self.handle.before ) |
| 1926 | main.cleanup() |
| 1927 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1928 | except Exception: |
| 1929 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 0468b04 | 2015-02-19 19:08:21 -0800 | [diff] [blame] | 1930 | main.cleanup() |
| 1931 | main.exit() |
| 1932 | |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1933 | def createLinkGraphFile( self, benchIp, ONOSIpList, deviceCount): |
| 1934 | ''' |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1935 | Create/formats the LinkGraph.cfg file based on arguments |
| 1936 | -only creates a linear topology and connects islands |
| 1937 | -evenly distributes devices |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1938 | -must be called by ONOSbench |
| 1939 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1940 | ONOSIpList - list of all of the node IPs to be used |
| 1941 | |
| 1942 | deviceCount - number of switches to be assigned |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1943 | ''' |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 1944 | main.log.info("Creating link graph configuration file." ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1945 | linkGraphPath = self.home + "/tools/package/etc/linkGraph.cfg" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1946 | tempFile = "/tmp/linkGraph.cfg" |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1947 | |
| 1948 | linkGraph = open(tempFile, 'w+') |
| 1949 | linkGraph.write("# NullLinkProvider topology description (config file).\n") |
| 1950 | linkGraph.write("# The NodeId is only added if the destination is another node's device.\n") |
| 1951 | 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] | 1952 | |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1953 | clusterCount = len(ONOSIpList) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1954 | |
| 1955 | if type(deviceCount) is int or type(deviceCount) is str: |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1956 | deviceCount = int(deviceCount) |
| 1957 | switchList = [0]*(clusterCount+1) |
| 1958 | baselineSwitchCount = deviceCount/clusterCount |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1959 | |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1960 | for node in range(1, clusterCount + 1): |
| 1961 | switchList[node] = baselineSwitchCount |
| 1962 | |
| 1963 | for node in range(1, (deviceCount%clusterCount)+1): |
| 1964 | switchList[node] += 1 |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1965 | |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1966 | if type(deviceCount) is list: |
| 1967 | main.log.info("Using provided device distribution") |
| 1968 | switchList = [0] |
| 1969 | for i in deviceCount: |
| 1970 | switchList.append(int(i)) |
| 1971 | |
| 1972 | tempList = ['0'] |
| 1973 | tempList.extend(ONOSIpList) |
| 1974 | ONOSIpList = tempList |
| 1975 | |
| 1976 | myPort = 6 |
| 1977 | lastSwitch = 0 |
| 1978 | for node in range(1, clusterCount+1): |
| 1979 | if switchList[node] == 0: |
| 1980 | continue |
| 1981 | |
| 1982 | linkGraph.write("graph " + ONOSIpList[node] + " {\n") |
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 | if node > 1: |
| 1985 | #connect to last device on previous node |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1986 | line = ("\t0:5 -> " + str(lastSwitch) + ":6:" + lastIp + "\n") #ONOSIpList[node-1] |
| 1987 | linkGraph.write(line) |
| 1988 | |
| 1989 | lastSwitch = 0 |
| 1990 | for switch in range (0, switchList[node]-1): |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1991 | line = "" |
| 1992 | line = ("\t" + str(switch) + ":" + str(myPort)) |
| 1993 | line += " -- " |
| 1994 | line += (str(switch+1) + ":" + str(myPort-1) + "\n") |
| 1995 | linkGraph.write(line) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 1996 | lastSwitch = switch+1 |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 1997 | lastIp = ONOSIpList[node] |
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 | #lastSwitch += 1 |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2000 | if node < (clusterCount): |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2001 | #connect to first device on the next node |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2002 | line = ("\t" + str(lastSwitch) + ":6 -> 0:5:" + ONOSIpList[node+1] + "\n") |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2003 | linkGraph.write(line) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2004 | |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2005 | linkGraph.write("}\n") |
| 2006 | linkGraph.close() |
| 2007 | |
| 2008 | #SCP |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2009 | os.system( "scp " + tempFile + " " + self.user_name + "@" + benchIp + ":" + linkGraphPath) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2010 | main.log.info("linkGraph.cfg creation complete") |
| 2011 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2012 | def configNullDev( self, ONOSIpList, deviceCount, numPorts=10): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2013 | |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2014 | ''' |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2015 | ONOSIpList = list of Ip addresses of nodes switches will be devided amongst |
| 2016 | 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] | 2017 | 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] | 2018 | ''' |
| 2019 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 2020 | main.log.info("Configuring Null Device Provider" ) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2021 | clusterCount = len(ONOSIpList) |
| 2022 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2023 | try: |
| 2024 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2025 | if type(deviceCount) is int or type(deviceCount) is str: |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 2026 | main.log.info("Creating device distribution") |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2027 | deviceCount = int(deviceCount) |
| 2028 | switchList = [0]*(clusterCount+1) |
| 2029 | baselineSwitchCount = deviceCount/clusterCount |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2030 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2031 | for node in range(1, clusterCount + 1): |
| 2032 | switchList[node] = baselineSwitchCount |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2033 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2034 | for node in range(1, (deviceCount%clusterCount)+1): |
| 2035 | switchList[node] += 1 |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2036 | |
| 2037 | if type(deviceCount) is list: |
| 2038 | main.log.info("Using provided device distribution") |
| 2039 | |
| 2040 | if len(deviceCount) == clusterCount: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2041 | switchList = ['0'] |
| 2042 | switchList.extend(deviceCount) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2043 | |
| 2044 | if len(deviceCount) == (clusterCount + 1): |
| 2045 | if deviceCount[0] == '0' or deviceCount[0] == 0: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2046 | switchList = deviceCount |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2047 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2048 | assert len(switchList) == (clusterCount + 1) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2049 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2050 | except AssertionError: |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2051 | main.log.error( "Bad device/Ip list match") |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2052 | except TypeError: |
| 2053 | main.log.exception( self.name + ": Object not as expected" ) |
| 2054 | return None |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2055 | except Exception: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2056 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2057 | main.cleanup() |
| 2058 | main.exit() |
| 2059 | |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2060 | |
| 2061 | ONOSIp = [0] |
| 2062 | ONOSIp.extend(ONOSIpList) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2063 | |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2064 | devicesString = "devConfigs = " |
| 2065 | for node in range(1, len(ONOSIp)): |
| 2066 | devicesString += (ONOSIp[node] + ":" + str(switchList[node] )) |
| 2067 | if node < clusterCount: |
| 2068 | devicesString += (",") |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2069 | |
| 2070 | try: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2071 | self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider devConfigs " + devicesString ) |
| 2072 | self.handle.expect(":~") |
| 2073 | self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider numPorts " + str(numPorts) ) |
| 2074 | self.handle.expect(":~") |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2075 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2076 | for i in range(10): |
| 2077 | self.handle.sendline("onos $OC1 cfg get org.onosproject.provider.nil.device.impl.NullDeviceProvider") |
| 2078 | self.handle.expect(":~") |
| 2079 | verification = self.handle.before |
| 2080 | if (" value=" + str(numPorts)) in verification and (" value=" + devicesString) in verification: |
| 2081 | break |
| 2082 | else: |
| 2083 | time.sleep(1) |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2084 | |
cameron@onlab.us | 2cc8bf1 | 2015-04-02 14:12:30 -0700 | [diff] [blame] | 2085 | assert ("value=" + str(numPorts)) in verification and (" value=" + devicesString) in verification |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2086 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2087 | except AssertionError: |
| 2088 | main.log.error("Incorrect Config settings: " + verification) |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2089 | except Exception: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2090 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2091 | main.cleanup() |
| 2092 | main.exit() |
| 2093 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2094 | 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] | 2095 | ''' |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2096 | 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] | 2097 | you want to use a different topology file than linkGraph.cfg |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2098 | ''' |
| 2099 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2100 | |
| 2101 | try: |
| 2102 | self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider eventRate " + str(eventRate)) |
| 2103 | self.handle.expect(":~") |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2104 | self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider cfgFile " + fileName ) |
| 2105 | self.handle.expect(":~") |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2106 | |
| 2107 | for i in range(10): |
| 2108 | 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] | 2109 | self.handle.expect(":~") |
| 2110 | verification = self.handle.before |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2111 | if (" value=" + str(eventRate)) in verification and (" value=" + fileName) in verification: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2112 | break |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2113 | else: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2114 | time.sleep(1) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2115 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2116 | assert ("value=" + str(eventRate)) in verification and (" value=" + fileName) in verification |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2117 | |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2118 | except pexpect.EOF: |
| 2119 | main.log.error( self.name + ": EOF exception found" ) |
| 2120 | main.log.error( self.name + ": " + self.handle.before ) |
| 2121 | main.cleanup() |
| 2122 | main.exit() |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2123 | except AssertionError: |
| 2124 | main.log.info("Settings did not post to ONOS") |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2125 | main.log.error(varification) |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2126 | except Exception: |
cameron@onlab.us | 7590096 | 2015-03-30 13:22:49 -0700 | [diff] [blame] | 2127 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2128 | main.log.error(varification) |
| 2129 | main.cleanup() |
| 2130 | main.exit() |
andrew@onlab.us | 3b08713 | 2015-03-11 15:00:08 -0700 | [diff] [blame] | 2131 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 2132 | def getOnosIps( self ): |
| 2133 | """ |
| 2134 | Get all onos IPs stored in |
| 2135 | """ |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 2136 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 2137 | return sorted( self.onosIps.values() ) |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 2138 | |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 2139 | def listLog( self, nodeIp ): |
| 2140 | """ |
| 2141 | Get a list of all the karaf log names |
| 2142 | """ |
| 2143 | try: |
| 2144 | cmd = "onos-ssh " + nodeIp + " ls -tr /opt/onos/log" |
| 2145 | self.handle.sendline( cmd ) |
| 2146 | self.handle.expect( ":~" ) |
| 2147 | before = self.handle.before.splitlines() |
| 2148 | logNames = [] |
| 2149 | for word in before: |
| 2150 | if 'karaf.log' in word: |
| 2151 | logNames.append( word ) |
| 2152 | return logNames |
| 2153 | except pexpect.EOF: |
| 2154 | main.log.error( self.name + ": EOF exception found" ) |
| 2155 | main.log.error( self.name + ": " + self.handle.before ) |
| 2156 | main.cleanup() |
| 2157 | main.exit() |
| 2158 | except pexpect.TIMEOUT: |
| 2159 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 2160 | main.log.error( self.name + ": " + self.handle.before ) |
| 2161 | main.cleanup() |
| 2162 | main.exit() |
| 2163 | except Exception: |
| 2164 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2165 | main.cleanup() |
| 2166 | main.exit() |
| 2167 | |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 2168 | def logReport( self, nodeIp, searchTerms, outputMode="s", startStr=None, endStr=None ): |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2169 | """ |
| 2170 | Searches the latest ONOS log file for the given search terms and |
| 2171 | prints the total occurances of each term. Returns to combined total of |
| 2172 | all occurances. |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2173 | |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2174 | Arguments: |
| 2175 | * nodeIp - The ip of the ONOS node where the log is located |
| 2176 | * searchTerms - A string to grep for or a list of strings to grep |
| 2177 | for in the ONOS log. Will print out the number of |
| 2178 | occurances for each term. |
| 2179 | Optional Arguments: |
| 2180 | * outputMode - 's' or 'd'. If 'd' will print the last 5 lines |
| 2181 | containing each search term as well as the total |
| 2182 | number of occurances of each term. Defaults to 's', |
| 2183 | which prints the simple output of just the number |
| 2184 | of occurances for each term. |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 2185 | * startStr - the start string to be given to stream editor command |
| 2186 | as the start point for extraction of data |
| 2187 | * endStr - the end string to be given to stream editor command as |
| 2188 | the end point for extraction of data |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2189 | """ |
| 2190 | try: |
| 2191 | main.log.info( " Log Report for {} ".format( nodeIp ).center( 70, '=' ) ) |
| 2192 | if type( searchTerms ) is str: |
| 2193 | searchTerms = [searchTerms] |
| 2194 | numTerms = len( searchTerms ) |
| 2195 | outputMode = outputMode.lower() |
cameron@onlab.us | 70dd8c6 | 2015-05-14 11:19:39 -0700 | [diff] [blame] | 2196 | |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2197 | totalHits = 0 |
| 2198 | logLines = [] |
| 2199 | for termIndex in range( numTerms ): |
| 2200 | term = searchTerms[termIndex] |
| 2201 | logLines.append( [term] ) |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 2202 | if startStr and endStr: |
| 2203 | cmd = "onos-ssh {} \"sed -n '/{}/,/{}/p' /opt/onos/log/karaf.log | grep {}\"".format( nodeIp, |
| 2204 | startStr, |
| 2205 | endStr, |
| 2206 | term ) |
| 2207 | else: |
| 2208 | cmd = "onos-ssh {} cat /opt/onos/log/karaf.log | grep {}".format( nodeIp, |
| 2209 | term ) |
Jon Hall | b424222 | 2016-01-25 17:07:04 -0800 | [diff] [blame] | 2210 | self.handle.sendline( cmd ) |
| 2211 | self.handle.expect( ":~" ) |
| 2212 | before = self.handle.before.splitlines() |
| 2213 | count = 0 |
| 2214 | for line in before: |
| 2215 | if term in line and "grep" not in line: |
| 2216 | count += 1 |
| 2217 | if before.index( line ) > ( len( before ) - 7 ): |
| 2218 | logLines[termIndex].append( line ) |
| 2219 | main.log.info( "{}: {}".format( term, count ) ) |
| 2220 | totalHits += count |
| 2221 | if termIndex == numTerms - 1: |
| 2222 | print "\n" |
| 2223 | if outputMode != "s": |
| 2224 | outputString = "" |
| 2225 | for term in logLines: |
| 2226 | outputString = term[0] + ": \n" |
| 2227 | for line in range( 1, len( term ) ): |
| 2228 | outputString += ( "\t" + term[line] + "\n" ) |
| 2229 | if outputString != ( term[0] + ": \n" ): |
| 2230 | main.log.info( outputString ) |
| 2231 | main.log.info( "=" * 70 ) |
| 2232 | return totalHits |
| 2233 | except pexpect.EOF: |
| 2234 | main.log.error( self.name + ": EOF exception found" ) |
| 2235 | main.log.error( self.name + ": " + self.handle.before ) |
| 2236 | main.cleanup() |
| 2237 | main.exit() |
| 2238 | except pexpect.TIMEOUT: |
| 2239 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 2240 | main.log.error( self.name + ": " + self.handle.before ) |
| 2241 | main.cleanup() |
| 2242 | main.exit() |
| 2243 | except Exception: |
| 2244 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2245 | main.cleanup() |
| 2246 | main.exit() |
kelvin-onlab | 7a719bb | 2015-07-08 11:09:51 -0700 | [diff] [blame] | 2247 | |
| 2248 | def copyMininetFile( self, fileName, localPath, userName, ip, |
| 2249 | mnPath='~/mininet/custom/', timeout = 60 ): |
| 2250 | """ |
| 2251 | Description: |
| 2252 | Copy mininet topology file from dependency folder in the test folder |
| 2253 | and paste it to the mininet machine's mininet/custom folder |
| 2254 | Required: |
| 2255 | fileName - Name of the topology file to copy |
| 2256 | localPath - File path of the mininet topology file |
| 2257 | userName - User name of the mininet machine to send the file to |
| 2258 | ip - Ip address of the mininet machine |
| 2259 | Optional: |
| 2260 | mnPath - of the mininet directory to send the file to |
| 2261 | Return: |
| 2262 | Return main.TRUE if successfully copied the file otherwise |
| 2263 | return main.FALSE |
| 2264 | """ |
| 2265 | |
| 2266 | try: |
| 2267 | cmd = "scp " + localPath + fileName + " " + userName + "@" + \ |
| 2268 | str( ip ) + ":" + mnPath + fileName |
| 2269 | |
| 2270 | self.handle.sendline( "" ) |
| 2271 | self.handle.expect( "\$" ) |
| 2272 | |
| 2273 | main.log.info( self.name + ": Execute: " + cmd ) |
| 2274 | |
| 2275 | self.handle.sendline( cmd ) |
| 2276 | |
| 2277 | i = self.handle.expect( [ 'No such file', |
| 2278 | "100%", |
| 2279 | pexpect.TIMEOUT ] ) |
| 2280 | |
| 2281 | if i == 0: |
| 2282 | main.log.error( self.name + ": File " + fileName + |
| 2283 | " does not exist!" ) |
| 2284 | return main.FALSE |
| 2285 | |
| 2286 | if i == 1: |
| 2287 | main.log.info( self.name + ": File " + fileName + |
| 2288 | " has been copied!" ) |
| 2289 | self.handle.sendline( "" ) |
| 2290 | self.handle.expect( "\$" ) |
| 2291 | return main.TRUE |
| 2292 | |
| 2293 | except pexpect.EOF: |
| 2294 | main.log.error( self.name + ": EOF exception found" ) |
| 2295 | main.log.error( self.name + ": " + self.handle.before ) |
| 2296 | main.cleanup() |
| 2297 | main.exit() |
| 2298 | except pexpect.TIMEOUT: |
| 2299 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 2300 | main.log.error( self.name + ": " + self.handle.before ) |
| 2301 | main.cleanup() |
| 2302 | main.exit() |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2303 | |
| 2304 | def jvmSet(self, memory=8): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2305 | |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2306 | import os |
| 2307 | |
| 2308 | homeDir = os.path.expanduser('~') |
| 2309 | filename = "/onos/tools/package/bin/onos-service" |
| 2310 | |
| 2311 | serviceConfig = open(homeDir + filename, 'w+') |
| 2312 | serviceConfig.write("#!/bin/bash\n ") |
| 2313 | serviceConfig.write("#------------------------------------- \n ") |
| 2314 | serviceConfig.write("# Starts ONOS Apache Karaf container\n ") |
| 2315 | serviceConfig.write("#------------------------------------- \n ") |
| 2316 | serviceConfig.write("#export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-openjdk-amd64/}\n ") |
| 2317 | serviceConfig.write("""export JAVA_OPTS="${JAVA_OPTS:--Xms""" + str(memory) + "G -Xmx" + str(memory) + """G}" \n """) |
| 2318 | serviceConfig.write("[ -d $ONOS_HOME ] && cd $ONOS_HOME || ONOS_HOME=$(dirname $0)/..\n") |
| 2319 | serviceConfig.write("""${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/karaf "$@" \n """) |
| 2320 | serviceConfig.close() |
| 2321 | |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2322 | def createDBFile( self, testData ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2323 | |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2324 | filename = main.TEST + "DB" |
| 2325 | DBString = "" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2326 | |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2327 | for item in testData: |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2328 | if type( item ) is string: |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2329 | item = "'" + item + "'" |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2330 | if testData.index( item ) < len( testData - 1 ): |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2331 | item += "," |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2332 | DBString += str( item ) |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2333 | |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2334 | DBFile = open( filename, "a" ) |
| 2335 | DBFile.write( DBString ) |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2336 | DBFile.close() |
| 2337 | |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2338 | def verifySummary( self, ONOSIp, *deviceCount ): |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2339 | |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2340 | self.handle.sendline( "onos " + ONOSIp + " summary" ) |
| 2341 | self.handle.expect( ":~" ) |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2342 | |
| 2343 | summaryStr = self.handle.before |
| 2344 | print "\nSummary\n==============\n" + summaryStr + "\n\n" |
| 2345 | |
| 2346 | #passed = "SCC(s)=1" in summaryStr |
| 2347 | #if deviceCount: |
| 2348 | # passed = "devices=" + str(deviceCount) + "," not in summaryStr |
| 2349 | |
GlennRC | 772363b | 2015-08-25 13:05:57 -0700 | [diff] [blame] | 2350 | passed = False |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2351 | if "SCC(s)=1," in summaryStr: |
| 2352 | passed = True |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2353 | print "Summary is verifed" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2354 | else: |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2355 | print "Summary failed" |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2356 | |
| 2357 | if deviceCount: |
| 2358 | print" =============================" |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2359 | checkStr = "devices=" + str( deviceCount[0] ) + "," |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2360 | print "Checkstr: " + checkStr |
| 2361 | if checkStr not in summaryStr: |
| 2362 | passed = False |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2363 | print "Device count failed" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 2364 | else: |
| 2365 | print "device count verified" |
cameron@onlab.us | 78b8965 | 2015-07-08 15:21:03 -0700 | [diff] [blame] | 2366 | |
| 2367 | return passed |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2368 | |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2369 | def getIpAddr( self, iface=None ): |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2370 | """ |
| 2371 | Update self.ip_address with numerical ip address. If multiple IP's are |
| 2372 | located on the device, will attempt to use self.nicAddr to choose the |
| 2373 | right one. Defaults to 127.0.0.1 if no other address is found or cannot |
| 2374 | determine the correct address. |
| 2375 | |
| 2376 | ONLY WORKS WITH IPV4 ADDRESSES |
| 2377 | """ |
| 2378 | try: |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2379 | LOCALHOST = "127.0.0.1" |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2380 | ipPat = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" |
| 2381 | pattern = re.compile( ipPat ) |
| 2382 | match = re.search( pattern, self.ip_address ) |
| 2383 | if self.nicAddr: |
| 2384 | nicPat = self.nicAddr.replace( ".", "\." ).replace( "\*", r"\d{1,3}" ) |
| 2385 | nicPat = re.compile( nicPat ) |
| 2386 | else: |
| 2387 | nicPat = None |
| 2388 | # IF self.ip_address is an ip address and matches |
| 2389 | # self.nicAddr: return self.ip_address |
| 2390 | if match: |
| 2391 | curIp = match.group(0) |
| 2392 | if nicPat: |
| 2393 | nicMatch = re.search( nicPat, curIp ) |
| 2394 | if nicMatch: |
| 2395 | return self.ip_address |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2396 | # ELSE: IF iface, return ip of interface |
| 2397 | cmd = "ifconfig" |
| 2398 | ifPat = re.compile( "inet addr:({})".format( ipPat ) ) |
| 2399 | if iface: |
| 2400 | cmd += " " + str( iface ) |
| 2401 | raw = subprocess.check_output( cmd.split() ) |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2402 | ifPat = re.compile( "inet addr:({})".format( ipPat ) ) |
| 2403 | ips = re.findall( ifPat, raw ) |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2404 | if iface: |
| 2405 | if ips: |
| 2406 | ip = ips[0] |
| 2407 | self.ip_address = ip |
| 2408 | return ip |
| 2409 | else: |
| 2410 | main.log.error( "Error finding ip, ifconfig output:".format( raw ) ) |
| 2411 | # ELSE: attempt to get address matching nicPat. |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2412 | if nicPat: |
| 2413 | for ip in ips: |
| 2414 | curMatch = re.search( nicPat, ip ) |
| 2415 | if curMatch: |
| 2416 | self.ip_address = ip |
| 2417 | return ip |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2418 | else: # If only one non-localhost ip, return that |
| 2419 | tmpList = [ ip for ip in ips if ip is not LOCALHOST ] |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2420 | if len(tmpList) == 1: |
| 2421 | curIp = tmpList[0] |
| 2422 | self.ip_address = curIp |
| 2423 | return curIp |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2424 | # Either no non-localhost IPs, or more than 1 |
Jon Hall | ebccd35 | 2016-05-20 15:17:17 -0700 | [diff] [blame] | 2425 | main.log.warn( "getIpAddr failed to find a public IP address" ) |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2426 | return LOCALHOST |
Jon Hall | e179095 | 2016-05-23 15:51:46 -0700 | [diff] [blame] | 2427 | except subprocess.CalledProcessError: |
Jon Hall | 8f6d462 | 2016-05-23 15:27:18 -0700 | [diff] [blame] | 2428 | main.log.exception( "Error executing ifconfig" ) |
| 2429 | except IndexError: |
| 2430 | main.log.exception( "Error getting IP Address" ) |
Jon Hall | 6c44c0b | 2016-04-20 15:21:00 -0700 | [diff] [blame] | 2431 | except Exception: |
| 2432 | main.log.exception( "Uncaught exception" ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2433 | |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 2434 | def startBasicONOS( self, nodeList, opSleep=60, onosStartupSleep=30 ): |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2435 | ''' |
| 2436 | Start onos cluster with defined nodes, but only with drivers app |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2437 | ''' |
| 2438 | import time |
| 2439 | |
| 2440 | self.createCellFile( self.ip_address, |
| 2441 | "temp", |
| 2442 | self.ip_address, |
| 2443 | "drivers", |
| 2444 | nodeList ) |
| 2445 | |
| 2446 | main.log.info( self.name + ": Apply cell to environment" ) |
| 2447 | cellResult = self.setCell( "temp" ) |
| 2448 | verifyResult = self.verifyCell() |
| 2449 | |
| 2450 | main.log.info( self.name + ": Creating ONOS package" ) |
You Wang | d1bcaca | 2016-10-24 15:23:26 -0700 | [diff] [blame] | 2451 | packageResult = self.buckBuild( timeout=opSleep ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2452 | |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 2453 | main.log.info( self.name + ": Uninstalling ONOS" ) |
| 2454 | for nd in nodeList: |
| 2455 | self.onosUninstall( nodeIp=nd ) |
| 2456 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2457 | main.log.info( self.name + ": Installing ONOS package" ) |
| 2458 | for nd in nodeList: |
You Wang | c669d21 | 2017-01-25 11:09:48 -0800 | [diff] [blame] | 2459 | self.onosInstall( node=nd ) |
| 2460 | |
| 2461 | main.log.info( self.name + ": Set up ONOS secure SSH" ) |
| 2462 | for nd in nodeList: |
| 2463 | self.onosSecureSSH( node=nd ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 2464 | |
| 2465 | main.log.info( self.name + ": Starting ONOS service" ) |
| 2466 | time.sleep( onosStartupSleep ) |
| 2467 | |
| 2468 | onosStatus = True |
| 2469 | for nd in nodeList: |
| 2470 | onosStatus = onosStatus & self.isup( node = nd ) |
| 2471 | #print "onosStatus is: " + str( onosStatus ) |
| 2472 | |
| 2473 | return main.TRUE if onosStatus else main.FALSE |
| 2474 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 2475 | def onosNetCfg( self, controllerIps, path, fileName ): |
| 2476 | """ |
| 2477 | Push a specified json file to ONOS through the onos-netcfg service |
| 2478 | |
| 2479 | Required: |
| 2480 | controllerIps - the Ips of the ONOS nodes in the cluster |
| 2481 | path - the location of the file to be sent |
| 2482 | fileName - name of the json file to be sent |
| 2483 | |
| 2484 | Returns main.TRUE on successfully sending json file, and main.FALSE if |
| 2485 | there is an error. |
| 2486 | """ |
| 2487 | try: |
| 2488 | cmd = "onos-netcfg {0} {1}{2}.json".format( controllerIps, path, fileName ) |
| 2489 | main.log.info( "Sending: " + cmd ) |
| 2490 | main.ONOSbench.handle.sendline( cmd ) |
| 2491 | handle = self.handle.before |
| 2492 | print handle |
| 2493 | if "Error" in handle: |
| 2494 | main.log.error( self.name + ": " + self.handle.before ) |
| 2495 | return main.FALSE |
| 2496 | else: |
| 2497 | self.handle.expect( "\$" ) |
| 2498 | return main.TRUE |
| 2499 | except pexpect.EOF: |
| 2500 | main.log.error( self.name + ": EOF exception found" ) |
| 2501 | main.log.error( self.name + ": " + self.handle.before ) |
| 2502 | main.cleanup() |
| 2503 | main.exit() |
| 2504 | except Exception: |
| 2505 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2506 | main.cleanup() |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 2507 | main.exit() |