forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
17 changed files
with
364 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/python3 | ||
|
||
''' | ||
Script to show Voltage and Current Sensor status. | ||
''' | ||
from tabulate import tabulate | ||
from natsort import natsorted | ||
import argparse | ||
import os | ||
import sys | ||
|
||
# mock the redis for unit test purposes # | ||
try: | ||
if os.environ["UTILITIES_UNIT_TESTING"] == "1": | ||
modules_path = os.path.join(os.path.dirname(__file__), "..") | ||
test_path = os.path.join(modules_path, "tests") | ||
sys.path.insert(0, modules_path) | ||
sys.path.insert(0, test_path) | ||
import mock_tables.dbconnector | ||
except KeyError: | ||
pass | ||
|
||
from swsscommon.swsscommon import SonicV2Connector | ||
|
||
header = ['Sensor', '', 'High TH', 'Low TH', 'Crit High TH', 'Crit Low TH', 'Warning', 'Timestamp'] | ||
|
||
TIMESTAMP_FIELD_NAME = 'timestamp' | ||
UNIT_FIELD_NAME = 'unit' | ||
HIGH_THRESH_FIELD_NAME = 'high_threshold' | ||
LOW_THRESH_FIELD_NAME = 'low_threshold' | ||
CRIT_HIGH_THRESH_FIELD_NAME = 'critical_high_threshold' | ||
CRIT_LOW_THRESH_FIELD_NAME = 'critical_low_threshold' | ||
WARNING_STATUS_FIELD_NAME = 'warning_status' | ||
VOLTAGE_INFO_TABLE_NAME = 'VOLTAGE_INFO' | ||
CURRENT_INFO_TABLE_NAME = 'CURRENT_INFO' | ||
|
||
|
||
class SensorShow(object): | ||
def __init__(self, type): | ||
self.db = SonicV2Connector(use_unix_socket_path=True) | ||
self.db.connect(self.db.STATE_DB) | ||
self.field_name = type | ||
header[1] = type.capitalize() | ||
|
||
if type == "voltage": | ||
self.table_name = VOLTAGE_INFO_TABLE_NAME | ||
else: | ||
self.table_name = CURRENT_INFO_TABLE_NAME | ||
|
||
def show(self): | ||
keys = self.db.keys(self.db.STATE_DB, self.table_name + '*') | ||
if not keys: | ||
print('Sensor not detected') | ||
return | ||
|
||
table = [] | ||
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(self.table_name, key)) | ||
continue | ||
|
||
name = key_list[1] | ||
data_dict = self.db.get_all(self.db.STATE_DB, key) | ||
#print(name, data_dict) | ||
table.append((name, | ||
"{} {}".format(data_dict[self.field_name], data_dict[UNIT_FIELD_NAME]), | ||
data_dict[HIGH_THRESH_FIELD_NAME], | ||
data_dict[LOW_THRESH_FIELD_NAME], | ||
data_dict[CRIT_HIGH_THRESH_FIELD_NAME], | ||
data_dict[CRIT_LOW_THRESH_FIELD_NAME], | ||
data_dict[WARNING_STATUS_FIELD_NAME], | ||
data_dict[TIMESTAMP_FIELD_NAME] | ||
)) | ||
|
||
if table: | ||
print(tabulate(table, header, tablefmt='simple', stralign='right')) | ||
else: | ||
print('No sensor data available') | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-t", "--type", help="sensor type", required=True, choices=['voltage', 'current']) | ||
args = parser.parse_args() | ||
|
||
sensor_show = SensorShow(args.type) | ||
sensor_show.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
tests/db_migrator_input/state_db/fast_reboot_upgrade_from_202205.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"FAST_RESTART_ENABLE_TABLE|system": { | ||
"enable": "true" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.