Skip to content

Commit 4175cb9

Browse files
authored
[show priority-group drop counters] Add user info output when user want to check PG counters and polling are disabled (#1678)
Signed-off-by: Andriy Yurkiv <[email protected]> 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
1 parent 920bb87 commit 4175cb9

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

scripts/pg-drop

+13-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ try:
2626
except KeyError:
2727
pass
2828

29-
from swsscommon.swsscommon import SonicV2Connector
29+
from swsscommon.swsscommon import ConfigDBConnector, SonicV2Connector
3030

3131
STATUS_NA = 'N/A'
3232

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

50+
self.configdb = ConfigDBConnector()
51+
self.configdb.connect()
52+
5053
dropstat_dir = get_dropstat_dir()
5154
self.port_drop_stats_file = os.path.join(dropstat_dir, 'pg_drop_stats')
5255

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

218+
def check_if_stats_enabled(self):
219+
pg_drop_info = self.configdb.get_entry('FLEX_COUNTER_TABLE', 'PG_DROP')
220+
if pg_drop_info:
221+
status = pg_drop_info.get("FLEX_COUNTER_STATUS", 'disable')
222+
if status == "disable":
223+
print("Warning: PG counters are disabled. Use 'counterpoll pg-drop enable' to enable polling")
224+
sys.exit(0)
225+
215226
def main():
216227
parser = argparse.ArgumentParser(description='Display PG drop counter',
217228
formatter_class=argparse.RawTextHelpFormatter,
@@ -240,6 +251,7 @@ pg-drop -c clear
240251
if command == 'clear':
241252
pgdropstat.clear_drop_counts()
242253
elif command == 'show':
254+
pgdropstat.check_if_stats_enabled()
243255
pgdropstat.print_all_stat(COUNTER_TABLE_PREFIX, "pg_drop" )
244256
else:
245257
print("Command not recognized")

tests/pgdrop_input/config_db.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"FLEX_COUNTER_TABLE|QUEUE": {
3+
"POLL_INTERVAL": "10000",
4+
"FLEX_COUNTER_STATUS": "enable"
5+
},
6+
"FLEX_COUNTER_TABLE|PORT": {
7+
"POLL_INTERVAL": "1000",
8+
"FLEX_COUNTER_STATUS": "enable"
9+
},
10+
"FLEX_COUNTER_TABLE|PORT_BUFFER_DROP": {
11+
"POLL_INTERVAL": "60000",
12+
"FLEX_COUNTER_STATUS": "enable"
13+
},
14+
"FLEX_COUNTER_TABLE|QUEUE_WATERMARK": {
15+
"POLL_INTERVAL": "10000",
16+
"FLEX_COUNTER_STATUS": "enable"
17+
},
18+
"FLEX_COUNTER_TABLE|PG_WATERMARK": {
19+
"POLL_INTERVAL": "10000",
20+
"FLEX_COUNTER_STATUS": "enable"
21+
},
22+
"FLEX_COUNTER_TABLE|PG_DROP": {
23+
"POLL_INTERVAL": "10000",
24+
"FLEX_COUNTER_STATUS": "disable"
25+
}
26+
}

tests/pgdropstat_test.py

+25
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import os
22
import sys
3+
import pytest
34

45
import show.main as show
56
import clear.main as clear
67
import config.main as config
78

89
from click.testing import CliRunner
10+
from shutil import copyfile
911

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

44+
@pytest.fixture(scope='function')
45+
def replace_config_db_file(self):
46+
sample_config_db_file = os.path.join(test_path, "pgdrop_input", "config_db.json")
47+
mock_config_db_file = os.path.join(test_path, "mock_tables", "config_db.json")
48+
49+
#Backup origin config_db and replace it with config_db file with disabled PG_DROP counters
50+
copyfile(mock_config_db_file, "/tmp/config_db.json")
51+
copyfile(sample_config_db_file, mock_config_db_file)
52+
53+
yield
54+
55+
copyfile("/tmp/config_db.json", mock_config_db_file)
56+
57+
def test_show_pg_drop_disabled(self, replace_config_db_file):
58+
runner = CliRunner()
59+
60+
result = runner.invoke(show.cli.commands["priority-group"].commands["drop"].commands["counters"])
61+
assert result.exit_code == 0
62+
print(result.exit_code)
63+
64+
assert result.output == "Warning: PG counters are disabled. Use 'counterpoll pg-drop enable' to enable polling\n"
65+
print(result.output)
66+
4267
def test_show_pg_drop_show(self):
4368
self.executor(clear_before_show = False)
4469

0 commit comments

Comments
 (0)