def test_info(self, mock_exec, mock_udev): self.maxDiff = None mock_exec.side_effect = [ ('BYT;\n' '/dev/fake:476940MiB:scsi:512:4096:msdos:ATA 1BD14;\n' # parted '1:0.03MiB:1.00MiB:0.97MiB:free;\n' '1:1.00MiB:191MiB:190MiB:ext3::boot;\n' '2:191MiB:476939MiB:476748MiB:::lvm;\n' '1:476939MiB:476940MiB:1.02MiB:free;\n', 0), ("/dev/sda: x86 boot sector; partition 1: ID=0x83", 0), # file ("", 0), ("uuid1", 0), # blkid ("uuid2", 0), ("", 0) ] expected = { 'generic': {'dev': '/dev/fake', 'logical_block': 512, 'model': 'ATA 1BD14', 'physical_block': 4096, 'size': 476940, 'table': 'msdos', 'has_bootloader': True}, 'parts': [{'disk_dev': '/dev/fake', 'name': '/dev/fake1', 'begin': 1, 'end': 1, 'fstype': 'free', 'num': 1, 'size': 1, 'uuid': "", 'type': None, 'flags': []}, {'disk_dev': '/dev/fake', 'name': '/dev/fake1', 'begin': 1, 'end': 191, 'fstype': 'ext3', 'num': 1, 'size': 190, 'uuid': "uuid1", 'type': None, 'flags': ['boot']}, {'disk_dev': '/dev/fake', 'name': '/dev/fake2', 'begin': 191, 'end': 476939, 'fstype': None, 'num': 2, 'size': 476748, 'uuid': "uuid2", 'type': None, 'flags': ['lvm']}, {'disk_dev': '/dev/fake', 'name': '/dev/fake1', 'begin': 476939, 'end': 476940, 'fstype': 'free', 'num': 1, 'size': 2, 'uuid': "", 'type': None, 'flags': []}]} actual = pu.info('/dev/fake') self.assertDictEqual(expected, actual)
def _get_hw_partition_schema(self): """Reads disks/partitions from underlying hardware. Does not rely on deploy_config """ # NOTE(lobur): Only disks/partitions currently supported. # No vgs/volumes LOG.debug('--- Reading HW partition scheme from the node ---') partition_schema = objects.PartitionScheme() disk_infos = [pu.info(disk['name']) for disk in self.hu_disks] fstab = self._find_hw_fstab() LOG.debug('Scanning all disks on the node') for disk_info in disk_infos: parted = partition_schema.add_parted( name=disk_info['generic']['dev'], label=disk_info['generic']['table'], install_bootloader=disk_info['generic']['has_bootloader'] ) LOG.debug('Scanning all partitions on disk %s ' % disk_info['generic']['dev']) for part in disk_info['parts']: if part.get('fstype', '') == 'free': LOG.debug('Skipping a free partition at:' 'begin=%s, end=%s' % (part.get('begin'), part.get('end'))) continue LOG.debug('Adding partition: ' 'name=%s size=%s to hw schema' % (part.get('disk_dev'), part.get('size'))) # NOTE(lobur): avoid use of parted.add_partition to omit # counting logic; use real data instead. partition = objects.Partition( name=part.get('name'), count=part.get('num'), device=part.get('disk_dev'), begin=part.get('begin'), end=part.get('end'), partition_type=part.get('type'), flags=part.get('flags') ) parted.partitions.append(partition) mnt_point = self._get_mount_point_from_fstab(fstab, part['uuid']) if mnt_point: LOG.debug('Adding filesystem: ' 'device=%s fs_type=%s mount_point=%s ' 'to hw schema' % (part.get('name'), part.get('fstype'), mnt_point)) partition_schema.add_fs(device=part.get('name'), mount=mnt_point, fs_type=part.get('fstype', '')) else: LOG.warning("Not adding %s filesystem to hw_schema because" " it has no mount point in fstab" % part.get('name')) return partition_schema
def test_info(self, mock_exec, mock_udev): self.maxDiff = None mock_exec.side_effect = [ ( 'BYT;\n' '/dev/fake:476940MiB:scsi:512:4096:msdos:ATA 1BD14;\n' # parted '1:0.03MiB:1.00MiB:0.97MiB:free;\n' '1:1.00MiB:191MiB:190MiB:ext3::boot;\n' '2:191MiB:476939MiB:476748MiB:::lvm;\n' '1:476939MiB:476940MiB:1.02MiB:free;\n', 0), ("/dev/sda: x86 boot sector; partition 1: ID=0x83", 0), # file ("", 0), ("uuid1", 0), # blkid ("uuid2", 0), ("", 0) ] expected = { 'generic': { 'dev': '/dev/fake', 'logical_block': 512, 'model': 'ATA 1BD14', 'physical_block': 4096, 'size': 476940, 'table': 'msdos', 'has_bootloader': True }, 'parts': [{ 'disk_dev': '/dev/fake', 'name': '/dev/fake1', 'begin': 1, 'end': 1, 'fstype': 'free', 'num': 1, 'size': 1, 'uuid': "", 'type': None, 'flags': [] }, { 'disk_dev': '/dev/fake', 'name': '/dev/fake1', 'begin': 1, 'end': 191, 'fstype': 'ext3', 'num': 1, 'size': 190, 'uuid': "uuid1", 'type': None, 'flags': ['boot'] }, { 'disk_dev': '/dev/fake', 'name': '/dev/fake2', 'begin': 191, 'end': 476939, 'fstype': None, 'num': 2, 'size': 476748, 'uuid': "uuid2", 'type': None, 'flags': ['lvm'] }, { 'disk_dev': '/dev/fake', 'name': '/dev/fake1', 'begin': 476939, 'end': 476940, 'fstype': 'free', 'num': 1, 'size': 2, 'uuid': "", 'type': None, 'flags': [] }] } actual = pu.info('/dev/fake') self.assertDictEqual(expected, actual)
def _get_hw_partition_schema(self): """Reads disks/partitions from underlying hardware. Does not rely on deploy_config """ # NOTE(lobur): Only disks/partitions currently supported. # No vgs/volumes LOG.debug('--- Reading HW partition scheme from the node ---') partition_schema = objects.PartitionScheme() disk_infos = [pu.info(disk['name']) for disk in self.hu_disks] fstab = self._find_hw_fstab() LOG.debug('Scanning all disks on the node') for disk_info in disk_infos: parted = partition_schema.add_parted( name=disk_info['generic']['dev'], label=disk_info['generic']['table'], install_bootloader=disk_info['generic']['has_bootloader']) LOG.debug('Scanning all partitions on disk %s ' % disk_info['generic']['dev']) for part in disk_info['parts']: if part.get('fstype', '') == 'free': LOG.debug('Skipping a free partition at:' 'begin=%s, end=%s' % (part.get('begin'), part.get('end'))) continue LOG.debug('Adding partition: ' 'name=%s size=%s to hw schema' % (part.get('disk_dev'), part.get('size'))) # NOTE(lobur): avoid use of parted.add_partition to omit # counting logic; use real data instead. partition = objects.Partition(name=part.get('name'), count=part.get('num'), device=part.get('disk_dev'), begin=part.get('begin'), end=part.get('end'), partition_type=part.get('type'), flags=part.get('flags')) parted.partitions.append(partition) mnt_point = self._get_mount_point_from_fstab( fstab, part['uuid']) if mnt_point: LOG.debug( 'Adding filesystem: ' 'device=%s fs_type=%s mount_point=%s ' 'to hw schema' % (part.get('name'), part.get('fstype'), mnt_point)) partition_schema.add_fs(device=part.get('name'), mount=mnt_point, fs_type=part.get('fstype', '')) else: LOG.warning("Not adding %s filesystem to hw_schema because" " it has no mount point in fstab" % part.get('name')) return partition_schema