Beispiel #1
0
    def test_destroy_device(self):
        """Test DestroyDevice."""
        dev1 = StorageDevice("dev1",
                             exists=False,
                             size=Size("15 GiB"),
                             fmt=get_format("disklabel"))

        dev2 = StorageDevice("dev2",
                             exists=False,
                             parents=[dev1],
                             size=Size("6 GiB"),
                             fmt=get_format("ext4"))

        dev3 = StorageDevice("dev3",
                             exists=False,
                             size=Size("15 GiB"),
                             fmt=get_format("disklabel"))

        self.module.on_storage_changed(create_storage())
        self.module.storage.devicetree._add_device(dev1)
        self.module.storage.devicetree._add_device(dev2)
        self.module.storage.devicetree._add_device(dev3)

        with pytest.raises(StorageConfigurationError):
            self.interface.DestroyDevice("dev1")

        assert dev1 in self.module.storage.devices
        assert dev2 in self.module.storage.devices
        assert dev3 in self.module.storage.devices

        self.interface.DestroyDevice("dev2")

        assert dev1 not in self.module.storage.devices
        assert dev2 not in self.module.storage.devices
        assert dev3 in self.module.storage.devices

        self.interface.DestroyDevice("dev3")

        assert dev1 not in self.module.storage.devices
        assert dev2 not in self.module.storage.devices
        assert dev3 not in self.module.storage.devices
    def test_is_device_shrinkable(self, update_size_info):
        """Test IsDeviceShrinkable."""
        self.module.on_storage_changed(create_storage())

        dev1 = StorageDevice(
            "dev1",
            exists=True,
            size=Size("10 GiB"),
            fmt=get_format(None, exists=True)
        )

        self._add_device(dev1)
        assert self.interface.IsDeviceShrinkable("dev1") == False

        dev1._resizable = True
        dev1.format._resizable = True
        dev1.format._min_size = Size("1 GiB")
        assert self.interface.IsDeviceShrinkable("dev1") == True

        dev1.format._min_size = Size("10 GiB")
        assert self.interface.IsDeviceShrinkable("dev1") == False
Beispiel #3
0
    def test_luks1_format_args(self):
        storage = create_storage()
        storage._escrow_certificates["file:///tmp/escrow.crt"] = "CERTIFICATE"

        request = PartitioningRequest()
        request.encrypted = True
        request.passphrase = "passphrase"
        request.luks_version = "luks1"
        request.cipher = "aes-xts-plain64"
        request.escrow_certificate = "file:///tmp/escrow.crt"
        request.backup_passphrase_enabled = True

        args = AutomaticPartitioningTask._get_luks_format_args(
            storage, request)
        assert args == {
            "passphrase": "passphrase",
            "cipher": "aes-xts-plain64",
            "luks_version": "luks1",
            "pbkdf_args": None,
            "escrow_cert": "CERTIFICATE",
            "add_backup_passphrase": True,
        }
    def test_get_device_partitions(self):
        """Test GetDevicePartitions."""
        self.module.on_storage_changed(create_storage())
        dev1 = DiskDevice(
            "dev1"
        )
        self._add_device(dev1)

        dev2 = DiskDevice(
            "dev2",
            fmt=get_format("disklabel")
        )
        self._add_device(dev2)

        dev3 = PartitionDevice(
            "dev3"
        )
        dev2.add_child(dev3)
        self._add_device(dev3)

        assert self.interface.GetDevicePartitions("dev1") == []
        assert self.interface.GetDevicePartitions("dev2") == ["dev3"]
        assert self.interface.GetDevicePartitions("dev3") == []
Beispiel #5
0
    def test_opal_verification_old_firmware(self, mocked_arch, version_getter, xfs_mountable):
        """Check verify_opal_compatibility with an older firmware."""
        storage = create_storage()

        mocked_arch.get_arch.return_value = "ppc64le"
        mocked_arch.is_powernv.return_value = True
        version_getter.return_value = "5.9.50-openpower1-p59fd803"
        xfs_mountable.return_value = True

        # No devices.
        self._verify_opal_compatibility(storage, message=None)

        # No mount points.
        dev1 = StorageDevice("dev1", size=Size("10 GiB"))
        storage.devicetree._add_device(dev1)

        self._verify_opal_compatibility(storage, message=None)

        # Different filesystem.
        dev1.format = get_format("ext2", mountpoint="/boot")
        self._verify_opal_compatibility(storage, message=None)

        # XFS on /
        dev1.format = get_format("xfs", mountpoint="/")
        self._verify_opal_compatibility(storage, message=(
            "Your firmware doesn't support XFS file system features "
            "on the /boot file system. The system will not be bootable. "
            "Please, upgrade the firmware or change the file system type."
        ))

        # XFS on /boot
        dev1.format = get_format("xfs", mountpoint="/boot")
        self._verify_opal_compatibility(storage, message=(
            "Your firmware doesn't support XFS file system features "
            "on the /boot file system. The system will not be bootable. "
            "Please, upgrade the firmware or change the file system type."
        ))
Beispiel #6
0
    def test_get_device_tree(self, publisher):
        """Test GetDeviceTree."""
        reset_dbus_container(DeviceTreeContainer)
        self.module.on_storage_changed(create_storage())

        tree_path = self.interface.GetDeviceTree()

        publisher.assert_called_once()
        object_path, obj = publisher.call_args[0]

        assert tree_path == object_path
        assert isinstance(obj, DeviceTreeInterface)

        assert obj.implementation == self.module._device_tree_module
        assert obj.implementation.storage == self.module.storage
        assert tree_path.endswith("/DeviceTree/1")

        publisher.reset_mock()

        assert tree_path == self.interface.GetDeviceTree()
        assert tree_path == self.interface.GetDeviceTree()
        assert tree_path == self.interface.GetDeviceTree()

        publisher.assert_not_called()
Beispiel #7
0
    def get_device_tree_test(self, publisher):
        """Test GetDeviceTree."""
        DeviceTreeContainer._counter = 0
        self.module.on_storage_changed(create_storage())

        tree_path = self.interface.GetDeviceTree()

        publisher.assert_called_once()
        object_path, obj = publisher.call_args[0]

        self.assertEqual(tree_path, object_path)
        self.assertIsInstance(obj, DeviceTreeInterface)

        self.assertEqual(obj.implementation, self.module._device_tree_module)
        self.assertEqual(obj.implementation.storage, self.module.storage)
        self.assertTrue(tree_path.endswith("/DeviceTree/1"))

        publisher.reset_mock()

        self.assertEqual(tree_path, self.interface.GetDeviceTree())
        self.assertEqual(tree_path, self.interface.GetDeviceTree())
        self.assertEqual(tree_path, self.interface.GetDeviceTree())

        publisher.assert_not_called()
 def test_find_existing_systems(self):
     storage = create_storage()
     task = FindExistingSystemsTask(storage.devicetree)
     assert task.run() == []
Beispiel #9
0
 def setUp(self):
     self.maxDiff = None
     self.storage = create_storage()
Beispiel #10
0
 def device_tree_test(self, publisher):
     """Test the device tree."""
     self.module.on_storage_changed(create_storage())
     path = self.interface.GetDeviceTree()
     check_dbus_object_creation(self, path, publisher, DeviceTreeSchedulerModule)
Beispiel #11
0
 def request_handler_test(self):
     """Test the request_handler property."""
     self.module.on_storage_changed(create_storage())
     self.assertIsNotNone(self.module.request_handler)
     self.assertEqual(self.module.storage_handler, self.module.request_handler.blivet_utils)
Beispiel #12
0
 def test_gather_no_requests(self):
     """Test GatherRequests with no devices."""
     self.module.on_storage_changed(create_storage())
     assert self.interface.GatherRequests() == []
Beispiel #13
0
 def setUp(self):
     flags.testing = True
     self._storage = create_storage()
     self._config = DiskInitializationConfig()
Beispiel #14
0
 def storage_handler_test(self):
     """Test the storage_handler property."""
     self.module.on_storage_changed(create_storage())
     self.assertIsNotNone(self.module.storage_handler)
     self.assertEqual(self.module.storage, self.module.storage_handler.storage)
 def test_storage_handler(self):
     """Test the storage_handler property."""
     self.module.on_storage_changed(create_storage())
     assert self.module.storage_handler is not None
     assert self.module.storage == self.module.storage_handler.storage
 def test_request_handler(self):
     """Test the request_handler property."""
     self.module.on_storage_changed(create_storage())
     assert self.module.request_handler is not None
     assert self.module.storage_handler == self.module.request_handler.blivet_utils
 def gather_no_requests_test(self):
     """Test GatherRequests with no devices."""
     self.module.on_storage_changed(create_storage())
     self.assertEqual(self.interface.GatherRequests(), [])
    def test_validate_selected_disks(self):
        """Test ValidateSelectedDisks."""
        storage = create_storage()
        self.disk_selection_module.on_storage_changed(storage)

        dev1 = DiskDevice("dev1",
                          exists=False,
                          size=Size("15 GiB"),
                          fmt=get_format("disklabel"))
        dev2 = DiskDevice("dev2",
                          exists=False,
                          parents=[dev1],
                          size=Size("6 GiB"),
                          fmt=get_format("disklabel"))
        dev3 = DiskDevice("dev3",
                          exists=False,
                          parents=[dev2],
                          size=Size("6 GiB"),
                          fmt=get_format("disklabel"))
        storage.devicetree._add_device(dev1)
        storage.devicetree._add_device(dev2)
        storage.devicetree._add_device(dev3)

        report = ValidationReport.from_structure(
            self.disk_selection_interface.ValidateSelectedDisks([]))

        assert report.is_valid() == True

        report = ValidationReport.from_structure(
            self.disk_selection_interface.ValidateSelectedDisks(["devX"]))

        assert report.is_valid() == False
        assert report.error_messages == [
            "The selected disk devX is not recognized."
        ]
        assert report.warning_messages == []

        report = ValidationReport.from_structure(
            self.disk_selection_interface.ValidateSelectedDisks(["dev1"]))

        assert report.is_valid() == False
        assert report.error_messages == [
            "You selected disk dev1, which contains devices that also use "
            "unselected disks dev2, dev3. You must select or de-select "
            "these disks as a set."
        ]
        assert report.warning_messages == []

        report = ValidationReport.from_structure(
            self.disk_selection_interface.ValidateSelectedDisks(
                ["dev1", "dev2"]))

        assert report.is_valid() == False
        assert report.error_messages == [
            "You selected disk dev1, which contains devices that also "
            "use unselected disk dev3. You must select or de-select "
            "these disks as a set.",
            "You selected disk dev2, which contains devices that also "
            "use unselected disk dev3. You must select or de-select "
            "these disks as a set."
        ]
        assert report.warning_messages == []

        report = ValidationReport.from_structure(
            self.disk_selection_interface.ValidateSelectedDisks(
                ["dev1", "dev2", "dev3"]))

        assert report.is_valid() == True
Beispiel #19
0
 def setUp(self):
     """Set up the module."""
     self.maxDiff = None
     self.module = DeviceTreeSchedulerModule()
     self.interface = DeviceTreeSchedulerInterface(self.module)
     self.module.on_storage_changed(create_storage())
Beispiel #20
0
 def is_device_resizable_test(self):
     """Test IsDeviceResizable."""
     self.module.on_storage_changed(create_storage())
     self._add_device(StorageDevice("dev1"))
     self.assertEqual(self.interface.IsDeviceResizable("dev1"), False)
Beispiel #21
0
    def __init__(self):
        super().__init__()
        # The storage model.
        self._current_storage = None
        self._storage_playground = None
        self.storage_changed = Signal()

        # The created partitioning modules.
        self._created_partitioning = []
        self.created_partitioning_changed = Signal()

        # The applied partitioning module.
        self._applied_partitioning = None
        self.applied_partitioning_changed = Signal()
        self.partitioning_reset = Signal()

        # Initialize modules.
        self._modules = []

        self._storage_checker_module = StorageCheckerModule()
        self._add_module(self._storage_checker_module)

        self._device_tree_module = DeviceTreeModule()
        self._add_module(self._device_tree_module)

        self._disk_init_module = DiskInitializationModule()
        self._add_module(self._disk_init_module)

        self._disk_selection_module = DiskSelectionModule()
        self._add_module(self._disk_selection_module)

        self._snapshot_module = SnapshotModule()
        self._add_module(self._snapshot_module)

        self._bootloader_module = BootloaderModule()
        self._add_module(self._bootloader_module)

        self._fcoe_module = FCOEModule()
        self._add_module(self._fcoe_module)

        self._iscsi_module = ISCSIModule()
        self._add_module(self._iscsi_module)

        self._nvdimm_module = NVDIMMModule()
        self._add_module(self._nvdimm_module)

        self._dasd_module = DASDModule()
        self._add_module(self._dasd_module)

        self._zfcp_module = ZFCPModule()
        self._add_module(self._zfcp_module)

        # Connect modules to signals.
        self.storage_changed.connect(
            self._device_tree_module.on_storage_changed
        )
        self.storage_changed.connect(
            self._disk_init_module.on_storage_changed
        )
        self.storage_changed.connect(
            self._disk_selection_module.on_storage_changed
        )
        self.storage_changed.connect(
            self._snapshot_module.on_storage_changed
        )
        self.storage_changed.connect(
            self._bootloader_module.on_storage_changed
        )
        self.storage_changed.connect(
            self._nvdimm_module.on_storage_changed
        )
        self.storage_changed.connect(
            self._dasd_module.on_storage_changed
        )
        self._disk_init_module.format_unrecognized_enabled_changed.connect(
            self._dasd_module.on_format_unrecognized_enabled_changed
        )
        self._disk_init_module.format_ldl_enabled_changed.connect(
            self._dasd_module.on_format_ldl_enabled_changed
        )
        self._disk_selection_module.protected_devices_changed.connect(
            self.on_protected_devices_changed
        )

        # After connecting modules to signals, create the initial
        # storage model. It will be propagated to all modules.
        self._set_storage(create_storage())
Beispiel #22
0
    def fix_btrfs_test(self, configure, install, conf):
        """Test the final configuration of the boot loader."""
        storage = create_storage()
        sysroot = "/tmp/sysroot"
        version = "4.17.7-200.fc28.x86_64"

        conf.target.is_directory = True
        FixBTRFSBootloaderTask(storage=storage,
                               mode=BootloaderMode.ENABLED,
                               payload_type=PAYLOAD_TYPE_RPM_OSTREE,
                               kernel_versions=[version],
                               sysroot=sysroot).run()
        configure.assert_not_called()
        install.assert_not_called()

        conf.target.is_directory = True
        FixBTRFSBootloaderTask(storage=storage,
                               mode=BootloaderMode.ENABLED,
                               payload_type=PAYLOAD_TYPE_LIVE_IMAGE,
                               kernel_versions=[version],
                               sysroot=sysroot).run()
        configure.assert_not_called()
        install.assert_not_called()

        conf.target.is_directory = False
        FixBTRFSBootloaderTask(storage=storage,
                               mode=BootloaderMode.DISABLED,
                               payload_type=PAYLOAD_TYPE_LIVE_IMAGE,
                               kernel_versions=[version],
                               sysroot=sysroot).run()
        configure.assert_not_called()
        install.assert_not_called()

        conf.target.is_directory = False
        FixBTRFSBootloaderTask(storage=storage,
                               mode=BootloaderMode.ENABLED,
                               payload_type=PAYLOAD_TYPE_LIVE_IMAGE,
                               kernel_versions=[version],
                               sysroot=sysroot).run()
        configure.assert_not_called()
        install.assert_not_called()

        dev1 = DiskDevice("dev1",
                          fmt=get_format("disklabel"),
                          size=Size("10 GiB"))
        storage.devicetree._add_device(dev1)

        dev2 = BTRFSDevice("dev2",
                           fmt=get_format("btrfs", mountpoint="/"),
                           size=Size("5 GiB"),
                           parents=[dev1])
        storage.devicetree._add_device(dev2)

        # Make the btrfs format mountable.
        dev2.format._mount = Mock(available=True)

        conf.target.is_directory = False
        FixBTRFSBootloaderTask(storage=storage,
                               mode=BootloaderMode.ENABLED,
                               payload_type=PAYLOAD_TYPE_LIVE_IMAGE,
                               kernel_versions=[version],
                               sysroot=sysroot).run()
        configure.assert_called_once_with(storage, BootloaderMode.ENABLED,
                                          PAYLOAD_TYPE_LIVE_IMAGE, [version],
                                          sysroot)
        install.assert_called_once_with(storage, BootloaderMode.ENABLED)
Beispiel #23
0
 def test_find_existing_systems(self):
     storage = create_storage()
     task = FindExistingSystemsTask(storage.devicetree)
     self.assertEqual(task.run(), [])