Skip to content

Commit

Permalink
[show priority-group drop counters] Do not show table when PG counter…
Browse files Browse the repository at this point in the history
…s disabled & add Unit test
  • Loading branch information
ayurkiv authored and ayurkiv-nvda committed Jul 15, 2021
1 parent 1c2f21d commit 3b772ae
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion scripts/pg-drop
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ class PgDropStat(object):
if pg_drop_info:
status = pg_drop_info.get("FLEX_COUNTER_STATUS", 'disable')
if status == "disable":
print("Warning: PG counters are disabled. Current stats may be outdated. Use 'counterpoll pg-drop enable' to enable polling")
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',
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

0 comments on commit 3b772ae

Please sign in to comment.