From 6f514280e2af564af9d20f34d667d8181c31a698 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Thu, 26 Mar 2020 02:02:17 +0800 Subject: [PATCH] [Mellanox] Fix thermal control issue: use natural sort for fan status and thermal status (#836) * [thermal fix] use natural sort for fan status and thermal status * [thermal fix] set fan status to N/A when fan is removed * Adjust header name for show platform temperature output --- scripts/fanshow | 12 ++++++++---- scripts/tempershow | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/fanshow b/scripts/fanshow index 75ad576cd4..81d0a9e2d8 100644 --- a/scripts/fanshow +++ b/scripts/fanshow @@ -8,6 +8,7 @@ import argparse from tabulate import tabulate from swsssdk import SonicV2Connector +from natsort import natsorted header = ['FAN', 'Speed', 'Direction', 'Presence', 'Status', 'Timestamp'] @@ -32,7 +33,7 @@ class FanShow(object): return table = [] - for key in keys: + for key in natsorted(keys): key_list = key.split('|') if len(key_list) != 2: # error data in DB, log it and ignore print('Warn: Invalid key in table FAN_INFO: {}'.format(key)) @@ -47,18 +48,21 @@ class FanShow(object): else: speed = '{}%'.format(data_dict[SPEED_FIELD_NAME]) except ValueError as e: - print('Warn: cannot convert speed value from {}'.format(data_dict[SPEED_FIELD_NAME])) speed = data_dict[SPEED_FIELD_NAME] presence = data_dict[PRESENCE_FIELD_NAME].lower() presence = 'Present' if presence == 'true' else 'Not Present' status = data_dict[STATUS_FIELD_NAME].lower() - status = 'OK' if status == 'true' else 'Not OK' + if status == 'true': + status = 'OK' + elif status == 'false': + status = 'Not OK' + else: + status = 'N/A' table.append((name, speed, data_dict[DIRECTION_FIELD_NAME], presence, status, data_dict[TIMESTAMP_FIELD_NAME])) if table: - table.sort() print(tabulate(table, header, tablefmt='simple', stralign='right')) else: print('No fan status data available\n') diff --git a/scripts/tempershow b/scripts/tempershow index d8ba6a645b..aabc4943ed 100644 --- a/scripts/tempershow +++ b/scripts/tempershow @@ -8,9 +8,10 @@ import argparse from tabulate import tabulate from swsssdk import SonicV2Connector +from natsort import natsorted -header = ['NAME', 'Temperature', 'High Threshold', 'Low Threshold', 'Critical High Threshold', 'Critical Low Threshold', 'Warning Status', 'Timestamp'] +header = ['Sensor', 'Temperature', 'High TH', 'Low TH', 'Crit High TH', 'Crit Low TH', 'Warning', 'Timestamp'] TEMPER_TABLE_NAME = 'TEMPERATURE_INFO' TEMPER_FIELD_NAME = 'temperature' @@ -34,7 +35,7 @@ class TemperShow(object): return table = [] - for key in keys: + for key in natsorted(keys): key_list = key.split('|') if len(key_list) != 2: # error data in DB, log it and ignore print('Warn: Invalid key in table {}: {}'.format(TEMPER_TABLE_NAME, key)) @@ -53,7 +54,6 @@ class TemperShow(object): )) if table: - table.sort() print(tabulate(table, header, tablefmt='simple', stralign='right')) else: print('No tempeature data available\n')