| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2025 Red Hat, Inc. |
| 5 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
|
| 7 |
|
| 8 |
from sys import stderr |
| 9 |
|
| 10 |
import storagelib |
| 11 |
import testlib |
| 12 |
|
| 13 |
|
| 14 |
@testlib.skipImage("Debian and Ubuntu does not boot, drive is not detected.", "debian-*", "ubuntu-*") |
| 15 |
class TestStorageSmart(storagelib.StorageSmartCase): |
| 16 |
|
| 17 |
def udisks_mock_smart_supported(self): |
| 18 |
m = self.machine |
| 19 |
# udisks2 version > 2.10.90 is required to mock SMART data on virtual disks |
| 20 |
if m.image.startswith("fedora") or m.image.startswith("rhel") or m.image.startswith("centos"): |
| 21 |
version_str = self.machine.execute("rpm -q udisks2 --qf '%{NAME} %{VERSION}\n'").strip() |
| 22 |
elif m.image.startswith("debian") or m.image.startswith("ubuntu"): |
| 23 |
version_str = self.machine.execute("dpkg-query -f '${Package} ${Version}\n' --show udisks2").strip() |
| 24 |
elif m.image == "arch": |
| 25 |
version_str = self.machine.execute("pacman -Q udisks2").strip() |
| 26 |
else: |
| 27 |
return False |
| 28 |
|
| 29 |
version = tuple(int(v) for v in version_str.split()[1].split('-')[0].split('.')) |
| 30 |
|
| 31 |
return version > (2, 10, 90) |
| 32 |
|
| 33 |
def has_new_libblockdev(self): |
| 34 |
m = self.machine |
| 35 |
|
| 36 |
if m.image.startswith("fedora") or m.image.startswith("rhel") or m.image.startswith("centos"): |
| 37 |
version_str = self.machine.execute("rpm -q libblockdev --qf '%{NAME} %{VERSION}-%{RELEASE}\n'").strip() |
| 38 |
elif m.image.startswith("debian") or m.image.startswith("ubuntu"): |
| 39 |
version_str = self.machine.execute("dpkg-query -f '${Package} ${Version}\n' --show libblockdev").strip() |
| 40 |
elif m.image == "arch": |
| 41 |
version_str = self.machine.execute("pacman -Q libblockdev").strip() |
| 42 |
else: |
| 43 |
return False |
| 44 |
|
| 45 |
base_ver, sub_ver = version_str.split()[1].split('-') |
| 46 |
base_ver = tuple(int(v) for v in base_ver.split('.')) |
| 47 |
# split on `dot` to remove extra info from rpm |
| 48 |
sub_ver = int(sub_ver.split('.')[0]) |
| 49 |
|
| 50 |
if base_ver > (3, 3, 1): |
| 51 |
return True |
| 52 |
elif base_ver == (3, 3, 1) and sub_ver > 1: # copr @storage/udisks-daily |
| 53 |
return True |
| 54 |
elif base_ver == (3, 3, 0) and sub_ver >= 3: |
| 55 |
return True |
| 56 |
else: |
| 57 |
return False |
| 58 |
|
| 59 |
def set_smart_dump(self, name: str, block: str): |
| 60 |
self.machine.execute(f"udisksctl smart-simulate -f /tmp/smart-dumps/{name} -b {block}") |
| 61 |
|
| 62 |
def testSmart(self): |
| 63 |
def check_smart_info(assessment: str, hours: str, status: str, bad_sectors: str | None = None, |
| 64 |
failing_attrs: str | None = None): |
| 65 |
self.assertIn(assessment, b.text(self.card_desc("Device health (SMART)", "Assessment"))) |
| 66 |
b.wait_in_text(self.card_desc("Device health (SMART)", "Power on hours"), hours) |
| 67 |
b.wait_in_text(self.card_desc("Device health (SMART)", "Self-test status"), status) |
| 68 |
if bad_sectors is not None: |
| 69 |
b.wait_in_text(self.card_desc("Device health (SMART)", "Number of bad sectors"), bad_sectors) |
| 70 |
b.wait_visible(self.card_desc("Device health (SMART)", "Number of bad sectors") + " .pf-m-warning") |
| 71 |
if failing_attrs is not None: |
| 72 |
b.wait_in_text(self.card_desc("Device health (SMART)", "Attributes failing"), failing_attrs) |
| 73 |
b.wait_visible(self.card_desc("Device health (SMART)", "Attributes failing") + " .pf-m-warning") |
| 74 |
|
| 75 |
m = self.machine |
| 76 |
b = self.browser |
| 77 |
|
| 78 |
# udisks2 version > 2.10.1 is required to mock SMART data on virtual disks |
| 79 |
if not self.udisks_mock_smart_supported(): |
| 80 |
stderr.write("Image has old udisks2 version, cannot run SMART test.\n") |
| 81 |
return |
| 82 |
|
| 83 |
m.upload(["verify/files/smart-dumps"], "/tmp") |
| 84 |
# Failing disk, storage page is not loaded |
| 85 |
self.set_smart_dump("Maxtor_96147H8--BAC51KJ0--2", "/dev/sda") |
| 86 |
self.login_and_go("/system") |
| 87 |
b.wait_in_text("#smart-status", "1 disk is failing") |
| 88 |
|
| 89 |
self.set_smart_dump("MCCOE64GEMPP--2.9.09", "/dev/sda") |
| 90 |
b.wait_not_present("#smart-status") |
| 91 |
|
| 92 |
# Clicking the link navigates to storage page, failing disk has red icon |
| 93 |
self.set_smart_dump("Maxtor_96147H8--BAC51KJ0--2", "/dev/sda") |
| 94 |
b.wait_in_text("#smart-status", "1 disk is failing") |
| 95 |
b.click("#smart-status a") |
| 96 |
b.enter_page("/storage") |
| 97 |
b.wait_visible(self.card("Storage")) |
| 98 |
b.wait_visible(self.card_row("Storage", name="sda")) |
| 99 |
b.wait_visible(self.card_row("Storage", name="sda") + " .ct-icon-times-circle") |
| 100 |
|
| 101 |
# new disk, no failing sectors |
| 102 |
self.set_smart_dump("MCCOE64GEMPP--2.9.09", "/dev/sda") |
| 103 |
|
| 104 |
b.wait_visible(self.card("Storage")) |
| 105 |
self.click_card_row("Storage", name="sda") |
| 106 |
b.wait_visible(self.card("Device health (SMART)")) |
| 107 |
check_smart_info("Disk is OK", "1 hours", "Successful") |
| 108 |
|
| 109 |
# Disk with running self test |
| 110 |
self.set_smart_dump("SAMSUNG_MMCQE28G8MUP--0VA_VAM08L1Q", "/dev/sda") |
| 111 |
check_smart_info("Disk is OK", "2417 hours", "In progress, 30%") |
| 112 |
|
| 113 |
# Interrupted self test, disk is OK |
| 114 |
self.set_smart_dump("INTEL_SSDSA2MH080G1GC--045C8820", "/dev/sda") |
| 115 |
check_smart_info("Disk is OK", "2309 hours", "Interrupted") |
| 116 |
|
| 117 |
# latest libblockdev builds (since 3.3.0-99) from copr have different behavior when assessing disk as failed |
| 118 |
has_new_libblockdev = self.has_new_libblockdev() |
| 119 |
|
| 120 |
# Aborted self test and has known bad sector (overall assessment is still OK) |
| 121 |
self.set_smart_dump("ST9160821AS--3.CLH", "/dev/sda") |
| 122 |
if has_new_libblockdev: |
| 123 |
check_smart_info("Disk is OK", "556 hours", "Aborted", bad_sectors="1") |
| 124 |
else: |
| 125 |
check_smart_info("Disk is failing", "556 hours", "Aborted", bad_sectors="1") |
| 126 |
|
| 127 |
# Multiple bad sectors |
| 128 |
self.set_smart_dump("Maxtor_96147H8--BAC51KJ0", "/dev/sda") |
| 129 |
if has_new_libblockdev: |
| 130 |
check_smart_info("Disk is OK", "2016 hours", "Successful", bad_sectors="71") |
| 131 |
else: |
| 132 |
check_smart_info("Disk is failing", "2016 hours", "Successful", bad_sectors="71") |
| 133 |
|
| 134 |
# Multiple bad sectors with failing attribute |
| 135 |
self.set_smart_dump("Maxtor_96147H8--BAC51KJ0--2", "/dev/sda") |
| 136 |
check_smart_info("Disk is failing", "2262 hours", "Successful", bad_sectors="71", failing_attrs="1") |
| 137 |
b.wait_visible(self.card_desc("Device health (SMART)", "Assessment") + " .pf-m-danger") |
| 138 |
|
| 139 |
# Check that SMART card is not visible on DVD drive |
| 140 |
b.go("/storage") |
| 141 |
self.click_card_row("Storage", name="sr0") |
| 142 |
b.wait_visible(self.card("Media drive")) |
| 143 |
b.wait_not_present(self.card("Device health (SMART)")) |
| 144 |
|
| 145 |
|
| 146 |
if __name__ == '__main__': |
| 147 |
testlib.test_main() |