From 8dab09bd8c84c4debfb88a2c526473db908eb24e Mon Sep 17 00:00:00 2001 From: vdahiya12 <67608553+vdahiya12@users.noreply.github.com> Date: Tue, 9 Aug 2022 13:15:03 -0700 Subject: [PATCH 1/2] [config][muxcable] add support to enable/disable ycable telemetry (#2297) This PR provides a capability to sonic-utilities CLI to enable/disable telemetry for ycabled. Basically there is a periodic loop for ycabled which posts telemetry data for that configured interval of time(currently 60 sec). This PR diables this data posting, and does not call platform API calls for ycable. This PR is required for the initiative of getting some failover/switchover not get interfered because of sonic-telemetry API calls. The CLI for enabling/disabling telemetry is config muxcable telemetry enable/disable What I did How I did it How to verify it Previous command output (if the output of a command-line utility has changed) New command output (if the output of a command-line utility has changed) Dependent on sonic-net/sonic-platform-daemons#279 and submodule update Signed-off-by: vaibhav-dahiya --- config/muxcable.py | 43 +++++++++++++++++++++ tests/muxcable_test.py | 88 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) diff --git a/config/muxcable.py b/config/muxcable.py index cf28d059b3..f3d8e9d8e6 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -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='', 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) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 30798e3915..d7a5f09bc3 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -2095,6 +2095,94 @@ def test_show_muxcable_packetloss_port_json(self): assert result.exit_code == 0 assert result.output == show_muxcable_packetloss_expected_output_json + @mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) + @mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0)) + @mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) + @mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0])) + def test_show_muxcable_tunnel_route(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"], obj=db) + + assert result.exit_code == 0 + assert result.output == show_muxcable_tunnel_route_expected_output + + @mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) + @mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0)) + @mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) + @mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0])) + def test_show_muxcable_tunnel_route_json(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"], + ["--json"], obj=db) + + assert result.exit_code == 0 + assert result.output == show_muxcable_tunnel_route_expected_output_json + + @mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) + @mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0)) + @mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) + @mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0])) + def test_show_muxcable_tunnel_route_port(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"], + ["Ethernet0"], obj=db) + + assert result.exit_code == 0 + assert result.output == show_muxcable_tunnel_route_expected_port_output + + @mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) + @mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0)) + @mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) + @mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0])) + def test_show_muxcable_tunnel_route_json_port(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"], + ["Ethernet0", "--json"], obj=db) + assert result.exit_code == 0 + assert result.output == show_muxcable_tunnel_route_expected_output_port_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" From e5a059bb70f45e27fd9c0f37ddf258ec73c54ed8 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 10 Aug 2022 00:13:13 +0000 Subject: [PATCH 2/2] fix tests Signed-off-by: vaibhav-dahiya --- tests/muxcable_test.py | 54 ------------------------------------------ 1 file changed, 54 deletions(-) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index d7a5f09bc3..16e10ea2f5 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -2095,60 +2095,6 @@ def test_show_muxcable_packetloss_port_json(self): assert result.exit_code == 0 assert result.output == show_muxcable_packetloss_expected_output_json - @mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) - @mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0)) - @mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) - @mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0])) - def test_show_muxcable_tunnel_route(self): - runner = CliRunner() - db = Db() - - result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"], obj=db) - - assert result.exit_code == 0 - assert result.output == show_muxcable_tunnel_route_expected_output - - @mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) - @mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0)) - @mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) - @mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0])) - def test_show_muxcable_tunnel_route_json(self): - runner = CliRunner() - db = Db() - - result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"], - ["--json"], obj=db) - - assert result.exit_code == 0 - assert result.output == show_muxcable_tunnel_route_expected_output_json - - @mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) - @mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0)) - @mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) - @mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0])) - def test_show_muxcable_tunnel_route_port(self): - runner = CliRunner() - db = Db() - - result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"], - ["Ethernet0"], obj=db) - - assert result.exit_code == 0 - assert result.output == show_muxcable_tunnel_route_expected_port_output - - @mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) - @mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0)) - @mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) - @mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0])) - def test_show_muxcable_tunnel_route_json_port(self): - runner = CliRunner() - db = Db() - - result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"], - ["Ethernet0", "--json"], obj=db) - assert result.exit_code == 0 - assert result.output == show_muxcable_tunnel_route_expected_output_port_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))