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 |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 22 | import traceback |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 23 | import os.path |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 24 | sys.path.append( "../" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 25 | from drivers.common.clidriver import CLI |
| 26 | |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 27 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 28 | class OnosDriver( CLI ): |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 29 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 30 | def __init__( self ): |
| 31 | """ |
| 32 | Initialize client |
| 33 | """ |
| 34 | super( CLI, self ).__init__() |
| 35 | |
| 36 | def connect( self, **connectargs ): |
| 37 | """ |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 38 | Creates ssh handle for ONOS "bench". |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 39 | """ |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 40 | try: |
| 41 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 42 | vars( self )[ key ] = connectargs[ key ] |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 43 | self.home = "~/ONOS" |
| 44 | for key in self.options: |
| 45 | if key == "home": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 46 | self.home = self.options[ 'home' ] |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 47 | break |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 48 | if self.home == None or self.home == "": |
| 49 | self.home = "~/ONOS" |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame^] | 50 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 51 | self.name = self.options[ 'name' ] |
| 52 | self.handle = super( OnosDriver, self ).connect( |
| 53 | user_name=self.user_name, |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 54 | ip_address=self.ip_address, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 55 | port=self.port, |
| 56 | pwd=self.pwd, |
| 57 | home=self.home ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 58 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 59 | self.handle.sendline( "cd " + self.home ) |
| 60 | self.handle.expect( "\$" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 61 | if self.handle: |
| 62 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 63 | else: |
| 64 | main.log.info( "NO ONOS HANDLE" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 65 | return main.FALSE |
| 66 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 67 | main.log.error( self.name + ": EOF exception found" ) |
| 68 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 69 | main.cleanup() |
| 70 | main.exit() |
| 71 | except: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 72 | main.log.info( self.name + ":" * 30 ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 73 | main.log.error( traceback.print_exc() ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 74 | main.log.info( ":" * 30 ) |
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 | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 82 | response = '' |
| 83 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 84 | self.handle.sendline( "" ) |
| 85 | self.handle.expect( "\$" ) |
| 86 | self.handle.sendline( "exit" ) |
| 87 | self.handle.expect( "closed" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 88 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 89 | main.log.error( self.name + ": EOF exception found" ) |
| 90 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 91 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 92 | main.log.error( self.name + ": Connection failed to the host" ) |
Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame] | 93 | response = main.FALSE |
| 94 | return response |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 95 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 96 | def onosPackage( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 97 | """ |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 98 | Produce a self-contained tar.gz file that can be deployed |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 99 | and executed on any platform with Java 7 JRE. |
| 100 | """ |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 101 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 102 | self.handle.sendline( "onos-package" ) |
| 103 | self.handle.expect( "onos-package" ) |
| 104 | self.handle.expect( "tar.gz", timeout=30 ) |
| 105 | handle = str( self.handle.before ) |
| 106 | main.log.info( "onos-package command returned: " + |
| 107 | handle ) |
| 108 | # As long as the sendline does not time out, |
| 109 | # return true. However, be careful to interpret |
| 110 | # the results of the onos-package command return |
andrewonlab | 0748d2a | 2014-10-09 13:24:17 -0400 | [diff] [blame] | 111 | return main.TRUE |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 112 | |
andrewonlab | 7735d85 | 2014-10-09 13:02:47 -0400 | [diff] [blame] | 113 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 114 | main.log.error( self.name + ": EOF exception found" ) |
| 115 | main.log.error( self.name + ": " + self.handle.before ) |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 116 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 117 | main.log.error( "Failed to package ONOS" ) |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 118 | main.cleanup() |
| 119 | main.exit() |
| 120 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 121 | def onosBuild( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 122 | """ |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 123 | Use the pre defined script to build onos via mvn |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 124 | """ |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 125 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 126 | self.handle.sendline( "onos-build" ) |
| 127 | self.handle.expect( "onos-build" ) |
| 128 | i = self.handle.expect( [ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 129 | "BUILD SUCCESS", |
| 130 | "ERROR", |
| 131 | "BUILD FAILED" ], |
| 132 | timeout=120 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 133 | handle = str( self.handle.before ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 134 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 135 | main.log.info( "onos-build command returned: " + |
| 136 | handle ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 137 | |
| 138 | if i == 0: |
| 139 | return main.TRUE |
| 140 | else: |
| 141 | return handle |
| 142 | |
| 143 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 144 | main.log.error( self.name + ": EOF exception found" ) |
| 145 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 146 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 147 | main.log.error( "Failed to build ONOS" ) |
andrewonlab | 8790abb | 2014-11-06 13:51:54 -0500 | [diff] [blame] | 148 | main.cleanup() |
| 149 | main.exit() |
| 150 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 151 | def cleanInstall( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 152 | """ |
| 153 | Runs mvn clean install in the root of the ONOS directory. |
| 154 | This will clean all ONOS artifacts then compile each module |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame] | 155 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 156 | Returns: main.TRUE on success |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 157 | On Failure, exits the test |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 158 | """ |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 159 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 160 | main.log.info( "Running 'mvn clean install' on " + |
| 161 | str( self.name ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 162 | ". This may take some time." ) |
| 163 | self.handle.sendline( "cd " + self.home ) |
| 164 | self.handle.expect( "\$" ) |
Jon Hall | ea7818b | 2014-10-09 14:30:59 -0400 | [diff] [blame] | 165 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 166 | self.handle.sendline( "" ) |
| 167 | self.handle.expect( "\$" ) |
| 168 | self.handle.sendline( "mvn clean install" ) |
| 169 | self.handle.expect( "mvn clean install" ) |
| 170 | while True: |
| 171 | i = self.handle.expect( [ |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 172 | 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s\ |
| 173 | Runtime\sEnvironment\sto\scontinue', |
| 174 | 'BUILD\sFAILURE', |
| 175 | 'BUILD\sSUCCESS', |
| 176 | 'ONOS\$', |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 177 | pexpect.TIMEOUT ], timeout=600 ) |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 178 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 179 | main.log.error( self.name + ":There is insufficient memory \ |
| 180 | for the Java Runtime Environment to continue." ) |
| 181 | # return main.FALSE |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 182 | main.cleanup() |
| 183 | main.exit() |
| 184 | if i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 185 | main.log.error( self.name + ": Build failure!" ) |
| 186 | # return main.FALSE |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 187 | main.cleanup() |
| 188 | main.exit() |
| 189 | elif i == 2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 190 | main.log.info( self.name + ": Build success!" ) |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 191 | elif i == 3: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 192 | main.log.info( self.name + ": Build complete" ) |
| 193 | # Print the build time |
Jon Hall | f8ef52c | 2014-10-09 19:37:33 -0400 | [diff] [blame] | 194 | for line in self.handle.before.splitlines(): |
| 195 | if "Total time:" in line: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 196 | main.log.info( line ) |
| 197 | self.handle.sendline( "" ) |
| 198 | self.handle.expect( "\$", timeout=60 ) |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 199 | return main.TRUE |
| 200 | elif i == 4: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 201 | main.log.error( |
| 202 | self.name + |
| 203 | ": mvn clean install TIMEOUT!" ) |
| 204 | # return main.FALSE |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 205 | main.cleanup() |
| 206 | main.exit() |
| 207 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 208 | main.log.error( self.name + ": unexpected response from \ |
| 209 | mvn clean install" ) |
| 210 | # return main.FALSE |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 211 | main.cleanup() |
| 212 | main.exit() |
| 213 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 214 | main.log.error( self.name + ": EOF exception found" ) |
| 215 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 216 | main.cleanup() |
| 217 | main.exit() |
| 218 | except: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 219 | main.log.info( self.name + ":" * 60 ) |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 220 | main.log.error( traceback.print_exc() ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 221 | main.log.info( ":" * 60 ) |
Jon Hall | de9d9aa | 2014-10-08 20:36:02 -0400 | [diff] [blame] | 222 | main.cleanup() |
| 223 | main.exit() |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 224 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 225 | def gitPull( self, comp1="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 226 | """ |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 227 | Assumes that "git pull" works without login |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 228 | |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 229 | This function will perform a git pull on the ONOS instance. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 230 | 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] | 231 | for the purpose of pulling from other nodes if necessary. |
| 232 | |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 233 | Otherwise, this function will perform a git pull in the |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 234 | ONOS repository. If it has any problems, it will return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 235 | 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] | 236 | If it has no updates, it will return 3. |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 237 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 238 | """ |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 239 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 240 | # main.log.info( self.name + ": Stopping ONOS" ) |
| 241 | # self.stop() |
| 242 | self.handle.sendline( "cd " + self.home ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 243 | self.handle.expect( self.home + "\$" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 244 | if comp1 == "": |
| 245 | self.handle.sendline( "git pull" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 246 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 247 | self.handle.sendline( "git pull " + comp1 ) |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 248 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 249 | i = self.handle.expect( |
| 250 | [ |
| 251 | 'fatal', |
| 252 | 'Username\sfor\s(.*):\s', |
| 253 | '\sfile(s*) changed,\s', |
| 254 | 'Already up-to-date', |
| 255 | 'Aborting', |
| 256 | 'You\sare\snot\scurrently\son\sa\sbranch', |
| 257 | 'You\sasked\sme\sto\spull\swithout\stelling\sme\swhich\ |
| 258 | \sbranch\syou', |
| 259 | 'Pull\sis\snot\spossible\sbecause\syou\shave\sunmerged\ |
| 260 | \sfiles', |
| 261 | pexpect.TIMEOUT ], |
| 262 | timeout=300 ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 263 | # debug |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 264 | # main.log.report( self.name +": DEBUG: \n"+ |
| 265 | # "git pull response: " + |
| 266 | # str( self.handle.before ) + str( self.handle.after ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 267 | if i == 0: |
| 268 | main.log.error( self.name + ": Git pull had some issue..." ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 269 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 270 | elif i == 1: |
| 271 | main.log.error( |
| 272 | self.name + |
| 273 | ": Git Pull Asking for username. " ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 274 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 275 | elif i == 2: |
| 276 | main.log.info( |
| 277 | self.name + |
| 278 | ": Git Pull - pulling repository now" ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 279 | self.handle.expect( self.home + "\$", 120 ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 280 | # So that only when git pull is done, we do mvn clean compile |
| 281 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 282 | elif i == 3: |
| 283 | main.log.info( self.name + ": Git Pull - Already up to date" ) |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 284 | return i |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 285 | elif i == 4: |
| 286 | main.log.info( |
| 287 | self.name + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 288 | ": Git Pull - Aborting...\ |
| 289 | Are there conflicting git files?" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 290 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 291 | elif i == 5: |
| 292 | main.log.info( |
| 293 | self.name + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 294 | ": Git Pull - You are not currently\ |
| 295 | on a branch so git pull failed!" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 296 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 297 | elif i == 6: |
| 298 | main.log.info( |
| 299 | self.name + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 300 | ": Git Pull - You have not configured\ |
| 301 | an upstream branch to pull from\ |
| 302 | . Git pull failed!" ) |
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 == 7: |
| 305 | main.log.info( |
| 306 | self.name + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 307 | ": Git Pull - Pull is not possible\ |
| 308 | because you have unmerged files." ) |
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 == 8: |
| 311 | main.log.error( self.name + ": Git Pull - TIMEOUT" ) |
| 312 | main.log.error( |
| 313 | self.name + " Response was: " + str( |
| 314 | self.handle.before ) ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 315 | return main.ERROR |
| 316 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 317 | main.log.error( |
| 318 | self.name + |
| 319 | ": Git Pull - Unexpected response, check for pull errors" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 320 | return main.ERROR |
| 321 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 322 | main.log.error( self.name + ": EOF exception found" ) |
| 323 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 324 | main.cleanup() |
| 325 | main.exit() |
| 326 | except: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 327 | main.log.info( self.name + ":" * 60 ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 328 | main.log.error( traceback.print_exc() ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 329 | main.log.info( ":" * 80 ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 330 | main.cleanup() |
| 331 | main.exit() |
| 332 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 333 | def gitCheckout( self, branch="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 334 | """ |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 335 | Assumes that "git pull" works without login |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 336 | |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 337 | This function will perform a git git checkout on the ONOS instance. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 338 | If used as gitCheckout( "branch" ) it will do git checkout |
| 339 | of the "branch". |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 340 | |
| 341 | Otherwise, this function will perform a git checkout of the master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 342 | branch of the ONOS repository. If it has any problems, it will return |
| 343 | main.ERROR. |
| 344 | 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] | 345 | successful then the function will return main.TRUE. |
| 346 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 347 | """ |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 348 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 349 | self.handle.sendline( "cd " + self.home ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 350 | self.handle.expect( self.home + "\$" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 351 | main.log.info( |
| 352 | self.name + |
| 353 | ": Checking out git branch: " + |
| 354 | branch + |
| 355 | "..." ) |
| 356 | cmd = "git checkout " + branch |
| 357 | self.handle.sendline( cmd ) |
| 358 | self.handle.expect( cmd ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 359 | i = self.handle.expect( |
| 360 | [ |
| 361 | 'fatal', |
| 362 | 'Username\sfor\s(.*):\s', |
| 363 | 'Already\son\s\'', |
| 364 | 'Switched\sto\sbranch\s\'' + |
| 365 | str( branch ), |
| 366 | pexpect.TIMEOUT, |
| 367 | 'error: Your local changes to the following files\ |
| 368 | would be overwritten by checkout:', |
| 369 | 'error: you need to resolve your current index first' ], |
| 370 | timeout=60 ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 371 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 372 | if i == 0: |
| 373 | main.log.error( |
| 374 | self.name + |
| 375 | ": Git checkout had some issue..." ) |
| 376 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 377 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 378 | elif i == 1: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 379 | main.log.error( |
| 380 | self.name + |
| 381 | ": Git checkout asking for username." + |
| 382 | " Please configure your local git repository to be able " + |
| 383 | "to access your remote repository passwordlessly" ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 384 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 385 | elif i == 2: |
| 386 | main.log.info( |
| 387 | self.name + |
| 388 | ": Git Checkout %s : Already on this branch" % |
| 389 | branch ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 390 | self.handle.expect( self.home + "\$" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 391 | # main.log.info( "DEBUG: after checkout cmd = "+ |
| 392 | # self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 393 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 394 | elif i == 3: |
| 395 | main.log.info( |
| 396 | self.name + |
| 397 | ": Git checkout %s - Switched to this branch" % |
| 398 | branch ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 399 | self.handle.expect( self.home + "\$" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 400 | # main.log.info( "DEBUG: after checkout cmd = "+ |
| 401 | # self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 402 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 403 | elif i == 4: |
| 404 | main.log.error( self.name + ": Git Checkout- TIMEOUT" ) |
| 405 | main.log.error( |
| 406 | self.name + " Response was: " + str( |
| 407 | self.handle.before ) ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 408 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 409 | elif i == 5: |
| 410 | self.handle.expect( "Aborting" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 411 | main.log.error( |
| 412 | self.name + |
| 413 | ": Git checkout error: \n" + |
| 414 | "Your local changes to the following\ |
| 415 | files would be overwritten by checkout:" + |
| 416 | str( |
| 417 | self.handle.before ) ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 418 | self.handle.expect( self.home + "\$" ) |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 419 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 420 | elif i == 6: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 421 | main.log.error( self.name + |
| 422 | ": Git checkout error: \n" + |
| 423 | "You need to resolve your\ |
| 424 | current index first:" + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 425 | str( self.handle.before ) ) |
kelvin-onlab | a148458 | 2015-02-02 15:46:20 -0800 | [diff] [blame] | 426 | self.handle.expect( self.home + "\$" ) |
Jon Hall | 81e29af | 2014-11-04 20:41:23 -0500 | [diff] [blame] | 427 | return main.ERROR |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 428 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 429 | main.log.error( |
| 430 | self.name + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 431 | ": Git Checkout - Unexpected response,\ |
| 432 | check for pull errors" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 433 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 434 | return main.ERROR |
| 435 | |
| 436 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 437 | main.log.error( self.name + ": EOF exception found" ) |
| 438 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 439 | main.cleanup() |
| 440 | main.exit() |
| 441 | except: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 442 | main.log.info( self.name + ":" * 60 ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 443 | main.log.error( traceback.print_exc() ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 444 | main.log.info( ":" * 80 ) |
Jon Hall | acabffd | 2014-10-09 12:36:53 -0400 | [diff] [blame] | 445 | main.cleanup() |
| 446 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 447 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 448 | def getVersion( self, report=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 449 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 450 | Writes the COMMIT number to the report to be parsed\ |
| 451 | by Jenkins data collecter. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 452 | """ |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 453 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 454 | self.handle.sendline( "" ) |
| 455 | self.handle.expect( "\$" ) |
| 456 | self.handle.sendline( |
| 457 | "cd " + |
| 458 | self.home + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 459 | "; git log -1 --pretty=fuller --decorate=short | grep -A 6\ |
| 460 | \"commit\" --color=never" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 461 | # NOTE: for some reason there are backspaces inserted in this |
| 462 | # phrase when run from Jenkins on some tests |
| 463 | self.handle.expect( "never" ) |
| 464 | self.handle.expect( "\$" ) |
| 465 | response = ( self.name + ": \n" + str( |
| 466 | self.handle.before + self.handle.after ) ) |
| 467 | self.handle.sendline( "cd " + self.home ) |
| 468 | self.handle.expect( "\$" ) |
| 469 | lines = response.splitlines() |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 470 | for line in lines: |
Jon Hall | fd19120 | 2014-11-07 18:36:09 -0500 | [diff] [blame] | 471 | print line |
| 472 | if report: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 473 | for line in lines[ 2:-1 ]: |
| 474 | # Bracket replacement is for Wiki-compliant |
| 475 | # formatting. '<' or '>' are interpreted |
| 476 | # as xml specific tags that cause errors |
| 477 | line = line.replace( "<", "[" ) |
| 478 | line = line.replace( ">", "]" ) |
| 479 | main.log.report( "\t" + line ) |
| 480 | return lines[ 2 ] |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 481 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 482 | main.log.error( self.name + ": EOF exception found" ) |
| 483 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 484 | main.cleanup() |
| 485 | main.exit() |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 486 | except pexpect.TIMEOUT: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 487 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 488 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 489 | main.cleanup() |
| 490 | main.exit() |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 491 | except: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 492 | main.log.info( self.name + ":" * 60 ) |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 493 | main.log.error( traceback.print_exc() ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 494 | main.log.info( ":" * 80 ) |
Jon Hall | 45ec092 | 2014-10-10 19:33:49 -0400 | [diff] [blame] | 495 | main.cleanup() |
| 496 | main.exit() |
| 497 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 498 | def createCellFile( self, benchIp, fileName, mnIpAddrs, |
| 499 | extraFeatureString, *onosIpAddrs ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 500 | """ |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 501 | Creates a cell file based on arguments |
| 502 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 503 | * Bench IP address ( benchIp ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 504 | - Needed to copy the cell file over |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 505 | * File name of the cell file ( fileName ) |
| 506 | * Mininet IP address ( mnIpAddrs ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 507 | - Note that only 1 ip address is |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 508 | supported currently |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 509 | * ONOS IP addresses ( onosIpAddrs ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 510 | - Must be passed in as last arguments |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 511 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 512 | NOTE: Assumes cells are located at: |
| 513 | ~/<self.home>/tools/test/cells/ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 514 | """ |
| 515 | # Variable initialization |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 516 | cellDirectory = self.home + "/tools/test/cells/" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 517 | # We want to create the cell file in the dependencies directory |
| 518 | # of TestON first, then copy over to ONOS bench |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 519 | tempDirectory = "/tmp/" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 520 | # Create the cell file in the directory for writing ( w+ ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 521 | cellFile = open( tempDirectory + fileName, 'w+' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 522 | |
| 523 | # Feature string is hardcoded environment variables |
| 524 | # That you may wish to use by default on startup. |
| 525 | # Note that you may not want certain features listed |
| 526 | # on here. |
jenkins | bd0e753 | 2015-02-10 14:32:54 -0800 | [diff] [blame] | 527 | coreFeatureString = "export ONOS_FEATURES=" + extraFeatureString |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 528 | mnString = "export OCN=" |
| 529 | onosString = "export OC" |
| 530 | tempCount = 1 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 531 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 532 | # Create ONOSNIC ip address prefix |
| 533 | tempOnosIp = onosIpAddrs[ 0 ] |
| 534 | tempList = [] |
| 535 | tempList = tempOnosIp.split( "." ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 536 | # Omit last element of list to format for NIC |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 537 | tempList = tempList[ :-1 ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 538 | # Structure the nic string ip |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 539 | nicAddr = ".".join( tempList ) + ".*" |
| 540 | onosNicString = "export ONOS_NIC=" + nicAddr |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 541 | |
| 542 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 543 | # Start writing to file |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 544 | cellFile.write( onosNicString + "\n" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 545 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 546 | for arg in onosIpAddrs: |
| 547 | # For each argument in onosIpAddrs, write to file |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 548 | # Output should look like the following: |
andrewonlab | d494049 | 2014-10-24 12:21:27 -0400 | [diff] [blame] | 549 | # export OC1="10.128.20.11" |
| 550 | # export OC2="10.128.20.12" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 551 | cellFile.write( onosString + str( tempCount ) + |
| 552 | "=" + "\"" + arg + "\"" + "\n" ) |
| 553 | tempCount = tempCount + 1 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 554 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 555 | cellFile.write( mnString + "\"" + mnIpAddrs + "\"" + "\n" ) |
| 556 | cellFile.write( coreFeatureString + "\n" ) |
| 557 | cellFile.close() |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 558 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 559 | # We use os.system to send the command to TestON cluster |
| 560 | # to account for the case in which TestON is not located |
| 561 | # on the same cluster as the ONOS bench |
| 562 | # Note that even if TestON is located on the same cluster |
| 563 | # as ONOS bench, you must setup passwordless ssh |
| 564 | # between TestON and ONOS bench in order to automate the test. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 565 | os.system( "scp " + tempDirectory + fileName + |
| 566 | " admin@" + benchIp + ":" + cellDirectory ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 567 | |
andrewonlab | 2a6c934 | 2014-10-16 13:40:15 -0400 | [diff] [blame] | 568 | return main.TRUE |
| 569 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 570 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 571 | main.log.error( self.name + ": EOF exception found" ) |
| 572 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 573 | main.cleanup() |
| 574 | main.exit() |
| 575 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 576 | main.log.info( self.name + ":::::::::" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 577 | main.log.error( traceback.print_exc() ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 578 | main.log.info( ":::::::" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 579 | main.cleanup() |
| 580 | main.exit() |
| 581 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 582 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 583 | """ |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 584 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 585 | """ |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 586 | try: |
| 587 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 588 | main.log.error( "Must define cellname" ) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 589 | main.cleanup() |
| 590 | main.exit() |
| 591 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 592 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 593 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 594 | # Note that this variable name is subject to change |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 595 | # and that this driver will have to change accordingly |
jenkins | bd0e753 | 2015-02-10 14:32:54 -0800 | [diff] [blame] | 596 | self.handle.expect( "ONOS_CELL" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 597 | handleBefore = self.handle.before |
| 598 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 599 | # Get the rest of the handle |
| 600 | self.handle.sendline( "" ) |
| 601 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 602 | handleMore = self.handle.before |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 603 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 604 | main.log.info( "Cell call returned: " + handleBefore + |
| 605 | handleAfter + handleMore ) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 606 | |
| 607 | return main.TRUE |
| 608 | |
| 609 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 610 | main.log.error( self.name + ": EOF exception found" ) |
| 611 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 612 | main.cleanup() |
| 613 | main.exit() |
| 614 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 615 | main.log.info( self.name + " ::::::" ) |
| 616 | main.log.error( traceback.print_exc() ) |
| 617 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 618 | main.cleanup() |
| 619 | main.exit() |
| 620 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 621 | def verifyCell( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 622 | """ |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 623 | Calls 'onos-verify-cell' to check for cell installation |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 624 | """ |
| 625 | # TODO: Add meaningful expect value |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 626 | |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 627 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 628 | # Clean handle by sending empty and expecting $ |
| 629 | self.handle.sendline( "" ) |
| 630 | self.handle.expect( "\$" ) |
| 631 | self.handle.sendline( "onos-verify-cell" ) |
| 632 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 633 | handleBefore = self.handle.before |
| 634 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 635 | # Get the rest of the handle |
| 636 | self.handle.sendline( "" ) |
| 637 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 638 | handleMore = self.handle.before |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 639 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 640 | main.log.info( "Verify cell returned: " + handleBefore + |
| 641 | handleAfter + handleMore ) |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 642 | |
| 643 | return main.TRUE |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 644 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 645 | main.log.error( self.name + ": EOF exception found" ) |
| 646 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 647 | main.cleanup() |
| 648 | main.exit() |
| 649 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 650 | main.log.info( self.name + " ::::::" ) |
| 651 | main.log.error( traceback.print_exc() ) |
| 652 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 653 | main.cleanup() |
| 654 | main.exit() |
| 655 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 656 | def onosCli( self, ONOSIp, cmdstr ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 657 | """ |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 658 | Uses 'onos' command to send various ONOS CLI arguments. |
| 659 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 660 | * ONOSIp: specify the ip of the cell machine |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 661 | * cmdstr: specify the command string to send |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 662 | |
| 663 | This function is intended to expose the entire karaf |
andrewonlab | 6e20c34 | 2014-10-10 18:08:48 -0400 | [diff] [blame] | 664 | CLI commands for ONOS. Try to use this function first |
| 665 | before attempting to write a ONOS CLI specific driver |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 666 | function. |
| 667 | You can see a list of available 'cmdstr' arguments |
andrewonlab | 6e20c34 | 2014-10-10 18:08:48 -0400 | [diff] [blame] | 668 | by starting onos, and typing in 'onos' to enter the |
| 669 | onos> CLI. Then, type 'help' to see the list of |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 670 | available commands. |
| 671 | """ |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 672 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 673 | if not ONOSIp: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 674 | main.log.error( "You must specify the IP address" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 675 | return main.FALSE |
| 676 | if not cmdstr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 677 | main.log.error( "You must specify the command string" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 678 | return main.FALSE |
| 679 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 680 | cmdstr = str( cmdstr ) |
| 681 | self.handle.sendline( "" ) |
| 682 | self.handle.expect( "\$" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 683 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 684 | self.handle.sendline( "onos -w " + ONOSIp + " " + cmdstr ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 685 | self.handle.expect( "\$" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 686 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 687 | handleBefore = self.handle.before |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 688 | print "handle_before = ", self.handle.before |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 689 | # handleAfter = str( self.handle.after ) |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 690 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 691 | # self.handle.sendline( "" ) |
| 692 | # self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 693 | # handleMore = str( self.handle.before ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 694 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 695 | main.log.info( "Command sent successfully" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 696 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 697 | # Obtain return handle that consists of result from |
| 698 | # the onos command. The string may need to be |
| 699 | # configured further. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 700 | # returnString = handleBefore + handleAfter |
| 701 | returnString = handleBefore |
| 702 | print "return_string = ", returnString |
| 703 | return returnString |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 704 | |
| 705 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 706 | main.log.error( self.name + ": EOF exception found" ) |
| 707 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 708 | main.cleanup() |
| 709 | main.exit() |
| 710 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 711 | main.log.info( self.name + " ::::::" ) |
| 712 | main.log.error( traceback.print_exc() ) |
| 713 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 714 | main.cleanup() |
| 715 | main.exit() |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 716 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 717 | def onosInstall( self, options="-f", node="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 718 | """ |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 719 | Installs ONOS bits on the designated cell machine. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 720 | If -f option is provided, it also forces an uninstall. |
| 721 | Presently, install also includes onos-push-bits and |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 722 | onos-config within. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 723 | The node option allows you to selectively only push the jar |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 724 | files to certain onos nodes |
| 725 | |
| 726 | Returns: main.TRUE on success and main.FALSE on failure |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 727 | """ |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 728 | try: |
andrewonlab | 114768a | 2014-11-14 12:44:44 -0500 | [diff] [blame] | 729 | if options: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 730 | self.handle.sendline( "onos-install " + options + " " + node ) |
andrewonlab | 114768a | 2014-11-14 12:44:44 -0500 | [diff] [blame] | 731 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 732 | self.handle.sendline( "onos-install " + node ) |
| 733 | self.handle.expect( "onos-install " ) |
| 734 | # NOTE: this timeout may need to change depending on the network |
| 735 | # and size of ONOS |
| 736 | i = self.handle.expect( [ "Network\sis\sunreachable", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 737 | "onos\sstart/running,\sprocess", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 738 | "ONOS\sis\salready\sinstalled", |
| 739 | pexpect.TIMEOUT ], timeout=60 ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 740 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 741 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 742 | main.log.warn( "Network is unreachable" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 743 | return main.FALSE |
| 744 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 745 | main.log.info( |
| 746 | "ONOS was installed on " + |
| 747 | node + |
| 748 | " and started" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 749 | return main.TRUE |
andrewonlab | d9a73a7 | 2014-11-14 17:28:21 -0500 | [diff] [blame] | 750 | elif i == 2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 751 | main.log.info( "ONOS is already installed on " + node ) |
andrewonlab | d9a73a7 | 2014-11-14 17:28:21 -0500 | [diff] [blame] | 752 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 753 | elif i == 3: |
| 754 | main.log.info( |
| 755 | "Installation of ONOS on " + |
| 756 | node + |
| 757 | " timed out" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 758 | return main.FALSE |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 759 | |
| 760 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 761 | main.log.error( self.name + ": EOF exception found" ) |
| 762 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 763 | main.cleanup() |
| 764 | main.exit() |
| 765 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 766 | main.log.info( self.name + " ::::::" ) |
| 767 | main.log.error( traceback.print_exc() ) |
| 768 | main.log.info( self.name + " ::::::" ) |
andrewonlab | c03bf6c | 2014-10-09 14:56:18 -0400 | [diff] [blame] | 769 | main.cleanup() |
| 770 | main.exit() |
andrewonlab | 95ca146 | 2014-10-09 14:04:24 -0400 | [diff] [blame] | 771 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 772 | def onosStart( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 773 | """ |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 774 | Calls onos command: 'onos-service [<node-ip>] start' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 775 | This command is a remote management of the ONOS upstart daemon |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 776 | """ |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 777 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 778 | self.handle.sendline( "" ) |
| 779 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 780 | self.handle.sendline( "onos-service " + str( nodeIp ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 781 | " start" ) |
| 782 | i = self.handle.expect( [ |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 783 | "Job\sis\salready\srunning", |
| 784 | "start/running", |
| 785 | "Unknown\sinstance", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 786 | pexpect.TIMEOUT ], timeout=120 ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 787 | |
| 788 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 789 | main.log.info( "Service is already running" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 790 | return main.TRUE |
| 791 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 792 | main.log.info( "ONOS service started" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 793 | return main.TRUE |
| 794 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 795 | main.log.error( "ONOS service failed to start" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 796 | main.cleanup() |
| 797 | main.exit() |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 798 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 799 | main.log.error( self.name + ": EOF exception found" ) |
| 800 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 801 | main.cleanup() |
| 802 | main.exit() |
| 803 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 804 | main.log.info( self.name + " ::::::" ) |
| 805 | main.log.error( traceback.print_exc() ) |
| 806 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 807 | main.cleanup() |
| 808 | main.exit() |
| 809 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 810 | def onosStop( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 811 | """ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 812 | Calls onos command: 'onos-service [<node-ip>] stop' |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 813 | This command is a remote management of the ONOS upstart daemon |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 814 | """ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 815 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 816 | self.handle.sendline( "" ) |
| 817 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 818 | self.handle.sendline( "onos-service " + str( nodeIp ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 819 | " stop" ) |
| 820 | i = self.handle.expect( [ |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 821 | "stop/waiting", |
| 822 | "Unknown\sinstance", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 823 | pexpect.TIMEOUT ], timeout=60 ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 824 | |
| 825 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 826 | main.log.info( "ONOS service stopped" ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 827 | return main.TRUE |
| 828 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 829 | main.log.info( "Unknown ONOS instance specified: " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 830 | str( nodeIp ) ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 831 | return main.FALSE |
| 832 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 833 | main.log.error( "ONOS service failed to stop" ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 834 | return main.FALSE |
| 835 | |
| 836 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 837 | main.log.error( self.name + ": EOF exception found" ) |
| 838 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 839 | main.cleanup() |
| 840 | main.exit() |
| 841 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 842 | main.log.info( self.name + " ::::::" ) |
| 843 | main.log.error( traceback.print_exc() ) |
| 844 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 845 | main.cleanup() |
| 846 | main.exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 847 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 848 | def onosUninstall( self, nodeIp="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 849 | """ |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 850 | Calls the command: 'onos-uninstall' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 851 | Uninstalls ONOS from the designated cell machine, stopping |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 852 | if needed |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 853 | """ |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 854 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 855 | self.handle.sendline( "" ) |
| 856 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 857 | self.handle.sendline( "onos-uninstall " + str( nodeIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 858 | self.handle.expect( "\$" ) |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 859 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 860 | main.log.info( "ONOS " + nodeIp + " was uninstalled" ) |
andrewonlab | 9dfd208 | 2014-11-13 17:44:03 -0500 | [diff] [blame] | 861 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 862 | # onos-uninstall command does not return any text |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 863 | return main.TRUE |
| 864 | |
| 865 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 866 | main.log.error( self.name + ": EOF exception found" ) |
| 867 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 868 | main.cleanup() |
| 869 | main.exit() |
| 870 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 871 | main.log.info( self.name + " ::::::" ) |
| 872 | main.log.error( traceback.print_exc() ) |
| 873 | main.log.info( self.name + " ::::::" ) |
andrewonlab | c8d4797 | 2014-10-09 16:52:36 -0400 | [diff] [blame] | 874 | main.cleanup() |
| 875 | main.exit() |
andrewonlab | 2b30bd3 | 2014-10-09 16:48:55 -0400 | [diff] [blame] | 876 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 877 | def onosDie( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 878 | """ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 879 | Issues the command 'onos-die <node-ip>' |
| 880 | This command calls onos-kill and also stops the node |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 881 | """ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 882 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 883 | self.handle.sendline( "" ) |
| 884 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 885 | cmdStr = "onos-kill " + str( nodeIp ) |
| 886 | self.handle.sendline( cmdStr ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 887 | i = self.handle.expect( [ |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 888 | "Killing\sONOS", |
| 889 | "ONOS\sprocess\sis\snot\srunning", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 890 | pexpect.TIMEOUT ], timeout=20 ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 891 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 892 | main.log.info( "ONOS instance " + str( nodeIp ) + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 893 | " was killed and stopped" ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 894 | return main.TRUE |
| 895 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 896 | main.log.info( "ONOS process was not running" ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 897 | return main.FALSE |
| 898 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 899 | main.log.error( self.name + ": EOF exception found" ) |
| 900 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 901 | main.cleanup() |
| 902 | main.exit() |
| 903 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 904 | main.log.info( self.name + " ::::::" ) |
| 905 | main.log.error( traceback.print_exc() ) |
| 906 | main.log.info( self.name + " ::::::" ) |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 907 | main.cleanup() |
| 908 | main.exit() |
| 909 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 910 | def onosKill( self, nodeIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 911 | """ |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 912 | Calls the command: 'onos-kill [<node-ip>]' |
| 913 | "Remotely, and unceremoniously kills the ONOS instance running on |
| 914 | the specified cell machine" - Tom V |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 915 | """ |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 916 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 917 | self.handle.sendline( "" ) |
| 918 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 919 | self.handle.sendline( "onos-kill " + str( nodeIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 920 | i = self.handle.expect( [ |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 921 | "\$", |
| 922 | "No\sroute\sto\shost", |
| 923 | "password:", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 924 | pexpect.TIMEOUT ], timeout=20 ) |
| 925 | |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 926 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 927 | main.log.info( |
| 928 | "ONOS instance " + str( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 929 | nodeIp ) + " was killed" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 930 | return main.TRUE |
| 931 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 932 | main.log.info( "No route to host" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 933 | return main.FALSE |
| 934 | elif i == 2: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 935 | main.log.info( |
| 936 | "Passwordless login for host: " + |
| 937 | str( nodeIp ) + |
| 938 | " not configured" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 939 | return main.FALSE |
| 940 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 941 | main.log.info( "ONOS instasnce was not killed" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 942 | return main.FALSE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 943 | |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 944 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 945 | main.log.error( self.name + ": EOF exception found" ) |
| 946 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 947 | main.cleanup() |
| 948 | main.exit() |
| 949 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 950 | main.log.info( self.name + " ::::::" ) |
| 951 | main.log.error( traceback.print_exc() ) |
| 952 | main.log.info( self.name + " ::::::" ) |
andrewonlab | e8e56fd | 2014-10-09 17:12:44 -0400 | [diff] [blame] | 953 | main.cleanup() |
| 954 | main.exit() |
| 955 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 956 | def onosRemoveRaftLogs( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 957 | """ |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 958 | Removes Raft / Copy cat files from ONOS to ensure |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 959 | a cleaner environment. |
| 960 | |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 961 | Description: |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 962 | Stops all ONOS defined in the cell, |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 963 | wipes the raft / copycat log files |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 964 | """ |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 965 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 966 | self.handle.sendline( "" ) |
| 967 | self.handle.expect( "\$" ) |
| 968 | self.handle.sendline( "onos-remove-raft-logs" ) |
| 969 | # Sometimes this command hangs |
| 970 | i = self.handle.expect( [ "\$", pexpect.TIMEOUT ], |
| 971 | timeout=120 ) |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 972 | if i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 973 | i = self.handle.expect( [ "\$", pexpect.TIMEOUT ], |
| 974 | timeout=120 ) |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 975 | if i == 1: |
| 976 | return main.FALSE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 977 | self.handle.sendline( "" ) |
| 978 | self.handle.expect( "\$" ) |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 979 | return main.TRUE |
| 980 | |
| 981 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 982 | main.log.error( self.name + ": EOF exception found" ) |
| 983 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 984 | main.cleanup() |
| 985 | main.exit() |
| 986 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 987 | main.log.info( self.name + " ::::::" ) |
| 988 | main.log.error( traceback.print_exc() ) |
| 989 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 19fbdca | 2014-11-14 12:55:59 -0500 | [diff] [blame] | 990 | main.cleanup() |
| 991 | main.exit() |
Jon Hall | fcc8862 | 2014-11-25 13:09:54 -0500 | [diff] [blame] | 992 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 993 | def onosStartNetwork( self, mntopo ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 994 | """ |
| 995 | Calls the command 'onos-start-network [ <mininet-topo> ] |
| 996 | "remotely starts the specified topology on the cell's |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 997 | mininet machine against all controllers configured in the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 998 | cell." |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 999 | * Specify mininet topology file name for mntopo |
| 1000 | * Topo files should be placed at: |
| 1001 | ~/<your-onos-directory>/tools/test/topos |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1002 | |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1003 | NOTE: This function will take you to the mininet prompt |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1004 | """ |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1005 | try: |
| 1006 | if not mntopo: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1007 | main.log.error( "You must specify a topo file to execute" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1008 | return main.FALSE |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1009 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1010 | mntopo = str( mntopo ) |
| 1011 | self.handle.sendline( "" ) |
| 1012 | self.handle.expect( "\$" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1013 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1014 | self.handle.sendline( "onos-start-network " + mntopo ) |
| 1015 | self.handle.expect( "mininet>" ) |
| 1016 | main.log.info( "Network started, entered mininet prompt" ) |
| 1017 | |
| 1018 | # TODO: Think about whether return is necessary or not |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1019 | |
| 1020 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1021 | main.log.error( self.name + ": EOF exception found" ) |
| 1022 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1023 | main.cleanup() |
| 1024 | main.exit() |
| 1025 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1026 | main.log.info( self.name + " ::::::" ) |
| 1027 | main.log.error( traceback.print_exc() ) |
| 1028 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 9428209 | 2014-10-10 13:00:11 -0400 | [diff] [blame] | 1029 | main.cleanup() |
| 1030 | main.exit() |
| 1031 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1032 | def isup( self, node="" ): |
| 1033 | """ |
| 1034 | Run's onos-wait-for-start which only returns once ONOS is at run |
| 1035 | level 100( ready for use ) |
andrewonlab | 8d0d7d7 | 2014-10-09 16:33:15 -0400 | [diff] [blame] | 1036 | |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1037 | Returns: main.TRUE if ONOS is running and main.FALSE on timeout |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1038 | """ |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1039 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1040 | self.handle.sendline( "onos-wait-for-start " + node ) |
| 1041 | self.handle.expect( "onos-wait-for-start" ) |
| 1042 | # NOTE: this timeout is arbitrary" |
| 1043 | i = self.handle.expect( [ "\$", pexpect.TIMEOUT ], timeout=120 ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1044 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1045 | main.log.info( self.name + ": " + node + " is up" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1046 | return main.TRUE |
| 1047 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1048 | # NOTE: since this function won't return until ONOS is ready, |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1049 | # we will kill it on timeout |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1050 | main.log.error( "ONOS has not started yet" ) |
| 1051 | self.handle.send( "\x03" ) # Control-C |
| 1052 | self.handle.expect( "\$" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1053 | return main.FALSE |
| 1054 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1055 | main.log.error( self.name + ": EOF exception found" ) |
| 1056 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1057 | main.cleanup() |
| 1058 | main.exit() |
| 1059 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1060 | main.log.info( self.name + " ::::::" ) |
| 1061 | main.log.error( traceback.print_exc() ) |
| 1062 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 7993bfc | 2014-10-09 16:30:14 -0400 | [diff] [blame] | 1063 | main.cleanup() |
| 1064 | main.exit() |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 1065 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1066 | def pushTestIntentsShell( |
| 1067 | self, |
| 1068 | dpidSrc, |
| 1069 | dpidDst, |
| 1070 | numIntents, |
| 1071 | dirFile, |
| 1072 | onosIp, |
| 1073 | numMult="", |
| 1074 | appId="", |
| 1075 | report=True, |
| 1076 | options="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1077 | """ |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1078 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1079 | Use the linux prompt to push test intents to |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1080 | better parallelize the results than the CLI |
| 1081 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1082 | * dpidSrc: specify source dpid |
| 1083 | * dpidDst: specify destination dpid |
| 1084 | * numIntents: specify number of intents to push |
| 1085 | * dirFile: specify directory and file name to save |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1086 | results |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1087 | * onosIp: specify the IP of ONOS to install on |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1088 | NOTE: |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1089 | You must invoke this command at linux shell prompt |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1090 | """ |
| 1091 | try: |
| 1092 | # Create the string to sendline |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1093 | if options: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1094 | baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1095 | options + " " |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1096 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1097 | baseCmd = "onos " + str( onosIp ) + " push-test-intents " |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1098 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1099 | addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst ) |
| 1100 | if not numMult: |
| 1101 | addIntents = addDpid + " " + str( numIntents ) |
| 1102 | elif numMult: |
| 1103 | addIntents = addDpid + " " + str( numIntents ) + " " +\ |
| 1104 | str( numMult ) |
| 1105 | if appId: |
| 1106 | addApp = addIntents + " " + str( appId ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1107 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1108 | addApp = addIntents |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1109 | |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1110 | if report: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1111 | sendCmd = addApp + " > " + str( dirFile ) + " &" |
andrewonlab | aedc833 | 2014-12-04 12:43:03 -0500 | [diff] [blame] | 1112 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1113 | sendCmd = addApp + " &" |
| 1114 | main.log.info( "Send cmd: " + sendCmd ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1115 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1116 | self.handle.sendline( sendCmd ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1117 | |
| 1118 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1119 | main.log.error( self.name + ": EOF exception found" ) |
| 1120 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1121 | main.cleanup() |
| 1122 | main.exit() |
| 1123 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1124 | main.log.info( self.name + " ::::::" ) |
| 1125 | main.log.error( traceback.print_exc() ) |
| 1126 | main.log.info( self.name + " ::::::" ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1127 | main.cleanup() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1128 | main.exit() |
andrewonlab | 05e362f | 2014-10-10 00:40:57 -0400 | [diff] [blame] | 1129 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1130 | def getTopology( self, topologyOutput ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1131 | """ |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1132 | parses the onos:topology output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1133 | Returns: a topology dict populated by the key values found in |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1134 | the cli command. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1135 | """ |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1136 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1137 | # call the cli to get the topology summary |
| 1138 | # cmdstr = "onos:topology" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1139 | # cliResult = self.onosCli( ip, cmdstr ) |
| 1140 | # print "cli_result = ", cliResult |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1141 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1142 | # Parse the output |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1143 | topology = {} |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1144 | # for line in cliResult.split( "\n" ): |
| 1145 | for line in topologyOutput.splitlines(): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1146 | if not line.startswith( "time=" ): |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1147 | continue |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1148 | # else |
| 1149 | # print line |
| 1150 | for var in line.split( "," ): |
| 1151 | # print "'"+var+"'" |
| 1152 | # print "'"+var.strip()+"'" |
| 1153 | key, value = var.strip().split( "=" ) |
| 1154 | topology[ key ] = value |
| 1155 | # print "topology = ", topology |
| 1156 | # devices = topology.get( 'devices', False ) |
| 1157 | # print "devices = ", devices |
| 1158 | # links = topology.get( 'links', False ) |
| 1159 | # print "links = ", links |
| 1160 | # SCCs = topology.get( 'SCC(s)', False ) |
| 1161 | # print "SCCs = ", SCCs |
| 1162 | # paths = topology.get( 'paths', False ) |
| 1163 | # print "paths = ", paths |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1164 | |
| 1165 | return topology |
| 1166 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1167 | main.log.error( self.name + ": EOF exception found" ) |
| 1168 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1169 | main.cleanup() |
| 1170 | main.exit() |
| 1171 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1172 | main.log.info( self.name + " ::::::" ) |
| 1173 | main.log.error( traceback.print_exc() ) |
| 1174 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1175 | main.cleanup() |
| 1176 | main.exit() |
| 1177 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1178 | def checkStatus( |
| 1179 | self, |
| 1180 | topologyResult, |
| 1181 | numoswitch, |
| 1182 | numolink, |
| 1183 | logLevel="info" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1184 | """ |
| 1185 | Checks the number of swithes & links that ONOS sees against the |
| 1186 | supplied values. By default this will report to main.log, but the |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1187 | log level can be specifid. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1188 | |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1189 | Params: ip = ip used for the onos cli |
| 1190 | numoswitch = expected number of switches |
| 1191 | numlink = expected number of links |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1192 | logLevel = level to log to. |
| 1193 | Currently accepts 'info', 'warn' and 'report' |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1194 | |
| 1195 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1196 | logLevel can |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1197 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1198 | Returns: main.TRUE if the number of switchs and links are correct, |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1199 | main.FALSE if the numer of switches and links is incorrect, |
| 1200 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1201 | """ |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1202 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1203 | topology = self.getTopology( topologyResult ) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1204 | if topology == {}: |
| 1205 | return main.ERROR |
| 1206 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1207 | # Is the number of switches is what we expected |
| 1208 | devices = topology.get( 'devices', False ) |
| 1209 | links = topology.get( 'links', False ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1210 | if not devices or not links: |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1211 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1212 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1213 | # Is the number of links is what we expected |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1214 | linkCheck = ( int( links ) == int( numolink ) ) |
| 1215 | if ( switchCheck and linkCheck ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1216 | # We expected the correct numbers |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1217 | output = output + "The number of links and switches match "\ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1218 | + "what was expected" |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1219 | result = main.TRUE |
| 1220 | else: |
| 1221 | output = output + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1222 | "The number of links and switches does not match\ |
| 1223 | what was expected" |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1224 | result = main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1225 | output = output + "\n ONOS sees %i devices (%i expected)\ |
| 1226 | and %i links (%i expected)" %\ |
| 1227 | ( int( devices ), int( numoswitch ), |
| 1228 | int( links ), int( numolink ) ) |
| 1229 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1230 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1231 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1232 | main.log.warn( output ) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1233 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1234 | main.log.info( output ) |
| 1235 | return result |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1236 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1237 | main.log.error( self.name + ": EOF exception found" ) |
| 1238 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1239 | main.cleanup() |
| 1240 | main.exit() |
| 1241 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1242 | main.log.info( self.name + " ::::::" ) |
| 1243 | main.log.error( traceback.print_exc() ) |
| 1244 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 77f53ce | 2014-10-13 18:02:06 -0400 | [diff] [blame] | 1245 | main.cleanup() |
| 1246 | main.exit() |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1247 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1248 | def tsharkPcap( self, interface, dirFile ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1249 | """ |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1250 | Capture all packet activity and store in specified |
| 1251 | directory/file |
| 1252 | |
| 1253 | Required: |
| 1254 | * interface: interface to capture |
| 1255 | * dir: directory/filename to store pcap |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1256 | """ |
| 1257 | self.handle.sendline( "" ) |
| 1258 | self.handle.expect( "\$" ) |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1259 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1260 | self.handle.sendline( "tshark -i " + str( interface ) + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1261 | " -t e -w " + str( dirFile ) + " &" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1262 | self.handle.sendline( "\r" ) |
| 1263 | self.handle.expect( "Capturing on" ) |
| 1264 | self.handle.sendline( "\r" ) |
| 1265 | self.handle.expect( "\$" ) |
andrewonlab | 970399c | 2014-11-07 13:09:32 -0500 | [diff] [blame] | 1266 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1267 | main.log.info( "Tshark started capturing files on " + |
| 1268 | str( interface ) + " and saving to directory: " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1269 | str( dirFile ) ) |
Shreya Shah | a73aaad | 2014-10-27 18:03:09 -0400 | [diff] [blame] | 1270 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1271 | def runOnosTopoCfg( self, instanceName, jsonFile ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1272 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1273 | On ONOS bench, run this command: |
| 1274 | ./~/ONOS/tools/test/bin/onos-topo-cfg $OC1 filename |
| 1275 | which starts the rest and copies |
| 1276 | the json file to the onos instance |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1277 | """ |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 1278 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1279 | self.handle.sendline( "" ) |
| 1280 | self.handle.expect( "\$" ) |
| 1281 | self.handle.sendline( "cd ~/ONOS/tools/test/bin" ) |
| 1282 | self.handle.expect( "/bin$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1283 | cmd = "./onos-topo-cfg " + instanceName + " " + jsonFile |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 1284 | print "cmd = ", cmd |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1285 | self.handle.sendline( cmd ) |
| 1286 | self.handle.expect( "\$" ) |
| 1287 | self.handle.sendline( "cd ~" ) |
| 1288 | self.handle.expect( "\$" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 1289 | return main.TRUE |
| 1290 | except: |
| 1291 | return main.FALSE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1292 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1293 | def tsharkGrep( self, grep, directory, interface='eth0' ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1294 | """ |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1295 | Required: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1296 | * grep string |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1297 | * directory to store results |
| 1298 | Optional: |
| 1299 | * interface - default: eth0 |
| 1300 | Description: |
| 1301 | Uses tshark command to grep specific group of packets |
| 1302 | and stores the results to specified directory. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1303 | The timestamp is hardcoded to be in epoch |
| 1304 | """ |
| 1305 | self.handle.sendline( "" ) |
| 1306 | self.handle.expect( "\$" ) |
| 1307 | self.handle.sendline( "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1308 | self.handle.sendline( |
| 1309 | "tshark -i " + |
| 1310 | str( interface ) + |
| 1311 | " -t e | grep --line-buffered \"" + |
| 1312 | str(grep) + |
| 1313 | "\" >" + |
| 1314 | directory + |
| 1315 | " &" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1316 | self.handle.sendline( "\r" ) |
| 1317 | self.handle.expect( "Capturing on" ) |
| 1318 | self.handle.sendline( "\r" ) |
| 1319 | self.handle.expect( "\$" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1320 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1321 | def tsharkStop( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1322 | """ |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1323 | Removes wireshark files from /tmp and kills all tshark processes |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1324 | """ |
| 1325 | # Remove all pcap from previous captures |
| 1326 | self.execute( cmd="sudo rm /tmp/wireshark*" ) |
| 1327 | self.handle.sendline( "" ) |
| 1328 | self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\" |" + |
| 1329 | " grep -v grep | awk '{print $2}'`" ) |
| 1330 | self.handle.sendline( "" ) |
| 1331 | main.log.info( "Tshark stopped" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1332 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1333 | def ptpd( self, args ): |
| 1334 | """ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1335 | Initiate ptp with user-specified args. |
| 1336 | Required: |
| 1337 | * args: specify string of args after command |
| 1338 | 'sudo ptpd' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1339 | """ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1340 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1341 | self.handle.sendline( "sudo ptpd " + str( args ) ) |
| 1342 | i = self.handle.expect( [ |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1343 | "Multiple", |
| 1344 | "Error", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1345 | "\$" ] ) |
| 1346 | self.handle.expect( "\$" ) |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1347 | |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1348 | if i == 0: |
| 1349 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1350 | main.log.info( "ptpd returned an error: " + |
| 1351 | str( handle ) ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1352 | return handle |
| 1353 | elif i == 1: |
| 1354 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1355 | main.log.error( "ptpd returned an error: " + |
| 1356 | str( handle ) ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1357 | return handle |
| 1358 | else: |
| 1359 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1360 | |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1361 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1362 | main.log.error( self.name + ": EOF exception found" ) |
| 1363 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1364 | main.cleanup() |
| 1365 | main.exit() |
| 1366 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1367 | main.log.info( self.name + " ::::::" ) |
| 1368 | main.log.error( traceback.print_exc() ) |
| 1369 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 0c38a4a | 2014-10-28 18:35:35 -0400 | [diff] [blame] | 1370 | main.cleanup() |
| 1371 | main.exit() |
andrewonlab | ba44bcf | 2014-10-16 16:54:41 -0400 | [diff] [blame] | 1372 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1373 | def cpLogsToDir( self, logToCopy, |
| 1374 | destDir, copyFileName="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1375 | """ |
| 1376 | Copies logs to a desired directory. |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1377 | Current implementation of ONOS deletes its karaf |
| 1378 | logs on every iteration. For debugging purposes, |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1379 | you may want to use this function to capture |
| 1380 | certain karaf logs. ( or any other logs if needed ) |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1381 | Localtime will be attached to the filename |
| 1382 | |
| 1383 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1384 | * logToCopy: specify directory and log name to |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1385 | copy. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1386 | ex ) /opt/onos/log/karaf.log.1 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1387 | For copying multiple files, leave copyFileName |
| 1388 | empty and only specify destDir - |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1389 | ex ) /opt/onos/log/karaf* |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1390 | * destDir: specify directory to copy to. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1391 | ex ) /tmp/ |
| 1392 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1393 | * copyFileName: If you want to rename the log |
| 1394 | file, specify copyFileName. This will not work |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1395 | with multiple file copying |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1396 | """ |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1397 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1398 | localtime = time.strftime( '%x %X' ) |
| 1399 | localtime = localtime.replace( "/", "" ) |
| 1400 | localtime = localtime.replace( " ", "_" ) |
| 1401 | localtime = localtime.replace( ":", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1402 | if destDir[ -1: ] != "/": |
| 1403 | destDir += "/" |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1404 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1405 | if copyFileName: |
| 1406 | self.handle.sendline( |
| 1407 | "cp " + |
| 1408 | str( logToCopy ) + |
| 1409 | " " + |
| 1410 | str( destDir ) + |
| 1411 | str( copyFileName ) + |
| 1412 | localtime ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1413 | self.handle.expect( "cp" ) |
| 1414 | self.handle.expect( "\$" ) |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1415 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1416 | self.handle.sendline( "cp " + str( logToCopy ) + |
| 1417 | " " + str( destDir ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1418 | self.handle.expect( "cp" ) |
| 1419 | self.handle.expect( "\$" ) |
andrewonlab | 5d7a8f3 | 2014-11-10 13:07:56 -0500 | [diff] [blame] | 1420 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1421 | return self.handle.before |
| 1422 | |
| 1423 | except pexpect.EOF: |
| 1424 | main.log.error( "Copying files failed" ) |
| 1425 | main.log.error( self.name + ": EOF exception found" ) |
| 1426 | main.log.error( self.name + ": " + self.handle.before ) |
| 1427 | except: |
| 1428 | main.log.error( "Copying files failed" ) |
| 1429 | main.log.info( self.name + " ::::::" ) |
| 1430 | main.log.error( traceback.print_exc() ) |
| 1431 | main.log.info( self.name + " ::::::" ) |
| 1432 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1433 | def checkLogs( self, onosIp ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1434 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1435 | runs onos-check-logs on the given onos node |
| 1436 | returns the response |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1437 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1438 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1439 | cmd = "onos-check-logs " + str( onosIp ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1440 | self.handle.sendline( cmd ) |
| 1441 | self.handle.expect( cmd ) |
| 1442 | self.handle.expect( "\$" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1443 | response = self.handle.before |
| 1444 | return response |
| 1445 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1446 | main.log.error( "Lost ssh connection" ) |
| 1447 | main.log.error( self.name + ": EOF exception found" ) |
| 1448 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1449 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1450 | main.log.error( "Some error in check_logs:" ) |
| 1451 | main.log.info( self.name + " ::::::" ) |
| 1452 | main.log.error( traceback.print_exc() ) |
| 1453 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1454 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1455 | def onosStatus( self, node="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1456 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1457 | Calls onos command: 'onos-service [<node-ip>] status' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1458 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1459 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1460 | self.handle.sendline( "" ) |
| 1461 | self.handle.expect( "\$" ) |
| 1462 | self.handle.sendline( "onos-service " + str( node ) + |
| 1463 | " status" ) |
| 1464 | i = self.handle.expect( [ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1465 | "start/running", |
| 1466 | "stop/waiting", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1467 | pexpect.TIMEOUT ], timeout=120 ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1468 | |
| 1469 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1470 | main.log.info( "ONOS is running" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1471 | return main.TRUE |
| 1472 | elif i == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1473 | main.log.info( "ONOS is stopped" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1474 | return main.FALSE |
| 1475 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1476 | main.log.error( "ONOS service failed to check the status" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1477 | main.cleanup() |
| 1478 | main.exit() |
| 1479 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1480 | main.log.error( self.name + ": EOF exception found" ) |
| 1481 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1482 | main.cleanup() |
| 1483 | main.exit() |
| 1484 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1485 | main.log.info( self.name + " ::::::" ) |
| 1486 | main.log.error( traceback.print_exc() ) |
| 1487 | main.log.info( self.name + " ::::::" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1488 | main.cleanup() |
| 1489 | main.exit() |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame^] | 1490 | |
| 1491 | def setIpTables( self, ip, port='', action='add', packet_type='tcp', |
| 1492 | direction='INPUT', rule='DROP' ): |
| 1493 | ''' |
| 1494 | Description: |
| 1495 | add or remove iptables rule to DROP (default) packets from |
| 1496 | specific IP and PORT |
| 1497 | Usage: |
| 1498 | * specify action ('add' or 'remove') |
| 1499 | when removing, pass in the same argument as you would add. It will |
| 1500 | delete that specific rule. |
| 1501 | * specify the ip to block |
| 1502 | * specify the destination port to block (defaults to all ports) |
| 1503 | * optional packet type to block (default tcp) |
| 1504 | * optional iptables rule (default DROP) |
| 1505 | * optional direction to block (default 'INPUT') |
| 1506 | Returns: |
| 1507 | main.TRUE on success or |
| 1508 | main.FALSE if given invalid input or |
| 1509 | main.ERROR if there is an error in response from iptables |
| 1510 | WARNING: |
| 1511 | * This function uses root privilege iptables command which may result |
| 1512 | in unwanted network errors. USE WITH CAUTION |
| 1513 | ''' |
| 1514 | import time |
| 1515 | |
| 1516 | # NOTE********* |
| 1517 | # The strict checking methods of this driver function is intentional |
| 1518 | # to discourage any misuse or error of iptables, which can cause |
| 1519 | # severe network errors |
| 1520 | # ************* |
| 1521 | |
| 1522 | # NOTE: Sleep needed to give some time for rule to be added and |
| 1523 | # registered to the instance. If you are calling this function |
| 1524 | # multiple times this sleep will prevent any errors. |
| 1525 | # DO NOT REMOVE |
| 1526 | time.sleep( 5 ) |
| 1527 | try: |
| 1528 | # input validation |
| 1529 | action_type = action.lower() |
| 1530 | rule = rule.upper() |
| 1531 | direction = direction.upper() |
| 1532 | if action_type != 'add' and action_type != 'remove': |
| 1533 | main.log.error( "Invalid action type. Use 'add' or " |
| 1534 | "'remove' table rule" ) |
| 1535 | if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG': |
| 1536 | # NOTE Currently only supports rules DROP, ACCEPT, and LOG |
| 1537 | main.log.error( "Invalid rule. Valid rules are 'DROP' or " |
| 1538 | "'ACCEPT' or 'LOG' only." ) |
| 1539 | if direction != 'INPUT' and direction != 'OUTPUT': |
| 1540 | # NOTE currently only supports rules INPUT and OUPTUT |
| 1541 | main.log.error( "Invalid rule. Valid directions are" |
| 1542 | " 'OUTPUT' or 'INPUT'" ) |
| 1543 | return main.FALSE |
| 1544 | return main.FALSE |
| 1545 | return main.FALSE |
| 1546 | if action_type == 'add': |
| 1547 | # -A is the 'append' action of iptables |
| 1548 | actionFlag = '-A' |
| 1549 | elif action_type == 'remove': |
| 1550 | # -D is the 'delete' rule of iptables |
| 1551 | actionFlag = '-D' |
| 1552 | self.handle.sendline( "" ) |
| 1553 | self.handle.expect( "\$" ) |
| 1554 | cmd = "sudo iptables " + actionFlag + " " +\ |
| 1555 | direction +\ |
| 1556 | " -p " + str( packet_type ) +\ |
| 1557 | " -s " + str( ip ) |
| 1558 | if port: |
| 1559 | cmd += " --dport " + str( port ) |
| 1560 | cmd += " -j " + str( rule ) |
| 1561 | |
| 1562 | self.handle.sendline( cmd ) |
| 1563 | self.handle.expect( "\$" ) |
| 1564 | main.log.warn( self.handle.before ) |
| 1565 | |
| 1566 | info_string = "On " + str( self.name ) |
| 1567 | info_string += " " + str( action_type ) |
| 1568 | info_string += " iptable rule [ " |
| 1569 | info_string += " IP: " + str( ip ) |
| 1570 | info_string += " Port: " + str( port ) |
| 1571 | info_string += " Rule: " + str( rule ) |
| 1572 | info_string += " Direction: " + str( direction ) + " ]" |
| 1573 | main.log.info( info_string ) |
| 1574 | return main.TRUE |
| 1575 | except pexpect.TIMEOUT: |
| 1576 | main.log.exception( self.name + ": Timeout exception in " |
| 1577 | "setIpTables function" ) |
| 1578 | return main.ERROR |
| 1579 | except pexpect.EOF: |
| 1580 | main.log.error( self.name + ": EOF exception found" ) |
| 1581 | main.log.error( self.name + ": " + self.handle.before ) |
| 1582 | main.cleanup() |
| 1583 | main.exit() |
| 1584 | except: |
| 1585 | main.log.exception( "Unknown error:") |
| 1586 | main.cleanup() |
| 1587 | main.exit() |
| 1588 | |