Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1 | """ |
| 2 | Description: This test is to determine if a single |
| 3 | instance ONOS 'cluster' can handle a restart |
| 4 | |
| 5 | List of test cases: |
| 6 | CASE1: Compile ONOS and push it to the test machines |
| 7 | CASE2: Assign devices to controllers |
| 8 | CASE21: Assign mastership to controllers |
| 9 | CASE3: Assign intents |
| 10 | CASE4: Ping across added host intents |
| 11 | CASE5: Reading state of ONOS |
| 12 | CASE6: The Failure case. |
| 13 | CASE7: Check state after control plane failure |
| 14 | CASE8: Compare topo |
| 15 | CASE9: Link s3-s28 down |
| 16 | CASE10: Link s3-s28 up |
| 17 | CASE11: Switch down |
| 18 | CASE12: Switch up |
| 19 | CASE13: Clean up |
| 20 | CASE14: start election app on all onos nodes |
| 21 | CASE15: Check that Leadership Election is still functional |
| 22 | CASE16: Install Distributed Primitives app |
| 23 | CASE17: Check for basic functionality with distributed primitives |
| 24 | """ |
| 25 | |
| 26 | |
| 27 | class HAsingleInstanceRestart: |
| 28 | |
| 29 | def __init__( self ): |
| 30 | self.default = '' |
| 31 | |
| 32 | def CASE1( self, main ): |
| 33 | """ |
| 34 | CASE1 is to compile ONOS and push it to the test machines |
| 35 | |
| 36 | Startup sequence: |
| 37 | cell <name> |
| 38 | onos-verify-cell |
| 39 | NOTE: temporary - onos-remove-raft-logs |
| 40 | onos-uninstall |
| 41 | start mininet |
| 42 | git pull |
| 43 | mvn clean install |
| 44 | onos-package |
| 45 | onos-install -f |
| 46 | onos-wait-for-start |
| 47 | start cli sessions |
| 48 | start tcpdump |
| 49 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 50 | import imp |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 51 | main.log.info( "ONOS Single node cluster restart " + |
| 52 | "HA test - initialization" ) |
| 53 | main.case( "Setting up test environment" ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 54 | main.caseExplanation = "Setup the test environment including " +\ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 55 | "installing ONOS, starting Mininet and ONOS" +\ |
| 56 | "cli sessions." |
| 57 | # TODO: save all the timers and output them for plotting |
| 58 | |
| 59 | # load some variables from the params file |
| 60 | PULLCODE = False |
| 61 | if main.params[ 'Git' ] == 'True': |
| 62 | PULLCODE = True |
| 63 | gitBranch = main.params[ 'branch' ] |
| 64 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 65 | |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 66 | main.numCtrls = int( main.params[ 'num_controllers' ] ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 67 | if main.ONOSbench.maxNodes: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 68 | if main.ONOSbench.maxNodes < main.numCtrls: |
| 69 | main.numCtrls = int( main.ONOSbench.maxNodes ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 70 | |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 71 | try: |
| 72 | fileName = "Counters" |
| 73 | path = main.params[ 'imports' ][ 'path' ] |
| 74 | main.Counters = imp.load_source( fileName, |
| 75 | path + fileName + ".py" ) |
| 76 | except Exception as e: |
| 77 | main.log.exception( e ) |
| 78 | main.cleanup() |
| 79 | main.exit() |
| 80 | |
| 81 | main.CLIs = [] |
| 82 | main.nodes = [] |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 83 | ipList = [] |
| 84 | for i in range( 1, int( main.ONOSbench.maxNodes ) + 1 ): |
| 85 | try: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 86 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 87 | main.nodes.append( getattr( main, 'ONOS' + str( i ) ) ) |
| 88 | ipList.append( main.nodes[ -1 ].ip_address ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 89 | except AttributeError: |
| 90 | break |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 91 | |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 92 | main.step( "Create cell file" ) |
| 93 | cellAppString = main.params[ 'ENV' ][ 'appString' ] |
| 94 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName, |
| 95 | main.Mininet1.ip_address, |
| 96 | cellAppString, ipList ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 97 | main.step( "Applying cell variable to environment" ) |
| 98 | cellResult = main.ONOSbench.setCell( cellName ) |
| 99 | verifyResult = main.ONOSbench.verifyCell() |
| 100 | |
| 101 | # FIXME:this is short term fix |
| 102 | main.log.info( "Removing raft logs" ) |
| 103 | main.ONOSbench.onosRemoveRaftLogs() |
| 104 | |
| 105 | main.log.info( "Uninstalling ONOS" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 106 | for node in main.nodes: |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 107 | main.ONOSbench.onosUninstall( node.ip_address ) |
| 108 | |
| 109 | # Make sure ONOS is DEAD |
| 110 | main.log.info( "Killing any ONOS processes" ) |
| 111 | killResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 112 | for node in main.nodes: |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 113 | killed = main.ONOSbench.onosKill( node.ip_address ) |
| 114 | killResults = killResults and killed |
| 115 | |
| 116 | cleanInstallResult = main.TRUE |
| 117 | gitPullResult = main.TRUE |
| 118 | |
| 119 | main.step( "Starting Mininet" ) |
| 120 | # scp topo file to mininet |
| 121 | # TODO: move to params? |
| 122 | topoName = "obelisk.py" |
| 123 | filePath = main.ONOSbench.home + "/tools/test/topos/" |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 124 | main.ONOSbench.scp( main.Mininet1, |
| 125 | filePath + topoName, |
| 126 | main.Mininet1.home, |
| 127 | direction="to" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 128 | mnResult = main.Mininet1.startNet( ) |
| 129 | utilities.assert_equals( expect=main.TRUE, actual=mnResult, |
| 130 | onpass="Mininet Started", |
| 131 | onfail="Error starting Mininet" ) |
| 132 | |
| 133 | main.step( "Git checkout and pull " + gitBranch ) |
| 134 | if PULLCODE: |
| 135 | main.ONOSbench.gitCheckout( gitBranch ) |
| 136 | gitPullResult = main.ONOSbench.gitPull() |
| 137 | # values of 1 or 3 are good |
| 138 | utilities.assert_lesser( expect=0, actual=gitPullResult, |
| 139 | onpass="Git pull successful", |
| 140 | onfail="Git pull failed" ) |
| 141 | main.ONOSbench.getVersion( report=True ) |
| 142 | |
| 143 | main.step( "Using mvn clean install" ) |
| 144 | cleanInstallResult = main.TRUE |
| 145 | if PULLCODE and gitPullResult == main.TRUE: |
| 146 | cleanInstallResult = main.ONOSbench.cleanInstall() |
| 147 | else: |
| 148 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 149 | "clean install" ) |
| 150 | utilities.assert_equals( expect=main.TRUE, |
| 151 | actual=cleanInstallResult, |
| 152 | onpass="MCI successful", |
| 153 | onfail="MCI failed" ) |
| 154 | # GRAPHS |
| 155 | # NOTE: important params here: |
| 156 | # job = name of Jenkins job |
| 157 | # Plot Name = Plot-HA, only can be used if multiple plots |
| 158 | # index = The number of the graph under plot name |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 159 | job = "HAsingleInstanceRestart" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 160 | plotName = "Plot-HA" |
| 161 | graphs = '<ac:structured-macro ac:name="html">\n' |
| 162 | graphs += '<ac:plain-text-body><![CDATA[\n' |
| 163 | graphs += '<iframe src="https://onos-jenkins.onlab.us/job/' + job +\ |
| 164 | '/plot/' + plotName + '/getPlot?index=0' +\ |
| 165 | '&width=500&height=300"' +\ |
| 166 | 'noborder="0" width="500" height="300" scrolling="yes" ' +\ |
| 167 | 'seamless="seamless"></iframe>\n' |
| 168 | graphs += ']]></ac:plain-text-body>\n' |
| 169 | graphs += '</ac:structured-macro>\n' |
| 170 | main.log.wiki(graphs) |
| 171 | |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 172 | main.CLIs = [] |
| 173 | main.nodes = [] |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 174 | ipList = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 175 | for i in range( 1, main.numCtrls + 1 ): |
| 176 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 177 | main.nodes.append( getattr( main, 'ONOS' + str( i ) ) ) |
| 178 | ipList.append( main.nodes[ -1 ].ip_address ) |
Jon Hall | 5cf14d5 | 2015-07-16 12:15:19 -0700 | [diff] [blame] | 179 | |
| 180 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "SingleHA", |
| 181 | main.Mininet1.ip_address, |
| 182 | cellAppString, ipList[ 0 ] ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 183 | cellResult = main.ONOSbench.setCell( "SingleHA" ) |
| 184 | verifyResult = main.ONOSbench.verifyCell() |
| 185 | main.step( "Creating ONOS package" ) |
| 186 | packageResult = main.ONOSbench.onosPackage() |
| 187 | utilities.assert_equals( expect=main.TRUE, actual=packageResult, |
| 188 | onpass="ONOS package successful", |
| 189 | onfail="ONOS package failed" ) |
| 190 | |
| 191 | main.step( "Installing ONOS package" ) |
| 192 | onosInstallResult = main.ONOSbench.onosInstall( |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 193 | options="-f", node=main.nodes[0].ip_address ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 194 | utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult, |
| 195 | onpass="ONOS install successful", |
| 196 | onfail="ONOS install failed" ) |
| 197 | |
| 198 | main.step( "Checking if ONOS is up yet" ) |
| 199 | for i in range( 2 ): |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 200 | onos1Isup = main.ONOSbench.isup( main.nodes[0].ip_address ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 201 | if onos1Isup: |
| 202 | break |
| 203 | utilities.assert_equals( expect=main.TRUE, actual=onos1Isup, |
| 204 | onpass="ONOS startup successful", |
| 205 | onfail="ONOS startup failed" ) |
| 206 | |
| 207 | main.log.step( "Starting ONOS CLI sessions" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 208 | cliResults = main.ONOScli1.startOnosCli( main.nodes[0].ip_address ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 209 | utilities.assert_equals( expect=main.TRUE, actual=cliResults, |
| 210 | onpass="ONOS cli startup successful", |
| 211 | onfail="ONOS cli startup failed" ) |
| 212 | |
| 213 | if main.params[ 'tcpdump' ].lower() == "true": |
| 214 | main.step( "Start Packet Capture MN" ) |
| 215 | main.Mininet2.startTcpdump( |
| 216 | str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST ) |
| 217 | + "-MN.pcap", |
| 218 | intf=main.params[ 'MNtcpdump' ][ 'intf' ], |
| 219 | port=main.params[ 'MNtcpdump' ][ 'port' ] ) |
| 220 | |
| 221 | main.step( "App Ids check" ) |
| 222 | appCheck = main.ONOScli1.appToIDCheck() |
| 223 | if appCheck != main.TRUE: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 224 | main.log.warn( main.CLIs[0].apps() ) |
| 225 | main.log.warn( main.CLIs[0].appIDs() ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 226 | utilities.assert_equals( expect=main.TRUE, actual=appCheck, |
| 227 | onpass="App Ids seem to be correct", |
| 228 | onfail="Something is wrong with app Ids" ) |
| 229 | |
| 230 | if cliResults == main.FALSE: |
| 231 | main.log.error( "Failed to start ONOS, stopping test" ) |
| 232 | main.cleanup() |
| 233 | main.exit() |
| 234 | |
| 235 | def CASE2( self, main ): |
| 236 | """ |
| 237 | Assign devices to controllers |
| 238 | """ |
| 239 | import re |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 240 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 241 | assert main, "main not defined" |
| 242 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 243 | |
| 244 | main.case( "Assigning devices to controllers" ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 245 | main.caseExplanation = "Assign switches to ONOS using 'ovs-vsctl' " +\ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 246 | "and check that an ONOS node becomes the " +\ |
| 247 | "master of the device." |
| 248 | main.step( "Assign switches to controllers" ) |
| 249 | |
| 250 | ipList = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 251 | for i in range( main.numCtrls ): |
| 252 | ipList.append( main.nodes[ i ].ip_address ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 253 | swList = [] |
| 254 | for i in range( 1, 29 ): |
| 255 | swList.append( "s" + str( i ) ) |
| 256 | main.Mininet1.assignSwController( sw=swList, ip=ipList ) |
| 257 | |
| 258 | mastershipCheck = main.TRUE |
| 259 | for i in range( 1, 29 ): |
| 260 | response = main.Mininet1.getSwController( "s" + str( i ) ) |
| 261 | try: |
| 262 | main.log.info( str( response ) ) |
| 263 | except Exception: |
| 264 | main.log.info( repr( response ) ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 265 | if re.search( "tcp:" + main.nodes[0].ip_address, response ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 266 | mastershipCheck = mastershipCheck and main.TRUE |
| 267 | else: |
| 268 | mastershipCheck = main.FALSE |
| 269 | if mastershipCheck == main.TRUE: |
| 270 | main.log.info( "Switch mastership assigned correctly" ) |
| 271 | utilities.assert_equals( |
| 272 | expect=main.TRUE, |
| 273 | actual=mastershipCheck, |
| 274 | onpass="Switch mastership assigned correctly", |
| 275 | onfail="Switches not assigned correctly to controllers" ) |
| 276 | |
| 277 | def CASE21( self, main ): |
| 278 | """ |
| 279 | Assign mastership to controllers |
| 280 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 281 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 282 | assert main, "main not defined" |
| 283 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 284 | assert main.CLIs, "main.CLIs not defined" |
| 285 | assert main.nodes, "main.nodes not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 286 | |
| 287 | main.case( "Assigning Controller roles for switches" ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 288 | main.caseExplanation = "Check that ONOS is connected to each " +\ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 289 | "device. Then manually assign" +\ |
| 290 | " mastership to specific ONOS nodes using" +\ |
| 291 | " 'device-role'" |
| 292 | main.step( "Assign mastership of switches to specific controllers" ) |
| 293 | roleCall = main.TRUE |
| 294 | roleCheck = main.TRUE |
| 295 | try: |
| 296 | for i in range( 1, 29 ): # switches 1 through 28 |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 297 | ip = main.nodes[ 0 ].ip_address # ONOS1 |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 298 | # set up correct variables: |
| 299 | if i == 1: |
| 300 | deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' ) |
| 301 | elif i == 2: |
| 302 | deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' ) |
| 303 | elif i == 3: |
| 304 | deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' ) |
| 305 | elif i == 4: |
| 306 | deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' ) |
| 307 | elif i == 5: |
| 308 | deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' ) |
| 309 | elif i == 6: |
| 310 | deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' ) |
| 311 | elif i == 7: |
| 312 | deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' ) |
| 313 | elif i >= 8 and i <= 17: |
| 314 | dpid = '3' + str( i ).zfill( 3 ) |
| 315 | deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' ) |
| 316 | elif i >= 18 and i <= 27: |
| 317 | dpid = '6' + str( i ).zfill( 3 ) |
| 318 | deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' ) |
| 319 | elif i == 28: |
| 320 | deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' ) |
| 321 | else: |
| 322 | main.log.error( "You didn't write an else statement for " + |
| 323 | "switch s" + str( i ) ) |
| 324 | # Assign switch |
| 325 | assert deviceId, "No device id for s" + str( i ) + " in ONOS" |
| 326 | # TODO: make this controller dynamic |
| 327 | roleCall = roleCall and main.ONOScli1.deviceRole( deviceId, |
| 328 | ip ) |
| 329 | # Check assignment |
| 330 | master = main.ONOScli1.getRole( deviceId ).get( 'master' ) |
| 331 | if ip in master: |
| 332 | roleCheck = roleCheck and main.TRUE |
| 333 | else: |
| 334 | roleCheck = roleCheck and main.FALSE |
| 335 | main.log.error( "Error, controller " + ip + " is not" + |
| 336 | " master " + "of device " + |
| 337 | str( deviceId ) + ". Master is " + |
| 338 | repr( master ) + "." ) |
| 339 | except ( AttributeError, AssertionError ): |
| 340 | main.log.exception( "Something is wrong with ONOS device view" ) |
| 341 | main.log.info( main.ONOScli1.devices() ) |
| 342 | utilities.assert_equals( |
| 343 | expect=main.TRUE, |
| 344 | actual=roleCall, |
| 345 | onpass="Re-assigned switch mastership to designated controller", |
| 346 | onfail="Something wrong with deviceRole calls" ) |
| 347 | |
| 348 | main.step( "Check mastership was correctly assigned" ) |
| 349 | utilities.assert_equals( |
| 350 | expect=main.TRUE, |
| 351 | actual=roleCheck, |
| 352 | onpass="Switches were successfully reassigned to designated " + |
| 353 | "controller", |
| 354 | onfail="Switches were not successfully reassigned" ) |
| 355 | |
| 356 | def CASE3( self, main ): |
| 357 | """ |
| 358 | Assign intents |
| 359 | """ |
| 360 | import time |
| 361 | import json |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 362 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 363 | assert main, "main not defined" |
| 364 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 365 | # NOTE: we must reinstall intents until we have a persistant intent |
| 366 | # datastore! |
| 367 | main.case( "Adding host Intents" ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 368 | main.caseExplanation = "Discover hosts by using pingall then " +\ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 369 | "assign predetermined host-to-host intents." +\ |
| 370 | " After installation, check that the intent" +\ |
| 371 | " is distributed to all nodes and the state" +\ |
| 372 | " is INSTALLED" |
| 373 | |
| 374 | # install onos-app-fwd |
| 375 | main.step( "Install reactive forwarding app" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 376 | installResults = main.CLIs[0].activateApp( "org.onosproject.fwd" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 377 | utilities.assert_equals( expect=main.TRUE, actual=installResults, |
| 378 | onpass="Install fwd successful", |
| 379 | onfail="Install fwd failed" ) |
| 380 | |
| 381 | main.step( "Check app ids" ) |
| 382 | appCheck = main.ONOScli1.appToIDCheck() |
| 383 | if appCheck != main.TRUE: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 384 | main.log.warn( main.CLIs[0].apps() ) |
| 385 | main.log.warn( main.CLIs[0].appIDs() ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 386 | utilities.assert_equals( expect=main.TRUE, actual=appCheck, |
| 387 | onpass="App Ids seem to be correct", |
| 388 | onfail="Something is wrong with app Ids" ) |
| 389 | |
| 390 | main.step( "Discovering Hosts( Via pingall for now )" ) |
| 391 | # FIXME: Once we have a host discovery mechanism, use that instead |
| 392 | # REACTIVE FWD test |
| 393 | pingResult = main.FALSE |
| 394 | for i in range(2): # Retry if pingall fails first time |
| 395 | time1 = time.time() |
| 396 | pingResult = main.Mininet1.pingall() |
| 397 | if i == 0: |
| 398 | utilities.assert_equals( |
| 399 | expect=main.TRUE, |
| 400 | actual=pingResult, |
| 401 | onpass="Reactive Pingall test passed", |
| 402 | onfail="Reactive Pingall failed, " + |
| 403 | "one or more ping pairs failed" ) |
| 404 | time2 = time.time() |
| 405 | main.log.info( "Time for pingall: %2f seconds" % |
| 406 | ( time2 - time1 ) ) |
| 407 | # timeout for fwd flows |
| 408 | time.sleep( 11 ) |
| 409 | # uninstall onos-app-fwd |
| 410 | main.step( "Uninstall reactive forwarding app" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 411 | uninstallResult = main.CLIs[0].deactivateApp( "org.onosproject.fwd" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 412 | utilities.assert_equals( expect=main.TRUE, actual=uninstallResult, |
| 413 | onpass="Uninstall fwd successful", |
| 414 | onfail="Uninstall fwd failed" ) |
| 415 | |
| 416 | main.step( "Check app ids" ) |
| 417 | appCheck2 = main.ONOScli1.appToIDCheck() |
| 418 | if appCheck2 != main.TRUE: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 419 | main.log.warn( main.CLIs[0].apps() ) |
| 420 | main.log.warn( main.CLIs[0].appIDs() ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 421 | utilities.assert_equals( expect=main.TRUE, actual=appCheck2, |
| 422 | onpass="App Ids seem to be correct", |
| 423 | onfail="Something is wrong with app Ids" ) |
| 424 | |
| 425 | main.step( "Add host intents via cli" ) |
| 426 | intentIds = [] |
| 427 | # TODO: move the host numbers to params |
| 428 | # Maybe look at all the paths we ping? |
| 429 | intentAddResult = True |
| 430 | hostResult = main.TRUE |
| 431 | for i in range( 8, 18 ): |
| 432 | main.log.info( "Adding host intent between h" + str( i ) + |
| 433 | " and h" + str( i + 10 ) ) |
| 434 | host1 = "00:00:00:00:00:" + \ |
| 435 | str( hex( i )[ 2: ] ).zfill( 2 ).upper() |
| 436 | host2 = "00:00:00:00:00:" + \ |
| 437 | str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper() |
| 438 | # NOTE: getHost can return None |
| 439 | host1Dict = main.ONOScli1.getHost( host1 ) |
| 440 | host2Dict = main.ONOScli1.getHost( host2 ) |
| 441 | host1Id = None |
| 442 | host2Id = None |
| 443 | if host1Dict and host2Dict: |
| 444 | host1Id = host1Dict.get( 'id', None ) |
| 445 | host2Id = host2Dict.get( 'id', None ) |
| 446 | if host1Id and host2Id: |
| 447 | tmpId = main.ONOScli1.addHostIntent( host1Id, host2Id ) |
| 448 | if tmpId: |
| 449 | main.log.info( "Added intent with id: " + tmpId ) |
| 450 | intentIds.append( tmpId ) |
| 451 | else: |
| 452 | main.log.error( "addHostIntent returned: " + |
| 453 | repr( tmpId ) ) |
| 454 | else: |
| 455 | main.log.error( "Error, getHost() failed for h" + str( i ) + |
| 456 | " and/or h" + str( i + 10 ) ) |
| 457 | hosts = main.ONOScli1.hosts() |
| 458 | main.log.warn( "Hosts output: " ) |
| 459 | try: |
| 460 | main.log.warn( json.dumps( json.loads( hosts ), |
| 461 | sort_keys=True, |
| 462 | indent=4, |
| 463 | separators=( ',', ': ' ) ) ) |
| 464 | except ( ValueError, TypeError ): |
| 465 | main.log.warn( repr( hosts ) ) |
| 466 | hostResult = main.FALSE |
| 467 | utilities.assert_equals( expect=main.TRUE, actual=hostResult, |
| 468 | onpass="Found a host id for each host", |
| 469 | onfail="Error looking up host ids" ) |
| 470 | |
| 471 | intentStart = time.time() |
| 472 | onosIds = main.ONOScli1.getAllIntentsId() |
| 473 | main.log.info( "Submitted intents: " + str( intentIds ) ) |
| 474 | main.log.info( "Intents in ONOS: " + str( onosIds ) ) |
| 475 | for intent in intentIds: |
| 476 | if intent in onosIds: |
| 477 | pass # intent submitted is in onos |
| 478 | else: |
| 479 | intentAddResult = False |
| 480 | if intentAddResult: |
| 481 | intentStop = time.time() |
| 482 | else: |
| 483 | intentStop = None |
| 484 | # Print the intent states |
| 485 | intents = main.ONOScli1.intents() |
| 486 | intentStates = [] |
| 487 | installedCheck = True |
| 488 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 489 | count = 0 |
| 490 | try: |
| 491 | for intent in json.loads( intents ): |
| 492 | state = intent.get( 'state', None ) |
| 493 | if "INSTALLED" not in state: |
| 494 | installedCheck = False |
| 495 | intentId = intent.get( 'id', None ) |
| 496 | intentStates.append( ( intentId, state ) ) |
| 497 | except ( ValueError, TypeError ): |
| 498 | main.log.exception( "Error parsing intents" ) |
| 499 | # add submitted intents not in the store |
| 500 | tmplist = [ i for i, s in intentStates ] |
| 501 | missingIntents = False |
| 502 | for i in intentIds: |
| 503 | if i not in tmplist: |
| 504 | intentStates.append( ( i, " - " ) ) |
| 505 | missingIntents = True |
| 506 | intentStates.sort() |
| 507 | for i, s in intentStates: |
| 508 | count += 1 |
| 509 | main.log.info( "%-6s%-15s%-15s" % |
| 510 | ( str( count ), str( i ), str( s ) ) ) |
| 511 | leaders = main.ONOScli1.leaders() |
| 512 | try: |
| 513 | missing = False |
| 514 | if leaders: |
| 515 | parsedLeaders = json.loads( leaders ) |
| 516 | main.log.warn( json.dumps( parsedLeaders, |
| 517 | sort_keys=True, |
| 518 | indent=4, |
| 519 | separators=( ',', ': ' ) ) ) |
| 520 | # check for all intent partitions |
| 521 | topics = [] |
| 522 | for i in range( 14 ): |
| 523 | topics.append( "intent-partition-" + str( i ) ) |
| 524 | main.log.debug( topics ) |
| 525 | ONOStopics = [ j['topic'] for j in parsedLeaders ] |
| 526 | for topic in topics: |
| 527 | if topic not in ONOStopics: |
| 528 | main.log.error( "Error: " + topic + |
| 529 | " not in leaders" ) |
| 530 | missing = True |
| 531 | else: |
| 532 | main.log.error( "leaders() returned None" ) |
| 533 | except ( ValueError, TypeError ): |
| 534 | main.log.exception( "Error parsing leaders" ) |
| 535 | main.log.error( repr( leaders ) ) |
| 536 | # Check all nodes |
| 537 | if missing: |
| 538 | response = main.ONOScli1.leaders( jsonFormat=False) |
| 539 | main.log.warn( "ONOS1 leaders output: \n" + |
| 540 | str( response ) ) |
| 541 | |
| 542 | partitions = main.ONOScli1.partitions() |
| 543 | try: |
| 544 | if partitions : |
| 545 | parsedPartitions = json.loads( partitions ) |
| 546 | main.log.warn( json.dumps( parsedPartitions, |
| 547 | sort_keys=True, |
| 548 | indent=4, |
| 549 | separators=( ',', ': ' ) ) ) |
| 550 | # TODO check for a leader in all paritions |
| 551 | # TODO check for consistency among nodes |
| 552 | else: |
| 553 | main.log.error( "partitions() returned None" ) |
| 554 | except ( ValueError, TypeError ): |
| 555 | main.log.exception( "Error parsing partitions" ) |
| 556 | main.log.error( repr( partitions ) ) |
| 557 | pendingMap = main.ONOScli1.pendingMap() |
| 558 | try: |
| 559 | if pendingMap : |
| 560 | parsedPending = json.loads( pendingMap ) |
| 561 | main.log.warn( json.dumps( parsedPending, |
| 562 | sort_keys=True, |
| 563 | indent=4, |
| 564 | separators=( ',', ': ' ) ) ) |
| 565 | # TODO check something here? |
| 566 | else: |
| 567 | main.log.error( "pendingMap() returned None" ) |
| 568 | except ( ValueError, TypeError ): |
| 569 | main.log.exception( "Error parsing pending map" ) |
| 570 | main.log.error( repr( pendingMap ) ) |
| 571 | |
| 572 | intentAddResult = bool( intentAddResult and not missingIntents and |
| 573 | installedCheck ) |
| 574 | if not intentAddResult: |
| 575 | main.log.error( "Error in pushing host intents to ONOS" ) |
| 576 | |
| 577 | main.step( "Intent Anti-Entropy dispersion" ) |
| 578 | for i in range(100): |
| 579 | correct = True |
| 580 | main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 581 | for cli in main.CLIs: |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 582 | onosIds = [] |
| 583 | ids = cli.getAllIntentsId() |
| 584 | onosIds.append( ids ) |
| 585 | main.log.debug( "Intents in " + cli.name + ": " + |
| 586 | str( sorted( onosIds ) ) ) |
| 587 | if sorted( ids ) != sorted( intentIds ): |
| 588 | main.log.warn( "Set of intent IDs doesn't match" ) |
| 589 | correct = False |
| 590 | break |
| 591 | else: |
| 592 | intents = json.loads( cli.intents() ) |
| 593 | for intent in intents: |
| 594 | if intent[ 'state' ] != "INSTALLED": |
| 595 | main.log.warn( "Intent " + intent[ 'id' ] + |
| 596 | " is " + intent[ 'state' ] ) |
| 597 | correct = False |
| 598 | break |
| 599 | if correct: |
| 600 | break |
| 601 | else: |
| 602 | time.sleep(1) |
| 603 | if not intentStop: |
| 604 | intentStop = time.time() |
| 605 | global gossipTime |
| 606 | gossipTime = intentStop - intentStart |
| 607 | main.log.info( "It took about " + str( gossipTime ) + |
| 608 | " seconds for all intents to appear in each node" ) |
| 609 | # FIXME: make this time configurable/calculate based off of number of |
| 610 | # nodes and gossip rounds |
| 611 | utilities.assert_greater_equals( |
| 612 | expect=40, actual=gossipTime, |
| 613 | onpass="ECM anti-entropy for intents worked within " + |
| 614 | "expected time", |
| 615 | onfail="Intent ECM anti-entropy took too long" ) |
| 616 | if gossipTime <= 40: |
| 617 | intentAddResult = True |
| 618 | |
| 619 | if not intentAddResult or "key" in pendingMap: |
| 620 | import time |
| 621 | installedCheck = True |
| 622 | main.log.info( "Sleeping 60 seconds to see if intents are found" ) |
| 623 | time.sleep( 60 ) |
| 624 | onosIds = main.ONOScli1.getAllIntentsId() |
| 625 | main.log.info( "Submitted intents: " + str( intentIds ) ) |
| 626 | main.log.info( "Intents in ONOS: " + str( onosIds ) ) |
| 627 | # Print the intent states |
| 628 | intents = main.ONOScli1.intents() |
| 629 | intentStates = [] |
| 630 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 631 | count = 0 |
| 632 | try: |
| 633 | for intent in json.loads( intents ): |
| 634 | # Iter through intents of a node |
| 635 | state = intent.get( 'state', None ) |
| 636 | if "INSTALLED" not in state: |
| 637 | installedCheck = False |
| 638 | intentId = intent.get( 'id', None ) |
| 639 | intentStates.append( ( intentId, state ) ) |
| 640 | except ( ValueError, TypeError ): |
| 641 | main.log.exception( "Error parsing intents" ) |
| 642 | # add submitted intents not in the store |
| 643 | tmplist = [ i for i, s in intentStates ] |
| 644 | for i in intentIds: |
| 645 | if i not in tmplist: |
| 646 | intentStates.append( ( i, " - " ) ) |
| 647 | intentStates.sort() |
| 648 | for i, s in intentStates: |
| 649 | count += 1 |
| 650 | main.log.info( "%-6s%-15s%-15s" % |
| 651 | ( str( count ), str( i ), str( s ) ) ) |
| 652 | leaders = main.ONOScli1.leaders() |
| 653 | try: |
| 654 | missing = False |
| 655 | if leaders: |
| 656 | parsedLeaders = json.loads( leaders ) |
| 657 | main.log.warn( json.dumps( parsedLeaders, |
| 658 | sort_keys=True, |
| 659 | indent=4, |
| 660 | separators=( ',', ': ' ) ) ) |
| 661 | # check for all intent partitions |
| 662 | # check for election |
| 663 | topics = [] |
| 664 | for i in range( 14 ): |
| 665 | topics.append( "intent-partition-" + str( i ) ) |
| 666 | # FIXME: this should only be after we start the app |
| 667 | topics.append( "org.onosproject.election" ) |
| 668 | main.log.debug( topics ) |
| 669 | ONOStopics = [ j['topic'] for j in parsedLeaders ] |
| 670 | for topic in topics: |
| 671 | if topic not in ONOStopics: |
| 672 | main.log.error( "Error: " + topic + |
| 673 | " not in leaders" ) |
| 674 | missing = True |
| 675 | else: |
| 676 | main.log.error( "leaders() returned None" ) |
| 677 | except ( ValueError, TypeError ): |
| 678 | main.log.exception( "Error parsing leaders" ) |
| 679 | main.log.error( repr( leaders ) ) |
| 680 | # Check all nodes |
| 681 | if missing: |
| 682 | response = main.ONOScli1.leaders( jsonFormat=False) |
| 683 | main.log.warn( "ONOS1 leaders output: \n" + |
| 684 | str( response ) ) |
| 685 | partitions = main.ONOScli1.partitions() |
| 686 | try: |
| 687 | if partitions : |
| 688 | parsedPartitions = json.loads( partitions ) |
| 689 | main.log.warn( json.dumps( parsedPartitions, |
| 690 | sort_keys=True, |
| 691 | indent=4, |
| 692 | separators=( ',', ': ' ) ) ) |
| 693 | # TODO check for a leader in all paritions |
| 694 | # TODO check for consistency among nodes |
| 695 | else: |
| 696 | main.log.error( "partitions() returned None" ) |
| 697 | except ( ValueError, TypeError ): |
| 698 | main.log.exception( "Error parsing partitions" ) |
| 699 | main.log.error( repr( partitions ) ) |
| 700 | pendingMap = main.ONOScli1.pendingMap() |
| 701 | try: |
| 702 | if pendingMap : |
| 703 | parsedPending = json.loads( pendingMap ) |
| 704 | main.log.warn( json.dumps( parsedPending, |
| 705 | sort_keys=True, |
| 706 | indent=4, |
| 707 | separators=( ',', ': ' ) ) ) |
| 708 | # TODO check something here? |
| 709 | else: |
| 710 | main.log.error( "pendingMap() returned None" ) |
| 711 | except ( ValueError, TypeError ): |
| 712 | main.log.exception( "Error parsing pending map" ) |
| 713 | main.log.error( repr( pendingMap ) ) |
| 714 | |
| 715 | def CASE4( self, main ): |
| 716 | """ |
| 717 | Ping across added host intents |
| 718 | """ |
| 719 | import json |
| 720 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 721 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 722 | assert main, "main not defined" |
| 723 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 724 | main.case( "Verify connectivity by sendind traffic across Intents" ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 725 | main.caseExplanation = "Ping across added host intents to check " +\ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 726 | "functionality and check the state of " +\ |
| 727 | "the intent" |
| 728 | main.step( "Ping across added host intents" ) |
| 729 | PingResult = main.TRUE |
| 730 | for i in range( 8, 18 ): |
| 731 | ping = main.Mininet1.pingHost( src="h" + str( i ), |
| 732 | target="h" + str( i + 10 ) ) |
| 733 | PingResult = PingResult and ping |
| 734 | if ping == main.FALSE: |
| 735 | main.log.warn( "Ping failed between h" + str( i ) + |
| 736 | " and h" + str( i + 10 ) ) |
| 737 | elif ping == main.TRUE: |
| 738 | main.log.info( "Ping test passed!" ) |
| 739 | # Don't set PingResult or you'd override failures |
| 740 | if PingResult == main.FALSE: |
| 741 | main.log.error( |
| 742 | "Intents have not been installed correctly, pings failed." ) |
| 743 | # TODO: pretty print |
| 744 | main.log.warn( "ONOS1 intents: " ) |
| 745 | try: |
| 746 | tmpIntents = main.ONOScli1.intents() |
| 747 | main.log.warn( json.dumps( json.loads( tmpIntents ), |
| 748 | sort_keys=True, |
| 749 | indent=4, |
| 750 | separators=( ',', ': ' ) ) ) |
| 751 | except ( ValueError, TypeError ): |
| 752 | main.log.warn( repr( tmpIntents ) ) |
| 753 | utilities.assert_equals( |
| 754 | expect=main.TRUE, |
| 755 | actual=PingResult, |
| 756 | onpass="Intents have been installed correctly and pings work", |
| 757 | onfail="Intents have not been installed correctly, pings failed." ) |
| 758 | |
| 759 | main.step( "Check Intent state" ) |
| 760 | installedCheck = True |
| 761 | # Print the intent states |
| 762 | intents = main.ONOScli1.intents() |
| 763 | intentStates = [] |
| 764 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 765 | count = 0 |
| 766 | # Iter through intents of a node |
| 767 | try: |
| 768 | for intent in json.loads( intents ): |
| 769 | state = intent.get( 'state', None ) |
| 770 | if "INSTALLED" not in state: |
| 771 | installedCheck = False |
| 772 | intentId = intent.get( 'id', None ) |
| 773 | intentStates.append( ( intentId, state ) ) |
| 774 | except ( ValueError, TypeError ): |
| 775 | main.log.exception( "Error parsing intents." ) |
| 776 | # Print states |
| 777 | intentStates.sort() |
| 778 | for i, s in intentStates: |
| 779 | count += 1 |
| 780 | main.log.info( "%-6s%-15s%-15s" % |
| 781 | ( str( count ), str( i ), str( s ) ) ) |
| 782 | utilities.assert_equals( expect=True, actual=installedCheck, |
| 783 | onpass="Intents are all INSTALLED", |
| 784 | onfail="Intents are not all in " + |
| 785 | "INSTALLED state" ) |
| 786 | |
| 787 | main.step( "Check leadership of topics" ) |
| 788 | leaders = main.ONOScli1.leaders() |
| 789 | topicCheck = main.TRUE |
| 790 | try: |
| 791 | if leaders: |
| 792 | parsedLeaders = json.loads( leaders ) |
| 793 | main.log.warn( json.dumps( parsedLeaders, |
| 794 | sort_keys=True, |
| 795 | indent=4, |
| 796 | separators=( ',', ': ' ) ) ) |
| 797 | # check for all intent partitions |
| 798 | # check for election |
| 799 | # TODO: Look at Devices as topics now that it uses this system |
| 800 | topics = [] |
| 801 | for i in range( 14 ): |
| 802 | topics.append( "intent-partition-" + str( i ) ) |
| 803 | # FIXME: this should only be after we start the app |
| 804 | # FIXME: topics.append( "org.onosproject.election" ) |
| 805 | # Print leaders output |
| 806 | main.log.debug( topics ) |
| 807 | ONOStopics = [ j['topic'] for j in parsedLeaders ] |
| 808 | for topic in topics: |
| 809 | if topic not in ONOStopics: |
| 810 | main.log.error( "Error: " + topic + |
| 811 | " not in leaders" ) |
| 812 | topicCheck = main.FALSE |
| 813 | else: |
| 814 | main.log.error( "leaders() returned None" ) |
| 815 | topicCheck = main.FALSE |
| 816 | except ( ValueError, TypeError ): |
| 817 | topicCheck = main.FALSE |
| 818 | main.log.exception( "Error parsing leaders" ) |
| 819 | main.log.error( repr( leaders ) ) |
| 820 | # TODO: Check for a leader of these topics |
| 821 | utilities.assert_equals( expect=main.TRUE, actual=topicCheck, |
| 822 | onpass="intent Partitions is in leaders", |
| 823 | onfail="Some topics were lost " ) |
| 824 | # Print partitions |
| 825 | partitions = main.ONOScli1.partitions() |
| 826 | try: |
| 827 | if partitions : |
| 828 | parsedPartitions = json.loads( partitions ) |
| 829 | main.log.warn( json.dumps( parsedPartitions, |
| 830 | sort_keys=True, |
| 831 | indent=4, |
| 832 | separators=( ',', ': ' ) ) ) |
| 833 | # TODO check for a leader in all paritions |
| 834 | # TODO check for consistency among nodes |
| 835 | else: |
| 836 | main.log.error( "partitions() returned None" ) |
| 837 | except ( ValueError, TypeError ): |
| 838 | main.log.exception( "Error parsing partitions" ) |
| 839 | main.log.error( repr( partitions ) ) |
| 840 | # Print Pending Map |
| 841 | pendingMap = main.ONOScli1.pendingMap() |
| 842 | try: |
| 843 | if pendingMap : |
| 844 | parsedPending = json.loads( pendingMap ) |
| 845 | main.log.warn( json.dumps( parsedPending, |
| 846 | sort_keys=True, |
| 847 | indent=4, |
| 848 | separators=( ',', ': ' ) ) ) |
| 849 | # TODO check something here? |
| 850 | else: |
| 851 | main.log.error( "pendingMap() returned None" ) |
| 852 | except ( ValueError, TypeError ): |
| 853 | main.log.exception( "Error parsing pending map" ) |
| 854 | main.log.error( repr( pendingMap ) ) |
| 855 | |
| 856 | if not installedCheck: |
| 857 | main.log.info( "Waiting 60 seconds to see if the state of " + |
| 858 | "intents change" ) |
| 859 | time.sleep( 60 ) |
| 860 | # Print the intent states |
| 861 | intents = main.ONOScli1.intents() |
| 862 | intentStates = [] |
| 863 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 864 | count = 0 |
| 865 | # Iter through intents of a node |
| 866 | try: |
| 867 | for intent in json.loads( intents ): |
| 868 | state = intent.get( 'state', None ) |
| 869 | if "INSTALLED" not in state: |
| 870 | installedCheck = False |
| 871 | intentId = intent.get( 'id', None ) |
| 872 | intentStates.append( ( intentId, state ) ) |
| 873 | except ( ValueError, TypeError ): |
| 874 | main.log.exception( "Error parsing intents." ) |
| 875 | intentStates.sort() |
| 876 | for i, s in intentStates: |
| 877 | count += 1 |
| 878 | main.log.info( "%-6s%-15s%-15s" % |
| 879 | ( str( count ), str( i ), str( s ) ) ) |
| 880 | leaders = main.ONOScli1.leaders() |
| 881 | try: |
| 882 | missing = False |
| 883 | if leaders: |
| 884 | parsedLeaders = json.loads( leaders ) |
| 885 | main.log.warn( json.dumps( parsedLeaders, |
| 886 | sort_keys=True, |
| 887 | indent=4, |
| 888 | separators=( ',', ': ' ) ) ) |
| 889 | # check for all intent partitions |
| 890 | # check for election |
| 891 | topics = [] |
| 892 | for i in range( 14 ): |
| 893 | topics.append( "intent-partition-" + str( i ) ) |
| 894 | # FIXME: this should only be after we start the app |
| 895 | topics.append( "org.onosproject.election" ) |
| 896 | main.log.debug( topics ) |
| 897 | ONOStopics = [ j['topic'] for j in parsedLeaders ] |
| 898 | for topic in topics: |
| 899 | if topic not in ONOStopics: |
| 900 | main.log.error( "Error: " + topic + |
| 901 | " not in leaders" ) |
| 902 | missing = True |
| 903 | else: |
| 904 | main.log.error( "leaders() returned None" ) |
| 905 | except ( ValueError, TypeError ): |
| 906 | main.log.exception( "Error parsing leaders" ) |
| 907 | main.log.error( repr( leaders ) ) |
| 908 | if missing: |
| 909 | response = main.ONOScli1.leaders( jsonFormat=False) |
| 910 | main.log.warn( "ONOS1 leaders output: \n" + |
| 911 | str( response ) ) |
| 912 | partitions = main.ONOScli1.partitions() |
| 913 | try: |
| 914 | if partitions : |
| 915 | parsedPartitions = json.loads( partitions ) |
| 916 | main.log.warn( json.dumps( parsedPartitions, |
| 917 | sort_keys=True, |
| 918 | indent=4, |
| 919 | separators=( ',', ': ' ) ) ) |
| 920 | # TODO check for a leader in all paritions |
| 921 | # TODO check for consistency among nodes |
| 922 | else: |
| 923 | main.log.error( "partitions() returned None" ) |
| 924 | except ( ValueError, TypeError ): |
| 925 | main.log.exception( "Error parsing partitions" ) |
| 926 | main.log.error( repr( partitions ) ) |
| 927 | pendingMap = main.ONOScli1.pendingMap() |
| 928 | try: |
| 929 | if pendingMap : |
| 930 | parsedPending = json.loads( pendingMap ) |
| 931 | main.log.warn( json.dumps( parsedPending, |
| 932 | sort_keys=True, |
| 933 | indent=4, |
| 934 | separators=( ',', ': ' ) ) ) |
| 935 | # TODO check something here? |
| 936 | else: |
| 937 | main.log.error( "pendingMap() returned None" ) |
| 938 | except ( ValueError, TypeError ): |
| 939 | main.log.exception( "Error parsing pending map" ) |
| 940 | main.log.error( repr( pendingMap ) ) |
| 941 | # Print flowrules |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 942 | main.log.debug( main.CLIs[0].flows( jsonFormat=False ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 943 | main.step( "Wait a minute then ping again" ) |
| 944 | # the wait is above |
| 945 | PingResult = main.TRUE |
| 946 | for i in range( 8, 18 ): |
| 947 | ping = main.Mininet1.pingHost( src="h" + str( i ), |
| 948 | target="h" + str( i + 10 ) ) |
| 949 | PingResult = PingResult and ping |
| 950 | if ping == main.FALSE: |
| 951 | main.log.warn( "Ping failed between h" + str( i ) + |
| 952 | " and h" + str( i + 10 ) ) |
| 953 | elif ping == main.TRUE: |
| 954 | main.log.info( "Ping test passed!" ) |
| 955 | # Don't set PingResult or you'd override failures |
| 956 | if PingResult == main.FALSE: |
| 957 | main.log.error( |
| 958 | "Intents have not been installed correctly, pings failed." ) |
| 959 | # TODO: pretty print |
| 960 | main.log.warn( "ONOS1 intents: " ) |
| 961 | try: |
| 962 | tmpIntents = main.ONOScli1.intents() |
| 963 | main.log.warn( json.dumps( json.loads( tmpIntents ), |
| 964 | sort_keys=True, |
| 965 | indent=4, |
| 966 | separators=( ',', ': ' ) ) ) |
| 967 | except ( ValueError, TypeError ): |
| 968 | main.log.warn( repr( tmpIntents ) ) |
| 969 | utilities.assert_equals( |
| 970 | expect=main.TRUE, |
| 971 | actual=PingResult, |
| 972 | onpass="Intents have been installed correctly and pings work", |
| 973 | onfail="Intents have not been installed correctly, pings failed." ) |
| 974 | |
| 975 | def CASE5( self, main ): |
| 976 | """ |
| 977 | Reading state of ONOS |
| 978 | """ |
| 979 | import json |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 980 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 981 | assert main, "main not defined" |
| 982 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 983 | |
| 984 | main.case( "Setting up and gathering data for current state" ) |
| 985 | # The general idea for this test case is to pull the state of |
| 986 | # ( intents,flows, topology,... ) from each ONOS node |
| 987 | # We can then compare them with each other and also with past states |
| 988 | |
| 989 | main.step( "Check that each switch has a master" ) |
| 990 | global mastershipState |
| 991 | mastershipState = '[]' |
| 992 | |
| 993 | # Assert that each device has a master |
| 994 | rolesNotNull = main.ONOScli1.rolesNotNull() |
| 995 | utilities.assert_equals( |
| 996 | expect=main.TRUE, |
| 997 | actual=rolesNotNull, |
| 998 | onpass="Each device has a master", |
| 999 | onfail="Some devices don't have a master assigned" ) |
| 1000 | |
| 1001 | main.step( "Get the Mastership of each switch" ) |
| 1002 | ONOS1Mastership = main.ONOScli1.roles() |
| 1003 | # TODO: Make this a meaningful check |
| 1004 | if "Error" in ONOS1Mastership or not ONOS1Mastership: |
| 1005 | main.log.error( "Error in getting ONOS roles" ) |
| 1006 | main.log.warn( |
| 1007 | "ONOS1 mastership response: " + |
| 1008 | repr( ONOS1Mastership ) ) |
| 1009 | consistentMastership = main.FALSE |
| 1010 | else: |
| 1011 | mastershipState = ONOS1Mastership |
| 1012 | consistentMastership = main.TRUE |
| 1013 | |
| 1014 | main.step( "Get the intents from each controller" ) |
| 1015 | global intentState |
| 1016 | intentState = [] |
| 1017 | ONOS1Intents = main.ONOScli1.intents( jsonFormat=True ) |
| 1018 | intentCheck = main.FALSE |
| 1019 | if "Error" in ONOS1Intents or not ONOS1Intents: |
| 1020 | main.log.error( "Error in getting ONOS intents" ) |
| 1021 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) ) |
| 1022 | else: |
| 1023 | intentCheck = main.TRUE |
| 1024 | |
| 1025 | main.step( "Get the flows from each controller" ) |
| 1026 | global flowState |
| 1027 | flowState = [] |
| 1028 | flowCheck = main.FALSE |
| 1029 | ONOS1Flows = main.ONOScli1.flows( jsonFormat=True ) |
| 1030 | if "Error" in ONOS1Flows or not ONOS1Flows: |
| 1031 | main.log.error( "Error in getting ONOS flows" ) |
| 1032 | main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows ) |
| 1033 | else: |
| 1034 | # TODO: Do a better check, maybe compare flows on switches? |
| 1035 | flowState = ONOS1Flows |
| 1036 | flowCheck = main.TRUE |
| 1037 | |
| 1038 | main.step( "Get the OF Table entries" ) |
| 1039 | global flows |
| 1040 | flows = [] |
| 1041 | for i in range( 1, 29 ): |
Jon Hall | 9043c90 | 2015-07-30 14:23:44 -0700 | [diff] [blame] | 1042 | flows.append( main.Mininet1.getFlowTable( 1.3, "s" + str( i ) ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1043 | if flowCheck == main.FALSE: |
| 1044 | for table in flows: |
| 1045 | main.log.warn( table ) |
| 1046 | # TODO: Compare switch flow tables with ONOS flow tables |
| 1047 | |
| 1048 | main.step( "Collecting topology information from ONOS" ) |
| 1049 | devices = [] |
| 1050 | devices.append( main.ONOScli1.devices() ) |
| 1051 | hosts = [] |
| 1052 | hosts.append( json.loads( main.ONOScli1.hosts() ) ) |
| 1053 | ports = [] |
| 1054 | ports.append( main.ONOScli1.ports() ) |
| 1055 | links = [] |
| 1056 | links.append( main.ONOScli1.links() ) |
| 1057 | clusters = [] |
| 1058 | clusters.append( main.ONOScli1.clusters() ) |
| 1059 | |
| 1060 | main.step( "Each host has an IP address" ) |
| 1061 | ipResult = main.TRUE |
| 1062 | for controller in range( 0, len( hosts ) ): |
| 1063 | controllerStr = str( controller + 1 ) |
| 1064 | for host in hosts[ controller ]: |
| 1065 | if host is None or host.get( 'ipAddresses', [] ) == []: |
| 1066 | main.log.error( |
| 1067 | "DEBUG:Error with host ips on controller" + |
| 1068 | controllerStr + ": " + str( host ) ) |
| 1069 | ipResult = main.FALSE |
| 1070 | utilities.assert_equals( |
| 1071 | expect=main.TRUE, |
| 1072 | actual=ipResult, |
| 1073 | onpass="The ips of the hosts aren't empty", |
| 1074 | onfail="The ip of at least one host is missing" ) |
| 1075 | |
| 1076 | # there should always only be one cluster |
| 1077 | main.step( "There is only one dataplane cluster" ) |
| 1078 | try: |
| 1079 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
| 1080 | except ( ValueError, TypeError ): |
| 1081 | main.log.exception( "Error parsing clusters[0]: " + |
| 1082 | repr( clusters[ 0 ] ) ) |
| 1083 | clusterResults = main.FALSE |
| 1084 | if numClusters == 1: |
| 1085 | clusterResults = main.TRUE |
| 1086 | utilities.assert_equals( |
| 1087 | expect=1, |
| 1088 | actual=numClusters, |
| 1089 | onpass="ONOS shows 1 SCC", |
| 1090 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
| 1091 | |
| 1092 | main.step( "Comparing ONOS topology to MN" ) |
| 1093 | devicesResults = main.TRUE |
| 1094 | linksResults = main.TRUE |
| 1095 | hostsResults = main.TRUE |
| 1096 | mnSwitches = main.Mininet1.getSwitches() |
| 1097 | mnLinks = main.Mininet1.getLinks() |
| 1098 | mnHosts = main.Mininet1.getHosts() |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1099 | for controller in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1100 | controllerStr = str( controller + 1 ) |
| 1101 | if devices[ controller ] and ports[ controller ] and\ |
| 1102 | "Error" not in devices[ controller ] and\ |
| 1103 | "Error" not in ports[ controller ]: |
| 1104 | |
| 1105 | currentDevicesResult = main.Mininet1.compareSwitches( |
| 1106 | mnSwitches, |
| 1107 | json.loads( devices[ controller ] ), |
| 1108 | json.loads( ports[ controller ] ) ) |
| 1109 | else: |
| 1110 | currentDevicesResult = main.FALSE |
| 1111 | utilities.assert_equals( expect=main.TRUE, |
| 1112 | actual=currentDevicesResult, |
| 1113 | onpass="ONOS" + controllerStr + |
| 1114 | " Switches view is correct", |
| 1115 | onfail="ONOS" + controllerStr + |
| 1116 | " Switches view is incorrect" ) |
| 1117 | if links[ controller ] and "Error" not in links[ controller ]: |
| 1118 | currentLinksResult = main.Mininet1.compareLinks( |
| 1119 | mnSwitches, mnLinks, |
| 1120 | json.loads( links[ controller ] ) ) |
| 1121 | else: |
| 1122 | currentLinksResult = main.FALSE |
| 1123 | utilities.assert_equals( expect=main.TRUE, |
| 1124 | actual=currentLinksResult, |
| 1125 | onpass="ONOS" + controllerStr + |
| 1126 | " links view is correct", |
| 1127 | onfail="ONOS" + controllerStr + |
| 1128 | " links view is incorrect" ) |
| 1129 | |
| 1130 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 1131 | currentHostsResult = main.Mininet1.compareHosts( |
| 1132 | mnHosts, |
| 1133 | hosts[ controller ] ) |
| 1134 | else: |
| 1135 | currentHostsResult = main.FALSE |
| 1136 | utilities.assert_equals( expect=main.TRUE, |
| 1137 | actual=currentHostsResult, |
| 1138 | onpass="ONOS" + controllerStr + |
| 1139 | " hosts exist in Mininet", |
| 1140 | onfail="ONOS" + controllerStr + |
| 1141 | " hosts don't match Mininet" ) |
| 1142 | |
| 1143 | devicesResults = devicesResults and currentDevicesResult |
| 1144 | linksResults = linksResults and currentLinksResult |
| 1145 | hostsResults = hostsResults and currentHostsResult |
| 1146 | |
| 1147 | main.step( "Device information is correct" ) |
| 1148 | utilities.assert_equals( |
| 1149 | expect=main.TRUE, |
| 1150 | actual=devicesResults, |
| 1151 | onpass="Device information is correct", |
| 1152 | onfail="Device information is incorrect" ) |
| 1153 | |
| 1154 | main.step( "Links are correct" ) |
| 1155 | utilities.assert_equals( |
| 1156 | expect=main.TRUE, |
| 1157 | actual=linksResults, |
| 1158 | onpass="Link are correct", |
| 1159 | onfail="Links are incorrect" ) |
| 1160 | |
| 1161 | main.step( "Hosts are correct" ) |
| 1162 | utilities.assert_equals( |
| 1163 | expect=main.TRUE, |
| 1164 | actual=hostsResults, |
| 1165 | onpass="Hosts are correct", |
| 1166 | onfail="Hosts are incorrect" ) |
| 1167 | |
| 1168 | def CASE6( self, main ): |
| 1169 | """ |
| 1170 | The Failure case. |
| 1171 | """ |
| 1172 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1173 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1174 | assert main, "main not defined" |
| 1175 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1176 | |
| 1177 | # Reset non-persistent variables |
| 1178 | try: |
| 1179 | iCounterValue = 0 |
| 1180 | except NameError: |
| 1181 | main.log.error( "iCounterValue not defined, setting to 0" ) |
| 1182 | iCounterValue = 0 |
| 1183 | |
| 1184 | main.case( "Restart ONOS node" ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 1185 | main.caseExplanation = "Killing ONOS process and restart cli " +\ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1186 | "sessions once onos is up." |
| 1187 | main.step( "Killing ONOS processes" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1188 | killResult = main.ONOSbench.onosKill( main.nodes[0].ip_address ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1189 | start = time.time() |
| 1190 | utilities.assert_equals( expect=main.TRUE, actual=killResult, |
| 1191 | onpass="ONOS Killed", |
| 1192 | onfail="Error killing ONOS" ) |
| 1193 | |
| 1194 | main.step( "Checking if ONOS is up yet" ) |
| 1195 | count = 0 |
| 1196 | while count < 10: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1197 | onos1Isup = main.ONOSbench.isup( main.nodes[0].ip_address ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1198 | if onos1Isup == main.TRUE: |
| 1199 | elapsed = time.time() - start |
| 1200 | break |
| 1201 | else: |
| 1202 | count = count + 1 |
| 1203 | utilities.assert_equals( expect=main.TRUE, actual=onos1Isup, |
| 1204 | onpass="ONOS is back up", |
| 1205 | onfail="ONOS failed to start" ) |
| 1206 | |
| 1207 | main.log.step( "Starting ONOS CLI sessions" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1208 | cliResults = main.ONOScli1.startOnosCli( main.nodes[0].ip_address ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1209 | utilities.assert_equals( expect=main.TRUE, actual=cliResults, |
| 1210 | onpass="ONOS cli startup successful", |
| 1211 | onfail="ONOS cli startup failed" ) |
| 1212 | |
| 1213 | if elapsed: |
| 1214 | main.log.info( "ESTIMATE: ONOS took %s seconds to restart" % |
| 1215 | str( elapsed ) ) |
| 1216 | main.restartTime = elapsed |
| 1217 | else: |
| 1218 | main.restartTime = -1 |
| 1219 | time.sleep( 5 ) |
| 1220 | # rerun on election apps |
| 1221 | main.ONOScli1.electionTestRun() |
| 1222 | |
| 1223 | def CASE7( self, main ): |
| 1224 | """ |
| 1225 | Check state after ONOS failure |
| 1226 | """ |
| 1227 | import json |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1228 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1229 | assert main, "main not defined" |
| 1230 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1231 | main.case( "Running ONOS Constant State Tests" ) |
| 1232 | main.step( "Check that each switch has a master" ) |
| 1233 | # Assert that each device has a master |
| 1234 | rolesNotNull = main.ONOScli1.rolesNotNull() |
| 1235 | utilities.assert_equals( |
| 1236 | expect=main.TRUE, |
| 1237 | actual=rolesNotNull, |
| 1238 | onpass="Each device has a master", |
| 1239 | onfail="Some devices don't have a master assigned" ) |
| 1240 | |
| 1241 | main.step( "Check if switch roles are consistent across all nodes" ) |
| 1242 | ONOS1Mastership = main.ONOScli1.roles() |
| 1243 | # FIXME: Refactor this whole case for single instance |
| 1244 | if "Error" in ONOS1Mastership or not ONOS1Mastership: |
| 1245 | main.log.error( "Error in getting ONOS mastership" ) |
| 1246 | main.log.warn( "ONOS1 mastership response: " + |
| 1247 | repr( ONOS1Mastership ) ) |
| 1248 | consistentMastership = main.FALSE |
| 1249 | else: |
| 1250 | consistentMastership = main.TRUE |
| 1251 | utilities.assert_equals( |
| 1252 | expect=main.TRUE, |
| 1253 | actual=consistentMastership, |
| 1254 | onpass="Switch roles are consistent across all ONOS nodes", |
| 1255 | onfail="ONOS nodes have different views of switch roles" ) |
| 1256 | |
| 1257 | description2 = "Compare switch roles from before failure" |
| 1258 | main.step( description2 ) |
| 1259 | |
| 1260 | currentJson = json.loads( ONOS1Mastership ) |
| 1261 | oldJson = json.loads( mastershipState ) |
| 1262 | mastershipCheck = main.TRUE |
| 1263 | for i in range( 1, 29 ): |
| 1264 | switchDPID = str( |
| 1265 | main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) ) |
| 1266 | |
| 1267 | current = [ switch[ 'master' ] for switch in currentJson |
| 1268 | if switchDPID in switch[ 'id' ] ] |
| 1269 | old = [ switch[ 'master' ] for switch in oldJson |
| 1270 | if switchDPID in switch[ 'id' ] ] |
| 1271 | if current == old: |
| 1272 | mastershipCheck = mastershipCheck and main.TRUE |
| 1273 | else: |
| 1274 | main.log.warn( "Mastership of switch %s changed" % switchDPID ) |
| 1275 | mastershipCheck = main.FALSE |
| 1276 | utilities.assert_equals( |
| 1277 | expect=main.TRUE, |
| 1278 | actual=mastershipCheck, |
| 1279 | onpass="Mastership of Switches was not changed", |
| 1280 | onfail="Mastership of some switches changed" ) |
| 1281 | mastershipCheck = mastershipCheck and consistentMastership |
| 1282 | |
| 1283 | main.step( "Get the intents and compare across all nodes" ) |
| 1284 | ONOS1Intents = main.ONOScli1.intents( jsonFormat=True ) |
| 1285 | intentCheck = main.FALSE |
| 1286 | if "Error" in ONOS1Intents or not ONOS1Intents: |
| 1287 | main.log.error( "Error in getting ONOS intents" ) |
| 1288 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) ) |
| 1289 | else: |
| 1290 | intentCheck = main.TRUE |
| 1291 | utilities.assert_equals( |
| 1292 | expect=main.TRUE, |
| 1293 | actual=intentCheck, |
| 1294 | onpass="Intents are consistent across all ONOS nodes", |
| 1295 | onfail="ONOS nodes have different views of intents" ) |
| 1296 | # Print the intent states |
| 1297 | intents = [] |
| 1298 | intents.append( ONOS1Intents ) |
| 1299 | intentStates = [] |
| 1300 | for node in intents: # Iter through ONOS nodes |
| 1301 | nodeStates = [] |
| 1302 | # Iter through intents of a node |
| 1303 | for intent in json.loads( node ): |
| 1304 | nodeStates.append( intent[ 'state' ] ) |
| 1305 | intentStates.append( nodeStates ) |
| 1306 | out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ] |
| 1307 | main.log.info( dict( out ) ) |
| 1308 | |
| 1309 | # NOTE: Store has no durability, so intents are lost across system |
| 1310 | # restarts |
| 1311 | """ |
| 1312 | main.step( "Compare current intents with intents before the failure" ) |
| 1313 | # NOTE: this requires case 5 to pass for intentState to be set. |
| 1314 | # maybe we should stop the test if that fails? |
| 1315 | sameIntents = main.FALSE |
| 1316 | if intentState and intentState == ONOSIntents[ 0 ]: |
| 1317 | sameIntents = main.TRUE |
| 1318 | main.log.info( "Intents are consistent with before failure" ) |
| 1319 | # TODO: possibly the states have changed? we may need to figure out |
| 1320 | # what the acceptable states are |
| 1321 | elif len( intentState ) == len( ONOSIntents[ 0 ] ): |
| 1322 | sameIntents = main.TRUE |
| 1323 | try: |
| 1324 | before = json.loads( intentState ) |
| 1325 | after = json.loads( ONOSIntents[ 0 ] ) |
| 1326 | for intent in before: |
| 1327 | if intent not in after: |
| 1328 | sameIntents = main.FALSE |
| 1329 | main.log.debug( "Intent is not currently in ONOS " + |
| 1330 | "(at least in the same form):" ) |
| 1331 | main.log.debug( json.dumps( intent ) ) |
| 1332 | except ( ValueError, TypeError ): |
| 1333 | main.log.exception( "Exception printing intents" ) |
| 1334 | main.log.debug( repr( ONOSIntents[0] ) ) |
| 1335 | main.log.debug( repr( intentState ) ) |
| 1336 | if sameIntents == main.FALSE: |
| 1337 | try: |
| 1338 | main.log.debug( "ONOS intents before: " ) |
| 1339 | main.log.debug( json.dumps( json.loads( intentState ), |
| 1340 | sort_keys=True, indent=4, |
| 1341 | separators=( ',', ': ' ) ) ) |
| 1342 | main.log.debug( "Current ONOS intents: " ) |
| 1343 | main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ), |
| 1344 | sort_keys=True, indent=4, |
| 1345 | separators=( ',', ': ' ) ) ) |
| 1346 | except ( ValueError, TypeError ): |
| 1347 | main.log.exception( "Exception printing intents" ) |
| 1348 | main.log.debug( repr( ONOSIntents[0] ) ) |
| 1349 | main.log.debug( repr( intentState ) ) |
| 1350 | utilities.assert_equals( |
| 1351 | expect=main.TRUE, |
| 1352 | actual=sameIntents, |
| 1353 | onpass="Intents are consistent with before failure", |
| 1354 | onfail="The Intents changed during failure" ) |
| 1355 | intentCheck = intentCheck and sameIntents |
| 1356 | """ |
| 1357 | main.step( "Get the OF Table entries and compare to before " + |
| 1358 | "component failure" ) |
| 1359 | FlowTables = main.TRUE |
| 1360 | flows2 = [] |
| 1361 | for i in range( 28 ): |
| 1362 | main.log.info( "Checking flow table on s" + str( i + 1 ) ) |
Jon Hall | 9043c90 | 2015-07-30 14:23:44 -0700 | [diff] [blame] | 1363 | tmpFlows = main.Mininet1.getFlowTable( 1.3, "s" + str( i + 1 ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1364 | flows2.append( tmpFlows ) |
Jon Hall | 9043c90 | 2015-07-30 14:23:44 -0700 | [diff] [blame] | 1365 | tempResult = main.Mininet1.flowComp( |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1366 | flow1=flows[ i ], |
| 1367 | flow2=tmpFlows ) |
| 1368 | FlowTables = FlowTables and tempResult |
| 1369 | if FlowTables == main.FALSE: |
| 1370 | main.log.info( "Differences in flow table for switch: s" + |
| 1371 | str( i + 1 ) ) |
| 1372 | utilities.assert_equals( |
| 1373 | expect=main.TRUE, |
| 1374 | actual=FlowTables, |
| 1375 | onpass="No changes were found in the flow tables", |
| 1376 | onfail="Changes were found in the flow tables" ) |
| 1377 | |
| 1378 | main.step( "Leadership Election is still functional" ) |
| 1379 | # Test of LeadershipElection |
| 1380 | |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1381 | leader = main.nodes[0].ip_address |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1382 | leaderResult = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1383 | for controller in range( 1, main.numCtrls + 1 ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1384 | # loop through ONOScli handlers |
| 1385 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
| 1386 | leaderN = node.electionTestLeader() |
| 1387 | # verify leader is ONOS1 |
| 1388 | # NOTE even though we restarted ONOS, it is the only one so onos 1 |
| 1389 | # must be leader |
| 1390 | if leaderN == leader: |
| 1391 | # all is well |
| 1392 | pass |
| 1393 | elif leaderN == main.FALSE: |
| 1394 | # error in response |
| 1395 | main.log.error( "Something is wrong with " + |
| 1396 | "electionTestLeader function, check the" + |
| 1397 | " error logs" ) |
| 1398 | leaderResult = main.FALSE |
| 1399 | elif leader != leaderN: |
| 1400 | leaderResult = main.FALSE |
| 1401 | main.log.error( "ONOS" + str( controller ) + " sees " + |
| 1402 | str( leaderN ) + |
| 1403 | " as the leader of the election app. " + |
| 1404 | "Leader should be " + str( leader ) ) |
| 1405 | utilities.assert_equals( |
| 1406 | expect=main.TRUE, |
| 1407 | actual=leaderResult, |
| 1408 | onpass="Leadership election passed", |
| 1409 | onfail="Something went wrong with Leadership election" ) |
| 1410 | |
| 1411 | def CASE8( self, main ): |
| 1412 | """ |
| 1413 | Compare topo |
| 1414 | """ |
| 1415 | import json |
| 1416 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1417 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1418 | assert main, "main not defined" |
| 1419 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1420 | |
| 1421 | main.case( "Compare ONOS Topology view to Mininet topology" ) |
Jon Hall | 783bbf9 | 2015-07-23 14:33:19 -0700 | [diff] [blame] | 1422 | main.caseExplanation = "Compare topology objects between Mininet" +\ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1423 | " and ONOS" |
| 1424 | |
| 1425 | main.step( "Comparing ONOS topology to MN" ) |
| 1426 | devicesResults = main.TRUE |
| 1427 | linksResults = main.TRUE |
| 1428 | hostsResults = main.TRUE |
| 1429 | hostAttachmentResults = True |
| 1430 | topoResult = main.FALSE |
| 1431 | elapsed = 0 |
| 1432 | count = 0 |
| 1433 | main.step( "Collecting topology information from ONOS" ) |
| 1434 | startTime = time.time() |
| 1435 | # Give time for Gossip to work |
| 1436 | while topoResult == main.FALSE and elapsed < 60: |
| 1437 | count += 1 |
| 1438 | cliStart = time.time() |
| 1439 | devices = [] |
| 1440 | devices.append( main.ONOScli1.devices() ) |
| 1441 | hosts = [] |
| 1442 | hosts.append( json.loads( main.ONOScli1.hosts() ) ) |
| 1443 | ipResult = main.TRUE |
| 1444 | for controller in range( 0, len( hosts ) ): |
| 1445 | controllerStr = str( controller + 1 ) |
| 1446 | for host in hosts[ controller ]: |
| 1447 | if host is None or host.get( 'ipAddresses', [] ) == []: |
| 1448 | main.log.error( |
| 1449 | "DEBUG:Error with host ips on controller" + |
| 1450 | controllerStr + ": " + str( host ) ) |
| 1451 | ipResult = main.FALSE |
| 1452 | ports = [] |
| 1453 | ports.append( main.ONOScli1.ports() ) |
| 1454 | links = [] |
| 1455 | links.append( main.ONOScli1.links() ) |
| 1456 | clusters = [] |
| 1457 | clusters.append( main.ONOScli1.clusters() ) |
| 1458 | |
| 1459 | elapsed = time.time() - startTime |
| 1460 | cliTime = time.time() - cliStart |
| 1461 | print "CLI time: " + str( cliTime ) |
| 1462 | |
| 1463 | mnSwitches = main.Mininet1.getSwitches() |
| 1464 | mnLinks = main.Mininet1.getLinks() |
| 1465 | mnHosts = main.Mininet1.getHosts() |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1466 | for controller in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1467 | controllerStr = str( controller + 1 ) |
| 1468 | if devices[ controller ] and ports[ controller ] and\ |
| 1469 | "Error" not in devices[ controller ] and\ |
| 1470 | "Error" not in ports[ controller ]: |
| 1471 | |
| 1472 | currentDevicesResult = main.Mininet1.compareSwitches( |
| 1473 | mnSwitches, |
| 1474 | json.loads( devices[ controller ] ), |
| 1475 | json.loads( ports[ controller ] ) ) |
| 1476 | else: |
| 1477 | currentDevicesResult = main.FALSE |
| 1478 | utilities.assert_equals( expect=main.TRUE, |
| 1479 | actual=currentDevicesResult, |
| 1480 | onpass="ONOS" + controllerStr + |
| 1481 | " Switches view is correct", |
| 1482 | onfail="ONOS" + controllerStr + |
| 1483 | " Switches view is incorrect" ) |
| 1484 | |
| 1485 | if links[ controller ] and "Error" not in links[ controller ]: |
| 1486 | currentLinksResult = main.Mininet1.compareLinks( |
| 1487 | mnSwitches, mnLinks, |
| 1488 | json.loads( links[ controller ] ) ) |
| 1489 | else: |
| 1490 | currentLinksResult = main.FALSE |
| 1491 | utilities.assert_equals( expect=main.TRUE, |
| 1492 | actual=currentLinksResult, |
| 1493 | onpass="ONOS" + controllerStr + |
| 1494 | " links view is correct", |
| 1495 | onfail="ONOS" + controllerStr + |
| 1496 | " links view is incorrect" ) |
| 1497 | |
| 1498 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 1499 | currentHostsResult = main.Mininet1.compareHosts( |
| 1500 | mnHosts, |
| 1501 | hosts[ controller ] ) |
| 1502 | else: |
| 1503 | currentHostsResult = main.FALSE |
| 1504 | utilities.assert_equals( expect=main.TRUE, |
| 1505 | actual=currentHostsResult, |
| 1506 | onpass="ONOS" + controllerStr + |
| 1507 | " hosts exist in Mininet", |
| 1508 | onfail="ONOS" + controllerStr + |
| 1509 | " hosts don't match Mininet" ) |
| 1510 | # CHECKING HOST ATTACHMENT POINTS |
| 1511 | hostAttachment = True |
| 1512 | zeroHosts = False |
| 1513 | # FIXME: topo-HA/obelisk specific mappings: |
| 1514 | # key is mac and value is dpid |
| 1515 | mappings = {} |
| 1516 | for i in range( 1, 29 ): # hosts 1 through 28 |
| 1517 | # set up correct variables: |
| 1518 | macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2) |
| 1519 | if i == 1: |
| 1520 | deviceId = "1000".zfill(16) |
| 1521 | elif i == 2: |
| 1522 | deviceId = "2000".zfill(16) |
| 1523 | elif i == 3: |
| 1524 | deviceId = "3000".zfill(16) |
| 1525 | elif i == 4: |
| 1526 | deviceId = "3004".zfill(16) |
| 1527 | elif i == 5: |
| 1528 | deviceId = "5000".zfill(16) |
| 1529 | elif i == 6: |
| 1530 | deviceId = "6000".zfill(16) |
| 1531 | elif i == 7: |
| 1532 | deviceId = "6007".zfill(16) |
| 1533 | elif i >= 8 and i <= 17: |
| 1534 | dpid = '3' + str( i ).zfill( 3 ) |
| 1535 | deviceId = dpid.zfill(16) |
| 1536 | elif i >= 18 and i <= 27: |
| 1537 | dpid = '6' + str( i ).zfill( 3 ) |
| 1538 | deviceId = dpid.zfill(16) |
| 1539 | elif i == 28: |
| 1540 | deviceId = "2800".zfill(16) |
| 1541 | mappings[ macId ] = deviceId |
| 1542 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 1543 | if hosts[ controller ] == []: |
| 1544 | main.log.warn( "There are no hosts discovered" ) |
| 1545 | zeroHosts = True |
| 1546 | else: |
| 1547 | for host in hosts[ controller ]: |
| 1548 | mac = None |
| 1549 | location = None |
| 1550 | device = None |
| 1551 | port = None |
| 1552 | try: |
| 1553 | mac = host.get( 'mac' ) |
| 1554 | assert mac, "mac field could not be found for this host object" |
| 1555 | |
| 1556 | location = host.get( 'location' ) |
| 1557 | assert location, "location field could not be found for this host object" |
| 1558 | |
| 1559 | # Trim the protocol identifier off deviceId |
| 1560 | device = str( location.get( 'elementId' ) ).split(':')[1] |
| 1561 | assert device, "elementId field could not be found for this host location object" |
| 1562 | |
| 1563 | port = location.get( 'port' ) |
| 1564 | assert port, "port field could not be found for this host location object" |
| 1565 | |
| 1566 | # Now check if this matches where they should be |
| 1567 | if mac and device and port: |
| 1568 | if str( port ) != "1": |
| 1569 | main.log.error( "The attachment port is incorrect for " + |
| 1570 | "host " + str( mac ) + |
| 1571 | ". Expected: 1 Actual: " + str( port) ) |
| 1572 | hostAttachment = False |
| 1573 | if device != mappings[ str( mac ) ]: |
| 1574 | main.log.error( "The attachment device is incorrect for " + |
| 1575 | "host " + str( mac ) + |
| 1576 | ". Expected: " + mappings[ str( mac ) ] + |
| 1577 | " Actual: " + device ) |
| 1578 | hostAttachment = False |
| 1579 | else: |
| 1580 | hostAttachment = False |
| 1581 | except AssertionError: |
| 1582 | main.log.exception( "Json object not as expected" ) |
| 1583 | main.log.error( repr( host ) ) |
| 1584 | hostAttachment = False |
| 1585 | else: |
| 1586 | main.log.error( "No hosts json output or \"Error\"" + |
| 1587 | " in output. hosts = " + |
| 1588 | repr( hosts[ controller ] ) ) |
| 1589 | if zeroHosts is False: |
| 1590 | hostAttachment = True |
| 1591 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1592 | devicesResults = devicesResults and currentDevicesResult |
| 1593 | linksResults = linksResults and currentLinksResult |
| 1594 | hostsResults = hostsResults and currentHostsResult |
| 1595 | hostAttachmentResults = hostAttachmentResults and\ |
| 1596 | hostAttachment |
| 1597 | |
| 1598 | # "consistent" results don't make sense for single instance |
| 1599 | # there should always only be one cluster |
| 1600 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
| 1601 | clusterResults = main.FALSE |
| 1602 | if numClusters == 1: |
| 1603 | clusterResults = main.TRUE |
| 1604 | utilities.assert_equals( |
| 1605 | expect=1, |
| 1606 | actual=numClusters, |
| 1607 | onpass="ONOS shows 1 SCC", |
| 1608 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
| 1609 | |
| 1610 | topoResult = ( devicesResults and linksResults |
| 1611 | and hostsResults and ipResult and clusterResults and |
| 1612 | hostAttachmentResults ) |
| 1613 | |
| 1614 | topoResult = topoResult and int( count <= 2 ) |
| 1615 | note = "note it takes about " + str( int( cliTime ) ) + \ |
| 1616 | " seconds for the test to make all the cli calls to fetch " +\ |
| 1617 | "the topology from each ONOS instance" |
| 1618 | main.log.info( |
| 1619 | "Very crass estimate for topology discovery/convergence( " + |
| 1620 | str( note ) + " ): " + str( elapsed ) + " seconds, " + |
| 1621 | str( count ) + " tries" ) |
| 1622 | utilities.assert_equals( expect=main.TRUE, actual=topoResult, |
| 1623 | onpass="Topology Check Test successful", |
| 1624 | onfail="Topology Check Test NOT successful" ) |
| 1625 | |
| 1626 | def CASE9( self, main ): |
| 1627 | """ |
| 1628 | Link s3-s28 down |
| 1629 | """ |
| 1630 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1631 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1632 | assert main, "main not defined" |
| 1633 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1634 | # NOTE: You should probably run a topology check after this |
| 1635 | |
| 1636 | linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 1637 | |
| 1638 | description = "Turn off a link to ensure that Link Discovery " +\ |
| 1639 | "is working properly" |
| 1640 | main.case( description ) |
| 1641 | |
| 1642 | main.step( "Kill Link between s3 and s28" ) |
| 1643 | LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" ) |
| 1644 | main.log.info( "Waiting " + str( linkSleep ) + |
| 1645 | " seconds for link down to be discovered" ) |
| 1646 | time.sleep( linkSleep ) |
| 1647 | utilities.assert_equals( expect=main.TRUE, actual=LinkDown, |
| 1648 | onpass="Link down successful", |
| 1649 | onfail="Failed to bring link down" ) |
| 1650 | # TODO do some sort of check here |
| 1651 | |
| 1652 | def CASE10( self, main ): |
| 1653 | """ |
| 1654 | Link s3-s28 up |
| 1655 | """ |
| 1656 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1657 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1658 | assert main, "main not defined" |
| 1659 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1660 | # NOTE: You should probably run a topology check after this |
| 1661 | |
| 1662 | linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 1663 | |
| 1664 | description = "Restore a link to ensure that Link Discovery is " + \ |
| 1665 | "working properly" |
| 1666 | main.case( description ) |
| 1667 | |
| 1668 | main.step( "Bring link between s3 and s28 back up" ) |
| 1669 | LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" ) |
| 1670 | main.log.info( "Waiting " + str( linkSleep ) + |
| 1671 | " seconds for link up to be discovered" ) |
| 1672 | time.sleep( linkSleep ) |
| 1673 | utilities.assert_equals( expect=main.TRUE, actual=LinkUp, |
| 1674 | onpass="Link up successful", |
| 1675 | onfail="Failed to bring link up" ) |
| 1676 | # TODO do some sort of check here |
| 1677 | |
| 1678 | def CASE11( self, main ): |
| 1679 | """ |
| 1680 | Switch Down |
| 1681 | """ |
| 1682 | # NOTE: You should probably run a topology check after this |
| 1683 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1684 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1685 | assert main, "main not defined" |
| 1686 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1687 | |
| 1688 | switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 1689 | |
| 1690 | description = "Killing a switch to ensure it is discovered correctly" |
| 1691 | main.case( description ) |
| 1692 | switch = main.params[ 'kill' ][ 'switch' ] |
| 1693 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
| 1694 | |
| 1695 | # TODO: Make this switch parameterizable |
| 1696 | main.step( "Kill " + switch ) |
| 1697 | main.log.info( "Deleting " + switch ) |
| 1698 | main.Mininet1.delSwitch( switch ) |
| 1699 | main.log.info( "Waiting " + str( switchSleep ) + |
| 1700 | " seconds for switch down to be discovered" ) |
| 1701 | time.sleep( switchSleep ) |
| 1702 | device = main.ONOScli1.getDevice( dpid=switchDPID ) |
| 1703 | # Peek at the deleted switch |
| 1704 | main.log.warn( str( device ) ) |
| 1705 | result = main.FALSE |
| 1706 | if device and device[ 'available' ] is False: |
| 1707 | result = main.TRUE |
| 1708 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 1709 | onpass="Kill switch successful", |
| 1710 | onfail="Failed to kill switch?" ) |
| 1711 | |
| 1712 | def CASE12( self, main ): |
| 1713 | """ |
| 1714 | Switch Up |
| 1715 | """ |
| 1716 | # NOTE: You should probably run a topology check after this |
| 1717 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1718 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1719 | assert main, "main not defined" |
| 1720 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1721 | |
| 1722 | switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 1723 | switch = main.params[ 'kill' ][ 'switch' ] |
| 1724 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
| 1725 | links = main.params[ 'kill' ][ 'links' ].split() |
| 1726 | description = "Adding a switch to ensure it is discovered correctly" |
| 1727 | main.case( description ) |
| 1728 | |
| 1729 | main.step( "Add back " + switch ) |
| 1730 | main.Mininet1.addSwitch( switch, dpid=switchDPID ) |
| 1731 | for peer in links: |
| 1732 | main.Mininet1.addLink( switch, peer ) |
| 1733 | ipList = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1734 | for i in range( main.numCtrls ): |
| 1735 | ipList.append( main.nodes[ i ].ip_address ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1736 | main.Mininet1.assignSwController( sw=switch, ip=ipList ) |
| 1737 | main.log.info( "Waiting " + str( switchSleep ) + |
| 1738 | " seconds for switch up to be discovered" ) |
| 1739 | time.sleep( switchSleep ) |
| 1740 | device = main.ONOScli1.getDevice( dpid=switchDPID ) |
| 1741 | # Peek at the deleted switch |
| 1742 | main.log.warn( str( device ) ) |
| 1743 | result = main.FALSE |
| 1744 | if device and device[ 'available' ]: |
| 1745 | result = main.TRUE |
| 1746 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 1747 | onpass="add switch successful", |
| 1748 | onfail="Failed to add switch?" ) |
| 1749 | |
| 1750 | def CASE13( self, main ): |
| 1751 | """ |
| 1752 | Clean up |
| 1753 | """ |
| 1754 | import os |
| 1755 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1756 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1757 | assert main, "main not defined" |
| 1758 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1759 | # printing colors to terminal |
| 1760 | colors = { 'cyan': '\033[96m', 'purple': '\033[95m', |
| 1761 | 'blue': '\033[94m', 'green': '\033[92m', |
| 1762 | 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' } |
| 1763 | main.case( "Test Cleanup" ) |
| 1764 | main.step( "Killing tcpdumps" ) |
| 1765 | main.Mininet2.stopTcpdump() |
| 1766 | |
| 1767 | testname = main.TEST |
| 1768 | if main.params[ 'BACKUP' ] == "True": |
| 1769 | main.step( "Copying MN pcap and ONOS log files to test station" ) |
| 1770 | teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ] |
| 1771 | teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ] |
| 1772 | # NOTE: MN Pcap file is being saved to ~/packet_captures |
| 1773 | # scp this file as MN and TestON aren't necessarily the same vm |
| 1774 | # FIXME: scp |
| 1775 | # mn files |
| 1776 | # TODO: Load these from params |
| 1777 | # NOTE: must end in / |
| 1778 | logFolder = "/opt/onos/log/" |
| 1779 | logFiles = [ "karaf.log", "karaf.log.1" ] |
| 1780 | # NOTE: must end in / |
| 1781 | dstDir = "~/packet_captures/" |
| 1782 | for f in logFiles: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1783 | main.ONOSbench.handle.sendline( "scp sdn@" + main.nodes[0].ip_address + ":" + |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1784 | logFolder + f + " " + |
| 1785 | teststationUser + "@" + |
| 1786 | teststationIP + ":" + dstDir + |
| 1787 | str( testname ) + "-ONOS1-" + f ) |
| 1788 | main.ONOSbench.handle.expect( "\$" ) |
| 1789 | |
| 1790 | # std*.log's |
| 1791 | # NOTE: must end in / |
| 1792 | logFolder = "/opt/onos/var/" |
| 1793 | logFiles = [ "stderr.log", "stdout.log" ] |
| 1794 | # NOTE: must end in / |
| 1795 | dstDir = "~/packet_captures/" |
| 1796 | for f in logFiles: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1797 | main.ONOSbench.handle.sendline( "scp sdn@" + main.nodes[0].ip_address + ":" + |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1798 | logFolder + f + " " + |
| 1799 | teststationUser + "@" + |
| 1800 | teststationIP + ":" + dstDir + |
| 1801 | str( testname ) + "-ONOS1-" + f ) |
| 1802 | main.ONOSbench.handle.expect( "\$" ) |
| 1803 | # sleep so scp can finish |
| 1804 | time.sleep( 10 ) |
| 1805 | main.step( "Packing and rotating pcap archives" ) |
| 1806 | os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) ) |
| 1807 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1808 | main.step( "Stopping Mininet" ) |
| 1809 | mnResult = main.Mininet1.stopNet() |
| 1810 | utilities.assert_equals( expect=main.TRUE, actual=mnResult, |
| 1811 | onpass="Mininet stopped", |
| 1812 | onfail="MN cleanup NOT successful" ) |
| 1813 | |
| 1814 | main.step( "Checking ONOS Logs for errors" ) |
| 1815 | print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \ |
| 1816 | colors[ 'end' ] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1817 | print main.ONOSbench.checkLogs( main.nodes[0].ip_address, restart=True ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1818 | |
| 1819 | try: |
| 1820 | timerLog = open( main.logdir + "/Timers.csv", 'w') |
| 1821 | # Overwrite with empty line and close |
| 1822 | labels = "Gossip Intents, Restart" |
| 1823 | data = str( gossipTime ) + ", " + str( main.restartTime ) |
| 1824 | timerLog.write( labels + "\n" + data ) |
| 1825 | timerLog.close() |
| 1826 | except NameError, e: |
| 1827 | main.log.exception(e) |
| 1828 | |
| 1829 | def CASE14( self, main ): |
| 1830 | """ |
| 1831 | start election app on all onos nodes |
| 1832 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1833 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1834 | assert main, "main not defined" |
| 1835 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 1836 | |
| 1837 | main.case("Start Leadership Election app") |
| 1838 | main.step( "Install leadership election app" ) |
| 1839 | appResult = main.ONOScli1.activateApp( "org.onosproject.election" ) |
| 1840 | utilities.assert_equals( |
| 1841 | expect=main.TRUE, |
| 1842 | actual=appResult, |
| 1843 | onpass="Election app installed", |
| 1844 | onfail="Something went wrong with installing Leadership election" ) |
| 1845 | |
| 1846 | main.step( "Run for election on each node" ) |
| 1847 | leaderResult = main.ONOScli1.electionTestRun() |
| 1848 | # check for leader |
| 1849 | leader = main.ONOScli1.electionTestLeader() |
| 1850 | # verify leader is ONOS1 |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1851 | if leader == main.nodes[0].ip_address: |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1852 | # all is well |
| 1853 | pass |
| 1854 | elif leader is None: |
| 1855 | # No leader elected |
| 1856 | main.log.error( "No leader was elected" ) |
| 1857 | leaderResult = main.FALSE |
| 1858 | elif leader == main.FALSE: |
| 1859 | # error in response |
| 1860 | # TODO: add check for "Command not found:" in the driver, this |
| 1861 | # means the app isn't loaded |
| 1862 | main.log.error( "Something is wrong with electionTestLeader" + |
| 1863 | " function, check the error logs" ) |
| 1864 | leaderResult = main.FALSE |
| 1865 | else: |
| 1866 | # error in response |
| 1867 | main.log.error( |
| 1868 | "Unexpected response from electionTestLeader function:'" + |
| 1869 | str( leader ) + |
| 1870 | "'" ) |
| 1871 | leaderResult = main.FALSE |
| 1872 | utilities.assert_equals( |
| 1873 | expect=main.TRUE, |
| 1874 | actual=leaderResult, |
| 1875 | onpass="Successfully ran for leadership", |
| 1876 | onfail="Failed to run for leadership" ) |
| 1877 | |
| 1878 | def CASE15( self, main ): |
| 1879 | """ |
| 1880 | Check that Leadership Election is still functional |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 1881 | 15.1 Run election on each node |
| 1882 | 15.2 Check that each node has the same leaders and candidates |
| 1883 | 15.3 Find current leader and withdraw |
| 1884 | 15.4 Check that a new node was elected leader |
| 1885 | 15.5 Check that that new leader was the candidate of old leader |
| 1886 | 15.6 Run for election on old leader |
| 1887 | 15.7 Check that oldLeader is a candidate, and leader if only 1 node |
| 1888 | 15.8 Make sure that the old leader was added to the candidate list |
| 1889 | |
| 1890 | old and new variable prefixes refer to data from before vs after |
| 1891 | withdrawl and later before withdrawl vs after re-election |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1892 | """ |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 1893 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 1894 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1895 | assert main, "main not defined" |
| 1896 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 1897 | assert main.CLIs, "main.CLIs not defined" |
| 1898 | assert main.nodes, "main.nodes not defined" |
| 1899 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1900 | description = "Check that Leadership Election is still functional" |
| 1901 | main.case( description ) |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 1902 | # NOTE: Need to re-run since being a canidate is not persistant |
| 1903 | # TODO: add check for "Command not found:" in the driver, this |
| 1904 | # means the election test app isn't loaded |
acsmars | 2c2fcdd | 2015-08-25 17:14:13 -0700 | [diff] [blame] | 1905 | |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 1906 | oldLeaders = [] # leaders by node before withdrawl from candidates |
| 1907 | newLeaders = [] # leaders by node after withdrawl from candidates |
| 1908 | oldAllCandidates = [] # list of lists of each nodes' candidates before |
| 1909 | newAllCandidates = [] # list of lists of each nodes' candidates after |
| 1910 | oldCandidates = [] # list of candidates from node 0 before withdrawl |
| 1911 | newCandidates = [] # list of candidates from node 0 after withdrawl |
| 1912 | oldLeader = '' # the old leader from oldLeaders, None if not same |
| 1913 | newLeader = '' # the new leaders fron newLoeaders, None if not same |
| 1914 | oldLeaderCLI = None # the CLI of the old leader used for re-electing |
| 1915 | expectNoLeader = False # True when there is only one leader |
| 1916 | if main.numCtrls == 1: |
| 1917 | expectNoLeader = True |
acsmars | 2c2fcdd | 2015-08-25 17:14:13 -0700 | [diff] [blame] | 1918 | |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 1919 | main.step( "Run for election on each node" ) |
| 1920 | electionResult = main.TRUE |
| 1921 | |
| 1922 | for cli in main.CLIs: # run test election on each node |
| 1923 | if cli.electionTestRun() == main.FALSE: |
| 1924 | electionResult = main.FALSE |
| 1925 | |
| 1926 | utilities.assert_equals( |
| 1927 | expect=main.TRUE, |
| 1928 | actual=electionResult, |
| 1929 | onpass="All nodes successfully ran for leadership", |
| 1930 | onfail="At least one node failed to run for leadership" ) |
| 1931 | |
| 1932 | main.step( "Check that each node shows the same leader and candidates" ) |
| 1933 | sameResult = main.TRUE |
| 1934 | failMessage = "Nodes have different leaders" |
| 1935 | for cli in main.CLIs: |
| 1936 | node = cli.specificLeaderCandidate( 'org.onosproject.election' ) |
| 1937 | oldAllCandidates.append( node ) |
| 1938 | oldLeaders.append( node[ 0 ] ) |
| 1939 | oldCandidates = oldAllCandidates[ 0 ] |
| 1940 | |
| 1941 | # Check that each node has the same leader. Defines oldLeader |
| 1942 | if len( set( oldLeaders ) ) != 1: |
| 1943 | sameResult = main.FALSE |
| 1944 | main.log.error( "More than one leader present:" + str( oldLeaders ) ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1945 | oldLeader = None |
| 1946 | else: |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 1947 | oldLeader = oldLeaders[ 0 ] |
| 1948 | |
| 1949 | # Check that each node's candidate list is the same |
| 1950 | for candidates in oldAllCandidates: |
| 1951 | if set( candidates ) != set( oldCandidates ): |
| 1952 | sameResult = main.FALSE |
| 1953 | failMessage += "and candidates" |
| 1954 | |
| 1955 | utilities.assert_equals( |
| 1956 | expect=main.TRUE, |
| 1957 | actual=sameResult, |
| 1958 | onpass="Leadership is consistent for the election topic", |
| 1959 | onfail=failMessage ) |
| 1960 | |
| 1961 | main.step( "Find current leader and withdraw" ) |
| 1962 | withdrawResult = main.TRUE |
| 1963 | # do some sanity checking on leader before using it |
| 1964 | if oldLeader is None: |
| 1965 | main.log.error( "Leadership isn't consistent." ) |
| 1966 | withdrawResult = main.FALSE |
| 1967 | # Get the CLI of the oldLeader |
| 1968 | for i in range( len( main.CLIs ) ): |
| 1969 | if oldLeader == main.nodes[ i ].ip_address: |
| 1970 | oldLeaderCLI = main.CLIs[ i ] |
| 1971 | break |
| 1972 | else: # FOR/ELSE statement |
| 1973 | main.log.error( "Leader election, could not find current leader" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1974 | if oldLeader: |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 1975 | withdrawResult = oldLeaderCLI.electionTestWithdraw() |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 1976 | utilities.assert_equals( |
| 1977 | expect=main.TRUE, |
| 1978 | actual=withdrawResult, |
| 1979 | onpass="Node was withdrawn from election", |
| 1980 | onfail="Node was not withdrawn from election" ) |
| 1981 | |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 1982 | main.step( "Check that a new node was elected leader" ) |
| 1983 | |
| 1984 | # FIXME: use threads |
| 1985 | newLeaderResult = main.TRUE |
| 1986 | failMessage = "Nodes have different leaders" |
| 1987 | |
| 1988 | # Get new leaders and candidates |
| 1989 | for cli in main.CLIs: |
| 1990 | node = cli.specificLeaderCandidate( 'org.onosproject.election' ) |
| 1991 | # elections might no have finished yet |
| 1992 | if node[ 0 ] == 'none' and not expectNoLeader: |
| 1993 | main.log.info( "Node has no leader, waiting 5 seconds to be " + |
| 1994 | "sure elections are complete." ) |
| 1995 | time.sleep(5) |
| 1996 | node = cli.specificLeaderCandidate( 'org.onosproject.election' ) |
| 1997 | # election still isn't done or there is a problem |
| 1998 | if node[ 0 ] == 'none': |
| 1999 | main.log.error( "No leader was elected on at least 1 node" ) |
| 2000 | newLeaderResult = main.FALSE |
| 2001 | newAllCandidates.append( node ) |
| 2002 | newLeaders.append( node[ 0 ] ) |
| 2003 | newCandidates = newAllCandidates[ 0 ] |
| 2004 | |
| 2005 | # Check that each node has the same leader. Defines newLeader |
| 2006 | if len( set( newLeaders ) ) != 1: |
| 2007 | newLeaderResult = main.FALSE |
| 2008 | main.log.error( "Nodes have different leaders: " + |
| 2009 | str( newLeaders ) ) |
| 2010 | newLeader = None |
| 2011 | else: |
| 2012 | newLeader = newLeaders[ 0 ] |
| 2013 | |
| 2014 | # Check that each node's candidate list is the same |
| 2015 | for candidates in newAllCandidates: |
| 2016 | if set( candidates ) != set( newCandidates ): |
| 2017 | newLeaderResult = main.FALSE |
| 2018 | main.error.log( "Discrepancy in candidate lists detected" ) |
| 2019 | |
| 2020 | # Check that the new leader is not the older leader, which was withdrawn |
| 2021 | if newLeader == oldLeader: |
| 2022 | newLeaderResult = main.FALSE |
| 2023 | main.log.error( "All nodes still see old leader: " + oldLeader + |
| 2024 | " as the current leader" ) |
| 2025 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2026 | utilities.assert_equals( |
| 2027 | expect=main.TRUE, |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 2028 | actual=newLeaderResult, |
| 2029 | onpass="Leadership election passed", |
| 2030 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2031 | |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 2032 | main.step( "Check that that new leader was the candidate of old leader") |
| 2033 | # candidates[ 2 ] should be come the top candidate after withdrawl |
| 2034 | correctCandidateResult = main.TRUE |
| 2035 | if expectNoLeader: |
| 2036 | if newLeader == 'none': |
| 2037 | main.log.info( "No leader expected. None found. Pass" ) |
| 2038 | correctCandidateResult = main.TRUE |
| 2039 | else: |
| 2040 | main.log.info( "Expected no leader, got: " + str( newLeader ) ) |
| 2041 | correctCandidateResult = main.FALSE |
| 2042 | elif newLeader != oldCandidates[ 2 ]: |
| 2043 | correctCandidateResult = main.FALSE |
| 2044 | main.log.error( "Candidate " + newLeader + " was elected. " + |
| 2045 | oldCandidates[ 2 ] + " should have had priority." ) |
| 2046 | |
| 2047 | utilities.assert_equals( |
| 2048 | expect=main.TRUE, |
| 2049 | actual=correctCandidateResult, |
| 2050 | onpass="Correct Candidate Elected", |
| 2051 | onfail="Incorrect Candidate Elected" ) |
| 2052 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2053 | main.step( "Run for election on old leader( just so everyone " + |
| 2054 | "is in the hat )" ) |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 2055 | if oldLeaderCLI is not None: |
| 2056 | runResult = oldLeaderCLI.electionTestRun() |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2057 | else: |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 2058 | main.log.error( "No old leader to re-elect" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2059 | runResult = main.FALSE |
| 2060 | utilities.assert_equals( |
| 2061 | expect=main.TRUE, |
| 2062 | actual=runResult, |
| 2063 | onpass="App re-ran for election", |
| 2064 | onfail="App failed to run for election" ) |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 2065 | main.step( |
| 2066 | "Check that oldLeader is a candidate, and leader if only 1 node" ) |
| 2067 | # verify leader didn't just change |
| 2068 | positionResult = main.TRUE |
| 2069 | # Get new leaders and candidates, wait if oldLeader is not a candidate yet |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2070 | |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 2071 | # Reset and reuse the new candidate and leaders lists |
| 2072 | newAllCandidates = [] |
| 2073 | newCandidates = [] |
| 2074 | newLeaders = [] |
| 2075 | for cli in main.CLIs: |
| 2076 | node = cli.specificLeaderCandidate( 'org.onosproject.election' ) |
| 2077 | if oldLeader not in node: # election might no have finished yet |
| 2078 | main.log.info( "Old Leader not elected, waiting 5 seconds to " + |
| 2079 | "be sure elections are complete" ) |
| 2080 | time.sleep(5) |
| 2081 | node = cli.specificLeaderCandidate( 'org.onosproject.election' ) |
| 2082 | if oldLeader not in node: # election still isn't done, errors |
| 2083 | main.log.error( |
| 2084 | "Old leader was not elected on at least one node" ) |
| 2085 | positionResult = main.FALSE |
| 2086 | newAllCandidates.append( node ) |
| 2087 | newLeaders.append( node[ 0 ] ) |
| 2088 | newCandidates = newAllCandidates[ 0 ] |
| 2089 | |
| 2090 | # Check that each node has the same leader. Defines newLeader |
| 2091 | if len( set( newLeaders ) ) != 1: |
| 2092 | positionResult = main.FALSE |
| 2093 | main.log.error( "Nodes have different leaders: " + |
| 2094 | str( newLeaders ) ) |
| 2095 | newLeader = None |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2096 | else: |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 2097 | newLeader = newLeaders[ 0 ] |
| 2098 | |
| 2099 | # Check that each node's candidate list is the same |
| 2100 | for candidates in newAllCandidates: |
| 2101 | if set( candidates ) != set( newCandidates ): |
| 2102 | newLeaderResult = main.FALSE |
| 2103 | main.error.log( "Discrepancy in candidate lists detected" ) |
| 2104 | |
| 2105 | # Check that the re-elected node is last on the candidate List |
| 2106 | if oldLeader != newCandidates[ -1 ]: |
| 2107 | main.log.error( "Old Leader (" + oldLeader + ") not in the proper position " + |
| 2108 | str( newCandidates ) ) |
| 2109 | positionResult = main.FALSE |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2110 | |
| 2111 | utilities.assert_equals( |
| 2112 | expect=main.TRUE, |
acsmars | 71adceb | 2015-08-31 15:09:26 -0700 | [diff] [blame] | 2113 | actual=positionResult, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2114 | onpass="Old leader successfully re-ran for election", |
| 2115 | onfail="Something went wrong with Leadership election after " + |
| 2116 | "the old leader re-ran for election" ) |
| 2117 | |
| 2118 | def CASE16( self, main ): |
| 2119 | """ |
| 2120 | Install Distributed Primitives app |
| 2121 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2122 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2123 | assert main, "main not defined" |
| 2124 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2125 | assert main.CLIs, "main.CLIs not defined" |
| 2126 | assert main.nodes, "main.nodes not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2127 | |
| 2128 | # Variables for the distributed primitives tests |
| 2129 | global pCounterName |
| 2130 | global iCounterName |
| 2131 | global pCounterValue |
| 2132 | global iCounterValue |
| 2133 | global onosSet |
| 2134 | global onosSetName |
| 2135 | pCounterName = "TestON-Partitions" |
| 2136 | iCounterName = "TestON-inMemory" |
| 2137 | pCounterValue = 0 |
| 2138 | iCounterValue = 0 |
| 2139 | onosSet = set([]) |
| 2140 | onosSetName = "TestON-set" |
| 2141 | |
| 2142 | description = "Install Primitives app" |
| 2143 | main.case( description ) |
| 2144 | main.step( "Install Primitives app" ) |
| 2145 | appName = "org.onosproject.distributedprimitives" |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2146 | appResults = main.CLIs[0].activateApp( appName ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2147 | utilities.assert_equals( expect=main.TRUE, |
| 2148 | actual=appResults, |
| 2149 | onpass="Primitives app activated", |
| 2150 | onfail="Primitives app not activated" ) |
| 2151 | |
| 2152 | def CASE17( self, main ): |
| 2153 | """ |
| 2154 | Check for basic functionality with distributed primitives |
| 2155 | """ |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2156 | # Make sure variables are defined/set |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2157 | assert main.numCtrls, "main.numCtrls not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2158 | assert main, "main not defined" |
| 2159 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2160 | assert main.CLIs, "main.CLIs not defined" |
| 2161 | assert main.nodes, "main.nodes not defined" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2162 | assert pCounterName, "pCounterName not defined" |
| 2163 | assert iCounterName, "iCounterName not defined" |
| 2164 | assert onosSetName, "onosSetName not defined" |
| 2165 | # NOTE: assert fails if value is 0/None/Empty/False |
| 2166 | try: |
| 2167 | pCounterValue |
| 2168 | except NameError: |
| 2169 | main.log.error( "pCounterValue not defined, setting to 0" ) |
| 2170 | pCounterValue = 0 |
| 2171 | try: |
| 2172 | iCounterValue |
| 2173 | except NameError: |
| 2174 | main.log.error( "iCounterValue not defined, setting to 0" ) |
| 2175 | iCounterValue = 0 |
| 2176 | try: |
| 2177 | onosSet |
| 2178 | except NameError: |
| 2179 | main.log.error( "onosSet not defined, setting to empty Set" ) |
| 2180 | onosSet = set([]) |
| 2181 | # Variables for the distributed primitives tests. These are local only |
| 2182 | addValue = "a" |
| 2183 | addAllValue = "a b c d e f" |
| 2184 | retainValue = "c d e f" |
| 2185 | |
| 2186 | description = "Check for basic functionality with distributed " +\ |
| 2187 | "primitives" |
| 2188 | main.case( description ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2189 | main.caseExplanation = "Test the methods of the distributed " +\ |
| 2190 | "primitives (counters and sets) throught the cli" |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2191 | # DISTRIBUTED ATOMIC COUNTERS |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2192 | # Partitioned counters |
| 2193 | main.step( "Increment then get a default counter on each node" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2194 | pCounters = [] |
| 2195 | threads = [] |
| 2196 | addedPValues = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2197 | for i in range( main.numCtrls ): |
| 2198 | t = main.Thread( target=main.CLIs[i].counterTestAddAndGet, |
| 2199 | name="counterAddAndGet-" + str( i ), |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2200 | args=[ pCounterName ] ) |
| 2201 | pCounterValue += 1 |
| 2202 | addedPValues.append( pCounterValue ) |
| 2203 | threads.append( t ) |
| 2204 | t.start() |
| 2205 | |
| 2206 | for t in threads: |
| 2207 | t.join() |
| 2208 | pCounters.append( t.result ) |
| 2209 | # Check that counter incremented numController times |
| 2210 | pCounterResults = True |
| 2211 | for i in addedPValues: |
| 2212 | tmpResult = i in pCounters |
| 2213 | pCounterResults = pCounterResults and tmpResult |
| 2214 | if not tmpResult: |
| 2215 | main.log.error( str( i ) + " is not in partitioned " |
| 2216 | "counter incremented results" ) |
| 2217 | utilities.assert_equals( expect=True, |
| 2218 | actual=pCounterResults, |
| 2219 | onpass="Default counter incremented", |
| 2220 | onfail="Error incrementing default" + |
| 2221 | " counter" ) |
| 2222 | |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2223 | main.step( "Get then Increment a default counter on each node" ) |
| 2224 | pCounters = [] |
| 2225 | threads = [] |
| 2226 | addedPValues = [] |
| 2227 | for i in range( main.numCtrls ): |
| 2228 | t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd, |
| 2229 | name="counterGetAndAdd-" + str( i ), |
| 2230 | args=[ pCounterName ] ) |
| 2231 | addedPValues.append( pCounterValue ) |
| 2232 | pCounterValue += 1 |
| 2233 | threads.append( t ) |
| 2234 | t.start() |
| 2235 | |
| 2236 | for t in threads: |
| 2237 | t.join() |
| 2238 | pCounters.append( t.result ) |
| 2239 | # Check that counter incremented numController times |
| 2240 | pCounterResults = True |
| 2241 | for i in addedPValues: |
| 2242 | tmpResult = i in pCounters |
| 2243 | pCounterResults = pCounterResults and tmpResult |
| 2244 | if not tmpResult: |
| 2245 | main.log.error( str( i ) + " is not in partitioned " |
| 2246 | "counter incremented results" ) |
| 2247 | utilities.assert_equals( expect=True, |
| 2248 | actual=pCounterResults, |
| 2249 | onpass="Default counter incremented", |
| 2250 | onfail="Error incrementing default" + |
| 2251 | " counter" ) |
| 2252 | |
| 2253 | main.step( "Counters we added have the correct values" ) |
| 2254 | incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue ) |
| 2255 | utilities.assert_equals( expect=main.TRUE, |
| 2256 | actual=incrementCheck, |
| 2257 | onpass="Added counters are correct", |
| 2258 | onfail="Added counters are incorrect" ) |
| 2259 | |
| 2260 | main.step( "Add -8 to then get a default counter on each node" ) |
| 2261 | pCounters = [] |
| 2262 | threads = [] |
| 2263 | addedPValues = [] |
| 2264 | for i in range( main.numCtrls ): |
| 2265 | t = main.Thread( target=main.CLIs[i].counterTestAddAndGet, |
| 2266 | name="counterIncrement-" + str( i ), |
| 2267 | args=[ pCounterName ], |
| 2268 | kwargs={ "delta": -8 } ) |
| 2269 | pCounterValue += -8 |
| 2270 | addedPValues.append( pCounterValue ) |
| 2271 | threads.append( t ) |
| 2272 | t.start() |
| 2273 | |
| 2274 | for t in threads: |
| 2275 | t.join() |
| 2276 | pCounters.append( t.result ) |
| 2277 | # Check that counter incremented numController times |
| 2278 | pCounterResults = True |
| 2279 | for i in addedPValues: |
| 2280 | tmpResult = i in pCounters |
| 2281 | pCounterResults = pCounterResults and tmpResult |
| 2282 | if not tmpResult: |
| 2283 | main.log.error( str( i ) + " is not in partitioned " |
| 2284 | "counter incremented results" ) |
| 2285 | utilities.assert_equals( expect=True, |
| 2286 | actual=pCounterResults, |
| 2287 | onpass="Default counter incremented", |
| 2288 | onfail="Error incrementing default" + |
| 2289 | " counter" ) |
| 2290 | |
| 2291 | main.step( "Add 5 to then get a default counter on each node" ) |
| 2292 | pCounters = [] |
| 2293 | threads = [] |
| 2294 | addedPValues = [] |
| 2295 | for i in range( main.numCtrls ): |
| 2296 | t = main.Thread( target=main.CLIs[i].counterTestAddAndGet, |
| 2297 | name="counterIncrement-" + str( i ), |
| 2298 | args=[ pCounterName ], |
| 2299 | kwargs={ "delta": 5 } ) |
| 2300 | pCounterValue += 5 |
| 2301 | addedPValues.append( pCounterValue ) |
| 2302 | threads.append( t ) |
| 2303 | t.start() |
| 2304 | |
| 2305 | for t in threads: |
| 2306 | t.join() |
| 2307 | pCounters.append( t.result ) |
| 2308 | # Check that counter incremented numController times |
| 2309 | pCounterResults = True |
| 2310 | for i in addedPValues: |
| 2311 | tmpResult = i in pCounters |
| 2312 | pCounterResults = pCounterResults and tmpResult |
| 2313 | if not tmpResult: |
| 2314 | main.log.error( str( i ) + " is not in partitioned " |
| 2315 | "counter incremented results" ) |
| 2316 | utilities.assert_equals( expect=True, |
| 2317 | actual=pCounterResults, |
| 2318 | onpass="Default counter incremented", |
| 2319 | onfail="Error incrementing default" + |
| 2320 | " counter" ) |
| 2321 | |
| 2322 | main.step( "Get then add 5 to a default counter on each node" ) |
| 2323 | pCounters = [] |
| 2324 | threads = [] |
| 2325 | addedPValues = [] |
| 2326 | for i in range( main.numCtrls ): |
| 2327 | t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd, |
| 2328 | name="counterIncrement-" + str( i ), |
| 2329 | args=[ pCounterName ], |
| 2330 | kwargs={ "delta": 5 } ) |
| 2331 | addedPValues.append( pCounterValue ) |
| 2332 | pCounterValue += 5 |
| 2333 | threads.append( t ) |
| 2334 | t.start() |
| 2335 | |
| 2336 | for t in threads: |
| 2337 | t.join() |
| 2338 | pCounters.append( t.result ) |
| 2339 | # Check that counter incremented numController times |
| 2340 | pCounterResults = True |
| 2341 | for i in addedPValues: |
| 2342 | tmpResult = i in pCounters |
| 2343 | pCounterResults = pCounterResults and tmpResult |
| 2344 | if not tmpResult: |
| 2345 | main.log.error( str( i ) + " is not in partitioned " |
| 2346 | "counter incremented results" ) |
| 2347 | utilities.assert_equals( expect=True, |
| 2348 | actual=pCounterResults, |
| 2349 | onpass="Default counter incremented", |
| 2350 | onfail="Error incrementing default" + |
| 2351 | " counter" ) |
| 2352 | |
| 2353 | main.step( "Counters we added have the correct values" ) |
| 2354 | incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue ) |
| 2355 | utilities.assert_equals( expect=main.TRUE, |
| 2356 | actual=incrementCheck, |
| 2357 | onpass="Added counters are correct", |
| 2358 | onfail="Added counters are incorrect" ) |
| 2359 | |
| 2360 | # In-Memory counters |
| 2361 | main.step( "Increment and get an in-memory counter on each node" ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2362 | iCounters = [] |
| 2363 | addedIValues = [] |
| 2364 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2365 | for i in range( main.numCtrls ): |
| 2366 | t = main.Thread( target=main.CLIs[i].counterTestAddAndGet, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2367 | name="icounterIncrement-" + str( i ), |
| 2368 | args=[ iCounterName ], |
| 2369 | kwargs={ "inMemory": True } ) |
| 2370 | iCounterValue += 1 |
| 2371 | addedIValues.append( iCounterValue ) |
| 2372 | threads.append( t ) |
| 2373 | t.start() |
| 2374 | |
| 2375 | for t in threads: |
| 2376 | t.join() |
| 2377 | iCounters.append( t.result ) |
| 2378 | # Check that counter incremented numController times |
| 2379 | iCounterResults = True |
| 2380 | for i in addedIValues: |
| 2381 | tmpResult = i in iCounters |
| 2382 | iCounterResults = iCounterResults and tmpResult |
| 2383 | if not tmpResult: |
| 2384 | main.log.error( str( i ) + " is not in the in-memory " |
| 2385 | "counter incremented results" ) |
| 2386 | utilities.assert_equals( expect=True, |
| 2387 | actual=iCounterResults, |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2388 | onpass="In-memory counter incremented", |
| 2389 | onfail="Error incrementing in-memory" + |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2390 | " counter" ) |
| 2391 | |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2392 | main.step( "Get then Increment a in-memory counter on each node" ) |
| 2393 | iCounters = [] |
| 2394 | threads = [] |
| 2395 | addedIValues = [] |
| 2396 | for i in range( main.numCtrls ): |
| 2397 | t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd, |
| 2398 | name="counterGetAndAdd-" + str( i ), |
| 2399 | args=[ iCounterName ], |
| 2400 | kwargs={ "inMemory": True } ) |
| 2401 | addedIValues.append( iCounterValue ) |
| 2402 | iCounterValue += 1 |
| 2403 | threads.append( t ) |
| 2404 | t.start() |
| 2405 | |
| 2406 | for t in threads: |
| 2407 | t.join() |
| 2408 | iCounters.append( t.result ) |
| 2409 | # Check that counter incremented numController times |
| 2410 | iCounterResults = True |
| 2411 | for i in addedIValues: |
| 2412 | tmpResult = i in iCounters |
| 2413 | iCounterResults = iCounterResults and tmpResult |
| 2414 | if not tmpResult: |
| 2415 | main.log.error( str( i ) + " is not in in-memory " |
| 2416 | "counter incremented results" ) |
| 2417 | utilities.assert_equals( expect=True, |
| 2418 | actual=iCounterResults, |
| 2419 | onpass="In-memory counter incremented", |
| 2420 | onfail="Error incrementing in-memory" + |
| 2421 | " counter" ) |
| 2422 | |
| 2423 | main.step( "Counters we added have the correct values" ) |
| 2424 | incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue ) |
| 2425 | utilities.assert_equals( expect=main.TRUE, |
| 2426 | actual=incrementCheck, |
| 2427 | onpass="Added counters are correct", |
| 2428 | onfail="Added counters are incorrect" ) |
| 2429 | |
| 2430 | main.step( "Add -8 to then get a in-memory counter on each node" ) |
| 2431 | iCounters = [] |
| 2432 | threads = [] |
| 2433 | addedIValues = [] |
| 2434 | for i in range( main.numCtrls ): |
| 2435 | t = main.Thread( target=main.CLIs[i].counterTestAddAndGet, |
| 2436 | name="counterIncrement-" + str( i ), |
| 2437 | args=[ iCounterName ], |
| 2438 | kwargs={ "delta": -8, "inMemory": True } ) |
| 2439 | iCounterValue += -8 |
| 2440 | addedIValues.append( iCounterValue ) |
| 2441 | threads.append( t ) |
| 2442 | t.start() |
| 2443 | |
| 2444 | for t in threads: |
| 2445 | t.join() |
| 2446 | iCounters.append( t.result ) |
| 2447 | # Check that counter incremented numController times |
| 2448 | iCounterResults = True |
| 2449 | for i in addedIValues: |
| 2450 | tmpResult = i in iCounters |
| 2451 | iCounterResults = iCounterResults and tmpResult |
| 2452 | if not tmpResult: |
| 2453 | main.log.error( str( i ) + " is not in in-memory " |
| 2454 | "counter incremented results" ) |
| 2455 | utilities.assert_equals( expect=True, |
| 2456 | actual=pCounterResults, |
| 2457 | onpass="In-memory counter incremented", |
| 2458 | onfail="Error incrementing in-memory" + |
| 2459 | " counter" ) |
| 2460 | |
| 2461 | main.step( "Add 5 to then get a in-memory counter on each node" ) |
| 2462 | iCounters = [] |
| 2463 | threads = [] |
| 2464 | addedIValues = [] |
| 2465 | for i in range( main.numCtrls ): |
| 2466 | t = main.Thread( target=main.CLIs[i].counterTestAddAndGet, |
| 2467 | name="counterIncrement-" + str( i ), |
| 2468 | args=[ iCounterName ], |
| 2469 | kwargs={ "delta": 5, "inMemory": True } ) |
| 2470 | iCounterValue += 5 |
| 2471 | addedIValues.append( iCounterValue ) |
| 2472 | threads.append( t ) |
| 2473 | t.start() |
| 2474 | |
| 2475 | for t in threads: |
| 2476 | t.join() |
| 2477 | iCounters.append( t.result ) |
| 2478 | # Check that counter incremented numController times |
| 2479 | iCounterResults = True |
| 2480 | for i in addedIValues: |
| 2481 | tmpResult = i in iCounters |
| 2482 | iCounterResults = iCounterResults and tmpResult |
| 2483 | if not tmpResult: |
| 2484 | main.log.error( str( i ) + " is not in in-memory " |
| 2485 | "counter incremented results" ) |
| 2486 | utilities.assert_equals( expect=True, |
| 2487 | actual=pCounterResults, |
| 2488 | onpass="In-memory counter incremented", |
| 2489 | onfail="Error incrementing in-memory" + |
| 2490 | " counter" ) |
| 2491 | |
| 2492 | main.step( "Get then add 5 to a in-memory counter on each node" ) |
| 2493 | iCounters = [] |
| 2494 | threads = [] |
| 2495 | addedIValues = [] |
| 2496 | for i in range( main.numCtrls ): |
| 2497 | t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd, |
| 2498 | name="counterIncrement-" + str( i ), |
| 2499 | args=[ iCounterName ], |
| 2500 | kwargs={ "delta": 5, "inMemory": True } ) |
| 2501 | addedIValues.append( iCounterValue ) |
| 2502 | iCounterValue += 5 |
| 2503 | threads.append( t ) |
| 2504 | t.start() |
| 2505 | |
| 2506 | for t in threads: |
| 2507 | t.join() |
| 2508 | iCounters.append( t.result ) |
| 2509 | # Check that counter incremented numController times |
| 2510 | iCounterResults = True |
| 2511 | for i in addedIValues: |
| 2512 | tmpResult = i in iCounters |
| 2513 | iCounterResults = iCounterResults and tmpResult |
| 2514 | if not tmpResult: |
| 2515 | main.log.error( str( i ) + " is not in in-memory " |
| 2516 | "counter incremented results" ) |
| 2517 | utilities.assert_equals( expect=True, |
| 2518 | actual=iCounterResults, |
| 2519 | onpass="In-memory counter incremented", |
| 2520 | onfail="Error incrementing in-memory" + |
| 2521 | " counter" ) |
| 2522 | |
| 2523 | main.step( "Counters we added have the correct values" ) |
| 2524 | incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue ) |
| 2525 | utilities.assert_equals( expect=main.TRUE, |
| 2526 | actual=incrementCheck, |
| 2527 | onpass="Added counters are correct", |
| 2528 | onfail="Added counters are incorrect" ) |
| 2529 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2530 | main.step( "Check counters are consistant across nodes" ) |
| 2531 | onosCounters = [] |
| 2532 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2533 | for i in range( main.numCtrls ): |
| 2534 | t = main.Thread( target=main.CLIs[i].counters, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2535 | name="counters-" + str( i ) ) |
| 2536 | threads.append( t ) |
| 2537 | t.start() |
| 2538 | for t in threads: |
| 2539 | t.join() |
| 2540 | onosCounters.append( t.result ) |
| 2541 | tmp = [ i == onosCounters[ 0 ] for i in onosCounters ] |
| 2542 | if all( tmp ): |
| 2543 | main.log.info( "Counters are consistent across all nodes" ) |
| 2544 | consistentCounterResults = main.TRUE |
| 2545 | else: |
| 2546 | main.log.error( "Counters are not consistent across all nodes" ) |
| 2547 | consistentCounterResults = main.FALSE |
| 2548 | utilities.assert_equals( expect=main.TRUE, |
| 2549 | actual=consistentCounterResults, |
| 2550 | onpass="ONOS counters are consistent " + |
| 2551 | "across nodes", |
| 2552 | onfail="ONOS Counters are inconsistent " + |
| 2553 | "across nodes" ) |
| 2554 | |
| 2555 | main.step( "Counters we added have the correct values" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2556 | incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue ) |
| 2557 | incrementCheck = incrementCheck and \ |
| 2558 | main.Counters.counterCheck( iCounterName, iCounterValue ) |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2559 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2560 | actual=incrementCheck, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2561 | onpass="Added counters are correct", |
| 2562 | onfail="Added counters are incorrect" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2563 | |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2564 | # DISTRIBUTED SETS |
| 2565 | main.step( "Distributed Set get" ) |
| 2566 | size = len( onosSet ) |
| 2567 | getResponses = [] |
| 2568 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2569 | for i in range( main.numCtrls ): |
| 2570 | t = main.Thread( target=main.CLIs[i].setTestGet, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2571 | name="setTestGet-" + str( i ), |
| 2572 | args=[ onosSetName ] ) |
| 2573 | threads.append( t ) |
| 2574 | t.start() |
| 2575 | for t in threads: |
| 2576 | t.join() |
| 2577 | getResponses.append( t.result ) |
| 2578 | |
| 2579 | getResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2580 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2581 | if isinstance( getResponses[ i ], list): |
| 2582 | current = set( getResponses[ i ] ) |
| 2583 | if len( current ) == len( getResponses[ i ] ): |
| 2584 | # no repeats |
| 2585 | if onosSet != current: |
| 2586 | main.log.error( "ONOS" + str( i + 1 ) + |
| 2587 | " has incorrect view" + |
| 2588 | " of set " + onosSetName + ":\n" + |
| 2589 | str( getResponses[ i ] ) ) |
| 2590 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 2591 | main.log.debug( "Actual: " + str( current ) ) |
| 2592 | getResults = main.FALSE |
| 2593 | else: |
| 2594 | # error, set is not a set |
| 2595 | main.log.error( "ONOS" + str( i + 1 ) + |
| 2596 | " has repeat elements in" + |
| 2597 | " set " + onosSetName + ":\n" + |
| 2598 | str( getResponses[ i ] ) ) |
| 2599 | getResults = main.FALSE |
| 2600 | elif getResponses[ i ] == main.ERROR: |
| 2601 | getResults = main.FALSE |
| 2602 | utilities.assert_equals( expect=main.TRUE, |
| 2603 | actual=getResults, |
| 2604 | onpass="Set elements are correct", |
| 2605 | onfail="Set elements are incorrect" ) |
| 2606 | |
| 2607 | main.step( "Distributed Set size" ) |
| 2608 | sizeResponses = [] |
| 2609 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2610 | for i in range( main.numCtrls ): |
| 2611 | t = main.Thread( target=main.CLIs[i].setTestSize, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2612 | name="setTestSize-" + str( i ), |
| 2613 | args=[ onosSetName ] ) |
| 2614 | threads.append( t ) |
| 2615 | t.start() |
| 2616 | for t in threads: |
| 2617 | t.join() |
| 2618 | sizeResponses.append( t.result ) |
| 2619 | |
| 2620 | sizeResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2621 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2622 | if size != sizeResponses[ i ]: |
| 2623 | sizeResults = main.FALSE |
| 2624 | main.log.error( "ONOS" + str( i + 1 ) + |
| 2625 | " expected a size of " + str( size ) + |
| 2626 | " for set " + onosSetName + |
| 2627 | " but got " + str( sizeResponses[ i ] ) ) |
| 2628 | utilities.assert_equals( expect=main.TRUE, |
| 2629 | actual=sizeResults, |
| 2630 | onpass="Set sizes are correct", |
| 2631 | onfail="Set sizes are incorrect" ) |
| 2632 | |
| 2633 | main.step( "Distributed Set add()" ) |
| 2634 | onosSet.add( addValue ) |
| 2635 | addResponses = [] |
| 2636 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2637 | for i in range( main.numCtrls ): |
| 2638 | t = main.Thread( target=main.CLIs[i].setTestAdd, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2639 | name="setTestAdd-" + str( i ), |
| 2640 | args=[ onosSetName, addValue ] ) |
| 2641 | threads.append( t ) |
| 2642 | t.start() |
| 2643 | for t in threads: |
| 2644 | t.join() |
| 2645 | addResponses.append( t.result ) |
| 2646 | |
| 2647 | # main.TRUE = successfully changed the set |
| 2648 | # main.FALSE = action resulted in no change in set |
| 2649 | # main.ERROR - Some error in executing the function |
| 2650 | addResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2651 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2652 | if addResponses[ i ] == main.TRUE: |
| 2653 | # All is well |
| 2654 | pass |
| 2655 | elif addResponses[ i ] == main.FALSE: |
| 2656 | # Already in set, probably fine |
| 2657 | pass |
| 2658 | elif addResponses[ i ] == main.ERROR: |
| 2659 | # Error in execution |
| 2660 | addResults = main.FALSE |
| 2661 | else: |
| 2662 | # unexpected result |
| 2663 | addResults = main.FALSE |
| 2664 | if addResults != main.TRUE: |
| 2665 | main.log.error( "Error executing set add" ) |
| 2666 | |
| 2667 | # Check if set is still correct |
| 2668 | size = len( onosSet ) |
| 2669 | getResponses = [] |
| 2670 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2671 | for i in range( main.numCtrls ): |
| 2672 | t = main.Thread( target=main.CLIs[i].setTestGet, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2673 | name="setTestGet-" + str( i ), |
| 2674 | args=[ onosSetName ] ) |
| 2675 | threads.append( t ) |
| 2676 | t.start() |
| 2677 | for t in threads: |
| 2678 | t.join() |
| 2679 | getResponses.append( t.result ) |
| 2680 | getResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2681 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2682 | if isinstance( getResponses[ i ], list): |
| 2683 | current = set( getResponses[ i ] ) |
| 2684 | if len( current ) == len( getResponses[ i ] ): |
| 2685 | # no repeats |
| 2686 | if onosSet != current: |
| 2687 | main.log.error( "ONOS" + str( i + 1 ) + |
| 2688 | " has incorrect view" + |
| 2689 | " of set " + onosSetName + ":\n" + |
| 2690 | str( getResponses[ i ] ) ) |
| 2691 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 2692 | main.log.debug( "Actual: " + str( current ) ) |
| 2693 | getResults = main.FALSE |
| 2694 | else: |
| 2695 | # error, set is not a set |
| 2696 | main.log.error( "ONOS" + str( i + 1 ) + |
| 2697 | " has repeat elements in" + |
| 2698 | " set " + onosSetName + ":\n" + |
| 2699 | str( getResponses[ i ] ) ) |
| 2700 | getResults = main.FALSE |
| 2701 | elif getResponses[ i ] == main.ERROR: |
| 2702 | getResults = main.FALSE |
| 2703 | sizeResponses = [] |
| 2704 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2705 | for i in range( main.numCtrls ): |
| 2706 | t = main.Thread( target=main.CLIs[i].setTestSize, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2707 | name="setTestSize-" + str( i ), |
| 2708 | args=[ onosSetName ] ) |
| 2709 | threads.append( t ) |
| 2710 | t.start() |
| 2711 | for t in threads: |
| 2712 | t.join() |
| 2713 | sizeResponses.append( t.result ) |
| 2714 | sizeResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2715 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2716 | if size != sizeResponses[ i ]: |
| 2717 | sizeResults = main.FALSE |
| 2718 | main.log.error( "ONOS" + str( i + 1 ) + |
| 2719 | " expected a size of " + str( size ) + |
| 2720 | " for set " + onosSetName + |
| 2721 | " but got " + str( sizeResponses[ i ] ) ) |
| 2722 | addResults = addResults and getResults and sizeResults |
| 2723 | utilities.assert_equals( expect=main.TRUE, |
| 2724 | actual=addResults, |
| 2725 | onpass="Set add correct", |
| 2726 | onfail="Set add was incorrect" ) |
| 2727 | |
| 2728 | main.step( "Distributed Set addAll()" ) |
| 2729 | onosSet.update( addAllValue.split() ) |
| 2730 | addResponses = [] |
| 2731 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2732 | for i in range( main.numCtrls ): |
| 2733 | t = main.Thread( target=main.CLIs[i].setTestAdd, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2734 | name="setTestAddAll-" + str( i ), |
| 2735 | args=[ onosSetName, addAllValue ] ) |
| 2736 | threads.append( t ) |
| 2737 | t.start() |
| 2738 | for t in threads: |
| 2739 | t.join() |
| 2740 | addResponses.append( t.result ) |
| 2741 | |
| 2742 | # main.TRUE = successfully changed the set |
| 2743 | # main.FALSE = action resulted in no change in set |
| 2744 | # main.ERROR - Some error in executing the function |
| 2745 | addAllResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2746 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2747 | if addResponses[ i ] == main.TRUE: |
| 2748 | # All is well |
| 2749 | pass |
| 2750 | elif addResponses[ i ] == main.FALSE: |
| 2751 | # Already in set, probably fine |
| 2752 | pass |
| 2753 | elif addResponses[ i ] == main.ERROR: |
| 2754 | # Error in execution |
| 2755 | addAllResults = main.FALSE |
| 2756 | else: |
| 2757 | # unexpected result |
| 2758 | addAllResults = main.FALSE |
| 2759 | if addAllResults != main.TRUE: |
| 2760 | main.log.error( "Error executing set addAll" ) |
| 2761 | |
| 2762 | # Check if set is still correct |
| 2763 | size = len( onosSet ) |
| 2764 | getResponses = [] |
| 2765 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2766 | for i in range( main.numCtrls ): |
| 2767 | t = main.Thread( target=main.CLIs[i].setTestGet, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2768 | name="setTestGet-" + str( i ), |
| 2769 | args=[ onosSetName ] ) |
| 2770 | threads.append( t ) |
| 2771 | t.start() |
| 2772 | for t in threads: |
| 2773 | t.join() |
| 2774 | getResponses.append( t.result ) |
| 2775 | getResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2776 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2777 | if isinstance( getResponses[ i ], list): |
| 2778 | current = set( getResponses[ i ] ) |
| 2779 | if len( current ) == len( getResponses[ i ] ): |
| 2780 | # no repeats |
| 2781 | if onosSet != current: |
| 2782 | main.log.error( "ONOS" + str( i + 1 ) + |
| 2783 | " has incorrect view" + |
| 2784 | " of set " + onosSetName + ":\n" + |
| 2785 | str( getResponses[ i ] ) ) |
| 2786 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 2787 | main.log.debug( "Actual: " + str( current ) ) |
| 2788 | getResults = main.FALSE |
| 2789 | else: |
| 2790 | # error, set is not a set |
| 2791 | main.log.error( "ONOS" + str( i + 1 ) + |
| 2792 | " has repeat elements in" + |
| 2793 | " set " + onosSetName + ":\n" + |
| 2794 | str( getResponses[ i ] ) ) |
| 2795 | getResults = main.FALSE |
| 2796 | elif getResponses[ i ] == main.ERROR: |
| 2797 | getResults = main.FALSE |
| 2798 | sizeResponses = [] |
| 2799 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2800 | for i in range( main.numCtrls ): |
| 2801 | t = main.Thread( target=main.CLIs[i].setTestSize, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2802 | name="setTestSize-" + str( i ), |
| 2803 | args=[ onosSetName ] ) |
| 2804 | threads.append( t ) |
| 2805 | t.start() |
| 2806 | for t in threads: |
| 2807 | t.join() |
| 2808 | sizeResponses.append( t.result ) |
| 2809 | sizeResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2810 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2811 | if size != sizeResponses[ i ]: |
| 2812 | sizeResults = main.FALSE |
| 2813 | main.log.error( "ONOS" + str( i + 1 ) + |
| 2814 | " expected a size of " + str( size ) + |
| 2815 | " for set " + onosSetName + |
| 2816 | " but got " + str( sizeResponses[ i ] ) ) |
| 2817 | addAllResults = addAllResults and getResults and sizeResults |
| 2818 | utilities.assert_equals( expect=main.TRUE, |
| 2819 | actual=addAllResults, |
| 2820 | onpass="Set addAll correct", |
| 2821 | onfail="Set addAll was incorrect" ) |
| 2822 | |
| 2823 | main.step( "Distributed Set contains()" ) |
| 2824 | containsResponses = [] |
| 2825 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2826 | for i in range( main.numCtrls ): |
| 2827 | t = main.Thread( target=main.CLIs[i].setTestGet, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2828 | name="setContains-" + str( i ), |
| 2829 | args=[ onosSetName ], |
| 2830 | kwargs={ "values": addValue } ) |
| 2831 | threads.append( t ) |
| 2832 | t.start() |
| 2833 | for t in threads: |
| 2834 | t.join() |
| 2835 | # NOTE: This is the tuple |
| 2836 | containsResponses.append( t.result ) |
| 2837 | |
| 2838 | containsResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2839 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2840 | if containsResponses[ i ] == main.ERROR: |
| 2841 | containsResults = main.FALSE |
| 2842 | else: |
| 2843 | containsResults = containsResults and\ |
| 2844 | containsResponses[ i ][ 1 ] |
| 2845 | utilities.assert_equals( expect=main.TRUE, |
| 2846 | actual=containsResults, |
| 2847 | onpass="Set contains is functional", |
| 2848 | onfail="Set contains failed" ) |
| 2849 | |
| 2850 | main.step( "Distributed Set containsAll()" ) |
| 2851 | containsAllResponses = [] |
| 2852 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2853 | for i in range( main.numCtrls ): |
| 2854 | t = main.Thread( target=main.CLIs[i].setTestGet, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2855 | name="setContainsAll-" + str( i ), |
| 2856 | args=[ onosSetName ], |
| 2857 | kwargs={ "values": addAllValue } ) |
| 2858 | threads.append( t ) |
| 2859 | t.start() |
| 2860 | for t in threads: |
| 2861 | t.join() |
| 2862 | # NOTE: This is the tuple |
| 2863 | containsAllResponses.append( t.result ) |
| 2864 | |
| 2865 | containsAllResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2866 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2867 | if containsResponses[ i ] == main.ERROR: |
| 2868 | containsResults = main.FALSE |
| 2869 | else: |
| 2870 | containsResults = containsResults and\ |
| 2871 | containsResponses[ i ][ 1 ] |
| 2872 | utilities.assert_equals( expect=main.TRUE, |
| 2873 | actual=containsAllResults, |
| 2874 | onpass="Set containsAll is functional", |
| 2875 | onfail="Set containsAll failed" ) |
| 2876 | |
| 2877 | main.step( "Distributed Set remove()" ) |
| 2878 | onosSet.remove( addValue ) |
| 2879 | removeResponses = [] |
| 2880 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2881 | for i in range( main.numCtrls ): |
| 2882 | t = main.Thread( target=main.CLIs[i].setTestRemove, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2883 | name="setTestRemove-" + str( i ), |
| 2884 | args=[ onosSetName, addValue ] ) |
| 2885 | threads.append( t ) |
| 2886 | t.start() |
| 2887 | for t in threads: |
| 2888 | t.join() |
| 2889 | removeResponses.append( t.result ) |
| 2890 | |
| 2891 | # main.TRUE = successfully changed the set |
| 2892 | # main.FALSE = action resulted in no change in set |
| 2893 | # main.ERROR - Some error in executing the function |
| 2894 | removeResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2895 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2896 | if removeResponses[ i ] == main.TRUE: |
| 2897 | # All is well |
| 2898 | pass |
| 2899 | elif removeResponses[ i ] == main.FALSE: |
| 2900 | # not in set, probably fine |
| 2901 | pass |
| 2902 | elif removeResponses[ i ] == main.ERROR: |
| 2903 | # Error in execution |
| 2904 | removeResults = main.FALSE |
| 2905 | else: |
| 2906 | # unexpected result |
| 2907 | removeResults = main.FALSE |
| 2908 | if removeResults != main.TRUE: |
| 2909 | main.log.error( "Error executing set remove" ) |
| 2910 | |
| 2911 | # Check if set is still correct |
| 2912 | size = len( onosSet ) |
| 2913 | getResponses = [] |
| 2914 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2915 | for i in range( main.numCtrls ): |
| 2916 | t = main.Thread( target=main.CLIs[i].setTestGet, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2917 | name="setTestGet-" + str( i ), |
| 2918 | args=[ onosSetName ] ) |
| 2919 | threads.append( t ) |
| 2920 | t.start() |
| 2921 | for t in threads: |
| 2922 | t.join() |
| 2923 | getResponses.append( t.result ) |
| 2924 | getResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2925 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2926 | if isinstance( getResponses[ i ], list): |
| 2927 | current = set( getResponses[ i ] ) |
| 2928 | if len( current ) == len( getResponses[ i ] ): |
| 2929 | # no repeats |
| 2930 | if onosSet != current: |
| 2931 | main.log.error( "ONOS" + str( i + 1 ) + |
| 2932 | " has incorrect view" + |
| 2933 | " of set " + onosSetName + ":\n" + |
| 2934 | str( getResponses[ i ] ) ) |
| 2935 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 2936 | main.log.debug( "Actual: " + str( current ) ) |
| 2937 | getResults = main.FALSE |
| 2938 | else: |
| 2939 | # error, set is not a set |
| 2940 | main.log.error( "ONOS" + str( i + 1 ) + |
| 2941 | " has repeat elements in" + |
| 2942 | " set " + onosSetName + ":\n" + |
| 2943 | str( getResponses[ i ] ) ) |
| 2944 | getResults = main.FALSE |
| 2945 | elif getResponses[ i ] == main.ERROR: |
| 2946 | getResults = main.FALSE |
| 2947 | sizeResponses = [] |
| 2948 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2949 | for i in range( main.numCtrls ): |
| 2950 | t = main.Thread( target=main.CLIs[i].setTestSize, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2951 | name="setTestSize-" + str( i ), |
| 2952 | args=[ onosSetName ] ) |
| 2953 | threads.append( t ) |
| 2954 | t.start() |
| 2955 | for t in threads: |
| 2956 | t.join() |
| 2957 | sizeResponses.append( t.result ) |
| 2958 | sizeResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2959 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2960 | if size != sizeResponses[ i ]: |
| 2961 | sizeResults = main.FALSE |
| 2962 | main.log.error( "ONOS" + str( i + 1 ) + |
| 2963 | " expected a size of " + str( size ) + |
| 2964 | " for set " + onosSetName + |
| 2965 | " but got " + str( sizeResponses[ i ] ) ) |
| 2966 | removeResults = removeResults and getResults and sizeResults |
| 2967 | utilities.assert_equals( expect=main.TRUE, |
| 2968 | actual=removeResults, |
| 2969 | onpass="Set remove correct", |
| 2970 | onfail="Set remove was incorrect" ) |
| 2971 | |
| 2972 | main.step( "Distributed Set removeAll()" ) |
| 2973 | onosSet.difference_update( addAllValue.split() ) |
| 2974 | removeAllResponses = [] |
| 2975 | threads = [] |
| 2976 | try: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2977 | for i in range( main.numCtrls ): |
| 2978 | t = main.Thread( target=main.CLIs[i].setTestRemove, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2979 | name="setTestRemoveAll-" + str( i ), |
| 2980 | args=[ onosSetName, addAllValue ] ) |
| 2981 | threads.append( t ) |
| 2982 | t.start() |
| 2983 | for t in threads: |
| 2984 | t.join() |
| 2985 | removeAllResponses.append( t.result ) |
| 2986 | except Exception, e: |
| 2987 | main.log.exception(e) |
| 2988 | |
| 2989 | # main.TRUE = successfully changed the set |
| 2990 | # main.FALSE = action resulted in no change in set |
| 2991 | # main.ERROR - Some error in executing the function |
| 2992 | removeAllResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 2993 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 2994 | if removeAllResponses[ i ] == main.TRUE: |
| 2995 | # All is well |
| 2996 | pass |
| 2997 | elif removeAllResponses[ i ] == main.FALSE: |
| 2998 | # not in set, probably fine |
| 2999 | pass |
| 3000 | elif removeAllResponses[ i ] == main.ERROR: |
| 3001 | # Error in execution |
| 3002 | removeAllResults = main.FALSE |
| 3003 | else: |
| 3004 | # unexpected result |
| 3005 | removeAllResults = main.FALSE |
| 3006 | if removeAllResults != main.TRUE: |
| 3007 | main.log.error( "Error executing set removeAll" ) |
| 3008 | |
| 3009 | # Check if set is still correct |
| 3010 | size = len( onosSet ) |
| 3011 | getResponses = [] |
| 3012 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3013 | for i in range( main.numCtrls ): |
| 3014 | t = main.Thread( target=main.CLIs[i].setTestGet, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3015 | name="setTestGet-" + str( i ), |
| 3016 | args=[ onosSetName ] ) |
| 3017 | threads.append( t ) |
| 3018 | t.start() |
| 3019 | for t in threads: |
| 3020 | t.join() |
| 3021 | getResponses.append( t.result ) |
| 3022 | getResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3023 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3024 | if isinstance( getResponses[ i ], list): |
| 3025 | current = set( getResponses[ i ] ) |
| 3026 | if len( current ) == len( getResponses[ i ] ): |
| 3027 | # no repeats |
| 3028 | if onosSet != current: |
| 3029 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3030 | " has incorrect view" + |
| 3031 | " of set " + onosSetName + ":\n" + |
| 3032 | str( getResponses[ i ] ) ) |
| 3033 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3034 | main.log.debug( "Actual: " + str( current ) ) |
| 3035 | getResults = main.FALSE |
| 3036 | else: |
| 3037 | # error, set is not a set |
| 3038 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3039 | " has repeat elements in" + |
| 3040 | " set " + onosSetName + ":\n" + |
| 3041 | str( getResponses[ i ] ) ) |
| 3042 | getResults = main.FALSE |
| 3043 | elif getResponses[ i ] == main.ERROR: |
| 3044 | getResults = main.FALSE |
| 3045 | sizeResponses = [] |
| 3046 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3047 | for i in range( main.numCtrls ): |
| 3048 | t = main.Thread( target=main.CLIs[i].setTestSize, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3049 | name="setTestSize-" + str( i ), |
| 3050 | args=[ onosSetName ] ) |
| 3051 | threads.append( t ) |
| 3052 | t.start() |
| 3053 | for t in threads: |
| 3054 | t.join() |
| 3055 | sizeResponses.append( t.result ) |
| 3056 | sizeResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3057 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3058 | if size != sizeResponses[ i ]: |
| 3059 | sizeResults = main.FALSE |
| 3060 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3061 | " expected a size of " + str( size ) + |
| 3062 | " for set " + onosSetName + |
| 3063 | " but got " + str( sizeResponses[ i ] ) ) |
| 3064 | removeAllResults = removeAllResults and getResults and sizeResults |
| 3065 | utilities.assert_equals( expect=main.TRUE, |
| 3066 | actual=removeAllResults, |
| 3067 | onpass="Set removeAll correct", |
| 3068 | onfail="Set removeAll was incorrect" ) |
| 3069 | |
| 3070 | main.step( "Distributed Set addAll()" ) |
| 3071 | onosSet.update( addAllValue.split() ) |
| 3072 | addResponses = [] |
| 3073 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3074 | for i in range( main.numCtrls ): |
| 3075 | t = main.Thread( target=main.CLIs[i].setTestAdd, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3076 | name="setTestAddAll-" + str( i ), |
| 3077 | args=[ onosSetName, addAllValue ] ) |
| 3078 | threads.append( t ) |
| 3079 | t.start() |
| 3080 | for t in threads: |
| 3081 | t.join() |
| 3082 | addResponses.append( t.result ) |
| 3083 | |
| 3084 | # main.TRUE = successfully changed the set |
| 3085 | # main.FALSE = action resulted in no change in set |
| 3086 | # main.ERROR - Some error in executing the function |
| 3087 | addAllResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3088 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3089 | if addResponses[ i ] == main.TRUE: |
| 3090 | # All is well |
| 3091 | pass |
| 3092 | elif addResponses[ i ] == main.FALSE: |
| 3093 | # Already in set, probably fine |
| 3094 | pass |
| 3095 | elif addResponses[ i ] == main.ERROR: |
| 3096 | # Error in execution |
| 3097 | addAllResults = main.FALSE |
| 3098 | else: |
| 3099 | # unexpected result |
| 3100 | addAllResults = main.FALSE |
| 3101 | if addAllResults != main.TRUE: |
| 3102 | main.log.error( "Error executing set addAll" ) |
| 3103 | |
| 3104 | # Check if set is still correct |
| 3105 | size = len( onosSet ) |
| 3106 | getResponses = [] |
| 3107 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3108 | for i in range( main.numCtrls ): |
| 3109 | t = main.Thread( target=main.CLIs[i].setTestGet, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3110 | name="setTestGet-" + str( i ), |
| 3111 | args=[ onosSetName ] ) |
| 3112 | threads.append( t ) |
| 3113 | t.start() |
| 3114 | for t in threads: |
| 3115 | t.join() |
| 3116 | getResponses.append( t.result ) |
| 3117 | getResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3118 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3119 | if isinstance( getResponses[ i ], list): |
| 3120 | current = set( getResponses[ i ] ) |
| 3121 | if len( current ) == len( getResponses[ i ] ): |
| 3122 | # no repeats |
| 3123 | if onosSet != current: |
| 3124 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3125 | " has incorrect view" + |
| 3126 | " of set " + onosSetName + ":\n" + |
| 3127 | str( getResponses[ i ] ) ) |
| 3128 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3129 | main.log.debug( "Actual: " + str( current ) ) |
| 3130 | getResults = main.FALSE |
| 3131 | else: |
| 3132 | # error, set is not a set |
| 3133 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3134 | " has repeat elements in" + |
| 3135 | " set " + onosSetName + ":\n" + |
| 3136 | str( getResponses[ i ] ) ) |
| 3137 | getResults = main.FALSE |
| 3138 | elif getResponses[ i ] == main.ERROR: |
| 3139 | getResults = main.FALSE |
| 3140 | sizeResponses = [] |
| 3141 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3142 | for i in range( main.numCtrls ): |
| 3143 | t = main.Thread( target=main.CLIs[i].setTestSize, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3144 | name="setTestSize-" + str( i ), |
| 3145 | args=[ onosSetName ] ) |
| 3146 | threads.append( t ) |
| 3147 | t.start() |
| 3148 | for t in threads: |
| 3149 | t.join() |
| 3150 | sizeResponses.append( t.result ) |
| 3151 | sizeResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3152 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3153 | if size != sizeResponses[ i ]: |
| 3154 | sizeResults = main.FALSE |
| 3155 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3156 | " expected a size of " + str( size ) + |
| 3157 | " for set " + onosSetName + |
| 3158 | " but got " + str( sizeResponses[ i ] ) ) |
| 3159 | addAllResults = addAllResults and getResults and sizeResults |
| 3160 | utilities.assert_equals( expect=main.TRUE, |
| 3161 | actual=addAllResults, |
| 3162 | onpass="Set addAll correct", |
| 3163 | onfail="Set addAll was incorrect" ) |
| 3164 | |
| 3165 | main.step( "Distributed Set clear()" ) |
| 3166 | onosSet.clear() |
| 3167 | clearResponses = [] |
| 3168 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3169 | for i in range( main.numCtrls ): |
| 3170 | t = main.Thread( target=main.CLIs[i].setTestRemove, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3171 | name="setTestClear-" + str( i ), |
| 3172 | args=[ onosSetName, " "], # Values doesn't matter |
| 3173 | kwargs={ "clear": True } ) |
| 3174 | threads.append( t ) |
| 3175 | t.start() |
| 3176 | for t in threads: |
| 3177 | t.join() |
| 3178 | clearResponses.append( t.result ) |
| 3179 | |
| 3180 | # main.TRUE = successfully changed the set |
| 3181 | # main.FALSE = action resulted in no change in set |
| 3182 | # main.ERROR - Some error in executing the function |
| 3183 | clearResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3184 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3185 | if clearResponses[ i ] == main.TRUE: |
| 3186 | # All is well |
| 3187 | pass |
| 3188 | elif clearResponses[ i ] == main.FALSE: |
| 3189 | # Nothing set, probably fine |
| 3190 | pass |
| 3191 | elif clearResponses[ i ] == main.ERROR: |
| 3192 | # Error in execution |
| 3193 | clearResults = main.FALSE |
| 3194 | else: |
| 3195 | # unexpected result |
| 3196 | clearResults = main.FALSE |
| 3197 | if clearResults != main.TRUE: |
| 3198 | main.log.error( "Error executing set clear" ) |
| 3199 | |
| 3200 | # Check if set is still correct |
| 3201 | size = len( onosSet ) |
| 3202 | getResponses = [] |
| 3203 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3204 | for i in range( main.numCtrls ): |
| 3205 | t = main.Thread( target=main.CLIs[i].setTestGet, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3206 | name="setTestGet-" + str( i ), |
| 3207 | args=[ onosSetName ] ) |
| 3208 | threads.append( t ) |
| 3209 | t.start() |
| 3210 | for t in threads: |
| 3211 | t.join() |
| 3212 | getResponses.append( t.result ) |
| 3213 | getResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3214 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3215 | if isinstance( getResponses[ i ], list): |
| 3216 | current = set( getResponses[ i ] ) |
| 3217 | if len( current ) == len( getResponses[ i ] ): |
| 3218 | # no repeats |
| 3219 | if onosSet != current: |
| 3220 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3221 | " has incorrect view" + |
| 3222 | " of set " + onosSetName + ":\n" + |
| 3223 | str( getResponses[ i ] ) ) |
| 3224 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3225 | main.log.debug( "Actual: " + str( current ) ) |
| 3226 | getResults = main.FALSE |
| 3227 | else: |
| 3228 | # error, set is not a set |
| 3229 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3230 | " has repeat elements in" + |
| 3231 | " set " + onosSetName + ":\n" + |
| 3232 | str( getResponses[ i ] ) ) |
| 3233 | getResults = main.FALSE |
| 3234 | elif getResponses[ i ] == main.ERROR: |
| 3235 | getResults = main.FALSE |
| 3236 | sizeResponses = [] |
| 3237 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3238 | for i in range( main.numCtrls ): |
| 3239 | t = main.Thread( target=main.CLIs[i].setTestSize, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3240 | name="setTestSize-" + str( i ), |
| 3241 | args=[ onosSetName ] ) |
| 3242 | threads.append( t ) |
| 3243 | t.start() |
| 3244 | for t in threads: |
| 3245 | t.join() |
| 3246 | sizeResponses.append( t.result ) |
| 3247 | sizeResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3248 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3249 | if size != sizeResponses[ i ]: |
| 3250 | sizeResults = main.FALSE |
| 3251 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3252 | " expected a size of " + str( size ) + |
| 3253 | " for set " + onosSetName + |
| 3254 | " but got " + str( sizeResponses[ i ] ) ) |
| 3255 | clearResults = clearResults and getResults and sizeResults |
| 3256 | utilities.assert_equals( expect=main.TRUE, |
| 3257 | actual=clearResults, |
| 3258 | onpass="Set clear correct", |
| 3259 | onfail="Set clear was incorrect" ) |
| 3260 | |
| 3261 | main.step( "Distributed Set addAll()" ) |
| 3262 | onosSet.update( addAllValue.split() ) |
| 3263 | addResponses = [] |
| 3264 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3265 | for i in range( main.numCtrls ): |
| 3266 | t = main.Thread( target=main.CLIs[i].setTestAdd, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3267 | name="setTestAddAll-" + str( i ), |
| 3268 | args=[ onosSetName, addAllValue ] ) |
| 3269 | threads.append( t ) |
| 3270 | t.start() |
| 3271 | for t in threads: |
| 3272 | t.join() |
| 3273 | addResponses.append( t.result ) |
| 3274 | |
| 3275 | # main.TRUE = successfully changed the set |
| 3276 | # main.FALSE = action resulted in no change in set |
| 3277 | # main.ERROR - Some error in executing the function |
| 3278 | addAllResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3279 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3280 | if addResponses[ i ] == main.TRUE: |
| 3281 | # All is well |
| 3282 | pass |
| 3283 | elif addResponses[ i ] == main.FALSE: |
| 3284 | # Already in set, probably fine |
| 3285 | pass |
| 3286 | elif addResponses[ i ] == main.ERROR: |
| 3287 | # Error in execution |
| 3288 | addAllResults = main.FALSE |
| 3289 | else: |
| 3290 | # unexpected result |
| 3291 | addAllResults = main.FALSE |
| 3292 | if addAllResults != main.TRUE: |
| 3293 | main.log.error( "Error executing set addAll" ) |
| 3294 | |
| 3295 | # Check if set is still correct |
| 3296 | size = len( onosSet ) |
| 3297 | getResponses = [] |
| 3298 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3299 | for i in range( main.numCtrls ): |
| 3300 | t = main.Thread( target=main.CLIs[i].setTestGet, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3301 | name="setTestGet-" + str( i ), |
| 3302 | args=[ onosSetName ] ) |
| 3303 | threads.append( t ) |
| 3304 | t.start() |
| 3305 | for t in threads: |
| 3306 | t.join() |
| 3307 | getResponses.append( t.result ) |
| 3308 | getResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3309 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3310 | if isinstance( getResponses[ i ], list): |
| 3311 | current = set( getResponses[ i ] ) |
| 3312 | if len( current ) == len( getResponses[ i ] ): |
| 3313 | # no repeats |
| 3314 | if onosSet != current: |
| 3315 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3316 | " has incorrect view" + |
| 3317 | " of set " + onosSetName + ":\n" + |
| 3318 | str( getResponses[ i ] ) ) |
| 3319 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3320 | main.log.debug( "Actual: " + str( current ) ) |
| 3321 | getResults = main.FALSE |
| 3322 | else: |
| 3323 | # error, set is not a set |
| 3324 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3325 | " has repeat elements in" + |
| 3326 | " set " + onosSetName + ":\n" + |
| 3327 | str( getResponses[ i ] ) ) |
| 3328 | getResults = main.FALSE |
| 3329 | elif getResponses[ i ] == main.ERROR: |
| 3330 | getResults = main.FALSE |
| 3331 | sizeResponses = [] |
| 3332 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3333 | for i in range( main.numCtrls ): |
| 3334 | t = main.Thread( target=main.CLIs[i].setTestSize, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3335 | name="setTestSize-" + str( i ), |
| 3336 | args=[ onosSetName ] ) |
| 3337 | threads.append( t ) |
| 3338 | t.start() |
| 3339 | for t in threads: |
| 3340 | t.join() |
| 3341 | sizeResponses.append( t.result ) |
| 3342 | sizeResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3343 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3344 | if size != sizeResponses[ i ]: |
| 3345 | sizeResults = main.FALSE |
| 3346 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3347 | " expected a size of " + str( size ) + |
| 3348 | " for set " + onosSetName + |
| 3349 | " but got " + str( sizeResponses[ i ] ) ) |
| 3350 | addAllResults = addAllResults and getResults and sizeResults |
| 3351 | utilities.assert_equals( expect=main.TRUE, |
| 3352 | actual=addAllResults, |
| 3353 | onpass="Set addAll correct", |
| 3354 | onfail="Set addAll was incorrect" ) |
| 3355 | |
| 3356 | main.step( "Distributed Set retain()" ) |
| 3357 | onosSet.intersection_update( retainValue.split() ) |
| 3358 | retainResponses = [] |
| 3359 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3360 | for i in range( main.numCtrls ): |
| 3361 | t = main.Thread( target=main.CLIs[i].setTestRemove, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3362 | name="setTestRetain-" + str( i ), |
| 3363 | args=[ onosSetName, retainValue ], |
| 3364 | kwargs={ "retain": True } ) |
| 3365 | threads.append( t ) |
| 3366 | t.start() |
| 3367 | for t in threads: |
| 3368 | t.join() |
| 3369 | retainResponses.append( t.result ) |
| 3370 | |
| 3371 | # main.TRUE = successfully changed the set |
| 3372 | # main.FALSE = action resulted in no change in set |
| 3373 | # main.ERROR - Some error in executing the function |
| 3374 | retainResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3375 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3376 | if retainResponses[ i ] == main.TRUE: |
| 3377 | # All is well |
| 3378 | pass |
| 3379 | elif retainResponses[ i ] == main.FALSE: |
| 3380 | # Already in set, probably fine |
| 3381 | pass |
| 3382 | elif retainResponses[ i ] == main.ERROR: |
| 3383 | # Error in execution |
| 3384 | retainResults = main.FALSE |
| 3385 | else: |
| 3386 | # unexpected result |
| 3387 | retainResults = main.FALSE |
| 3388 | if retainResults != main.TRUE: |
| 3389 | main.log.error( "Error executing set retain" ) |
| 3390 | |
| 3391 | # Check if set is still correct |
| 3392 | size = len( onosSet ) |
| 3393 | getResponses = [] |
| 3394 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3395 | for i in range( main.numCtrls ): |
| 3396 | t = main.Thread( target=main.CLIs[i].setTestGet, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3397 | name="setTestGet-" + str( i ), |
| 3398 | args=[ onosSetName ] ) |
| 3399 | threads.append( t ) |
| 3400 | t.start() |
| 3401 | for t in threads: |
| 3402 | t.join() |
| 3403 | getResponses.append( t.result ) |
| 3404 | getResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3405 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3406 | if isinstance( getResponses[ i ], list): |
| 3407 | current = set( getResponses[ i ] ) |
| 3408 | if len( current ) == len( getResponses[ i ] ): |
| 3409 | # no repeats |
| 3410 | if onosSet != current: |
| 3411 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3412 | " has incorrect view" + |
| 3413 | " of set " + onosSetName + ":\n" + |
| 3414 | str( getResponses[ i ] ) ) |
| 3415 | main.log.debug( "Expected: " + str( onosSet ) ) |
| 3416 | main.log.debug( "Actual: " + str( current ) ) |
| 3417 | getResults = main.FALSE |
| 3418 | else: |
| 3419 | # error, set is not a set |
| 3420 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3421 | " has repeat elements in" + |
| 3422 | " set " + onosSetName + ":\n" + |
| 3423 | str( getResponses[ i ] ) ) |
| 3424 | getResults = main.FALSE |
| 3425 | elif getResponses[ i ] == main.ERROR: |
| 3426 | getResults = main.FALSE |
| 3427 | sizeResponses = [] |
| 3428 | threads = [] |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3429 | for i in range( main.numCtrls ): |
| 3430 | t = main.Thread( target=main.CLIs[i].setTestSize, |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3431 | name="setTestSize-" + str( i ), |
| 3432 | args=[ onosSetName ] ) |
| 3433 | threads.append( t ) |
| 3434 | t.start() |
| 3435 | for t in threads: |
| 3436 | t.join() |
| 3437 | sizeResponses.append( t.result ) |
| 3438 | sizeResults = main.TRUE |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3439 | for i in range( main.numCtrls ): |
Jon Hall | 85794ff | 2015-07-08 14:12:30 -0700 | [diff] [blame] | 3440 | if size != sizeResponses[ i ]: |
| 3441 | sizeResults = main.FALSE |
| 3442 | main.log.error( "ONOS" + str( i + 1 ) + |
| 3443 | " expected a size of " + |
| 3444 | str( size ) + " for set " + onosSetName + |
| 3445 | " but got " + str( sizeResponses[ i ] ) ) |
| 3446 | retainResults = retainResults and getResults and sizeResults |
| 3447 | utilities.assert_equals( expect=main.TRUE, |
| 3448 | actual=retainResults, |
| 3449 | onpass="Set retain correct", |
| 3450 | onfail="Set retain was incorrect" ) |
| 3451 | |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 3452 | # Transactional maps |
| 3453 | main.step( "Partitioned Transactional maps put" ) |
| 3454 | tMapValue = "Testing" |
| 3455 | numKeys = 100 |
| 3456 | putResult = True |
| 3457 | putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue ) |
| 3458 | if len( putResponses ) == 100: |
| 3459 | for i in putResponses: |
| 3460 | if putResponses[ i ][ 'value' ] != tMapValue: |
| 3461 | putResult = False |
| 3462 | else: |
| 3463 | putResult = False |
| 3464 | if not putResult: |
| 3465 | main.log.debug( "Put response values: " + str( putResponses ) ) |
| 3466 | utilities.assert_equals( expect=True, |
| 3467 | actual=putResult, |
| 3468 | onpass="Partitioned Transactional Map put successful", |
| 3469 | onfail="Partitioned Transactional Map put values are incorrect" ) |
| 3470 | |
| 3471 | main.step( "Partitioned Transactional maps get" ) |
| 3472 | getCheck = True |
| 3473 | for n in range( 1, numKeys + 1 ): |
| 3474 | getResponses = [] |
| 3475 | threads = [] |
| 3476 | valueCheck = True |
| 3477 | for i in range( main.numCtrls ): |
| 3478 | t = main.Thread( target=main.CLIs[i].transactionalMapGet, |
| 3479 | name="TMap-get-" + str( i ), |
| 3480 | args=[ "Key" + str ( n ) ] ) |
| 3481 | threads.append( t ) |
| 3482 | t.start() |
| 3483 | for t in threads: |
| 3484 | t.join() |
| 3485 | getResponses.append( t.result ) |
| 3486 | for node in getResponses: |
| 3487 | if node != tMapValue: |
| 3488 | valueCheck = False |
| 3489 | if not valueCheck: |
| 3490 | main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" ) |
| 3491 | main.log.warn( getResponses ) |
| 3492 | getCheck = getCheck and valueCheck |
| 3493 | utilities.assert_equals( expect=True, |
| 3494 | actual=getCheck, |
| 3495 | onpass="Partitioned Transactional Map get values were correct", |
| 3496 | onfail="Partitioned Transactional Map values incorrect" ) |
| 3497 | |
| 3498 | main.step( "In-memory Transactional maps put" ) |
| 3499 | tMapValue = "Testing" |
| 3500 | numKeys = 100 |
| 3501 | putResult = True |
| 3502 | putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue, inMemory=True ) |
| 3503 | if len( putResponses ) == 100: |
| 3504 | for i in putResponses: |
| 3505 | if putResponses[ i ][ 'value' ] != tMapValue: |
| 3506 | putResult = False |
| 3507 | else: |
| 3508 | putResult = False |
| 3509 | if not putResult: |
| 3510 | main.log.debug( "Put response values: " + str( putResponses ) ) |
| 3511 | utilities.assert_equals( expect=True, |
| 3512 | actual=putResult, |
| 3513 | onpass="In-Memory Transactional Map put successful", |
| 3514 | onfail="In-Memory Transactional Map put values are incorrect" ) |
| 3515 | |
| 3516 | main.step( "In-Memory Transactional maps get" ) |
| 3517 | getCheck = True |
| 3518 | for n in range( 1, numKeys + 1 ): |
| 3519 | getResponses = [] |
| 3520 | threads = [] |
| 3521 | valueCheck = True |
| 3522 | for i in range( main.numCtrls ): |
| 3523 | t = main.Thread( target=main.CLIs[i].transactionalMapGet, |
| 3524 | name="TMap-get-" + str( i ), |
| 3525 | args=[ "Key" + str ( n ) ], |
| 3526 | kwargs={ "inMemory": True } ) |
| 3527 | threads.append( t ) |
| 3528 | t.start() |
| 3529 | for t in threads: |
| 3530 | t.join() |
| 3531 | getResponses.append( t.result ) |
| 3532 | for node in getResponses: |
| 3533 | if node != tMapValue: |
| 3534 | valueCheck = False |
| 3535 | if not valueCheck: |
| 3536 | main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" ) |
| 3537 | main.log.warn( getResponses ) |
| 3538 | getCheck = getCheck and valueCheck |
| 3539 | utilities.assert_equals( expect=True, |
| 3540 | actual=getCheck, |
| 3541 | onpass="In-Memory Transactional Map get values were correct", |
| 3542 | onfail="In-Memory Transactional Map values incorrect" ) |