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