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

[config][muxcable] add support to enable/disable ycable telemetry (#2… #2304

Merged
merged 2 commits into from
Aug 10, 2022
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 config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,3 +1190,46 @@ def set_fec(db, port, target, mode):
else:
click.echo("ERR: Unable to set fec enable/disable port {} to {}".format(port, mode))
sys.exit(CONFIG_FAIL)

def update_configdb_ycable_telemetry_data(config_db, key, val):
log_verbosity = get_value_for_key_in_config_tbl(config_db, key, "log_verbosity", "XCVRD_LOG")

config_db.set_entry("XCVRD_LOG", key, {"log_verbosity": log_verbosity,
"disable_telemetry": val})
return 0

@muxcable.command()
@click.argument('state', metavar='<enable/disable telemetry>', required=True, type=click.Choice(["enable", "disable"]))
@clicommon.pass_db
def telemetry(db, state):
"""Enable/Disable Telemetry for ycabled """

per_npu_configdb = {}
xcvrd_log_cfg_db_tbl = {}

if state == 'enable':
val = 'False'
elif state == 'disable':
val = 'True'


# Getting all front asic namespace and correspding config and state DB connector

namespaces = multi_asic.get_front_end_namespaces()
for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
# replace these with correct macros
per_npu_configdb[asic_id] = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
per_npu_configdb[asic_id].connect()

xcvrd_log_cfg_db_tbl[asic_id] = per_npu_configdb[asic_id].get_table("XCVRD_LOG")

asic_index = multi_asic.get_asic_index_from_namespace(EMPTY_NAMESPACE)
rc = update_configdb_ycable_telemetry_data(per_npu_configdb[asic_index], "Y_CABLE", val)


if rc == 0:
click.echo("Success in ycabled telemetry state to {}".format(state))
else:
click.echo("ERR: Unable to set ycabled telemetry state to {}".format(state))
sys.exit(CONFIG_FAIL)
34 changes: 34 additions & 0 deletions tests/muxcable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,40 @@ def test_show_muxcable_packetloss_port_json(self):
assert result.exit_code == 0
assert result.output == show_muxcable_packetloss_expected_output_json

@mock.patch('config.muxcable.swsscommon.DBConnector', mock.MagicMock(return_value=0))
@mock.patch('config.muxcable.swsscommon.Table', mock.MagicMock(return_value=0))
@mock.patch('config.muxcable.swsscommon.Select', mock.MagicMock(return_value=0))
def test_config_muxcable_telemetry_enable_without_patch(self):
runner = CliRunner()
db = Db()

result = runner.invoke(config.config.commands["muxcable"].commands["telemetry"], [
"enable"], obj=db)
assert result.exit_code == 1

@mock.patch('config.muxcable.swsscommon.DBConnector', mock.MagicMock(return_value=0))
@mock.patch('config.muxcable.swsscommon.Table', mock.MagicMock(return_value=0))
@mock.patch('config.muxcable.swsscommon.Select', mock.MagicMock(return_value=0))
def test_config_muxcable_telemetry_disable_without_patch(self):
runner = CliRunner()
db = Db()

result = runner.invoke(config.config.commands["muxcable"].commands["telemetry"], [
"disable"], obj=db)
assert result.exit_code == 1

@mock.patch('config.muxcable.swsscommon.DBConnector', mock.MagicMock(return_value=0))
@mock.patch('config.muxcable.swsscommon.Table', mock.MagicMock(return_value=0))
@mock.patch('config.muxcable.swsscommon.Select', mock.MagicMock(return_value=0))
@mock.patch('config.muxcable.update_configdb_ycable_telemetry_data', mock.MagicMock(return_value=0))
def test_config_muxcable_telemetry_enable(self):
runner = CliRunner()
db = Db()

result = runner.invoke(config.config.commands["muxcable"].commands["telemetry"], [
"enable"], obj=db)
assert result.exit_code == 0

@classmethod
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"
Expand Down