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