示例#1
0
    def test_get_object_path(self):
        """Test get_object_path."""
        proxy = ObjectProxy(Mock(), "my.service", "/my/path")
        self.assertEqual(get_object_path(proxy), "/my/path")

        with self.assertRaises(TypeError):
            get_object_path(None)
示例#2
0
    def test_get_object_path(self):
        """Test get_object_path."""
        proxy = ObjectProxy(Mock(), "my.service", "/my/path")
        self.assertEqual(get_object_path(proxy), "/my/path")

        with self.assertRaises(TypeError) as cm:
            get_object_path(None)

        self.assertEqual("Invalid type 'NoneType'.", str(cm.exception))
示例#3
0
def set_source(payload_proxy, source_proxy):
    """Attach the source to the payload.

    :param payload_proxy: a DBus proxy of a payload
    :param source_proxy: a DBus proxy of a source
    """
    object_path = get_object_path(source_proxy)
    payload_proxy.Sources = [object_path]
示例#4
0
    def set_from_opts(self, opts):
        """Add the flatpak source if available."""
        flatpak_source = create_source(SOURCE_TYPE_FLATPAK)

        if not flatpak_source.IsAvailable():
            log.debug("The flatpak source is not available.")
            return

        sources = self.proxy.Sources
        sources.append(get_object_path(flatpak_source))
        self.proxy.SetSources(sources)
示例#5
0
    def _do_check(self):
        self.clear_errors()
        StorageCheckHandler.errors = []
        StorageCheckHandler.warnings = []

        try:
            log.debug("Generating updated storage configuration")
            task_path = self._partitioning.ConfigureWithTask()
            task_proxy = STORAGE.get_proxy(task_path)
            sync_run_task(task_proxy)
        except BootloaderConfigurationError as e:
            log.error("Storage configuration failed: %s", e)
            StorageCheckHandler.errors = [str(e)]
            reset_bootloader()
        else:
            log.debug("Checking storage configuration...")
            task_path = self._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)
            StorageCheckHandler.errors = report.error_messages
            StorageCheckHandler.warnings = report.warning_messages

            if report.is_valid():
                self._storage_module.ApplyPartitioning(
                    get_object_path(self._partitioning))

        if self.errors:
            self.set_warning(
                _("Error checking storage configuration.  <a href=\"\">Click for details</a> or press Done again to continue."
                  ))
        elif self.warnings:
            self.set_warning(
                _("Warning checking storage configuration.  <a href=\"\">Click for details</a> or press Done again to continue."
                  ))

        # on_info_bar_clicked requires self._error to be set, so set it to the
        # list of all errors and warnings that storage checking found.
        self._error = "\n".join(self.errors + self.warnings)

        return self._error == ""
示例#6
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