Skip to content

Commit

Permalink
[show priority-group drop counters] Add user info output when user wa…
Browse files Browse the repository at this point in the history
…nt to check PG counters and polling are disabled (sonic-net#1678)

Signed-off-by: Andriy Yurkiv <ayurkiv@nvidia.com>

What I did
Added additional output info for user when trying to show priority group counters and pg drop counters are disabled

How I did it
modify pg-drop script, add additional print during executing "show priority-group drop counters" if PG polling disabled

How to verify it
counterpoll pg-drop disable
show priority-group drop counters

Expect:
Warning: PG counters are disabled. Current stats may be outdated. Use 'counterpoll pg-drop enable' to enable'

Previous command output (if the output of a command-line utility has changed)
admin@r-tigon-04:/usr/local/bin$ show priority-group drop counters
Ingress PG dropped packets:
       Port    PG0    PG1    PG2    PG3    PG4    PG5    PG6    PG7
-----------  -----  -----  -----  -----  -----  -----  -----  -----
  Ethernet0      0      0      0      0      0      0      0      0
  Ethernet2      0      0      0      0      0      0      0      0
  Ethernet8      0      0      0      0      0      0      0      0
 Ethernet10      0      0      0      0      0      0      0      0
 Ethernet16      0      0      0      0      0      0      0      0

New command output (if the output of a command-line utility has changed)
admin@r-tigon-04:/usr/local/bin$ show priority-group drop counters
Warning: PG counters are disabled. Use 'counterpoll pg-drop enable' to enable polling
  • Loading branch information
ayurkiv-nvda authored Aug 11, 2021
1 parent 920bb87 commit 4175cb9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
14 changes: 13 additions & 1 deletion scripts/pg-drop
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ try:
except KeyError:
pass

from swsscommon.swsscommon import SonicV2Connector
from swsscommon.swsscommon import ConfigDBConnector, SonicV2Connector

STATUS_NA = 'N/A'

Expand All @@ -47,6 +47,9 @@ class PgDropStat(object):
self.counters_db = SonicV2Connector(host='127.0.0.1')
self.counters_db.connect(self.counters_db.COUNTERS_DB)

self.configdb = ConfigDBConnector()
self.configdb.connect()

dropstat_dir = get_dropstat_dir()
self.port_drop_stats_file = os.path.join(dropstat_dir, 'pg_drop_stats')

Expand Down Expand Up @@ -212,6 +215,14 @@ class PgDropStat(object):
sys.exit(e.errno)
print("Cleared PG drop counter")

def check_if_stats_enabled(self):
pg_drop_info = self.configdb.get_entry('FLEX_COUNTER_TABLE', 'PG_DROP')
if pg_drop_info:
status = pg_drop_info.get("FLEX_COUNTER_STATUS", 'disable')
if status == "disable":
print("Warning: PG counters are disabled. Use 'counterpoll pg-drop enable' to enable polling")
sys.exit(0)

def main():
parser = argparse.ArgumentParser(description='Display PG drop counter',
formatter_class=argparse.RawTextHelpFormatter,
Expand Down Expand Up @@ -240,6 +251,7 @@ pg-drop -c clear
if command == 'clear':
pgdropstat.clear_drop_counts()
elif command == 'show':
pgdropstat.check_if_stats_enabled()
pgdropstat.print_all_stat(COUNTER_TABLE_PREFIX, "pg_drop" )
else:
print("Command not recognized")
Expand Down
26 changes: 26 additions & 0 deletions tests/pgdrop_input/config_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"FLEX_COUNTER_TABLE|QUEUE": {
"POLL_INTERVAL": "10000",
"FLEX_COUNTER_STATUS": "enable"
},
"FLEX_COUNTER_TABLE|PORT": {
"POLL_INTERVAL": "1000",
"FLEX_COUNTER_STATUS": "enable"
},
"FLEX_COUNTER_TABLE|PORT_BUFFER_DROP": {
"POLL_INTERVAL": "60000",
"FLEX_COUNTER_STATUS": "enable"
},
"FLEX_COUNTER_TABLE|QUEUE_WATERMARK": {
"POLL_INTERVAL": "10000",
"FLEX_COUNTER_STATUS": "enable"
},
"FLEX_COUNTER_TABLE|PG_WATERMARK": {
"POLL_INTERVAL": "10000",
"FLEX_COUNTER_STATUS": "enable"
},
"FLEX_COUNTER_TABLE|PG_DROP": {
"POLL_INTERVAL": "10000",
"FLEX_COUNTER_STATUS": "disable"
}
}
25 changes: 25 additions & 0 deletions tests/pgdropstat_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
import sys
import pytest

import show.main as show
import clear.main as clear
import config.main as config

from click.testing import CliRunner
from shutil import copyfile

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
Expand Down Expand Up @@ -39,6 +41,29 @@ def setup_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "2"
print("SETUP")

@pytest.fixture(scope='function')
def replace_config_db_file(self):
sample_config_db_file = os.path.join(test_path, "pgdrop_input", "config_db.json")
mock_config_db_file = os.path.join(test_path, "mock_tables", "config_db.json")

#Backup origin config_db and replace it with config_db file with disabled PG_DROP counters
copyfile(mock_config_db_file, "/tmp/config_db.json")
copyfile(sample_config_db_file, mock_config_db_file)

yield

copyfile("/tmp/config_db.json", mock_config_db_file)

def test_show_pg_drop_disabled(self, replace_config_db_file):
runner = CliRunner()

result = runner.invoke(show.cli.commands["priority-group"].commands["drop"].commands["counters"])
assert result.exit_code == 0
print(result.exit_code)

assert result.output == "Warning: PG counters are disabled. Use 'counterpoll pg-drop enable' to enable polling\n"
print(result.output)

def test_show_pg_drop_show(self):
self.executor(clear_before_show = False)

Expand Down

0 comments on commit 4175cb9

Please sign in to comment.