Пример #1
0
    def test_validate_with_task(self, publisher):
        """Test ValidateWithTask."""
        self.module.on_storage_changed(Mock())
        task_path = self.interface.ValidateWithTask()

        obj = check_task_creation(task_path, publisher, StorageValidateTask)
        assert obj.implementation._storage == self.module.storage

        report = ValidationReport()
        report.error_messages = [
            "Something is wrong.", "Something is very wrong."
        ]
        report.warning_messages = ["Something might be wrong."]
        obj.implementation._set_result(report)

        result = obj.GetResult()
        expected_result = get_variant(
            Structure, {
                "error-messages":
                get_variant(
                    List[Str],
                    ["Something is wrong.", "Something is very wrong."]),
                "warning-messages":
                get_variant(List[Str], ["Something might be wrong."])
            })

        assert isinstance(result, Variant)
        assert get_native(result) == get_native(expected_result)
        assert result.equal(expected_result)
Пример #2
0
    def validate_selected_disks(self, drives):
        """Validate the list of selected disks.

        :param drives: a list of drives names
        :return: a validation report
        """
        report = ValidationReport()
        report.error_messages = check_disk_selection(self.storage, drives)
        return report
Пример #3
0
    def validate_device_factory_request(self, request):
        """Validate the given device factory request.

        :param request: a device factory request
        :return: a validation report
        """
        report = ValidationReport()
        error = utils.validate_device_factory_request(self.storage, request)

        if error:
            report.error_messages.append(error)

        return report
Пример #4
0
    def validate_container_name(self, name):
        """Validate the given container name.

        :param name: a container name
        :return: a validation report
        """
        report = ValidationReport()
        error = utils.validate_container_name(self.storage, name)

        if error:
            report.error_messages.append(error)

        return report
Пример #5
0
    def check_completeness(self, device_name):
        """Check that the specified device is complete.

        :param device_name: a name of the device
        :return: a validation report
        """
        report = ValidationReport()
        device = self._get_device(device_name)
        message = utils.check_device_completeness(device)

        if message:
            report.error_messages.append(message)

        return report
Пример #6
0
    def validate_mount_point(self, mount_point):
        """Validate the given mount point.

        :param mount_point: a path to a mount point
        :return: a validation report
        """
        report = ValidationReport()
        mount_points = self.storage.mountpoints.keys()
        error = utils.validate_mount_point(mount_point, mount_points)

        if error:
            report.error_messages.append(error)

        return report
Пример #7
0
    def validate_raid_level(self, raid_level, num_members):
        """Validate the given RAID level.

        :param raid_level: a RAID level name
        :param num_members: a number of members
        :return: a validation report
        """
        report = ValidationReport()
        raid_level = utils.get_raid_level_by_name(raid_level)
        error = utils.validate_raid_level(raid_level, num_members)

        if error:
            report.error_messages.append(error)

        return report
Пример #8
0
    def _validate_storage(self, storage):
        """Validate the storage model.

        :param storage: an instance of Blivet
        :return: a validation report
        """
        result = storage_checker.check(storage)

        for message in result.info:
            log.debug(message)

        validation_report = ValidationReport()
        validation_report.error_messages = result.errors
        validation_report.warning_messages = result.warnings

        return validation_report
Пример #9
0
    def _resolve_selection(self):
        """Resolve the new selection."""
        log.debug("Resolving the software selection.")
        report = ValidationReport()

        with self._reported_errors(report):
            self._dnf_manager.disable_modules(self._selection.disabled_modules)

        with self._reported_errors(report):
            self._dnf_manager.enable_modules(self._selection.modules)

        with self._reported_errors(report):
            self._dnf_manager.apply_specs(self._include_list,
                                          self._exclude_list)

        with self._reported_errors(report):
            self._dnf_manager.resolve_selection()

        log.debug("Resolving has been completed: %s", report)
        return report
Пример #10
0
def apply_partitioning(partitioning, show_message_cb, reset_storage_cb):
    """Apply the given partitioning.

    :param partitioning: a DBus proxy of a partitioning
    :param show_message_cb: a callback for showing a message
    :param reset_storage_cb: a callback for resetting the storage
    :return: an instance of ValidationReport
    """
    log.debug("Applying partitioning")
    report = ValidationReport()

    try:
        show_message_cb(_("Saving storage configuration..."))
        task_path = partitioning.ConfigureWithTask()
        task_proxy = STORAGE.get_proxy(task_path)
        sync_run_task(task_proxy)
    except StorageConfigurationError as e:
        show_message_cb(_("Failed to save storage configuration"))
        report.error_messages.append(str(e))
        reset_bootloader()
        reset_storage_cb()
    except BootloaderConfigurationError as e:
        show_message_cb(_("Failed to save boot loader configuration"))
        report.error_messages.append(str(e))
        reset_bootloader()
    else:
        show_message_cb(_("Checking storage configuration..."))
        task_path = partitioning.ValidateWithTask()
        task_proxy = STORAGE.get_proxy(task_path)
        sync_run_task(task_proxy)

        result = unwrap_variant(task_proxy.GetResult())
        report = ValidationReport.from_structure(result)
        log.debug("Validation has been completed: %s", report)

        if report.is_valid():
            storage_proxy = STORAGE.get_proxy()
            storage_proxy.ApplyPartitioning(get_object_path(partitioning))
            log.debug("Partitioning has been applied.")

    return report