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 | |
| 25 | main.case( "Constructing test variables and building ONOS package" ) |
| 26 | main.step( "Constructing test variables" ) |
| 27 | stepResult = main.FALSE |
| 28 | |
| 29 | # Test variables |
| 30 | main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir ) |
| 31 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 32 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 33 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
| 34 | main.dependencyPath = main.testOnDirectory + \ |
| 35 | main.params[ 'DEPENDENCY' ][ 'path' ] |
| 36 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
| 37 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
| 38 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] ) |
| 39 | main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
| 40 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 41 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 42 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 43 | main.cellData = {} # for creating cell file |
| 44 | main.CLIs = [] |
| 45 | main.ONOSip = [] |
| 46 | |
| 47 | main.ONOSip = main.ONOSbench.getOnosIps() |
| 48 | |
| 49 | # Assigning ONOS cli handles to a list |
| 50 | for i in range( 1, main.maxNodes + 1 ): |
| 51 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 52 | |
| 53 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
| 54 | main.startUp = imp.load_source( wrapperFile1, |
| 55 | main.dependencyPath + |
| 56 | wrapperFile1 + |
| 57 | ".py" ) |
| 58 | |
| 59 | copyResult1 = main.ONOSbench.scp( main.Mininet1, |
| 60 | main.dependencyPath + |
| 61 | main.topology, |
| 62 | main.Mininet1.home, |
| 63 | direction="to" ) |
| 64 | if main.CLIs: |
| 65 | stepResult = main.TRUE |
| 66 | else: |
| 67 | main.log.error( "Did not properly created list of ONOS CLI handle" ) |
| 68 | stepResult = main.FALSE |
| 69 | |
| 70 | utilities.assert_equals( expect=main.TRUE, |
| 71 | actual=stepResult, |
| 72 | onpass="Successfully construct " + |
| 73 | "test variables ", |
| 74 | onfail="Failed to construct test variables" ) |
| 75 | |
| 76 | if gitPull == 'True': |
| 77 | main.step( "Building ONOS in " + gitBranch + " branch" ) |
| 78 | onosBuildResult = main.startUp.onosBuild( main, gitBranch ) |
| 79 | stepResult = onosBuildResult |
| 80 | utilities.assert_equals( expect=main.TRUE, |
| 81 | actual=stepResult, |
| 82 | onpass="Successfully compiled " + |
| 83 | "latest ONOS", |
| 84 | onfail="Failed to compile " + |
| 85 | "latest ONOS" ) |
| 86 | else: |
| 87 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 88 | "clean install" ) |
| 89 | |
| 90 | def CASE2( self, main ): |
| 91 | """ |
| 92 | - Set up cell |
| 93 | - Create cell file |
| 94 | - Set cell file |
| 95 | - Verify cell file |
| 96 | - Kill ONOS process |
| 97 | - Uninstall ONOS cluster |
| 98 | - Verify ONOS start up |
| 99 | - Install ONOS cluster |
| 100 | - Connect to cli |
| 101 | """ |
| 102 | |
| 103 | # main.scale[ 0 ] determines the current number of ONOS controller |
| 104 | main.numCtrls = int( main.scale[ 0 ] ) |
| 105 | |
| 106 | main.case( "Starting up " + str( main.numCtrls ) + |
| 107 | " node(s) ONOS cluster" ) |
| 108 | |
| 109 | #kill off all onos processes |
| 110 | main.log.info( "Safety check, killing all ONOS processes" + |
| 111 | " before initiating environment setup" ) |
| 112 | |
| 113 | for i in range( main.maxNodes ): |
| 114 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 115 | |
| 116 | print "NODE COUNT = ", main.numCtrls |
| 117 | |
| 118 | tempOnosIp = [] |
| 119 | for i in range( main.numCtrls ): |
| 120 | tempOnosIp.append( main.ONOSip[i] ) |
| 121 | |
Jon Hall | 5c526d1 | 2016-03-08 08:54:46 -0800 | [diff] [blame] | 122 | onosUser = main.params[ 'ENV' ][ 'cellUser' ] |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 123 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 124 | "temp", |
| 125 | main.Mininet1.ip_address, |
| 126 | main.apps, |
| 127 | tempOnosIp, |
Jon Hall | 5c526d1 | 2016-03-08 08:54:46 -0800 | [diff] [blame] | 128 | onosUser) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 129 | |
| 130 | main.step( "Apply cell to environment" ) |
| 131 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 132 | verifyResult = main.ONOSbench.verifyCell() |
| 133 | stepResult = cellResult and verifyResult |
| 134 | utilities.assert_equals( expect=main.TRUE, |
| 135 | actual=stepResult, |
| 136 | onpass="Successfully applied cell to " + \ |
| 137 | "environment", |
| 138 | onfail="Failed to apply cell to environment " ) |
| 139 | |
| 140 | main.step( "Creating ONOS package" ) |
| 141 | main.ONOSbench.handle.sendline( "cp ~/TestON/tests/USECASE_SegmentRouting/2x2.json ~/onos/tools/package/config/network-cfg.json") |
| 142 | packageResult = main.ONOSbench.onosPackage() |
| 143 | stepResult = packageResult |
| 144 | utilities.assert_equals( expect=main.TRUE, |
| 145 | actual=stepResult, |
| 146 | onpass="Successfully created ONOS package", |
| 147 | onfail="Failed to create ONOS package" ) |
| 148 | |
| 149 | time.sleep( main.startUpSleep ) |
| 150 | main.step( "Installing ONOS package" ) |
| 151 | onosInstallResult = main.TRUE |
| 152 | for i in range( main.numCtrls ): |
| 153 | onosInstallResult = onosInstallResult and \ |
| 154 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
| 155 | stepResult = onosInstallResult |
| 156 | utilities.assert_equals( expect=main.TRUE, |
| 157 | actual=stepResult, |
| 158 | onpass="Successfully installed ONOS package", |
| 159 | onfail="Failed to install ONOS package" ) |
| 160 | |
| 161 | main.step( "Starting ONOS service" ) |
| 162 | stopResult = main.TRUE |
| 163 | startResult = main.TRUE |
| 164 | onosIsUp = main.TRUE |
| 165 | |
| 166 | for i in range( main.numCtrls ): |
| 167 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 168 | if onosIsUp == main.TRUE: |
| 169 | main.log.report( "ONOS instance is up and ready" ) |
| 170 | else: |
| 171 | main.log.report( "ONOS instance may not be up, stop and " + |
| 172 | "start ONOS again " ) |
| 173 | for i in range( main.numCtrls ): |
| 174 | stopResult = stopResult and \ |
| 175 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 176 | for i in range( main.numCtrls ): |
| 177 | startResult = startResult and \ |
| 178 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 179 | stepResult = onosIsUp and stopResult and startResult |
| 180 | utilities.assert_equals( expect=main.TRUE, |
| 181 | actual=stepResult, |
| 182 | onpass="ONOS service is ready", |
| 183 | onfail="ONOS service did not start properly" ) |
| 184 | time.sleep( main.startUpSleep ) |
| 185 | |
| 186 | def CASE9( self, main ): |
| 187 | ''' |
| 188 | Report errors/warnings/exceptions |
| 189 | ''' |
| 190 | #main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 191 | # [ "INFO" ], |
| 192 | # "a" ) |
| 193 | #main.log.info("Error report: \n" ) |
| 194 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 195 | [ "INFO", |
| 196 | "FOLLOWER", |
| 197 | "WARN", |
| 198 | "flow", |
| 199 | "ERROR", |
| 200 | "Except" ], |
| 201 | "s" ) |
| 202 | |
| 203 | |
| 204 | def CASE11( self, main ): |
| 205 | """ |
| 206 | Start mininet |
| 207 | """ |
| 208 | main.log.report( "Start Mininet topology" ) |
| 209 | main.log.case( "Start Mininet topology" ) |
| 210 | |
| 211 | main.step( "Starting Mininet Topology" ) |
| 212 | topoResult = main.Mininet1.startNet( topoFile= main.dependencyPath + main.topology, args="--onos 1" ) |
| 213 | stepResult = topoResult |
| 214 | utilities.assert_equals( expect=main.TRUE, |
| 215 | actual=stepResult, |
| 216 | onpass="Successfully loaded topology", |
| 217 | onfail="Failed to load topology" ) |
| 218 | # Exit if topology did not load properly |
| 219 | if not topoResult: |
| 220 | main.cleanup() |
| 221 | main.exit() |
| 222 | main.step("Waiting for switch initialization and configuration") |
| 223 | time.sleep( main.startUpSleep ) |
| 224 | pa = main.Mininet1.pingall() |
| 225 | utilities.assert_equals( expect=main.TRUE, actual=pa, |
| 226 | onpass="Full connectivity successfully tested", |
| 227 | onfail="Full connectivity failed" ) |
| 228 | # cleanup mininet |
| 229 | main.CLIs[0].logout() |
| 230 | main.ONOSbench.onosStop( main.ONOSip[0] ) |
| 231 | main.Mininet1.stopNet() |
| 232 | main.Mininet1.disconnect() |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |