diff --git a/scripts/flow_counters_stat b/scripts/flow_counters_stat index 0c2ec80575d9..8901d92f6627 100755 --- a/scripts/flow_counters_stat +++ b/scripts/flow_counters_stat @@ -230,7 +230,7 @@ class FlowCounterStats(object): # counter OID is changed. old_values[-1] = values[-1] for i in diff_column_positions: - old_values[i] = 0 + old_values[i] = '0' values[i] = ns_diff(values[i], old_values[i]) need_update_cache = True continue @@ -238,13 +238,13 @@ class FlowCounterStats(object): has_negative_diff = False for i in diff_column_positions: # If any diff has negative value, set all counter values to 0 and update cache - if values[i] < old_values[i]: + if int(values[i]) < int(old_values[i]): has_negative_diff = True break if has_negative_diff: for i in diff_column_positions: - old_values[i] = 0 + old_values[i] = '0' values[i] = ns_diff(values[i], old_values[i]) need_update_cache = True continue diff --git a/tests/flow_counter_stats_test.py b/tests/flow_counter_stats_test.py index 61c938a06350..807ed6122332 100644 --- a/tests/flow_counter_stats_test.py +++ b/tests/flow_counter_stats_test.py @@ -132,25 +132,25 @@ def test_diff(self): stats._collect = mock.MagicMock() old_data = { '': { - 'bgp': [100, 200, 50.0, 1], - 'bgpv6': [100, 200, 50.0, 2], - 'lldp': [100, 200, 50.0, 3], + 'bgp': ['100', '200', '50.0', '1'], + 'bgpv6': ['100', '200', '50.0', '2'], + 'lldp': ['100', '200', '50.0', '3'], } } stats._save(old_data) stats.data = { '': { - 'bgp': [100, 200, 50.0, 4], - 'bgpv6': [100, 100, 50.0, 2], - 'lldp': [200, 300, 50.0, 3], + 'bgp': ['100', '200', '50.0', '4'], + 'bgpv6': ['100', '100', '50.0', '2'], + 'lldp': ['200', '300', '50.0', '3'], } } stats._collect_and_diff() cached_data = stats._load() - assert cached_data['']['bgp'] == [0, 0, 50.0, 4] - assert cached_data['']['bgpv6'] == [0, 0, 50.0, 2] - assert cached_data['']['lldp'] == [100, 200, 50.0, 3] + assert cached_data['']['bgp'] == ['0', '0', '50.0', '4'] + assert cached_data['']['bgpv6'] == ['0', '0', '50.0', '2'] + assert cached_data['']['lldp'] == ['100', '200', '50.0', '3'] class TestTrapStatsMultiAsic: