Skip to content

Commit 84fe4da

Browse files
committed
[pg drop counters] Remove backup with cached PG drop counters after 'config reload', add user info when polling disabled
Signed-off-by: Andriy Yurkiv <[email protected]>
1 parent 58e7e87 commit 84fe4da

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

config/main.py

+5
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,11 @@ def reload(filename, yes, load_sysinfo, no_service_restart):
824824
if multi_asic.is_multi_asic():
825825
num_cfg_file += num_asic
826826

827+
# Remove cached PG drop counters data
828+
dropstat_dir_prefix = '/tmp/dropstat'
829+
command = "rm -rf {}-*".format(dropstat_dir_prefix)
830+
run_command(command, display_cmd=True)
831+
827832
# If the user give the filename[s], extract the file names.
828833
if filename is not None:
829834
cfg_files = filename.split(',')

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 swsssdk import SonicV2Connector
29+
from swsssdk import SonicV2Connector,ConfigDBConnector
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"

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
'mock_tables/asic0/*',
6666
'mock_tables/asic1/*',
6767
'mock_tables/asic2/*',
68+
'mock_tables/pgdrop_input/*',
6869
'bgp_commands_input/*',
6970
'filter_fdb_input/*',
7071
'pfcwd_input/*',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}
27+

sonic-utilities-tests/pgdropstat_test.py

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

45
import show.main as show
56
import clear.main as clear
7+
import config.main as config
68

79
from click.testing import CliRunner
10+
from shutil import copyfile
811

912
test_path = os.path.dirname(os.path.abspath(__file__))
1013
modules_path = os.path.dirname(test_path)
@@ -38,6 +41,29 @@ def setup_class(cls):
3841
os.environ['UTILITIES_UNIT_TESTING'] = "2"
3942
print("SETUP")
4043

44+
@pytest.fixture(scope='function')
45+
def replace_config_db_file(self):
46+
sample_config_db_file = os.path.join(test_path, "mock_tables/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+
4167
def test_show_pg_drop_show(self):
4268
self.executor(clear_before_show = False)
4369

0 commit comments

Comments
 (0)