From 301287ec49c7edcc2922740be6cfd58275be5dad Mon Sep 17 00:00:00 2001 From: hantienEdgecore Date: Wed, 17 Aug 2022 15:59:08 +0800 Subject: [PATCH 1/3] [ssd_generic]Fix ssd no vendor information The ssd information can show correctly even if can't get model information in generic SSD information. When unknown model name , use Virtuim tool to get SSD Health/Temperature . How has this been Tested ? Manual testing on Edgecore switch (ex AS4630_54PE) --- sonic_platform_base/sonic_ssd/ssd_generic.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sonic_platform_base/sonic_ssd/ssd_generic.py b/sonic_platform_base/sonic_ssd/ssd_generic.py index 8d38d11e0..e9a52158f 100644 --- a/sonic_platform_base/sonic_ssd/ssd_generic.py +++ b/sonic_platform_base/sonic_ssd/ssd_generic.py @@ -57,8 +57,9 @@ def __init__(self, diskdev): self.fetch_vendor_ssd_info(diskdev, model_short) self.parse_vendor_ssd_info(model_short) else: - # No handler registered for this disk model - pass + # unknown model name , use Virtium to get information + self.vendor_ssd_info =self._execute_shell(self.vendor_ssd_utility["Virtium"]["utility"].format(diskdev)) + self.parse_virtium_info() else: # Failed to get disk model self.model = "Unknown" @@ -124,20 +125,22 @@ def parse_innodisk_info(self): self.temperature = temp_raw.split()[-6] def parse_virtium_info(self): - if self.vendor_ssd_info: - self.temperature = self._parse_re('Temperature_Celsius\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info) + self.temperature = self._parse_re('Temperature_Celsius\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info) + self.health = self._parse_re('Remaining_Life_Left\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info) + if self.health == NOT_AVAILABLE: nand_endurance = self._parse_re('NAND_Endurance\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info) avg_erase_count = self._parse_re('Average_Erase_Count\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info) try: self.health = 100 - (float(avg_erase_count) * 100 / float(nand_endurance)) - except (ValueError, ZeroDivisionError): + except ValueError: pass def fetch_vendor_ssd_info(self, diskdev, model): self.vendor_ssd_info = self._execute_shell(self.vendor_ssd_utility[model]["utility"].format(diskdev)) def parse_vendor_ssd_info(self, model): - self.vendor_ssd_utility[model]["parser"]() + if self.vendor_ssd_info: + self.vendor_ssd_utility[model]["parser"]() def get_health(self): """ From 9ba0f70f143b44b437342f555cd134dc07e3ebe5 Mon Sep 17 00:00:00 2001 From: hantienEdgecore Date: Tue, 7 Mar 2023 10:57:33 +0800 Subject: [PATCH 2/3] [ssd_generic_test]Update test case for ssd_generic.py modify --- tests/ssd_generic_test.py | 78 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 6 deletions(-) diff --git a/tests/ssd_generic_test.py b/tests/ssd_generic_test.py index 73e89281c..3a20515c8 100644 --- a/tests/ssd_generic_test.py +++ b/tests/ssd_generic_test.py @@ -1,4 +1,3 @@ - import sys if sys.version_info.major == 3: from unittest import mock @@ -71,6 +70,74 @@ Num ErrCount SQId CmdId Status PELoc LBA NSID VS 0 5275 0 0x0001 0x0004 - 0 1 -""" +output_SmartCmd_info = """SmartCmd -m /dev/sda +SMART attributes + ID Attribute High Raw Low Raw Value Worst Threshold + 1 Raw_Read_Error_Rate 0 0 100 100 0 + 5 Reserved_Attribute 0 0 100 100 0 + 9 Power_On_Hours 0 624 100 100 0 + 12 Power_Cycle_Count 0 113 100 100 0 +160 Uncorrectable_Sector_Count 0 0 100 100 0 +161 Valid_Spare_Block 0 45 100 100 0 +163 Reserved_Attribute 0 23 100 100 0 +164 Reserved_Attribute 0 128531 100 100 0 +165 Maximum_Erase_Count 0 160 100 100 0 +166 Reserved_Attribute 0 60 100 100 0 +167 Average_Erase_Count 0 126 100 100 0 +168 NAND_Endurance 0 3000 100 100 0 +169 Remaining_Life_Left 0 100 100 100 0 +175 Reserved_Attribute 0 0 100 100 0 +176 Reserved_Attribute 0 0 100 100 0 +177 Reserved_Attribute 0 20 100 100 50 +178 Reserved_Attribute 0 0 100 100 0 +181 Total_Program_Fail 0 0 100 100 0 +182 Total_Erase_Fail 0 0 100 100 0 +192 Sudden_Power_Lost_Count 0 47 100 100 0 +194 Temperature_Celsius 0 37 100 100 0 +195 Hardware_ECC_Recovered 0 1063 100 100 0 +196 Reallocated_Event_Count 0 0 100 100 16 +197 Current_Pending_Sector_Count 0 0 100 100 0 +198 Reserved_Attribute 0 0 100 100 0 +199 UDMA_CRC_Error_Count 0 0 100 100 50 +232 Reserved_Attribute 0 100 100 100 0 +241 Total_LBAs_Written 0 79687 100 100 0 +242 Total_LBAs_Read 0 51039 100 100 0 +245 Reserved_Attribute 0 128531 100 100 0 """ + +output_SmartCmd_info_2 = """SmartCmd -m /dev/sda +SMART attributes + ID Attribute High Raw Low Raw Value Worst Threshold + 1 Raw_Read_Error_Rate 0 0 100 100 0 + 5 Reserved_Attribute 0 0 100 100 0 + 9 Power_On_Hours 0 624 100 100 0 + 12 Power_Cycle_Count 0 113 100 100 0 +160 Uncorrectable_Sector_Count 0 0 100 100 0 +161 Valid_Spare_Block 0 45 100 100 0 +163 Reserved_Attribute 0 23 100 100 0 +164 Reserved_Attribute 0 128531 100 100 0 +165 Maximum_Erase_Count 0 160 100 100 0 +166 Reserved_Attribute 0 60 100 100 0 +167 Average_Erase_Count 0 126 100 100 0 +168 NAND_Endurance 0 3000 100 100 0 +169 Remaining_Life_Left 0 95 100 100 0 +175 Reserved_Attribute 0 0 100 100 0 +176 Reserved_Attribute 0 0 100 100 0 +177 Reserved_Attribute 0 20 100 100 50 +178 Reserved_Attribute 0 0 100 100 0 +181 Total_Program_Fail 0 0 100 100 0 +182 Total_Erase_Fail 0 0 100 100 0 +192 Sudden_Power_Lost_Count 0 47 100 100 0 +194 Temperature_Celsius 0 30 100 100 0 +195 Hardware_ECC_Recovered 0 1063 100 100 0 +196 Reallocated_Event_Count 0 0 100 100 16 +197 Current_Pending_Sector_Count 0 0 100 100 0 +198 Reserved_Attribute 0 0 100 100 0 +199 UDMA_CRC_Error_Count 0 0 100 100 50 +232 Reserved_Attribute 0 100 100 100 0 +241 Total_LBAs_Written 0 79687 100 100 0 +242 Total_LBAs_Read 0 51039 100 100 0 +245 Reserved_Attribute 0 128531 100 100 0 """ + output_ssd = """smartctl 6.6 2017-11-05 r4594 [x86_64-linux-5.10.0-8-2-amd64] (local build) Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org @@ -345,14 +412,14 @@ """ class TestSsdGeneric: - @mock.patch('sonic_platform_base.sonic_ssd.ssd_generic.SsdUtil._execute_shell', mock.MagicMock(return_value=output_nvme_ssd)) + @mock.patch('sonic_platform_base.sonic_ssd.ssd_generic.SsdUtil._execute_shell', mock.MagicMock(side_effect=[output_nvme_ssd,output_SmartCmd_info])) def test_nvme_ssd(self): # Test parsing nvme ssd info nvme_ssd = SsdUtil('/dev/nvme0n1') - assert(nvme_ssd.get_health() == 100.0) + assert(nvme_ssd.get_health() == '100') assert(nvme_ssd.get_model() == 'SFPC020GM1EC2TO-I-5E-11P-STD') assert(nvme_ssd.get_firmware() == "COT6OQ") - assert(nvme_ssd.get_temperature() == 37) + assert(nvme_ssd.get_temperature() == '37') assert(nvme_ssd.get_serial() == "A0221030722410000027") @mock.patch('sonic_platform_base.sonic_ssd.ssd_generic.SsdUtil._execute_shell', mock.MagicMock(return_value=output_lack_info_ssd)) @@ -365,7 +432,7 @@ def test_nvme_ssd_with_na_path(self): assert(nvme_ssd.get_temperature() == "N/A") assert(nvme_ssd.get_serial() == "N/A") - @mock.patch('sonic_platform_base.sonic_ssd.ssd_generic.SsdUtil._execute_shell', mock.MagicMock(return_value=output_ssd)) + @mock.patch('sonic_platform_base.sonic_ssd.ssd_generic.SsdUtil._execute_shell', mock.MagicMock(side_effect=[output_ssd,output_SmartCmd_info_2])) def test_ssd(self): # Test parsing a normal ssd info ssd = SsdUtil('/dev/sda') @@ -411,4 +478,3 @@ def test_Innodisk_missing_names_ssd(self): Innodisk_ssd.parse_vendor_ssd_info('InnoDisk') assert(Innodisk_ssd.get_health() == '94') assert(Innodisk_ssd.get_temperature() == '39') - From f5cafd24b1428e2daa3d0ec72e36a1ac94403e50 Mon Sep 17 00:00:00 2001 From: hantienEdgecore Date: Thu, 9 Mar 2023 09:43:08 +0800 Subject: [PATCH 3/3] [ssd_generic_test] fix ssd_generic_test.py test fail case --- tests/ssd_generic_test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/ssd_generic_test.py b/tests/ssd_generic_test.py index ae6d4b445..eb80bf339 100644 --- a/tests/ssd_generic_test.py +++ b/tests/ssd_generic_test.py @@ -671,7 +671,7 @@ def test_Innodisk_missing_names_ssd(self): def test_virtium_ssd(self, mock_exec): mock_exec.side_effect = [output_virtium_generic, output_virtium_vendor] virtium_ssd = SsdUtil('/dev/sda') - assert virtium_ssd.get_health() == 1 + assert virtium_ssd.get_health() == '1' assert virtium_ssd.get_model() == 'VSFDM8XC240G-V11-T' assert virtium_ssd.get_firmware() == "0913-000" assert virtium_ssd.get_temperature() == '34' @@ -679,7 +679,7 @@ def test_virtium_ssd(self, mock_exec): mock_exec.side_effect = [output_virtium_generic, output_virtium_no_remain_life] virtium_ssd = SsdUtil('/dev/sda') - assert virtium_ssd.get_health() == 99.42 + assert virtium_ssd.get_health() == '100' mock_exec.side_effect = [output_virtium_generic, output_virtium_invalid_nand_endurance] virtium_ssd = SsdUtil('/dev/sda') @@ -689,3 +689,4 @@ def test_virtium_ssd(self, mock_exec): virtium_ssd = SsdUtil('/dev/sda') assert virtium_ssd.get_health() == "N/A" +