Add HA testcases for new counter methods
Minor refactoring to allow a library file to be used
Change-Id: Ic634dfe26bf46d618dc703fa6fa8b5d234997dcf
diff --git a/TestON/tests/HAsanity/dependencies/Counters.py b/TestON/tests/HAsanity/dependencies/Counters.py
new file mode 100644
index 0000000..7abd73a
--- /dev/null
+++ b/TestON/tests/HAsanity/dependencies/Counters.py
@@ -0,0 +1,57 @@
+def __init__( self ):
+ self.default = ''
+
+def counterCheck( counterName, counterValue ):
+ """
+ Add Text here
+ """
+ import json
+ correctResults = main.TRUE
+ # Get onos counters results
+ onosCounters = []
+ threads = []
+ for i in range( main.numCtrls ):
+ t = main.Thread( target=main.CLIs[i].counters,
+ name="counters-" + str( i ) )
+ threads.append( t )
+ t.start()
+ for t in threads:
+ t.join()
+ onosCounters.append( t.result )
+ tmp = [ i == onosCounters[ 0 ] for i in onosCounters ]
+ if all( tmp ):
+ consistent = main.TRUE
+ else:
+ consistent = main.FALSE
+ main.log.error( "ONOS nodes have different values for counters" )
+ for node in onosCounters:
+ main.log.debug( node )
+
+ # Check for correct values
+ for i in range( main.numCtrls ):
+ try:
+ current = json.loads( onosCounters[i] )
+ except ( ValueError, TypeError ):
+ main.log.error( "Could not parse counters response from ONOS" +
+ str( i + 1 ) )
+ main.log.warn( repr( onosCounters[ i ] ) )
+ onosValue = None
+ try:
+ for database in current:
+ database = database.values()[0]
+ for counter in database:
+ if counter.get( 'name' ) == counterName:
+ onosValue = counter.get( 'value' )
+ break
+ except AttributeError, e:
+ main.log.error( "ONOS" + str( i + 1 ) + " counters result " +
+ "is not as expected" )
+ correctResults = main.FALSE
+ if onosValue == counterValue:
+ main.log.info( counterName + " counter value is correct" )
+ else:
+ main.log.error( counterName + " counter value is incorrect," +
+ " expected value: " + str( counterValue )
+ + " current value: " + str( onosValue ) )
+ correctResults = main.FALSE
+ return consistent and correctResults