Skip to content

Commit 48887d1

Browse files
authored
[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 <[email protected]>
1 parent 2088a9a commit 48887d1

4 files changed

Lines changed: 38 additions & 2 deletions

File tree

config/muxcable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,15 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c
233233
else:
234234
config_db.set_entry("MUX_CABLE", port, {"state": state_cfg_val,
235235
"server_ipv4": ipv4_value, "server_ipv6": ipv6_value})
236-
if str(state_cfg_val) == 'active' and str(state) != 'active':
236+
if (str(state_cfg_val) == 'active' and str(state) != 'active') or (str(state_cfg_val) == 'standby' and str(state) != 'standby'):
237237
port_status_dict[port] = 'INPROGRESS'
238238
else:
239239
port_status_dict[port] = 'OK'
240240

241241

242242
# 'muxcable' command ("config muxcable mode <port|all> active|auto")
243243
@muxcable.command()
244-
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "auto", "manual"]))
244+
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "auto", "manual", "standby"]))
245245
@click.argument('port', metavar='<port_name>', required=True, default=None)
246246
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL)
247247
@clicommon.pass_db

tests/mock_tables/config_db.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,11 @@
16361636
"server_ipv4": "10.1.1.1",
16371637
"server_ipv6": "fc00::75"
16381638
},
1639+
"MUX_CABLE|Ethernet16": {
1640+
"state": "standby",
1641+
"server_ipv4": "10.1.1.1",
1642+
"server_ipv6": "fc00::75"
1643+
},
16391644
"MUX_CABLE|Ethernet28": {
16401645
"state": "manual",
16411646
"server_ipv4": "10.1.1.1",

tests/mock_tables/state_db.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@
545545
"MUX_CABLE_TABLE|Ethernet8": {
546546
"state": "standby"
547547
},
548+
"MUX_CABLE_TABLE|Ethernet16": {
549+
"state": "standby"
550+
},
548551
"MUX_CABLE_TABLE|Ethernet12": {
549552
"state": "unknown"
550553
},
@@ -560,6 +563,9 @@
560563
"MUX_LINKMGR_TABLE|Ethernet8": {
561564
"state": "unhealthy"
562565
},
566+
"MUX_LINKMGR_TABLE|Ethernet16": {
567+
"state": "healthy"
568+
},
563569
"MUX_LINKMGR_TABLE|Ethernet12": {
564570
"state": "unhealthy"
565571
},

tests/muxcable_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
Ethernet4 standby healthy
3232
Ethernet8 standby unhealthy
3333
Ethernet12 unknown unhealthy
34+
Ethernet16 standby healthy
3435
Ethernet32 active healthy
3536
"""
3637

@@ -53,6 +54,10 @@
5354
"STATUS": "unknown",
5455
"HEALTH": "unhealthy"
5556
},
57+
"Ethernet16": {
58+
"STATUS": "standby",
59+
"HEALTH": "healthy"
60+
},
5661
"Ethernet32": {
5762
"STATUS": "active",
5863
"HEALTH": "healthy"
@@ -72,6 +77,7 @@
7277
Ethernet4 auto 10.3.1.1 e801::46
7378
Ethernet8 active 10.4.1.1 e802::46
7479
Ethernet12 active 10.4.1.1 e802::46
80+
Ethernet16 standby 10.1.1.1 fc00::75
7581
Ethernet28 manual 10.1.1.1 fc00::75
7682
Ethernet32 auto 10.1.1.1 fc00::75
7783
"""
@@ -109,6 +115,13 @@
109115
"IPv6": "e802::46"
110116
}
111117
},
118+
"Ethernet16": {
119+
"STATE": "standby",
120+
"SERVER": {
121+
"IPv4": "10.1.1.1",
122+
"IPv6": "fc00::75"
123+
}
124+
},
112125
"Ethernet28": {
113126
"STATE": "manual",
114127
"SERVER": {
@@ -151,6 +164,7 @@
151164
"Ethernet0": "OK",
152165
"Ethernet4": "OK",
153166
"Ethernet8": "OK",
167+
"Ethernet16": "OK",
154168
"Ethernet12": "OK"
155169
}
156170
"""
@@ -161,6 +175,7 @@
161175
"Ethernet0": "OK",
162176
"Ethernet4": "INPROGRESS",
163177
"Ethernet8": "OK",
178+
"Ethernet16": "INPROGRESS",
164179
"Ethernet12": "OK"
165180
}
166181
"""
@@ -381,6 +396,16 @@ def test_config_muxcable_tabular_port_Ethernet8_manual(self):
381396

382397
assert result.exit_code == 0
383398

399+
def test_config_muxcable_tabular_port_Ethernet16_standby(self):
400+
runner = CliRunner()
401+
db = Db()
402+
403+
with mock.patch('sonic_platform_base.sonic_sfp.sfputilhelper') as patched_util:
404+
patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0
405+
result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["standby", "Ethernet16"], obj=db)
406+
407+
assert result.exit_code == 0
408+
384409
def test_config_muxcable_mode_auto_json(self):
385410
runner = CliRunner()
386411
db = Db()

0 commit comments

Comments
 (0)