Skip to content

Commit

Permalink
[pbh]: Fix show PBH counters when cache is partial (#3356)
Browse files Browse the repository at this point in the history
* [pbh]: Fix show PBH counters when cache is partial.

Signed-off-by: Nazarii Hnydyn <[email protected]>
  • Loading branch information
nazariig authored Jun 27, 2024
1 parent 0e6a55e commit 667a150
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion show/plugins/pbh.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def get_counter_value(pbh_counters, saved_pbh_counters, key, type):
if not pbh_counters[key]:
return '0'

if key in saved_pbh_counters:
if key in saved_pbh_counters and saved_pbh_counters[key]:
new_value = int(pbh_counters[key][type]) - int(saved_pbh_counters[key][type])
if new_value >= 0:
return str(new_value)
Expand Down
8 changes: 8 additions & 0 deletions tests/pbh_input/assert_show_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
"""


show_pbh_statistics_partial = """\
TABLE RULE RX PACKETS COUNT RX BYTES COUNT
---------- ------ ------------------ ----------------
pbh_table1 nvgre 100 200
pbh_table2 vxlan 0 0
"""


show_pbh_statistics_updated="""\
TABLE RULE RX PACKETS COUNT RX BYTES COUNT
---------- ------ ------------------ ----------------
Expand Down
11 changes: 11 additions & 0 deletions tests/pbh_input/counters_db_partial.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"COUNTERS:oid:0x9000000000000": { },
"COUNTERS:oid:0x9000000000001": {
"SAI_ACL_COUNTER_ATTR_PACKETS": "300",
"SAI_ACL_COUNTER_ATTR_BYTES": "400"
},
"ACL_COUNTER_RULE_MAP": {
"pbh_table1:nvgre": "oid:0x9000000000000",
"pbh_table2:vxlan": "oid:0x9000000000001"
}
}
28 changes: 28 additions & 0 deletions tests/pbh_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,34 @@ def test_show_pbh_statistics_after_clear(self):
assert result.exit_code == SUCCESS
assert result.output == assert_show_output.show_pbh_statistics_zero

def test_show_pbh_statistics_after_clear_and_counters_partial(self):
dbconnector.dedicated_dbs['COUNTERS_DB'] = os.path.join(mock_db_path, 'counters_db_partial')
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'full_pbh_config')

self.remove_pbh_counters_file()

db = Db()
runner = CliRunner()

result = runner.invoke(
clear.cli.commands["pbh"].
commands["statistics"], [], obj=db
)

logger.debug("\n" + result.output)
logger.debug(result.exit_code)

dbconnector.dedicated_dbs['COUNTERS_DB'] = os.path.join(mock_db_path, 'counters_db')

result = runner.invoke(
show.cli.commands["pbh"].
commands["statistics"], [], obj=db
)

logger.debug("\n" + result.output)
logger.debug(result.exit_code)
assert result.exit_code == SUCCESS
assert result.output == assert_show_output.show_pbh_statistics_partial

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

0 comments on commit 667a150

Please sign in to comment.