def test_read_smart_nvme(self, mock_popen, mock_os_path_exists): hwlst = [] fake_output = sample('smartctl_nvme', mode='rb').splitlines() mock_popen.return_value = mock.Mock(stdout=fake_output) smart_utils.read_smart_nvme(hwlst, 'fake_nvme') self.assertEqual(hwlst, smart_utils_results.READ_SMART_NVME_RESULT)
def detect_disks(hw_lst): """Detect disks.""" names = diskinfo.disknames() sizes = diskinfo.disksizes(names) disks = [name for name, size in sizes.items() if size > 0] hw_lst.append(('disk', 'logical', 'count', str(len(disks)))) for name in disks: diskinfo.get_disk_info(name, sizes, hw_lst) # nvme devices do not need standard cache mechanisms if not name.startswith('nvme'): diskinfo.get_disk_cache(name, hw_lst) diskinfo.get_disk_id(name, hw_lst) # smartctl support # run only if smartctl command is there if which("smartctl"): if name.startswith('nvme'): sys.stderr.write('Reading SMART for nvme\n') smart_utils.read_smart_nvme(hw_lst, name) else: smart_utils.read_smart(hw_lst, "/dev/%s" % name) else: sys.stderr.write("Cannot find smartctl, exiting\n")