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