Skip to content

Commit

Permalink
[Mellanox] Fix thermal control issue: use natural sort for fan status…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Junchao-Mellanox committed Mar 25, 2020
1 parent 51d26ce commit 6f51428
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions scripts/fanshow
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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))
Expand All @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions scripts/tempershow
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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))
Expand All @@ -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')
Expand Down

0 comments on commit 6f51428

Please sign in to comment.