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 | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 39 | #main.json = ["4x4"] |
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 | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 42 | #main.args = [" --spine 4 --leaf 4 "] |
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 | |
| 117 | #kill off all onos processes |
| 118 | main.log.info( "Safety check, killing all ONOS processes" + |
| 119 | " before initiating environment setup" ) |
| 120 | |
| 121 | for i in range( main.maxNodes ): |
| 122 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 123 | |
| 124 | print "NODE COUNT = ", main.numCtrls |
| 125 | |
| 126 | tempOnosIp = [] |
| 127 | for i in range( main.numCtrls ): |
| 128 | tempOnosIp.append( main.ONOSip[i] ) |
Jon Hall | 5c526d1 | 2016-03-08 08:54:46 -0800 | [diff] [blame] | 129 | onosUser = main.params[ 'ENV' ][ 'cellUser' ] |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame] | 130 | main.step("Creating cell file") |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 131 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 132 | "temp", |
| 133 | main.Mininet1.ip_address, |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 134 | apps, |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame] | 135 | tempOnosIp, |
| 136 | onosUser ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 137 | |
| 138 | main.step( "Apply cell to environment" ) |
| 139 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 140 | verifyResult = main.ONOSbench.verifyCell() |
| 141 | stepResult = cellResult and verifyResult |
| 142 | utilities.assert_equals( expect=main.TRUE, |
| 143 | actual=stepResult, |
| 144 | onpass="Successfully applied cell to " + \ |
| 145 | "environment", |
| 146 | onfail="Failed to apply cell to environment " ) |
| 147 | |
| 148 | main.step( "Creating ONOS package" ) |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame] | 149 | main.jsonFile=main.json.pop(0) |
| 150 | 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] | 151 | packageResult = main.ONOSbench.onosPackage() |
Flavio Castro | 96eaa2e | 2016-04-23 16:24:47 -0700 | [diff] [blame] | 152 | #stepResult = packageResult |
| 153 | #utilities.assert_equals( expect=main.TRUE, |
| 154 | # actual=stepResult, |
| 155 | # onpass="Successfully created ONOS package", |
| 156 | # onfail="Failed to create ONOS package" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 157 | |
| 158 | time.sleep( main.startUpSleep ) |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 159 | |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 160 | main.step( "Installing ONOS package" ) |
| 161 | onosInstallResult = main.TRUE |
| 162 | for i in range( main.numCtrls ): |
| 163 | onosInstallResult = onosInstallResult and \ |
| 164 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
| 165 | stepResult = onosInstallResult |
| 166 | utilities.assert_equals( expect=main.TRUE, |
| 167 | actual=stepResult, |
| 168 | onpass="Successfully installed ONOS package", |
| 169 | onfail="Failed to install ONOS package" ) |
| 170 | |
| 171 | main.step( "Starting ONOS service" ) |
| 172 | stopResult = main.TRUE |
| 173 | startResult = main.TRUE |
| 174 | onosIsUp = main.TRUE |
| 175 | |
| 176 | for i in range( main.numCtrls ): |
| 177 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 178 | if onosIsUp == main.TRUE: |
| 179 | main.log.report( "ONOS instance is up and ready" ) |
| 180 | else: |
| 181 | main.log.report( "ONOS instance may not be up, stop and " + |
| 182 | "start ONOS again " ) |
| 183 | for i in range( main.numCtrls ): |
| 184 | stopResult = stopResult and \ |
| 185 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 186 | for i in range( main.numCtrls ): |
| 187 | startResult = startResult and \ |
| 188 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 189 | stepResult = onosIsUp and stopResult and startResult |
| 190 | utilities.assert_equals( expect=main.TRUE, |
| 191 | actual=stepResult, |
| 192 | onpass="ONOS service is ready", |
| 193 | onfail="ONOS service did not start properly" ) |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 194 | time.sleep( 2*main.startUpSleep ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 195 | |
| 196 | def CASE9( self, main ): |
| 197 | ''' |
| 198 | Report errors/warnings/exceptions |
| 199 | ''' |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame] | 200 | main.case( "Logging test for " + main.jsonFile ) |
Flavio Castro | 96eaa2e | 2016-04-23 16:24:47 -0700 | [diff] [blame] | 201 | #if len(main.json) > 0 : |
| 202 | main.ONOSbench.cpLogsToDir("/opt/onos/log/karaf.log",main.logdir, |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame] | 203 | copyFileName="karaf.log."+main.jsonFile+str(len(main.json))) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 204 | #main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 205 | # [ "INFO" ], |
| 206 | # "a" ) |
| 207 | #main.log.info("Error report: \n" ) |
| 208 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 209 | [ "INFO", |
| 210 | "FOLLOWER", |
| 211 | "WARN", |
| 212 | "flow", |
| 213 | "ERROR", |
| 214 | "Except" ], |
| 215 | "s" ) |
| 216 | |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 217 | def CASE11( self, main ): |
| 218 | """ |
| 219 | Start mininet |
| 220 | """ |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame] | 221 | main.case( "Start Leaf-Spine "+main.jsonFile+" Mininet Topology" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 222 | main.log.report( "Start Mininet topology" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 223 | |
| 224 | main.step( "Starting Mininet Topology" ) |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 225 | args,topo=" "," " |
| 226 | #if main.topology: |
| 227 | # topo = main.topology.pop(0) |
| 228 | #else: main.log.error( "Topo list is empty" ) |
| 229 | if main.args: |
| 230 | args = "--onos 1 " + main.args.pop(0) |
| 231 | else: main.log.error( "Argument list is empty" ) |
| 232 | |
| 233 | topoResult = main.Mininet1.startNet( topoFile= main.dependencyPath + main.topology, args=args ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 234 | stepResult = topoResult |
| 235 | utilities.assert_equals( expect=main.TRUE, |
| 236 | actual=stepResult, |
| 237 | onpass="Successfully loaded topology", |
| 238 | onfail="Failed to load topology" ) |
| 239 | # Exit if topology did not load properly |
| 240 | if not topoResult: |
| 241 | main.cleanup() |
| 242 | main.exit() |
| 243 | main.step("Waiting for switch initialization and configuration") |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 244 | time.sleep( 3*main.startUpSleep) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 245 | pa = main.Mininet1.pingall() |
| 246 | utilities.assert_equals( expect=main.TRUE, actual=pa, |
| 247 | onpass="Full connectivity successfully tested", |
| 248 | onfail="Full connectivity failed" ) |
| 249 | # cleanup mininet |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 250 | main.ONOSbench.onosStop( main.ONOSip[0] ) |
| 251 | main.Mininet1.stopNet() |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |