Skip to content

Commit c2ac2d2

Browse files
authored
[show] fix show muxcable metrics <port> for sorted output (sonic-net#1731)
This PR fixes the display for show muxcable metrics by sorting the output based on the time of the event. This is required for better display. For example admin@str2-7050cx3-acs-12:~$ show mux metrics Ethernet0 PORT EVENT TIME --------- --------------------------- --------------------------- Ethernet0 xcvrd_switch_standby_start 2021-Jul-21 02:03:28.784027 Ethernet0 orch_switch_standby_end 2021-Jul-21 02:03:28.788150 Ethernet0 linkmgrd_switch_standby_end 2021-Jul-21 02:03:28.790288 Signed-off-by: vaibhav-dahiya <[email protected]>
1 parent 4422911 commit c2ac2d2

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

show/muxcable.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import re
77
import utilities_common.cli as clicommon
88
from natsort import natsorted
9+
from collections import OrderedDict
10+
from operator import itemgetter
911
from sonic_py_common import multi_asic
1012
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
1113
from swsscommon import swsscommon
@@ -1003,11 +1005,12 @@ def metrics(db, port, json_output):
10031005
metrics_dict[asic_index] = per_npu_statedb[asic_index].get_all(
10041006
per_npu_statedb[asic_index].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))
10051007

1008+
ordered_dict = OrderedDict(sorted(metrics_dict[asic_index].items(), key=itemgetter(1)))
10061009
if json_output:
1007-
click.echo("{}".format(json.dumps(metrics_dict[asic_index], indent=4)))
1010+
click.echo("{}".format(json.dumps(ordered_dict, indent=4)))
10081011
else:
10091012
print_data = []
1010-
for key, val in metrics_dict[asic_index].items():
1013+
for key, val in ordered_dict.items():
10111014
print_port_data = []
10121015
print_port_data.append(port)
10131016
print_port_data.append(key)

tests/muxcable_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,17 @@
209209
PORT EVENT TIME
210210
--------- ---------------------------- ---------------------------
211211
Ethernet0 linkmgrd_switch_active_start 2021-May-13 10:00:21.420898
212-
Ethernet0 linkmgrd_switch_standby_end 2021-May-13 10:01:15.696728
213-
Ethernet0 xcvrd_switch_standby_end 2021-May-13 10:01:15.696051
214212
Ethernet0 xcvrd_switch_standby_start 2021-May-13 10:01:15.690835
213+
Ethernet0 xcvrd_switch_standby_end 2021-May-13 10:01:15.696051
214+
Ethernet0 linkmgrd_switch_standby_end 2021-May-13 10:01:15.696728
215215
"""
216216

217217
show_muxcable_metrics_expected_output_json = """\
218218
{
219219
"linkmgrd_switch_active_start": "2021-May-13 10:00:21.420898",
220-
"linkmgrd_switch_standby_end": "2021-May-13 10:01:15.696728",
220+
"xcvrd_switch_standby_start": "2021-May-13 10:01:15.690835",
221221
"xcvrd_switch_standby_end": "2021-May-13 10:01:15.696051",
222-
"xcvrd_switch_standby_start": "2021-May-13 10:01:15.690835"
222+
"linkmgrd_switch_standby_end": "2021-May-13 10:01:15.696728"
223223
}
224224
"""
225225

0 commit comments

Comments
 (0)