Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pbh]: Fix show PBH counters when cache is partial #3356

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion show/plugins/pbh.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions tests/pbh_input/assert_show_output.py
Original file line number Diff line number Diff line change
@@ -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
---------- ------ ------------------ ----------------
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
@@ -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')