diff --git a/kiwi/builder/disk.py b/kiwi/builder/disk.py index 92a7a94ccb2..96dfc8370d7 100644 --- a/kiwi/builder/disk.py +++ b/kiwi/builder/disk.py @@ -18,7 +18,7 @@ import os import logging from typing import ( - Dict, List, Optional, Tuple, Any + Dict, List, Optional, Tuple, Union ) # project @@ -49,6 +49,7 @@ from kiwi.filesystem import FileSystem from kiwi.filesystem.squashfs import FileSystemSquashFs from kiwi.volume_manager import VolumeManager +from kiwi.volume_manager.base import VolumeManagerBase from kiwi.command import Command from kiwi.system.setup import SystemSetup from kiwi.builder.install import InstallImageBuilder @@ -234,7 +235,8 @@ def create_disk(self) -> Result: # an instance of a class with the sync_data capability # representing the entire image system except for the boot/ area # which could live on another part of the disk - system: Any = None + system: Union[FileSystemBase, VolumeManagerBase] = \ + FileSystemBase(DeviceProvider()) # an instance of a class with the sync_data capability # representing the boot/ area of the disk if not part of @@ -644,7 +646,7 @@ def _build_main_system( self, device_map: Dict, disk: Disk, - system: Any, + system: Union[FileSystemBase, VolumeManagerBase], system_boot: Optional[FileSystemBase], system_efi: Optional[FileSystemBase], system_spare: Optional[FileSystemBase], @@ -1136,13 +1138,15 @@ def _write_crypttab_to_system_image( ) def _write_generic_fstab_to_system_image( - self, device_map: Dict, system: Any + self, device_map: Dict, + system: Union[FileSystemBase, VolumeManagerBase] ) -> None: log.info('Creating generic system etc/fstab') self._write_generic_fstab(device_map, self.system_setup, system) def _write_generic_fstab_to_boot_image( - self, device_map: Dict, system: Any + self, device_map: Dict, + system: Union[FileSystemBase, VolumeManagerBase] ) -> None: if self.initrd_system == 'kiwi': log.info('Creating generic boot image etc/fstab') @@ -1152,7 +1156,7 @@ def _write_generic_fstab_to_boot_image( def _write_generic_fstab( self, device_map: Dict, setup: SystemSetup, - system: Any + system: Union[FileSystemBase, VolumeManagerBase] ) -> None: root_is_snapshot = \ self.xml_state.build_type.get_btrfs_root_is_snapshot() @@ -1291,7 +1295,8 @@ def _write_recovery_metadata_to_boot_image(self) -> None: ) def _write_bootloader_meta_data_to_system_image( - self, device_map: Dict, disk: Disk, system: Any + self, device_map: Dict, disk: Disk, + system: Union[FileSystemBase, VolumeManagerBase] ) -> None: if self.bootloader != 'custom': log.info('Creating %s bootloader configuration', self.bootloader) @@ -1353,7 +1358,8 @@ def _write_bootloader_meta_data_to_system_image( ) def _sync_system_to_image( - self, device_map: Dict, system: Any, + self, device_map: Dict, + system: Union[FileSystemBase, VolumeManagerBase], system_boot: Optional[FileSystemBase], system_efi: Optional[FileSystemBase], system_spare: Optional[FileSystemBase], @@ -1551,7 +1557,8 @@ def _sync_system_to_image( self.integrity_root.write_integrity_metadata() def _install_bootloader( - self, device_map: Dict, disk, system: Any + self, device_map: Dict, disk, + system: Union[FileSystemBase, VolumeManagerBase] ) -> None: root_device = device_map['root'] boot_device = root_device @@ -1632,7 +1639,9 @@ def _install_bootloader( self.diskname, boot_device.get_device() ) - def _setup_property_root_is_readonly_snapshot(self, system: Any) -> None: + def _setup_property_root_is_readonly_snapshot( + self, system: Union[FileSystemBase, VolumeManagerBase] + ) -> None: if self.volume_manager_name: root_is_snapshot = \ self.xml_state.build_type.get_btrfs_root_is_snapshot() diff --git a/kiwi/filesystem/base.py b/kiwi/filesystem/base.py index eea08fb8592..2a497fa3c60 100644 --- a/kiwi/filesystem/base.py +++ b/kiwi/filesystem/base.py @@ -265,6 +265,56 @@ def umount(self) -> None: log.info('umount %s instance', type(self).__name__) self.filesystem_mount.umount() + def umount_volumes(self) -> None: + """ + Consistency layer with regards to VolumeManager classes + + Invokes umount + """ + self.umount() + + def mount_volumes(self) -> None: + """ + Consistency layer with regards to VolumeManager classes + + Invokes mount + """ + self.mount() + + def get_volumes(self) -> Dict: + """ + Consistency layer with regards to VolumeManager classes + + Raises + """ + raise NotImplementedError + + def get_root_volume_name(self) -> None: + """ + Consistency layer with regards to VolumeManager classes + + Raises + """ + raise NotImplementedError + + def get_fstab( + self, persistency_type: str = 'by-label', filesystem_name: str = '' + ) -> List[str]: + """ + Consistency layer with regards to VolumeManager classes + + Raises + """ + raise NotImplementedError + + def set_property_readonly_root(self) -> None: + """ + Consistency layer with regards to VolumeManager classes + + Raises + """ + raise NotImplementedError + def _map_size(self, size: float, from_unit: str, to_unit: str) -> float: """ Return byte size value for given size and unit diff --git a/kiwi/volume_manager/base.py b/kiwi/volume_manager/base.py index 67cbdf319a4..f1e6dd9f354 100644 --- a/kiwi/volume_manager/base.py +++ b/kiwi/volume_manager/base.py @@ -187,6 +187,22 @@ def umount_volumes(self): """ raise NotImplementedError + def umount(self): + """ + Consistency layer with regards to FileSystem classes + + Invokes umount_volumes + """ + self.umount_volumes() + + def mount(self): + """ + Consistency layer with regards to FileSystem classes + + Invokes mount_volumes + """ + self.mount_volumes() + def is_loop(self): """ Check if storage provider is loop based diff --git a/kiwi/volume_manager/btrfs.py b/kiwi/volume_manager/btrfs.py index d8ad12e2a70..e504373cc94 100644 --- a/kiwi/volume_manager/btrfs.py +++ b/kiwi/volume_manager/btrfs.py @@ -269,7 +269,9 @@ def create_volumes(self, filesystem_name): volume_mount ) - def get_fstab(self, persistency_type='by-label', filesystem_name=None): + def get_fstab( + self, persistency_type: str = 'by-label', filesystem_name: str = '' + ) -> List[str]: """ Implements creation of the fstab entries. The method returns a list of fstab compatible entries diff --git a/kiwi/volume_manager/lvm.py b/kiwi/volume_manager/lvm.py index ab88349971f..aa97b6a0b55 100644 --- a/kiwi/volume_manager/lvm.py +++ b/kiwi/volume_manager/lvm.py @@ -17,6 +17,9 @@ # import os import logging +from typing import ( + Dict, List +) # project import kiwi.defaults as defaults @@ -228,7 +231,9 @@ def create_volumes(self, filesystem_name): for mount_path in Path.sort_by_hierarchy(sorted(volume_paths.keys())): self.mount_list.append(volume_paths[mount_path]) - def get_fstab(self, persistency_type, filesystem_name): + def get_fstab( + self, persistency_type: str = 'by-label', filesystem_name: str = '' + ) -> List[str]: """ Implements creation of the fstab entries. The method returns a list of fstab compatible entries @@ -266,7 +271,7 @@ def get_fstab(self, persistency_type, filesystem_name): return fstab_entries - def get_volumes(self): + def get_volumes(self) -> Dict: """ Return dict of volumes diff --git a/test/unit/filesystem/base_test.py b/test/unit/filesystem/base_test.py index eb89c364f85..3f1698a8ea6 100644 --- a/test/unit/filesystem/base_test.py +++ b/test/unit/filesystem/base_test.py @@ -111,12 +111,40 @@ def test_umount(self): self.fsbase.umount() mount.umount.assert_called_once_with() + def test_umount_volumes(self): + mount = Mock() + self.fsbase.filesystem_mount = mount + self.fsbase.umount_volumes() + mount.umount.assert_called_once_with() + def test_mount(self): mount = Mock() self.fsbase.filesystem_mount = mount self.fsbase.mount() mount.mount.assert_called_once_with([]) + def test_mount_volumes(self): + mount = Mock() + self.fsbase.filesystem_mount = mount + self.fsbase.mount_volumes() + mount.mount.assert_called_once_with([]) + + def test_get_volumes(self): + with raises(NotImplementedError): + self.fsbase.get_volumes() + + def test_get_root_volume_name(self): + with raises(NotImplementedError): + self.fsbase.get_root_volume_name() + + def test_get_fstab(self): + with raises(NotImplementedError): + self.fsbase.get_fstab() + + def test_set_property_readonly_root(self): + with raises(NotImplementedError): + self.fsbase.set_property_readonly_root() + def test_fs_size(self): # size of 100k must be 100k (default unit) assert self.fsbase._fs_size(100) == '100' diff --git a/test/unit/volume_manager/base_test.py b/test/unit/volume_manager/base_test.py index aaba787a34f..9aec10e4423 100644 --- a/test/unit/volume_manager/base_test.py +++ b/test/unit/volume_manager/base_test.py @@ -213,10 +213,18 @@ def test_mount_volumes(self): with raises(NotImplementedError): self.volume_manager.mount_volumes() + def test_mount(self): + with raises(NotImplementedError): + self.volume_manager.mount() + def test_umount_volumes(self): with raises(NotImplementedError): self.volume_manager.umount_volumes() + def test_umount(self): + with raises(NotImplementedError): + self.volume_manager.umount() + def test_get_volumes(self): with raises(NotImplementedError): self.volume_manager.get_volumes()