diff --git a/TestON/tests/HA/HAclusterRestart/HAclusterRestart.py b/TestON/tests/HA/HAclusterRestart/HAclusterRestart.py
index 1112aa8..134ac76 100644
--- a/TestON/tests/HA/HAclusterRestart/HAclusterRestart.py
+++ b/TestON/tests/HA/HAclusterRestart/HAclusterRestart.py
@@ -3053,7 +3053,7 @@
         # verify leader didn't just change
         # Get new leaders and candidates
         reRunLeaders = []
-        time.sleep( 5 ) # Paremterize
+        time.sleep( 5 )  # Paremterize
         positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
 
         # Check that the re-elected node is last on the candidate List
@@ -3082,14 +3082,10 @@
         assert main.nodes, "main.nodes not defined"
 
         # Variables for the distributed primitives tests
-        global pCounterName
-        global pCounterValue
-        global onosSet
-        global onosSetName
-        pCounterName = "TestON-Partitions"
-        pCounterValue = 0
-        onosSet = set([])
-        onosSetName = "TestON-set"
+        main.pCounterName = "TestON-Partitions"
+        main.pCounterValue = 0
+        main.onosSet = set([])
+        main.onosSetName = "TestON-set"
 
         description = "Install Primitives app"
         main.case( description )
@@ -3107,1153 +3103,4 @@
         """
         Check for basic functionality with distributed primitives
         """
-        # Make sure variables are defined/set
-        assert main.numCtrls, "main.numCtrls not defined"
-        assert main, "main not defined"
-        assert utilities.assert_equals, "utilities.assert_equals not defined"
-        assert main.CLIs, "main.CLIs not defined"
-        assert main.nodes, "main.nodes not defined"
-        assert pCounterName, "pCounterName not defined"
-        assert onosSetName, "onosSetName not defined"
-        # NOTE: assert fails if value is 0/None/Empty/False
-        try:
-            pCounterValue
-        except NameError:
-            main.log.error( "pCounterValue not defined, setting to 0" )
-            pCounterValue = 0
-        try:
-            onosSet
-        except NameError:
-            main.log.error( "onosSet not defined, setting to empty Set" )
-            onosSet = set([])
-        # Variables for the distributed primitives tests. These are local only
-        addValue = "a"
-        addAllValue = "a b c d e f"
-        retainValue = "c d e f"
-
-        description = "Check for basic functionality with distributed " +\
-                      "primitives"
-        main.case( description )
-        main.caseExplanation = "Test the methods of the distributed " +\
-                                "primitives (counters and sets) throught the cli"
-        # DISTRIBUTED ATOMIC COUNTERS
-        # Partitioned counters
-        main.step( "Increment then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterAddAndGet-" + str( i ),
-                             args=[ pCounterName ] )
-            pCounterValue += 1
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then Increment a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterGetAndAdd-" + str( i ),
-                             args=[ pCounterName ] )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 1
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        main.step( "Add -8 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": -8 } )
-            pCounterValue += -8
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Add 5 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            pCounterValue += 5
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then add 5 to a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 5
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        # DISTRIBUTED SETS
-        main.step( "Distributed Set get" )
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=getResults,
-                                 onpass="Set elements are correct",
-                                 onfail="Set elements are incorrect" )
-
-        main.step( "Distributed Set size" )
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=sizeResults,
-                                 onpass="Set sizes are correct",
-                                 onfail="Set sizes are incorrect" )
-
-        main.step( "Distributed Set add()" )
-        onosSet.add( addValue )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAdd-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addResults = main.FALSE
-            else:
-                # unexpected result
-                addResults = main.FALSE
-        if addResults != main.TRUE:
-            main.log.error( "Error executing set add" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node + " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node + " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addResults = addResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addResults,
-                                 onpass="Set add correct",
-                                 onfail="Set add was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set contains()" )
-        containsResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContains-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsResponses.append( t.result )
-
-        containsResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsResults,
-                                 onpass="Set contains is functional",
-                                 onfail="Set contains failed" )
-
-        main.step( "Distributed Set containsAll()" )
-        containsAllResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContainsAll-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addAllValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsAllResponses.append( t.result )
-
-        containsAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsAllResults,
-                                 onpass="Set containsAll is functional",
-                                 onfail="Set containsAll failed" )
-
-        main.step( "Distributed Set remove()" )
-        onosSet.remove( addValue )
-        removeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRemove-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            removeResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeResults = main.FALSE
-            else:
-                # unexpected result
-                removeResults = main.FALSE
-        if removeResults != main.TRUE:
-            main.log.error( "Error executing set remove" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeResults = removeResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeResults,
-                                 onpass="Set remove correct",
-                                 onfail="Set remove was incorrect" )
-
-        main.step( "Distributed Set removeAll()" )
-        onosSet.difference_update( addAllValue.split() )
-        removeAllResponses = []
-        threads = []
-        try:
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].setTestRemove,
-                                 name="setTestRemoveAll-" + str( i ),
-                                 args=[ onosSetName, addAllValue ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                removeAllResponses.append( t.result )
-        except Exception, e:
-            main.log.exception(e)
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeAllResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeAllResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeAllResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeAllResults = main.FALSE
-            else:
-                # unexpected result
-                removeAllResults = main.FALSE
-        if removeAllResults != main.TRUE:
-            main.log.error( "Error executing set removeAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeAllResults = removeAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeAllResults,
-                                 onpass="Set removeAll correct",
-                                 onfail="Set removeAll was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set clear()" )
-        onosSet.clear()
-        clearResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestClear-" + str( i ),
-                             args=[ onosSetName, " "],  # Values doesn't matter
-                             kwargs={ "clear": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            clearResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        clearResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if clearResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif clearResponses[ i ] == main.FALSE:
-                # Nothing set, probably fine
-                pass
-            elif clearResponses[ i ] == main.ERROR:
-                # Error in execution
-                clearResults = main.FALSE
-            else:
-                # unexpected result
-                clearResults = main.FALSE
-        if clearResults != main.TRUE:
-            main.log.error( "Error executing set clear" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        clearResults = clearResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=clearResults,
-                                 onpass="Set clear correct",
-                                 onfail="Set clear was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set retain()" )
-        onosSet.intersection_update( retainValue.split() )
-        retainResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRetain-" + str( i ),
-                             args=[ onosSetName, retainValue ],
-                             kwargs={ "retain": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            retainResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        retainResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if retainResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif retainResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif retainResponses[ i ] == main.ERROR:
-                # Error in execution
-                retainResults = main.FALSE
-            else:
-                # unexpected result
-                retainResults = main.FALSE
-        if retainResults != main.TRUE:
-            main.log.error( "Error executing set retain" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node + " expected a size of " +
-                                str( size ) + " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        retainResults = retainResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=retainResults,
-                                 onpass="Set retain correct",
-                                 onfail="Set retain was incorrect" )
-
-        # Transactional maps
-        main.step( "Partitioned Transactional maps put" )
-        tMapValue = "Testing"
-        numKeys = 100
-        putResult = True
-        node = main.activeNodes[0]
-        putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue )
-        if putResponses and len( putResponses ) == 100:
-            for i in putResponses:
-                if putResponses[ i ][ 'value' ] != tMapValue:
-                    putResult = False
-        else:
-            putResult = False
-        if not putResult:
-            main.log.debug( "Put response values: " + str( putResponses ) )
-        utilities.assert_equals( expect=True,
-                                 actual=putResult,
-                                 onpass="Partitioned Transactional Map put successful",
-                                 onfail="Partitioned Transactional Map put values are incorrect" )
-
-        main.step( "Partitioned Transactional maps get" )
-        # FIXME: is this sleep needed?
-        time.sleep( 5 )
-
-        getCheck = True
-        for n in range( 1, numKeys + 1 ):
-            getResponses = []
-            threads = []
-            valueCheck = True
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].transactionalMapGet,
-                                 name="TMap-get-" + str( i ),
-                                 args=[ "Key" + str( n ) ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                getResponses.append( t.result )
-            for node in getResponses:
-                if node != tMapValue:
-                    valueCheck = False
-            if not valueCheck:
-                main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
-                main.log.warn( getResponses )
-            getCheck = getCheck and valueCheck
-        utilities.assert_equals( expect=True,
-                                 actual=getCheck,
-                                 onpass="Partitioned Transactional Map get values were correct",
-                                 onfail="Partitioned Transactional Map values incorrect" )
+        main.HA.CASE17( main )
diff --git a/TestON/tests/HA/HAfullNetPartition/HAfullNetPartition.py b/TestON/tests/HA/HAfullNetPartition/HAfullNetPartition.py
index f7aec3b..742e340 100644
--- a/TestON/tests/HA/HAfullNetPartition/HAfullNetPartition.py
+++ b/TestON/tests/HA/HAfullNetPartition/HAfullNetPartition.py
@@ -3060,7 +3060,7 @@
         # verify leader didn't just change
         # Get new leaders and candidates
         reRunLeaders = []
-        time.sleep( 5 ) # Paremterize
+        time.sleep( 5 )  # Paremterize
         positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
 
         # Check that the re-elected node is last on the candidate List
@@ -3089,14 +3089,10 @@
         assert main.nodes, "main.nodes not defined"
 
         # Variables for the distributed primitives tests
-        global pCounterName
-        global pCounterValue
-        global onosSet
-        global onosSetName
-        pCounterName = "TestON-Partitions"
-        pCounterValue = 0
-        onosSet = set([])
-        onosSetName = "TestON-set"
+        main.pCounterName = "TestON-Partitions"
+        main.pCounterValue = 0
+        main.onosSet = set([])
+        main.onosSetName = "TestON-set"
 
         description = "Install Primitives app"
         main.case( description )
@@ -3114,1153 +3110,4 @@
         """
         Check for basic functionality with distributed primitives
         """
-        # Make sure variables are defined/set
-        assert main.numCtrls, "main.numCtrls not defined"
-        assert main, "main not defined"
-        assert utilities.assert_equals, "utilities.assert_equals not defined"
-        assert main.CLIs, "main.CLIs not defined"
-        assert main.nodes, "main.nodes not defined"
-        assert pCounterName, "pCounterName not defined"
-        assert onosSetName, "onosSetName not defined"
-        # NOTE: assert fails if value is 0/None/Empty/False
-        try:
-            pCounterValue
-        except NameError:
-            main.log.error( "pCounterValue not defined, setting to 0" )
-            pCounterValue = 0
-        try:
-            onosSet
-        except NameError:
-            main.log.error( "onosSet not defined, setting to empty Set" )
-            onosSet = set([])
-        # Variables for the distributed primitives tests. These are local only
-        addValue = "a"
-        addAllValue = "a b c d e f"
-        retainValue = "c d e f"
-
-        description = "Check for basic functionality with distributed " +\
-                      "primitives"
-        main.case( description )
-        main.caseExplanation = "Test the methods of the distributed " +\
-                                "primitives (counters and sets) throught the cli"
-        # DISTRIBUTED ATOMIC COUNTERS
-        # Partitioned counters
-        main.step( "Increment then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterAddAndGet-" + str( i ),
-                             args=[ pCounterName ] )
-            pCounterValue += 1
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then Increment a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterGetAndAdd-" + str( i ),
-                             args=[ pCounterName ] )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 1
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        main.step( "Add -8 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": -8 } )
-            pCounterValue += -8
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Add 5 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            pCounterValue += 5
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then add 5 to a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 5
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        # DISTRIBUTED SETS
-        main.step( "Distributed Set get" )
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=getResults,
-                                 onpass="Set elements are correct",
-                                 onfail="Set elements are incorrect" )
-
-        main.step( "Distributed Set size" )
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=sizeResults,
-                                 onpass="Set sizes are correct",
-                                 onfail="Set sizes are incorrect" )
-
-        main.step( "Distributed Set add()" )
-        onosSet.add( addValue )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAdd-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addResults = main.FALSE
-            else:
-                # unexpected result
-                addResults = main.FALSE
-        if addResults != main.TRUE:
-            main.log.error( "Error executing set add" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node + " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node + " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addResults = addResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addResults,
-                                 onpass="Set add correct",
-                                 onfail="Set add was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set contains()" )
-        containsResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContains-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsResponses.append( t.result )
-
-        containsResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsResults,
-                                 onpass="Set contains is functional",
-                                 onfail="Set contains failed" )
-
-        main.step( "Distributed Set containsAll()" )
-        containsAllResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContainsAll-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addAllValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsAllResponses.append( t.result )
-
-        containsAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsAllResults,
-                                 onpass="Set containsAll is functional",
-                                 onfail="Set containsAll failed" )
-
-        main.step( "Distributed Set remove()" )
-        onosSet.remove( addValue )
-        removeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRemove-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            removeResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeResults = main.FALSE
-            else:
-                # unexpected result
-                removeResults = main.FALSE
-        if removeResults != main.TRUE:
-            main.log.error( "Error executing set remove" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeResults = removeResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeResults,
-                                 onpass="Set remove correct",
-                                 onfail="Set remove was incorrect" )
-
-        main.step( "Distributed Set removeAll()" )
-        onosSet.difference_update( addAllValue.split() )
-        removeAllResponses = []
-        threads = []
-        try:
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].setTestRemove,
-                                 name="setTestRemoveAll-" + str( i ),
-                                 args=[ onosSetName, addAllValue ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                removeAllResponses.append( t.result )
-        except Exception, e:
-            main.log.exception(e)
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeAllResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeAllResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeAllResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeAllResults = main.FALSE
-            else:
-                # unexpected result
-                removeAllResults = main.FALSE
-        if removeAllResults != main.TRUE:
-            main.log.error( "Error executing set removeAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeAllResults = removeAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeAllResults,
-                                 onpass="Set removeAll correct",
-                                 onfail="Set removeAll was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set clear()" )
-        onosSet.clear()
-        clearResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestClear-" + str( i ),
-                             args=[ onosSetName, " "],  # Values doesn't matter
-                             kwargs={ "clear": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            clearResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        clearResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if clearResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif clearResponses[ i ] == main.FALSE:
-                # Nothing set, probably fine
-                pass
-            elif clearResponses[ i ] == main.ERROR:
-                # Error in execution
-                clearResults = main.FALSE
-            else:
-                # unexpected result
-                clearResults = main.FALSE
-        if clearResults != main.TRUE:
-            main.log.error( "Error executing set clear" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        clearResults = clearResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=clearResults,
-                                 onpass="Set clear correct",
-                                 onfail="Set clear was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set retain()" )
-        onosSet.intersection_update( retainValue.split() )
-        retainResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRetain-" + str( i ),
-                             args=[ onosSetName, retainValue ],
-                             kwargs={ "retain": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            retainResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        retainResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if retainResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif retainResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif retainResponses[ i ] == main.ERROR:
-                # Error in execution
-                retainResults = main.FALSE
-            else:
-                # unexpected result
-                retainResults = main.FALSE
-        if retainResults != main.TRUE:
-            main.log.error( "Error executing set retain" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node + " expected a size of " +
-                                str( size ) + " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        retainResults = retainResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=retainResults,
-                                 onpass="Set retain correct",
-                                 onfail="Set retain was incorrect" )
-
-        # Transactional maps
-        main.step( "Partitioned Transactional maps put" )
-        tMapValue = "Testing"
-        numKeys = 100
-        putResult = True
-        node = main.activeNodes[0]
-        putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue )
-        if putResponses and len( putResponses ) == 100:
-            for i in putResponses:
-                if putResponses[ i ][ 'value' ] != tMapValue:
-                    putResult = False
-        else:
-            putResult = False
-        if not putResult:
-            main.log.debug( "Put response values: " + str( putResponses ) )
-        utilities.assert_equals( expect=True,
-                                 actual=putResult,
-                                 onpass="Partitioned Transactional Map put successful",
-                                 onfail="Partitioned Transactional Map put values are incorrect" )
-
-        main.step( "Partitioned Transactional maps get" )
-        # FIXME: is this sleep needed?
-        time.sleep( 5 )
-
-        getCheck = True
-        for n in range( 1, numKeys + 1 ):
-            getResponses = []
-            threads = []
-            valueCheck = True
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].transactionalMapGet,
-                                 name="TMap-get-" + str( i ),
-                                 args=[ "Key" + str( n ) ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                getResponses.append( t.result )
-            for node in getResponses:
-                if node != tMapValue:
-                    valueCheck = False
-            if not valueCheck:
-                main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
-                main.log.warn( getResponses )
-            getCheck = getCheck and valueCheck
-        utilities.assert_equals( expect=True,
-                                 actual=getCheck,
-                                 onpass="Partitioned Transactional Map get values were correct",
-                                 onfail="Partitioned Transactional Map values incorrect" )
+        main.HA.CASE17( main )
diff --git a/TestON/tests/HA/HAkillNodes/HAkillNodes.py b/TestON/tests/HA/HAkillNodes/HAkillNodes.py
index 336f0f1..560cb71 100644
--- a/TestON/tests/HA/HAkillNodes/HAkillNodes.py
+++ b/TestON/tests/HA/HAkillNodes/HAkillNodes.py
@@ -3116,7 +3116,7 @@
         # verify leader didn't just change
         # Get new leaders and candidates
         reRunLeaders = []
-        time.sleep( 5 ) # Paremterize
+        time.sleep( 5 )  # Paremterize
         positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
 
         # Check that the re-elected node is last on the candidate List
@@ -3145,14 +3145,10 @@
         assert main.nodes, "main.nodes not defined"
 
         # Variables for the distributed primitives tests
-        global pCounterName
-        global pCounterValue
-        global onosSet
-        global onosSetName
-        pCounterName = "TestON-Partitions"
-        pCounterValue = 0
-        onosSet = set([])
-        onosSetName = "TestON-set"
+        main.pCounterName = "TestON-Partitions"
+        main.pCounterValue = 0
+        main.onosSet = set([])
+        main.onosSetName = "TestON-set"
 
         description = "Install Primitives app"
         main.case( description )
@@ -3170,1153 +3166,4 @@
         """
         Check for basic functionality with distributed primitives
         """
-        # Make sure variables are defined/set
-        assert main.numCtrls, "main.numCtrls not defined"
-        assert main, "main not defined"
-        assert utilities.assert_equals, "utilities.assert_equals not defined"
-        assert main.CLIs, "main.CLIs not defined"
-        assert main.nodes, "main.nodes not defined"
-        assert pCounterName, "pCounterName not defined"
-        assert onosSetName, "onosSetName not defined"
-        # NOTE: assert fails if value is 0/None/Empty/False
-        try:
-            pCounterValue
-        except NameError:
-            main.log.error( "pCounterValue not defined, setting to 0" )
-            pCounterValue = 0
-        try:
-            onosSet
-        except NameError:
-            main.log.error( "onosSet not defined, setting to empty Set" )
-            onosSet = set([])
-        # Variables for the distributed primitives tests. These are local only
-        addValue = "a"
-        addAllValue = "a b c d e f"
-        retainValue = "c d e f"
-
-        description = "Check for basic functionality with distributed " +\
-                      "primitives"
-        main.case( description )
-        main.caseExplanation = "Test the methods of the distributed " +\
-                                "primitives (counters and sets) throught the cli"
-        # DISTRIBUTED ATOMIC COUNTERS
-        # Partitioned counters
-        main.step( "Increment then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterAddAndGet-" + str( i ),
-                             args=[ pCounterName ] )
-            pCounterValue += 1
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then Increment a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterGetAndAdd-" + str( i ),
-                             args=[ pCounterName ] )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 1
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        main.step( "Add -8 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": -8 } )
-            pCounterValue += -8
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Add 5 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            pCounterValue += 5
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then add 5 to a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 5
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        # DISTRIBUTED SETS
-        main.step( "Distributed Set get" )
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=getResults,
-                                 onpass="Set elements are correct",
-                                 onfail="Set elements are incorrect" )
-
-        main.step( "Distributed Set size" )
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=sizeResults,
-                                 onpass="Set sizes are correct",
-                                 onfail="Set sizes are incorrect" )
-
-        main.step( "Distributed Set add()" )
-        onosSet.add( addValue )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAdd-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addResults = main.FALSE
-            else:
-                # unexpected result
-                addResults = main.FALSE
-        if addResults != main.TRUE:
-            main.log.error( "Error executing set add" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node + " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node + " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addResults = addResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addResults,
-                                 onpass="Set add correct",
-                                 onfail="Set add was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set contains()" )
-        containsResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContains-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsResponses.append( t.result )
-
-        containsResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsResults,
-                                 onpass="Set contains is functional",
-                                 onfail="Set contains failed" )
-
-        main.step( "Distributed Set containsAll()" )
-        containsAllResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContainsAll-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addAllValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsAllResponses.append( t.result )
-
-        containsAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsAllResults,
-                                 onpass="Set containsAll is functional",
-                                 onfail="Set containsAll failed" )
-
-        main.step( "Distributed Set remove()" )
-        onosSet.remove( addValue )
-        removeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRemove-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            removeResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeResults = main.FALSE
-            else:
-                # unexpected result
-                removeResults = main.FALSE
-        if removeResults != main.TRUE:
-            main.log.error( "Error executing set remove" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeResults = removeResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeResults,
-                                 onpass="Set remove correct",
-                                 onfail="Set remove was incorrect" )
-
-        main.step( "Distributed Set removeAll()" )
-        onosSet.difference_update( addAllValue.split() )
-        removeAllResponses = []
-        threads = []
-        try:
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].setTestRemove,
-                                 name="setTestRemoveAll-" + str( i ),
-                                 args=[ onosSetName, addAllValue ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                removeAllResponses.append( t.result )
-        except Exception, e:
-            main.log.exception(e)
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeAllResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeAllResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeAllResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeAllResults = main.FALSE
-            else:
-                # unexpected result
-                removeAllResults = main.FALSE
-        if removeAllResults != main.TRUE:
-            main.log.error( "Error executing set removeAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeAllResults = removeAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeAllResults,
-                                 onpass="Set removeAll correct",
-                                 onfail="Set removeAll was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set clear()" )
-        onosSet.clear()
-        clearResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestClear-" + str( i ),
-                             args=[ onosSetName, " "],  # Values doesn't matter
-                             kwargs={ "clear": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            clearResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        clearResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if clearResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif clearResponses[ i ] == main.FALSE:
-                # Nothing set, probably fine
-                pass
-            elif clearResponses[ i ] == main.ERROR:
-                # Error in execution
-                clearResults = main.FALSE
-            else:
-                # unexpected result
-                clearResults = main.FALSE
-        if clearResults != main.TRUE:
-            main.log.error( "Error executing set clear" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        clearResults = clearResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=clearResults,
-                                 onpass="Set clear correct",
-                                 onfail="Set clear was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set retain()" )
-        onosSet.intersection_update( retainValue.split() )
-        retainResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRetain-" + str( i ),
-                             args=[ onosSetName, retainValue ],
-                             kwargs={ "retain": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            retainResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        retainResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if retainResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif retainResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif retainResponses[ i ] == main.ERROR:
-                # Error in execution
-                retainResults = main.FALSE
-            else:
-                # unexpected result
-                retainResults = main.FALSE
-        if retainResults != main.TRUE:
-            main.log.error( "Error executing set retain" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node + " expected a size of " +
-                                str( size ) + " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        retainResults = retainResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=retainResults,
-                                 onpass="Set retain correct",
-                                 onfail="Set retain was incorrect" )
-
-        # Transactional maps
-        main.step( "Partitioned Transactional maps put" )
-        tMapValue = "Testing"
-        numKeys = 100
-        putResult = True
-        node = main.activeNodes[0]
-        putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue )
-        if putResponses and len( putResponses ) == 100:
-            for i in putResponses:
-                if putResponses[ i ][ 'value' ] != tMapValue:
-                    putResult = False
-        else:
-            putResult = False
-        if not putResult:
-            main.log.debug( "Put response values: " + str( putResponses ) )
-        utilities.assert_equals( expect=True,
-                                 actual=putResult,
-                                 onpass="Partitioned Transactional Map put successful",
-                                 onfail="Partitioned Transactional Map put values are incorrect" )
-
-        main.step( "Partitioned Transactional maps get" )
-        # FIXME: is this sleep needed?
-        time.sleep( 5 )
-
-        getCheck = True
-        for n in range( 1, numKeys + 1 ):
-            getResponses = []
-            threads = []
-            valueCheck = True
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].transactionalMapGet,
-                                 name="TMap-get-" + str( i ),
-                                 args=[ "Key" + str( n ) ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                getResponses.append( t.result )
-            for node in getResponses:
-                if node != tMapValue:
-                    valueCheck = False
-            if not valueCheck:
-                main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
-                main.log.warn( getResponses )
-            getCheck = getCheck and valueCheck
-        utilities.assert_equals( expect=True,
-                                 actual=getCheck,
-                                 onpass="Partitioned Transactional Map get values were correct",
-                                 onfail="Partitioned Transactional Map values incorrect" )
+        main.HA.CASE17( main )
diff --git a/TestON/tests/HA/HAsanity/HAsanity.py b/TestON/tests/HA/HAsanity/HAsanity.py
index 32b7e14..2b2ea08 100644
--- a/TestON/tests/HA/HAsanity/HAsanity.py
+++ b/TestON/tests/HA/HAsanity/HAsanity.py
@@ -2976,7 +2976,7 @@
         # verify leader didn't just change
         # Get new leaders and candidates
         reRunLeaders = []
-        time.sleep( 5 ) # Paremterize
+        time.sleep( 5 )  # Paremterize
         positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
 
         # Check that the re-elected node is last on the candidate List
@@ -3005,14 +3005,10 @@
         assert main.nodes, "main.nodes not defined"
 
         # Variables for the distributed primitives tests
-        global pCounterName
-        global pCounterValue
-        global onosSet
-        global onosSetName
-        pCounterName = "TestON-Partitions"
-        pCounterValue = 0
-        onosSet = set([])
-        onosSetName = "TestON-set"
+        main.pCounterName = "TestON-Partitions"
+        main.pCounterValue = 0
+        main.onosSet = set([])
+        main.onosSetName = "TestON-set"
 
         description = "Install Primitives app"
         main.case( description )
@@ -3030,1153 +3026,4 @@
         """
         Check for basic functionality with distributed primitives
         """
-        # Make sure variables are defined/set
-        assert main.numCtrls, "main.numCtrls not defined"
-        assert main, "main not defined"
-        assert utilities.assert_equals, "utilities.assert_equals not defined"
-        assert main.CLIs, "main.CLIs not defined"
-        assert main.nodes, "main.nodes not defined"
-        assert pCounterName, "pCounterName not defined"
-        assert onosSetName, "onosSetName not defined"
-        # NOTE: assert fails if value is 0/None/Empty/False
-        try:
-            pCounterValue
-        except NameError:
-            main.log.error( "pCounterValue not defined, setting to 0" )
-            pCounterValue = 0
-        try:
-            onosSet
-        except NameError:
-            main.log.error( "onosSet not defined, setting to empty Set" )
-            onosSet = set([])
-        # Variables for the distributed primitives tests. These are local only
-        addValue = "a"
-        addAllValue = "a b c d e f"
-        retainValue = "c d e f"
-
-        description = "Check for basic functionality with distributed " +\
-                      "primitives"
-        main.case( description )
-        main.caseExplanation = "Test the methods of the distributed " +\
-                                "primitives (counters and sets) throught the cli"
-        # DISTRIBUTED ATOMIC COUNTERS
-        # Partitioned counters
-        main.step( "Increment then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterAddAndGet-" + str( i ),
-                             args=[ pCounterName ] )
-            pCounterValue += 1
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then Increment a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterGetAndAdd-" + str( i ),
-                             args=[ pCounterName ] )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 1
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        main.step( "Add -8 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": -8 } )
-            pCounterValue += -8
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Add 5 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            pCounterValue += 5
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then add 5 to a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 5
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        # DISTRIBUTED SETS
-        main.step( "Distributed Set get" )
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=getResults,
-                                 onpass="Set elements are correct",
-                                 onfail="Set elements are incorrect" )
-
-        main.step( "Distributed Set size" )
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=sizeResults,
-                                 onpass="Set sizes are correct",
-                                 onfail="Set sizes are incorrect" )
-
-        main.step( "Distributed Set add()" )
-        onosSet.add( addValue )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAdd-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addResults = main.FALSE
-            else:
-                # unexpected result
-                addResults = main.FALSE
-        if addResults != main.TRUE:
-            main.log.error( "Error executing set add" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node + " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node + " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addResults = addResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addResults,
-                                 onpass="Set add correct",
-                                 onfail="Set add was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set contains()" )
-        containsResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContains-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsResponses.append( t.result )
-
-        containsResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsResults,
-                                 onpass="Set contains is functional",
-                                 onfail="Set contains failed" )
-
-        main.step( "Distributed Set containsAll()" )
-        containsAllResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContainsAll-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addAllValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsAllResponses.append( t.result )
-
-        containsAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsAllResults,
-                                 onpass="Set containsAll is functional",
-                                 onfail="Set containsAll failed" )
-
-        main.step( "Distributed Set remove()" )
-        onosSet.remove( addValue )
-        removeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRemove-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            removeResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeResults = main.FALSE
-            else:
-                # unexpected result
-                removeResults = main.FALSE
-        if removeResults != main.TRUE:
-            main.log.error( "Error executing set remove" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeResults = removeResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeResults,
-                                 onpass="Set remove correct",
-                                 onfail="Set remove was incorrect" )
-
-        main.step( "Distributed Set removeAll()" )
-        onosSet.difference_update( addAllValue.split() )
-        removeAllResponses = []
-        threads = []
-        try:
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].setTestRemove,
-                                 name="setTestRemoveAll-" + str( i ),
-                                 args=[ onosSetName, addAllValue ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                removeAllResponses.append( t.result )
-        except Exception, e:
-            main.log.exception(e)
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeAllResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeAllResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeAllResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeAllResults = main.FALSE
-            else:
-                # unexpected result
-                removeAllResults = main.FALSE
-        if removeAllResults != main.TRUE:
-            main.log.error( "Error executing set removeAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeAllResults = removeAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeAllResults,
-                                 onpass="Set removeAll correct",
-                                 onfail="Set removeAll was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set clear()" )
-        onosSet.clear()
-        clearResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestClear-" + str( i ),
-                             args=[ onosSetName, " "],  # Values doesn't matter
-                             kwargs={ "clear": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            clearResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        clearResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if clearResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif clearResponses[ i ] == main.FALSE:
-                # Nothing set, probably fine
-                pass
-            elif clearResponses[ i ] == main.ERROR:
-                # Error in execution
-                clearResults = main.FALSE
-            else:
-                # unexpected result
-                clearResults = main.FALSE
-        if clearResults != main.TRUE:
-            main.log.error( "Error executing set clear" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        clearResults = clearResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=clearResults,
-                                 onpass="Set clear correct",
-                                 onfail="Set clear was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set retain()" )
-        onosSet.intersection_update( retainValue.split() )
-        retainResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRetain-" + str( i ),
-                             args=[ onosSetName, retainValue ],
-                             kwargs={ "retain": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            retainResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        retainResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if retainResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif retainResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif retainResponses[ i ] == main.ERROR:
-                # Error in execution
-                retainResults = main.FALSE
-            else:
-                # unexpected result
-                retainResults = main.FALSE
-        if retainResults != main.TRUE:
-            main.log.error( "Error executing set retain" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node + " expected a size of " +
-                                str( size ) + " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        retainResults = retainResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=retainResults,
-                                 onpass="Set retain correct",
-                                 onfail="Set retain was incorrect" )
-
-        # Transactional maps
-        main.step( "Partitioned Transactional maps put" )
-        tMapValue = "Testing"
-        numKeys = 100
-        putResult = True
-        node = main.activeNodes[0]
-        putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue )
-        if putResponses and len( putResponses ) == 100:
-            for i in putResponses:
-                if putResponses[ i ][ 'value' ] != tMapValue:
-                    putResult = False
-        else:
-            putResult = False
-        if not putResult:
-            main.log.debug( "Put response values: " + str( putResponses ) )
-        utilities.assert_equals( expect=True,
-                                 actual=putResult,
-                                 onpass="Partitioned Transactional Map put successful",
-                                 onfail="Partitioned Transactional Map put values are incorrect" )
-
-        main.step( "Partitioned Transactional maps get" )
-        # FIXME: is this sleep needed?
-        time.sleep( 5 )
-
-        getCheck = True
-        for n in range( 1, numKeys + 1 ):
-            getResponses = []
-            threads = []
-            valueCheck = True
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].transactionalMapGet,
-                                 name="TMap-get-" + str( i ),
-                                 args=[ "Key" + str( n ) ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                getResponses.append( t.result )
-            for node in getResponses:
-                if node != tMapValue:
-                    valueCheck = False
-            if not valueCheck:
-                main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
-                main.log.warn( getResponses )
-            getCheck = getCheck and valueCheck
-        utilities.assert_equals( expect=True,
-                                 actual=getCheck,
-                                 onpass="Partitioned Transactional Map get values were correct",
-                                 onfail="Partitioned Transactional Map values incorrect" )
+        main.HA.CASE17( main )
diff --git a/TestON/tests/HA/HAscaling/HAscaling.py b/TestON/tests/HA/HAscaling/HAscaling.py
index 112306a..c58ad41 100644
--- a/TestON/tests/HA/HAscaling/HAscaling.py
+++ b/TestON/tests/HA/HAscaling/HAscaling.py
@@ -3139,14 +3139,10 @@
         assert main.nodes, "main.nodes not defined"
 
         # Variables for the distributed primitives tests
-        global pCounterName
-        global pCounterValue
-        global onosSet
-        global onosSetName
-        pCounterName = "TestON-Partitions"
-        pCounterValue = 0
-        onosSet = set([])
-        onosSetName = "TestON-set"
+        main.pCounterName = "TestON-Partitions"
+        main.pCounterValue = 0
+        main.onosSet = set([])
+        main.onosSetName = "TestON-set"
 
         description = "Install Primitives app"
         main.case( description )
@@ -3164,1153 +3160,4 @@
         """
         Check for basic functionality with distributed primitives
         """
-        # Make sure variables are defined/set
-        assert main.numCtrls, "main.numCtrls not defined"
-        assert main, "main not defined"
-        assert utilities.assert_equals, "utilities.assert_equals not defined"
-        assert main.CLIs, "main.CLIs not defined"
-        assert main.nodes, "main.nodes not defined"
-        assert pCounterName, "pCounterName not defined"
-        assert onosSetName, "onosSetName not defined"
-        # NOTE: assert fails if value is 0/None/Empty/False
-        try:
-            pCounterValue
-        except NameError:
-            main.log.error( "pCounterValue not defined, setting to 0" )
-            pCounterValue = 0
-        try:
-            onosSet
-        except NameError:
-            main.log.error( "onosSet not defined, setting to empty Set" )
-            onosSet = set([])
-        # Variables for the distributed primitives tests. These are local only
-        addValue = "a"
-        addAllValue = "a b c d e f"
-        retainValue = "c d e f"
-
-        description = "Check for basic functionality with distributed " +\
-                      "primitives"
-        main.case( description )
-        main.caseExplanation = "Test the methods of the distributed " +\
-                                "primitives (counters and sets) throught the cli"
-        # DISTRIBUTED ATOMIC COUNTERS
-        # Partitioned counters
-        main.step( "Increment then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterAddAndGet-" + str( i ),
-                             args=[ pCounterName ] )
-            pCounterValue += 1
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then Increment a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterGetAndAdd-" + str( i ),
-                             args=[ pCounterName ] )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 1
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        main.step( "Add -8 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": -8 } )
-            pCounterValue += -8
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Add 5 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            pCounterValue += 5
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then add 5 to a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 5
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        # DISTRIBUTED SETS
-        main.step( "Distributed Set get" )
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=getResults,
-                                 onpass="Set elements are correct",
-                                 onfail="Set elements are incorrect" )
-
-        main.step( "Distributed Set size" )
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=sizeResults,
-                                 onpass="Set sizes are correct",
-                                 onfail="Set sizes are incorrect" )
-
-        main.step( "Distributed Set add()" )
-        onosSet.add( addValue )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAdd-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addResults = main.FALSE
-            else:
-                # unexpected result
-                addResults = main.FALSE
-        if addResults != main.TRUE:
-            main.log.error( "Error executing set add" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node + " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node + " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addResults = addResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addResults,
-                                 onpass="Set add correct",
-                                 onfail="Set add was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set contains()" )
-        containsResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContains-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsResponses.append( t.result )
-
-        containsResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsResults,
-                                 onpass="Set contains is functional",
-                                 onfail="Set contains failed" )
-
-        main.step( "Distributed Set containsAll()" )
-        containsAllResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContainsAll-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addAllValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsAllResponses.append( t.result )
-
-        containsAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsAllResults,
-                                 onpass="Set containsAll is functional",
-                                 onfail="Set containsAll failed" )
-
-        main.step( "Distributed Set remove()" )
-        onosSet.remove( addValue )
-        removeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRemove-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            removeResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeResults = main.FALSE
-            else:
-                # unexpected result
-                removeResults = main.FALSE
-        if removeResults != main.TRUE:
-            main.log.error( "Error executing set remove" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeResults = removeResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeResults,
-                                 onpass="Set remove correct",
-                                 onfail="Set remove was incorrect" )
-
-        main.step( "Distributed Set removeAll()" )
-        onosSet.difference_update( addAllValue.split() )
-        removeAllResponses = []
-        threads = []
-        try:
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].setTestRemove,
-                                 name="setTestRemoveAll-" + str( i ),
-                                 args=[ onosSetName, addAllValue ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                removeAllResponses.append( t.result )
-        except Exception, e:
-            main.log.exception(e)
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeAllResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeAllResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeAllResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeAllResults = main.FALSE
-            else:
-                # unexpected result
-                removeAllResults = main.FALSE
-        if removeAllResults != main.TRUE:
-            main.log.error( "Error executing set removeAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeAllResults = removeAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeAllResults,
-                                 onpass="Set removeAll correct",
-                                 onfail="Set removeAll was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set clear()" )
-        onosSet.clear()
-        clearResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestClear-" + str( i ),
-                             args=[ onosSetName, " "],  # Values doesn't matter
-                             kwargs={ "clear": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            clearResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        clearResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if clearResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif clearResponses[ i ] == main.FALSE:
-                # Nothing set, probably fine
-                pass
-            elif clearResponses[ i ] == main.ERROR:
-                # Error in execution
-                clearResults = main.FALSE
-            else:
-                # unexpected result
-                clearResults = main.FALSE
-        if clearResults != main.TRUE:
-            main.log.error( "Error executing set clear" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        clearResults = clearResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=clearResults,
-                                 onpass="Set clear correct",
-                                 onfail="Set clear was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set retain()" )
-        onosSet.intersection_update( retainValue.split() )
-        retainResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRetain-" + str( i ),
-                             args=[ onosSetName, retainValue ],
-                             kwargs={ "retain": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            retainResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        retainResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if retainResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif retainResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif retainResponses[ i ] == main.ERROR:
-                # Error in execution
-                retainResults = main.FALSE
-            else:
-                # unexpected result
-                retainResults = main.FALSE
-        if retainResults != main.TRUE:
-            main.log.error( "Error executing set retain" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node + " expected a size of " +
-                                str( size ) + " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        retainResults = retainResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=retainResults,
-                                 onpass="Set retain correct",
-                                 onfail="Set retain was incorrect" )
-
-        # Transactional maps
-        main.step( "Partitioned Transactional maps put" )
-        tMapValue = "Testing"
-        numKeys = 100
-        putResult = True
-        node = main.activeNodes[0]
-        putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue )
-        if putResponses and len( putResponses ) == 100:
-            for i in putResponses:
-                if putResponses[ i ][ 'value' ] != tMapValue:
-                    putResult = False
-        else:
-            putResult = False
-        if not putResult:
-            main.log.debug( "Put response values: " + str( putResponses ) )
-        utilities.assert_equals( expect=True,
-                                 actual=putResult,
-                                 onpass="Partitioned Transactional Map put successful",
-                                 onfail="Partitioned Transactional Map put values are incorrect" )
-
-        main.step( "Partitioned Transactional maps get" )
-        # FIXME: is this sleep needed?
-        time.sleep( 5 )
-
-        getCheck = True
-        for n in range( 1, numKeys + 1 ):
-            getResponses = []
-            threads = []
-            valueCheck = True
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].transactionalMapGet,
-                                 name="TMap-get-" + str( i ),
-                                 args=[ "Key" + str( n ) ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                getResponses.append( t.result )
-            for node in getResponses:
-                if node != tMapValue:
-                    valueCheck = False
-            if not valueCheck:
-                main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
-                main.log.warn( getResponses )
-            getCheck = getCheck and valueCheck
-        utilities.assert_equals( expect=True,
-                                 actual=getCheck,
-                                 onpass="Partitioned Transactional Map get values were correct",
-                                 onfail="Partitioned Transactional Map values incorrect" )
+        main.HA.CASE17( main )
diff --git a/TestON/tests/HA/HAsingleInstanceRestart/HAsingleInstanceRestart.params b/TestON/tests/HA/HAsingleInstanceRestart/HAsingleInstanceRestart.params
index d7ac493..f781c0c 100644
--- a/TestON/tests/HA/HAsingleInstanceRestart/HAsingleInstanceRestart.params
+++ b/TestON/tests/HA/HAsingleInstanceRestart/HAsingleInstanceRestart.params
@@ -14,6 +14,8 @@
     #CASE13: Clean up
     #CASE14: start election app on all onos nodes
     #CASE15: Check that Leadership Election is still functional
+    #CASE16: Install Distributed Primitives app
+    #CASE17: Check for basic functionality with distributed primitives
     <testcases>1,2,8,3,4,5,14,15,16,17,[6],8,3,7,4,15,17,9,8,4,10,8,4,11,8,4,12,8,4,13</testcases>
 
     <apps></apps>
diff --git a/TestON/tests/HA/HAsingleInstanceRestart/HAsingleInstanceRestart.py b/TestON/tests/HA/HAsingleInstanceRestart/HAsingleInstanceRestart.py
index 4d8eedc..4f15a60 100644
--- a/TestON/tests/HA/HAsingleInstanceRestart/HAsingleInstanceRestart.py
+++ b/TestON/tests/HA/HAsingleInstanceRestart/HAsingleInstanceRestart.py
@@ -2260,7 +2260,7 @@
         # verify leader didn't just change
         # Get new leaders and candidates
         reRunLeaders = []
-        time.sleep( 5 ) # Paremterize
+        time.sleep( 5 )  # Paremterize
         positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
 
         # Check that the re-elected node is last on the candidate List
@@ -2289,14 +2289,10 @@
         assert main.nodes, "main.nodes not defined"
 
         # Variables for the distributed primitives tests
-        global pCounterName
-        global pCounterValue
-        global onosSet
-        global onosSetName
-        pCounterName = "TestON-Partitions"
-        pCounterValue = 0
-        onosSet = set([])
-        onosSetName = "TestON-set"
+        main.pCounterName = "TestON-Partitions"
+        main.pCounterValue = 0
+        main.onosSet = set([])
+        main.onosSetName = "TestON-set"
 
         description = "Install Primitives app"
         main.case( description )
@@ -2308,1159 +2304,11 @@
                                  actual=appResults,
                                  onpass="Primitives app activated",
                                  onfail="Primitives app not activated" )
+        # TODO check on all nodes instead of sleeping
         time.sleep( 5 )  # To allow all nodes to activate
 
     def CASE17( self, main ):
         """
         Check for basic functionality with distributed primitives
         """
-        # Make sure variables are defined/set
-        assert main.numCtrls, "main.numCtrls not defined"
-        assert main, "main not defined"
-        assert utilities.assert_equals, "utilities.assert_equals not defined"
-        assert main.CLIs, "main.CLIs not defined"
-        assert main.nodes, "main.nodes not defined"
-        assert pCounterName, "pCounterName not defined"
-        assert onosSetName, "onosSetName not defined"
-        # NOTE: assert fails if value is 0/None/Empty/False
-        try:
-            pCounterValue
-        except NameError:
-            main.log.error( "pCounterValue not defined, setting to 0" )
-            pCounterValue = 0
-        try:
-            onosSet
-        except NameError:
-            main.log.error( "onosSet not defined, setting to empty Set" )
-            onosSet = set([])
-        # Variables for the distributed primitives tests. These are local only
-        addValue = "a"
-        addAllValue = "a b c d e f"
-        retainValue = "c d e f"
-
-        description = "Check for basic functionality with distributed " +\
-                      "primitives"
-        main.case( description )
-        main.caseExplanation = "Test the methods of the distributed " +\
-                                "primitives (counters and sets) throught the cli"
-        # DISTRIBUTED ATOMIC COUNTERS
-        # Partitioned counters
-        main.step( "Increment then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterAddAndGet-" + str( i ),
-                             args=[ pCounterName ] )
-            pCounterValue += 1
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then Increment a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterGetAndAdd-" + str( i ),
-                             args=[ pCounterName ] )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 1
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        main.step( "Add -8 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": -8 } )
-            pCounterValue += -8
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Add 5 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            pCounterValue += 5
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then add 5 to a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 5
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        # DISTRIBUTED SETS
-        main.step( "Distributed Set get" )
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=getResults,
-                                 onpass="Set elements are correct",
-                                 onfail="Set elements are incorrect" )
-
-        main.step( "Distributed Set size" )
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=sizeResults,
-                                 onpass="Set sizes are correct",
-                                 onfail="Set sizes are incorrect" )
-
-        main.step( "Distributed Set add()" )
-        onosSet.add( addValue )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAdd-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addResults = main.FALSE
-            else:
-                # unexpected result
-                addResults = main.FALSE
-        if addResults != main.TRUE:
-            main.log.error( "Error executing set add" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node + " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node + " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addResults = addResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addResults,
-                                 onpass="Set add correct",
-                                 onfail="Set add was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set contains()" )
-        containsResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContains-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsResponses.append( t.result )
-
-        containsResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsResults,
-                                 onpass="Set contains is functional",
-                                 onfail="Set contains failed" )
-
-        main.step( "Distributed Set containsAll()" )
-        containsAllResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContainsAll-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addAllValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsAllResponses.append( t.result )
-
-        containsAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsAllResults,
-                                 onpass="Set containsAll is functional",
-                                 onfail="Set containsAll failed" )
-
-        main.step( "Distributed Set remove()" )
-        onosSet.remove( addValue )
-        removeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRemove-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            removeResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeResults = main.FALSE
-            else:
-                # unexpected result
-                removeResults = main.FALSE
-        if removeResults != main.TRUE:
-            main.log.error( "Error executing set remove" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeResults = removeResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeResults,
-                                 onpass="Set remove correct",
-                                 onfail="Set remove was incorrect" )
-
-        main.step( "Distributed Set removeAll()" )
-        onosSet.difference_update( addAllValue.split() )
-        removeAllResponses = []
-        threads = []
-        try:
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].setTestRemove,
-                                 name="setTestRemoveAll-" + str( i ),
-                                 args=[ onosSetName, addAllValue ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                removeAllResponses.append( t.result )
-        except Exception, e:
-            main.log.exception(e)
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeAllResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeAllResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeAllResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeAllResults = main.FALSE
-            else:
-                # unexpected result
-                removeAllResults = main.FALSE
-        if removeAllResults != main.TRUE:
-            main.log.error( "Error executing set removeAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeAllResults = removeAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeAllResults,
-                                 onpass="Set removeAll correct",
-                                 onfail="Set removeAll was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set clear()" )
-        onosSet.clear()
-        clearResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestClear-" + str( i ),
-                             args=[ onosSetName, " "],  # Values doesn't matter
-                             kwargs={ "clear": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            clearResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        clearResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if clearResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif clearResponses[ i ] == main.FALSE:
-                # Nothing set, probably fine
-                pass
-            elif clearResponses[ i ] == main.ERROR:
-                # Error in execution
-                clearResults = main.FALSE
-            else:
-                # unexpected result
-                clearResults = main.FALSE
-        if clearResults != main.TRUE:
-            main.log.error( "Error executing set clear" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        clearResults = clearResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=clearResults,
-                                 onpass="Set clear correct",
-                                 onfail="Set clear was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set retain()" )
-        onosSet.intersection_update( retainValue.split() )
-        retainResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRetain-" + str( i ),
-                             args=[ onosSetName, retainValue ],
-                             kwargs={ "retain": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            retainResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        retainResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if retainResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif retainResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif retainResponses[ i ] == main.ERROR:
-                # Error in execution
-                retainResults = main.FALSE
-            else:
-                # unexpected result
-                retainResults = main.FALSE
-        if retainResults != main.TRUE:
-            main.log.error( "Error executing set retain" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node + " expected a size of " +
-                                str( size ) + " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        retainResults = retainResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=retainResults,
-                                 onpass="Set retain correct",
-                                 onfail="Set retain was incorrect" )
-
-        # Transactional maps
-        main.step( "Partitioned Transactional maps put" )
-        tMapValue = "Testing"
-        numKeys = 100
-        putResult = True
-        node = main.activeNodes[0]
-        putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue )
-        if putResponses and len( putResponses ) == 100:
-            for i in putResponses:
-                if putResponses[ i ][ 'value' ] != tMapValue:
-                    putResult = False
-        else:
-            putResult = False
-        if not putResult:
-            main.log.debug( "Put response values: " + str( putResponses ) )
-        utilities.assert_equals( expect=True,
-                                 actual=putResult,
-                                 onpass="Partitioned Transactional Map put successful",
-                                 onfail="Partitioned Transactional Map put values are incorrect" )
-
-        main.step( "Partitioned Transactional maps get" )
-        # FIXME: is this sleep needed?
-        time.sleep( 5 )
-
-        getCheck = True
-        for n in range( 1, numKeys + 1 ):
-            getResponses = []
-            threads = []
-            valueCheck = True
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].transactionalMapGet,
-                                 name="TMap-get-" + str( i ),
-                                 args=[ "Key" + str( n ) ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                getResponses.append( t.result )
-            for node in getResponses:
-                if node != tMapValue:
-                    valueCheck = False
-            if not valueCheck:
-                main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
-                main.log.warn( getResponses )
-            getCheck = getCheck and valueCheck
-        utilities.assert_equals( expect=True,
-                                 actual=getCheck,
-                                 onpass="Partitioned Transactional Map get values were correct",
-                                 onfail="Partitioned Transactional Map values incorrect" )
+        main.HA.CASE17( main )
diff --git a/TestON/tests/HA/HAstopNodes/HAstopNodes.py b/TestON/tests/HA/HAstopNodes/HAstopNodes.py
index b6a74e5..6c32b16 100644
--- a/TestON/tests/HA/HAstopNodes/HAstopNodes.py
+++ b/TestON/tests/HA/HAstopNodes/HAstopNodes.py
@@ -3089,7 +3089,7 @@
         # verify leader didn't just change
         # Get new leaders and candidates
         reRunLeaders = []
-        time.sleep( 5 ) # Paremterize
+        time.sleep( 5 )  # Paremterize
         positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
 
         # Check that the re-elected node is last on the candidate List
@@ -3118,14 +3118,10 @@
         assert main.nodes, "main.nodes not defined"
 
         # Variables for the distributed primitives tests
-        global pCounterName
-        global pCounterValue
-        global onosSet
-        global onosSetName
-        pCounterName = "TestON-Partitions"
-        pCounterValue = 0
-        onosSet = set([])
-        onosSetName = "TestON-set"
+        main.pCounterName = "TestON-Partitions"
+        main.pCounterValue = 0
+        main.onosSet = set([])
+        main.onosSetName = "TestON-set"
 
         description = "Install Primitives app"
         main.case( description )
@@ -3143,1153 +3139,4 @@
         """
         Check for basic functionality with distributed primitives
         """
-        # Make sure variables are defined/set
-        assert main.numCtrls, "main.numCtrls not defined"
-        assert main, "main not defined"
-        assert utilities.assert_equals, "utilities.assert_equals not defined"
-        assert main.CLIs, "main.CLIs not defined"
-        assert main.nodes, "main.nodes not defined"
-        assert pCounterName, "pCounterName not defined"
-        assert onosSetName, "onosSetName not defined"
-        # NOTE: assert fails if value is 0/None/Empty/False
-        try:
-            pCounterValue
-        except NameError:
-            main.log.error( "pCounterValue not defined, setting to 0" )
-            pCounterValue = 0
-        try:
-            onosSet
-        except NameError:
-            main.log.error( "onosSet not defined, setting to empty Set" )
-            onosSet = set([])
-        # Variables for the distributed primitives tests. These are local only
-        addValue = "a"
-        addAllValue = "a b c d e f"
-        retainValue = "c d e f"
-
-        description = "Check for basic functionality with distributed " +\
-                      "primitives"
-        main.case( description )
-        main.caseExplanation = "Test the methods of the distributed " +\
-                                "primitives (counters and sets) throught the cli"
-        # DISTRIBUTED ATOMIC COUNTERS
-        # Partitioned counters
-        main.step( "Increment then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterAddAndGet-" + str( i ),
-                             args=[ pCounterName ] )
-            pCounterValue += 1
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then Increment a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterGetAndAdd-" + str( i ),
-                             args=[ pCounterName ] )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 1
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        main.step( "Add -8 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": -8 } )
-            pCounterValue += -8
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Add 5 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            pCounterValue += 5
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then add 5 to a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 5
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        # DISTRIBUTED SETS
-        main.step( "Distributed Set get" )
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=getResults,
-                                 onpass="Set elements are correct",
-                                 onfail="Set elements are incorrect" )
-
-        main.step( "Distributed Set size" )
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=sizeResults,
-                                 onpass="Set sizes are correct",
-                                 onfail="Set sizes are incorrect" )
-
-        main.step( "Distributed Set add()" )
-        onosSet.add( addValue )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAdd-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addResults = main.FALSE
-            else:
-                # unexpected result
-                addResults = main.FALSE
-        if addResults != main.TRUE:
-            main.log.error( "Error executing set add" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node + " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node + " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addResults = addResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addResults,
-                                 onpass="Set add correct",
-                                 onfail="Set add was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set contains()" )
-        containsResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContains-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsResponses.append( t.result )
-
-        containsResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsResults,
-                                 onpass="Set contains is functional",
-                                 onfail="Set contains failed" )
-
-        main.step( "Distributed Set containsAll()" )
-        containsAllResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContainsAll-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addAllValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsAllResponses.append( t.result )
-
-        containsAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsAllResults,
-                                 onpass="Set containsAll is functional",
-                                 onfail="Set containsAll failed" )
-
-        main.step( "Distributed Set remove()" )
-        onosSet.remove( addValue )
-        removeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRemove-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            removeResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeResults = main.FALSE
-            else:
-                # unexpected result
-                removeResults = main.FALSE
-        if removeResults != main.TRUE:
-            main.log.error( "Error executing set remove" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeResults = removeResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeResults,
-                                 onpass="Set remove correct",
-                                 onfail="Set remove was incorrect" )
-
-        main.step( "Distributed Set removeAll()" )
-        onosSet.difference_update( addAllValue.split() )
-        removeAllResponses = []
-        threads = []
-        try:
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].setTestRemove,
-                                 name="setTestRemoveAll-" + str( i ),
-                                 args=[ onosSetName, addAllValue ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                removeAllResponses.append( t.result )
-        except Exception, e:
-            main.log.exception(e)
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeAllResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeAllResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeAllResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeAllResults = main.FALSE
-            else:
-                # unexpected result
-                removeAllResults = main.FALSE
-        if removeAllResults != main.TRUE:
-            main.log.error( "Error executing set removeAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeAllResults = removeAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeAllResults,
-                                 onpass="Set removeAll correct",
-                                 onfail="Set removeAll was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set clear()" )
-        onosSet.clear()
-        clearResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestClear-" + str( i ),
-                             args=[ onosSetName, " "],  # Values doesn't matter
-                             kwargs={ "clear": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            clearResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        clearResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if clearResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif clearResponses[ i ] == main.FALSE:
-                # Nothing set, probably fine
-                pass
-            elif clearResponses[ i ] == main.ERROR:
-                # Error in execution
-                clearResults = main.FALSE
-            else:
-                # unexpected result
-                clearResults = main.FALSE
-        if clearResults != main.TRUE:
-            main.log.error( "Error executing set clear" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        clearResults = clearResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=clearResults,
-                                 onpass="Set clear correct",
-                                 onfail="Set clear was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set retain()" )
-        onosSet.intersection_update( retainValue.split() )
-        retainResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRetain-" + str( i ),
-                             args=[ onosSetName, retainValue ],
-                             kwargs={ "retain": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            retainResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        retainResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if retainResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif retainResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif retainResponses[ i ] == main.ERROR:
-                # Error in execution
-                retainResults = main.FALSE
-            else:
-                # unexpected result
-                retainResults = main.FALSE
-        if retainResults != main.TRUE:
-            main.log.error( "Error executing set retain" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node + " expected a size of " +
-                                str( size ) + " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        retainResults = retainResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=retainResults,
-                                 onpass="Set retain correct",
-                                 onfail="Set retain was incorrect" )
-
-        # Transactional maps
-        main.step( "Partitioned Transactional maps put" )
-        tMapValue = "Testing"
-        numKeys = 100
-        putResult = True
-        node = main.activeNodes[0]
-        putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue )
-        if putResponses and len( putResponses ) == 100:
-            for i in putResponses:
-                if putResponses[ i ][ 'value' ] != tMapValue:
-                    putResult = False
-        else:
-            putResult = False
-        if not putResult:
-            main.log.debug( "Put response values: " + str( putResponses ) )
-        utilities.assert_equals( expect=True,
-                                 actual=putResult,
-                                 onpass="Partitioned Transactional Map put successful",
-                                 onfail="Partitioned Transactional Map put values are incorrect" )
-
-        main.step( "Partitioned Transactional maps get" )
-        # FIXME: is this sleep needed?
-        time.sleep( 5 )
-
-        getCheck = True
-        for n in range( 1, numKeys + 1 ):
-            getResponses = []
-            threads = []
-            valueCheck = True
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].transactionalMapGet,
-                                 name="TMap-get-" + str( i ),
-                                 args=[ "Key" + str( n ) ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                getResponses.append( t.result )
-            for node in getResponses:
-                if node != tMapValue:
-                    valueCheck = False
-            if not valueCheck:
-                main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
-                main.log.warn( getResponses )
-            getCheck = getCheck and valueCheck
-        utilities.assert_equals( expect=True,
-                                 actual=getCheck,
-                                 onpass="Partitioned Transactional Map get values were correct",
-                                 onfail="Partitioned Transactional Map values incorrect" )
+        main.HA.CASE17( main )
diff --git a/TestON/tests/HA/HAswapNodes/HAswapNodes.py b/TestON/tests/HA/HAswapNodes/HAswapNodes.py
index 1be977a..8f2b58c 100644
--- a/TestON/tests/HA/HAswapNodes/HAswapNodes.py
+++ b/TestON/tests/HA/HAswapNodes/HAswapNodes.py
@@ -3053,7 +3053,7 @@
         if newLeader == oldLeader:
             newLeaderResult = False
             main.log.error( "All nodes still see old leader: " + str( oldLeader ) +
-                    " as the current leader" )
+                " as the current leader" )
         utilities.assert_equals(
             expect=True,
             actual=newLeaderResult,
@@ -3135,14 +3135,10 @@
         assert main.nodes, "main.nodes not defined"
 
         # Variables for the distributed primitives tests
-        global pCounterName
-        global pCounterValue
-        global onosSet
-        global onosSetName
-        pCounterName = "TestON-Partitions"
-        pCounterValue = 0
-        onosSet = set([])
-        onosSetName = "TestON-set"
+        main.pCounterName = "TestON-Partitions"
+        main.pCounterValue = 0
+        main.onosSet = set([])
+        main.onosSetName = "TestON-set"
 
         description = "Install Primitives app"
         main.case( description )
@@ -3160,1150 +3156,4 @@
         """
         Check for basic functionality with distributed primitives
         """
-        # Make sure variables are defined/set
-        assert main.numCtrls, "main.numCtrls not defined"
-        assert main, "main not defined"
-        assert utilities.assert_equals, "utilities.assert_equals not defined"
-        assert main.CLIs, "main.CLIs not defined"
-        assert main.nodes, "main.nodes not defined"
-        assert pCounterName, "pCounterName not defined"
-        assert onosSetName, "onosSetName not defined"
-        # NOTE: assert fails if value is 0/None/Empty/False
-        try:
-            pCounterValue
-        except NameError:
-            main.log.error( "pCounterValue not defined, setting to 0" )
-            pCounterValue = 0
-        try:
-            onosSet
-        except NameError:
-            main.log.error( "onosSet not defined, setting to empty Set" )
-            onosSet = set([])
-        # Variables for the distributed primitives tests. These are local only
-        addValue = "a"
-        addAllValue = "a b c d e f"
-        retainValue = "c d e f"
-
-        description = "Check for basic functionality with distributed " +\
-                      "primitives"
-        main.case( description )
-        main.caseExplanation = "Test the methods of the distributed " +\
-                                "primitives (counters and sets) throught the cli"
-        # DISTRIBUTED ATOMIC COUNTERS
-        # Partitioned counters
-        main.step( "Increment then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterAddAndGet-" + str( i ),
-                             args=[ pCounterName ] )
-            pCounterValue += 1
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then Increment a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterGetAndAdd-" + str( i ),
-                             args=[ pCounterName ] )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 1
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        main.step( "Add -8 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": -8 } )
-            pCounterValue += -8
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Add 5 to then get a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            pCounterValue += 5
-            addedPValues.append( pCounterValue )
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Get then add 5 to a default counter on each node" )
-        pCounters = []
-        threads = []
-        addedPValues = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
-                             name="counterIncrement-" + str( i ),
-                             args=[ pCounterName ],
-                             kwargs={ "delta": 5 } )
-            addedPValues.append( pCounterValue )
-            pCounterValue += 5
-            threads.append( t )
-            t.start()
-
-        for t in threads:
-            t.join()
-            pCounters.append( t.result )
-        # Check that counter incremented numController times
-        pCounterResults = True
-        for i in addedPValues:
-            tmpResult = i in pCounters
-            pCounterResults = pCounterResults and tmpResult
-            if not tmpResult:
-                main.log.error( str( i ) + " is not in partitioned "
-                                "counter incremented results" )
-        utilities.assert_equals( expect=True,
-                                 actual=pCounterResults,
-                                 onpass="Default counter incremented",
-                                 onfail="Error incrementing default" +
-                                        " counter" )
-
-        main.step( "Counters we added have the correct values" )
-        incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=incrementCheck,
-                                 onpass="Added counters are correct",
-                                 onfail="Added counters are incorrect" )
-
-        # DISTRIBUTED SETS
-        main.step( "Distributed Set get" )
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=getResults,
-                                 onpass="Set elements are correct",
-                                 onfail="Set elements are incorrect" )
-
-        main.step( "Distributed Set size" )
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=sizeResults,
-                                 onpass="Set sizes are correct",
-                                 onfail="Set sizes are incorrect" )
-
-        main.step( "Distributed Set add()" )
-        onosSet.add( addValue )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAdd-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addResults = main.FALSE
-            else:
-                # unexpected result
-                addResults = main.FALSE
-        if addResults != main.TRUE:
-            main.log.error( "Error executing set add" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node + " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node + " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addResults = addResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addResults,
-                                 onpass="Set add correct",
-                                 onfail="Set add was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set contains()" )
-        containsResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContains-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsResponses.append( t.result )
-
-        containsResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsResults,
-                                 onpass="Set contains is functional",
-                                 onfail="Set contains failed" )
-
-        main.step( "Distributed Set containsAll()" )
-        containsAllResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setContainsAll-" + str( i ),
-                             args=[ onosSetName ],
-                             kwargs={ "values": addAllValue } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            # NOTE: This is the tuple
-            containsAllResponses.append( t.result )
-
-        containsAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if containsResponses[ i ] == main.ERROR:
-                containsResults = main.FALSE
-            else:
-                containsResults = containsResults and\
-                                  containsResponses[ i ][ 1 ]
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=containsAllResults,
-                                 onpass="Set containsAll is functional",
-                                 onfail="Set containsAll failed" )
-
-        main.step( "Distributed Set remove()" )
-        onosSet.remove( addValue )
-        removeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRemove-" + str( i ),
-                             args=[ onosSetName, addValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            removeResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeResults = main.FALSE
-            else:
-                # unexpected result
-                removeResults = main.FALSE
-        if removeResults != main.TRUE:
-            main.log.error( "Error executing set remove" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeResults = removeResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeResults,
-                                 onpass="Set remove correct",
-                                 onfail="Set remove was incorrect" )
-
-        main.step( "Distributed Set removeAll()" )
-        onosSet.difference_update( addAllValue.split() )
-        removeAllResponses = []
-        threads = []
-        try:
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].setTestRemove,
-                                 name="setTestRemoveAll-" + str( i ),
-                                 args=[ onosSetName, addAllValue ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                removeAllResponses.append( t.result )
-        except Exception, e:
-            main.log.exception(e)
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        removeAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if removeAllResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif removeAllResponses[ i ] == main.FALSE:
-                # not in set, probably fine
-                pass
-            elif removeAllResponses[ i ] == main.ERROR:
-                # Error in execution
-                removeAllResults = main.FALSE
-            else:
-                # unexpected result
-                removeAllResults = main.FALSE
-        if removeAllResults != main.TRUE:
-            main.log.error( "Error executing set removeAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        removeAllResults = removeAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=removeAllResults,
-                                 onpass="Set removeAll correct",
-                                 onfail="Set removeAll was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set clear()" )
-        onosSet.clear()
-        clearResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestClear-" + str( i ),
-                             args=[ onosSetName, " "],  # Values doesn't matter
-                             kwargs={ "clear": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            clearResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        clearResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if clearResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif clearResponses[ i ] == main.FALSE:
-                # Nothing set, probably fine
-                pass
-            elif clearResponses[ i ] == main.ERROR:
-                # Error in execution
-                clearResults = main.FALSE
-            else:
-                # unexpected result
-                clearResults = main.FALSE
-        if clearResults != main.TRUE:
-            main.log.error( "Error executing set clear" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        clearResults = clearResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=clearResults,
-                                 onpass="Set clear correct",
-                                 onfail="Set clear was incorrect" )
-
-        main.step( "Distributed Set addAll()" )
-        onosSet.update( addAllValue.split() )
-        addResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestAdd,
-                             name="setTestAddAll-" + str( i ),
-                             args=[ onosSetName, addAllValue ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            addResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        addAllResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if addResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif addResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif addResponses[ i ] == main.ERROR:
-                # Error in execution
-                addAllResults = main.FALSE
-            else:
-                # unexpected result
-                addAllResults = main.FALSE
-        if addAllResults != main.TRUE:
-            main.log.error( "Error executing set addAll" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node +
-                                " expected a size of " + str( size ) +
-                                " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        addAllResults = addAllResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=addAllResults,
-                                 onpass="Set addAll correct",
-                                 onfail="Set addAll was incorrect" )
-
-        main.step( "Distributed Set retain()" )
-        onosSet.intersection_update( retainValue.split() )
-        retainResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestRemove,
-                             name="setTestRetain-" + str( i ),
-                             args=[ onosSetName, retainValue ],
-                             kwargs={ "retain": True } )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            retainResponses.append( t.result )
-
-        # main.TRUE = successfully changed the set
-        # main.FALSE = action resulted in no change in set
-        # main.ERROR - Some error in executing the function
-        retainResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            if retainResponses[ i ] == main.TRUE:
-                # All is well
-                pass
-            elif retainResponses[ i ] == main.FALSE:
-                # Already in set, probably fine
-                pass
-            elif retainResponses[ i ] == main.ERROR:
-                # Error in execution
-                retainResults = main.FALSE
-            else:
-                # unexpected result
-                retainResults = main.FALSE
-        if retainResults != main.TRUE:
-            main.log.error( "Error executing set retain" )
-
-        # Check if set is still correct
-        size = len( onosSet )
-        getResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestGet,
-                             name="setTestGet-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            getResponses.append( t.result )
-        getResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if isinstance( getResponses[ i ], list):
-                current = set( getResponses[ i ] )
-                if len( current ) == len( getResponses[ i ] ):
-                    # no repeats
-                    if onosSet != current:
-                        main.log.error( "ONOS" + node +
-                                        " has incorrect view" +
-                                        " of set " + onosSetName + ":\n" +
-                                        str( getResponses[ i ] ) )
-                        main.log.debug( "Expected: " + str( onosSet ) )
-                        main.log.debug( "Actual: " + str( current ) )
-                        getResults = main.FALSE
-                else:
-                    # error, set is not a set
-                    main.log.error( "ONOS" + node +
-                                    " has repeat elements in" +
-                                    " set " + onosSetName + ":\n" +
-                                    str( getResponses[ i ] ) )
-                    getResults = main.FALSE
-            elif getResponses[ i ] == main.ERROR:
-                getResults = main.FALSE
-        sizeResponses = []
-        threads = []
-        for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].setTestSize,
-                             name="setTestSize-" + str( i ),
-                             args=[ onosSetName ] )
-            threads.append( t )
-            t.start()
-        for t in threads:
-            t.join()
-            sizeResponses.append( t.result )
-        sizeResults = main.TRUE
-        for i in range( len( main.activeNodes ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if size != sizeResponses[ i ]:
-                sizeResults = main.FALSE
-                main.log.error( "ONOS" + node + " expected a size of " +
-                                str( size ) + " for set " + onosSetName +
-                                " but got " + str( sizeResponses[ i ] ) )
-        retainResults = retainResults and getResults and sizeResults
-        utilities.assert_equals( expect=main.TRUE,
-                                 actual=retainResults,
-                                 onpass="Set retain correct",
-                                 onfail="Set retain was incorrect" )
-
-        # Transactional maps
-        main.step( "Partitioned Transactional maps put" )
-        tMapValue = "Testing"
-        numKeys = 100
-        putResult = True
-        node = main.activeNodes[0]
-        putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue )
-        if putResponses and len( putResponses ) == 100:
-            for i in putResponses:
-                if putResponses[ i ][ 'value' ] != tMapValue:
-                    putResult = False
-        else:
-            putResult = False
-        if not putResult:
-            main.log.debug( "Put response values: " + str( putResponses ) )
-        utilities.assert_equals( expect=True,
-                                 actual=putResult,
-                                 onpass="Partitioned Transactional Map put successful",
-                                 onfail="Partitioned Transactional Map put values are incorrect" )
-
-        main.step( "Partitioned Transactional maps get" )
-        getCheck = True
-        for n in range( 1, numKeys + 1 ):
-            getResponses = []
-            threads = []
-            valueCheck = True
-            for i in main.activeNodes:
-                t = main.Thread( target=main.CLIs[i].transactionalMapGet,
-                                 name="TMap-get-" + str( i ),
-                                 args=[ "Key" + str( n ) ] )
-                threads.append( t )
-                t.start()
-            for t in threads:
-                t.join()
-                getResponses.append( t.result )
-            for node in getResponses:
-                if node != tMapValue:
-                    valueCheck = False
-            if not valueCheck:
-                main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
-                main.log.warn( getResponses )
-            getCheck = getCheck and valueCheck
-        utilities.assert_equals( expect=True,
-                                 actual=getCheck,
-                                 onpass="Partitioned Transactional Map get values were correct",
-                                 onfail="Partitioned Transactional Map values incorrect" )
+        main.HA.CASE17( main )
diff --git a/TestON/tests/HA/dependencies/HA.py b/TestON/tests/HA/dependencies/HA.py
index e00d290..b6c6f26 100644
--- a/TestON/tests/HA/dependencies/HA.py
+++ b/TestON/tests/HA/dependencies/HA.py
@@ -159,3 +159,1368 @@
                 currentResult = False
             results = results and currentResult
         return results
+
+    def CASE17( self, main ):
+        """
+        Check for basic functionality with distributed primitives
+        """
+        #TODO: Clean this up so it's not just a cut/paste from the test
+        try:
+            # Make sure variables are defined/set
+            assert main.numCtrls, "main.numCtrls not defined"
+            assert utilities.assert_equals, "utilities.assert_equals not defined"
+            assert main.CLIs, "main.CLIs not defined"
+            assert main.nodes, "main.nodes not defined"
+            assert main.pCounterName, "main.pCounterName not defined"
+            assert main.onosSetName, "main.onosSetName not defined"
+            # NOTE: assert fails if value is 0/None/Empty/False
+            try:
+                main.pCounterValue
+            except NameError:
+                main.log.error( "main.pCounterValue not defined, setting to 0" )
+                main.pCounterValue = 0
+            try:
+                main.onosSet
+            except NameError:
+                main.log.error( "main.onosSet not defined, setting to empty Set" )
+                main.onosSet = set([])
+            # Variables for the distributed primitives tests. These are local only
+            addValue = "a"
+            addAllValue = "a b c d e f"
+            retainValue = "c d e f"
+            valueName = "TestOn-Value"
+            valueValue = None
+
+            description = "Check for basic functionality with distributed " +\
+                          "primitives"
+            main.case( description )
+            main.caseExplanation = "Test the methods of the distributed " +\
+                                    "primitives (counters and sets) throught the cli"
+            # DISTRIBUTED ATOMIC COUNTERS
+            # Partitioned counters
+            main.step( "Increment then get a default counter on each node" )
+            pCounters = []
+            threads = []
+            addedPValues = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
+                                 name="counterAddAndGet-" + str( i ),
+                                 args=[ main.pCounterName ] )
+                main.pCounterValue += 1
+                addedPValues.append( main.pCounterValue )
+                threads.append( t )
+                t.start()
+
+            for t in threads:
+                t.join()
+                pCounters.append( t.result )
+            # Check that counter incremented numController times
+            pCounterResults = True
+            for i in addedPValues:
+                tmpResult = i in pCounters
+                pCounterResults = pCounterResults and tmpResult
+                if not tmpResult:
+                    main.log.error( str( i ) + " is not in partitioned "
+                                    "counter incremented results" )
+            utilities.assert_equals( expect=True,
+                                     actual=pCounterResults,
+                                     onpass="Default counter incremented",
+                                     onfail="Error incrementing default" +
+                                            " counter" )
+
+            main.step( "Get then Increment a default counter on each node" )
+            pCounters = []
+            threads = []
+            addedPValues = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
+                                 name="counterGetAndAdd-" + str( i ),
+                                 args=[ main.pCounterName ] )
+                addedPValues.append( main.pCounterValue )
+                main.pCounterValue += 1
+                threads.append( t )
+                t.start()
+
+            for t in threads:
+                t.join()
+                pCounters.append( t.result )
+            # Check that counter incremented numController times
+            pCounterResults = True
+            for i in addedPValues:
+                tmpResult = i in pCounters
+                pCounterResults = pCounterResults and tmpResult
+                if not tmpResult:
+                    main.log.error( str( i ) + " is not in partitioned "
+                                    "counter incremented results" )
+            utilities.assert_equals( expect=True,
+                                     actual=pCounterResults,
+                                     onpass="Default counter incremented",
+                                     onfail="Error incrementing default" +
+                                            " counter" )
+
+            main.step( "Counters we added have the correct values" )
+            incrementCheck = main.HA.counterCheck( main.pCounterName, main.pCounterValue )
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=incrementCheck,
+                                     onpass="Added counters are correct",
+                                     onfail="Added counters are incorrect" )
+
+            main.step( "Add -8 to then get a default counter on each node" )
+            pCounters = []
+            threads = []
+            addedPValues = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
+                                 name="counterIncrement-" + str( i ),
+                                 args=[ main.pCounterName ],
+                                 kwargs={ "delta": -8 } )
+                main.pCounterValue += -8
+                addedPValues.append( main.pCounterValue )
+                threads.append( t )
+                t.start()
+
+            for t in threads:
+                t.join()
+                pCounters.append( t.result )
+            # Check that counter incremented numController times
+            pCounterResults = True
+            for i in addedPValues:
+                tmpResult = i in pCounters
+                pCounterResults = pCounterResults and tmpResult
+                if not tmpResult:
+                    main.log.error( str( i ) + " is not in partitioned "
+                                    "counter incremented results" )
+            utilities.assert_equals( expect=True,
+                                     actual=pCounterResults,
+                                     onpass="Default counter incremented",
+                                     onfail="Error incrementing default" +
+                                            " counter" )
+
+            main.step( "Add 5 to then get a default counter on each node" )
+            pCounters = []
+            threads = []
+            addedPValues = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
+                                 name="counterIncrement-" + str( i ),
+                                 args=[ main.pCounterName ],
+                                 kwargs={ "delta": 5 } )
+                main.pCounterValue += 5
+                addedPValues.append( main.pCounterValue )
+                threads.append( t )
+                t.start()
+
+            for t in threads:
+                t.join()
+                pCounters.append( t.result )
+            # Check that counter incremented numController times
+            pCounterResults = True
+            for i in addedPValues:
+                tmpResult = i in pCounters
+                pCounterResults = pCounterResults and tmpResult
+                if not tmpResult:
+                    main.log.error( str( i ) + " is not in partitioned "
+                                    "counter incremented results" )
+            utilities.assert_equals( expect=True,
+                                     actual=pCounterResults,
+                                     onpass="Default counter incremented",
+                                     onfail="Error incrementing default" +
+                                            " counter" )
+
+            main.step( "Get then add 5 to a default counter on each node" )
+            pCounters = []
+            threads = []
+            addedPValues = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
+                                 name="counterIncrement-" + str( i ),
+                                 args=[ main.pCounterName ],
+                                 kwargs={ "delta": 5 } )
+                addedPValues.append( main.pCounterValue )
+                main.pCounterValue += 5
+                threads.append( t )
+                t.start()
+
+            for t in threads:
+                t.join()
+                pCounters.append( t.result )
+            # Check that counter incremented numController times
+            pCounterResults = True
+            for i in addedPValues:
+                tmpResult = i in pCounters
+                pCounterResults = pCounterResults and tmpResult
+                if not tmpResult:
+                    main.log.error( str( i ) + " is not in partitioned "
+                                    "counter incremented results" )
+            utilities.assert_equals( expect=True,
+                                     actual=pCounterResults,
+                                     onpass="Default counter incremented",
+                                     onfail="Error incrementing default" +
+                                            " counter" )
+
+            main.step( "Counters we added have the correct values" )
+            incrementCheck = main.HA.counterCheck( main.pCounterName, main.pCounterValue )
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=incrementCheck,
+                                     onpass="Added counters are correct",
+                                     onfail="Added counters are incorrect" )
+
+            # DISTRIBUTED SETS
+            main.step( "Distributed Set get" )
+            size = len( main.onosSet )
+            getResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestGet,
+                                 name="setTestGet-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                getResponses.append( t.result )
+
+            getResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if isinstance( getResponses[ i ], list):
+                    current = set( getResponses[ i ] )
+                    if len( current ) == len( getResponses[ i ] ):
+                        # no repeats
+                        if main.onosSet != current:
+                            main.log.error( "ONOS" + node +
+                                            " has incorrect view" +
+                                            " of set " + main.onosSetName + ":\n" +
+                                            str( getResponses[ i ] ) )
+                            main.log.debug( "Expected: " + str( main.onosSet ) )
+                            main.log.debug( "Actual: " + str( current ) )
+                            getResults = main.FALSE
+                    else:
+                        # error, set is not a set
+                        main.log.error( "ONOS" + node +
+                                        " has repeat elements in" +
+                                        " set " + main.onosSetName + ":\n" +
+                                        str( getResponses[ i ] ) )
+                        getResults = main.FALSE
+                elif getResponses[ i ] == main.ERROR:
+                    getResults = main.FALSE
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=getResults,
+                                     onpass="Set elements are correct",
+                                     onfail="Set elements are incorrect" )
+
+            main.step( "Distributed Set size" )
+            sizeResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestSize,
+                                 name="setTestSize-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                sizeResponses.append( t.result )
+
+            sizeResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if size != sizeResponses[ i ]:
+                    sizeResults = main.FALSE
+                    main.log.error( "ONOS" + node +
+                                    " expected a size of " + str( size ) +
+                                    " for set " + main.onosSetName +
+                                    " but got " + str( sizeResponses[ i ] ) )
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=sizeResults,
+                                     onpass="Set sizes are correct",
+                                     onfail="Set sizes are incorrect" )
+
+            main.step( "Distributed Set add()" )
+            main.onosSet.add( addValue )
+            addResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestAdd,
+                                 name="setTestAdd-" + str( i ),
+                                 args=[ main.onosSetName, addValue ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                addResponses.append( t.result )
+
+            # main.TRUE = successfully changed the set
+            # main.FALSE = action resulted in no change in set
+            # main.ERROR - Some error in executing the function
+            addResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                if addResponses[ i ] == main.TRUE:
+                    # All is well
+                    pass
+                elif addResponses[ i ] == main.FALSE:
+                    # Already in set, probably fine
+                    pass
+                elif addResponses[ i ] == main.ERROR:
+                    # Error in execution
+                    addResults = main.FALSE
+                else:
+                    # unexpected result
+                    addResults = main.FALSE
+            if addResults != main.TRUE:
+                main.log.error( "Error executing set add" )
+
+            # Check if set is still correct
+            size = len( main.onosSet )
+            getResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestGet,
+                                 name="setTestGet-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                getResponses.append( t.result )
+            getResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if isinstance( getResponses[ i ], list):
+                    current = set( getResponses[ i ] )
+                    if len( current ) == len( getResponses[ i ] ):
+                        # no repeats
+                        if main.onosSet != current:
+                            main.log.error( "ONOS" + node + " has incorrect view" +
+                                            " of set " + main.onosSetName + ":\n" +
+                                            str( getResponses[ i ] ) )
+                            main.log.debug( "Expected: " + str( main.onosSet ) )
+                            main.log.debug( "Actual: " + str( current ) )
+                            getResults = main.FALSE
+                    else:
+                        # error, set is not a set
+                        main.log.error( "ONOS" + node + " has repeat elements in" +
+                                        " set " + main.onosSetName + ":\n" +
+                                        str( getResponses[ i ] ) )
+                        getResults = main.FALSE
+                elif getResponses[ i ] == main.ERROR:
+                    getResults = main.FALSE
+            sizeResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestSize,
+                                 name="setTestSize-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                sizeResponses.append( t.result )
+            sizeResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if size != sizeResponses[ i ]:
+                    sizeResults = main.FALSE
+                    main.log.error( "ONOS" + node +
+                                    " expected a size of " + str( size ) +
+                                    " for set " + main.onosSetName +
+                                    " but got " + str( sizeResponses[ i ] ) )
+            addResults = addResults and getResults and sizeResults
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=addResults,
+                                     onpass="Set add correct",
+                                     onfail="Set add was incorrect" )
+
+            main.step( "Distributed Set addAll()" )
+            main.onosSet.update( addAllValue.split() )
+            addResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestAdd,
+                                 name="setTestAddAll-" + str( i ),
+                                 args=[ main.onosSetName, addAllValue ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                addResponses.append( t.result )
+
+            # main.TRUE = successfully changed the set
+            # main.FALSE = action resulted in no change in set
+            # main.ERROR - Some error in executing the function
+            addAllResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                if addResponses[ i ] == main.TRUE:
+                    # All is well
+                    pass
+                elif addResponses[ i ] == main.FALSE:
+                    # Already in set, probably fine
+                    pass
+                elif addResponses[ i ] == main.ERROR:
+                    # Error in execution
+                    addAllResults = main.FALSE
+                else:
+                    # unexpected result
+                    addAllResults = main.FALSE
+            if addAllResults != main.TRUE:
+                main.log.error( "Error executing set addAll" )
+
+            # Check if set is still correct
+            size = len( main.onosSet )
+            getResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestGet,
+                                 name="setTestGet-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                getResponses.append( t.result )
+            getResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if isinstance( getResponses[ i ], list):
+                    current = set( getResponses[ i ] )
+                    if len( current ) == len( getResponses[ i ] ):
+                        # no repeats
+                        if main.onosSet != current:
+                            main.log.error( "ONOS" + node +
+                                            " has incorrect view" +
+                                            " of set " + main.onosSetName + ":\n" +
+                                            str( getResponses[ i ] ) )
+                            main.log.debug( "Expected: " + str( main.onosSet ) )
+                            main.log.debug( "Actual: " + str( current ) )
+                            getResults = main.FALSE
+                    else:
+                        # error, set is not a set
+                        main.log.error( "ONOS" + node +
+                                        " has repeat elements in" +
+                                        " set " + main.onosSetName + ":\n" +
+                                        str( getResponses[ i ] ) )
+                        getResults = main.FALSE
+                elif getResponses[ i ] == main.ERROR:
+                    getResults = main.FALSE
+            sizeResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestSize,
+                                 name="setTestSize-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                sizeResponses.append( t.result )
+            sizeResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if size != sizeResponses[ i ]:
+                    sizeResults = main.FALSE
+                    main.log.error( "ONOS" + node +
+                                    " expected a size of " + str( size ) +
+                                    " for set " + main.onosSetName +
+                                    " but got " + str( sizeResponses[ i ] ) )
+            addAllResults = addAllResults and getResults and sizeResults
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=addAllResults,
+                                     onpass="Set addAll correct",
+                                     onfail="Set addAll was incorrect" )
+
+            main.step( "Distributed Set contains()" )
+            containsResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestGet,
+                                 name="setContains-" + str( i ),
+                                 args=[ main.onosSetName ],
+                                 kwargs={ "values": addValue } )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                # NOTE: This is the tuple
+                containsResponses.append( t.result )
+
+            containsResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                if containsResponses[ i ] == main.ERROR:
+                    containsResults = main.FALSE
+                else:
+                    containsResults = containsResults and\
+                                      containsResponses[ i ][ 1 ]
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=containsResults,
+                                     onpass="Set contains is functional",
+                                     onfail="Set contains failed" )
+
+            main.step( "Distributed Set containsAll()" )
+            containsAllResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestGet,
+                                 name="setContainsAll-" + str( i ),
+                                 args=[ main.onosSetName ],
+                                 kwargs={ "values": addAllValue } )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                # NOTE: This is the tuple
+                containsAllResponses.append( t.result )
+
+            containsAllResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                if containsResponses[ i ] == main.ERROR:
+                    containsResults = main.FALSE
+                else:
+                    containsResults = containsResults and\
+                                      containsResponses[ i ][ 1 ]
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=containsAllResults,
+                                     onpass="Set containsAll is functional",
+                                     onfail="Set containsAll failed" )
+
+            main.step( "Distributed Set remove()" )
+            main.onosSet.remove( addValue )
+            removeResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestRemove,
+                                 name="setTestRemove-" + str( i ),
+                                 args=[ main.onosSetName, addValue ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                removeResponses.append( t.result )
+
+            # main.TRUE = successfully changed the set
+            # main.FALSE = action resulted in no change in set
+            # main.ERROR - Some error in executing the function
+            removeResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                if removeResponses[ i ] == main.TRUE:
+                    # All is well
+                    pass
+                elif removeResponses[ i ] == main.FALSE:
+                    # not in set, probably fine
+                    pass
+                elif removeResponses[ i ] == main.ERROR:
+                    # Error in execution
+                    removeResults = main.FALSE
+                else:
+                    # unexpected result
+                    removeResults = main.FALSE
+            if removeResults != main.TRUE:
+                main.log.error( "Error executing set remove" )
+
+            # Check if set is still correct
+            size = len( main.onosSet )
+            getResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestGet,
+                                 name="setTestGet-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                getResponses.append( t.result )
+            getResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if isinstance( getResponses[ i ], list):
+                    current = set( getResponses[ i ] )
+                    if len( current ) == len( getResponses[ i ] ):
+                        # no repeats
+                        if main.onosSet != current:
+                            main.log.error( "ONOS" + node +
+                                            " has incorrect view" +
+                                            " of set " + main.onosSetName + ":\n" +
+                                            str( getResponses[ i ] ) )
+                            main.log.debug( "Expected: " + str( main.onosSet ) )
+                            main.log.debug( "Actual: " + str( current ) )
+                            getResults = main.FALSE
+                    else:
+                        # error, set is not a set
+                        main.log.error( "ONOS" + node +
+                                        " has repeat elements in" +
+                                        " set " + main.onosSetName + ":\n" +
+                                        str( getResponses[ i ] ) )
+                        getResults = main.FALSE
+                elif getResponses[ i ] == main.ERROR:
+                    getResults = main.FALSE
+            sizeResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestSize,
+                                 name="setTestSize-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                sizeResponses.append( t.result )
+            sizeResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if size != sizeResponses[ i ]:
+                    sizeResults = main.FALSE
+                    main.log.error( "ONOS" + node +
+                                    " expected a size of " + str( size ) +
+                                    " for set " + main.onosSetName +
+                                    " but got " + str( sizeResponses[ i ] ) )
+            removeResults = removeResults and getResults and sizeResults
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=removeResults,
+                                     onpass="Set remove correct",
+                                     onfail="Set remove was incorrect" )
+
+            main.step( "Distributed Set removeAll()" )
+            main.onosSet.difference_update( addAllValue.split() )
+            removeAllResponses = []
+            threads = []
+            try:
+                for i in main.activeNodes:
+                    t = main.Thread( target=main.CLIs[i].setTestRemove,
+                                     name="setTestRemoveAll-" + str( i ),
+                                     args=[ main.onosSetName, addAllValue ] )
+                    threads.append( t )
+                    t.start()
+                for t in threads:
+                    t.join()
+                    removeAllResponses.append( t.result )
+            except Exception, e:
+                main.log.exception(e)
+
+            # main.TRUE = successfully changed the set
+            # main.FALSE = action resulted in no change in set
+            # main.ERROR - Some error in executing the function
+            removeAllResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                if removeAllResponses[ i ] == main.TRUE:
+                    # All is well
+                    pass
+                elif removeAllResponses[ i ] == main.FALSE:
+                    # not in set, probably fine
+                    pass
+                elif removeAllResponses[ i ] == main.ERROR:
+                    # Error in execution
+                    removeAllResults = main.FALSE
+                else:
+                    # unexpected result
+                    removeAllResults = main.FALSE
+            if removeAllResults != main.TRUE:
+                main.log.error( "Error executing set removeAll" )
+
+            # Check if set is still correct
+            size = len( main.onosSet )
+            getResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestGet,
+                                 name="setTestGet-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                getResponses.append( t.result )
+            getResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if isinstance( getResponses[ i ], list):
+                    current = set( getResponses[ i ] )
+                    if len( current ) == len( getResponses[ i ] ):
+                        # no repeats
+                        if main.onosSet != current:
+                            main.log.error( "ONOS" + node +
+                                            " has incorrect view" +
+                                            " of set " + main.onosSetName + ":\n" +
+                                            str( getResponses[ i ] ) )
+                            main.log.debug( "Expected: " + str( main.onosSet ) )
+                            main.log.debug( "Actual: " + str( current ) )
+                            getResults = main.FALSE
+                    else:
+                        # error, set is not a set
+                        main.log.error( "ONOS" + node +
+                                        " has repeat elements in" +
+                                        " set " + main.onosSetName + ":\n" +
+                                        str( getResponses[ i ] ) )
+                        getResults = main.FALSE
+                elif getResponses[ i ] == main.ERROR:
+                    getResults = main.FALSE
+            sizeResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestSize,
+                                 name="setTestSize-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                sizeResponses.append( t.result )
+            sizeResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if size != sizeResponses[ i ]:
+                    sizeResults = main.FALSE
+                    main.log.error( "ONOS" + node +
+                                    " expected a size of " + str( size ) +
+                                    " for set " + main.onosSetName +
+                                    " but got " + str( sizeResponses[ i ] ) )
+            removeAllResults = removeAllResults and getResults and sizeResults
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=removeAllResults,
+                                     onpass="Set removeAll correct",
+                                     onfail="Set removeAll was incorrect" )
+
+            main.step( "Distributed Set addAll()" )
+            main.onosSet.update( addAllValue.split() )
+            addResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestAdd,
+                                 name="setTestAddAll-" + str( i ),
+                                 args=[ main.onosSetName, addAllValue ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                addResponses.append( t.result )
+
+            # main.TRUE = successfully changed the set
+            # main.FALSE = action resulted in no change in set
+            # main.ERROR - Some error in executing the function
+            addAllResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                if addResponses[ i ] == main.TRUE:
+                    # All is well
+                    pass
+                elif addResponses[ i ] == main.FALSE:
+                    # Already in set, probably fine
+                    pass
+                elif addResponses[ i ] == main.ERROR:
+                    # Error in execution
+                    addAllResults = main.FALSE
+                else:
+                    # unexpected result
+                    addAllResults = main.FALSE
+            if addAllResults != main.TRUE:
+                main.log.error( "Error executing set addAll" )
+
+            # Check if set is still correct
+            size = len( main.onosSet )
+            getResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestGet,
+                                 name="setTestGet-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                getResponses.append( t.result )
+            getResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if isinstance( getResponses[ i ], list):
+                    current = set( getResponses[ i ] )
+                    if len( current ) == len( getResponses[ i ] ):
+                        # no repeats
+                        if main.onosSet != current:
+                            main.log.error( "ONOS" + node +
+                                            " has incorrect view" +
+                                            " of set " + main.onosSetName + ":\n" +
+                                            str( getResponses[ i ] ) )
+                            main.log.debug( "Expected: " + str( main.onosSet ) )
+                            main.log.debug( "Actual: " + str( current ) )
+                            getResults = main.FALSE
+                    else:
+                        # error, set is not a set
+                        main.log.error( "ONOS" + node +
+                                        " has repeat elements in" +
+                                        " set " + main.onosSetName + ":\n" +
+                                        str( getResponses[ i ] ) )
+                        getResults = main.FALSE
+                elif getResponses[ i ] == main.ERROR:
+                    getResults = main.FALSE
+            sizeResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestSize,
+                                 name="setTestSize-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                sizeResponses.append( t.result )
+            sizeResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if size != sizeResponses[ i ]:
+                    sizeResults = main.FALSE
+                    main.log.error( "ONOS" + node +
+                                    " expected a size of " + str( size ) +
+                                    " for set " + main.onosSetName +
+                                    " but got " + str( sizeResponses[ i ] ) )
+            addAllResults = addAllResults and getResults and sizeResults
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=addAllResults,
+                                     onpass="Set addAll correct",
+                                     onfail="Set addAll was incorrect" )
+
+            main.step( "Distributed Set clear()" )
+            main.onosSet.clear()
+            clearResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestRemove,
+                                 name="setTestClear-" + str( i ),
+                                 args=[ main.onosSetName, " "],  # Values doesn't matter
+                                 kwargs={ "clear": True } )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                clearResponses.append( t.result )
+
+            # main.TRUE = successfully changed the set
+            # main.FALSE = action resulted in no change in set
+            # main.ERROR - Some error in executing the function
+            clearResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                if clearResponses[ i ] == main.TRUE:
+                    # All is well
+                    pass
+                elif clearResponses[ i ] == main.FALSE:
+                    # Nothing set, probably fine
+                    pass
+                elif clearResponses[ i ] == main.ERROR:
+                    # Error in execution
+                    clearResults = main.FALSE
+                else:
+                    # unexpected result
+                    clearResults = main.FALSE
+            if clearResults != main.TRUE:
+                main.log.error( "Error executing set clear" )
+
+            # Check if set is still correct
+            size = len( main.onosSet )
+            getResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestGet,
+                                 name="setTestGet-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                getResponses.append( t.result )
+            getResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if isinstance( getResponses[ i ], list):
+                    current = set( getResponses[ i ] )
+                    if len( current ) == len( getResponses[ i ] ):
+                        # no repeats
+                        if main.onosSet != current:
+                            main.log.error( "ONOS" + node +
+                                            " has incorrect view" +
+                                            " of set " + main.onosSetName + ":\n" +
+                                            str( getResponses[ i ] ) )
+                            main.log.debug( "Expected: " + str( main.onosSet ) )
+                            main.log.debug( "Actual: " + str( current ) )
+                            getResults = main.FALSE
+                    else:
+                        # error, set is not a set
+                        main.log.error( "ONOS" + node +
+                                        " has repeat elements in" +
+                                        " set " + main.onosSetName + ":\n" +
+                                        str( getResponses[ i ] ) )
+                        getResults = main.FALSE
+                elif getResponses[ i ] == main.ERROR:
+                    getResults = main.FALSE
+            sizeResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestSize,
+                                 name="setTestSize-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                sizeResponses.append( t.result )
+            sizeResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if size != sizeResponses[ i ]:
+                    sizeResults = main.FALSE
+                    main.log.error( "ONOS" + node +
+                                    " expected a size of " + str( size ) +
+                                    " for set " + main.onosSetName +
+                                    " but got " + str( sizeResponses[ i ] ) )
+            clearResults = clearResults and getResults and sizeResults
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=clearResults,
+                                     onpass="Set clear correct",
+                                     onfail="Set clear was incorrect" )
+
+            main.step( "Distributed Set addAll()" )
+            main.onosSet.update( addAllValue.split() )
+            addResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestAdd,
+                                 name="setTestAddAll-" + str( i ),
+                                 args=[ main.onosSetName, addAllValue ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                addResponses.append( t.result )
+
+            # main.TRUE = successfully changed the set
+            # main.FALSE = action resulted in no change in set
+            # main.ERROR - Some error in executing the function
+            addAllResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                if addResponses[ i ] == main.TRUE:
+                    # All is well
+                    pass
+                elif addResponses[ i ] == main.FALSE:
+                    # Already in set, probably fine
+                    pass
+                elif addResponses[ i ] == main.ERROR:
+                    # Error in execution
+                    addAllResults = main.FALSE
+                else:
+                    # unexpected result
+                    addAllResults = main.FALSE
+            if addAllResults != main.TRUE:
+                main.log.error( "Error executing set addAll" )
+
+            # Check if set is still correct
+            size = len( main.onosSet )
+            getResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestGet,
+                                 name="setTestGet-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                getResponses.append( t.result )
+            getResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if isinstance( getResponses[ i ], list):
+                    current = set( getResponses[ i ] )
+                    if len( current ) == len( getResponses[ i ] ):
+                        # no repeats
+                        if main.onosSet != current:
+                            main.log.error( "ONOS" + node +
+                                            " has incorrect view" +
+                                            " of set " + main.onosSetName + ":\n" +
+                                            str( getResponses[ i ] ) )
+                            main.log.debug( "Expected: " + str( main.onosSet ) )
+                            main.log.debug( "Actual: " + str( current ) )
+                            getResults = main.FALSE
+                    else:
+                        # error, set is not a set
+                        main.log.error( "ONOS" + node +
+                                        " has repeat elements in" +
+                                        " set " + main.onosSetName + ":\n" +
+                                        str( getResponses[ i ] ) )
+                        getResults = main.FALSE
+                elif getResponses[ i ] == main.ERROR:
+                    getResults = main.FALSE
+            sizeResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestSize,
+                                 name="setTestSize-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                sizeResponses.append( t.result )
+            sizeResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if size != sizeResponses[ i ]:
+                    sizeResults = main.FALSE
+                    main.log.error( "ONOS" + node +
+                                    " expected a size of " + str( size ) +
+                                    " for set " + main.onosSetName +
+                                    " but got " + str( sizeResponses[ i ] ) )
+            addAllResults = addAllResults and getResults and sizeResults
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=addAllResults,
+                                     onpass="Set addAll correct",
+                                     onfail="Set addAll was incorrect" )
+
+            main.step( "Distributed Set retain()" )
+            main.onosSet.intersection_update( retainValue.split() )
+            retainResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestRemove,
+                                 name="setTestRetain-" + str( i ),
+                                 args=[ main.onosSetName, retainValue ],
+                                 kwargs={ "retain": True } )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                retainResponses.append( t.result )
+
+            # main.TRUE = successfully changed the set
+            # main.FALSE = action resulted in no change in set
+            # main.ERROR - Some error in executing the function
+            retainResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                if retainResponses[ i ] == main.TRUE:
+                    # All is well
+                    pass
+                elif retainResponses[ i ] == main.FALSE:
+                    # Already in set, probably fine
+                    pass
+                elif retainResponses[ i ] == main.ERROR:
+                    # Error in execution
+                    retainResults = main.FALSE
+                else:
+                    # unexpected result
+                    retainResults = main.FALSE
+            if retainResults != main.TRUE:
+                main.log.error( "Error executing set retain" )
+
+            # Check if set is still correct
+            size = len( main.onosSet )
+            getResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestGet,
+                                 name="setTestGet-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                getResponses.append( t.result )
+            getResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if isinstance( getResponses[ i ], list):
+                    current = set( getResponses[ i ] )
+                    if len( current ) == len( getResponses[ i ] ):
+                        # no repeats
+                        if main.onosSet != current:
+                            main.log.error( "ONOS" + node +
+                                            " has incorrect view" +
+                                            " of set " + main.onosSetName + ":\n" +
+                                            str( getResponses[ i ] ) )
+                            main.log.debug( "Expected: " + str( main.onosSet ) )
+                            main.log.debug( "Actual: " + str( current ) )
+                            getResults = main.FALSE
+                    else:
+                        # error, set is not a set
+                        main.log.error( "ONOS" + node +
+                                        " has repeat elements in" +
+                                        " set " + main.onosSetName + ":\n" +
+                                        str( getResponses[ i ] ) )
+                        getResults = main.FALSE
+                elif getResponses[ i ] == main.ERROR:
+                    getResults = main.FALSE
+            sizeResponses = []
+            threads = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].setTestSize,
+                                 name="setTestSize-" + str( i ),
+                                 args=[ main.onosSetName ] )
+                threads.append( t )
+                t.start()
+            for t in threads:
+                t.join()
+                sizeResponses.append( t.result )
+            sizeResults = main.TRUE
+            for i in range( len( main.activeNodes ) ):
+                node = str( main.activeNodes[i] + 1 )
+                if size != sizeResponses[ i ]:
+                    sizeResults = main.FALSE
+                    main.log.error( "ONOS" + node + " expected a size of " +
+                                    str( size ) + " for set " + main.onosSetName +
+                                    " but got " + str( sizeResponses[ i ] ) )
+            retainResults = retainResults and getResults and sizeResults
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=retainResults,
+                                     onpass="Set retain correct",
+                                     onfail="Set retain was incorrect" )
+
+            # Transactional maps
+            main.step( "Partitioned Transactional maps put" )
+            tMapValue = "Testing"
+            numKeys = 100
+            putResult = True
+            node = main.activeNodes[0]
+            putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue )
+            if putResponses and len( putResponses ) == 100:
+                for i in putResponses:
+                    if putResponses[ i ][ 'value' ] != tMapValue:
+                        putResult = False
+            else:
+                putResult = False
+            if not putResult:
+                main.log.debug( "Put response values: " + str( putResponses ) )
+            utilities.assert_equals( expect=True,
+                                     actual=putResult,
+                                     onpass="Partitioned Transactional Map put successful",
+                                     onfail="Partitioned Transactional Map put values are incorrect" )
+
+            main.step( "Partitioned Transactional maps get" )
+            # FIXME: is this sleep needed?
+            time.sleep( 5 )
+
+            getCheck = True
+            for n in range( 1, numKeys + 1 ):
+                getResponses = []
+                threads = []
+                valueCheck = True
+                for i in main.activeNodes:
+                    t = main.Thread( target=main.CLIs[i].transactionalMapGet,
+                                     name="TMap-get-" + str( i ),
+                                     args=[ "Key" + str( n ) ] )
+                    threads.append( t )
+                    t.start()
+                for t in threads:
+                    t.join()
+                    getResponses.append( t.result )
+                for node in getResponses:
+                    if node != tMapValue:
+                        valueCheck = False
+                if not valueCheck:
+                    main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
+                    main.log.warn( getResponses )
+                getCheck = getCheck and valueCheck
+            utilities.assert_equals( expect=True,
+                                     actual=getCheck,
+                                     onpass="Partitioned Transactional Map get values were correct",
+                                     onfail="Partitioned Transactional Map values incorrect" )
+
+            # DISTRIBUTED ATOMIC VALUE
+            main.step( "Get the value of a new value" )
+            threads = []
+            getValues = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].valueTestGet,
+                                 name="ValueGet-" + str( i ),
+                                 args=[ valueName ] )
+                threads.append( t )
+                t.start()
+
+            for t in threads:
+                t.join()
+                getValues.append( t.result )
+            main.log.debug( getValues )
+            # Check the results
+            atomicValueGetResult = True
+            expected = valueValue if valueValue is not None else "null"
+            main.log.debug( "Checking for value of " + expected )
+            for i in getValues:
+                if i != expected:
+                    atomicValueGetResult = False
+            utilities.assert_equals( expect=True,
+                                     actual=atomicValueGetResult,
+                                     onpass="Atomic Value get successful",
+                                     onfail="Error getting atomic Value " +
+                                            str( valueValue ) + ", found: " +
+                                            str( getValues ) )
+
+            main.step( "Atomic Value set()" )
+            valueValue = "foo"
+            threads = []
+            setValues = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].valueTestSet,
+                                 name="ValueSet-" + str( i ),
+                                 args=[ valueName, valueValue ] )
+                threads.append( t )
+                t.start()
+
+            for t in threads:
+                t.join()
+                setValues.append( t.result )
+            main.log.debug( setValues )
+            # Check the results
+            atomicValueSetResults = True
+            for i in setValues:
+                if i != main.TRUE:
+                    atomicValueSetResults = False
+            utilities.assert_equals( expect=True,
+                                     actual=atomicValueSetResults,
+                                     onpass="Atomic Value set successful",
+                                     onfail="Error setting atomic Value" +
+                                            str( setValues ) )
+
+            main.step( "Get the value after set()" )
+            threads = []
+            getValues = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].valueTestGet,
+                                 name="ValueGet-" + str( i ),
+                                 args=[ valueName ] )
+                threads.append( t )
+                t.start()
+
+            for t in threads:
+                t.join()
+                getValues.append( t.result )
+            main.log.debug( getValues )
+            # Check the results
+            atomicValueGetResult = True
+            expected = valueValue if valueValue is not None else "null"
+            main.log.debug( "Checking for value of " + expected )
+            for i in getValues:
+                if i != expected:
+                    atomicValueGetResult = False
+            utilities.assert_equals( expect=True,
+                                     actual=atomicValueGetResult,
+                                     onpass="Atomic Value get successful",
+                                     onfail="Error getting atomic Value " +
+                                            str( valueValue ) + ", found: " +
+                                            str( getValues ) )
+
+            main.step( "Atomic Value compareAndSet()" )
+            oldValue = valueValue
+            valueValue = "bar"
+            i = main.activeNodes[0]
+            CASValue = main.CLIs[i].valueTestCompareAndSet( valueName, oldValue, valueValue )
+            main.log.debug( CASValue )
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=CASValue,
+                                     onpass="Atomic Value comapreAndSet successful",
+                                     onfail="Error setting atomic Value:" +
+                                            str( CASValue ) )
+
+            main.step( "Get the value after compareAndSet()" )
+            threads = []
+            getValues = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].valueTestGet,
+                                 name="ValueGet-" + str( i ),
+                                 args=[ valueName ] )
+                threads.append( t )
+                t.start()
+
+            for t in threads:
+                t.join()
+                getValues.append( t.result )
+            main.log.debug( getValues )
+            # Check the results
+            atomicValueGetResult = True
+            expected = valueValue if valueValue is not None else "null"
+            main.log.debug( "Checking for value of " + expected )
+            for i in getValues:
+                if i != expected:
+                    atomicValueGetResult = False
+            utilities.assert_equals( expect=True,
+                                     actual=atomicValueGetResult,
+                                     onpass="Atomic Value get successful",
+                                     onfail="Error getting atomic Value " +
+                                            str( valueValue ) + ", found: " +
+                                            str( getValues ) )
+
+            main.step( "Atomic Value getAndSet()" )
+            oldValue = valueValue
+            valueValue = "baz"
+            i = main.activeNodes[0]
+            GASValue = main.CLIs[i].valueTestGetAndSet( valueName, valueValue )
+            main.log.debug( GASValue )
+            expected = oldValue if oldValue is not None else "null"
+            utilities.assert_equals( expect=expected,
+                                     actual=GASValue,
+                                     onpass="Atomic Value GAS successful",
+                                     onfail="Error with GetAndSet atomic Value: expected " +
+                                            str( expected ) + ", found: " +
+                                            str( GASValue ) )
+
+            main.step( "Get the value after getAndSet()" )
+            threads = []
+            getValues = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].valueTestGet,
+                                 name="ValueGet-" + str( i ),
+                                 args=[ valueName ] )
+                threads.append( t )
+                t.start()
+
+            for t in threads:
+                t.join()
+                getValues.append( t.result )
+            main.log.debug( getValues )
+            # Check the results
+            atomicValueGetResult = True
+            expected = valueValue if valueValue is not None else "null"
+            main.log.debug( "Checking for value of " + expected )
+            for i in getValues:
+                if i != expected:
+                    atomicValueGetResult = False
+            utilities.assert_equals( expect=True,
+                                     actual=atomicValueGetResult,
+                                     onpass="Atomic Value get successful",
+                                     onfail="Error getting atomic Value: expected " +
+                                            str( valueValue ) + ", found: " +
+                                            str( getValues ) )
+
+            main.step( "Atomic Value destory()" )
+            valueValue = None
+            threads = []
+            i = main.activeNodes[0]
+            destroyResult = main.CLIs[i].valueTestDestroy( valueName )
+            main.log.debug( destroyResult )
+            # Check the results
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=destroyResult,
+                                     onpass="Atomic Value destroy successful",
+                                     onfail="Error destroying atomic Value" )
+
+            main.step( "Get the value after destroy()" )
+            threads = []
+            getValues = []
+            for i in main.activeNodes:
+                t = main.Thread( target=main.CLIs[i].valueTestGet,
+                                 name="ValueGet-" + str( i ),
+                                 args=[ valueName ] )
+                threads.append( t )
+                t.start()
+
+            for t in threads:
+                t.join()
+                getValues.append( t.result )
+            main.log.debug( getValues )
+            # Check the results
+            atomicValueGetResult = True
+            expected = valueValue if valueValue is not None else "null"
+            main.log.debug( "Checking for value of " + expected )
+            for i in getValues:
+                if i != expected:
+                    atomicValueGetResult = False
+            utilities.assert_equals( expect=True,
+                                     actual=atomicValueGetResult,
+                                     onpass="Atomic Value get successful",
+                                     onfail="Error getting atomic Value " +
+                                            str( valueValue ) + ", found: " +
+                                            str( getValues ) )
+        except Exception as e:
+            main.log.error( "Exception: " + str( e ) )
