Skip to content

Commit a425ca2

Browse files
authored
[config] support for configuring muxcable to manual mode of operation (sonic-net#1642)
What I did This PR adds support for an option to configure muxcable mode to a manual mode. The manual mode is in addition to auto/active mode. The new output would look like this in case an active flag is passed to the command line admin@sonic:~$ sudo config muxcable mode manual Ethernet0 admin@sonic:~$ sudo config muxcable mode manual all added an option to set muxcable mode to manual mode, in addition to existing auto/active 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 25e17de commit a425ca2

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

config/muxcable.py

+9-27
Original file line numberDiff line numberDiff line change
@@ -73,43 +73,25 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c
7373
ipv6_value = get_value_for_key_in_config_tbl(config_db, port, "server_ipv6", "MUX_CABLE")
7474

7575
state = get_value_for_key_in_dict(muxcable_statedb_dict, port, "state", "MUX_CABLE_TABLE")
76-
if (state == "active" and configdb_state == "active") or (state == "standby" and configdb_state == "active") or (state == "unknown" and configdb_state == "active"):
77-
if state_cfg_val == "active":
78-
# status is already active, so right back error
79-
port_status_dict[port] = 'OK'
80-
if state_cfg_val == "auto":
81-
# display ok and write to cfgdb auto
82-
port_status_dict[port] = 'OK'
83-
config_db.set_entry("MUX_CABLE", port, {"state": "auto",
84-
"server_ipv4": ipv4_value, "server_ipv6": ipv6_value})
85-
elif state == "active" and configdb_state == "auto":
86-
if state_cfg_val == "active":
87-
# make the state active and write back OK
88-
config_db.set_entry("MUX_CABLE", port, {"state": "active",
89-
"server_ipv4": ipv4_value, "server_ipv6": ipv6_value})
90-
port_status_dict[port] = 'OK'
91-
if state_cfg_val == "auto":
92-
# dont write anything to db, write OK to user
93-
port_status_dict[port] = 'OK'
9476

95-
elif (state == "standby" and configdb_state == "auto") or (state == "unknown" and configdb_state == "auto"):
96-
if state_cfg_val == "active":
97-
# make the state active
98-
config_db.set_entry("MUX_CABLE", port, {"state": "active",
99-
"server_ipv4": ipv4_value, "server_ipv6": ipv6_value})
77+
if str(state_cfg_val) == str(configdb_state):
78+
port_status_dict[port] = 'OK'
79+
else:
80+
config_db.set_entry("MUX_CABLE", port, {"state": state_cfg_val,
81+
"server_ipv4": ipv4_value, "server_ipv6": ipv6_value})
82+
if str(state_cfg_val) == 'active' and str(state) != 'active':
10083
port_status_dict[port] = 'INPROGRESS'
101-
if state_cfg_val == "auto":
102-
# dont write anything to db
84+
else:
10385
port_status_dict[port] = 'OK'
10486

10587

10688
# 'muxcable' command ("config muxcable mode <port|all> active|auto")
10789
@muxcable.command()
108-
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "auto"]))
90+
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "auto", "manual"]))
10991
@click.argument('port', metavar='<port_name>', required=True, default=None)
11092
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL)
11193
def mode(state, port, json_output):
112-
"""Show muxcable summary information"""
94+
"""Config muxcable mode"""
11395

11496
port_table_keys = {}
11597
y_cable_asic_table_keys = {}

tests/mock_tables/config_db.json

+5
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,11 @@
15771577
"server_ipv4": "10.1.1.1",
15781578
"server_ipv6": "fc00::75"
15791579
},
1580+
"MUX_CABLE|Ethernet28": {
1581+
"state": "manual",
1582+
"server_ipv4": "10.1.1.1",
1583+
"server_ipv6": "fc00::75"
1584+
},
15801585
"MUX_CABLE|Ethernet0": {
15811586
"state": "active",
15821587
"server_ipv4": "10.2.1.1",

tests/muxcable_test.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
Ethernet4 auto 10.3.1.1 e801::46
7373
Ethernet8 active 10.4.1.1 e802::46
7474
Ethernet12 active 10.4.1.1 e802::46
75+
Ethernet28 manual 10.1.1.1 fc00::75
7576
Ethernet32 auto 10.1.1.1 fc00::75
7677
"""
7778

@@ -108,6 +109,13 @@
108109
"IPv6": "e802::46"
109110
}
110111
},
112+
"Ethernet28": {
113+
"STATE": "manual",
114+
"SERVER": {
115+
"IPv4": "10.1.1.1",
116+
"IPv6": "fc00::75"
117+
}
118+
},
111119
"Ethernet32": {
112120
"STATE": "auto",
113121
"SERVER": {
@@ -363,6 +371,16 @@ def test_config_muxcable_tabular_port_Ethernet8_auto(self):
363371

364372
assert result.exit_code == 0
365373

374+
def test_config_muxcable_tabular_port_Ethernet8_manual(self):
375+
runner = CliRunner()
376+
db = Db()
377+
378+
with mock.patch('sonic_platform_base.sonic_sfp.sfputilhelper') as patched_util:
379+
patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0
380+
result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["manual", "Ethernet8"], obj=db)
381+
382+
assert result.exit_code == 0
383+
366384
def test_config_muxcable_mode_auto_json(self):
367385
runner = CliRunner()
368386
db = Db()
@@ -377,8 +395,6 @@ def test_config_muxcable_mode_active_json(self):
377395
db = Db()
378396

379397
result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["active", "all", "--json"], obj=db)
380-
f = open("newfile1", "w")
381-
f.write(result.output)
382398

383399
assert result.exit_code == 0
384400
assert result.output == json_data_config_output_active_expected

0 commit comments

Comments
 (0)