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