Esempio n. 1
0
    def test_is_available(self):
        """Test check for flatpak availability of the system sources."""
        assert not FlatpakManager.is_source_available()

        with TemporaryDirectory() as temp:
            FlatpakManager.LOCAL_REMOTE_PATH = "file://" + temp

            assert FlatpakManager.is_source_available()
Esempio n. 2
0
    def is_available_test(self):
        """Test check for flatpak availability of the system sources."""
        self.assertFalse(FlatpakManager.is_source_available())

        with TemporaryDirectory() as temp:
            FlatpakManager.LOCAL_REMOTE_PATH = "file://" + temp

            self.assertTrue(FlatpakManager.is_source_available())
    def test_disabled_progress_reporting(self):
        """Test a callback with disabled progress reporting."""
        flatpak = FlatpakManager(sysroot="remote/path")

        flatpak._operation_started_callback(
            transaction=Mock(),
            operation=OperationMock(),
            progress=Mock(),
        )
    def test_get_empty_refs_required_space(self, remote_cls, installation_cls,
                                           transaction_cls):
        """Test flatpak required space method with no refs."""
        flatpak = FlatpakManager("any path")
        self._setup_flatpak_objects(remote_cls, installation_cls,
                                    transaction_cls)

        flatpak.initialize_with_system_path()
        self._installation.list_remote_refs_sync.return_value = []

        assert flatpak.get_required_size() == 0
    def test_get_required_space(self, remote_cls, installation_cls,
                                transaction_cls):
        """Test flatpak required space method."""
        flatpak = FlatpakManager("any path")
        self._setup_flatpak_objects(remote_cls, installation_cls,
                                    transaction_cls)

        flatpak.initialize_with_system_path()
        self._installation.list_remote_refs_sync.return_value = [
            RefMock(installed_size=2000),
            RefMock(installed_size=3000),
            RefMock(installed_size=100)
        ]

        assert flatpak.get_required_size() == 5100
    def test_operation_started_callback(self):
        """Test the callback for started operations."""
        progress = Mock()
        flatpak = FlatpakManager(sysroot="remote/path", callback=progress)

        with self.assertLogs(level="DEBUG") as cm:
            flatpak._operation_started_callback(
                transaction=Mock(),
                operation=OperationMock("app/org.test"),
                progress=Mock(),
            )

        progress.assert_called_once_with("Installing app/org.test")

        msg = "Flatpak operation: install of ref app/org.test state started"
        assert msg in "\n".join(cm.output)
Esempio n. 7
0
    def payload(self):
        # Try to find the payload class.  First try the install
        # class.  If it doesn't give us one, fall back to the default.
        if not self._payload:
            # Get the type of the DBus payload module if any.
            payload_type = self._get_dbus_payload_type()

            if payload_type == PAYLOAD_TYPE_RPM_OSTREE:
                if FlatpakManager.is_source_available():
                    from pyanaconda.payload.rpmostreepayload import RPMOSTreePayloadWithFlatpaks
                    klass = RPMOSTreePayloadWithFlatpaks
                else:
                    from pyanaconda.payload.rpmostreepayload import RPMOSTreePayload
                    klass = RPMOSTreePayload
            elif self.opts.liveinst:
                from pyanaconda.payload.live import LiveOSPayload
                klass = LiveOSPayload
            elif self.ksdata.liveimg.seen:
                from pyanaconda.payload.live import LiveImagePayload
                klass = LiveImagePayload
            else:
                from pyanaconda.payload.dnf import DNFPayload
                klass = DNFPayload

            self._payload = klass(self.ksdata)

        return self._payload
Esempio n. 8
0
    def test_initialize_with_path(self, remote_cls, installation_cls, transaction_cls):
        """Test flatpak initialize with path."""
        self._setup_flatpak_objects(remote_cls, installation_cls, transaction_cls)

        flatpak = FlatpakManager("/mock/system/root/path")
        flatpak.initialize_with_path("/test/path/installation")

        remote_cls.new.assert_called_once()
        installation_cls.new_for_path.assert_called_once()
        transaction_cls.new_for_installation.assert_called_once_with(self._installation)

        expected_remote_calls = [call.set_gpg_verify(False),
                                 call.set_url(flatpak.LOCAL_REMOTE_PATH)]
        self.assertEqual(self._remote.method_calls, expected_remote_calls)

        expected_remote_calls = [call.add_remote(self._remote, False, None)]
        self.assertEqual(self._installation.method_calls, expected_remote_calls)
    def test_operation_error_callback(self):
        """Test the callback for failed operations."""
        progress = Mock()
        flatpak = FlatpakManager(sysroot="remote/path", callback=progress)

        with self.assertLogs(level="DEBUG") as cm:
            flatpak._operation_error_callback(
                transaction=Mock(),
                operation=OperationMock("app/org.test"),
                error=Mock(message="Fake!"),
                details=Mock(),
            )

        progress.assert_not_called()

        msg = "Flatpak operation: install of ref app/org.test state failed"
        assert msg in "\n".join(cm.output)

        msg = "Flatpak operation has failed with a message: 'Fake!'"
        assert msg in "\n".join(cm.output)
    def test_install(self, remote_cls, installation_cls, transaction_cls):
        """Test flatpak installation is working."""
        progress = Mock()
        flatpak = FlatpakManager(sysroot="remote/path", callback=progress)

        self._setup_flatpak_objects(remote_cls, installation_cls,
                                    transaction_cls)
        flatpak.initialize_with_system_path()

        self._installation.list_remote_refs_sync.return_value = [
            RefMock("app/org.space.coolapp/x86_64/stable"),
            RefMock("app/com.prop.notcoolapp/i386/f36"),
            RefMock("runtime/org.space.coolruntime/x86_64/stable"),
            RefMock("runtime/com.prop.notcoolruntime/i386/f36"),
        ]

        flatpak.install_all()
        assert self._transaction.mock_calls == [
            call.connect("new_operation", flatpak._operation_started_callback),
            call.connect("operation_done",
                         flatpak._operation_stopped_callback),
            call.connect("operation_error", flatpak._operation_error_callback),
            call.add_install(FlatpakManager.LOCAL_REMOTE_NAME,
                             "app/org.space.coolapp/x86_64/stable", None),
            call.add_install(FlatpakManager.LOCAL_REMOTE_NAME,
                             "app/com.prop.notcoolapp/i386/f36", None),
            call.add_install(FlatpakManager.LOCAL_REMOTE_NAME,
                             "runtime/org.space.coolruntime/x86_64/stable",
                             None),
            call.add_install(FlatpakManager.LOCAL_REMOTE_NAME,
                             "runtime/com.prop.notcoolruntime/i386/f36", None),
            call.run()
        ]

        assert progress.mock_calls == []
    def test_replace_remote(self, remote_cls, installation_cls,
                            transaction_cls, open_mock, variant_type, variant):
        """Test flatpak replace remote for installed refs call."""
        flatpak = FlatpakManager("/system/test-root")
        self._setup_flatpak_objects(remote_cls, installation_cls,
                                    transaction_cls)

        install_path_mock = Mock()
        install_path_mock.get_path.return_value = "/path"

        self._installation.get_path.return_value = install_path_mock
        self._installation.list_installed_refs.return_value = [
            RefMock("app/org.test/x86_64/stable"),
            RefMock("runtime/org.run/x86_64/stable"),
        ]

        flatpak.initialize_with_system_path()
        flatpak.replace_installed_refs_remote("cylon_officer")

        # test that every file is read and written
        open_mock.has_calls([
            call("/path/app/org.test/x86_64/stable/active/deploy", "rb"),
            call("/path/app/org.test/x86_64/stable/active/deploy", "wb"),
            call("/path/runtime/org.run/x86_64/stable/active/deploy", "rb"),
            call("/path/runtime/org.run/x86_64/stable/active/deploy", "wb"),
        ])
Esempio n. 12
0
    def run(self):
        """Find the size of flatpaks to install.

        :return: the required size
        :rtype: Size
        """
        flatpak_payload = FlatpakManager(self._sysroot)

        # Initialize temporal repo to enable reading of the remote
        flatpak_payload.initialize_with_path("/var/tmp/anaconda-flatpak-temp")

        required_size = Size(flatpak_payload.get_required_size())
        # Clean up temporal repo again
        flatpak_payload.cleanup()

        return required_size
Esempio n. 13
0
    def test_cleanup_call_no_repo(self, remote_cls, installation_cls, transaction_cls, rmtree):
        """Test the cleanup call with no repository created."""
        flatpak = FlatpakManager("any path")

        self._setup_flatpak_objects(remote_cls, installation_cls, transaction_cls)

        file_mock_path = Mock()
        file_mock_path.get_path.return_value = "/install/test/path"
        self._installation.get_path.return_value = file_mock_path

        flatpak.initialize_with_path("/install/test/path")
        flatpak.cleanup()

        rmtree.assert_not_called()
Esempio n. 14
0
    def test_add_remote(self, remote_cls, installation_cls, transaction_cls):
        """Test flatpak add new remote."""
        flatpak = FlatpakManager("remote/path")

        self._setup_flatpak_objects(remote_cls, installation_cls, transaction_cls)

        flatpak.initialize_with_system_path()
        flatpak.add_remote("hive", "url://zerglings/home")

        remote_cls.new.assert_called_with("hive")
        self._remote.set_gpg_verify.assert_called_with(True)
        self._remote.set_url("url://zerglings/home")
        self.assertEqual(remote_cls.new.call_count, 2)
        self.assertEqual(self._installation.add_remote.call_count, 2)
Esempio n. 15
0
    def test_install(self, remote_cls, installation_cls, transaction_cls):
        """Test flatpak installation is working."""
        flatpak = FlatpakManager("remote/path")

        self._setup_flatpak_objects(remote_cls, installation_cls,
                                    transaction_cls)

        flatpak.initialize_with_system_path()

        mock_ref_list = [
            RefMock(name="org.space.coolapp",
                    kind=RefKind.APP,
                    arch="x86_64",
                    branch="stable"),
            RefMock(name="com.prop.notcoolapp",
                    kind=RefKind.APP,
                    arch="i386",
                    branch="f36"),
            RefMock(name="org.space.coolruntime",
                    kind=RefKind.RUNTIME,
                    arch="x86_64",
                    branch="stable"),
            RefMock(name="com.prop.notcoolruntime",
                    kind=RefKind.RUNTIME,
                    arch="i386",
                    branch="f36")
        ]

        self._installation.list_remote_refs_sync.return_value = mock_ref_list

        flatpak.install_all()

        expected_calls = [
            call.connect("new_operation", flatpak._operation_started_callback),
            call.connect("operation_done",
                         flatpak._operation_stopped_callback),
            call.connect("operation_error", flatpak._operation_error_callback),
            call.add_install(FlatpakManager.LOCAL_REMOTE_NAME,
                             mock_ref_list[0].format_ref(), None),
            call.add_install(FlatpakManager.LOCAL_REMOTE_NAME,
                             mock_ref_list[1].format_ref(), None),
            call.add_install(FlatpakManager.LOCAL_REMOTE_NAME,
                             mock_ref_list[2].format_ref(), None),
            call.add_install(FlatpakManager.LOCAL_REMOTE_NAME,
                             mock_ref_list[3].format_ref(), None),
            call.run()
        ]

        assert self._transaction.mock_calls == expected_calls
Esempio n. 16
0
    def test_remove_remote(self, remote_cls, installation_cls, transaction_cls):
        """Test flatpak remove a remote."""
        flatpak = FlatpakManager("remote/path")

        self._setup_flatpak_objects(remote_cls, installation_cls, transaction_cls)

        mock_remote1 = Mock()
        mock_remote2 = Mock()
        mock_remote1.get_name.return_value = "nest"
        mock_remote2.get_name.return_value = "hive"

        self._installation.list_remotes.return_value = [mock_remote1, mock_remote2]

        flatpak.initialize_with_system_path()
        flatpak.remove_remote("hive")

        self._installation.remove_remote.assert_called_once_with("hive", None)
Esempio n. 17
0
    def test_cleanup_call_mock_repo(self, remote_cls, installation_cls, transaction_cls, rmtree):
        """Test the cleanup call with mocked repository."""
        flatpak = FlatpakManager("any path")

        self._setup_flatpak_objects(remote_cls, installation_cls, transaction_cls)

        with TemporaryDirectory() as temp:
            install_path = os.path.join(temp, "install/test/path")
            file_mock_path = Mock()
            file_mock_path.get_path.return_value = install_path
            self._installation.get_path.return_value = file_mock_path

            os.makedirs(install_path)

            flatpak.initialize_with_path(install_path)
            flatpak.cleanup()

            rmtree.assert_called_once_with(install_path)
Esempio n. 18
0
    def test_replace_remote(self, remote_cls, installation_cls,
                            transaction_cls, open_mock, variant_type, variant):
        """Test flatpak replace remote for installed refs call."""
        flatpak = FlatpakManager("/system/test-root")

        self._setup_flatpak_objects(remote_cls, installation_cls,
                                    transaction_cls)

        install_path = "/installation/path"

        install_path_mock = Mock()
        install_path_mock.get_path.return_value = install_path
        self._installation.get_path.return_value = install_path_mock

        ref_mock_list = [
            RefMock(name="org.space.coolapp",
                    kind=RefKind.APP,
                    arch="x86_64",
                    branch="stable"),
            RefMock(name="org.space.coolruntime",
                    kind=RefKind.RUNTIME,
                    arch="x86_64",
                    branch="stable")
        ]

        self._installation.list_installed_refs.return_value = ref_mock_list

        flatpak.initialize_with_system_path()
        flatpak.replace_installed_refs_remote("cylon_officer")

        expected_refs = list(map(lambda x: x.format_ref(), ref_mock_list))

        open_calls = []

        for ref in expected_refs:
            ref_file_path = os.path.join(install_path, ref, "active/deploy")
            open_calls.append(call(ref_file_path, "rb"))
            open_calls.append(call(ref_file_path, "wb"))

        # test that every file is read and written
        assert open_mock.call_count == 2 * len(expected_refs)

        open_mock.has_calls(open_calls)
Esempio n. 19
0
    def run(self):
        self.report_progress(_("Installing Flatpak applications"))

        flatpak_manager = FlatpakManager(sysroot=self._sysroot,
                                         callback=self.report_progress)

        # Initialize new repo on the installed system
        flatpak_manager.initialize_with_system_path()
        flatpak_manager.install_all()

        self.report_progress(_("Performing post-installation Flatpak tasks"))
        flatpak_manager.add_remote("fedora",
                                   "oci+https://registry.fedoraproject.org")
        flatpak_manager.replace_installed_refs_remote("fedora")
        flatpak_manager.remove_remote(FlatpakManager.LOCAL_REMOTE_NAME)

        self.report_progress(_("Flatpak installation has finished"))
Esempio n. 20
0
    def test_cleanup_call_without_initialize(self):
        """Test the cleanup call without initialize."""
        flatpak = FlatpakManager("/tmp/flatpak-test")

        flatpak.cleanup()
    def run(self):
        self.report_progress(_("Starting Flatpak installation"))

        flatpak_manager = FlatpakManager(self._sysroot)

        # Initialize new repo on the installed system
        flatpak_manager.initialize_with_system_path()

        try:
            flatpak_manager.install_all()
        except FlatpakInstallError as e:
            raise PayloadInstallError(
                "Failed to install flatpaks: {}".format(e)) from e

        self.report_progress(_("Post-installation flatpak tasks"))

        flatpak_manager.add_remote("fedora",
                                   "oci+https://registry.fedoraproject.org")
        flatpak_manager.replace_installed_refs_remote("fedora")
        flatpak_manager.remove_remote(FlatpakManager.LOCAL_REMOTE_NAME)

        self.report_progress(_("Flatpak installation has finished"))