blob: 7abd73a251b6912b0408ff9b8facb029ee60fbd0 [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 ] ) )
38 onosValue = None
39 try:
40 for database in current:
41 database = database.values()[0]
42 for counter in database:
43 if counter.get( 'name' ) == counterName:
44 onosValue = counter.get( 'value' )
45 break
46 except AttributeError, e:
47 main.log.error( "ONOS" + str( i + 1 ) + " counters result " +
48 "is not as expected" )
49 correctResults = main.FALSE
50 if onosValue == counterValue:
51 main.log.info( counterName + " counter value is correct" )
52 else:
53 main.log.error( counterName + " counter value is incorrect," +
54 " expected value: " + str( counterValue )
55 + " current value: " + str( onosValue ) )
56 correctResults = main.FALSE
57 return consistent and correctResults