def test_get_major_minor(self, minor_mock, major_mock, stat_mock): major_mock.return_value = 8 minor_mock.return_value = 0 result = get_major_minor('/dev/sda') major, minor = result self.assertTrue(isinstance(result, tuple),"get_major_minor must return a tuple") self.assertGreater(major, minor)
def _populate_disks_entries(self): device_filepaths = glob('/dev/sd*[!0-9]') device_names = [os.path.basename(device_filepath) for device_filepath in device_filepaths] self.hctl_map = self._map_hctl_to_disk_device_names(device_names) all_device_filepaths = glob('/dev/sd*') self.uuid_map = self._map_uuid_to_disk_device_filepaths(all_device_filepaths) for device_filepath, device_name in map(None, device_filepaths, device_names): size = self._extract_size_from_fdisk(device_filepath) major_minor = get_major_minor(device_filepath) hctl = self.get_hctl(device_name) self.basic_disk_entries.append(DiskEntry(device_name, device_filepath, size, major_minor, hctl)) ldm = LinuxDeviceMapper() for detail in ldm.get_multipath_disks_details().values(): # TODO: Do we store here the rest of the dmp details? (alias, wwid, sysfs name, etc.) device_name = os.path.join("mapper", detail.alias) device_filepath = os.path.join("/", "dev", device_name) size = self._extract_size_from_fdisk(device_filepath) major_minor = get_major_minor(device_filepath) hctl = None entry = DiskEntry(device_name, device_filepath, size, major_minor, hctl) entry.mp_details = detail entry.path_groups = ldm.get_path_group_entries(detail.alias) self.multipath_disk_entries.append(entry)
def _get_sysfs_partitions(self, device_name): partitions = [] partition_filepaths = glob('/dev/%s[0-9]*' % device_name) for partition_filepath in partition_filepaths: size = self._extract_size_from_fdisk(partition_filepath) major_minor = get_major_minor(partition_filepath) hctl = self.get_hctl(os.path.basename(partition_filepath)) partitions.append(DiskEntry( os.path.basename(partition_filepath), partition_filepath, size, major_minor, hctl ) ) return partitions