Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 1 | |
| 2 | # Testing the basic intent functionality of ONOS |
| 3 | |
| 4 | class FUNCnetCfg: |
| 5 | |
| 6 | def __init__( self ): |
| 7 | self.default = '' |
| 8 | |
| 9 | def CASE1( self, main ): |
| 10 | import imp |
| 11 | import re |
| 12 | |
| 13 | """ |
| 14 | - Construct tests variables |
| 15 | - GIT ( optional ) |
| 16 | - Checkout ONOS master branch |
| 17 | - Pull latest ONOS code |
| 18 | - Building ONOS ( optional ) |
| 19 | - Install ONOS package |
| 20 | - Build ONOS package |
| 21 | """ |
| 22 | |
| 23 | main.case( "Constructing test variables and building ONOS package" ) |
| 24 | main.step( "Constructing test variables" ) |
| 25 | main.caseExplanation = "This test case is mainly for loading " +\ |
| 26 | "from params file, and pull and build the " +\ |
| 27 | " latest ONOS package" |
| 28 | stepResult = main.FALSE |
| 29 | |
| 30 | # Test variables |
| 31 | try: |
| 32 | main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir ) |
| 33 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 34 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
| 35 | main.dependencyPath = main.testOnDirectory + \ |
| 36 | main.params[ 'DEPENDENCY' ][ 'path' ] |
| 37 | if main.ONOSbench.maxNodes: |
| 38 | main.maxNodes = int( main.ONOSbench.maxNodes ) |
| 39 | else: |
| 40 | main.maxNodes = 0 |
| 41 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 42 | wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ] |
| 43 | wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ] |
| 44 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 45 | main.gossipTime = int( main.params[ 'SLEEP'][ 'cfgGossip' ] ) |
| 46 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 47 | main.cellData = {} # for creating cell file |
| 48 | main.hostsData = {} |
| 49 | main.nodes = [] |
| 50 | main.ONOSip = [] |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 51 | main.retrytimes = main.params[ 'RETRY' ] |
| 52 | main.retrysleep = main.params[ 'RetrySleep' ] |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 53 | main.ONOSip = main.ONOSbench.getOnosIps() |
| 54 | |
| 55 | # Assigning ONOS cli handles to a list |
| 56 | try: |
| 57 | for i in range( 1, main.maxNodes + 1 ): |
| 58 | main.nodes.append( getattr( main, 'ONOSrest' + str( i ) ) ) |
| 59 | except AttributeError: |
| 60 | main.log.warn( "A " + str( main.maxNodes ) + " node cluster " + |
| 61 | "was defined in env variables, but only " + |
| 62 | str( len( main.nodes ) ) + |
| 63 | " nodes were defined in the .topo file. " + |
| 64 | "Using " + str( len( main.nodes ) ) + |
| 65 | " nodes for the test." ) |
| 66 | |
| 67 | main.numCtrls = len( main.nodes ) |
| 68 | |
| 69 | # -- INIT SECTION, SHOULD ONLY BE RUN ONCE -- # |
| 70 | main.startUp = imp.load_source( wrapperFile1, |
| 71 | main.dependencyPath + |
| 72 | wrapperFile1 + |
| 73 | ".py" ) |
| 74 | |
| 75 | main.netCfg = imp.load_source( wrapperFile2, |
| 76 | main.dependencyPath + |
| 77 | wrapperFile2 + |
| 78 | ".py" ) |
| 79 | |
| 80 | main.topo = imp.load_source( wrapperFile3, |
| 81 | main.dependencyPath + |
| 82 | wrapperFile3 + |
| 83 | ".py" ) |
| 84 | |
| 85 | if main.nodes: |
| 86 | stepResult = main.TRUE |
| 87 | else: |
| 88 | main.log.error( "Did not properly created list of ONOS handle" ) |
| 89 | stepResult = main.FALSE |
| 90 | except Exception as e: |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 91 | main.log.exception( e ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 92 | main.cleanup() |
| 93 | main.exit() |
| 94 | |
| 95 | utilities.assert_equals( expect=main.TRUE, |
| 96 | actual=stepResult, |
| 97 | onpass="Successfully construct " + |
| 98 | "test variables ", |
| 99 | onfail="Failed to construct test variables" ) |
| 100 | |
| 101 | if gitPull == 'True': |
| 102 | main.step( "Building ONOS in " + gitBranch + " branch" ) |
| 103 | onosBuildResult = main.startUp.onosBuild( main, gitBranch ) |
| 104 | stepResult = onosBuildResult |
| 105 | utilities.assert_equals( expect=main.TRUE, |
| 106 | actual=stepResult, |
| 107 | onpass="Successfully compiled " + |
| 108 | "latest ONOS", |
| 109 | onfail="Failed to compile " + |
| 110 | "latest ONOS" ) |
| 111 | else: |
| 112 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 113 | "clean install" ) |
| 114 | main.ONOSbench.getVersion( report=True ) |
| 115 | |
| 116 | def CASE2( self, main ): |
| 117 | """ |
| 118 | - Set up cell |
| 119 | - Create cell file |
| 120 | - Set cell file |
| 121 | - Verify cell file |
| 122 | - Kill ONOS process |
| 123 | - Uninstall ONOS cluster |
| 124 | - Verify ONOS start up |
| 125 | - Install ONOS cluster |
| 126 | - Connect to cli |
| 127 | """ |
| 128 | import time |
| 129 | main.case( "Starting up " + str( main.numCtrls ) + |
| 130 | " node(s) ONOS cluster" ) |
| 131 | main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\ |
| 132 | " node(s) ONOS cluster" |
| 133 | |
| 134 | # kill off all onos processes |
| 135 | main.log.info( "Safety check, killing all ONOS processes" + |
| 136 | " before initiating environment setup" ) |
| 137 | |
| 138 | for i in range( main.maxNodes ): |
| 139 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 140 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 141 | |
| 142 | tempOnosIp = [] |
| 143 | for i in range( main.numCtrls ): |
| 144 | tempOnosIp.append( main.ONOSip[i] ) |
| 145 | |
| 146 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 147 | "temp", main.Mininet1.ip_address, |
| 148 | main.apps, tempOnosIp ) |
| 149 | |
| 150 | main.step( "Apply cell to environment" ) |
| 151 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 152 | verifyResult = main.ONOSbench.verifyCell() |
| 153 | stepResult = cellResult and verifyResult |
| 154 | utilities.assert_equals( expect=main.TRUE, |
| 155 | actual=stepResult, |
| 156 | onpass="Successfully applied cell to environment", |
| 157 | onfail="Failed to apply cell to environment " ) |
| 158 | |
| 159 | main.step( "Creating ONOS package" ) |
Jon Hall | bd60ea0 | 2016-08-23 10:03:59 -0700 | [diff] [blame] | 160 | packageResult = main.ONOSbench.buckBuild() |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 161 | stepResult = packageResult |
| 162 | utilities.assert_equals( expect=main.TRUE, |
| 163 | actual=stepResult, |
| 164 | onpass="Successfully created ONOS package", |
| 165 | onfail="Failed to create ONOS package" ) |
| 166 | |
| 167 | time.sleep( main.startUpSleep ) |
| 168 | main.step( "Uninstalling ONOS package" ) |
| 169 | onosUninstallResult = main.TRUE |
| 170 | for ip in main.ONOSip: |
| 171 | onosUninstallResult = onosUninstallResult and \ |
| 172 | main.ONOSbench.onosUninstall( nodeIp=ip ) |
| 173 | stepResult = onosUninstallResult |
| 174 | utilities.assert_equals( expect=main.TRUE, |
| 175 | actual=stepResult, |
| 176 | onpass="Successfully uninstalled ONOS package", |
| 177 | onfail="Failed to uninstall ONOS package" ) |
| 178 | |
| 179 | time.sleep( main.startUpSleep ) |
| 180 | main.step( "Installing ONOS package" ) |
| 181 | onosInstallResult = main.TRUE |
| 182 | for i in range( main.numCtrls ): |
| 183 | onosInstallResult = onosInstallResult and \ |
| 184 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
| 185 | stepResult = onosInstallResult |
| 186 | utilities.assert_equals( expect=main.TRUE, |
| 187 | actual=stepResult, |
| 188 | onpass="Successfully installed ONOS package", |
| 189 | onfail="Failed to install ONOS package" ) |
| 190 | |
| 191 | time.sleep( main.startUpSleep ) |
| 192 | main.step( "Starting ONOS service" ) |
| 193 | stopResult = main.TRUE |
| 194 | startResult = main.TRUE |
| 195 | onosIsUp = main.TRUE |
| 196 | |
| 197 | for i in range( main.numCtrls ): |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 198 | isUp = main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 199 | onosIsUp = onosIsUp and isUp |
| 200 | if isUp == main.TRUE: |
| 201 | main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) ) |
| 202 | else: |
| 203 | main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) + |
| 204 | "start ONOS again " ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 205 | stopResult = stopResult and \ |
| 206 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 207 | startResult = startResult and \ |
| 208 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 209 | stepResult = onosIsUp and stopResult and startResult |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 210 | utilities.assert_equals( expect=main.TRUE, |
| 211 | actual=stepResult, |
| 212 | onpass="ONOS service is ready", |
| 213 | onfail="ONOS service did not start properly" ) |
| 214 | |
| 215 | def CASE8( self, main ): |
| 216 | """ |
| 217 | Compare Topo |
| 218 | """ |
| 219 | import json |
| 220 | |
| 221 | main.case( "Compare ONOS Topology view to Mininet topology" ) |
| 222 | main.caseExplanation = "Compare topology elements between Mininet" +\ |
| 223 | " and ONOS" |
| 224 | |
| 225 | main.step( "Gathering topology information" ) |
| 226 | # TODO: add a parameterized sleep here |
| 227 | devicesResults = main.TRUE |
| 228 | linksResults = main.TRUE |
| 229 | hostsResults = main.TRUE |
| 230 | devices = main.topo.getAllDevices( main ) |
| 231 | hosts = main.topo.getAllHosts( main ) |
| 232 | ports = main.topo.getAllPorts( main ) |
| 233 | links = main.topo.getAllLinks( main ) |
| 234 | clusters = main.topo.getAllClusters( main ) |
| 235 | |
| 236 | mnSwitches = main.Mininet1.getSwitches() |
| 237 | mnLinks = main.Mininet1.getLinks() |
| 238 | mnHosts = main.Mininet1.getHosts() |
| 239 | |
| 240 | main.step( "Comparing MN topology to ONOS topology" ) |
| 241 | for controller in range( main.numCtrls ): |
| 242 | controllerStr = str( controller + 1 ) |
| 243 | if devices[ controller ] and ports[ controller ] and\ |
| 244 | "Error" not in devices[ controller ] and\ |
| 245 | "Error" not in ports[ controller ]: |
| 246 | |
| 247 | currentDevicesResult = main.Mininet1.compareSwitches( |
| 248 | mnSwitches, |
| 249 | json.loads( devices[ controller ] ), |
| 250 | json.loads( ports[ controller ] ) ) |
| 251 | else: |
| 252 | currentDevicesResult = main.FALSE |
| 253 | utilities.assert_equals( expect=main.TRUE, |
| 254 | actual=currentDevicesResult, |
| 255 | onpass="ONOS" + controllerStr + |
| 256 | " Switches view is correct", |
| 257 | onfail="ONOS" + controllerStr + |
| 258 | " Switches view is incorrect" ) |
| 259 | |
| 260 | if links[ controller ] and "Error" not in links[ controller ]: |
| 261 | currentLinksResult = main.Mininet1.compareLinks( |
| 262 | mnSwitches, mnLinks, |
| 263 | json.loads( links[ controller ] ) ) |
| 264 | else: |
| 265 | currentLinksResult = main.FALSE |
| 266 | utilities.assert_equals( expect=main.TRUE, |
| 267 | actual=currentLinksResult, |
| 268 | onpass="ONOS" + controllerStr + |
| 269 | " links view is correct", |
| 270 | onfail="ONOS" + controllerStr + |
| 271 | " links view is incorrect" ) |
| 272 | |
| 273 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 274 | currentHostsResult = main.Mininet1.compareHosts( |
| 275 | mnHosts, |
| 276 | json.loads( hosts[ controller ] ) ) |
| 277 | else: |
| 278 | currentHostsResult = main.FALSE |
| 279 | utilities.assert_equals( expect=main.TRUE, |
| 280 | actual=currentHostsResult, |
| 281 | onpass="ONOS" + controllerStr + |
| 282 | " hosts exist in Mininet", |
| 283 | onfail="ONOS" + controllerStr + |
| 284 | " hosts don't match Mininet" ) |
| 285 | |
| 286 | def CASE9( self, main ): |
| 287 | ''' |
| 288 | Report errors/warnings/exceptions |
| 289 | ''' |
| 290 | main.log.info( "Error report: \n" ) |
| 291 | main.ONOSbench.logReport( |
| 292 | globalONOSip[0], |
| 293 | [ "INFO", "WARN", "ERROR" , "Except" ], |
| 294 | "s" ) |
| 295 | # main.ONOSbench.logReport( globalONOSip[1], [ "INFO" ], "d" ) |
| 296 | |
| 297 | def CASE10( self, main ): |
| 298 | """ |
| 299 | Start Mininet topology with OF 1.0 switches |
| 300 | """ |
| 301 | main.OFProtocol = "1.0" |
| 302 | main.log.report( "Start Mininet topology with OF 1.0 switches" ) |
| 303 | main.case( "Start Mininet topology with OF 1.0 switches" ) |
| 304 | main.caseExplanation = "Start mininet topology with OF 1.0 " +\ |
| 305 | "switches to test intents, exits out if " +\ |
| 306 | "topology did not start correctly" |
| 307 | |
| 308 | main.step( "Starting Mininet topology with OF 1.0 switches" ) |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 309 | args = "--controller none --switch ovs,protocols=OpenFlow10" |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 310 | switches = int( main.params['MININET']['switch'] ) |
| 311 | cmd = "mn --topo linear,{} {}".format( switches, args ) |
| 312 | topoResult = main.Mininet1.startNet( mnCmd = cmd ) |
| 313 | stepResult = topoResult |
| 314 | utilities.assert_equals( expect=main.TRUE, |
| 315 | actual=stepResult, |
| 316 | onpass="Successfully loaded topology", |
| 317 | onfail="Failed to load topology" ) |
| 318 | # Exit if topology did not load properly |
| 319 | if not topoResult: |
| 320 | main.cleanup() |
| 321 | main.exit() |
| 322 | |
| 323 | def CASE11( self, main ): |
| 324 | """ |
| 325 | Start Mininet topology with OF 1.3 switches |
| 326 | """ |
| 327 | import re |
| 328 | main.OFProtocol = "1.3" |
| 329 | main.log.report( "Start Mininet topology with OF 1.3 switches" ) |
| 330 | main.case( "Start Mininet topology with OF 1.3 switches" ) |
| 331 | main.caseExplanation = "Start mininet topology with OF 1.3 " +\ |
| 332 | "switches to test intents, exits out if " +\ |
| 333 | "topology did not start correctly" |
| 334 | |
| 335 | main.step( "Starting Mininet topology with OF 1.3 switches" ) |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 336 | args = "--controller none --switch ovs,protocols=OpenFlow13" |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 337 | switches = int( main.params[ 'MININET' ][ 'switch' ] ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 338 | cmd = "mn --topo linear,{} {}".format( switches, args ) |
| 339 | topoResult = main.Mininet1.startNet( mnCmd = cmd ) |
| 340 | stepResult = topoResult |
| 341 | utilities.assert_equals( expect=main.TRUE, |
| 342 | actual=stepResult, |
| 343 | onpass="Successfully loaded topology", |
| 344 | onfail="Failed to load topology" ) |
| 345 | # Exit if topology did not load properly |
| 346 | if not topoResult: |
| 347 | main.cleanup() |
| 348 | main.exit() |
| 349 | |
| 350 | tempONOSip = [] |
| 351 | for i in range( main.numCtrls ): |
| 352 | tempONOSip.append( main.ONOSip[ i ] ) |
| 353 | |
| 354 | swList = [ "s" + str( i ) for i in range( 1, switches + 1 ) ] |
| 355 | assignResult = main.Mininet1.assignSwController( sw=swList, |
| 356 | ip=tempONOSip, |
| 357 | port='6653' ) |
| 358 | if not assignResult: |
| 359 | main.cleanup() |
| 360 | main.exit() |
| 361 | |
| 362 | assignResult = main.TRUE |
| 363 | for sw in swList: |
| 364 | response = main.Mininet1.getSwController( "s" + str( i ) ) |
| 365 | main.log.info( "Response is " + str( response ) ) |
| 366 | for ip in tempONOSip: |
| 367 | if re.search( "tcp:" + ip, response ): |
| 368 | assignResult = assignResult and main.TRUE |
| 369 | else: |
| 370 | assignResult = assignResult and main.FALSE |
| 371 | stepResult = assignResult |
| 372 | utilities.assert_equals( expect=main.TRUE, |
| 373 | actual=stepResult, |
| 374 | onpass="Successfully assigned switches" + |
| 375 | "to controller", |
| 376 | onfail="Failed to assign switches to " + |
| 377 | "controller" ) |
| 378 | |
| 379 | def CASE14( self, main ): |
| 380 | """ |
| 381 | Stop mininet |
| 382 | """ |
| 383 | main.log.report( "Stop Mininet topology" ) |
| 384 | main.case( "Stop Mininet topology" ) |
| 385 | main.caseExplanation = "Stopping the current mininet topology " +\ |
| 386 | "to start up fresh" |
| 387 | |
| 388 | main.step( "Stopping Mininet Topology" ) |
| 389 | topoResult = main.Mininet1.stopNet( ) |
| 390 | stepResult = topoResult |
| 391 | utilities.assert_equals( expect=main.TRUE, |
| 392 | actual=stepResult, |
| 393 | onpass="Successfully stop mininet", |
| 394 | onfail="Failed to stop mininet" ) |
| 395 | # Exit if topology did not load properly |
| 396 | if not topoResult: |
| 397 | main.cleanup() |
| 398 | main.exit() |
| 399 | |
| 400 | def CASE20( self, main ): |
| 401 | """ |
| 402 | Add some device configurations and then check they are distributed |
| 403 | to all nodes |
| 404 | """ |
| 405 | main.case( "Add Network configurations to the cluster" ) |
| 406 | main.caseExplanation = "Add Network Configurations for devices" +\ |
| 407 | " not discovered yet. One device is allowed" +\ |
| 408 | ", the other disallowed." |
| 409 | pprint = main.nodes[0].pprint |
| 410 | |
| 411 | main.step( "Add Net Cfg for switch1" ) |
| 412 | s1Json = { "rackAddress": 1, |
| 413 | "name": "Switch1", |
| 414 | "owner": "Jimmy", |
| 415 | "allowed": True } |
| 416 | main.s1Json = s1Json |
| 417 | setS1Allow = main.ONOSrest1.setNetCfg( s1Json, |
| 418 | subjectClass="devices", |
| 419 | subjectKey="of:0000000000000001", |
| 420 | configKey="basic" ) |
| 421 | s1Result = False |
| 422 | if setS1Allow: |
| 423 | # Check what we set is what is in ONOS |
| 424 | getS1 = main.ONOSrest1.getNetCfg( subjectClass="devices", |
| 425 | subjectKey="of:0000000000000001", |
| 426 | configKey="basic" ) |
| 427 | onosCfg = pprint( getS1 ) |
| 428 | sentCfg = pprint( s1Json ) |
| 429 | if onosCfg == sentCfg: |
| 430 | s1Result = True |
| 431 | else: |
| 432 | main.log.error( "ONOS NetCfg doesn't match what was sent" ) |
| 433 | main.log.debug( "ONOS config: {}".format( onosCfg ) ) |
| 434 | main.log.debug( "Sent config: {}".format( sentCfg ) ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 435 | utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 436 | utilities.assert_equals( expect=True, |
| 437 | actual=s1Result, |
| 438 | onpass="Net Cfg added for device s1", |
| 439 | onfail="Net Cfg for device s1 not correctly set" ) |
| 440 | |
| 441 | main.step( "Add Net Cfg for switch3" ) |
| 442 | s3Json = { "rackAddress": 3, |
| 443 | "name": "Switch3", |
| 444 | "owner": "Jane", |
| 445 | "allowed": False } |
| 446 | main.s3Json = s3Json |
| 447 | setS3Disallow = main.ONOSrest1.setNetCfg( s3Json, |
| 448 | subjectClass="devices", |
| 449 | subjectKey="of:0000000000000003", |
| 450 | configKey="basic" ) |
| 451 | s3Result = False |
| 452 | if setS3Disallow: |
| 453 | # Check what we set is what is in ONOS |
| 454 | getS3 = main.ONOSrest1.getNetCfg( subjectClass="devices", |
| 455 | subjectKey="of:0000000000000003", |
| 456 | configKey="basic" ) |
| 457 | onosCfg = pprint( getS3 ) |
| 458 | sentCfg = pprint( s3Json ) |
| 459 | if onosCfg == sentCfg: |
| 460 | s3Result = True |
| 461 | else: |
| 462 | main.log.error( "ONOS NetCfg doesn't match what was sent" ) |
| 463 | main.log.debug( "ONOS config: {}".format( onosCfg ) ) |
| 464 | main.log.debug( "Sent config: {}".format( sentCfg ) ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 465 | utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 466 | utilities.assert_equals( expect=True, |
| 467 | actual=s3Result, |
| 468 | onpass="Net Cfg added for device s3", |
| 469 | onfail="Net Cfg for device s3 not correctly set" ) |
| 470 | main.netCfg.compareCfg( main, main.gossipTime ) |
| 471 | |
| 472 | def CASE21( self, main ): |
| 473 | """ |
| 474 | Initial check of devices |
| 475 | """ |
| 476 | import json |
| 477 | try: |
| 478 | assert main.s1Json, "s1Json not defined" |
| 479 | except AssertionError: |
| 480 | main.log.exception( "Case Prerequisites not set: " ) |
| 481 | main.cleanup() |
| 482 | main.exit() |
| 483 | main.case( "Check Devices After they initially connect to ONOS" ) |
| 484 | |
| 485 | main.netCfg.compareCfg( main ) |
| 486 | |
| 487 | main.step( "ONOS should only show devices S1, S2, and S4" ) |
| 488 | devices = main.ONOSrest1.devices() |
| 489 | main.log.debug( main.ONOSrest1.pprint( devices ) ) |
| 490 | allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ] |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 491 | main.log.debug( allowedDevices ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 492 | onosDevices = [] |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 493 | try: |
| 494 | for sw in json.loads( devices ): |
| 495 | onosDevices.append( str( sw['id'] ) ) |
| 496 | onosDevices.sort() |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 497 | main.log.debug( onosDevices ) |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 498 | except( TypeError, ValueError ): |
| 499 | main.log.error( "Problem loading devices" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 500 | utilities.assert_equals( expect=allowedDevices, |
| 501 | actual=onosDevices, |
| 502 | onpass="Only allowed devices are in ONOS", |
| 503 | onfail="ONOS devices doesn't match the list" + |
| 504 | " of allowed devices" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 505 | main.step( "Check device annotations" ) |
| 506 | keys = [ 'name', 'owner', 'rackAddress' ] |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 507 | try: |
| 508 | for sw in json.loads( devices ): |
| 509 | if "of:0000000000000001" in sw['id']: |
| 510 | s1Correct = True |
| 511 | for k in keys: |
| 512 | if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[k] ): |
| 513 | s1Correct = False |
| 514 | main.log.debug( "{} is wrong on s1".format( k ) ) |
| 515 | if not s1Correct: |
| 516 | main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) ) |
| 517 | except( TypeError, ValueError ): |
| 518 | main.log.error( "Problem loading devices" ) |
| 519 | s1Correct = False |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 520 | try: |
| 521 | stepResult = s1Correct |
| 522 | except NameError: |
| 523 | stepResult = False |
| 524 | main.log.error( "s1 not found in devices" ) |
| 525 | utilities.assert_equals( expect=True, |
| 526 | actual=stepResult, |
| 527 | onpass="Configured device's annotations are correct", |
| 528 | onfail="Incorrect annotations for configured devices." ) |
| 529 | |
| 530 | def CASE22( self, main ): |
| 531 | """ |
| 532 | Add some device configurations for connected devices and then check |
| 533 | they are distributed to all nodes |
| 534 | """ |
| 535 | main.case( "Add Network configurations for connected devices to the cluster" ) |
| 536 | main.caseExplanation = "Add Network Configurations for discovered " +\ |
| 537 | "devices. One device is allowed" +\ |
| 538 | ", the other disallowed." |
| 539 | pprint = main.nodes[0].pprint |
| 540 | |
| 541 | main.step( "Add Net Cfg for switch2" ) |
| 542 | s2Json = { "rackAddress": 2, |
| 543 | "name": "Switch2", |
| 544 | "owner": "Jenny", |
| 545 | "allowed": True } |
| 546 | main.s2Json = s2Json |
| 547 | setS2Allow = main.ONOSrest2.setNetCfg( s2Json, |
| 548 | subjectClass="devices", |
| 549 | subjectKey="of:0000000000000002", |
| 550 | configKey="basic" ) |
| 551 | s2Result = False |
| 552 | if setS2Allow: |
| 553 | # Check what we set is what is in ONOS |
| 554 | getS2 = main.ONOSrest2.getNetCfg( subjectClass="devices", |
| 555 | subjectKey="of:0000000000000002", |
| 556 | configKey="basic" ) |
| 557 | onosCfg = pprint( getS2 ) |
| 558 | sentCfg = pprint( s2Json ) |
| 559 | if onosCfg == sentCfg: |
| 560 | s2Result = True |
| 561 | else: |
| 562 | main.log.error( "ONOS NetCfg doesn't match what was sent" ) |
| 563 | main.log.debug( "ONOS config: {}".format( onosCfg ) ) |
| 564 | main.log.debug( "Sent config: {}".format( sentCfg ) ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 565 | utilities.retry( f=main.ONOSrest2.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 566 | utilities.assert_equals( expect=True, |
| 567 | actual=s2Result, |
| 568 | onpass="Net Cfg added for device s2", |
| 569 | onfail="Net Cfg for device s2 not correctly set" ) |
| 570 | |
| 571 | main.step( "Add Net Cfg for switch4" ) |
| 572 | s4Json = { "rackAddress": 4, |
| 573 | "name": "Switch4", |
| 574 | "owner": "John", |
| 575 | "allowed": False } |
| 576 | main.s4Json = s4Json |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 577 | setS4Disallow = main.ONOSrest3.setNetCfg( s4Json, |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 578 | subjectClass="devices", |
| 579 | subjectKey="of:0000000000000004", |
| 580 | configKey="basic" ) |
| 581 | s4Result = False |
| 582 | if setS4Disallow: |
| 583 | # Check what we set is what is in ONOS |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 584 | getS4 = main.ONOSrest3.getNetCfg( subjectClass="devices", |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 585 | subjectKey="of:0000000000000004", |
| 586 | configKey="basic" ) |
| 587 | onosCfg = pprint( getS4 ) |
| 588 | sentCfg = pprint( s4Json ) |
| 589 | if onosCfg == sentCfg: |
| 590 | s4Result = True |
| 591 | else: |
| 592 | main.log.error( "ONOS NetCfg doesn't match what was sent" ) |
| 593 | main.log.debug( "ONOS config: {}".format( onosCfg ) ) |
| 594 | main.log.debug( "Sent config: {}".format( sentCfg ) ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 595 | main.step( "Retrying main.ONOSrest3.getNetCfg" ) |
| 596 | utilities.retry( f=main.ONOSrest3.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 597 | utilities.assert_equals( expect=True, |
| 598 | actual=s4Result, |
| 599 | onpass="Net Cfg added for device s4", |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 600 | onfail="Net Cfg for device s4 not correctly set" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 601 | |
| 602 | main.netCfg.compareCfg( main, main.gossipTime ) |
| 603 | |
| 604 | def CASE23( self, main ): |
| 605 | """ |
| 606 | Check of devices after all Network Configurations are set |
| 607 | """ |
| 608 | import json |
| 609 | try: |
| 610 | assert main.s1Json, "s1Json not defined" |
| 611 | assert main.s2Json, "s2Json not defined" |
| 612 | except AssertionError: |
| 613 | main.log.exception( "Case Prerequisites not set: " ) |
| 614 | main.cleanup() |
| 615 | main.exit() |
| 616 | main.case( "Check Devices after all configurations are set" ) |
| 617 | |
| 618 | main.netCfg.compareCfg( main ) |
| 619 | |
| 620 | main.step( "ONOS should only show devices S1 and S2" ) |
| 621 | devices = main.ONOSrest1.devices() |
| 622 | main.log.debug( main.ONOSrest1.pprint( devices ) ) |
| 623 | allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2 ] ] |
| 624 | onosDevices = [] |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 625 | try: |
| 626 | for sw in json.loads( devices ): |
| 627 | onosDevices.append( str( sw.get( 'id' ) ) ) |
| 628 | onosDevices.sort() |
| 629 | failMsg = "ONOS devices doesn't match the list of allowed devices.\n" |
| 630 | failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, |
| 631 | onosDevices ) |
| 632 | except( TypeError, ValueError ): |
| 633 | main.log.error( "Problem loading devices" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 634 | utilities.assert_equals( expect=allowedDevices, |
| 635 | actual=onosDevices, |
| 636 | onpass="Only allowed devices are in ONOS", |
| 637 | onfail=failMsg ) |
| 638 | |
| 639 | main.step( "Check device annotations" ) |
| 640 | keys = [ 'name', 'owner', 'rackAddress' ] |
Jeremy Songster | 5c3fdb4 | 2016-04-27 12:19:27 -0700 | [diff] [blame] | 641 | try: |
| 642 | for sw in json.loads( devices ): |
| 643 | if "of:0000000000000001" in sw.get( 'id' ): |
| 644 | s1Correct = True |
| 645 | for k in keys: |
| 646 | if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[k] ): |
| 647 | s1Correct = False |
| 648 | main.log.debug( "{} is wrong on s1".format( k ) ) |
| 649 | if not s1Correct: |
| 650 | main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) ) |
| 651 | elif "of:0000000000000002" in sw['id']: |
| 652 | s2Correct = True |
| 653 | for k in keys: |
| 654 | if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s2Json[k] ): |
| 655 | s2Correct = False |
| 656 | main.log.debug( "{} is wrong on s2".format( k ) ) |
| 657 | if not s2Correct: |
| 658 | main.log.error( "Annotations for s2 are incorrect: {}".format( sw ) ) |
| 659 | except( TypeError, ValueError ): |
| 660 | main.log.error( "Problem loading devices" ) |
| 661 | stepResult = False |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 662 | try: |
| 663 | stepResult = s1Correct and s2Correct |
| 664 | except NameError: |
| 665 | stepResult = False |
| 666 | main.log.error( "s1 and/or s2 not found in devices" ) |
| 667 | utilities.assert_equals( expect=True, |
| 668 | actual=stepResult, |
| 669 | onpass="Configured device's annotations are correct", |
| 670 | onfail="Incorrect annotations for configured devices." ) |
| 671 | |
| 672 | def CASE24( self, main ): |
| 673 | """ |
| 674 | Testing removal of configurations |
| 675 | """ |
Jon Hall | 541b8e0 | 2015-12-14 19:29:01 -0800 | [diff] [blame] | 676 | import time |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 677 | try: |
| 678 | assert main.s1Json, "s1Json not defined" |
| 679 | assert main.s2Json, "s2Json not defined" |
| 680 | assert main.s3Json, "s3Json not defined" |
| 681 | assert main.s4Json, "s4Json not defined" |
| 682 | except AssertionError: |
| 683 | main.log.exception( "Case Prerequisites not set: " ) |
| 684 | main.cleanup() |
| 685 | main.exit() |
| 686 | main.case( "Testing removal of configurations" ) |
| 687 | main.step( "Remove 'allowed' configuration from all devices" ) |
| 688 | |
| 689 | s1Json = main.s1Json # NOTE: This is a reference |
| 690 | try: |
| 691 | del s1Json['allowed'] |
| 692 | except KeyError: |
| 693 | main.log.exception( "Key not found" ) |
| 694 | setS1 = main.ONOSrest1.setNetCfg( s1Json, |
| 695 | subjectClass="devices", |
| 696 | subjectKey="of:0000000000000001", |
| 697 | configKey="basic" ) |
| 698 | |
| 699 | s2Json = main.s2Json # NOTE: This is a reference |
| 700 | try: |
Jon Hall | 541b8e0 | 2015-12-14 19:29:01 -0800 | [diff] [blame] | 701 | time.sleep( main.gossipTime ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 702 | del s2Json['allowed'] |
| 703 | except KeyError: |
| 704 | main.log.exception( "Key not found" ) |
| 705 | setS2 = main.ONOSrest2.setNetCfg( s2Json, |
| 706 | subjectClass="devices", |
| 707 | subjectKey="of:0000000000000002", |
| 708 | configKey="basic" ) |
| 709 | |
| 710 | s3Json = main.s3Json # NOTE: This is a reference |
| 711 | try: |
Jon Hall | 541b8e0 | 2015-12-14 19:29:01 -0800 | [diff] [blame] | 712 | time.sleep( main.gossipTime ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 713 | del s3Json['allowed'] |
| 714 | except KeyError: |
| 715 | main.log.exception( "Key not found" ) |
| 716 | setS3 = main.ONOSrest3.setNetCfg( s3Json, |
| 717 | subjectClass="devices", |
| 718 | subjectKey="of:0000000000000003", |
| 719 | configKey="basic" ) |
| 720 | |
| 721 | s4Json = main.s4Json # NOTE: This is a reference |
| 722 | try: |
Jon Hall | 541b8e0 | 2015-12-14 19:29:01 -0800 | [diff] [blame] | 723 | time.sleep( main.gossipTime ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 724 | del s4Json['allowed'] |
| 725 | except KeyError: |
| 726 | main.log.exception( "Key not found" ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 727 | setS4 = main.ONOSrest3.setNetCfg( s4Json, |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 728 | subjectClass="devices", |
| 729 | subjectKey="of:0000000000000004", |
| 730 | configKey="basic" ) |
| 731 | removeAllowed = setS1 and setS2 and setS3 and setS4 |
| 732 | utilities.assert_equals( expect=main.TRUE, |
| 733 | actual=removeAllowed, |
| 734 | onpass="Successfully removed 'allowed' config from devices", |
| 735 | onfail="Failed to remove the 'allowed' config key." ) |
| 736 | |
| 737 | main.netCfg.compareCfg( main, main.gossipTime ) |
| 738 | |
| 739 | main.step( "Delete basic config for s1 and s2" ) |
| 740 | removeS1 = main.ONOSrest1.removeNetCfg( subjectClass="devices", |
| 741 | subjectKey="of:0000000000000001", |
| 742 | configKey="basic" ) |
| 743 | removeS2 = main.ONOSrest2.removeNetCfg( subjectClass="devices", |
| 744 | subjectKey="of:0000000000000002", |
| 745 | configKey="basic" ) |
| 746 | removeSingles = removeS1 and removeS2 |
| 747 | utilities.assert_equals( expect=main.TRUE, |
| 748 | actual=removeSingles, |
| 749 | onpass="Successfully removed S1 and S2 basic config", |
| 750 | onfail="Failed to removed S1 and S2 basic config" ) |
| 751 | |
| 752 | main.netCfg.compareCfg( main, main.gossipTime ) |
| 753 | |
| 754 | main.step( "Delete the net config for S3" ) |
| 755 | removeS3 = main.ONOSrest3.removeNetCfg( subjectClass="devices", |
| 756 | subjectKey="of:0000000000000003" ) |
| 757 | utilities.assert_equals( expect=main.TRUE, |
| 758 | actual=removeS3, |
| 759 | onpass="Successfully removed S3's config", |
| 760 | onfail="Failed to removed S3's config" ) |
| 761 | |
| 762 | main.netCfg.compareCfg( main, main.gossipTime ) |
| 763 | |
| 764 | main.step( "Delete the net config for all devices" ) |
| 765 | remove = main.ONOSrest3.removeNetCfg( subjectClass="devices" ) |
| 766 | utilities.assert_equals( expect=main.TRUE, |
| 767 | actual=remove, |
| 768 | onpass="Successfully removed device config", |
| 769 | onfail="Failed to remove device config" ) |
| 770 | |
| 771 | main.netCfg.compareCfg( main, main.gossipTime ) |
| 772 | |
| 773 | main.step( "Assert the net config for devices is empty" ) |
| 774 | get = main.ONOSrest3.getNetCfg( subjectClass="devices" ) |
| 775 | utilities.assert_equals( expect='{}', |
| 776 | actual=get, |
| 777 | onpass="Successfully removed device config", |
| 778 | onfail="Failed to remove device config" ) |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 779 | |
| 780 | def CASE25( self, main ): |
| 781 | """ |
| 782 | Use network-cfg.json to configure devices during ONOS startup |
| 783 | """ |
| 784 | main.case( "Preparing network-cfg.json to load configurations" ) |
| 785 | main.step( "Moving network-cfg.json to $ONOS_ROOT/tools/package/config/" ) |
| 786 | prestartResult = main.TRUE |
| 787 | srcPath = "~/OnosSystemTest/TestON/tests/FUNC/FUNCnetCfg/dependencies/network-cfg.json" |
| 788 | dstPath = "~/onos/tools/package/config/network-cfg.json" |
| 789 | prestartResult = main.ONOSbench.scp( main.ONOSbench, srcPath, dstPath, direction="to" ) |
| 790 | utilities.assert_equals( expect=main.TRUE, |
| 791 | actual=prestartResult, |
| 792 | onpass="Successfully copied network-cfg.json to target directory", |
| 793 | onfail="Failed to copy network-cfg.json to target directory" ) |
| 794 | |
| 795 | def CASE26( self, main ): |
| 796 | """ |
| 797 | Check to see that pre-startup configurations were set correctly |
| 798 | """ |
| 799 | import json |
| 800 | main.case( "Check to see if the pre-startup configurations were set, then remove their allowed status" ) |
| 801 | main.step( "Checking configurations for Switches 5 and 6" ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 802 | main.step( "ONOS should only show devices S1, S2, S4, and S5" ) #and S6 |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 803 | devices = main.ONOSrest1.devices() |
| 804 | main.log.debug( main.ONOSrest1.pprint( devices ) ) |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 805 | allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5 ] ] #6 |
Jeremy Songster | 2baa44e | 2016-06-10 10:18:40 -0700 | [diff] [blame] | 806 | main.log.debug( allowedDevices ) |
| 807 | onosDevices = [] |
| 808 | try: |
| 809 | for sw in json.loads( devices ): |
| 810 | onosDevices.append( str( sw['id'] ) ) |
| 811 | onosDevices.sort() |
| 812 | main.log.debug( onosDevices ) |
| 813 | except( TypeError, ValueError ): |
| 814 | main.log.error( "Problem loading devices" ) |
| 815 | utilities.assert_equals( expect=allowedDevices, |
| 816 | actual=onosDevices, |
| 817 | onpass="Only allowed devices are in ONOS", |
| 818 | onfail="ONOS devices doesn't match the list" + |
| 819 | " of allowed devices" ) |
| 820 | |
| 821 | main.step( "Removing allowed status from Switches 5 and 6" ) |
| 822 | main.s5Json = { "allowed": False } |
| 823 | main.s6Json = { "allowed": False } |
| 824 | s5Json = main.s5Json |
| 825 | setS1 = main.ONOSrest1.setNetCfg( s5Json, |
| 826 | subjectClass="devices", |
| 827 | subjectKey="of:0000000000000005", |
| 828 | configKey="basic" ) |
| 829 | |
| 830 | s6Json = main.s6Json |
| 831 | setS1 = main.ONOSrest1.setNetCfg( s6Json, |
| 832 | subjectClass="devices", |
| 833 | subjectKey="of:0000000000000006", |
Ming Yan Shu | db74bf2 | 2016-06-23 14:56:22 -0700 | [diff] [blame] | 834 | configKey="basic" ) |
| 835 | |
| 836 | def CASE27( self, main ): |
| 837 | """ |
| 838 | 1) A = get /network/configuration |
| 839 | 2) Post A |
| 840 | 3) Compare A with ONOS |
| 841 | 4) Modify A so S6 is disallowed |
| 842 | 5) Check |
| 843 | |
| 844 | """ |
| 845 | import json |
| 846 | pprint = main.nodes[0].pprint |
| 847 | main.case( "Posting network configurations to the top level web resource" ) |
| 848 | main.step( "Get json object from Net Cfg" ) |
| 849 | getinfo = main.ONOSrest1.getNetCfg( ) |
| 850 | main.log.debug( getinfo ) |
| 851 | main.step( "Posting json object to Net Cfg" ) |
| 852 | postinfo = main.ONOSrest1.setNetCfg( json.loads( getinfo ) ) |
| 853 | main.step( "Compare device with ONOS" ) |
| 854 | main.netCfg.compareCfg( main ) |
| 855 | main.step ( "ONOS should only show devices S1, S2, S4, S5 and S6" ) |
| 856 | devices = main.ONOSrest1.devices( ) |
| 857 | main.log.debug( main.ONOSrest1.pprint( devices ) ) |
| 858 | allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ] |
| 859 | onosDevices = [] |
| 860 | try: |
| 861 | for sw in json.loads( devices ): |
| 862 | onosDevices.append( str( sw.get( 'id' ) ) ) |
| 863 | onosDevices.sort( ) |
| 864 | failMsg = "ONOS devices doesn't match the list of allowed devices. \n" |
| 865 | failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices ) |
| 866 | except( TypeError, ValueError ): |
| 867 | main.log.error( "Problem loading devices" ) |
| 868 | utilities.assert_equals( expect=allowedDevices, actual=onosDevices, |
| 869 | onpass="Only allowed devices are in ONOS", onfail=failMsg ) |
| 870 | |
| 871 | main.step( "Modify json object so S6 is disallowed" ) |
| 872 | main.s6Json = { "allowed": False } |
| 873 | s6Json = main.s6Json |
| 874 | setS6Disallow = main.ONOSrest1.setNetCfg( s6Json, subjectClass="devices", |
| 875 | subjectKey="of:0000000000000006", configKey="basic" ) |
| 876 | s6Result = False |
| 877 | if setS6Disallow: |
| 878 | getS6 = main.ONOSrest1.getNetCfg( subjectClass="devices", |
| 879 | subjectKey="of:0000000000000006", configKey="basic" ) |
| 880 | onosCfg = pprint( getS6 ) |
| 881 | sentCfg = pprint( s6Json ) |
| 882 | if onosCfg == sentCfg: |
| 883 | s6Result = True |
| 884 | else: |
| 885 | main.log.error( "ONOS NetCfg doesn't match what was sent" ) |
| 886 | main.log.debug( "ONOS config: {}".format( onosCfg ) ) |
| 887 | main.log.debug( "Sent config: {}".format( sentCfg ) ) |
| 888 | utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep ) |
| 889 | utilities.assert_equals( expect=True, actual=s6Result, |
| 890 | onpass="Net Cfg added for devices s6", |
| 891 | onfail="Net Cfg for device s6 not correctly set" ) |