Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 1 | import json |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 2 | import time |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3 | |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 4 | class HA(): |
Jon Hall | 57b5043 | 2015-10-22 10:20:10 -0700 | [diff] [blame] | 5 | |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 6 | def __init__( self ): |
| 7 | self.default = '' |
Jon Hall | 57b5043 | 2015-10-22 10:20:10 -0700 | [diff] [blame] | 8 | |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 9 | def consistentCheck( self ): |
| 10 | """ |
| 11 | Checks that TestON counters are consistent across all nodes. |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 12 | |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 13 | Returns the tuple (onosCounters, consistent) |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 14 | - onosCounters is the parsed json output of the counters command on |
| 15 | all nodes |
| 16 | - consistent is main.TRUE if all "TestON" counters are consitent across |
| 17 | all nodes or main.FALSE |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 18 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 19 | try: |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 20 | # Get onos counters results |
| 21 | onosCountersRaw = [] |
| 22 | threads = [] |
| 23 | for i in main.activeNodes: |
| 24 | t = main.Thread( target=utilities.retry, |
| 25 | name="counters-" + str( i ), |
| 26 | args=[ main.CLIs[i].counters, [ None ] ], |
| 27 | kwargs= { 'sleep': 5, 'attempts': 5, |
| 28 | 'randomTime': True } ) |
| 29 | threads.append( t ) |
| 30 | t.start() |
| 31 | for t in threads: |
| 32 | t.join() |
| 33 | onosCountersRaw.append( t.result ) |
| 34 | onosCounters = [] |
| 35 | for i in range( len( main.activeNodes ) ): |
| 36 | try: |
| 37 | onosCounters.append( json.loads( onosCountersRaw[i] ) ) |
| 38 | except ( ValueError, TypeError ): |
| 39 | main.log.error( "Could not parse counters response from ONOS" + |
| 40 | str( main.activeNodes[i] + 1 ) ) |
| 41 | main.log.warn( repr( onosCountersRaw[ i ] ) ) |
| 42 | onosCounters.append( [] ) |
| 43 | |
| 44 | testCounters = {} |
| 45 | # make a list of all the "TestON-*" counters in ONOS |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 46 | # lookes like a dict whose keys are the name of the ONOS node and |
| 47 | # values are a list of the counters. I.E. |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 48 | # { "ONOS1": [ { "name":"TestON-Partitions","value":56} ] |
| 49 | # } |
| 50 | # NOTE: There is an assumtion that all nodes are active |
| 51 | # based on the above for loops |
| 52 | for controller in enumerate( onosCounters ): |
| 53 | for key, value in controller[1].iteritems(): |
| 54 | if 'TestON' in key: |
| 55 | node = 'ONOS' + str( controller[0] + 1 ) |
| 56 | try: |
| 57 | testCounters[node].append( { key: value } ) |
| 58 | except KeyError: |
| 59 | testCounters[node] = [ { key: value } ] |
| 60 | # compare the counters on each node |
| 61 | firstV = testCounters.values()[0] |
| 62 | tmp = [ v == firstV for k, v in testCounters.iteritems() ] |
| 63 | if all( tmp ): |
| 64 | consistent = main.TRUE |
| 65 | else: |
| 66 | consistent = main.FALSE |
| 67 | main.log.error( "ONOS nodes have different values for counters:\n" + |
| 68 | testCounters ) |
| 69 | return ( onosCounters, consistent ) |
| 70 | except Exception: |
| 71 | main.log.exception( "" ) |
| 72 | main.cleanup() |
| 73 | main.exit() |
| 74 | |
| 75 | def counterCheck( self, counterName, counterValue ): |
| 76 | """ |
| 77 | Checks that TestON counters are consistent across all nodes and that |
| 78 | specified counter is in ONOS with the given value |
| 79 | """ |
| 80 | try: |
| 81 | correctResults = main.TRUE |
| 82 | # Get onos counters results and consistentCheck |
| 83 | onosCounters, consistent = self.consistentCheck() |
| 84 | # Check for correct values |
| 85 | for i in range( len( main.activeNodes ) ): |
| 86 | current = onosCounters[i] |
| 87 | onosValue = None |
| 88 | try: |
| 89 | onosValue = current.get( counterName ) |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 90 | except AttributeError: |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 91 | node = str( main.activeNodes[i] + 1 ) |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 92 | main.log.exception( "ONOS" + node + " counters result " + |
| 93 | "is not as expected" ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 94 | correctResults = main.FALSE |
| 95 | if onosValue == counterValue: |
| 96 | main.log.info( counterName + " counter value is correct" ) |
| 97 | else: |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 98 | main.log.error( counterName + |
| 99 | " counter value is incorrect," + |
| 100 | " expected value: " + str( counterValue ) + |
| 101 | " current value: " + str( onosValue ) ) |
Jon Hall | a440e87 | 2016-03-31 15:15:50 -0700 | [diff] [blame] | 102 | correctResults = main.FALSE |
| 103 | return consistent and correctResults |
| 104 | except Exception: |
| 105 | main.log.exception( "" ) |
| 106 | main.cleanup() |
| 107 | main.exit() |
Jon Hall | 41d39f1 | 2016-04-11 22:54:35 -0700 | [diff] [blame] | 108 | |
| 109 | def consistentLeaderboards( self, nodes ): |
| 110 | TOPIC = 'org.onosproject.election' |
| 111 | # FIXME: use threads |
| 112 | #FIXME: should we retry outside the function? |
| 113 | for n in range( 5 ): # Retry in case election is still happening |
| 114 | leaderList = [] |
| 115 | # Get all leaderboards |
| 116 | for cli in nodes: |
| 117 | leaderList.append( cli.specificLeaderCandidate( TOPIC ) ) |
| 118 | # Compare leaderboards |
| 119 | result = all( i == leaderList[0] for i in leaderList ) and\ |
| 120 | leaderList is not None |
| 121 | main.log.debug( leaderList ) |
| 122 | main.log.warn( result ) |
| 123 | if result: |
| 124 | return ( result, leaderList ) |
| 125 | time.sleep(5) # TODO: paramerterize |
| 126 | main.log.error( "Inconsistent leaderboards:" + str( leaderList ) ) |
| 127 | return ( result, leaderList ) |
| 128 | |
| 129 | def nodesCheck( self, nodes ): |
| 130 | nodesOutput = [] |
| 131 | results = True |
| 132 | threads = [] |
| 133 | for i in nodes: |
| 134 | t = main.Thread( target=main.CLIs[i].nodes, |
| 135 | name="nodes-" + str( i ), |
| 136 | args=[ ] ) |
| 137 | threads.append( t ) |
| 138 | t.start() |
| 139 | |
| 140 | for t in threads: |
| 141 | t.join() |
| 142 | nodesOutput.append( t.result ) |
| 143 | ips = [ main.nodes[node].ip_address for node in nodes ] |
| 144 | ips.sort() |
| 145 | for i in nodesOutput: |
| 146 | try: |
| 147 | current = json.loads( i ) |
| 148 | activeIps = [] |
| 149 | currentResult = False |
| 150 | for node in current: |
| 151 | if node['state'] == 'READY': |
| 152 | activeIps.append( node['ip'] ) |
| 153 | activeIps.sort() |
| 154 | if ips == activeIps: |
| 155 | currentResult = True |
| 156 | except ( ValueError, TypeError ): |
| 157 | main.log.error( "Error parsing nodes output" ) |
| 158 | main.log.warn( repr( i ) ) |
| 159 | currentResult = False |
| 160 | results = results and currentResult |
| 161 | return results |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 162 | |
| 163 | def CASE17( self, main ): |
| 164 | """ |
| 165 | Check for basic functionality with distributed primitives |
| 166 | """ |
| 167 | #TODO: Clean this up so it's not just a cut/paste from the test |
| 168 | try: |
| 169 | # Make sure variables are defined/set |
| 170 | assert main.numCtrls, "main.numCtrls not defined" |
| 171 | assert utilities.assert_equals, "utilities.assert_equals not defined" |
| 172 | assert main.CLIs, "main.CLIs not defined" |
| 173 | assert main.nodes, "main.nodes not defined" |
| 174 | assert main.pCounterName, "main.pCounterName not defined" |
| 175 | assert main.onosSetName, "main.onosSetName not defined" |
| 176 | # NOTE: assert fails if value is 0/None/Empty/False |
| 177 | try: |
| 178 | main.pCounterValue |
| 179 | except NameError: |
| 180 | main.log.error( "main.pCounterValue not defined, setting to 0" ) |
| 181 | main.pCounterValue = 0 |
| 182 | try: |
| 183 | main.onosSet |
| 184 | except NameError: |
| 185 | main.log.error( "main.onosSet not defined, setting to empty Set" ) |
| 186 | main.onosSet = set([]) |
| 187 | # Variables for the distributed primitives tests. These are local only |
| 188 | addValue = "a" |
| 189 | addAllValue = "a b c d e f" |
| 190 | retainValue = "c d e f" |
| 191 | valueName = "TestOn-Value" |
| 192 | valueValue = None |
| 193 | |
| 194 | description = "Check for basic functionality with distributed " +\ |
| 195 | "primitives" |
| 196 | main.case( description ) |
| 197 | main.caseExplanation = "Test the methods of the distributed " +\ |
| 198 | "primitives (counters and sets) throught the cli" |
| 199 | # DISTRIBUTED ATOMIC COUNTERS |
| 200 | # Partitioned counters |
| 201 | main.step( "Increment then get a default counter on each node" ) |
| 202 | pCounters = [] |
| 203 | threads = [] |
| 204 | addedPValues = [] |
| 205 | for i in main.activeNodes: |
| 206 | t = main.Thread( target=main.CLIs[i].counterTestAddAndGet, |
| 207 | name="counterAddAndGet-" + str( i ), |
| 208 | args=[ main.pCounterName ] ) |
| 209 | main.pCounterValue += 1 |
| 210 | addedPValues.append( main.pCounterValue ) |
| 211 | threads.append( t ) |
| 212 | t.start() |
| 213 | |
| 214 | for t in threads: |
| 215 | t.join() |
| 216 | pCounters.append( t.result ) |
| 217 | # Check that counter incremented numController times |
| 218 | pCounterResults = True |
| 219 | for i in addedPValues: |
| 220 | tmpResult = i in pCounters |
| 221 | pCounterResults = pCounterResults and tmpResult |
| 222 | if not tmpResult: |
| 223 | main.log.error( str( i ) + " is not in partitioned " |
| 224 | "counter incremented results" ) |
| 225 | utilities.assert_equals( expect=True, |
| 226 | actual=pCounterResults, |
| 227 | onpass="Default counter incremented", |
| 228 | onfail="Error incrementing default" + |
| 229 | " counter" ) |
| 230 | |
| 231 | main.step( "Get then Increment a default counter on each node" ) |
| 232 | pCounters = [] |
| 233 | threads = [] |
| 234 | addedPValues = [] |
| 235 | for i in main.activeNodes: |
| 236 | t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd, |
| 237 | name="counterGetAndAdd-" + str( i ), |
| 238 | args=[ main.pCounterName ] ) |
| 239 | addedPValues.append( main.pCounterValue ) |
| 240 | main.pCounterValue += 1 |
| 241 | threads.append( t ) |
| 242 | t.start() |
| 243 | |
| 244 | for t in threads: |
| 245 | t.join() |
| 246 | pCounters.append( t.result ) |
| 247 | # Check that counter incremented numController times |
| 248 | pCounterResults = True |
| 249 | for i in addedPValues: |
| 250 | tmpResult = i in pCounters |
| 251 | pCounterResults = pCounterResults and tmpResult |
| 252 | if not tmpResult: |
| 253 | main.log.error( str( i ) + " is not in partitioned " |
| 254 | "counter incremented results" ) |
| 255 | utilities.assert_equals( expect=True, |
| 256 | actual=pCounterResults, |
| 257 | onpass="Default counter incremented", |
| 258 | onfail="Error incrementing default" + |
| 259 | " counter" ) |
| 260 | |
| 261 | main.step( "Counters we added have the correct values" ) |
| 262 | incrementCheck = main.HA.counterCheck( main.pCounterName, main.pCounterValue ) |
| 263 | utilities.assert_equals( expect=main.TRUE, |
| 264 | actual=incrementCheck, |
| 265 | onpass="Added counters are correct", |
| 266 | onfail="Added counters are incorrect" ) |
| 267 | |
| 268 | main.step( "Add -8 to then get a default counter on each node" ) |
| 269 | pCounters = [] |
| 270 | threads = [] |
| 271 | addedPValues = [] |
| 272 | for i in main.activeNodes: |
| 273 | t = main.Thread( target=main.CLIs[i].counterTestAddAndGet, |
| 274 | name="counterIncrement-" + str( i ), |
| 275 | args=[ main.pCounterName ], |
| 276 | kwargs={ "delta": -8 } ) |
| 277 | main.pCounterValue += -8 |
| 278 | addedPValues.append( main.pCounterValue ) |
| 279 | threads.append( t ) |
| 280 | t.start() |
| 281 | |
| 282 | for t in threads: |
| 283 | t.join() |
| 284 | pCounters.append( t.result ) |
| 285 | # Check that counter incremented numController times |
| 286 | pCounterResults = True |
| 287 | for i in addedPValues: |
| 288 | tmpResult = i in pCounters |
| 289 | pCounterResults = pCounterResults and tmpResult |
| 290 | if not tmpResult: |
| 291 | main.log.error( str( i ) + " is not in partitioned " |
| 292 | "counter incremented results" ) |
| 293 | utilities.assert_equals( expect=True, |
| 294 | actual=pCounterResults, |
| 295 | onpass="Default counter incremented", |
| 296 | onfail="Error incrementing default" + |
| 297 | " counter" ) |
| 298 | |
| 299 | main.step( "Add 5 to then get a default counter on each node" ) |
| 300 | pCounters = [] |
| 301 | threads = [] |
| 302 | addedPValues = [] |
| 303 | for i in main.activeNodes: |
| 304 | t = main.Thread( target=main.CLIs[i].counterTestAddAndGet, |
| 305 | name="counterIncrement-" + str( i ), |
| 306 | args=[ main.pCounterName ], |
| 307 | kwargs={ "delta": 5 } ) |
| 308 | main.pCounterValue += 5 |
| 309 | addedPValues.append( main.pCounterValue ) |
| 310 | threads.append( t ) |
| 311 | t.start() |
| 312 | |
| 313 | for t in threads: |
| 314 | t.join() |
| 315 | pCounters.append( t.result ) |
| 316 | # Check that counter incremented numController times |
| 317 | pCounterResults = True |
| 318 | for i in addedPValues: |
| 319 | tmpResult = i in pCounters |
| 320 | pCounterResults = pCounterResults and tmpResult |
| 321 | if not tmpResult: |
| 322 | main.log.error( str( i ) + " is not in partitioned " |
| 323 | "counter incremented results" ) |
| 324 | utilities.assert_equals( expect=True, |
| 325 | actual=pCounterResults, |
| 326 | onpass="Default counter incremented", |
| 327 | onfail="Error incrementing default" + |
| 328 | " counter" ) |
| 329 | |
| 330 | main.step( "Get then add 5 to a default counter on each node" ) |
| 331 | pCounters = [] |
| 332 | threads = [] |
| 333 | addedPValues = [] |
| 334 | for i in main.activeNodes: |
| 335 | t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd, |
| 336 | name="counterIncrement-" + str( i ), |
| 337 | args=[ main.pCounterName ], |
| 338 | kwargs={ "delta": 5 } ) |
| 339 | addedPValues.append( main.pCounterValue ) |
| 340 | main.pCounterValue += 5 |
| 341 | threads.append( t ) |
| 342 | t.start() |
| 343 | |
| 344 | for t in threads: |
| 345 | t.join() |
| 346 | pCounters.append( t.result ) |
| 347 | # Check that counter incremented numController times |
| 348 | pCounterResults = True |
| 349 | for i in addedPValues: |
| 350 | tmpResult = i in pCounters |
| 351 | pCounterResults = pCounterResults and tmpResult |
| 352 | if not tmpResult: |
| 353 | main.log.error( str( i ) + " is not in partitioned " |
| 354 | "counter incremented results" ) |
| 355 | utilities.assert_equals( expect=True, |
| 356 | actual=pCounterResults, |
| 357 | onpass="Default counter incremented", |
| 358 | onfail="Error incrementing default" + |
| 359 | " counter" ) |
| 360 | |
| 361 | main.step( "Counters we added have the correct values" ) |
| 362 | incrementCheck = main.HA.counterCheck( main.pCounterName, main.pCounterValue ) |
| 363 | utilities.assert_equals( expect=main.TRUE, |
| 364 | actual=incrementCheck, |
| 365 | onpass="Added counters are correct", |
| 366 | onfail="Added counters are incorrect" ) |
| 367 | |
| 368 | # DISTRIBUTED SETS |
| 369 | main.step( "Distributed Set get" ) |
| 370 | size = len( main.onosSet ) |
| 371 | getResponses = [] |
| 372 | threads = [] |
| 373 | for i in main.activeNodes: |
| 374 | t = main.Thread( target=main.CLIs[i].setTestGet, |
| 375 | name="setTestGet-" + str( i ), |
| 376 | args=[ main.onosSetName ] ) |
| 377 | threads.append( t ) |
| 378 | t.start() |
| 379 | for t in threads: |
| 380 | t.join() |
| 381 | getResponses.append( t.result ) |
| 382 | |
| 383 | getResults = main.TRUE |
| 384 | for i in range( len( main.activeNodes ) ): |
| 385 | node = str( main.activeNodes[i] + 1 ) |
| 386 | if isinstance( getResponses[ i ], list): |
| 387 | current = set( getResponses[ i ] ) |
| 388 | if len( current ) == len( getResponses[ i ] ): |
| 389 | # no repeats |
| 390 | if main.onosSet != current: |
| 391 | main.log.error( "ONOS" + node + |
| 392 | " has incorrect view" + |
| 393 | " of set " + main.onosSetName + ":\n" + |
| 394 | str( getResponses[ i ] ) ) |
| 395 | main.log.debug( "Expected: " + str( main.onosSet ) ) |
| 396 | main.log.debug( "Actual: " + str( current ) ) |
| 397 | getResults = main.FALSE |
| 398 | else: |
| 399 | # error, set is not a set |
| 400 | main.log.error( "ONOS" + node + |
| 401 | " has repeat elements in" + |
| 402 | " set " + main.onosSetName + ":\n" + |
| 403 | str( getResponses[ i ] ) ) |
| 404 | getResults = main.FALSE |
| 405 | elif getResponses[ i ] == main.ERROR: |
| 406 | getResults = main.FALSE |
| 407 | utilities.assert_equals( expect=main.TRUE, |
| 408 | actual=getResults, |
| 409 | onpass="Set elements are correct", |
| 410 | onfail="Set elements are incorrect" ) |
| 411 | |
| 412 | main.step( "Distributed Set size" ) |
| 413 | sizeResponses = [] |
| 414 | threads = [] |
| 415 | for i in main.activeNodes: |
| 416 | t = main.Thread( target=main.CLIs[i].setTestSize, |
| 417 | name="setTestSize-" + str( i ), |
| 418 | args=[ main.onosSetName ] ) |
| 419 | threads.append( t ) |
| 420 | t.start() |
| 421 | for t in threads: |
| 422 | t.join() |
| 423 | sizeResponses.append( t.result ) |
| 424 | |
| 425 | sizeResults = main.TRUE |
| 426 | for i in range( len( main.activeNodes ) ): |
| 427 | node = str( main.activeNodes[i] + 1 ) |
| 428 | if size != sizeResponses[ i ]: |
| 429 | sizeResults = main.FALSE |
| 430 | main.log.error( "ONOS" + node + |
| 431 | " expected a size of " + str( size ) + |
| 432 | " for set " + main.onosSetName + |
| 433 | " but got " + str( sizeResponses[ i ] ) ) |
| 434 | utilities.assert_equals( expect=main.TRUE, |
| 435 | actual=sizeResults, |
| 436 | onpass="Set sizes are correct", |
| 437 | onfail="Set sizes are incorrect" ) |
| 438 | |
| 439 | main.step( "Distributed Set add()" ) |
| 440 | main.onosSet.add( addValue ) |
| 441 | addResponses = [] |
| 442 | threads = [] |
| 443 | for i in main.activeNodes: |
| 444 | t = main.Thread( target=main.CLIs[i].setTestAdd, |
| 445 | name="setTestAdd-" + str( i ), |
| 446 | args=[ main.onosSetName, addValue ] ) |
| 447 | threads.append( t ) |
| 448 | t.start() |
| 449 | for t in threads: |
| 450 | t.join() |
| 451 | addResponses.append( t.result ) |
| 452 | |
| 453 | # main.TRUE = successfully changed the set |
| 454 | # main.FALSE = action resulted in no change in set |
| 455 | # main.ERROR - Some error in executing the function |
| 456 | addResults = main.TRUE |
| 457 | for i in range( len( main.activeNodes ) ): |
| 458 | if addResponses[ i ] == main.TRUE: |
| 459 | # All is well |
| 460 | pass |
| 461 | elif addResponses[ i ] == main.FALSE: |
| 462 | # Already in set, probably fine |
| 463 | pass |
| 464 | elif addResponses[ i ] == main.ERROR: |
| 465 | # Error in execution |
| 466 | addResults = main.FALSE |
| 467 | else: |
| 468 | # unexpected result |
| 469 | addResults = main.FALSE |
| 470 | if addResults != main.TRUE: |
| 471 | main.log.error( "Error executing set add" ) |
| 472 | |
| 473 | # Check if set is still correct |
| 474 | size = len( main.onosSet ) |
| 475 | getResponses = [] |
| 476 | threads = [] |
| 477 | for i in main.activeNodes: |
| 478 | t = main.Thread( target=main.CLIs[i].setTestGet, |
| 479 | name="setTestGet-" + str( i ), |
| 480 | args=[ main.onosSetName ] ) |
| 481 | threads.append( t ) |
| 482 | t.start() |
| 483 | for t in threads: |
| 484 | t.join() |
| 485 | getResponses.append( t.result ) |
| 486 | getResults = main.TRUE |
| 487 | for i in range( len( main.activeNodes ) ): |
| 488 | node = str( main.activeNodes[i] + 1 ) |
| 489 | if isinstance( getResponses[ i ], list): |
| 490 | current = set( getResponses[ i ] ) |
| 491 | if len( current ) == len( getResponses[ i ] ): |
| 492 | # no repeats |
| 493 | if main.onosSet != current: |
| 494 | main.log.error( "ONOS" + node + " has incorrect view" + |
| 495 | " of set " + main.onosSetName + ":\n" + |
| 496 | str( getResponses[ i ] ) ) |
| 497 | main.log.debug( "Expected: " + str( main.onosSet ) ) |
| 498 | main.log.debug( "Actual: " + str( current ) ) |
| 499 | getResults = main.FALSE |
| 500 | else: |
| 501 | # error, set is not a set |
| 502 | main.log.error( "ONOS" + node + " has repeat elements in" + |
| 503 | " set " + main.onosSetName + ":\n" + |
| 504 | str( getResponses[ i ] ) ) |
| 505 | getResults = main.FALSE |
| 506 | elif getResponses[ i ] == main.ERROR: |
| 507 | getResults = main.FALSE |
| 508 | sizeResponses = [] |
| 509 | threads = [] |
| 510 | for i in main.activeNodes: |
| 511 | t = main.Thread( target=main.CLIs[i].setTestSize, |
| 512 | name="setTestSize-" + str( i ), |
| 513 | args=[ main.onosSetName ] ) |
| 514 | threads.append( t ) |
| 515 | t.start() |
| 516 | for t in threads: |
| 517 | t.join() |
| 518 | sizeResponses.append( t.result ) |
| 519 | sizeResults = main.TRUE |
| 520 | for i in range( len( main.activeNodes ) ): |
| 521 | node = str( main.activeNodes[i] + 1 ) |
| 522 | if size != sizeResponses[ i ]: |
| 523 | sizeResults = main.FALSE |
| 524 | main.log.error( "ONOS" + node + |
| 525 | " expected a size of " + str( size ) + |
| 526 | " for set " + main.onosSetName + |
| 527 | " but got " + str( sizeResponses[ i ] ) ) |
| 528 | addResults = addResults and getResults and sizeResults |
| 529 | utilities.assert_equals( expect=main.TRUE, |
| 530 | actual=addResults, |
| 531 | onpass="Set add correct", |
| 532 | onfail="Set add was incorrect" ) |
| 533 | |
| 534 | main.step( "Distributed Set addAll()" ) |
| 535 | main.onosSet.update( addAllValue.split() ) |
| 536 | addResponses = [] |
| 537 | threads = [] |
| 538 | for i in main.activeNodes: |
| 539 | t = main.Thread( target=main.CLIs[i].setTestAdd, |
| 540 | name="setTestAddAll-" + str( i ), |
| 541 | args=[ main.onosSetName, addAllValue ] ) |
| 542 | threads.append( t ) |
| 543 | t.start() |
| 544 | for t in threads: |
| 545 | t.join() |
| 546 | addResponses.append( t.result ) |
| 547 | |
| 548 | # main.TRUE = successfully changed the set |
| 549 | # main.FALSE = action resulted in no change in set |
| 550 | # main.ERROR - Some error in executing the function |
| 551 | addAllResults = main.TRUE |
| 552 | for i in range( len( main.activeNodes ) ): |
| 553 | if addResponses[ i ] == main.TRUE: |
| 554 | # All is well |
| 555 | pass |
| 556 | elif addResponses[ i ] == main.FALSE: |
| 557 | # Already in set, probably fine |
| 558 | pass |
| 559 | elif addResponses[ i ] == main.ERROR: |
| 560 | # Error in execution |
| 561 | addAllResults = main.FALSE |
| 562 | else: |
| 563 | # unexpected result |
| 564 | addAllResults = main.FALSE |
| 565 | if addAllResults != main.TRUE: |
| 566 | main.log.error( "Error executing set addAll" ) |
| 567 | |
| 568 | # Check if set is still correct |
| 569 | size = len( main.onosSet ) |
| 570 | getResponses = [] |
| 571 | threads = [] |
| 572 | for i in main.activeNodes: |
| 573 | t = main.Thread( target=main.CLIs[i].setTestGet, |
| 574 | name="setTestGet-" + str( i ), |
| 575 | args=[ main.onosSetName ] ) |
| 576 | threads.append( t ) |
| 577 | t.start() |
| 578 | for t in threads: |
| 579 | t.join() |
| 580 | getResponses.append( t.result ) |
| 581 | getResults = main.TRUE |
| 582 | for i in range( len( main.activeNodes ) ): |
| 583 | node = str( main.activeNodes[i] + 1 ) |
| 584 | if isinstance( getResponses[ i ], list): |
| 585 | current = set( getResponses[ i ] ) |
| 586 | if len( current ) == len( getResponses[ i ] ): |
| 587 | # no repeats |
| 588 | if main.onosSet != current: |
| 589 | main.log.error( "ONOS" + node + |
| 590 | " has incorrect view" + |
| 591 | " of set " + main.onosSetName + ":\n" + |
| 592 | str( getResponses[ i ] ) ) |
| 593 | main.log.debug( "Expected: " + str( main.onosSet ) ) |
| 594 | main.log.debug( "Actual: " + str( current ) ) |
| 595 | getResults = main.FALSE |
| 596 | else: |
| 597 | # error, set is not a set |
| 598 | main.log.error( "ONOS" + node + |
| 599 | " has repeat elements in" + |
| 600 | " set " + main.onosSetName + ":\n" + |
| 601 | str( getResponses[ i ] ) ) |
| 602 | getResults = main.FALSE |
| 603 | elif getResponses[ i ] == main.ERROR: |
| 604 | getResults = main.FALSE |
| 605 | sizeResponses = [] |
| 606 | threads = [] |
| 607 | for i in main.activeNodes: |
| 608 | t = main.Thread( target=main.CLIs[i].setTestSize, |
| 609 | name="setTestSize-" + str( i ), |
| 610 | args=[ main.onosSetName ] ) |
| 611 | threads.append( t ) |
| 612 | t.start() |
| 613 | for t in threads: |
| 614 | t.join() |
| 615 | sizeResponses.append( t.result ) |
| 616 | sizeResults = main.TRUE |
| 617 | for i in range( len( main.activeNodes ) ): |
| 618 | node = str( main.activeNodes[i] + 1 ) |
| 619 | if size != sizeResponses[ i ]: |
| 620 | sizeResults = main.FALSE |
| 621 | main.log.error( "ONOS" + node + |
| 622 | " expected a size of " + str( size ) + |
| 623 | " for set " + main.onosSetName + |
| 624 | " but got " + str( sizeResponses[ i ] ) ) |
| 625 | addAllResults = addAllResults and getResults and sizeResults |
| 626 | utilities.assert_equals( expect=main.TRUE, |
| 627 | actual=addAllResults, |
| 628 | onpass="Set addAll correct", |
| 629 | onfail="Set addAll was incorrect" ) |
| 630 | |
| 631 | main.step( "Distributed Set contains()" ) |
| 632 | containsResponses = [] |
| 633 | threads = [] |
| 634 | for i in main.activeNodes: |
| 635 | t = main.Thread( target=main.CLIs[i].setTestGet, |
| 636 | name="setContains-" + str( i ), |
| 637 | args=[ main.onosSetName ], |
| 638 | kwargs={ "values": addValue } ) |
| 639 | threads.append( t ) |
| 640 | t.start() |
| 641 | for t in threads: |
| 642 | t.join() |
| 643 | # NOTE: This is the tuple |
| 644 | containsResponses.append( t.result ) |
| 645 | |
| 646 | containsResults = main.TRUE |
| 647 | for i in range( len( main.activeNodes ) ): |
| 648 | if containsResponses[ i ] == main.ERROR: |
| 649 | containsResults = main.FALSE |
| 650 | else: |
| 651 | containsResults = containsResults and\ |
| 652 | containsResponses[ i ][ 1 ] |
| 653 | utilities.assert_equals( expect=main.TRUE, |
| 654 | actual=containsResults, |
| 655 | onpass="Set contains is functional", |
| 656 | onfail="Set contains failed" ) |
| 657 | |
| 658 | main.step( "Distributed Set containsAll()" ) |
| 659 | containsAllResponses = [] |
| 660 | threads = [] |
| 661 | for i in main.activeNodes: |
| 662 | t = main.Thread( target=main.CLIs[i].setTestGet, |
| 663 | name="setContainsAll-" + str( i ), |
| 664 | args=[ main.onosSetName ], |
| 665 | kwargs={ "values": addAllValue } ) |
| 666 | threads.append( t ) |
| 667 | t.start() |
| 668 | for t in threads: |
| 669 | t.join() |
| 670 | # NOTE: This is the tuple |
| 671 | containsAllResponses.append( t.result ) |
| 672 | |
| 673 | containsAllResults = main.TRUE |
| 674 | for i in range( len( main.activeNodes ) ): |
| 675 | if containsResponses[ i ] == main.ERROR: |
| 676 | containsResults = main.FALSE |
| 677 | else: |
| 678 | containsResults = containsResults and\ |
| 679 | containsResponses[ i ][ 1 ] |
| 680 | utilities.assert_equals( expect=main.TRUE, |
| 681 | actual=containsAllResults, |
| 682 | onpass="Set containsAll is functional", |
| 683 | onfail="Set containsAll failed" ) |
| 684 | |
| 685 | main.step( "Distributed Set remove()" ) |
| 686 | main.onosSet.remove( addValue ) |
| 687 | removeResponses = [] |
| 688 | threads = [] |
| 689 | for i in main.activeNodes: |
| 690 | t = main.Thread( target=main.CLIs[i].setTestRemove, |
| 691 | name="setTestRemove-" + str( i ), |
| 692 | args=[ main.onosSetName, addValue ] ) |
| 693 | threads.append( t ) |
| 694 | t.start() |
| 695 | for t in threads: |
| 696 | t.join() |
| 697 | removeResponses.append( t.result ) |
| 698 | |
| 699 | # main.TRUE = successfully changed the set |
| 700 | # main.FALSE = action resulted in no change in set |
| 701 | # main.ERROR - Some error in executing the function |
| 702 | removeResults = main.TRUE |
| 703 | for i in range( len( main.activeNodes ) ): |
| 704 | if removeResponses[ i ] == main.TRUE: |
| 705 | # All is well |
| 706 | pass |
| 707 | elif removeResponses[ i ] == main.FALSE: |
| 708 | # not in set, probably fine |
| 709 | pass |
| 710 | elif removeResponses[ i ] == main.ERROR: |
| 711 | # Error in execution |
| 712 | removeResults = main.FALSE |
| 713 | else: |
| 714 | # unexpected result |
| 715 | removeResults = main.FALSE |
| 716 | if removeResults != main.TRUE: |
| 717 | main.log.error( "Error executing set remove" ) |
| 718 | |
| 719 | # Check if set is still correct |
| 720 | size = len( main.onosSet ) |
| 721 | getResponses = [] |
| 722 | threads = [] |
| 723 | for i in main.activeNodes: |
| 724 | t = main.Thread( target=main.CLIs[i].setTestGet, |
| 725 | name="setTestGet-" + str( i ), |
| 726 | args=[ main.onosSetName ] ) |
| 727 | threads.append( t ) |
| 728 | t.start() |
| 729 | for t in threads: |
| 730 | t.join() |
| 731 | getResponses.append( t.result ) |
| 732 | getResults = main.TRUE |
| 733 | for i in range( len( main.activeNodes ) ): |
| 734 | node = str( main.activeNodes[i] + 1 ) |
| 735 | if isinstance( getResponses[ i ], list): |
| 736 | current = set( getResponses[ i ] ) |
| 737 | if len( current ) == len( getResponses[ i ] ): |
| 738 | # no repeats |
| 739 | if main.onosSet != current: |
| 740 | main.log.error( "ONOS" + node + |
| 741 | " has incorrect view" + |
| 742 | " of set " + main.onosSetName + ":\n" + |
| 743 | str( getResponses[ i ] ) ) |
| 744 | main.log.debug( "Expected: " + str( main.onosSet ) ) |
| 745 | main.log.debug( "Actual: " + str( current ) ) |
| 746 | getResults = main.FALSE |
| 747 | else: |
| 748 | # error, set is not a set |
| 749 | main.log.error( "ONOS" + node + |
| 750 | " has repeat elements in" + |
| 751 | " set " + main.onosSetName + ":\n" + |
| 752 | str( getResponses[ i ] ) ) |
| 753 | getResults = main.FALSE |
| 754 | elif getResponses[ i ] == main.ERROR: |
| 755 | getResults = main.FALSE |
| 756 | sizeResponses = [] |
| 757 | threads = [] |
| 758 | for i in main.activeNodes: |
| 759 | t = main.Thread( target=main.CLIs[i].setTestSize, |
| 760 | name="setTestSize-" + str( i ), |
| 761 | args=[ main.onosSetName ] ) |
| 762 | threads.append( t ) |
| 763 | t.start() |
| 764 | for t in threads: |
| 765 | t.join() |
| 766 | sizeResponses.append( t.result ) |
| 767 | sizeResults = main.TRUE |
| 768 | for i in range( len( main.activeNodes ) ): |
| 769 | node = str( main.activeNodes[i] + 1 ) |
| 770 | if size != sizeResponses[ i ]: |
| 771 | sizeResults = main.FALSE |
| 772 | main.log.error( "ONOS" + node + |
| 773 | " expected a size of " + str( size ) + |
| 774 | " for set " + main.onosSetName + |
| 775 | " but got " + str( sizeResponses[ i ] ) ) |
| 776 | removeResults = removeResults and getResults and sizeResults |
| 777 | utilities.assert_equals( expect=main.TRUE, |
| 778 | actual=removeResults, |
| 779 | onpass="Set remove correct", |
| 780 | onfail="Set remove was incorrect" ) |
| 781 | |
| 782 | main.step( "Distributed Set removeAll()" ) |
| 783 | main.onosSet.difference_update( addAllValue.split() ) |
| 784 | removeAllResponses = [] |
| 785 | threads = [] |
| 786 | try: |
| 787 | for i in main.activeNodes: |
| 788 | t = main.Thread( target=main.CLIs[i].setTestRemove, |
| 789 | name="setTestRemoveAll-" + str( i ), |
| 790 | args=[ main.onosSetName, addAllValue ] ) |
| 791 | threads.append( t ) |
| 792 | t.start() |
| 793 | for t in threads: |
| 794 | t.join() |
| 795 | removeAllResponses.append( t.result ) |
| 796 | except Exception, e: |
| 797 | main.log.exception(e) |
| 798 | |
| 799 | # main.TRUE = successfully changed the set |
| 800 | # main.FALSE = action resulted in no change in set |
| 801 | # main.ERROR - Some error in executing the function |
| 802 | removeAllResults = main.TRUE |
| 803 | for i in range( len( main.activeNodes ) ): |
| 804 | if removeAllResponses[ i ] == main.TRUE: |
| 805 | # All is well |
| 806 | pass |
| 807 | elif removeAllResponses[ i ] == main.FALSE: |
| 808 | # not in set, probably fine |
| 809 | pass |
| 810 | elif removeAllResponses[ i ] == main.ERROR: |
| 811 | # Error in execution |
| 812 | removeAllResults = main.FALSE |
| 813 | else: |
| 814 | # unexpected result |
| 815 | removeAllResults = main.FALSE |
| 816 | if removeAllResults != main.TRUE: |
| 817 | main.log.error( "Error executing set removeAll" ) |
| 818 | |
| 819 | # Check if set is still correct |
| 820 | size = len( main.onosSet ) |
| 821 | getResponses = [] |
| 822 | threads = [] |
| 823 | for i in main.activeNodes: |
| 824 | t = main.Thread( target=main.CLIs[i].setTestGet, |
| 825 | name="setTestGet-" + str( i ), |
| 826 | args=[ main.onosSetName ] ) |
| 827 | threads.append( t ) |
| 828 | t.start() |
| 829 | for t in threads: |
| 830 | t.join() |
| 831 | getResponses.append( t.result ) |
| 832 | getResults = main.TRUE |
| 833 | for i in range( len( main.activeNodes ) ): |
| 834 | node = str( main.activeNodes[i] + 1 ) |
| 835 | if isinstance( getResponses[ i ], list): |
| 836 | current = set( getResponses[ i ] ) |
| 837 | if len( current ) == len( getResponses[ i ] ): |
| 838 | # no repeats |
| 839 | if main.onosSet != current: |
| 840 | main.log.error( "ONOS" + node + |
| 841 | " has incorrect view" + |
| 842 | " of set " + main.onosSetName + ":\n" + |
| 843 | str( getResponses[ i ] ) ) |
| 844 | main.log.debug( "Expected: " + str( main.onosSet ) ) |
| 845 | main.log.debug( "Actual: " + str( current ) ) |
| 846 | getResults = main.FALSE |
| 847 | else: |
| 848 | # error, set is not a set |
| 849 | main.log.error( "ONOS" + node + |
| 850 | " has repeat elements in" + |
| 851 | " set " + main.onosSetName + ":\n" + |
| 852 | str( getResponses[ i ] ) ) |
| 853 | getResults = main.FALSE |
| 854 | elif getResponses[ i ] == main.ERROR: |
| 855 | getResults = main.FALSE |
| 856 | sizeResponses = [] |
| 857 | threads = [] |
| 858 | for i in main.activeNodes: |
| 859 | t = main.Thread( target=main.CLIs[i].setTestSize, |
| 860 | name="setTestSize-" + str( i ), |
| 861 | args=[ main.onosSetName ] ) |
| 862 | threads.append( t ) |
| 863 | t.start() |
| 864 | for t in threads: |
| 865 | t.join() |
| 866 | sizeResponses.append( t.result ) |
| 867 | sizeResults = main.TRUE |
| 868 | for i in range( len( main.activeNodes ) ): |
| 869 | node = str( main.activeNodes[i] + 1 ) |
| 870 | if size != sizeResponses[ i ]: |
| 871 | sizeResults = main.FALSE |
| 872 | main.log.error( "ONOS" + node + |
| 873 | " expected a size of " + str( size ) + |
| 874 | " for set " + main.onosSetName + |
| 875 | " but got " + str( sizeResponses[ i ] ) ) |
| 876 | removeAllResults = removeAllResults and getResults and sizeResults |
| 877 | utilities.assert_equals( expect=main.TRUE, |
| 878 | actual=removeAllResults, |
| 879 | onpass="Set removeAll correct", |
| 880 | onfail="Set removeAll was incorrect" ) |
| 881 | |
| 882 | main.step( "Distributed Set addAll()" ) |
| 883 | main.onosSet.update( addAllValue.split() ) |
| 884 | addResponses = [] |
| 885 | threads = [] |
| 886 | for i in main.activeNodes: |
| 887 | t = main.Thread( target=main.CLIs[i].setTestAdd, |
| 888 | name="setTestAddAll-" + str( i ), |
| 889 | args=[ main.onosSetName, addAllValue ] ) |
| 890 | threads.append( t ) |
| 891 | t.start() |
| 892 | for t in threads: |
| 893 | t.join() |
| 894 | addResponses.append( t.result ) |
| 895 | |
| 896 | # main.TRUE = successfully changed the set |
| 897 | # main.FALSE = action resulted in no change in set |
| 898 | # main.ERROR - Some error in executing the function |
| 899 | addAllResults = main.TRUE |
| 900 | for i in range( len( main.activeNodes ) ): |
| 901 | if addResponses[ i ] == main.TRUE: |
| 902 | # All is well |
| 903 | pass |
| 904 | elif addResponses[ i ] == main.FALSE: |
| 905 | # Already in set, probably fine |
| 906 | pass |
| 907 | elif addResponses[ i ] == main.ERROR: |
| 908 | # Error in execution |
| 909 | addAllResults = main.FALSE |
| 910 | else: |
| 911 | # unexpected result |
| 912 | addAllResults = main.FALSE |
| 913 | if addAllResults != main.TRUE: |
| 914 | main.log.error( "Error executing set addAll" ) |
| 915 | |
| 916 | # Check if set is still correct |
| 917 | size = len( main.onosSet ) |
| 918 | getResponses = [] |
| 919 | threads = [] |
| 920 | for i in main.activeNodes: |
| 921 | t = main.Thread( target=main.CLIs[i].setTestGet, |
| 922 | name="setTestGet-" + str( i ), |
| 923 | args=[ main.onosSetName ] ) |
| 924 | threads.append( t ) |
| 925 | t.start() |
| 926 | for t in threads: |
| 927 | t.join() |
| 928 | getResponses.append( t.result ) |
| 929 | getResults = main.TRUE |
| 930 | for i in range( len( main.activeNodes ) ): |
| 931 | node = str( main.activeNodes[i] + 1 ) |
| 932 | if isinstance( getResponses[ i ], list): |
| 933 | current = set( getResponses[ i ] ) |
| 934 | if len( current ) == len( getResponses[ i ] ): |
| 935 | # no repeats |
| 936 | if main.onosSet != current: |
| 937 | main.log.error( "ONOS" + node + |
| 938 | " has incorrect view" + |
| 939 | " of set " + main.onosSetName + ":\n" + |
| 940 | str( getResponses[ i ] ) ) |
| 941 | main.log.debug( "Expected: " + str( main.onosSet ) ) |
| 942 | main.log.debug( "Actual: " + str( current ) ) |
| 943 | getResults = main.FALSE |
| 944 | else: |
| 945 | # error, set is not a set |
| 946 | main.log.error( "ONOS" + node + |
| 947 | " has repeat elements in" + |
| 948 | " set " + main.onosSetName + ":\n" + |
| 949 | str( getResponses[ i ] ) ) |
| 950 | getResults = main.FALSE |
| 951 | elif getResponses[ i ] == main.ERROR: |
| 952 | getResults = main.FALSE |
| 953 | sizeResponses = [] |
| 954 | threads = [] |
| 955 | for i in main.activeNodes: |
| 956 | t = main.Thread( target=main.CLIs[i].setTestSize, |
| 957 | name="setTestSize-" + str( i ), |
| 958 | args=[ main.onosSetName ] ) |
| 959 | threads.append( t ) |
| 960 | t.start() |
| 961 | for t in threads: |
| 962 | t.join() |
| 963 | sizeResponses.append( t.result ) |
| 964 | sizeResults = main.TRUE |
| 965 | for i in range( len( main.activeNodes ) ): |
| 966 | node = str( main.activeNodes[i] + 1 ) |
| 967 | if size != sizeResponses[ i ]: |
| 968 | sizeResults = main.FALSE |
| 969 | main.log.error( "ONOS" + node + |
| 970 | " expected a size of " + str( size ) + |
| 971 | " for set " + main.onosSetName + |
| 972 | " but got " + str( sizeResponses[ i ] ) ) |
| 973 | addAllResults = addAllResults and getResults and sizeResults |
| 974 | utilities.assert_equals( expect=main.TRUE, |
| 975 | actual=addAllResults, |
| 976 | onpass="Set addAll correct", |
| 977 | onfail="Set addAll was incorrect" ) |
| 978 | |
| 979 | main.step( "Distributed Set clear()" ) |
| 980 | main.onosSet.clear() |
| 981 | clearResponses = [] |
| 982 | threads = [] |
| 983 | for i in main.activeNodes: |
| 984 | t = main.Thread( target=main.CLIs[i].setTestRemove, |
| 985 | name="setTestClear-" + str( i ), |
| 986 | args=[ main.onosSetName, " "], # Values doesn't matter |
| 987 | kwargs={ "clear": True } ) |
| 988 | threads.append( t ) |
| 989 | t.start() |
| 990 | for t in threads: |
| 991 | t.join() |
| 992 | clearResponses.append( t.result ) |
| 993 | |
| 994 | # main.TRUE = successfully changed the set |
| 995 | # main.FALSE = action resulted in no change in set |
| 996 | # main.ERROR - Some error in executing the function |
| 997 | clearResults = main.TRUE |
| 998 | for i in range( len( main.activeNodes ) ): |
| 999 | if clearResponses[ i ] == main.TRUE: |
| 1000 | # All is well |
| 1001 | pass |
| 1002 | elif clearResponses[ i ] == main.FALSE: |
| 1003 | # Nothing set, probably fine |
| 1004 | pass |
| 1005 | elif clearResponses[ i ] == main.ERROR: |
| 1006 | # Error in execution |
| 1007 | clearResults = main.FALSE |
| 1008 | else: |
| 1009 | # unexpected result |
| 1010 | clearResults = main.FALSE |
| 1011 | if clearResults != main.TRUE: |
| 1012 | main.log.error( "Error executing set clear" ) |
| 1013 | |
| 1014 | # Check if set is still correct |
| 1015 | size = len( main.onosSet ) |
| 1016 | getResponses = [] |
| 1017 | threads = [] |
| 1018 | for i in main.activeNodes: |
| 1019 | t = main.Thread( target=main.CLIs[i].setTestGet, |
| 1020 | name="setTestGet-" + str( i ), |
| 1021 | args=[ main.onosSetName ] ) |
| 1022 | threads.append( t ) |
| 1023 | t.start() |
| 1024 | for t in threads: |
| 1025 | t.join() |
| 1026 | getResponses.append( t.result ) |
| 1027 | getResults = main.TRUE |
| 1028 | for i in range( len( main.activeNodes ) ): |
| 1029 | node = str( main.activeNodes[i] + 1 ) |
| 1030 | if isinstance( getResponses[ i ], list): |
| 1031 | current = set( getResponses[ i ] ) |
| 1032 | if len( current ) == len( getResponses[ i ] ): |
| 1033 | # no repeats |
| 1034 | if main.onosSet != current: |
| 1035 | main.log.error( "ONOS" + node + |
| 1036 | " has incorrect view" + |
| 1037 | " of set " + main.onosSetName + ":\n" + |
| 1038 | str( getResponses[ i ] ) ) |
| 1039 | main.log.debug( "Expected: " + str( main.onosSet ) ) |
| 1040 | main.log.debug( "Actual: " + str( current ) ) |
| 1041 | getResults = main.FALSE |
| 1042 | else: |
| 1043 | # error, set is not a set |
| 1044 | main.log.error( "ONOS" + node + |
| 1045 | " has repeat elements in" + |
| 1046 | " set " + main.onosSetName + ":\n" + |
| 1047 | str( getResponses[ i ] ) ) |
| 1048 | getResults = main.FALSE |
| 1049 | elif getResponses[ i ] == main.ERROR: |
| 1050 | getResults = main.FALSE |
| 1051 | sizeResponses = [] |
| 1052 | threads = [] |
| 1053 | for i in main.activeNodes: |
| 1054 | t = main.Thread( target=main.CLIs[i].setTestSize, |
| 1055 | name="setTestSize-" + str( i ), |
| 1056 | args=[ main.onosSetName ] ) |
| 1057 | threads.append( t ) |
| 1058 | t.start() |
| 1059 | for t in threads: |
| 1060 | t.join() |
| 1061 | sizeResponses.append( t.result ) |
| 1062 | sizeResults = main.TRUE |
| 1063 | for i in range( len( main.activeNodes ) ): |
| 1064 | node = str( main.activeNodes[i] + 1 ) |
| 1065 | if size != sizeResponses[ i ]: |
| 1066 | sizeResults = main.FALSE |
| 1067 | main.log.error( "ONOS" + node + |
| 1068 | " expected a size of " + str( size ) + |
| 1069 | " for set " + main.onosSetName + |
| 1070 | " but got " + str( sizeResponses[ i ] ) ) |
| 1071 | clearResults = clearResults and getResults and sizeResults |
| 1072 | utilities.assert_equals( expect=main.TRUE, |
| 1073 | actual=clearResults, |
| 1074 | onpass="Set clear correct", |
| 1075 | onfail="Set clear was incorrect" ) |
| 1076 | |
| 1077 | main.step( "Distributed Set addAll()" ) |
| 1078 | main.onosSet.update( addAllValue.split() ) |
| 1079 | addResponses = [] |
| 1080 | threads = [] |
| 1081 | for i in main.activeNodes: |
| 1082 | t = main.Thread( target=main.CLIs[i].setTestAdd, |
| 1083 | name="setTestAddAll-" + str( i ), |
| 1084 | args=[ main.onosSetName, addAllValue ] ) |
| 1085 | threads.append( t ) |
| 1086 | t.start() |
| 1087 | for t in threads: |
| 1088 | t.join() |
| 1089 | addResponses.append( t.result ) |
| 1090 | |
| 1091 | # main.TRUE = successfully changed the set |
| 1092 | # main.FALSE = action resulted in no change in set |
| 1093 | # main.ERROR - Some error in executing the function |
| 1094 | addAllResults = main.TRUE |
| 1095 | for i in range( len( main.activeNodes ) ): |
| 1096 | if addResponses[ i ] == main.TRUE: |
| 1097 | # All is well |
| 1098 | pass |
| 1099 | elif addResponses[ i ] == main.FALSE: |
| 1100 | # Already in set, probably fine |
| 1101 | pass |
| 1102 | elif addResponses[ i ] == main.ERROR: |
| 1103 | # Error in execution |
| 1104 | addAllResults = main.FALSE |
| 1105 | else: |
| 1106 | # unexpected result |
| 1107 | addAllResults = main.FALSE |
| 1108 | if addAllResults != main.TRUE: |
| 1109 | main.log.error( "Error executing set addAll" ) |
| 1110 | |
| 1111 | # Check if set is still correct |
| 1112 | size = len( main.onosSet ) |
| 1113 | getResponses = [] |
| 1114 | threads = [] |
| 1115 | for i in main.activeNodes: |
| 1116 | t = main.Thread( target=main.CLIs[i].setTestGet, |
| 1117 | name="setTestGet-" + str( i ), |
| 1118 | args=[ main.onosSetName ] ) |
| 1119 | threads.append( t ) |
| 1120 | t.start() |
| 1121 | for t in threads: |
| 1122 | t.join() |
| 1123 | getResponses.append( t.result ) |
| 1124 | getResults = main.TRUE |
| 1125 | for i in range( len( main.activeNodes ) ): |
| 1126 | node = str( main.activeNodes[i] + 1 ) |
| 1127 | if isinstance( getResponses[ i ], list): |
| 1128 | current = set( getResponses[ i ] ) |
| 1129 | if len( current ) == len( getResponses[ i ] ): |
| 1130 | # no repeats |
| 1131 | if main.onosSet != current: |
| 1132 | main.log.error( "ONOS" + node + |
| 1133 | " has incorrect view" + |
| 1134 | " of set " + main.onosSetName + ":\n" + |
| 1135 | str( getResponses[ i ] ) ) |
| 1136 | main.log.debug( "Expected: " + str( main.onosSet ) ) |
| 1137 | main.log.debug( "Actual: " + str( current ) ) |
| 1138 | getResults = main.FALSE |
| 1139 | else: |
| 1140 | # error, set is not a set |
| 1141 | main.log.error( "ONOS" + node + |
| 1142 | " has repeat elements in" + |
| 1143 | " set " + main.onosSetName + ":\n" + |
| 1144 | str( getResponses[ i ] ) ) |
| 1145 | getResults = main.FALSE |
| 1146 | elif getResponses[ i ] == main.ERROR: |
| 1147 | getResults = main.FALSE |
| 1148 | sizeResponses = [] |
| 1149 | threads = [] |
| 1150 | for i in main.activeNodes: |
| 1151 | t = main.Thread( target=main.CLIs[i].setTestSize, |
| 1152 | name="setTestSize-" + str( i ), |
| 1153 | args=[ main.onosSetName ] ) |
| 1154 | threads.append( t ) |
| 1155 | t.start() |
| 1156 | for t in threads: |
| 1157 | t.join() |
| 1158 | sizeResponses.append( t.result ) |
| 1159 | sizeResults = main.TRUE |
| 1160 | for i in range( len( main.activeNodes ) ): |
| 1161 | node = str( main.activeNodes[i] + 1 ) |
| 1162 | if size != sizeResponses[ i ]: |
| 1163 | sizeResults = main.FALSE |
| 1164 | main.log.error( "ONOS" + node + |
| 1165 | " expected a size of " + str( size ) + |
| 1166 | " for set " + main.onosSetName + |
| 1167 | " but got " + str( sizeResponses[ i ] ) ) |
| 1168 | addAllResults = addAllResults and getResults and sizeResults |
| 1169 | utilities.assert_equals( expect=main.TRUE, |
| 1170 | actual=addAllResults, |
| 1171 | onpass="Set addAll correct", |
| 1172 | onfail="Set addAll was incorrect" ) |
| 1173 | |
| 1174 | main.step( "Distributed Set retain()" ) |
| 1175 | main.onosSet.intersection_update( retainValue.split() ) |
| 1176 | retainResponses = [] |
| 1177 | threads = [] |
| 1178 | for i in main.activeNodes: |
| 1179 | t = main.Thread( target=main.CLIs[i].setTestRemove, |
| 1180 | name="setTestRetain-" + str( i ), |
| 1181 | args=[ main.onosSetName, retainValue ], |
| 1182 | kwargs={ "retain": True } ) |
| 1183 | threads.append( t ) |
| 1184 | t.start() |
| 1185 | for t in threads: |
| 1186 | t.join() |
| 1187 | retainResponses.append( t.result ) |
| 1188 | |
| 1189 | # main.TRUE = successfully changed the set |
| 1190 | # main.FALSE = action resulted in no change in set |
| 1191 | # main.ERROR - Some error in executing the function |
| 1192 | retainResults = main.TRUE |
| 1193 | for i in range( len( main.activeNodes ) ): |
| 1194 | if retainResponses[ i ] == main.TRUE: |
| 1195 | # All is well |
| 1196 | pass |
| 1197 | elif retainResponses[ i ] == main.FALSE: |
| 1198 | # Already in set, probably fine |
| 1199 | pass |
| 1200 | elif retainResponses[ i ] == main.ERROR: |
| 1201 | # Error in execution |
| 1202 | retainResults = main.FALSE |
| 1203 | else: |
| 1204 | # unexpected result |
| 1205 | retainResults = main.FALSE |
| 1206 | if retainResults != main.TRUE: |
| 1207 | main.log.error( "Error executing set retain" ) |
| 1208 | |
| 1209 | # Check if set is still correct |
| 1210 | size = len( main.onosSet ) |
| 1211 | getResponses = [] |
| 1212 | threads = [] |
| 1213 | for i in main.activeNodes: |
| 1214 | t = main.Thread( target=main.CLIs[i].setTestGet, |
| 1215 | name="setTestGet-" + str( i ), |
| 1216 | args=[ main.onosSetName ] ) |
| 1217 | threads.append( t ) |
| 1218 | t.start() |
| 1219 | for t in threads: |
| 1220 | t.join() |
| 1221 | getResponses.append( t.result ) |
| 1222 | getResults = main.TRUE |
| 1223 | for i in range( len( main.activeNodes ) ): |
| 1224 | node = str( main.activeNodes[i] + 1 ) |
| 1225 | if isinstance( getResponses[ i ], list): |
| 1226 | current = set( getResponses[ i ] ) |
| 1227 | if len( current ) == len( getResponses[ i ] ): |
| 1228 | # no repeats |
| 1229 | if main.onosSet != current: |
| 1230 | main.log.error( "ONOS" + node + |
| 1231 | " has incorrect view" + |
| 1232 | " of set " + main.onosSetName + ":\n" + |
| 1233 | str( getResponses[ i ] ) ) |
| 1234 | main.log.debug( "Expected: " + str( main.onosSet ) ) |
| 1235 | main.log.debug( "Actual: " + str( current ) ) |
| 1236 | getResults = main.FALSE |
| 1237 | else: |
| 1238 | # error, set is not a set |
| 1239 | main.log.error( "ONOS" + node + |
| 1240 | " has repeat elements in" + |
| 1241 | " set " + main.onosSetName + ":\n" + |
| 1242 | str( getResponses[ i ] ) ) |
| 1243 | getResults = main.FALSE |
| 1244 | elif getResponses[ i ] == main.ERROR: |
| 1245 | getResults = main.FALSE |
| 1246 | sizeResponses = [] |
| 1247 | threads = [] |
| 1248 | for i in main.activeNodes: |
| 1249 | t = main.Thread( target=main.CLIs[i].setTestSize, |
| 1250 | name="setTestSize-" + str( i ), |
| 1251 | args=[ main.onosSetName ] ) |
| 1252 | threads.append( t ) |
| 1253 | t.start() |
| 1254 | for t in threads: |
| 1255 | t.join() |
| 1256 | sizeResponses.append( t.result ) |
| 1257 | sizeResults = main.TRUE |
| 1258 | for i in range( len( main.activeNodes ) ): |
| 1259 | node = str( main.activeNodes[i] + 1 ) |
| 1260 | if size != sizeResponses[ i ]: |
| 1261 | sizeResults = main.FALSE |
| 1262 | main.log.error( "ONOS" + node + " expected a size of " + |
| 1263 | str( size ) + " for set " + main.onosSetName + |
| 1264 | " but got " + str( sizeResponses[ i ] ) ) |
| 1265 | retainResults = retainResults and getResults and sizeResults |
| 1266 | utilities.assert_equals( expect=main.TRUE, |
| 1267 | actual=retainResults, |
| 1268 | onpass="Set retain correct", |
| 1269 | onfail="Set retain was incorrect" ) |
| 1270 | |
| 1271 | # Transactional maps |
| 1272 | main.step( "Partitioned Transactional maps put" ) |
| 1273 | tMapValue = "Testing" |
| 1274 | numKeys = 100 |
| 1275 | putResult = True |
| 1276 | node = main.activeNodes[0] |
| 1277 | putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue ) |
| 1278 | if putResponses and len( putResponses ) == 100: |
| 1279 | for i in putResponses: |
| 1280 | if putResponses[ i ][ 'value' ] != tMapValue: |
| 1281 | putResult = False |
| 1282 | else: |
| 1283 | putResult = False |
| 1284 | if not putResult: |
| 1285 | main.log.debug( "Put response values: " + str( putResponses ) ) |
| 1286 | utilities.assert_equals( expect=True, |
| 1287 | actual=putResult, |
| 1288 | onpass="Partitioned Transactional Map put successful", |
| 1289 | onfail="Partitioned Transactional Map put values are incorrect" ) |
| 1290 | |
| 1291 | main.step( "Partitioned Transactional maps get" ) |
| 1292 | # FIXME: is this sleep needed? |
| 1293 | time.sleep( 5 ) |
| 1294 | |
| 1295 | getCheck = True |
| 1296 | for n in range( 1, numKeys + 1 ): |
| 1297 | getResponses = [] |
| 1298 | threads = [] |
| 1299 | valueCheck = True |
| 1300 | for i in main.activeNodes: |
| 1301 | t = main.Thread( target=main.CLIs[i].transactionalMapGet, |
| 1302 | name="TMap-get-" + str( i ), |
| 1303 | args=[ "Key" + str( n ) ] ) |
| 1304 | threads.append( t ) |
| 1305 | t.start() |
| 1306 | for t in threads: |
| 1307 | t.join() |
| 1308 | getResponses.append( t.result ) |
| 1309 | for node in getResponses: |
| 1310 | if node != tMapValue: |
| 1311 | valueCheck = False |
| 1312 | if not valueCheck: |
| 1313 | main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" ) |
| 1314 | main.log.warn( getResponses ) |
| 1315 | getCheck = getCheck and valueCheck |
| 1316 | utilities.assert_equals( expect=True, |
| 1317 | actual=getCheck, |
| 1318 | onpass="Partitioned Transactional Map get values were correct", |
| 1319 | onfail="Partitioned Transactional Map values incorrect" ) |
| 1320 | |
| 1321 | # DISTRIBUTED ATOMIC VALUE |
| 1322 | main.step( "Get the value of a new value" ) |
| 1323 | threads = [] |
| 1324 | getValues = [] |
| 1325 | for i in main.activeNodes: |
| 1326 | t = main.Thread( target=main.CLIs[i].valueTestGet, |
| 1327 | name="ValueGet-" + str( i ), |
| 1328 | args=[ valueName ] ) |
| 1329 | threads.append( t ) |
| 1330 | t.start() |
| 1331 | |
| 1332 | for t in threads: |
| 1333 | t.join() |
| 1334 | getValues.append( t.result ) |
| 1335 | main.log.debug( getValues ) |
| 1336 | # Check the results |
| 1337 | atomicValueGetResult = True |
| 1338 | expected = valueValue if valueValue is not None else "null" |
| 1339 | main.log.debug( "Checking for value of " + expected ) |
| 1340 | for i in getValues: |
| 1341 | if i != expected: |
| 1342 | atomicValueGetResult = False |
| 1343 | utilities.assert_equals( expect=True, |
| 1344 | actual=atomicValueGetResult, |
| 1345 | onpass="Atomic Value get successful", |
| 1346 | onfail="Error getting atomic Value " + |
| 1347 | str( valueValue ) + ", found: " + |
| 1348 | str( getValues ) ) |
| 1349 | |
| 1350 | main.step( "Atomic Value set()" ) |
| 1351 | valueValue = "foo" |
| 1352 | threads = [] |
| 1353 | setValues = [] |
| 1354 | for i in main.activeNodes: |
| 1355 | t = main.Thread( target=main.CLIs[i].valueTestSet, |
| 1356 | name="ValueSet-" + str( i ), |
| 1357 | args=[ valueName, valueValue ] ) |
| 1358 | threads.append( t ) |
| 1359 | t.start() |
| 1360 | |
| 1361 | for t in threads: |
| 1362 | t.join() |
| 1363 | setValues.append( t.result ) |
| 1364 | main.log.debug( setValues ) |
| 1365 | # Check the results |
| 1366 | atomicValueSetResults = True |
| 1367 | for i in setValues: |
| 1368 | if i != main.TRUE: |
| 1369 | atomicValueSetResults = False |
| 1370 | utilities.assert_equals( expect=True, |
| 1371 | actual=atomicValueSetResults, |
| 1372 | onpass="Atomic Value set successful", |
| 1373 | onfail="Error setting atomic Value" + |
| 1374 | str( setValues ) ) |
| 1375 | |
| 1376 | main.step( "Get the value after set()" ) |
| 1377 | threads = [] |
| 1378 | getValues = [] |
| 1379 | for i in main.activeNodes: |
| 1380 | t = main.Thread( target=main.CLIs[i].valueTestGet, |
| 1381 | name="ValueGet-" + str( i ), |
| 1382 | args=[ valueName ] ) |
| 1383 | threads.append( t ) |
| 1384 | t.start() |
| 1385 | |
| 1386 | for t in threads: |
| 1387 | t.join() |
| 1388 | getValues.append( t.result ) |
| 1389 | main.log.debug( getValues ) |
| 1390 | # Check the results |
| 1391 | atomicValueGetResult = True |
| 1392 | expected = valueValue if valueValue is not None else "null" |
| 1393 | main.log.debug( "Checking for value of " + expected ) |
| 1394 | for i in getValues: |
| 1395 | if i != expected: |
| 1396 | atomicValueGetResult = False |
| 1397 | utilities.assert_equals( expect=True, |
| 1398 | actual=atomicValueGetResult, |
| 1399 | onpass="Atomic Value get successful", |
| 1400 | onfail="Error getting atomic Value " + |
| 1401 | str( valueValue ) + ", found: " + |
| 1402 | str( getValues ) ) |
| 1403 | |
| 1404 | main.step( "Atomic Value compareAndSet()" ) |
| 1405 | oldValue = valueValue |
| 1406 | valueValue = "bar" |
| 1407 | i = main.activeNodes[0] |
| 1408 | CASValue = main.CLIs[i].valueTestCompareAndSet( valueName, oldValue, valueValue ) |
| 1409 | main.log.debug( CASValue ) |
| 1410 | utilities.assert_equals( expect=main.TRUE, |
| 1411 | actual=CASValue, |
| 1412 | onpass="Atomic Value comapreAndSet successful", |
| 1413 | onfail="Error setting atomic Value:" + |
| 1414 | str( CASValue ) ) |
| 1415 | |
| 1416 | main.step( "Get the value after compareAndSet()" ) |
| 1417 | threads = [] |
| 1418 | getValues = [] |
| 1419 | for i in main.activeNodes: |
| 1420 | t = main.Thread( target=main.CLIs[i].valueTestGet, |
| 1421 | name="ValueGet-" + str( i ), |
| 1422 | args=[ valueName ] ) |
| 1423 | threads.append( t ) |
| 1424 | t.start() |
| 1425 | |
| 1426 | for t in threads: |
| 1427 | t.join() |
| 1428 | getValues.append( t.result ) |
| 1429 | main.log.debug( getValues ) |
| 1430 | # Check the results |
| 1431 | atomicValueGetResult = True |
| 1432 | expected = valueValue if valueValue is not None else "null" |
| 1433 | main.log.debug( "Checking for value of " + expected ) |
| 1434 | for i in getValues: |
| 1435 | if i != expected: |
| 1436 | atomicValueGetResult = False |
| 1437 | utilities.assert_equals( expect=True, |
| 1438 | actual=atomicValueGetResult, |
| 1439 | onpass="Atomic Value get successful", |
| 1440 | onfail="Error getting atomic Value " + |
| 1441 | str( valueValue ) + ", found: " + |
| 1442 | str( getValues ) ) |
| 1443 | |
| 1444 | main.step( "Atomic Value getAndSet()" ) |
| 1445 | oldValue = valueValue |
| 1446 | valueValue = "baz" |
| 1447 | i = main.activeNodes[0] |
| 1448 | GASValue = main.CLIs[i].valueTestGetAndSet( valueName, valueValue ) |
| 1449 | main.log.debug( GASValue ) |
| 1450 | expected = oldValue if oldValue is not None else "null" |
| 1451 | utilities.assert_equals( expect=expected, |
| 1452 | actual=GASValue, |
| 1453 | onpass="Atomic Value GAS successful", |
| 1454 | onfail="Error with GetAndSet atomic Value: expected " + |
| 1455 | str( expected ) + ", found: " + |
| 1456 | str( GASValue ) ) |
| 1457 | |
| 1458 | main.step( "Get the value after getAndSet()" ) |
| 1459 | threads = [] |
| 1460 | getValues = [] |
| 1461 | for i in main.activeNodes: |
| 1462 | t = main.Thread( target=main.CLIs[i].valueTestGet, |
| 1463 | name="ValueGet-" + str( i ), |
| 1464 | args=[ valueName ] ) |
| 1465 | threads.append( t ) |
| 1466 | t.start() |
| 1467 | |
| 1468 | for t in threads: |
| 1469 | t.join() |
| 1470 | getValues.append( t.result ) |
| 1471 | main.log.debug( getValues ) |
| 1472 | # Check the results |
| 1473 | atomicValueGetResult = True |
| 1474 | expected = valueValue if valueValue is not None else "null" |
| 1475 | main.log.debug( "Checking for value of " + expected ) |
| 1476 | for i in getValues: |
| 1477 | if i != expected: |
| 1478 | atomicValueGetResult = False |
| 1479 | utilities.assert_equals( expect=True, |
| 1480 | actual=atomicValueGetResult, |
| 1481 | onpass="Atomic Value get successful", |
| 1482 | onfail="Error getting atomic Value: expected " + |
| 1483 | str( valueValue ) + ", found: " + |
| 1484 | str( getValues ) ) |
| 1485 | |
| 1486 | main.step( "Atomic Value destory()" ) |
| 1487 | valueValue = None |
| 1488 | threads = [] |
| 1489 | i = main.activeNodes[0] |
| 1490 | destroyResult = main.CLIs[i].valueTestDestroy( valueName ) |
| 1491 | main.log.debug( destroyResult ) |
| 1492 | # Check the results |
| 1493 | utilities.assert_equals( expect=main.TRUE, |
| 1494 | actual=destroyResult, |
| 1495 | onpass="Atomic Value destroy successful", |
| 1496 | onfail="Error destroying atomic Value" ) |
| 1497 | |
| 1498 | main.step( "Get the value after destroy()" ) |
| 1499 | threads = [] |
| 1500 | getValues = [] |
| 1501 | for i in main.activeNodes: |
| 1502 | t = main.Thread( target=main.CLIs[i].valueTestGet, |
| 1503 | name="ValueGet-" + str( i ), |
| 1504 | args=[ valueName ] ) |
| 1505 | threads.append( t ) |
| 1506 | t.start() |
| 1507 | |
| 1508 | for t in threads: |
| 1509 | t.join() |
| 1510 | getValues.append( t.result ) |
| 1511 | main.log.debug( getValues ) |
| 1512 | # Check the results |
| 1513 | atomicValueGetResult = True |
| 1514 | expected = valueValue if valueValue is not None else "null" |
| 1515 | main.log.debug( "Checking for value of " + expected ) |
| 1516 | for i in getValues: |
| 1517 | if i != expected: |
| 1518 | atomicValueGetResult = False |
| 1519 | utilities.assert_equals( expect=True, |
| 1520 | actual=atomicValueGetResult, |
| 1521 | onpass="Atomic Value get successful", |
| 1522 | onfail="Error getting atomic Value " + |
| 1523 | str( valueValue ) + ", found: " + |
| 1524 | str( getValues ) ) |
| 1525 | except Exception as e: |
| 1526 | main.log.error( "Exception: " + str( e ) ) |