Skip to content

Commit 28044e7

Browse files
theasianpianistdaall
authored andcommitted
[show mux]: Sort output by intf name (#1418)
Signed-off-by: Lawrence Lee <[email protected]>
1 parent d038905 commit 28044e7

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

show/muxcable.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import click
66
import utilities_common.cli as clicommon
7+
from natsort import natsorted
78
from sonic_py_common import multi_asic
89
from swsscommon import swsscommon
910
from swsssdk import ConfigDBConnector
@@ -190,7 +191,7 @@ def status(port, json_output):
190191
port_status_dict["MUX_CABLE"] = {}
191192
for namespace in namespaces:
192193
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
193-
for key in port_table_keys[asic_id]:
194+
for key in natsorted(port_table_keys[asic_id]):
194195
port = key.split("|")[1]
195196
muxcable_info_dict[asic_id] = per_npu_statedb[asic_id].get_all(
196197
per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))
@@ -201,7 +202,7 @@ def status(port, json_output):
201202
print_data = []
202203
for namespace in namespaces:
203204
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
204-
for key in port_table_keys[asic_id]:
205+
for key in natsorted(port_table_keys[asic_id]):
205206
port = key.split("|")[1]
206207
muxcable_info_dict[asic_id] = per_npu_statedb[asic_id].get_all(
207208
per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))
@@ -317,7 +318,7 @@ def config(port, json_output):
317318
port_status_dict["MUX_CABLE"]["PORTS"] = {}
318319
for namespace in namespaces:
319320
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
320-
for port in port_mux_tbl_keys[asic_id]:
321+
for port in natsorted(port_mux_tbl_keys[asic_id]):
321322
create_json_dump_per_port_config(port_status_dict, per_npu_configdb, asic_id, port)
322323

323324
click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
@@ -326,7 +327,7 @@ def config(port, json_output):
326327
print_peer_tor = []
327328
for namespace in namespaces:
328329
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
329-
for port in port_mux_tbl_keys[asic_id]:
330+
for port in natsorted(port_mux_tbl_keys[asic_id]):
330331
create_table_dump_per_port_config(print_data, per_npu_configdb, asic_id, port)
331332

332333
headers = ['SWITCH_NAME', 'PEER_TOR']

tests/muxcable_test.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,16 @@
2323
tabular_data_status_output_expected = """\
2424
PORT STATUS HEALTH
2525
---------- -------- --------
26-
Ethernet32 active HEALTHY
2726
Ethernet0 active HEALTHY
2827
Ethernet4 standby HEALTHY
2928
Ethernet8 standby HEALTHY
3029
Ethernet12 unknown HEALTHY
30+
Ethernet32 active HEALTHY
3131
"""
3232

3333
json_data_status_output_expected = """\
3434
{
3535
"MUX_CABLE": {
36-
"Ethernet32": {
37-
"STATUS": "active",
38-
"HEALTH": "HEALTHY"
39-
},
4036
"Ethernet0": {
4137
"STATUS": "active",
4238
"HEALTH": "HEALTHY"
@@ -52,6 +48,10 @@
5248
"Ethernet12": {
5349
"STATUS": "unknown",
5450
"HEALTH": "HEALTHY"
51+
},
52+
"Ethernet32": {
53+
"STATUS": "active",
54+
"HEALTH": "HEALTHY"
5555
}
5656
}
5757
}
@@ -64,25 +64,18 @@
6464
sonic-switch 10.2.2.2
6565
port state ipv4 ipv6
6666
---------- ------- -------- --------
67-
Ethernet32 auto 10.1.1.1 fc00::75
6867
Ethernet0 active 10.2.1.1 e800::46
6968
Ethernet4 auto 10.3.1.1 e801::46
7069
Ethernet8 active 10.4.1.1 e802::46
7170
Ethernet12 active 10.4.1.1 e802::46
71+
Ethernet32 auto 10.1.1.1 fc00::75
7272
"""
7373

7474
json_data_status_config_output_expected = """\
7575
{
7676
"MUX_CABLE": {
7777
"PEER_TOR": "10.2.2.2",
7878
"PORTS": {
79-
"Ethernet32": {
80-
"STATE": "auto",
81-
"SERVER": {
82-
"IPv4": "10.1.1.1",
83-
"IPv6": "fc00::75"
84-
}
85-
},
8679
"Ethernet0": {
8780
"STATE": "active",
8881
"SERVER": {
@@ -110,6 +103,13 @@
110103
"IPv4": "10.4.1.1",
111104
"IPv6": "e802::46"
112105
}
106+
},
107+
"Ethernet32": {
108+
"STATE": "auto",
109+
"SERVER": {
110+
"IPv4": "10.1.1.1",
111+
"IPv6": "fc00::75"
112+
}
113113
}
114114
}
115115
}

0 commit comments

Comments
 (0)