class RPMOSTreePayloadWithFlatpaks(RPMOSTreePayload): def __init__(self, *args, **kwargs): """Variant of rpmostree payload with flatpak support. This variant will be used if flatpaks are available for system. """ super().__init__(*args, **kwargs) self._flatpak_payload = FlatpakPayload(conf.target.system_root) # Initialize temporal repo to enable reading of the remote self._flatpak_payload.initialize_with_path( "/var/tmp/anaconda-flatpak-temp") @property def space_required(self): return super().space_required + Size( self._flatpak_payload.get_required_size()) def install(self): # install ostree payload first super().install() # then flatpaks self._flatpak_install() def _flatpak_install(self): # Install flatpak from the local source on SilverBlue progressQ.send_message(_("Starting Flatpak installation")) # Cleanup temporal repo created in the __init__ self._flatpak_payload.cleanup() # Initialize new repo on the installed system self._flatpak_payload.initialize_with_system_path() try: self._flatpak_payload.install_all() except FlatpakInstallError as e: exn = PayloadInstallError("Failed to install flatpaks: %s" % e) log.error(str(exn)) if errors.errorHandler.cb(exn) == errors.ERROR_RAISE: progressQ.send_quit(1) util.ipmi_abort(scripts=self.data.scripts) sys.exit(1) progressQ.send_message(_("Post-installation flatpak tasks")) self._flatpak_payload.add_remote( "fedora", "oci+https://registry.fedoraproject.org") self._flatpak_payload.replace_installed_refs_remote("fedora") self._flatpak_payload.remove_remote(FlatpakPayload.LOCAL_REMOTE_NAME) progressQ.send_message(_("Flatpak installation has finished"))
def get_empty_refs_required_space_test(self, remote_cls, installation_cls, transaction_cls): """Test flatpak required space method with no refs.""" flatpak = FlatpakPayload("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 = [] installation_size = flatpak.get_required_size() self.assertEqual(installation_size, 0)
def add_remote_test(self, remote_cls, installation_cls, transaction_cls): """Test flatpak add new remote.""" flatpak = FlatpakPayload("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)
def install_test(self, remote_cls, installation_cls, transaction_cls): """Test flatpak installation is working.""" flatpak = FlatpakPayload("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(FlatpakPayload.LOCAL_REMOTE_NAME, mock_ref_list[0].format_ref(), None), call.add_install(FlatpakPayload.LOCAL_REMOTE_NAME, mock_ref_list[1].format_ref(), None), call.add_install(FlatpakPayload.LOCAL_REMOTE_NAME, mock_ref_list[2].format_ref(), None), call.add_install(FlatpakPayload.LOCAL_REMOTE_NAME, mock_ref_list[3].format_ref(), None), call.run() ] self.assertEqual(self._transaction.mock_calls, expected_calls)
def remove_remote_test(self, remote_cls, installation_cls, transaction_cls): """Test flatpak remove a remote.""" flatpak = FlatpakPayload("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)
def replace_remote_test(self, remote_cls, installation_cls, transaction_cls, open_mock, variant_type, variant): """Test flatpak replace remote for installed refs call.""" flatpak = FlatpakPayload("/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 self.assertEqual(open_mock.call_count, 2 * len(expected_refs)) open_mock.has_calls(open_calls)