diff --git a/show/muxcable.py b/show/muxcable.py index fd2abaf526..07443080ef 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -4,6 +4,7 @@ import click import utilities_common.cli as clicommon +from natsort import natsorted from sonic_py_common import multi_asic from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector from tabulate import tabulate @@ -189,7 +190,7 @@ def status(port, json_output): port_status_dict["MUX_CABLE"] = {} for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) - for key in port_table_keys[asic_id]: + for key in natsorted(port_table_keys[asic_id]): port = key.split("|")[1] muxcable_info_dict[asic_id] = per_npu_statedb[asic_id].get_all( per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port)) @@ -200,7 +201,7 @@ def status(port, json_output): print_data = [] for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) - for key in port_table_keys[asic_id]: + for key in natsorted(port_table_keys[asic_id]): port = key.split("|")[1] muxcable_info_dict[asic_id] = per_npu_statedb[asic_id].get_all( per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port)) @@ -316,7 +317,7 @@ def config(port, json_output): port_status_dict["MUX_CABLE"]["PORTS"] = {} for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) - for port in port_mux_tbl_keys[asic_id]: + for port in natsorted(port_mux_tbl_keys[asic_id]): create_json_dump_per_port_config(port_status_dict, per_npu_configdb, asic_id, port) click.echo("{}".format(json.dumps(port_status_dict, indent=4))) @@ -325,7 +326,7 @@ def config(port, json_output): print_peer_tor = [] for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) - for port in port_mux_tbl_keys[asic_id]: + for port in natsorted(port_mux_tbl_keys[asic_id]): create_table_dump_per_port_config(print_data, per_npu_configdb, asic_id, port) headers = ['SWITCH_NAME', 'PEER_TOR'] diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 0639fca7aa..f6f35e7b8c 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -23,20 +23,16 @@ tabular_data_status_output_expected = """\ PORT STATUS HEALTH ---------- -------- -------- -Ethernet32 active HEALTHY Ethernet0 active HEALTHY Ethernet4 standby HEALTHY Ethernet8 standby HEALTHY Ethernet12 unknown HEALTHY +Ethernet32 active HEALTHY """ json_data_status_output_expected = """\ { "MUX_CABLE": { - "Ethernet32": { - "STATUS": "active", - "HEALTH": "HEALTHY" - }, "Ethernet0": { "STATUS": "active", "HEALTH": "HEALTHY" @@ -52,6 +48,10 @@ "Ethernet12": { "STATUS": "unknown", "HEALTH": "HEALTHY" + }, + "Ethernet32": { + "STATUS": "active", + "HEALTH": "HEALTHY" } } } @@ -64,11 +64,11 @@ sonic-switch 10.2.2.2 port state ipv4 ipv6 ---------- ------- -------- -------- -Ethernet32 auto 10.1.1.1 fc00::75 Ethernet0 active 10.2.1.1 e800::46 Ethernet4 auto 10.3.1.1 e801::46 Ethernet8 active 10.4.1.1 e802::46 Ethernet12 active 10.4.1.1 e802::46 +Ethernet32 auto 10.1.1.1 fc00::75 """ json_data_status_config_output_expected = """\ @@ -76,13 +76,6 @@ "MUX_CABLE": { "PEER_TOR": "10.2.2.2", "PORTS": { - "Ethernet32": { - "STATE": "auto", - "SERVER": { - "IPv4": "10.1.1.1", - "IPv6": "fc00::75" - } - }, "Ethernet0": { "STATE": "active", "SERVER": { @@ -110,6 +103,13 @@ "IPv4": "10.4.1.1", "IPv6": "e802::46" } + }, + "Ethernet32": { + "STATE": "auto", + "SERVER": { + "IPv4": "10.1.1.1", + "IPv6": "fc00::75" + } } } }