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