Exemple #1
0
    def get_fstab(self, persistency_type='by-label', filesystem_name=None):
        """
        Implements creation of the fstab entries. The method
        returns a list of fstab compatible entries

        :param string persistency_type: by-label | by-uuid
        :param string filesystem_name: unused

        :return: list of fstab entries

        :rtype: list
        """
        fstab_entries = []
        mount_options = \
            self.custom_filesystem_args['mount_options'] or ['defaults']
        block_operation = BlockID(self.device)
        blkid_type = 'LABEL' if persistency_type == 'by-label' else 'UUID'
        device_id = block_operation.get_blkid(blkid_type)
        for volume_mount in self.subvol_mount_list:
            subvol_name = self._get_subvol_name_from_mountpoint(volume_mount)
            mount_entry_options = mount_options + ['subvol=' + subvol_name]
            fs_check = self._is_volume_enabled_for_fs_check(
                volume_mount.mountpoint)
            fstab_entry = ' '.join([
                blkid_type + '=' + device_id,
                subvol_name.replace('@', ''), 'btrfs',
                ','.join(mount_entry_options),
                '0 {fs_passno}'.format(fs_passno='2' if fs_check else '0')
            ])
            fstab_entries.append(fstab_entry)
        return fstab_entries
Exemple #2
0
 def _get_root_cmdline_parameter(self, boot_device):
     cmdline = self.xml_state.build_type.get_kernelcmdline()
     persistency_type = self.xml_state.build_type.get_devicepersistency()
     if cmdline and 'root=' in cmdline:
         log.info(
             'Kernel root device explicitly set via kernelcmdline'
         )
         root_search = re.search(r'(root=(.*)[ ]+|root=(.*)$)', cmdline)
         if root_search:
             return root_search.group(1)
     if boot_device:
         block_operation = BlockID(boot_device)
         if persistency_type == 'by-label':
             blkid_type = 'LABEL'
         elif persistency_type == 'by-partuuid':
             blkid_type = 'PARTUUID'
         else:
             blkid_type = 'UUID'
         location = block_operation.get_blkid(blkid_type)
         if self.xml_state.build_type.get_overlayroot():
             return f'root=overlay:{blkid_type}={location}'
         else:
             return f'root={blkid_type}={location}'
     else:
         log.warning(
             'No explicit root= cmdline provided'
         )
Exemple #3
0
 def _preserve_root_filesystem_uuid(self, device_map):
     block_operation = BlockID(
         device_map['root'].get_device()
     )
     rootfs_uuid = block_operation.get_blkid('UUID')
     if rootfs_uuid:
         self.xml_state.set_root_filesystem_uuid(
             rootfs_uuid
         )
Exemple #4
0
 def _preserve_root_partition_uuid(self, device_map):
     block_operation = BlockID(
         device_map['root'].get_device()
     )
     partition_uuid = block_operation.get_blkid('PARTUUID')
     if partition_uuid:
         self.xml_state.set_root_partition_uuid(
             partition_uuid
         )
Exemple #5
0
class TestBlockID:
    def setup(self):
        self.blkid = BlockID('device')

    @patch('kiwi.utils.block.Command.run')
    def test_setup_with_uuid_format(self, mock_command):
        BlockID('UUID=uuid')
        mock_command.assert_called_once_with(['blkid', '--uuid', 'uuid'])

    @patch('kiwi.utils.block.Command.run')
    def test_get_blkid(self, mock_command):
        self.blkid.get_blkid('LABEL')
        mock_command.assert_called_once_with(
            ['blkid', 'device', '-s', 'LABEL', '-o', 'value'])

    @patch('kiwi.utils.block.BlockID.get_blkid')
    def test_get_filesystem(self, mock_get_blkid):
        self.blkid.get_filesystem()
        mock_get_blkid.assert_called_once_with('TYPE')

    @patch('kiwi.utils.block.BlockID.get_blkid')
    def test_get_label(self, mock_get_blkid):
        self.blkid.get_label()
        mock_get_blkid.assert_called_once_with('LABEL')

    @patch('kiwi.utils.block.BlockID.get_blkid')
    def test_get_uuid(self, mock_get_blkid):
        self.blkid.get_uuid()
        mock_get_blkid.assert_called_once_with('UUID')
Exemple #6
0
class TestBlockID(object):
    def setup(self):
        self.blkid = BlockID('device')

    @patch('kiwi.utils.block.Command.run')
    def test_get_blkid(self, mock_command):
        self.blkid.get_blkid('LABEL')
        mock_command.assert_called_once_with(
            ['blkid', 'device', '-s', 'LABEL', '-o', 'value']
        )

    @patch('kiwi.utils.block.BlockID.get_blkid')
    def test_get_filesystem(self, mock_get_blkid):
        self.blkid.get_filesystem()
        mock_get_blkid.assert_called_once_with('TYPE')

    @patch('kiwi.utils.block.BlockID.get_blkid')
    def test_get_label(self, mock_get_blkid):
        self.blkid.get_label()
        mock_get_blkid.assert_called_once_with('LABEL')

    @patch('kiwi.utils.block.BlockID.get_blkid')
    def test_get_uuid(self, mock_get_blkid):
        self.blkid.get_uuid()
        mock_get_blkid.assert_called_once_with('UUID')
Exemple #7
0
 def _add_generic_fstab_entry(self,
                              device,
                              mount_point,
                              options=None,
                              check='0 0'):
     if not options:
         options = ['defaults']
     block_operation = BlockID(device)
     blkid_type = 'LABEL' if self.persistency_type == 'by-label' else 'UUID'
     device_id = block_operation.get_blkid(blkid_type)
     fstab_entry = ' '.join([
         blkid_type + '=' + device_id, mount_point,
         block_operation.get_filesystem(), ','.join(options), check
     ])
     self.fstab.add_entry(fstab_entry)
Exemple #8
0
 def _add_generic_fstab_entry(
     self, device, mount_point, options=None, check='0 0'
 ):
     if not options:
         options = ['defaults']
     block_operation = BlockID(device)
     blkid_type = 'LABEL' if self.persistency_type == 'by-label' else 'UUID'
     device_id = block_operation.get_blkid(blkid_type)
     fstab_entry = ' '.join(
         [
             blkid_type + '=' + device_id, mount_point,
             block_operation.get_filesystem(), ','.join(options), check
         ]
     )
     if fstab_entry not in self.generic_fstab_entries:
         self.generic_fstab_entries.append(
             fstab_entry
         )
Exemple #9
0
    def get_fstab(self, persistency_type='by-label', filesystem_name=None):
        """
        Implements creation of the fstab entries. The method
        returns a list of fstab compatible entries

        :param string persistency_type: by-label | by-uuid
        :param string filesystem_name: unused

        :return: list of fstab entries

        :rtype: list
        """
        fstab_entries = []
        mount_options = \
            self.custom_filesystem_args['mount_options'] or ['defaults']
        block_operation = BlockID(self.device)
        blkid_type = 'LABEL' if persistency_type == 'by-label' else 'UUID'
        device_id = block_operation.get_blkid(blkid_type)
        if self.custom_args['root_is_snapshot']:
            mount_entry_options = mount_options + ['subvol=@/.snapshots']
            fstab_entry = ' '.join(
                [
                    blkid_type + '=' + device_id, '/.snapshots',
                    'btrfs', ','.join(mount_entry_options), '0 0'
                ]
            )
            fstab_entries.append(fstab_entry)
        for volume_mount in self.subvol_mount_list:
            subvol_name = self._get_subvol_name_from_mountpoint(volume_mount)
            mount_entry_options = mount_options + ['subvol=' + subvol_name]
            fstab_entry = ' '.join(
                [
                    blkid_type + '=' + device_id, subvol_name.replace('@', ''),
                    'btrfs', ','.join(mount_entry_options), '0 0'
                ]
            )
            fstab_entries.append(fstab_entry)
        return fstab_entries
Exemple #10
0
 def _add_fstab_entry(self,
                      device: str,
                      mount_point: str,
                      options: List = None,
                      check: str = '0 0') -> None:
     if not options:
         options = ['defaults']
     block_operation = BlockID(device)
     if self.volume_manager_name and self.volume_manager_name == 'lvm' \
        and (mount_point == '/' or mount_point == 'swap'):
         fstab_entry = ' '.join([
             device, mount_point,
             block_operation.get_filesystem(), ','.join(options), check
         ])
     else:
         blkid_type = 'LABEL' if self.persistency_type == 'by-label' \
             else 'UUID'
         device_id = block_operation.get_blkid(blkid_type)
         fstab_entry = ' '.join([
             blkid_type + '=' + device_id, mount_point,
             block_operation.get_filesystem(), ','.join(options), check
         ])
     self.fstab.add_entry(fstab_entry)
Exemple #11
0
    def get_block_storage_filesystem(self) -> str:
        """
        Retrieve filesystem type from image_filepath. The method
        only returns a value if image_filepath at construction
        time of the VeritySetup object is a block device containing
        a filesystem

        :rtype: blkid TYPE value or empty string

        :return: str
        """
        try:
            return BlockID(self.image_filepath).get_filesystem()
        except Exception:
            return ''
Exemple #12
0
 def setup(self):
     self.blkid = BlockID('device')
Exemple #13
0
 def test_setup_with_uuid_format(self, mock_command):
     BlockID('UUID=uuid')
     mock_command.assert_called_once_with(
         ['blkid', '--uuid', 'uuid']
     )
Exemple #14
0
	def set_device(self, device):
		self._state.set_root_partition_uuid(uuid=BlockID(device=device).get_blkid('PARTUUID'))
		self._device = device
		return True
Exemple #15
0
 def setup(self):
     self.blkid = BlockID('device')