Skip to content

Commit

Permalink
[pg drop counters] Remove backup with cached PG drop counters after '…
Browse files Browse the repository at this point in the history
…config reload', add user info when polling disabled

Signed-off-by: Andriy Yurkiv <ayurkiv@nvidia.com>
  • Loading branch information
ayurkiv-nvda committed May 25, 2022
1 parent 58e7e87 commit 84fe4da
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
5 changes: 5 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,11 @@ def reload(filename, yes, load_sysinfo, no_service_restart):
if multi_asic.is_multi_asic():
num_cfg_file += num_asic

# Remove cached PG drop counters data
dropstat_dir_prefix = '/tmp/dropstat'
command = "rm -rf {}-*".format(dropstat_dir_prefix)
run_command(command, display_cmd=True)

# If the user give the filename[s], extract the file names.
if filename is not None:
cfg_files = filename.split(',')
Expand Down
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 swsssdk import SonicV2Connector
from swsssdk import SonicV2Connector,ConfigDBConnector

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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
'mock_tables/asic0/*',
'mock_tables/asic1/*',
'mock_tables/asic2/*',
'mock_tables/pgdrop_input/*',
'bgp_commands_input/*',
'filter_fdb_input/*',
'pfcwd_input/*',
Expand Down
27 changes: 27 additions & 0 deletions sonic-utilities-tests/mock_tables/pgdrop_input/config_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"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"
}
}

26 changes: 26 additions & 0 deletions sonic-utilities-tests/pgdropstat_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +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 @@ -38,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, "mock_tables/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 84fe4da

Please sign in to comment.