blob: 21308c2231d9b78b181ab234eae809a40d64522a [file] [log] [blame]
Jon Halle1a3b752015-07-22 13:02:46 -07001def __init__( self ):
2 self.default = ''
3
4def counterCheck( counterName, counterValue ):
5 """
6 Add Text here
7 """
8 import json
9 correctResults = main.TRUE
10 # Get onos counters results
11 onosCounters = []
12 threads = []
13 for i in range( main.numCtrls ):
14 t = main.Thread( target=main.CLIs[i].counters,
15 name="counters-" + str( i ) )
16 threads.append( t )
17 t.start()
18 for t in threads:
19 t.join()
20 onosCounters.append( t.result )
21 tmp = [ i == onosCounters[ 0 ] for i in onosCounters ]
22 if all( tmp ):
23 consistent = main.TRUE
24 else:
25 consistent = main.FALSE
26 main.log.error( "ONOS nodes have different values for counters" )
27 for node in onosCounters:
28 main.log.debug( node )
29
30 # Check for correct values
31 for i in range( main.numCtrls ):
32 try:
33 current = json.loads( onosCounters[i] )
34 except ( ValueError, TypeError ):
35 main.log.error( "Could not parse counters response from ONOS" +
36 str( i + 1 ) )
37 main.log.warn( repr( onosCounters[ i ] ) )
Jon Hall2c3a8d72015-09-11 10:46:24 -070038 return main.FALSE
Jon Halle1a3b752015-07-22 13:02:46 -070039 onosValue = None
40 try:
41 for database in current:
42 database = database.values()[0]
43 for counter in database:
44 if counter.get( 'name' ) == counterName:
45 onosValue = counter.get( 'value' )
46 break
47 except AttributeError, e:
48 main.log.error( "ONOS" + str( i + 1 ) + " counters result " +
49 "is not as expected" )
50 correctResults = main.FALSE
51 if onosValue == counterValue:
52 main.log.info( counterName + " counter value is correct" )
53 else:
54 main.log.error( counterName + " counter value is incorrect," +
55 " expected value: " + str( counterValue )
56 + " current value: " + str( onosValue ) )
57 correctResults = main.FALSE
58 return consistent and correctResults