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

[counterpoll] make the 'eni' command functional only on the DPU #3679

Merged
merged 1 commit into from
Dec 24, 2024
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
29 changes: 25 additions & 4 deletions counterpoll/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,12 @@ def disable(ctx):


# ENI counter commands
@cli.group()
@click.group()
@click.pass_context
def eni(ctx):
""" ENI counter commands """
ctx.obj = ConfigDBConnector()
ctx.obj.connect()
if not is_dpu(ctx.obj):
click.echo("ENI counters are not supported on non DPU platforms")
exit(1)


@eni.command(name='interval')
Expand Down Expand Up @@ -534,3 +531,27 @@ def disable(filename):
def delay(filename):
""" Delay counters in config_db file """
_update_config_db_flex_counter_table("delay", filename)


"""
The list of dynamic commands that are added on a specific condition.
Format:
(click group/command, callback function)
"""
dynamic_commands = [
(eni, is_dpu)
]


def register_dynamic_commands(cmds):
"""
Dynamically register commands based on condition callback.
"""
db = ConfigDBConnector()
db.connect()
for cmd, cb in cmds:
if cb(db):
cli.add_command(cmd)


register_dynamic_commands(dynamic_commands)
9 changes: 7 additions & 2 deletions tests/counterpoll_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import mock
import sys
import importlib
from click.testing import CliRunner
from shutil import copyfile
from utilities_common.db import Db
Expand Down Expand Up @@ -248,13 +249,15 @@ def test_update_route_counter_interval(self):
def test_update_eni_status(self, status):
runner = CliRunner()
result = runner.invoke(counterpoll.cli, ["eni", status])
assert result.exit_code == 1
assert result.output == "ENI counters are not supported on non DPU platforms\n"
assert 'No such command "eni"' in result.output
assert result.exit_code == 2

@pytest.mark.parametrize("status", ["disable", "enable"])
@mock.patch('counterpoll.main.device_info.get_platform_info')
def test_update_eni_status_dpu(self, mock_get_platform_info, status):
mock_get_platform_info.return_value = {'switch_type': 'dpu'}
importlib.reload(counterpoll)

runner = CliRunner()
db = Db()

Expand All @@ -267,6 +270,8 @@ def test_update_eni_status_dpu(self, mock_get_platform_info, status):
@mock.patch('counterpoll.main.device_info.get_platform_info')
def test_update_eni_interval(self, mock_get_platform_info):
mock_get_platform_info.return_value = {'switch_type': 'dpu'}
importlib.reload(counterpoll)

runner = CliRunner()
db = Db()
test_interval = "2000"
Expand Down
Loading