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 | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 32 | main.diff = ( main.params[ 'ENV' ][ 'diffApps' ] ).split(";") |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 33 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame^] | 34 | main.path = os.path.dirname( main.testFile ) |
| 35 | main.dependencyPath = main.path + "/dependencies/" |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 36 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 37 | #main.json = ["4x4"] |
| 38 | main.json = ["2x2", "2x2"] |
| 39 | main.args = [" ", " "] |
| 40 | #main.args = [" --spine 4 --leaf 4 "] |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 41 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
| 42 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] ) |
| 43 | main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
| 44 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 45 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 46 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 47 | main.cellData = {} # for creating cell file |
| 48 | main.CLIs = [] |
| 49 | main.ONOSip = [] |
| 50 | |
| 51 | main.ONOSip = main.ONOSbench.getOnosIps() |
| 52 | |
| 53 | # Assigning ONOS cli handles to a list |
| 54 | for i in range( 1, main.maxNodes + 1 ): |
| 55 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 56 | |
| 57 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
| 58 | main.startUp = imp.load_source( wrapperFile1, |
| 59 | main.dependencyPath + |
| 60 | wrapperFile1 + |
| 61 | ".py" ) |
| 62 | |
| 63 | copyResult1 = main.ONOSbench.scp( main.Mininet1, |
| 64 | main.dependencyPath + |
| 65 | main.topology, |
| 66 | main.Mininet1.home, |
| 67 | direction="to" ) |
| 68 | if main.CLIs: |
| 69 | stepResult = main.TRUE |
| 70 | else: |
| 71 | main.log.error( "Did not properly created list of ONOS CLI handle" ) |
| 72 | stepResult = main.FALSE |
| 73 | |
| 74 | utilities.assert_equals( expect=main.TRUE, |
| 75 | actual=stepResult, |
| 76 | onpass="Successfully construct " + |
| 77 | "test variables ", |
| 78 | onfail="Failed to construct test variables" ) |
| 79 | |
| 80 | if gitPull == 'True': |
| 81 | main.step( "Building ONOS in " + gitBranch + " branch" ) |
| 82 | onosBuildResult = main.startUp.onosBuild( main, gitBranch ) |
| 83 | stepResult = onosBuildResult |
| 84 | utilities.assert_equals( expect=main.TRUE, |
| 85 | actual=stepResult, |
| 86 | onpass="Successfully compiled " + |
| 87 | "latest ONOS", |
| 88 | onfail="Failed to compile " + |
| 89 | "latest ONOS" ) |
| 90 | else: |
| 91 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 92 | "clean install" ) |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 93 | |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 94 | def CASE2( self, main ): |
| 95 | """ |
| 96 | - Set up cell |
| 97 | - Create cell file |
| 98 | - Set cell file |
| 99 | - Verify cell file |
| 100 | - Kill ONOS process |
| 101 | - Uninstall ONOS cluster |
| 102 | - Verify ONOS start up |
| 103 | - Install ONOS cluster |
| 104 | - Connect to cli |
| 105 | """ |
| 106 | |
| 107 | # main.scale[ 0 ] determines the current number of ONOS controller |
| 108 | main.numCtrls = int( main.scale[ 0 ] ) |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame^] | 109 | apps=main.apps |
| 110 | if main.diff: |
| 111 | apps = main.apps+","+main.diff.pop(0) |
| 112 | else: main.log.error( "App list is empty" ) |
| 113 | main.case( "Package and start ONOS using apps:" + apps) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 114 | |
| 115 | #kill off all onos processes |
| 116 | main.log.info( "Safety check, killing all ONOS processes" + |
| 117 | " before initiating environment setup" ) |
| 118 | |
| 119 | for i in range( main.maxNodes ): |
| 120 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 121 | |
| 122 | print "NODE COUNT = ", main.numCtrls |
| 123 | |
| 124 | tempOnosIp = [] |
| 125 | for i in range( main.numCtrls ): |
| 126 | tempOnosIp.append( main.ONOSip[i] ) |
Jon Hall | 5c526d1 | 2016-03-08 08:54:46 -0800 | [diff] [blame] | 127 | onosUser = main.params[ 'ENV' ][ 'cellUser' ] |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame^] | 128 | main.step("Creating cell file") |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 129 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 130 | "temp", |
| 131 | main.Mininet1.ip_address, |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 132 | apps, |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame^] | 133 | tempOnosIp, |
| 134 | onosUser ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 135 | |
| 136 | main.step( "Apply cell to environment" ) |
| 137 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 138 | verifyResult = main.ONOSbench.verifyCell() |
| 139 | stepResult = cellResult and verifyResult |
| 140 | utilities.assert_equals( expect=main.TRUE, |
| 141 | actual=stepResult, |
| 142 | onpass="Successfully applied cell to " + \ |
| 143 | "environment", |
| 144 | onfail="Failed to apply cell to environment " ) |
| 145 | |
| 146 | main.step( "Creating ONOS package" ) |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame^] | 147 | main.jsonFile=main.json.pop(0) |
| 148 | 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] | 149 | packageResult = main.ONOSbench.onosPackage() |
| 150 | stepResult = packageResult |
| 151 | utilities.assert_equals( expect=main.TRUE, |
| 152 | actual=stepResult, |
| 153 | onpass="Successfully created ONOS package", |
| 154 | onfail="Failed to create ONOS package" ) |
| 155 | |
| 156 | time.sleep( main.startUpSleep ) |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 157 | |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 158 | main.step( "Installing ONOS package" ) |
| 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 |
| 188 | utilities.assert_equals( expect=main.TRUE, |
| 189 | actual=stepResult, |
| 190 | onpass="ONOS service is ready", |
| 191 | onfail="ONOS service did not start properly" ) |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 192 | time.sleep( 2*main.startUpSleep ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 193 | |
| 194 | def CASE9( self, main ): |
| 195 | ''' |
| 196 | Report errors/warnings/exceptions |
| 197 | ''' |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame^] | 198 | main.case( "Logging test for " + main.jsonFile ) |
| 199 | if len(main.json) > 0 : |
| 200 | main.ONOSbench.cpLogsToDir("/opt/onos/log/karaf.log",main.logdir, |
| 201 | copyFileName="karaf.log."+main.jsonFile+str(len(main.json))) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 202 | #main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 203 | # [ "INFO" ], |
| 204 | # "a" ) |
| 205 | #main.log.info("Error report: \n" ) |
| 206 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 207 | [ "INFO", |
| 208 | "FOLLOWER", |
| 209 | "WARN", |
| 210 | "flow", |
| 211 | "ERROR", |
| 212 | "Except" ], |
| 213 | "s" ) |
| 214 | |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 215 | def CASE11( self, main ): |
| 216 | """ |
| 217 | Start mininet |
| 218 | """ |
Flavio Castro | 7b4d726 | 2016-04-19 11:59:02 -0700 | [diff] [blame^] | 219 | main.case( "Start Leaf-Spine "+main.jsonFile+" Mininet Topology" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 220 | main.log.report( "Start Mininet topology" ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 221 | |
| 222 | main.step( "Starting Mininet Topology" ) |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 223 | args,topo=" "," " |
| 224 | #if main.topology: |
| 225 | # topo = main.topology.pop(0) |
| 226 | #else: main.log.error( "Topo list is empty" ) |
| 227 | if main.args: |
| 228 | args = "--onos 1 " + main.args.pop(0) |
| 229 | else: main.log.error( "Argument list is empty" ) |
| 230 | |
| 231 | topoResult = main.Mininet1.startNet( topoFile= main.dependencyPath + main.topology, args=args ) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 232 | stepResult = topoResult |
| 233 | utilities.assert_equals( expect=main.TRUE, |
| 234 | actual=stepResult, |
| 235 | onpass="Successfully loaded topology", |
| 236 | onfail="Failed to load topology" ) |
| 237 | # Exit if topology did not load properly |
| 238 | if not topoResult: |
| 239 | main.cleanup() |
| 240 | main.exit() |
| 241 | main.step("Waiting for switch initialization and configuration") |
Flavio Castro | 4cd37c1 | 2016-03-28 07:39:16 -0700 | [diff] [blame] | 242 | time.sleep( 3*main.startUpSleep) |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 243 | pa = main.Mininet1.pingall() |
| 244 | utilities.assert_equals( expect=main.TRUE, actual=pa, |
| 245 | onpass="Full connectivity successfully tested", |
| 246 | onfail="Full connectivity failed" ) |
| 247 | # cleanup mininet |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 248 | main.ONOSbench.onosStop( main.ONOSip[0] ) |
| 249 | main.Mininet1.stopNet() |
Flavio Castro | cc38a54 | 2016-03-03 13:15:46 -0800 | [diff] [blame] | 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |