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