Beispiel #1
0
    def update_container_data_test(self):
        """Test UpdateContainerData."""
        pv1 = StorageDevice(
            "pv1",
            size=Size("1025 MiB"),
            fmt=get_format("lvmpv")
        )
        pv2 = StorageDevice(
            "pv2",
            size=Size("513 MiB"),
            fmt=get_format("lvmpv")
        )
        vg = LVMVolumeGroupDevice(
            "testvg",
            parents=[pv1, pv2]
        )

        self._add_device(pv1)
        self._add_device(pv2)
        self._add_device(vg)

        request = DeviceFactoryRequest()
        request.device_type = DEVICE_TYPE_PARTITION

        with self.assertRaises(StorageError):
            self.interface.UpdateContainerData(
                    DeviceFactoryRequest.to_structure(request),
                    "anaconda"
            )

        request.device_type = DEVICE_TYPE_BTRFS
        request = DeviceFactoryRequest.from_structure(
            self.interface.UpdateContainerData(
                DeviceFactoryRequest.to_structure(request),
                "anaconda"
            )
        )

        self.assertEqual(request.container_spec, "")
        self.assertEqual(request.container_name, "anaconda")
        self.assertEqual(request.container_encrypted, False)
        self.assertEqual(request.container_raid_level, "single")
        self.assertEqual(request.container_size_policy, 0)
        self.assertEqual(request.disks, [])

        request.device_type = DEVICE_TYPE_LVM
        request = DeviceFactoryRequest.from_structure(
            self.interface.UpdateContainerData(
                DeviceFactoryRequest.to_structure(request),
                "testvg"
            )
        )

        self.assertEqual(request.container_spec, "testvg")
        self.assertEqual(request.container_name, "testvg")
        self.assertEqual(request.container_encrypted, False)
        self.assertEqual(request.container_raid_level, "")
        self.assertEqual(request.container_size_policy, Size("1.5 GiB").get_bytes())
        self.assertEqual(request.disks, [])
Beispiel #2
0
    def ChangeDevice(self, request: Structure, original_request: Structure):
        """Change a device in the storage model.

        FIXME: Remove the original request from the arguments.

        :param request: a device factory request
        :param original_request: an original device factory request
        :raise: StorageError if the device cannot be changed
        """
        self.implementation.change_device(
            DeviceFactoryRequest.from_structure(request),
            DeviceFactoryRequest.from_structure(original_request))
Beispiel #3
0
    def AddDevice(self, request: Structure):
        """Add a new device to the storage model.

        :param request: a device factory request
        :raise: StorageError if the device cannot be created
        """
        self.implementation.add_device(
            DeviceFactoryRequest.from_structure(request))
Beispiel #4
0
    def ValidateDeviceFactoryRequest(self, request: Structure) -> Structure:
        """Validate the given device factory request.

        :param request: a device factory request
        :return: a validation report
        """
        request = DeviceFactoryRequest.from_structure(request)
        report = self.implementation.validate_device_factory_request(request)
        return ValidationReport.to_structure(report)
    def GenerateContainerData(self, request: Structure) -> Structure:
        """Generate the container data for the device factory request.

        :param request: a device factory request
        :return: a device factory request
        """
        request = DeviceFactoryRequest.from_structure(request)
        self.implementation.generate_container_data(request)
        return DeviceFactoryRequest.to_structure(request)
    def test_update_container_data(self):
        """Test UpdateContainerData."""
        pv1 = StorageDevice("pv1",
                            size=Size("1025 MiB"),
                            fmt=get_format("lvmpv"))
        pv2 = StorageDevice("pv2",
                            size=Size("513 MiB"),
                            fmt=get_format("lvmpv"))
        vg = LVMVolumeGroupDevice("testvg", parents=[pv1, pv2])

        self._add_device(pv1)
        self._add_device(pv2)
        self._add_device(vg)

        request = DeviceFactoryRequest()
        request.device_type = DEVICE_TYPE_PARTITION

        with pytest.raises(StorageError):
            self.interface.UpdateContainerData(
                DeviceFactoryRequest.to_structure(request), "anaconda")

        request.device_type = DEVICE_TYPE_BTRFS
        request = DeviceFactoryRequest.from_structure(
            self.interface.UpdateContainerData(
                DeviceFactoryRequest.to_structure(request), "anaconda"))

        assert request.container_spec == ""
        assert request.container_name == "anaconda"
        assert request.container_encrypted is False
        assert request.container_raid_level == "single"
        assert request.container_size_policy == 0
        assert request.disks == []

        request.device_type = DEVICE_TYPE_LVM
        request = DeviceFactoryRequest.from_structure(
            self.interface.UpdateContainerData(
                DeviceFactoryRequest.to_structure(request), "testvg"))

        assert request.container_spec == "testvg"
        assert request.container_name == "testvg"
        assert request.container_encrypted is False
        assert request.container_raid_level == ""
        assert request.container_size_policy == Size("1.5 GiB").get_bytes()
        assert request.disks == []
    def UpdateContainerData(self, request: Structure,
                            container_name: Str) -> Structure:
        """Update the container data in the device factory request.

        :param request: a device factory request
        :param container_name: a container name
        :return: a device factory request
        """
        request = DeviceFactoryRequest.from_structure(request)
        self.implementation.update_container_data(request, container_name)
        return DeviceFactoryRequest.to_structure(request)
Beispiel #8
0
    def GenerateDeviceFactoryPermissions(self,
                                         request: Structure) -> Structure:
        """Generate device factory permissions for the given request.

        The permissions will reflect which device attributes we are allowed
        to change in the requested device.

        :param request: a device factory request
        :return: device factory permissions
        """
        request = DeviceFactoryRequest.from_structure(request)
        permissions = self.implementation.generate_device_factory_permissions(
            request)
        return DeviceFactoryPermissions.to_structure(permissions)
Beispiel #9
0
    def generate_container_data_test(self, proxy_getter):
        """Test GenerateContainerData."""
        network_proxy = Mock()
        network_proxy.Hostname = "localhost"
        network_proxy.GetCurrentHostname.return_value = "localhost"
        proxy_getter.return_value = network_proxy

        pv1 = StorageDevice("pv1",
                            size=Size("1025 MiB"),
                            fmt=get_format("lvmpv"))
        pv2 = StorageDevice("pv2",
                            size=Size("513 MiB"),
                            fmt=get_format("lvmpv"))
        vg = LVMVolumeGroupDevice("testvg", parents=[pv1, pv2])
        lv = LVMLogicalVolumeDevice("testlv",
                                    size=Size("512 MiB"),
                                    parents=[vg],
                                    fmt=get_format("xfs"),
                                    exists=False,
                                    seg_type="raid1",
                                    pvs=[pv1, pv2])

        self._add_device(pv1)
        self._add_device(pv2)
        self._add_device(vg)
        self._add_device(lv)

        request = DeviceFactoryRequest()
        request.device_spec = lv.name

        request.device_type = DEVICE_TYPE_LVM
        request = DeviceFactoryRequest.from_structure(
            self.interface.GenerateContainerData(
                DeviceFactoryRequest.to_structure(request)))

        self.assertEqual(request.container_spec, "testvg")
        self.assertEqual(request.container_name, "testvg")
        self.assertEqual(request.container_encrypted, False)
        self.assertEqual(request.container_raid_level, "")
        self.assertEqual(request.container_size_policy,
                         Size("1.5 GiB").get_bytes())

        request.device_type = DEVICE_TYPE_BTRFS
        request = DeviceFactoryRequest.from_structure(
            self.interface.GenerateContainerData(
                DeviceFactoryRequest.to_structure(request)))

        self.assertEqual(request.container_spec, "")
        self.assertEqual(request.container_name, "anaconda")
        self.assertEqual(request.container_encrypted, False)
        self.assertEqual(request.container_raid_level, "single")
        self.assertEqual(request.container_size_policy, 0)

        request.device_type = DEVICE_TYPE_PARTITION
        request = DeviceFactoryRequest.from_structure(
            self.interface.GenerateContainerData(
                DeviceFactoryRequest.to_structure(request)))

        self.assertEqual(request.container_spec, "")
        self.assertEqual(request.container_name, "")
        self.assertEqual(request.container_encrypted, False)
        self.assertEqual(request.container_raid_level, "")
        self.assertEqual(request.container_size_policy, 0)