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

[show priority-group drop counters] Add user info output when user want to check PG counters and polling are disabled #1678

Merged
merged 2 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
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
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,10 +1,12 @@
import os
import sys
import pytest

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

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 +40,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