import json import unittest from misc.disks import ( LVAttr, WearoutIndicator, WearoutReading, _get_wearout_reading_from_smartctl_output, ) class TestDisks(unittest.TestCase): def test_lv_attr_declaration(self): self.assertEqual( LVAttr.from_str("rwi-aor---", "Data/lvol0"), LVAttr( vol_type=LVAttr.VolType.RAID, permissions=LVAttr.Permissions.WRITABLE, allocation_policy=LVAttr.AllocationPolicy.INHERITED, fixed_minor=False, state=LVAttr.State.ACTIVE, is_open=LVAttr.IsOpen.OPEN, target_type=LVAttr.TargetType.RAID, zero_before_use=False, health=LVAttr.Health.OK, skip_activation=False, name="Data/lvol0", ), ) def test_wearout_reading_nvme_ssd(self): with open("tests/smartctl_nvme_ssd.json") as f: smartctl_output = json.load(f) self.assertEqual( _get_wearout_reading_from_smartctl_output(smartctl_output), WearoutReading(indicator=WearoutIndicator.SPARE_BLOCKS, current_reading=100, threshold_reading=10), ) def test_wearout_reading_ata_hdd(self): with open("tests/smartctl_ata_hdd.json") as f: smartctl_output = json.load(f) self.assertEqual( _get_wearout_reading_from_smartctl_output(smartctl_output), WearoutReading(indicator=WearoutIndicator.REALLOCATED_SECTORS, current_reading=200, threshold_reading=140), ) def test_wearout_reading_ata_ssd(self): with open("tests/smartctl_ata_ssd.json") as f: smartctl_output = json.load(f) self.assertEqual( _get_wearout_reading_from_smartctl_output(smartctl_output), WearoutReading(indicator=WearoutIndicator.SPARE_BLOCKS, current_reading=100, threshold_reading=5), ) if __name__ == "__main__": unittest.main()