Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 1 | # CASE1: Startup |
| 2 | # CASE2: Load vpls topology and configurations from demo script |
| 3 | # CASE3: Test CLI commands |
| 4 | |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 5 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 6 | class VPLSBasic: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 7 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 8 | def __init__( self ): |
| 9 | self.default = '' |
| 10 | |
| 11 | def CASE1( self, main ): |
| 12 | """ |
| 13 | CASE1 is to compile ONOS and push it to the test machines |
| 14 | |
| 15 | Startup sequence: |
| 16 | cell <name> |
| 17 | onos-verify-cell |
| 18 | NOTE: temporary - onos-remove-raft-logs |
| 19 | onos-uninstall |
| 20 | start mininet |
| 21 | git pull |
| 22 | mvn clean install |
| 23 | onos-package |
| 24 | onos-install -f |
| 25 | onos-wait-for-start |
| 26 | start cli sessions |
| 27 | start tcpdump |
| 28 | """ |
| 29 | import imp |
| 30 | import time |
| 31 | import json |
| 32 | main.case( "Setting up test environment" ) |
| 33 | main.caseExplanation = "Setup the test environment including " +\ |
| 34 | "installing ONOS, starting Mininet and ONOS" +\ |
| 35 | "cli sessions." |
| 36 | |
| 37 | # load some variables from the params file |
| 38 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 39 | |
| 40 | main.numCtrls = int( main.params[ 'num_controllers' ] ) |
| 41 | |
| 42 | ofPort = main.params[ 'CTRL' ][ 'port' ] |
| 43 | |
| 44 | main.CLIs = [] |
| 45 | main.RESTs = [] |
| 46 | main.nodes = [] |
| 47 | ipList = [] |
| 48 | for i in range( 1, main.numCtrls + 1 ): |
| 49 | try: |
| 50 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 51 | main.RESTs.append( getattr( main, 'ONOSrest' + str( i ) ) ) |
| 52 | main.nodes.append( getattr( main, 'ONOS' + str( i ) ) ) |
| 53 | ipList.append( main.nodes[ -1 ].ip_address ) |
| 54 | except AttributeError: |
| 55 | break |
| 56 | |
| 57 | main.step( "Create cell file" ) |
| 58 | cellAppString = main.params[ 'ENV' ][ 'cellApps' ] |
| 59 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName, |
| 60 | main.Mininet1.ip_address, |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 61 | cellAppString, ipList, main.ONOScli1.karafUser ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 62 | main.step( "Applying cell variable to environment" ) |
| 63 | cellResult = main.ONOSbench.setCell( cellName ) |
| 64 | verifyResult = main.ONOSbench.verifyCell() |
| 65 | |
| 66 | main.log.info( "Uninstalling ONOS" ) |
| 67 | for node in main.nodes: |
| 68 | main.ONOSbench.onosUninstall( node.ip_address ) |
| 69 | |
| 70 | # Make sure ONOS is DEAD |
| 71 | main.log.info( "Killing any ONOS processes" ) |
| 72 | killResults = main.TRUE |
| 73 | for node in main.nodes: |
| 74 | killed = main.ONOSbench.onosKill( node.ip_address ) |
| 75 | killResults = killResults and killed |
| 76 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 77 | main.step( "Starting Mininet" ) |
| 78 | # scp topo file to mininet |
| 79 | # TODO: move to params? |
| 80 | topoName = "vpls" |
| 81 | topoFile = "vpls.py" |
| 82 | filePath = main.ONOSbench.home + "/tools/test/topos/" |
| 83 | main.ONOSbench.scp( main.Mininet1, |
| 84 | filePath + topoFile, |
| 85 | main.Mininet1.home, |
| 86 | direction="to" ) |
| 87 | topo = " --custom " + main.Mininet1.home + topoFile + " --topo " + topoName |
| 88 | args = " --switch ovs,protocols=OpenFlow13 --controller=remote" |
| 89 | for node in main.nodes: |
| 90 | args += ",ip=" + node.ip_address |
| 91 | mnCmd = "sudo mn" + topo + args |
| 92 | mnResult = main.Mininet1.startNet( mnCmd=mnCmd ) |
| 93 | utilities.assert_equals( expect=main.TRUE, actual=mnResult, |
| 94 | onpass="Mininet Started", |
| 95 | onfail="Error starting Mininet" ) |
| 96 | |
| 97 | main.ONOSbench.getVersion( report=True ) |
| 98 | |
| 99 | main.step( "Creating ONOS package" ) |
| 100 | packageResult = main.ONOSbench.buckBuild() |
| 101 | utilities.assert_equals( expect=main.TRUE, actual=packageResult, |
| 102 | onpass="ONOS package successful", |
| 103 | onfail="ONOS package failed" ) |
| 104 | |
| 105 | main.step( "Installing ONOS package" ) |
| 106 | onosInstallResult = main.TRUE |
| 107 | for node in main.nodes: |
| 108 | tmpResult = main.ONOSbench.onosInstall( options="-f", |
| 109 | node=node.ip_address ) |
| 110 | onosInstallResult = onosInstallResult and tmpResult |
| 111 | utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult, |
| 112 | onpass="ONOS install successful", |
| 113 | onfail="ONOS install failed" ) |
| 114 | |
You Wang | f5de25b | 2017-01-06 15:13:01 -0800 | [diff] [blame] | 115 | main.step( "Set up ONOS secure SSH" ) |
| 116 | secureSshResult = main.TRUE |
| 117 | for node in main.nodes: |
| 118 | secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=node.ip_address ) |
| 119 | utilities.assert_equals( expect=main.TRUE, actual=secureSshResult, |
| 120 | onpass="Test step PASS", |
| 121 | onfail="Test step FAIL" ) |
| 122 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 123 | main.step( "Checking if ONOS is up yet" ) |
| 124 | for i in range( 2 ): |
| 125 | onosIsupResult = main.TRUE |
| 126 | for node in main.nodes: |
| 127 | started = main.ONOSbench.isup( node.ip_address ) |
| 128 | if not started: |
| 129 | main.log.error( node.name + " hasn't started" ) |
| 130 | onosIsupResult = onosIsupResult and started |
| 131 | if onosIsupResult == main.TRUE: |
| 132 | break |
| 133 | utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult, |
| 134 | onpass="ONOS startup successful", |
| 135 | onfail="ONOS startup failed" ) |
| 136 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 137 | main.step( "Starting ONOS CLI sessions" ) |
| 138 | cliResults = main.TRUE |
| 139 | threads = [] |
| 140 | for i in range( main.numCtrls ): |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 141 | t = main.Thread( target=main.CLIs[ i ].startOnosCli, |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 142 | name="startOnosCli-" + str( i ), |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 143 | args=[ main.nodes[ i ].ip_address ] ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 144 | threads.append( t ) |
| 145 | t.start() |
| 146 | |
| 147 | for t in threads: |
| 148 | t.join() |
| 149 | cliResults = cliResults and t.result |
| 150 | utilities.assert_equals( expect=main.TRUE, actual=cliResults, |
| 151 | onpass="ONOS cli startup successful", |
| 152 | onfail="ONOS cli startup failed" ) |
| 153 | |
| 154 | main.activeNodes = [ i for i in range( 0, len( main.CLIs ) ) ] |
| 155 | |
| 156 | main.step( "Activate apps defined in the params file" ) |
| 157 | # get data from the params |
| 158 | apps = main.params.get( 'apps' ) |
| 159 | if apps: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 160 | apps = apps.split( ',' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 161 | main.log.warn( apps ) |
| 162 | activateResult = True |
| 163 | for app in apps: |
| 164 | main.CLIs[ 0 ].app( app, "Activate" ) |
| 165 | # TODO: check this worked |
| 166 | time.sleep( SLEEP ) # wait for apps to activate |
| 167 | for app in apps: |
| 168 | state = main.CLIs[ 0 ].appStatus( app ) |
| 169 | if state == "ACTIVE": |
Jon Hall | 937bc81 | 2017-01-31 16:44:10 -0800 | [diff] [blame] | 170 | activateResult = activateResult and True |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 171 | else: |
| 172 | main.log.error( "{} is in {} state".format( app, state ) ) |
Jon Hall | 937bc81 | 2017-01-31 16:44:10 -0800 | [diff] [blame] | 173 | activateResult = False |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 174 | utilities.assert_equals( expect=True, |
| 175 | actual=activateResult, |
| 176 | onpass="Successfully activated apps", |
| 177 | onfail="Failed to activate apps" ) |
| 178 | else: |
| 179 | main.log.warn( "No apps were specified to be loaded after startup" ) |
| 180 | |
| 181 | main.step( "Set ONOS configurations" ) |
| 182 | config = main.params.get( 'ONOS_Configuration' ) |
| 183 | if config: |
| 184 | main.log.debug( config ) |
| 185 | checkResult = main.TRUE |
| 186 | for component in config: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 187 | for setting in config[ component ]: |
| 188 | value = config[ component ][ setting ] |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 189 | check = main.CLIs[ 0 ].setCfg( component, setting, value ) |
| 190 | main.log.info( "Value was changed? {}".format( main.TRUE == check ) ) |
| 191 | checkResult = check and checkResult |
| 192 | utilities.assert_equals( expect=main.TRUE, |
| 193 | actual=checkResult, |
| 194 | onpass="Successfully set config", |
| 195 | onfail="Failed to set config" ) |
| 196 | else: |
| 197 | main.log.warn( "No configurations were specified to be changed after startup" ) |
| 198 | |
| 199 | main.step( "App Ids check" ) |
| 200 | appCheck = main.TRUE |
| 201 | threads = [] |
| 202 | for i in main.activeNodes: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 203 | t = main.Thread( target=main.CLIs[ i ].appToIDCheck, |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 204 | name="appToIDCheck-" + str( i ), |
| 205 | args=[] ) |
| 206 | threads.append( t ) |
| 207 | t.start() |
| 208 | |
| 209 | for t in threads: |
| 210 | t.join() |
| 211 | appCheck = appCheck and t.result |
| 212 | if appCheck != main.TRUE: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 213 | main.log.warn( main.CLIs[ 0 ].apps() ) |
| 214 | main.log.warn( main.CLIs[ 0 ].appIDs() ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 215 | utilities.assert_equals( expect=main.TRUE, actual=appCheck, |
| 216 | onpass="App Ids seem to be correct", |
| 217 | onfail="Something is wrong with app Ids" ) |
| 218 | |
| 219 | def CASE2( self, main ): |
| 220 | """ |
| 221 | Load and test vpls configurations from json configuration file |
| 222 | """ |
| 223 | import os.path |
| 224 | from tests.USECASE.VPLS.dependencies import vpls |
| 225 | |
| 226 | pprint = main.ONOSrest1.pprint |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 227 | hosts = int( main.params[ 'vpls' ][ 'hosts' ] ) |
| 228 | SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 229 | |
| 230 | main.step( "Discover hosts using pings" ) |
| 231 | for i in range( 1, hosts + 1 ): |
| 232 | src = "h" + str( i ) |
| 233 | for j in range( 1, hosts + 1 ): |
| 234 | if j == i: |
| 235 | continue |
| 236 | dst = "h" + str( j ) |
| 237 | pingResult = main.Mininet1.pingHost( SRC=src, TARGET=dst ) |
| 238 | |
| 239 | main.step( "Load VPLS configurations" ) |
| 240 | # TODO: load from params |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 241 | fileName = main.params[ 'DEPENDENCY' ][ 'topology' ] |
| 242 | app = main.params[ 'vpls' ][ 'name' ] |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 243 | # TODO make this a function? |
| 244 | main.ONOSbench.handle.sendline( "onos-netcfg $OC1 " + fileName ) |
| 245 | # Time for netcfg to load data |
| 246 | time.sleep( SLEEP ) |
| 247 | # 'Master' copy of test configuration |
| 248 | try: |
| 249 | with open( os.path.expanduser( fileName ) ) as dataFile: |
| 250 | originalCfg = json.load( dataFile ) |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 251 | main.vplsConfig = originalCfg[ 'apps' ].get( app ).get( 'vpls' ).get( 'vplsList' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 252 | except Exception as e: |
| 253 | main.log.error( "Error loading config file: {}".format( e ) ) |
| 254 | if main.vplsConfig: |
| 255 | result = True |
| 256 | else: |
| 257 | result = False |
| 258 | utilities.assert_equals( expect=True, |
| 259 | actual=result, |
| 260 | onpass="Loaded vpls configuration", |
| 261 | onfail="Failed to load vpls configuration" ) |
| 262 | |
| 263 | main.step( "Check interface configurations" ) |
| 264 | result = False |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 265 | getPorts = utilities.retry( f=main.ONOSrest1.getNetCfg, |
| 266 | retValue=False, |
| 267 | kwargs={"subjectClass":"ports"}, |
| 268 | sleep=SLEEP ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 269 | onosCfg = pprint( getPorts ) |
| 270 | sentCfg = pprint( originalCfg.get( "ports" ) ) |
| 271 | |
| 272 | if onosCfg == sentCfg: |
| 273 | main.log.info( "ONOS interfaces NetCfg matches what was sent" ) |
| 274 | result = True |
| 275 | else: |
| 276 | main.log.error( "ONOS interfaces NetCfg doesn't match what was sent" ) |
| 277 | main.log.debug( "ONOS config: {}".format( onosCfg ) ) |
| 278 | main.log.debug( "Sent config: {}".format( sentCfg ) ) |
| 279 | utilities.assert_equals( expect=True, |
| 280 | actual=result, |
| 281 | onpass="Net Cfg added for interfaces", |
| 282 | onfail="Net Cfg not added for interfaces" ) |
| 283 | |
| 284 | # Run a bunch of checks to verify functionality based on configs |
| 285 | vpls.verify( main ) |
| 286 | |
| 287 | def CASE3( self, main ): |
| 288 | """ |
| 289 | Test VPLS cli commands |
| 290 | High level steps: |
| 291 | remove interface from a network |
| 292 | Clean configs |
| 293 | create vpls network |
| 294 | add interfaces to a network |
| 295 | add encap |
| 296 | change encap |
| 297 | remove encap |
| 298 | list? |
| 299 | """ |
| 300 | from tests.USECASE.VPLS.dependencies import vpls |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 301 | SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 302 | pprint = main.ONOSrest1.pprint |
| 303 | |
| 304 | main.step( "Remove an interface from a vpls network" ) |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 305 | main.CLIs[ 0 ].vplsRemIface( 'VPLS1', 'h1' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 306 | time.sleep( SLEEP ) |
| 307 | #update master config json |
| 308 | for network in main.vplsConfig: |
| 309 | if network.get( 'name' ) == 'VPLS1': |
| 310 | ifaces = network.get( 'interfaces' ) |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 311 | ifaces.remove( 'h1' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 312 | vpls.verify( main ) |
| 313 | |
| 314 | main.step( "Clean all vpls configurations" ) |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 315 | main.CLIs[ 0 ].vplsClean() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 316 | time.sleep( SLEEP ) |
| 317 | main.vplsConfig = [] |
| 318 | vpls.verify( main ) |
| 319 | |
| 320 | main.step( "Create a new vpls network" ) |
| 321 | name = "Network1" |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 322 | main.CLIs[ 0 ].vplsCreate( name ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 323 | time.sleep( SLEEP ) |
| 324 | network1 = { 'name': name, 'interfaces': [], 'encapsulation': 'NONE' } |
| 325 | main.vplsConfig.append( network1 ) |
| 326 | vpls.verify( main ) |
| 327 | |
| 328 | main.step( "Add interfaces to the network" ) |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 329 | main.CLIs[ 0 ].vplsAddIface( name, "h1" ) |
| 330 | main.CLIs[ 0 ].vplsAddIface( name, "h5" ) |
| 331 | main.CLIs[ 0 ].vplsAddIface( name, "h4" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 332 | time.sleep( SLEEP ) |
| 333 | for network in main.vplsConfig: |
| 334 | if network.get( 'name' ) == name: |
| 335 | ifaces = network.get( 'interfaces' ) |
| 336 | ifaces.append( 'h1' ) |
| 337 | ifaces.append( 'h4' ) |
| 338 | ifaces.append( 'h5' ) |
| 339 | network[ 'interfaces' ] = ifaces |
| 340 | vpls.verify( main ) |
| 341 | |
| 342 | main.step( "Add MPLS encapsulation to a vpls network" ) |
| 343 | encapType = "MPLS" |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 344 | main.CLIs[ 0 ].vplsSetEncap( name, encapType ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 345 | for network in main.vplsConfig: |
| 346 | if network.get( 'name' ) == name: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 347 | network[ 'encapsulation' ] = encapType |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 348 | time.sleep( SLEEP ) |
| 349 | vpls.verify( main ) |
| 350 | |
| 351 | main.step( "Change an encapsulation type" ) |
| 352 | encapType = "VLAN" |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 353 | main.CLIs[ 0 ].vplsSetEncap( name, encapType ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 354 | for network in main.vplsConfig: |
| 355 | if network.get( 'name' ) == name: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 356 | network[ 'encapsulation' ] = encapType |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 357 | time.sleep( SLEEP ) |
| 358 | vpls.verify( main ) |
| 359 | |
| 360 | main.step( "Remove encapsulation" ) |
| 361 | encapType = "NONE" |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 362 | main.CLIs[ 0 ].vplsSetEncap( name, encapType ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 363 | for network in main.vplsConfig: |
| 364 | if network.get( 'name' ) == name: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 365 | network[ 'encapsulation' ] = encapType |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 366 | time.sleep( SLEEP ) |
| 367 | vpls.verify( main ) |
| 368 | |
| 369 | main.step( "Clean all vpls configurations" ) |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 370 | main.CLIs[ 0 ].vplsClean() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 371 | time.sleep( SLEEP ) |
| 372 | main.vplsConfig = [] |
| 373 | vpls.verify( main ) |