Skip to content

Commit

Permalink
[show mux]: Sort output by intf name (sonic-net#1418)
Browse files Browse the repository at this point in the history
Signed-off-by: Lawrence Lee <[email protected]>
  • Loading branch information
theasianpianist authored Feb 10, 2021
1 parent eb70ebc commit f5b8a1e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
9 changes: 5 additions & 4 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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)))
Expand All @@ -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']
Expand Down
26 changes: 13 additions & 13 deletions tests/muxcable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -52,6 +48,10 @@
"Ethernet12": {
"STATUS": "unknown",
"HEALTH": "HEALTHY"
},
"Ethernet32": {
"STATUS": "active",
"HEALTH": "HEALTHY"
}
}
}
Expand All @@ -64,25 +64,18 @@
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 = """\
{
"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": {
Expand Down Expand Up @@ -110,6 +103,13 @@
"IPv4": "10.4.1.1",
"IPv6": "e802::46"
}
},
"Ethernet32": {
"STATE": "auto",
"SERVER": {
"IPv4": "10.1.1.1",
"IPv6": "fc00::75"
}
}
}
}
Expand Down

0 comments on commit f5b8a1e

Please sign in to comment.