Skip to content

Commit

Permalink
Add psu hardware revision to psushow table (sonic-net#1601)
Browse files Browse the repository at this point in the history
- What I did
Added a field for hardware revision to the psushow output table.

- How I did it
Defined new psu status field sourced from "revision" field in STATE_DB added in alexrallen/sonic-platform-daemons#1 and adds it to the table output with the header "HW Rev"

All relevant unit tests were also updated.

- How to verify it
Execute show platform psustatus and verify that "HW Rev" column is present and appropriately populated depending on the platform.
  • Loading branch information
alexrallen authored May 23, 2021
1 parent f1726fe commit e23c5ee
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
7 changes: 3 additions & 4 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -775,10 +775,9 @@ This command displays the status of the device's power supply units
- Example:
```
admin@sonic:~$ show platform psustatus
PSU Status
----- --------
PSU 1 OK
PSU 2 OK
PSU Model Serial HW Rev Voltage (V) Current (A) Power (W) Status LED
----- ------------- ------------ -------- ------------- ------------- ----------- -------- -----
PSU 1 MTEF-PSF-AC-A MT1621X15246 A3 11.97 4.56 54.56 OK green
```

**show platform fan**
Expand Down
4 changes: 3 additions & 1 deletion scripts/psushow
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def get_psu_status_list():

psu_status['model'] = db.get(db.STATE_DB, 'PSU_INFO|{}'.format(psu_name), 'model') if presence else 'N/A'
psu_status['serial'] = db.get(db.STATE_DB, 'PSU_INFO|{}'.format(psu_name), 'serial') if presence else 'N/A'
psu_status['revision'] = db.get(db.STATE_DB, 'PSU_INFO|{}'.format(psu_name), 'revision') if presence else 'N/A'
psu_status['voltage'] = db.get(db.STATE_DB, 'PSU_INFO|{}'.format(psu_name), 'voltage') if presence else 'N/A'
psu_status['current'] = db.get(db.STATE_DB, 'PSU_INFO|{}'.format(psu_name), 'current') if presence else 'N/A'
psu_status['power'] = db.get(db.STATE_DB, 'PSU_INFO|{}'.format(psu_name), 'power') if presence else 'N/A'
Expand All @@ -63,7 +64,7 @@ def psu_status_show_table(index):
print('Error: Failed to get PSU status')
return None

header = ['PSU', 'Model', 'Serial', 'Voltage (V)', 'Current (A)', 'Power (W)', 'Status', 'LED']
header = ['PSU', 'Model', 'Serial', 'HW Rev', 'Voltage (V)', 'Current (A)', 'Power (W)', 'Status', 'LED']
status_table = []

if index > 0:
Expand All @@ -78,6 +79,7 @@ def psu_status_show_table(index):
status_table.append([psu_status['name'],
psu_status['model'],
psu_status['serial'],
psu_status['revision'],
psu_status['voltage'],
psu_status['current'],
psu_status['power'],
Expand Down
2 changes: 2 additions & 0 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"status": "true",
"model": "0J6J4K",
"serial": "CN-0J6J4K-17972-5AF-0086-A00",
"revision": "1",
"temp": "None",
"temp_threshold": "None",
"voltage": "12.19",
Expand All @@ -156,6 +157,7 @@
"status": "true",
"model": "0J6J4K",
"serial": "CN-0J6J4K-17972-5AF-008M-A00",
"revision": "A",
"temp": "None",
"temp_threshold": "None",
"voltage": "12.18",
Expand Down
26 changes: 16 additions & 10 deletions tests/psushow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_get_psu_status_list(self):
'led_status': 'green',
'model': '0J6J4K',
'serial': 'CN-0J6J4K-17972-5AF-0086-A00',
'revision': '1',
'voltage': '12.19',
'current': '8.37',
'power': '102.7'
Expand All @@ -46,6 +47,7 @@ def test_get_psu_status_list(self):
'led_status': 'green',
'model': '0J6J4K',
'serial': 'CN-0J6J4K-17972-5AF-008M-A00',
'revision': 'A',
'voltage': '12.18',
'current': '10.07',
'power': '122.0'
Expand All @@ -57,10 +59,10 @@ def test_get_psu_status_list(self):

def test_status_table(self, capsys):
expected_output = '''\
PSU Model Serial Voltage (V) Current (A) Power (W) Status LED
----- ------- ---------------------------- ------------- ------------- ----------- -------- -----
PSU 1 0J6J4K CN-0J6J4K-17972-5AF-0086-A00 12.19 8.37 102.70 OK green
PSU 2 0J6J4K CN-0J6J4K-17972-5AF-008M-A00 12.18 10.07 122.00 OK green
PSU Model Serial HW Rev Voltage (V) Current (A) Power (W) Status LED
----- ------- ---------------------------- -------- ------------- ------------- ----------- -------- -----
PSU 1 0J6J4K CN-0J6J4K-17972-5AF-0086-A00 1 12.19 8.37 102.70 OK green
PSU 2 0J6J4K CN-0J6J4K-17972-5AF-008M-A00 A 12.18 10.07 122.00 OK green
'''
for arg in ['-s', '--status']:
with mock.patch('sys.argv', ['psushow', arg]):
Expand All @@ -70,9 +72,9 @@ def test_status_table(self, capsys):
assert captured.out == expected_output

expected_output = '''\
PSU Model Serial Voltage (V) Current (A) Power (W) Status LED
----- ------- ---------------------------- ------------- ------------- ----------- -------- -----
PSU 1 0J6J4K CN-0J6J4K-17972-5AF-0086-A00 12.19 8.37 102.70 OK green
PSU Model Serial HW Rev Voltage (V) Current (A) Power (W) Status LED
----- ------- ---------------------------- -------- ------------- ------------- ----------- -------- -----
PSU 1 0J6J4K CN-0J6J4K-17972-5AF-0086-A00 1 12.19 8.37 102.70 OK green
'''
for arg in ['-s', '--status']:
with mock.patch('sys.argv', ['psushow', arg, '-i', '1']):
Expand All @@ -82,9 +84,9 @@ def test_status_table(self, capsys):
assert captured.out == expected_output

expected_output = '''\
PSU Model Serial Voltage (V) Current (A) Power (W) Status LED
----- ------- ---------------------------- ------------- ------------- ----------- -------- -----
PSU 2 0J6J4K CN-0J6J4K-17972-5AF-008M-A00 12.18 10.07 122.00 OK green
PSU Model Serial HW Rev Voltage (V) Current (A) Power (W) Status LED
----- ------- ---------------------------- -------- ------------- ------------- ----------- -------- -----
PSU 2 0J6J4K CN-0J6J4K-17972-5AF-008M-A00 A 12.18 10.07 122.00 OK green
'''
for arg in ['-s', '--status']:
with mock.patch('sys.argv', ['psushow', arg, '-i', '2']):
Expand Down Expand Up @@ -116,6 +118,7 @@ def test_status_json(self, capsys):
"led_status": "green",
"model": "0J6J4K",
"serial": "CN-0J6J4K-17972-5AF-0086-A00",
"revision": "1",
"voltage": "12.19",
"current": "8.37",
"power": "102.7"
Expand All @@ -128,6 +131,7 @@ def test_status_json(self, capsys):
"led_status": "green",
"model": "0J6J4K",
"serial": "CN-0J6J4K-17972-5AF-008M-A00",
"revision": "A",
"voltage": "12.18",
"current": "10.07",
"power": "122.0"
Expand All @@ -151,6 +155,7 @@ def test_status_json(self, capsys):
"led_status": "green",
"model": "0J6J4K",
"serial": "CN-0J6J4K-17972-5AF-0086-A00",
"revision": "1",
"voltage": "12.19",
"current": "8.37",
"power": "102.7"
Expand All @@ -174,6 +179,7 @@ def test_status_json(self, capsys):
"led_status": "green",
"model": "0J6J4K",
"serial": "CN-0J6J4K-17972-5AF-008M-A00",
"revision": "A",
"voltage": "12.18",
"current": "10.07",
"power": "122.0"
Expand Down

0 comments on commit e23c5ee

Please sign in to comment.