Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 1 | |
| 2 | # This test is to determine if the Segment Routing application is working properly |
| 3 | |
| 4 | class USECASE_SegmentRouting: |
| 5 | |
| 6 | def __init__( self ): |
| 7 | self.default = '' |
| 8 | |
| 9 | def CASE1( self, main ): |
| 10 | import time |
| 11 | import os |
| 12 | import imp |
| 13 | import re |
| 14 | |
| 15 | """ |
| 16 | - Construct tests variables |
| 17 | - GIT ( optional ) |
| 18 | - Checkout ONOS master branch |
| 19 | - Pull latest ONOS code |
| 20 | - Building ONOS ( optional ) |
| 21 | - Install ONOS package |
| 22 | - Build ONOS package |
| 23 | """ |
| 24 | |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 25 | main.case( "Constructing test variables and building ONOS" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 26 | main.step( "Constructing test variables" ) |
| 27 | stepResult = main.FALSE |
| 28 | |
| 29 | # Test variables |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 30 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 31 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
Flavio Castro | 96eaa2e | 2016-04-23 16:24:47 -0700 | [diff] [blame] | 32 | main.diff = [] |
| 33 | main.diff.extend(( main.params[ 'ENV' ][ 'diffApps' ] ).split(";")) |
| 34 | main.diff.extend(( main.params[ 'ENV' ][ 'diffApps' ] ).split(";")) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 35 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame] | 36 | main.path = os.path.dirname( main.testFile ) |
| 37 | main.dependencyPath = main.path + "/dependencies/" |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 38 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 39 | #main.json = ["0x1","0x1"] |
Flavio Castro | 96eaa2e | 2016-04-23 16:24:47 -0700 | [diff] [blame] | 40 | main.json = ["2x2", "2x2","4x4","4x4"] |
| 41 | main.args = [" ", " ", " --spine 4 --leaf 4 ", " --spine 4 --leaf 4 "] |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 42 | #main.args = [" --spine 0 --leaf 1 "," --spine 0 --leaf 1 "] |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 43 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
| 44 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] ) |
| 45 | main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
| 46 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 47 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 48 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 49 | main.cellData = {} # for creating cell file |
| 50 | main.CLIs = [] |
| 51 | main.ONOSip = [] |
| 52 | |
| 53 | main.ONOSip = main.ONOSbench.getOnosIps() |
| 54 | |
| 55 | # Assigning ONOS cli handles to a list |
| 56 | for i in range( 1, main.maxNodes + 1 ): |
| 57 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 58 | |
| 59 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
| 60 | main.startUp = imp.load_source( wrapperFile1, |
| 61 | main.dependencyPath + |
| 62 | wrapperFile1 + |
| 63 | ".py" ) |
| 64 | |
| 65 | copyResult1 = main.ONOSbench.scp( main.Mininet1, |
| 66 | main.dependencyPath + |
| 67 | main.topology, |
| 68 | main.Mininet1.home, |
| 69 | direction="to" ) |
| 70 | if main.CLIs: |
| 71 | stepResult = main.TRUE |
| 72 | else: |
| 73 | main.log.error( "Did not properly created list of ONOS CLI handle" ) |
| 74 | stepResult = main.FALSE |
| 75 | |
| 76 | utilities.assert_equals( expect=main.TRUE, |
| 77 | actual=stepResult, |
| 78 | onpass="Successfully construct " + |
| 79 | "test variables ", |
| 80 | onfail="Failed to construct test variables" ) |
| 81 | |
| 82 | if gitPull == 'True': |
| 83 | main.step( "Building ONOS in " + gitBranch + " branch" ) |
| 84 | onosBuildResult = main.startUp.onosBuild( main, gitBranch ) |
| 85 | stepResult = onosBuildResult |
| 86 | utilities.assert_equals( expect=main.TRUE, |
| 87 | actual=stepResult, |
| 88 | onpass="Successfully compiled " + |
| 89 | "latest ONOS", |
| 90 | onfail="Failed to compile " + |
| 91 | "latest ONOS" ) |
| 92 | else: |
| 93 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 94 | "clean install" ) |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 95 | |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 96 | def CASE2( self, main ): |
| 97 | """ |
| 98 | - Set up cell |
| 99 | - Create cell file |
| 100 | - Set cell file |
| 101 | - Verify cell file |
| 102 | - Kill ONOS process |
| 103 | - Uninstall ONOS cluster |
| 104 | - Verify ONOS start up |
| 105 | - Install ONOS cluster |
| 106 | - Connect to cli |
| 107 | """ |
| 108 | |
| 109 | # main.scale[ 0 ] determines the current number of ONOS controller |
| 110 | main.numCtrls = int( main.scale[ 0 ] ) |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame] | 111 | apps=main.apps |
| 112 | if main.diff: |
| 113 | apps = main.apps+","+main.diff.pop(0) |
| 114 | else: main.log.error( "App list is empty" ) |
| 115 | main.case( "Package and start ONOS using apps:" + apps) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 116 | |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 117 | print "NODE COUNT = ", main.numCtrls |
| 118 | |
| 119 | tempOnosIp = [] |
| 120 | for i in range( main.numCtrls ): |
| 121 | tempOnosIp.append( main.ONOSip[i] ) |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 122 | |
Jon Hall | 5c526d1 | 2016-03-08 08:54:46 -0800 | [diff] [blame] | 123 | onosUser = main.params[ 'ENV' ][ 'cellUser' ] |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 124 | main.step("Create and Apply cell file") |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 125 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 126 | "temp", |
| 127 | main.Mininet1.ip_address, |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 128 | apps, |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame] | 129 | tempOnosIp, |
| 130 | onosUser ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 131 | |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 132 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 133 | verifyResult = main.ONOSbench.verifyCell() |
| 134 | stepResult = cellResult and verifyResult |
| 135 | utilities.assert_equals( expect=main.TRUE, |
| 136 | actual=stepResult, |
| 137 | onpass="Successfully applied cell to " + \ |
| 138 | "environment", |
| 139 | onfail="Failed to apply cell to environment " ) |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 140 | #kill off all onos processes |
| 141 | main.log.info( "Safety check, killing all ONOS processes" + |
| 142 | " before initiating environment setup" ) |
| 143 | |
| 144 | for i in range( main.maxNodes ): |
| 145 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 146 | |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 147 | main.step( "Create and Install ONOS package" ) |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame] | 148 | main.jsonFile=main.json.pop(0) |
| 149 | main.ONOSbench.handle.sendline( "cp "+main.path+"/"+main.jsonFile+".json ~/onos/tools/package/config/network-cfg.json") |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 150 | packageResult = main.ONOSbench.onosPackage() |
Flavio Castro | 96eaa2e | 2016-04-23 16:24:47 -0700 | [diff] [blame] | 151 | #stepResult = packageResult |
| 152 | #utilities.assert_equals( expect=main.TRUE, |
| 153 | # actual=stepResult, |
| 154 | # onpass="Successfully created ONOS package", |
| 155 | # onfail="Failed to create ONOS package" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 156 | |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 157 | #time.sleep( main.startUpSleep ) |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 158 | |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 159 | onosInstallResult = main.TRUE |
| 160 | for i in range( main.numCtrls ): |
| 161 | onosInstallResult = onosInstallResult and \ |
| 162 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
| 163 | stepResult = onosInstallResult |
| 164 | utilities.assert_equals( expect=main.TRUE, |
| 165 | actual=stepResult, |
| 166 | onpass="Successfully installed ONOS package", |
| 167 | onfail="Failed to install ONOS package" ) |
| 168 | |
| 169 | main.step( "Starting ONOS service" ) |
| 170 | stopResult = main.TRUE |
| 171 | startResult = main.TRUE |
| 172 | onosIsUp = main.TRUE |
| 173 | |
| 174 | for i in range( main.numCtrls ): |
| 175 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 176 | if onosIsUp == main.TRUE: |
| 177 | main.log.report( "ONOS instance is up and ready" ) |
| 178 | else: |
| 179 | main.log.report( "ONOS instance may not be up, stop and " + |
| 180 | "start ONOS again " ) |
| 181 | for i in range( main.numCtrls ): |
| 182 | stopResult = stopResult and \ |
| 183 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 184 | for i in range( main.numCtrls ): |
| 185 | startResult = startResult and \ |
| 186 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 187 | stepResult = onosIsUp and stopResult and startResult |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 188 | |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 189 | utilities.assert_equals( expect=main.TRUE, |
| 190 | actual=stepResult, |
| 191 | onpass="ONOS service is ready", |
| 192 | onfail="ONOS service did not start properly" ) |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 193 | #time.sleep( 2*main.startUpSleep ) |
Flavio Castro | bdcfad6 | 2016-05-10 09:52:28 -0700 | [diff] [blame] | 194 | #main.ONOSbench.handle.sendline( "onos-secure-ssh") |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 195 | main.step( "Checking if ONOS CLI is ready" ) |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 196 | cellResult = main.CLIs[0].setCell( "temp" ) |
| 197 | |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 198 | cliResult = main.CLIs[0].startOnosCli( main.ONOSip[ 0 ], |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 199 | commandlineTimeout=60, onosStartTimeout=100 ) |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 200 | utilities.assert_equals( expect=main.TRUE, |
| 201 | actual=cliResult, |
| 202 | onpass="ONOS CLI is ready", |
| 203 | onfail="ONOS CLI is not ready" ) |
| 204 | for i in range( 10 ): |
| 205 | ready = True |
| 206 | output = main.CLIs[0].summary() |
| 207 | if not output: |
| 208 | ready = False |
| 209 | if ready: |
| 210 | break |
| 211 | time.sleep( 10 ) |
| 212 | utilities.assert_equals( expect=True, actual=ready, |
| 213 | onpass="ONOS summary command succeded", |
| 214 | onfail="ONOS summary command failed" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 215 | |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 216 | if not ready: |
| 217 | main.log.error( "ONOS startup failed!" ) |
| 218 | main.cleanup() |
| 219 | main.exit() |
| 220 | |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 221 | def CASE3( self, main ): |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 222 | """ |
| 223 | Start mininet |
| 224 | """ |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame] | 225 | main.case( "Start Leaf-Spine "+main.jsonFile+" Mininet Topology" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 226 | main.log.report( "Start Mininet topology" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 227 | |
| 228 | main.step( "Starting Mininet Topology" ) |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 229 | args,topo=" "," " |
| 230 | #if main.topology: |
| 231 | # topo = main.topology.pop(0) |
| 232 | #else: main.log.error( "Topo list is empty" ) |
| 233 | if main.args: |
| 234 | args = "--onos 1 " + main.args.pop(0) |
| 235 | else: main.log.error( "Argument list is empty" ) |
| 236 | |
| 237 | topoResult = main.Mininet1.startNet( topoFile= main.dependencyPath + main.topology, args=args ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 238 | stepResult = topoResult |
| 239 | utilities.assert_equals( expect=main.TRUE, |
| 240 | actual=stepResult, |
| 241 | onpass="Successfully loaded topology", |
| 242 | onfail="Failed to load topology" ) |
| 243 | # Exit if topology did not load properly |
| 244 | if not topoResult: |
| 245 | main.cleanup() |
| 246 | main.exit() |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 247 | #main.step("Waiting for switch initialization and configuration") |
| 248 | main.step(" Check whether the flow count is bigger than 80" ) |
| 249 | count = utilities.retry( main.CLIs[0].checkFlowCount, |
| 250 | main.FALSE, |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 251 | kwargs={'min':10}, |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 252 | attempts=10 ) |
| 253 | utilities.assertEquals( \ |
| 254 | expect=True, |
| 255 | actual=(count>0), |
| 256 | onpass="Flow count looks correct: "+str(count), |
| 257 | onfail="Flow count looks wrong: "+str(count) ) |
| 258 | |
| 259 | main.step( "Check whether all flow status are ADDED" ) |
| 260 | flowCheck = utilities.retry( main.CLIs[0].checkFlowsState, |
| 261 | main.FALSE, |
| 262 | kwargs={'isPENDING':False}, |
| 263 | attempts=10 ) |
| 264 | utilities.assertEquals( \ |
| 265 | expect=main.TRUE, |
| 266 | actual=flowCheck, |
| 267 | onpass="Flow status is correct!", |
| 268 | onfail="Flow status is wrong!" ) |
| 269 | main.ONOSbench.dumpFlows( main.ONOSip[0], |
Flavio Castro | 60a41d5 | 2016-05-16 11:20:09 -0700 | [diff] [blame] | 270 | main.logdir, "flowsBefore" + main.jsonFile) |
Flavio Castro | b771895 | 2016-05-18 08:53:41 -0700 | [diff] [blame] | 271 | main.ONOSbench.dumpGroups( main.ONOSip[0], |
| 272 | main.logdir, "groupsBefore" + main.jsonFile) |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 273 | #time.sleep( 3*main.startUpSleep) |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 274 | main.count=1 |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 275 | |
| 276 | def CASE4( self, main ): |
| 277 | main.case( "Check full connectivity" ) |
| 278 | main.log.report( "Check full connectivity" ) |
| 279 | |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 280 | main.step("Check full connectivity"+str(main.count)) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 281 | pa = main.Mininet1.pingall() |
| 282 | utilities.assert_equals( expect=main.TRUE, actual=pa, |
| 283 | onpass="Full connectivity successfully tested", |
| 284 | onfail="Full connectivity failed" ) |
| 285 | # cleanup mininet |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 286 | main.ONOSbench.dumpFlows( main.ONOSip[0], |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 287 | main.logdir, "flowsAfter" + str(main.count) + main.jsonFile) |
Flavio Castro | b771895 | 2016-05-18 08:53:41 -0700 | [diff] [blame] | 288 | main.ONOSbench.dumpGroups( main.ONOSip[0], |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 289 | main.logdir, "groupsAfter" + str(main.count) + main.jsonFile) |
Flavio Castro | 60a41d5 | 2016-05-16 11:20:09 -0700 | [diff] [blame] | 290 | |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 291 | def CASE10( self, main ): |
| 292 | ''' |
| 293 | Report errors/warnings/exceptions |
| 294 | ''' |
| 295 | main.case( "Logging test for " + main.jsonFile ) |
| 296 | #if len(main.json) > 0 : |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 297 | main.ONOSbench.onosStop( main.ONOSip[0] ) |
| 298 | main.Mininet1.stopNet() |
Flavio Castro | 4c0165e | 2016-05-24 17:53:50 -0700 | [diff] [blame^] | 299 | main.ONOSbench.cpLogsToDir("/opt/onos/log/karaf.log",main.logdir, |
| 300 | copyFileName="karaf.log."+main.jsonFile+str(len(main.json))) |
| 301 | #main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 302 | # [ "INFO" ], |
| 303 | # "a" ) |
| 304 | #main.log.info("Error report: \n" ) |
| 305 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 306 | [ "INFO", |
| 307 | "FOLLOWER", |
| 308 | "WARN", |
| 309 | "flow", |
| 310 | "ERROR", |
| 311 | "Except" ], |
| 312 | "s" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 313 | |
| 314 | |
| 315 | |