Skip to content

Commit 667a150

Browse files
authored
[pbh]: Fix show PBH counters when cache is partial (sonic-net#3356)
* [pbh]: Fix show PBH counters when cache is partial. Signed-off-by: Nazarii Hnydyn <[email protected]>
1 parent 0e6a55e commit 667a150

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

show/plugins/pbh.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def get_counter_value(pbh_counters, saved_pbh_counters, key, type):
395395
if not pbh_counters[key]:
396396
return '0'
397397

398-
if key in saved_pbh_counters:
398+
if key in saved_pbh_counters and saved_pbh_counters[key]:
399399
new_value = int(pbh_counters[key][type]) - int(saved_pbh_counters[key][type])
400400
if new_value >= 0:
401401
return str(new_value)

tests/pbh_input/assert_show_output.py

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@
7878
"""
7979

8080

81+
show_pbh_statistics_partial = """\
82+
TABLE RULE RX PACKETS COUNT RX BYTES COUNT
83+
---------- ------ ------------------ ----------------
84+
pbh_table1 nvgre 100 200
85+
pbh_table2 vxlan 0 0
86+
"""
87+
88+
8189
show_pbh_statistics_updated="""\
8290
TABLE RULE RX PACKETS COUNT RX BYTES COUNT
8391
---------- ------ ------------------ ----------------
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"COUNTERS:oid:0x9000000000000": { },
3+
"COUNTERS:oid:0x9000000000001": {
4+
"SAI_ACL_COUNTER_ATTR_PACKETS": "300",
5+
"SAI_ACL_COUNTER_ATTR_BYTES": "400"
6+
},
7+
"ACL_COUNTER_RULE_MAP": {
8+
"pbh_table1:nvgre": "oid:0x9000000000000",
9+
"pbh_table2:vxlan": "oid:0x9000000000001"
10+
}
11+
}

tests/pbh_test.py

+28
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,34 @@ def test_show_pbh_statistics_after_clear(self):
946946
assert result.exit_code == SUCCESS
947947
assert result.output == assert_show_output.show_pbh_statistics_zero
948948

949+
def test_show_pbh_statistics_after_clear_and_counters_partial(self):
950+
dbconnector.dedicated_dbs['COUNTERS_DB'] = os.path.join(mock_db_path, 'counters_db_partial')
951+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'full_pbh_config')
952+
953+
self.remove_pbh_counters_file()
954+
955+
db = Db()
956+
runner = CliRunner()
957+
958+
result = runner.invoke(
959+
clear.cli.commands["pbh"].
960+
commands["statistics"], [], obj=db
961+
)
962+
963+
logger.debug("\n" + result.output)
964+
logger.debug(result.exit_code)
965+
966+
dbconnector.dedicated_dbs['COUNTERS_DB'] = os.path.join(mock_db_path, 'counters_db')
967+
968+
result = runner.invoke(
969+
show.cli.commands["pbh"].
970+
commands["statistics"], [], obj=db
971+
)
972+
973+
logger.debug("\n" + result.output)
974+
logger.debug(result.exit_code)
975+
assert result.exit_code == SUCCESS
976+
assert result.output == assert_show_output.show_pbh_statistics_partial
949977

950978
def test_show_pbh_statistics_after_clear_and_counters_updated(self):
951979
dbconnector.dedicated_dbs['COUNTERS_DB'] = os.path.join(mock_db_path, 'counters_db')

0 commit comments

Comments
 (0)