From 48887d1001a8daaa4a9d53520693f1d0686f1e24 Mon Sep 17 00:00:00 2001 From: vdahiya12 <67608553+vdahiya12@users.noreply.github.com> Date: Thu, 23 Sep 2021 11:49:44 -0700 Subject: [PATCH] [config] support for configuring muxcable to standby mode of operation (#1837) What I did This PR adds support for an option to configure muxcable mode to a standby mode. The standby mode is in addition to auto\active\manual mode. The new output would look like this in case an standby arg is passed to the command line admin@sonic:~$ sudo config muxcable mode standby Ethernet0 admin@sonic:~$ sudo config muxcable mode standby all added an option to set muxcable mode to standby mode, in addition to existing auto/active/manual modes. How I did it added the changes in config/muxcable.py and added testcases How to verify it Ran the unit tests Signed-off-by: vaibhav-dahiya --- config/muxcable.py | 4 ++-- tests/mock_tables/config_db.json | 5 +++++ tests/mock_tables/state_db.json | 6 ++++++ tests/muxcable_test.py | 25 +++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/config/muxcable.py b/config/muxcable.py index 28172529719c..c88adffe3785 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -233,7 +233,7 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c else: config_db.set_entry("MUX_CABLE", port, {"state": state_cfg_val, "server_ipv4": ipv4_value, "server_ipv6": ipv6_value}) - if str(state_cfg_val) == 'active' and str(state) != 'active': + if (str(state_cfg_val) == 'active' and str(state) != 'active') or (str(state_cfg_val) == 'standby' and str(state) != 'standby'): port_status_dict[port] = 'INPROGRESS' else: port_status_dict[port] = 'OK' @@ -241,7 +241,7 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c # 'muxcable' command ("config muxcable mode active|auto") @muxcable.command() -@click.argument('state', metavar='', required=True, type=click.Choice(["active", "auto", "manual"])) +@click.argument('state', metavar='', required=True, type=click.Choice(["active", "auto", "manual", "standby"])) @click.argument('port', metavar='', required=True, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL) @clicommon.pass_db diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index 07e0e284250e..06305d30465e 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -1636,6 +1636,11 @@ "server_ipv4": "10.1.1.1", "server_ipv6": "fc00::75" }, + "MUX_CABLE|Ethernet16": { + "state": "standby", + "server_ipv4": "10.1.1.1", + "server_ipv6": "fc00::75" + }, "MUX_CABLE|Ethernet28": { "state": "manual", "server_ipv4": "10.1.1.1", diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index 729725fe227a..af2519d3ce21 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -545,6 +545,9 @@ "MUX_CABLE_TABLE|Ethernet8": { "state": "standby" }, + "MUX_CABLE_TABLE|Ethernet16": { + "state": "standby" + }, "MUX_CABLE_TABLE|Ethernet12": { "state": "unknown" }, @@ -560,6 +563,9 @@ "MUX_LINKMGR_TABLE|Ethernet8": { "state": "unhealthy" }, + "MUX_LINKMGR_TABLE|Ethernet16": { + "state": "healthy" + }, "MUX_LINKMGR_TABLE|Ethernet12": { "state": "unhealthy" }, diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index a8a4f764e90a..43ed0013e6b1 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -31,6 +31,7 @@ Ethernet4 standby healthy Ethernet8 standby unhealthy Ethernet12 unknown unhealthy +Ethernet16 standby healthy Ethernet32 active healthy """ @@ -53,6 +54,10 @@ "STATUS": "unknown", "HEALTH": "unhealthy" }, + "Ethernet16": { + "STATUS": "standby", + "HEALTH": "healthy" + }, "Ethernet32": { "STATUS": "active", "HEALTH": "healthy" @@ -72,6 +77,7 @@ Ethernet4 auto 10.3.1.1 e801::46 Ethernet8 active 10.4.1.1 e802::46 Ethernet12 active 10.4.1.1 e802::46 +Ethernet16 standby 10.1.1.1 fc00::75 Ethernet28 manual 10.1.1.1 fc00::75 Ethernet32 auto 10.1.1.1 fc00::75 """ @@ -109,6 +115,13 @@ "IPv6": "e802::46" } }, + "Ethernet16": { + "STATE": "standby", + "SERVER": { + "IPv4": "10.1.1.1", + "IPv6": "fc00::75" + } + }, "Ethernet28": { "STATE": "manual", "SERVER": { @@ -151,6 +164,7 @@ "Ethernet0": "OK", "Ethernet4": "OK", "Ethernet8": "OK", + "Ethernet16": "OK", "Ethernet12": "OK" } """ @@ -161,6 +175,7 @@ "Ethernet0": "OK", "Ethernet4": "INPROGRESS", "Ethernet8": "OK", + "Ethernet16": "INPROGRESS", "Ethernet12": "OK" } """ @@ -381,6 +396,16 @@ def test_config_muxcable_tabular_port_Ethernet8_manual(self): assert result.exit_code == 0 + def test_config_muxcable_tabular_port_Ethernet16_standby(self): + runner = CliRunner() + db = Db() + + with mock.patch('sonic_platform_base.sonic_sfp.sfputilhelper') as patched_util: + patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0 + result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["standby", "Ethernet16"], obj=db) + + assert result.exit_code == 0 + def test_config_muxcable_mode_auto_json(self): runner = CliRunner() db = Db()