Skip to content

Commit

Permalink
[config] support for configuring muxcable to standby mode of operation (
Browse files Browse the repository at this point in the history
sonic-net#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 <vdahiya@microsoft.com>
  • Loading branch information
vdahiya12 authored Sep 23, 2021
1 parent 2088a9a commit 48887d1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ 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'


# 'muxcable' command ("config muxcable mode <port|all> active|auto")
@muxcable.command()
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "auto", "manual"]))
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "auto", "manual", "standby"]))
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL)
@clicommon.pass_db
Expand Down
5 changes: 5 additions & 0 deletions tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@
"MUX_CABLE_TABLE|Ethernet8": {
"state": "standby"
},
"MUX_CABLE_TABLE|Ethernet16": {
"state": "standby"
},
"MUX_CABLE_TABLE|Ethernet12": {
"state": "unknown"
},
Expand All @@ -560,6 +563,9 @@
"MUX_LINKMGR_TABLE|Ethernet8": {
"state": "unhealthy"
},
"MUX_LINKMGR_TABLE|Ethernet16": {
"state": "healthy"
},
"MUX_LINKMGR_TABLE|Ethernet12": {
"state": "unhealthy"
},
Expand Down
25 changes: 25 additions & 0 deletions tests/muxcable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
Ethernet4 standby healthy
Ethernet8 standby unhealthy
Ethernet12 unknown unhealthy
Ethernet16 standby healthy
Ethernet32 active healthy
"""

Expand All @@ -53,6 +54,10 @@
"STATUS": "unknown",
"HEALTH": "unhealthy"
},
"Ethernet16": {
"STATUS": "standby",
"HEALTH": "healthy"
},
"Ethernet32": {
"STATUS": "active",
"HEALTH": "healthy"
Expand All @@ -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
"""
Expand Down Expand Up @@ -109,6 +115,13 @@
"IPv6": "e802::46"
}
},
"Ethernet16": {
"STATE": "standby",
"SERVER": {
"IPv4": "10.1.1.1",
"IPv6": "fc00::75"
}
},
"Ethernet28": {
"STATE": "manual",
"SERVER": {
Expand Down Expand Up @@ -151,6 +164,7 @@
"Ethernet0": "OK",
"Ethernet4": "OK",
"Ethernet8": "OK",
"Ethernet16": "OK",
"Ethernet12": "OK"
}
"""
Expand All @@ -161,6 +175,7 @@
"Ethernet0": "OK",
"Ethernet4": "INPROGRESS",
"Ethernet8": "OK",
"Ethernet16": "INPROGRESS",
"Ethernet12": "OK"
}
"""
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 48887d1

Please sign in to comment.