|
| 1 | + |
| 2 | +import sys |
| 3 | +if sys.version_info.major == 3: |
| 4 | + from unittest import mock |
| 5 | +else: |
| 6 | + import mock |
| 7 | + |
| 8 | +from sonic_platform_base.sonic_ssd.ssd_generic import SsdUtil |
| 9 | + |
| 10 | +output_nvme_ssd = """smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.10.0-8-2-amd64] (local build) |
| 11 | +Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org |
| 12 | +
|
| 13 | +=== START OF INFORMATION SECTION === |
| 14 | +Model Number: SFPC020GM1EC2TO-I-5E-11P-STD |
| 15 | +Serial Number: A0221030722410000027 |
| 16 | +Firmware Version: COT6OQ |
| 17 | +PCI Vendor/Subsystem ID: 0x1dd4 |
| 18 | +IEEE OUI Identifier: 0x8c6078 |
| 19 | +Controller ID: 1 |
| 20 | +NVMe Version: 1.3 |
| 21 | +Number of Namespaces: 1 |
| 22 | +Namespace 1 Size/Capacity: 20,014,718,976 [20.0 GB] |
| 23 | +Namespace 1 Formatted LBA Size: 512 |
| 24 | +Namespace 1 IEEE EUI-64: 486834 133070001b |
| 25 | +Local Time is: Tue Mar 1 06:35:23 2022 UTC |
| 26 | +Firmware Updates (0x12): 1 Slot, no Reset required |
| 27 | +Optional Admin Commands (0x0016): Format Frmw_DL Self_Test |
| 28 | +Optional NVM Commands (0x001f): Comp Wr_Unc DS_Mngmt Wr_Zero Sav/Sel_Feat |
| 29 | +Log Page Attributes (0x0e): Cmd_Eff_Lg Ext_Get_Lg Telmtry_Lg |
| 30 | +Maximum Data Transfer Size: 64 Pages |
| 31 | +Warning Comp. Temp. Threshold: 105 Celsius |
| 32 | +Critical Comp. Temp. Threshold: 120 Celsius |
| 33 | +
|
| 34 | +Supported Power States |
| 35 | +St Op Max Active Idle RL RT WL WT Ent_Lat Ex_Lat |
| 36 | + 0 + 3.50W - - 0 0 0 0 0 0 |
| 37 | + 1 + 2.50W - - 1 1 1 1 0 0 |
| 38 | + 2 + 1.50W - - 2 2 2 2 0 0 |
| 39 | + 3 - 0.0200W - - 3 3 3 3 2200 3000 |
| 40 | + 4 - 0.0100W - - 4 4 4 4 15000 12000 |
| 41 | +
|
| 42 | +Supported LBA Sizes (NSID 0x1) |
| 43 | +Id Fmt Data Metadt Rel_Perf |
| 44 | + 0 + 512 0 0 |
| 45 | +
|
| 46 | +=== START OF SMART DATA SECTION === |
| 47 | +SMART overall-health self-assessment test result: PASSED |
| 48 | +
|
| 49 | +SMART/Health Information (NVMe Log 0x02) |
| 50 | +Critical Warning: 0x00 |
| 51 | +Temperature: 37 Celsius |
| 52 | +Available Spare: 100% |
| 53 | +Available Spare Threshold: 10% |
| 54 | +Percentage Used: 0% |
| 55 | +Data Units Read: 1,546,369 [791 GB] |
| 56 | +Data Units Written: 7,118,163 [3.64 TB] |
| 57 | +Host Read Commands: 27,027,268 |
| 58 | +Host Write Commands: 87,944,082 |
| 59 | +Controller Busy Time: 5,660 |
| 60 | +Power Cycles: 455 |
| 61 | +Power On Hours: 3,638 |
| 62 | +Unsafe Shutdowns: 435 |
| 63 | +Media and Data Integrity Errors: 0 |
| 64 | +Error Information Log Entries: 5,275 |
| 65 | +Warning Comp. Temperature Time: 0 |
| 66 | +Critical Comp. Temperature Time: 0 |
| 67 | +Temperature Sensor 1: 41 Celsius |
| 68 | +Temperature Sensor 2: 38 Celsius |
| 69 | +
|
| 70 | +Error Information (NVMe Log 0x01, 16 of 64 entries) |
| 71 | +Num ErrCount SQId CmdId Status PELoc LBA NSID VS |
| 72 | + 0 5275 0 0x0001 0x0004 - 0 1 -""" |
| 73 | + |
| 74 | +class TestSsdGeneric: |
| 75 | + @mock.patch('sonic_platform_base.sonic_ssd.ssd_generic.SsdUtil._execute_shell', mock.MagicMock(return_value=output_nvme_ssd)) |
| 76 | + def test_nvme_ssd(self): |
| 77 | + nvme_ssd = SsdUtil('/dev/nvme0n1') |
| 78 | + assert(nvme_ssd.get_health() == 100.0) |
| 79 | + assert(nvme_ssd.get_model() == 'SFPC020GM1EC2TO-I-5E-11P-STD') |
| 80 | + assert(nvme_ssd.get_firmware() == "COT6OQ") |
| 81 | + assert(nvme_ssd.get_temperature() == 37) |
| 82 | + assert(nvme_ssd.get_serial() == "A0221030722410000027") |
| 83 | + |
| 84 | + |
0 commit comments