Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2016 Open Networking Foundation (ONF) |
| 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
| 21 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 22 | # CASE1: Startup |
| 23 | # CASE2: Load vpls topology and configurations from demo script |
| 24 | # CASE3: Test CLI commands |
| 25 | |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 26 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 27 | class VPLSBasic: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 28 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 29 | def __init__( self ): |
| 30 | self.default = '' |
| 31 | |
| 32 | def CASE1( self, main ): |
| 33 | """ |
| 34 | CASE1 is to compile ONOS and push it to the test machines |
| 35 | |
| 36 | Startup sequence: |
| 37 | cell <name> |
| 38 | onos-verify-cell |
| 39 | NOTE: temporary - onos-remove-raft-logs |
| 40 | onos-uninstall |
| 41 | start mininet |
| 42 | git pull |
| 43 | mvn clean install |
| 44 | onos-package |
| 45 | onos-install -f |
| 46 | onos-wait-for-start |
| 47 | start cli sessions |
| 48 | start tcpdump |
| 49 | """ |
| 50 | import imp |
| 51 | import time |
| 52 | import json |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 53 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 54 | try: |
| 55 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 56 | main.testSetUp = ONOSSetup() |
| 57 | except ImportError: |
| 58 | main.log.error( "ONOSSetup not found. exiting the test" ) |
| 59 | main.exit() |
| 60 | main.testSetUp.envSetupDescription() |
| 61 | stepResult = main.FALSE |
| 62 | try: |
| 63 | # load some variables from the params file |
| 64 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 65 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 66 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 67 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 68 | ofPort = main.params[ 'CTRL' ][ 'port' ] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 69 | stepResult = main.testSetUp.envSetup() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 70 | except Exception as e: |
| 71 | main.testSetUp.envSetupException( e ) |
| 72 | main.testSetUp.evnSetupConclusion( stepResult ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 73 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 74 | main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster, |
| 75 | cellName=cellName ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 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 |
Jeremy Ronquillo | 3008aa3 | 2017-07-07 15:38:57 -0700 | [diff] [blame] | 88 | args = " --switch ovs,protocols=OpenFlow13" |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 89 | for ctrl in main.Cluster.active(): |
| 90 | args += " --controller=remote,ip=" + ctrl.ipAddress |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 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 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 97 | |
| 98 | main.step( "Activate apps defined in the params file" ) |
| 99 | # get data from the params |
| 100 | apps = main.params.get( 'apps' ) |
| 101 | if apps: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 102 | apps = apps.split( ',' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 103 | main.log.warn( apps ) |
| 104 | activateResult = True |
| 105 | for app in apps: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 106 | main.Cluster.active( 0 ).CLI.app( app, "Activate" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 107 | # TODO: check this worked |
| 108 | time.sleep( SLEEP ) # wait for apps to activate |
| 109 | for app in apps: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 110 | state = main.Cluster.active( 0 ).CLI.appStatus( app ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 111 | if state == "ACTIVE": |
Jon Hall | 937bc81 | 2017-01-31 16:44:10 -0800 | [diff] [blame] | 112 | activateResult = activateResult and True |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 113 | else: |
| 114 | main.log.error( "{} is in {} state".format( app, state ) ) |
Jon Hall | 937bc81 | 2017-01-31 16:44:10 -0800 | [diff] [blame] | 115 | activateResult = False |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 116 | utilities.assert_equals( expect=True, |
| 117 | actual=activateResult, |
| 118 | onpass="Successfully activated apps", |
| 119 | onfail="Failed to activate apps" ) |
| 120 | else: |
| 121 | main.log.warn( "No apps were specified to be loaded after startup" ) |
| 122 | |
| 123 | main.step( "Set ONOS configurations" ) |
| 124 | config = main.params.get( 'ONOS_Configuration' ) |
| 125 | if config: |
| 126 | main.log.debug( config ) |
| 127 | checkResult = main.TRUE |
| 128 | for component in config: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 129 | for setting in config[ component ]: |
| 130 | value = config[ component ][ setting ] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 131 | check = main.Cluster.active( 0 ).CLI.setCfg( component, setting, value ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 132 | main.log.info( "Value was changed? {}".format( main.TRUE == check ) ) |
| 133 | checkResult = check and checkResult |
| 134 | utilities.assert_equals( expect=main.TRUE, |
| 135 | actual=checkResult, |
| 136 | onpass="Successfully set config", |
| 137 | onfail="Failed to set config" ) |
| 138 | else: |
| 139 | main.log.warn( "No configurations were specified to be changed after startup" ) |
| 140 | |
| 141 | main.step( "App Ids check" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 142 | appCheck = main.Cluster.command( "appToIDCheck", returnBool=True ) |
| 143 | if appCheck != True: |
| 144 | main.log.warn( main.Cluster.active( 0 ).CLI.apps() ) |
| 145 | main.log.warn( main.Cluster.active( 0 ).CLI.appIDs() ) |
| 146 | utilities.assert_equals( expect=True, actual=appCheck, |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 147 | onpass="App Ids seem to be correct", |
| 148 | onfail="Something is wrong with app Ids" ) |
| 149 | |
| 150 | def CASE2( self, main ): |
| 151 | """ |
| 152 | Load and test vpls configurations from json configuration file |
| 153 | """ |
| 154 | import os.path |
| 155 | from tests.USECASE.VPLS.dependencies import vpls |
| 156 | |
Jeremy Ronquillo | 3008aa3 | 2017-07-07 15:38:57 -0700 | [diff] [blame] | 157 | main.vpls = vpls |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 158 | pprint = main.Cluster.active( 0 ).REST.pprint |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 159 | hosts = int( main.params[ 'vpls' ][ 'hosts' ] ) |
| 160 | SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 161 | |
| 162 | main.step( "Discover hosts using pings" ) |
| 163 | for i in range( 1, hosts + 1 ): |
| 164 | src = "h" + str( i ) |
| 165 | for j in range( 1, hosts + 1 ): |
| 166 | if j == i: |
| 167 | continue |
| 168 | dst = "h" + str( j ) |
| 169 | pingResult = main.Mininet1.pingHost( SRC=src, TARGET=dst ) |
| 170 | |
| 171 | main.step( "Load VPLS configurations" ) |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 172 | fileName = main.params[ 'DEPENDENCY' ][ 'topology' ] |
| 173 | app = main.params[ 'vpls' ][ 'name' ] |
Jeremy Ronquillo | 3008aa3 | 2017-07-07 15:38:57 -0700 | [diff] [blame] | 174 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 175 | loadVPLSResult = main.ONOSbench.onosNetCfg( main.Cluster.active( 0 ).ipAddress, "", fileName ) |
Jeremy Ronquillo | 3008aa3 | 2017-07-07 15:38:57 -0700 | [diff] [blame] | 176 | utilities.assert_equals( expect=main.TRUE, |
| 177 | actual=loadVPLSResult, |
| 178 | onpass="Loaded vpls configuration.", |
| 179 | onfail="Failed to load vpls configuration." ) |
| 180 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 181 | # Time for netcfg to load data |
| 182 | time.sleep( SLEEP ) |
| 183 | # 'Master' copy of test configuration |
Jeremy Ronquillo | 3008aa3 | 2017-07-07 15:38:57 -0700 | [diff] [blame] | 184 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 185 | try: |
| 186 | with open( os.path.expanduser( fileName ) ) as dataFile: |
| 187 | originalCfg = json.load( dataFile ) |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 188 | main.vplsConfig = originalCfg[ 'apps' ].get( app ).get( 'vpls' ).get( 'vplsList' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 189 | except Exception as e: |
| 190 | main.log.error( "Error loading config file: {}".format( e ) ) |
| 191 | if main.vplsConfig: |
| 192 | result = True |
| 193 | else: |
| 194 | result = False |
| 195 | utilities.assert_equals( expect=True, |
| 196 | actual=result, |
| 197 | onpass="Loaded vpls configuration", |
| 198 | onfail="Failed to load vpls configuration" ) |
| 199 | |
| 200 | main.step( "Check interface configurations" ) |
| 201 | result = False |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 202 | getPorts = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg, |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 203 | retValue=False, |
| 204 | kwargs={"subjectClass":"ports"}, |
| 205 | sleep=SLEEP ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 206 | onosCfg = pprint( getPorts ) |
| 207 | sentCfg = pprint( originalCfg.get( "ports" ) ) |
| 208 | |
| 209 | if onosCfg == sentCfg: |
| 210 | main.log.info( "ONOS interfaces NetCfg matches what was sent" ) |
| 211 | result = True |
| 212 | else: |
| 213 | main.log.error( "ONOS interfaces NetCfg doesn't match what was sent" ) |
| 214 | main.log.debug( "ONOS config: {}".format( onosCfg ) ) |
| 215 | main.log.debug( "Sent config: {}".format( sentCfg ) ) |
| 216 | utilities.assert_equals( expect=True, |
| 217 | actual=result, |
| 218 | onpass="Net Cfg added for interfaces", |
| 219 | onfail="Net Cfg not added for interfaces" ) |
| 220 | |
| 221 | # Run a bunch of checks to verify functionality based on configs |
| 222 | vpls.verify( main ) |
| 223 | |
Jeremy Ronquillo | 3008aa3 | 2017-07-07 15:38:57 -0700 | [diff] [blame] | 224 | main.step( "Loading vpls configuration in case any configuration was missed." ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 225 | loadVPLSResult = main.ONOSbench.onosNetCfg( main.Cluster.active( 0 ).ipAddress, "", fileName ) |
Jeremy Ronquillo | 3008aa3 | 2017-07-07 15:38:57 -0700 | [diff] [blame] | 226 | utilities.assert_equals( expect=main.TRUE, |
| 227 | actual=loadVPLSResult, |
| 228 | onpass="Loaded vpls configuration.", |
| 229 | onfail="Failed to load vpls configuration." ) |
| 230 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 231 | def CASE3( self, main ): |
| 232 | """ |
| 233 | Test VPLS cli commands |
| 234 | High level steps: |
| 235 | remove interface from a network |
| 236 | Clean configs |
| 237 | create vpls network |
| 238 | add interfaces to a network |
| 239 | add encap |
| 240 | change encap |
| 241 | remove encap |
| 242 | list? |
| 243 | """ |
| 244 | from tests.USECASE.VPLS.dependencies import vpls |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 245 | SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 246 | pprint = main.Cluster.active( 0 ).REST.pprint |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 247 | |
| 248 | main.step( "Remove an interface from a vpls network" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 249 | main.Cluster.active( 0 ).CLI.vplsRemIface( 'VPLS1', 'h1' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 250 | time.sleep( SLEEP ) |
| 251 | #update master config json |
| 252 | for network in main.vplsConfig: |
| 253 | if network.get( 'name' ) == 'VPLS1': |
| 254 | ifaces = network.get( 'interfaces' ) |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 255 | ifaces.remove( 'h1' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 256 | vpls.verify( main ) |
| 257 | |
| 258 | main.step( "Clean all vpls configurations" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 259 | main.Cluster.active( 0 ).CLI.vplsClean() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 260 | time.sleep( SLEEP ) |
| 261 | main.vplsConfig = [] |
| 262 | vpls.verify( main ) |
| 263 | |
| 264 | main.step( "Create a new vpls network" ) |
| 265 | name = "Network1" |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 266 | main.Cluster.active( 0 ).CLI.vplsCreate( name ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 267 | time.sleep( SLEEP ) |
| 268 | network1 = { 'name': name, 'interfaces': [], 'encapsulation': 'NONE' } |
| 269 | main.vplsConfig.append( network1 ) |
| 270 | vpls.verify( main ) |
| 271 | |
| 272 | main.step( "Add interfaces to the network" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 273 | main.Cluster.active( 0 ).CLI.vplsAddIface( name, "h1" ) |
| 274 | main.Cluster.active( 0 ).CLI.vplsAddIface( name, "h5" ) |
| 275 | main.Cluster.active( 0 ).CLI.vplsAddIface( name, "h4" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 276 | time.sleep( SLEEP ) |
| 277 | for network in main.vplsConfig: |
| 278 | if network.get( 'name' ) == name: |
| 279 | ifaces = network.get( 'interfaces' ) |
| 280 | ifaces.append( 'h1' ) |
| 281 | ifaces.append( 'h4' ) |
| 282 | ifaces.append( 'h5' ) |
| 283 | network[ 'interfaces' ] = ifaces |
| 284 | vpls.verify( main ) |
| 285 | |
| 286 | main.step( "Add MPLS encapsulation to a vpls network" ) |
| 287 | encapType = "MPLS" |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 288 | main.Cluster.active( 0 ).CLI.vplsSetEncap( name, encapType ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 289 | for network in main.vplsConfig: |
| 290 | if network.get( 'name' ) == name: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 291 | network[ 'encapsulation' ] = encapType |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 292 | time.sleep( SLEEP ) |
| 293 | vpls.verify( main ) |
| 294 | |
| 295 | main.step( "Change an encapsulation type" ) |
| 296 | encapType = "VLAN" |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 297 | main.Cluster.active( 0 ).CLI.vplsSetEncap( name, encapType ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 298 | for network in main.vplsConfig: |
| 299 | if network.get( 'name' ) == name: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 300 | network[ 'encapsulation' ] = encapType |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 301 | time.sleep( SLEEP ) |
| 302 | vpls.verify( main ) |
| 303 | |
| 304 | main.step( "Remove encapsulation" ) |
| 305 | encapType = "NONE" |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 306 | main.Cluster.active( 0 ).CLI.vplsSetEncap( name, encapType ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 307 | for network in main.vplsConfig: |
| 308 | if network.get( 'name' ) == name: |
Jon Hall | ed25823 | 2017-05-24 17:30:18 -0700 | [diff] [blame] | 309 | network[ 'encapsulation' ] = encapType |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 310 | time.sleep( SLEEP ) |
| 311 | vpls.verify( main ) |
| 312 | |
| 313 | main.step( "Clean all vpls configurations" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 314 | main.Cluster.active( 0 ).CLI.vplsClean() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 315 | time.sleep( SLEEP ) |
| 316 | main.vplsConfig = [] |
| 317 | vpls.verify( main ) |