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