def setup(self, mock_path):
     mock_path.return_value = True
     self.device_provider = mock.Mock()
     self.device_provider.is_loop = mock.Mock()
     self.device = MappedDevice(
         '/dev/foo', self.device_provider
     )
示例#2
0
文件: lvm.py 项目: kylozhang/kiwi
 def _create_filesystem(self, volume_name, filesystem_name):
     device_node = self.volume_map[volume_name]
     label = None
     if volume_name == 'LVRoot':
         label = self.custom_args['root_label']
     filesystem = FileSystem(name=filesystem_name,
                             device_provider=MappedDevice(
                                 device=device_node, device_provider=self),
                             custom_args=self.custom_filesystem_args)
     filesystem.create_on_device(label=label)
示例#3
0
    def get_device(self) -> Optional[MappedDevice]:
        """
        Instance of MappedDevice providing the luks device

        :return: mapped luks device

        :rtype: MappedDevice
        """
        if self.luks_device:
            return MappedDevice(device=self.luks_device, device_provider=self)
        return None
class TestMappedDevice:
    @patch('os.path.exists')
    def setup(self, mock_path):
        mock_path.return_value = True
        self.device_provider = mock.Mock()
        self.device_provider.is_loop = mock.Mock()
        self.device = MappedDevice(
            '/dev/foo', self.device_provider
        )

    @patch('os.path.exists')
    @raises(KiwiMappedDeviceError)
    def test_device_not_existingr(self, mock_path):
        mock_path.return_value = False
        MappedDevice('/dev/foo', mock.Mock())

    def test_get_device(self):
        assert self.device.get_device() == '/dev/foo'

    def test_is_loop(self):
        assert self.device.is_loop() == self.device_provider.is_loop()
示例#5
0
 def _create_filesystem(self, volume_name, volume_label, filesystem_name):
     device_node = self.volume_map[volume_name]
     if volume_name == 'LVRoot' and not volume_label:
         # if there is no @root volume definition for the root volume,
         # perform a second lookup of a label specified via the
         # rootfs_label from the type setup
         volume_label = self.custom_args['root_label']
     filesystem = FileSystem(name=filesystem_name,
                             device_provider=MappedDevice(
                                 device=device_node, device_provider=self),
                             custom_args=self.custom_filesystem_args)
     filesystem.create_on_device(label=volume_label)
class TestMappedDevice(object):
    @patch('os.path.exists')
    def setup(self, mock_path):
        mock_path.return_value = True
        self.device_provider = mock.Mock()
        self.device_provider.is_loop = mock.Mock()
        self.device = MappedDevice(
            '/dev/foo', self.device_provider
        )

    @patch('os.path.exists')
    @raises(KiwiMappedDeviceError)
    def test_device_not_existingr(self, mock_path):
        mock_path.return_value = False
        MappedDevice('/dev/foo', mock.Mock())

    def test_get_device(self):
        assert self.device.get_device() == '/dev/foo'

    def test_is_loop(self):
        assert self.device.is_loop() == self.device_provider.is_loop()
示例#7
0
    def get_device(self):
        """
        Dictionary with instance of MappedDevice for the root device node

        :return: root device map
        :rtype: dict
        """
        return {
            'root': MappedDevice(
                device=self.device, device_provider=self
            )
        }
示例#8
0
文件: btrfs.py 项目: eduardoj/kiwi
    def setup(self, name=None):
        """
        Setup btrfs volume management

        In case of btrfs a toplevel(@) subvolume is created and marked
        as default volume. If snapshots are activated via the custom_args
        the setup method also created the @/.snapshots/1/snapshot
        subvolumes. There is no concept of a volume manager name, thus
        the name argument is not used for btrfs

        :param string name: unused
        """
        self.setup_mountpoint()

        filesystem = FileSystem(
            name='btrfs',
            device_provider=MappedDevice(
                device=self.device, device_provider=self
            ),
            custom_args=self.custom_filesystem_args
        )
        filesystem.create_on_device(
            label=self.custom_args['root_label']
        )
        self.toplevel_mount = MountManager(
            device=self.device, mountpoint=self.mountpoint
        )
        self.toplevel_mount.mount(
            self.custom_filesystem_args['mount_options']
        )
        if self.custom_args['quota_groups']:
            Command.run(
                ['btrfs', 'quota', 'enable', self.mountpoint]
            )
        root_volume = self.mountpoint + '/@'
        Command.run(
            ['btrfs', 'subvolume', 'create', root_volume]
        )
        if self.custom_args['root_is_snapshot']:
            snapshot_volume = self.mountpoint + '/@/.snapshots'
            Command.run(
                ['btrfs', 'subvolume', 'create', snapshot_volume]
            )
            Path.create(snapshot_volume + '/1')
            snapshot = self.mountpoint + '/@/.snapshots/1/snapshot'
            Command.run(
                ['btrfs', 'subvolume', 'snapshot', root_volume, snapshot]
            )
            self._set_default_volume('@/.snapshots/1/snapshot')
        else:
            self._set_default_volume('@')
示例#9
0
    def test_create_disk_volume_managed_root(self, mock_exists, mock_grub_dir,
                                             mock_command, mock_volume_manager,
                                             mock_fs):
        mock_exists.return_value = True
        volume_manager = mock.Mock()
        volume_manager.get_device = mock.Mock(
            return_value={
                'root': MappedDevice('/dev/systemVG/LVRoot', mock.Mock()),
                'swap': MappedDevice('/dev/systemVG/LVSwap', mock.Mock())
            })
        volume_manager.get_fstab = mock.Mock(
            return_value=['fstab_volume_entries'])
        mock_volume_manager.return_value = volume_manager
        filesystem = mock.Mock()
        mock_fs.return_value = filesystem
        self.disk_builder.volume_manager_name = 'lvm'

        with patch('builtins.open'):
            self.disk_builder.create_disk()

        self.disk.create_root_lvm_partition.assert_called_once_with('all_free')
        volume_manager.setup.assert_called_once_with('systemVG')
        volume_manager.create_volumes.assert_called_once_with('btrfs')
        volume_manager.mount_volumes.call_args_list[0].assert_called_once_with(
        )
        assert volume_manager.get_fstab.call_args_list == [
            call(None, 'btrfs'), call(None, 'btrfs')
        ]
        volume_manager.sync_data.assert_called_once_with([
            'image', '.profile', '.kconfig', '.buildenv', 'var/cache/kiwi',
            'boot/*', 'boot/.*', 'boot/efi/*', 'boot/efi/.*'
        ])
        volume_manager.umount_volumes.call_args_list[
            0].assert_called_once_with()
        self.setup.create_fstab.assert_called_once_with(
            self.disk_builder.fstab)
        self.boot_image_task.setup.create_fstab.assert_called_once_with(
            self.disk_builder.fstab)
示例#10
0
    def get_device(self):
        """
        Names of partition devices

        Note that the mapping requires an explicit map() call

        :return: instances of MappedDevice
        :rtype: dict
        """
        device_map = {}
        for partition_name, device_node in list(self.partition_map.items()):
            device_map[partition_name] = MappedDevice(device=device_node,
                                                      device_provider=self)
        return device_map
示例#11
0
 def test_create_disk_volume_managed_root(
     self, mock_exists, mock_command, mock_open, mock_volume_manager, mock_fs
 ):
     mock_exists.return_value = True
     volume_manager = mock.Mock()
     volume_manager.get_device = mock.Mock(
         return_value={
             'root': MappedDevice('/dev/systemVG/LVRoot', mock.Mock())
         }
     )
     volume_manager.get_fstab = mock.Mock(
         return_value=['fstab_volume_entries']
     )
     mock_volume_manager.return_value = volume_manager
     filesystem = mock.Mock()
     mock_fs.return_value = filesystem
     self.disk_builder.volume_manager_name = 'lvm'
     self.disk_builder.create_disk()
     self.disk.create_root_lvm_partition.assert_called_once_with(
         'all_free'
     )
     volume_manager.setup.assert_called_once_with('systemVG')
     volume_manager.create_volumes.assert_called_once_with('btrfs')
     volume_manager.mount_volumes.call_args_list[0].assert_called_once_with()
     volume_manager.get_fstab.assert_called_once_with(None, 'btrfs')
     volume_manager.sync_data.assert_called_once_with([
         'image', '.profile', '.kconfig', 'var/cache/kiwi',
         'boot/*', 'boot/.*', 'boot/efi/*', 'boot/efi/.*'
     ])
     volume_manager.umount_volumes.call_args_list[0].assert_called_once_with()
     self.setup.create_fstab.assert_called_once_with(
         [
             'fstab_volume_entries',
             'UUID=blkid_result / filesystem ro 0 0',
             'UUID=blkid_result /boot filesystem defaults 0 0',
             'UUID=blkid_result /boot/efi filesystem defaults 0 0'
         ]
     )
     self.boot_image_task.setup.create_fstab.assert_called_once_with(
         [
             'fstab_volume_entries',
             'UUID=blkid_result / filesystem ro 0 0',
             'UUID=blkid_result /boot filesystem defaults 0 0',
             'UUID=blkid_result /boot/efi filesystem defaults 0 0'
         ]
     )
示例#12
0
文件: lvm.py 项目: michal42/kiwi-1
    def get_device(self):
        """
        Dictionary of MappedDevice instances per volume

        Note: The mapping requires an explicit create_volumes() call

        :return: root plus volume device map
        :rtype: dict
        """
        device_map = {}
        for volume_name, volume_node in list(self.volume_map.items()):
            if volume_name == 'LVRoot':
                # LVRoot volume device takes precedence over the
                # root partition device from the disk. Therefore use
                # the same key to put them on the same level
                volume_name = 'root'
            device_map[volume_name] = MappedDevice(device=volume_node,
                                                   device_provider=self)
        return device_map
示例#13
0
 def test_create_volume_managed_root(
     self, mock_exists, mock_command, mock_open, mock_volume_manager, mock_fs
 ):
     mock_exists.return_value = True
     volume_manager = mock.Mock()
     volume_manager.get_device = mock.Mock(
         return_value={
             'root': MappedDevice('/dev/systemVG/LVRoot', mock.Mock())
         }
     )
     mock_volume_manager.return_value = volume_manager
     filesystem = mock.Mock()
     mock_fs.return_value = filesystem
     self.disk_builder.volume_manager_name = 'lvm'
     self.disk_builder.create()
     self.disk.create_root_lvm_partition.assert_called_once_with(
         'all_free'
     )
     volume_manager.setup.assert_called_once_with('systemVG')
     volume_manager.create_volumes.assert_called_once_with('btrfs')
     volume_manager.sync_data.assert_called_once_with([
         'image', '.profile', '.kconfig', 'var/cache/kiwi',
         'boot/*', 'boot/.*', 'boot/efi/*', 'boot/efi/.*'
     ])
示例#14
0
    def setup(self, mock_exists):
        Defaults.set_platform_name('x86_64')

        def side_effect(filename):
            if filename.endswith('.config/kiwi/config.yml'):
                return False
            elif filename.endswith('etc/kiwi.yml'):
                return False
            else:
                return True

        mock_exists.side_effect = side_effect
        description = XMLDescription(
            '../data/example_disk_config.xml'
        )
        self.device_map = {
            'root': MappedDevice('/dev/root-device', Mock()),
            'swap': MappedDevice('/dev/swap-device', Mock()),
            'readonly': MappedDevice('/dev/readonly-root-device', Mock()),
            'boot': MappedDevice('/dev/boot-device', Mock()),
            'prep': MappedDevice('/dev/prep-device', Mock()),
            'efi': MappedDevice('/dev/efi-device', Mock()),
            'spare': MappedDevice('/dev/spare-device', Mock()),
            'var': MappedDevice('/dev/spare-device', Mock())
        }
        self.id_map = {
            'kiwi_RootPart': 1,
            'kiwi_BootPart': 1
        }
        self.id_map_sorted = OrderedDict(
            sorted(self.id_map.items())
        )
        self.boot_names_type = namedtuple(
            'boot_names_type', ['kernel_name', 'initrd_name']
        )
        self.block_operation = Mock()
        self.block_operation.get_blkid = Mock(
            return_value='blkid_result'
        )
        self.block_operation.get_filesystem = Mock(
            return_value='blkid_result_fs'
        )
        kiwi.builder.disk.BlockID = Mock(
            return_value=self.block_operation
        )
        self.loop_provider = Mock()
        kiwi.builder.disk.LoopDevice = Mock(
            return_value=self.loop_provider
        )
        self.disk = Mock()
        provider = Mock()
        provider.get_device = Mock(
            return_value='/dev/some-loop'
        )
        self.disk.storage_provider = provider
        self.partitioner = Mock()
        self.partitioner.get_id = Mock(
            return_value=1
        )
        self.disk.partitioner = self.partitioner
        self.disk.get_uuid = Mock(
            return_value='0815'
        )
        self.disk.get_public_partition_id_map = Mock(
            return_value=self.id_map_sorted
        )
        self.disk.get_device = Mock(
            return_value=self.device_map
        )
        kernel_info = Mock()
        kernel_info.version = '1.2.3'
        kernel_info.name = 'vmlinuz-1.2.3-default'
        self.kernel = Mock()
        self.kernel.get_kernel = Mock(
            return_value=kernel_info
        )
        self.kernel.get_xen_hypervisor = Mock()
        self.kernel.copy_kernel = Mock()
        self.kernel.copy_xen_hypervisor = Mock()
        kiwi.builder.disk.Kernel = Mock(
            return_value=self.kernel
        )
        kiwi.builder.disk.Disk = Mock(
            return_value=self.disk
        )
        self.disk_setup = Mock()
        self.disk_setup.get_disksize_mbytes.return_value = 1024
        self.disk_setup.boot_partition_size.return_value = 0
        self.disk_setup.get_efi_label = Mock(
            return_value='EFI'
        )
        self.disk_setup.get_root_label = Mock(
            return_value='ROOT'
        )
        self.disk_setup.get_boot_label = Mock(
            return_value='BOOT'
        )
        self.disk_setup.need_boot_partition = Mock(
            return_value=True
        )
        self.bootloader_install = Mock()
        kiwi.builder.disk.BootLoaderInstall.new = MagicMock(
            return_value=self.bootloader_install
        )
        self.bootloader_config = Mock()
        self.bootloader_config.get_boot_cmdline = Mock(
            return_value='boot_cmdline'
        )
        kiwi.builder.disk.BootLoaderConfig.new = MagicMock(
            return_value=self.bootloader_config
        )
        kiwi.builder.disk.DiskSetup = MagicMock(
            return_value=self.disk_setup
        )
        self.boot_image_task = Mock()
        self.boot_image_task.boot_root_directory = 'boot_dir'
        self.boot_image_task.kernel_filename = 'kernel'
        self.boot_image_task.initrd_filename = 'initrd'
        self.boot_image_task.xen_hypervisor_filename = 'xen_hypervisor'
        self.boot_image_task.get_boot_names.return_value = self.boot_names_type(
            kernel_name='linux.vmx',
            initrd_name='initrd.vmx'
        )
        kiwi.builder.disk.BootImage.new = Mock(
            return_value=self.boot_image_task
        )
        self.firmware = Mock()
        self.firmware.get_legacy_bios_partition_size.return_value = 0
        self.firmware.get_efi_partition_size.return_value = 0
        self.firmware.get_prep_partition_size.return_value = 0
        self.firmware.efi_mode = Mock(
            return_value='efi'
        )
        kiwi.builder.disk.FirmWare = Mock(
            return_value=self.firmware
        )
        self.setup = Mock()
        kiwi.builder.disk.SystemSetup = Mock(
            return_value=self.setup
        )
        self.install_image = Mock()
        kiwi.builder.disk.InstallImageBuilder = Mock(
            return_value=self.install_image
        )
        self.raid_root = Mock()
        self.raid_root.get_device.return_value = MappedDevice(
            '/dev/md0', Mock()
        )
        kiwi.builder.disk.RaidDevice = Mock(
            return_value=self.raid_root
        )
        self.luks_root = Mock()
        kiwi.builder.disk.LuksDevice = Mock(
            return_value=self.luks_root
        )
        self.fstab = Mock()
        kiwi.builder.disk.Fstab = Mock(
            return_value=self.fstab
        )
        self.xml_state = XMLState(description.load())
        self.disk_builder = DiskBuilder(
            self.xml_state, 'target_dir', 'root_dir',
            custom_args={'signing_keys': ['key_file_a', 'key_file_b']}
        )
        self.disk_builder.bundle_format = '%N'
        self.disk_builder.root_filesystem_is_overlay = False
        self.disk_builder.build_type_name = 'oem'
        self.disk_builder.image_format = None
示例#15
0
 def test_device_not_existingr(self, mock_path):
     mock_path.return_value = False
     with raises(KiwiMappedDeviceError):
         MappedDevice('/dev/foo', Mock())
 def test_device_not_existingr(self, mock_path):
     mock_path.return_value = False
     MappedDevice('/dev/foo', mock.Mock())
示例#17
0
 def setup(self, mock_machine, mock_exists):
     mock_machine.return_value = 'x86_64'
     mock_exists.return_value = True
     description = XMLDescription('../data/example_disk_config.xml')
     self.device_map = {
         'root': MappedDevice('/dev/root-device', mock.Mock()),
         'readonly': MappedDevice('/dev/readonly-root-device', mock.Mock()),
         'boot': MappedDevice('/dev/boot-device', mock.Mock()),
         'prep': MappedDevice('/dev/prep-device', mock.Mock()),
         'efi': MappedDevice('/dev/efi-device', mock.Mock())
     }
     self.id_map = {'kiwi_RootPart': 1, 'kiwi_BootPart': 1}
     self.id_map_sorted = OrderedDict(sorted(self.id_map.items()))
     self.block_operation = mock.Mock()
     self.block_operation.get_blkid = mock.Mock(return_value='blkid_result')
     self.block_operation.get_filesystem = mock.Mock(
         return_value='filesystem')
     kiwi.builder.disk.BlockID = mock.Mock(
         return_value=self.block_operation)
     self.loop_provider = mock.Mock()
     kiwi.builder.disk.LoopDevice = mock.Mock(
         return_value=self.loop_provider)
     self.disk = mock.Mock()
     provider = mock.Mock()
     provider.get_device = mock.Mock(return_value='/dev/some-loop')
     self.disk.storage_provider = provider
     self.partitioner = mock.Mock()
     self.partitioner.get_id = mock.Mock(return_value=1)
     self.disk.partitioner = self.partitioner
     self.disk.get_uuid = mock.Mock(return_value='0815')
     self.disk.get_public_partition_id_map = mock.Mock(
         return_value=self.id_map_sorted)
     self.disk.get_device = mock.Mock(return_value=self.device_map)
     kernel_info = mock.Mock()
     kernel_info.version = '1.2.3'
     kernel_info.name = 'vmlinuz-1.2.3-default'
     self.kernel = mock.Mock()
     self.kernel.get_kernel = mock.Mock(return_value=kernel_info)
     self.kernel.get_xen_hypervisor = mock.Mock()
     self.kernel.copy_kernel = mock.Mock()
     self.kernel.copy_xen_hypervisor = mock.Mock()
     kiwi.builder.disk.Kernel = mock.Mock(return_value=self.kernel)
     self.disk.subformat = mock.Mock()
     self.disk.subformat.get_target_name_for_format = mock.Mock(
         return_value='some-target-format-name')
     kiwi.builder.disk.DiskFormat = mock.Mock(
         return_value=self.disk.subformat)
     kiwi.builder.disk.Disk = mock.Mock(return_value=self.disk)
     self.disk_setup = mock.Mock()
     self.disk_setup.get_efi_label = mock.Mock(return_value='EFI')
     self.disk_setup.get_root_label = mock.Mock(return_value='ROOT')
     self.disk_setup.get_boot_label = mock.Mock(return_value='BOOT')
     self.disk_setup.need_boot_partition = mock.Mock(return_value=True)
     self.bootloader_install = mock.Mock()
     kiwi.builder.disk.BootLoaderInstall = mock.MagicMock(
         return_value=self.bootloader_install)
     self.bootloader_config = mock.Mock()
     kiwi.builder.disk.BootLoaderConfig = mock.MagicMock(
         return_value=self.bootloader_config)
     kiwi.builder.disk.DiskSetup = mock.MagicMock(
         return_value=self.disk_setup)
     self.boot_image_task = mock.Mock()
     self.boot_image_task.boot_root_directory = 'boot_dir'
     self.boot_image_task.kernel_filename = 'kernel'
     self.boot_image_task.initrd_filename = 'initrd'
     self.boot_image_task.xen_hypervisor_filename = 'xen_hypervisor'
     kiwi.builder.disk.BootImage = mock.Mock(
         return_value=self.boot_image_task)
     self.firmware = mock.Mock()
     self.firmware.efi_mode = mock.Mock(return_value='efi')
     kiwi.builder.disk.FirmWare = mock.Mock(return_value=self.firmware)
     self.setup = mock.Mock()
     kiwi.builder.disk.SystemSetup = mock.Mock(return_value=self.setup)
     self.boot_image_kiwi = mock.Mock()
     self.boot_image_kiwi.boot_root_directory = 'boot_dir_kiwi'
     kiwi.builder.disk.BootImageKiwi = mock.Mock(
         return_value=self.boot_image_kiwi)
     self.install_image = mock.Mock()
     kiwi.builder.disk.InstallImageBuilder = mock.Mock(
         return_value=self.install_image)
     self.raid_root = mock.Mock()
     kiwi.builder.disk.RaidDevice = mock.Mock(return_value=self.raid_root)
     self.luks_root = mock.Mock()
     kiwi.builder.disk.LuksDevice = mock.Mock(return_value=self.luks_root)
     self.disk_builder = DiskBuilder(
         XMLState(description.load()),
         'target_dir',
         'root_dir',
         custom_args={'signing_keys': ['key_file_a', 'key_file_b']})
     self.disk_builder.root_filesystem_is_overlay = False
     self.disk_builder.build_type_name = 'oem'
     self.disk_builder.image_format = None
示例#18
0
 def setup(self, mock_path):
     mock_path.return_value = True
     self.device_provider = Mock()
     self.device_provider.is_loop = Mock()
     self.device = MappedDevice('/dev/foo', self.device_provider)