Skip to content

Commit ef55364

Browse files
authored
SSD Health: Retrieve SSD health and temperature values from generic SSD info (#229)
The problem: The current SSD health API uses a SSD vendor specific utility to retrieve values for overall SSD health and internal SSD temperature. These utilities are typically made available only in binary form and are not always available for all platform architectures (amd64, arm64, armhf, etc.) Vendor licensing agreements can prevent the inclusion of utility source code in the Sonic build. The solution presented here is to retrieve SSD health and temperature values from the generic SSD info retrieved via the open-source smartmontools utility (smartctl). These values can be overwritten with values retrieved using a vendor specific utility when available. smartmontools is already included in the Sonic source tree and is being built for all platform architectures.
1 parent 26c8346 commit ef55364

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sonic_platform_base/sonic_ssd/ssd_generic.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def __init__(self, diskdev):
6363
def _execute_shell(self, cmd):
6464
process = subprocess.Popen(cmd.split(), universal_newlines=True, stdout=subprocess.PIPE)
6565
output, error = process.communicate()
66+
exit_code = process.returncode
67+
if exit_code:
68+
return None
6669
return output
6770

6871
def _parse_re(self, pattern, buffer):
@@ -72,10 +75,13 @@ def _parse_re(self, pattern, buffer):
7275
def fetch_generic_ssd_info(self, diskdev):
7376
self.ssd_info = self._execute_shell(self.vendor_ssd_utility["Generic"]["utility"].format(diskdev))
7477

78+
# Health and temperature values may be overwritten with vendor specific data
7579
def parse_generic_ssd_info(self):
7680
self.model = self._parse_re('Device Model:\s*(.+?)\n', self.ssd_info)
7781
self.serial = self._parse_re('Serial Number:\s*(.+?)\n', self.ssd_info)
7882
self.firmware = self._parse_re('Firmware Version:\s*(.+?)\n', self.ssd_info)
83+
self.health = self._parse_re('Remaining_Lifetime_Perc\s*(.+?)\n', self.ssd_info).split()[-1]
84+
self.temperature = self._parse_re('Temperature_Celsius\s*(.+?)\n', self.ssd_info).split()[-6]
7985

8086
def parse_innodisk_info(self):
8187
self.health = self._parse_re('Health:\s*(.+?)%', self.vendor_ssd_info)
@@ -94,7 +100,8 @@ def fetch_vendor_ssd_info(self, diskdev, model):
94100
self.vendor_ssd_info = self._execute_shell(self.vendor_ssd_utility[model]["utility"].format(diskdev))
95101

96102
def parse_vendor_ssd_info(self, model):
97-
self.vendor_ssd_utility[model]["parser"]()
103+
if self.vendor_ssd_info:
104+
self.vendor_ssd_utility[model]["parser"]()
98105

99106
def get_health(self):
100107
"""

0 commit comments

Comments
 (0)