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