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

Add new CLI for PG drop counters part of counterpoll utility #1355

Merged
merged 1 commit into from
Feb 17, 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
43 changes: 43 additions & 0 deletions counterpoll/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

BUFFER_POOL_WATERMARK = "BUFFER_POOL_WATERMARK"
PORT_BUFFER_DROP = "PORT_BUFFER_DROP"
PG_DROP = "PG_DROP"
DISABLE = "disable"
ENABLE = "enable"
DEFLT_60_SEC= "default (60000)"
Expand Down Expand Up @@ -123,6 +124,45 @@ def disable():
port_info['FLEX_COUNTER_STATUS'] = DISABLE
configdb.mod_entry("FLEX_COUNTER_TABLE", PORT_BUFFER_DROP, port_info)

# Ingress PG drop packet stat
@cli.group()
@click.pass_context
def pg_drop(ctx):
""" Ingress PG drop counter commands """
ctx.obj = swsssdk.ConfigDBConnector()
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swsssdk [](start = 14, length = 7)

swsssdk is deprecated largely in sonic-utilities. Could you adapt the new ConfigDBConnector as in latest code?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it also deprecated on 202012? this PR should go to 202012 as well thus need to know if the change should be done on specific branch only
@ayurkiv-nvda FYI

ctx.obj.connect()

@pg_drop.command()
@click.argument('poll_interval', type=click.IntRange(1000, 30000))
@click.pass_context
def interval(ctx, poll_interval):
"""
Set pg_drop packets counter query interval
interval is between 1s and 30s.
"""

port_info = {}
port_info['POLL_INTERVAL'] = poll_interval
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", PG_DROP, port_info)

@pg_drop.command()
@click.pass_context
def enable(ctx):
""" Enable pg_drop counter query """

port_info = {}
port_info['FLEX_COUNTER_STATUS'] = ENABLE
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", PG_DROP, port_info)

@pg_drop.command()
@click.pass_context
def disable(ctx):
""" Disable pg_drop counter query """

port_info = {}
port_info['FLEX_COUNTER_STATUS'] = DISABLE
ctx.obj.mod_entry("FLEX_COUNTER_TABLE", PG_DROP, port_info)

# RIF counter commands
@cli.group()
def rif():
Expand Down Expand Up @@ -212,6 +252,7 @@ def show():
rif_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'RIF')
queue_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'QUEUE_WATERMARK')
pg_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'PG_WATERMARK')
pg_drop_info = configdb.get_entry('FLEX_COUNTER_TABLE', PG_DROP)
buffer_pool_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', BUFFER_POOL_WATERMARK)

header = ("Type", "Interval (in ms)", "Status")
Expand All @@ -228,6 +269,8 @@ def show():
data.append(["QUEUE_WATERMARK_STAT", queue_wm_info.get("POLL_INTERVAL", DEFLT_10_SEC), queue_wm_info.get("FLEX_COUNTER_STATUS", DISABLE)])
if pg_wm_info:
data.append(["PG_WATERMARK_STAT", pg_wm_info.get("POLL_INTERVAL", DEFLT_10_SEC), pg_wm_info.get("FLEX_COUNTER_STATUS", DISABLE)])
if pg_drop_info:
data.append(['PG_DROP_STAT', pg_drop_info.get("POLL_INTERVAL", DEFLT_10_SEC), pg_drop_info.get("FLEX_COUNTER_STATUS", DISABLE)])
if buffer_pool_wm_info:
data.append(["BUFFER_POOL_WATERMARK_STAT", buffer_pool_wm_info.get("POLL_INTERVAL", DEFLT_10_SEC), buffer_pool_wm_info.get("FLEX_COUNTER_STATUS", DISABLE)])

Expand Down
34 changes: 34 additions & 0 deletions tests/counterpoll_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
from click.testing import CliRunner
from shutil import copyfile
from utilities_common.db import Db

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
Expand All @@ -25,6 +26,7 @@
PORT_BUFFER_DROP 60000 enable
QUEUE_WATERMARK_STAT 10000 enable
PG_WATERMARK_STAT 10000 enable
PG_DROP_STAT 10000 enable
"""

class TestCounterpoll(object):
Expand Down Expand Up @@ -54,6 +56,14 @@ def test_port_buffer_drop_interval_too_short(self):
assert result.exit_code == 2
assert expected in result.output

def test_pg_drop_interval_too_long(self):
runner = CliRunner()
result = runner.invoke(counterpoll.cli.commands["pg-drop"].commands["interval"], ["50000"])
print(result.output)
expected = "Invalid value for \"POLL_INTERVAL\": 50000 is not in the valid range of 1000 to 30000."
assert result.exit_code == 2
assert expected in result.output

@pytest.fixture(scope='class')
def _get_config_db_file(self):
sample_config_db_file = os.path.join(test_path, "counterpoll_input", "config_db.json")
Expand All @@ -76,6 +86,30 @@ def test_update_counter_config_db_status(self, status, _get_config_db_file):
for counter, counter_config in config_db["FLEX_COUNTER_TABLE"].items():
assert counter_config["FLEX_COUNTER_STATUS"] == status

@pytest.mark.parametrize("status", ["disable", "enable"])
def test_update_pg_drop_status(self, status):
runner = CliRunner()
db = Db()

result = runner.invoke(counterpoll.cli.commands["pg-drop"].commands[status], [], obj=db.cfgdb)
print(result.exit_code, result.output)
assert result.exit_code == 0
ayurkiv-nvda marked this conversation as resolved.
Show resolved Hide resolved

table = db.cfgdb.get_table('FLEX_COUNTER_TABLE')
assert status == table["PG_DROP"]["FLEX_COUNTER_STATUS"]

def test_update_pg_drop_interval(self):
runner = CliRunner()
db = Db()
test_interval = "20000"

result = runner.invoke(counterpoll.cli.commands["pg-drop"].commands["interval"], [test_interval], obj=db.cfgdb)
print(result.exit_code, result.output)
assert result.exit_code == 0

table = db.cfgdb.get_table('FLEX_COUNTER_TABLE')
assert test_interval == table["PG_DROP"]["POLL_INTERVAL"]

@classmethod
def teardown_class(cls):
print("TEARDOWN")
Expand Down
4 changes: 4 additions & 0 deletions tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,10 @@
"POLL_INTERVAL": "10000",
"FLEX_COUNTER_STATUS": "enable"
},
"FLEX_COUNTER_TABLE|PG_DROP": {
"POLL_INTERVAL": "10000",
"FLEX_COUNTER_STATUS": "enable"
},
"PFC_WD|Ethernet0": {
"action": "drop",
"detection_time": "600",
Expand Down