Skip to content

Commit

Permalink
[config] support for configuring muxcable to manual mode of operation (
Browse files Browse the repository at this point in the history
…#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 <vdahiya@microsoft.com>
  • Loading branch information
vdahiya12 committed Jun 10, 2021
1 parent 25e17de commit a425ca2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
36 changes: 9 additions & 27 deletions config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,43 +73,25 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c
ipv6_value = get_value_for_key_in_config_tbl(config_db, port, "server_ipv6", "MUX_CABLE")

state = get_value_for_key_in_dict(muxcable_statedb_dict, port, "state", "MUX_CABLE_TABLE")
if (state == "active" and configdb_state == "active") or (state == "standby" and configdb_state == "active") or (state == "unknown" and configdb_state == "active"):
if state_cfg_val == "active":
# status is already active, so right back error
port_status_dict[port] = 'OK'
if state_cfg_val == "auto":
# display ok and write to cfgdb auto
port_status_dict[port] = 'OK'
config_db.set_entry("MUX_CABLE", port, {"state": "auto",
"server_ipv4": ipv4_value, "server_ipv6": ipv6_value})
elif state == "active" and configdb_state == "auto":
if state_cfg_val == "active":
# make the state active and write back OK
config_db.set_entry("MUX_CABLE", port, {"state": "active",
"server_ipv4": ipv4_value, "server_ipv6": ipv6_value})
port_status_dict[port] = 'OK'
if state_cfg_val == "auto":
# dont write anything to db, write OK to user
port_status_dict[port] = 'OK'

elif (state == "standby" and configdb_state == "auto") or (state == "unknown" and configdb_state == "auto"):
if state_cfg_val == "active":
# make the state active
config_db.set_entry("MUX_CABLE", port, {"state": "active",
"server_ipv4": ipv4_value, "server_ipv6": ipv6_value})
if str(state_cfg_val) == str(configdb_state):
port_status_dict[port] = 'OK'
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':
port_status_dict[port] = 'INPROGRESS'
if state_cfg_val == "auto":
# dont write anything to db
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"]))
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "auto", "manual"]))
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL)
def mode(state, port, json_output):
"""Show muxcable summary information"""
"""Config muxcable mode"""

port_table_keys = {}
y_cable_asic_table_keys = {}
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 @@ -1577,6 +1577,11 @@
"server_ipv4": "10.1.1.1",
"server_ipv6": "fc00::75"
},
"MUX_CABLE|Ethernet28": {
"state": "manual",
"server_ipv4": "10.1.1.1",
"server_ipv6": "fc00::75"
},
"MUX_CABLE|Ethernet0": {
"state": "active",
"server_ipv4": "10.2.1.1",
Expand Down
20 changes: 18 additions & 2 deletions tests/muxcable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,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
Ethernet28 manual 10.1.1.1 fc00::75
Ethernet32 auto 10.1.1.1 fc00::75
"""

Expand Down Expand Up @@ -108,6 +109,13 @@
"IPv6": "e802::46"
}
},
"Ethernet28": {
"STATE": "manual",
"SERVER": {
"IPv4": "10.1.1.1",
"IPv6": "fc00::75"
}
},
"Ethernet32": {
"STATE": "auto",
"SERVER": {
Expand Down Expand Up @@ -363,6 +371,16 @@ def test_config_muxcable_tabular_port_Ethernet8_auto(self):

assert result.exit_code == 0

def test_config_muxcable_tabular_port_Ethernet8_manual(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"], ["manual", "Ethernet8"], obj=db)

assert result.exit_code == 0

def test_config_muxcable_mode_auto_json(self):
runner = CliRunner()
db = Db()
Expand All @@ -377,8 +395,6 @@ def test_config_muxcable_mode_active_json(self):
db = Db()

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

assert result.exit_code == 0
assert result.output == json_data_config_output_active_expected
Expand Down

0 comments on commit a425ca2

Please sign in to comment.