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