예제 #1
0
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")
예제 #2
0
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)

        # TODO(rpittau): add smart-tools support for nvme devices
        if not name.startswith('nvme'):
            smart_utils.read_smart(hw_lst, "/dev/%s" % name)
예제 #3
0
 def test_get_disk_info(self, mock_os_path_exists, mock_open):
     fake_disk_values = [
         'Cyberdyne Systems', 'T1000', '0x00', '0', '512', '0', '1023',
         '[none]'
     ]
     mock_open.side_effect = [
         mock.mock_open(read_data=fake_value).return_value
         for fake_value in fake_disk_values
     ]
     hw = []
     sizes = {'fake': 100}
     diskinfo.get_disk_info('fake', sizes, hw)
     self.assertEqual(hw, [('disk', 'fake', 'size', '100'),
                           ('disk', 'fake', 'vendor', 'Cyberdyne Systems'),
                           ('disk', 'fake', 'model', 'T1000'),
                           ('disk', 'fake', 'rev', '0x00'),
                           ('disk', 'fake', 'optimal_io_size', '0'),
                           ('disk', 'fake', 'physical_block_size', '512'),
                           ('disk', 'fake', 'rotational', '0'),
                           ('disk', 'fake', 'nr_requests', '1023'),
                           ('disk', 'fake', 'scheduler', 'none')])