Skip to content

Commit

Permalink
[show] fix show muxcable metrics <port> for sorted output (#1731)
Browse files Browse the repository at this point in the history
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 <vdahiya@microsoft.com>
  • Loading branch information
vdahiya12 committed Jul 28, 2021
1 parent 4422911 commit c2ac2d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import re
import utilities_common.cli as clicommon
from natsort import natsorted
from collections import OrderedDict
from operator import itemgetter
from sonic_py_common import multi_asic
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
from swsscommon import swsscommon
Expand Down Expand Up @@ -1003,11 +1005,12 @@ def metrics(db, port, json_output):
metrics_dict[asic_index] = per_npu_statedb[asic_index].get_all(
per_npu_statedb[asic_index].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))

ordered_dict = OrderedDict(sorted(metrics_dict[asic_index].items(), key=itemgetter(1)))
if json_output:
click.echo("{}".format(json.dumps(metrics_dict[asic_index], indent=4)))
click.echo("{}".format(json.dumps(ordered_dict, indent=4)))
else:
print_data = []
for key, val in metrics_dict[asic_index].items():
for key, val in ordered_dict.items():
print_port_data = []
print_port_data.append(port)
print_port_data.append(key)
Expand Down
8 changes: 4 additions & 4 deletions tests/muxcable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,17 @@
PORT EVENT TIME
--------- ---------------------------- ---------------------------
Ethernet0 linkmgrd_switch_active_start 2021-May-13 10:00:21.420898
Ethernet0 linkmgrd_switch_standby_end 2021-May-13 10:01:15.696728
Ethernet0 xcvrd_switch_standby_end 2021-May-13 10:01:15.696051
Ethernet0 xcvrd_switch_standby_start 2021-May-13 10:01:15.690835
Ethernet0 xcvrd_switch_standby_end 2021-May-13 10:01:15.696051
Ethernet0 linkmgrd_switch_standby_end 2021-May-13 10:01:15.696728
"""

show_muxcable_metrics_expected_output_json = """\
{
"linkmgrd_switch_active_start": "2021-May-13 10:00:21.420898",
"linkmgrd_switch_standby_end": "2021-May-13 10:01:15.696728",
"xcvrd_switch_standby_start": "2021-May-13 10:01:15.690835",
"xcvrd_switch_standby_end": "2021-May-13 10:01:15.696051",
"xcvrd_switch_standby_start": "2021-May-13 10:01:15.690835"
"linkmgrd_switch_standby_end": "2021-May-13 10:01:15.696728"
}
"""

Expand Down

0 comments on commit c2ac2d2

Please sign in to comment.