def run_failure_test(self, sysroot_new_mock, async_new_mock, context_mock): """Test OSTree remote pull task failure""" data = _make_config_data() sysroot_mock = sysroot_new_mock() repo_mock = MagicMock() sysroot_mock.get_repo.return_value = [None, repo_mock] repo_mock.pull_with_options.side_effect = [GError("blah")] with patch.object(PullRemoteAndDeleteTask, "report_progress") as progress_mock: with self.assertRaises(PayloadInstallationError) as ex: task = PullRemoteAndDeleteTask(data) task.run() context_mock.assert_called_once() async_new_mock.assert_called_once() self.assertEqual(len(sysroot_new_mock.mock_calls), 4) # 1 above, 1 direct in run(), 2 on the result: load(), get_repo() repo_mock.pull_with_options.assert_called_once() name, args, kwargs = repo_mock.pull_with_options.mock_calls[0] opts = args[1] self.assertEqual(type(opts), Variant) self.assertDictEqual(opts.unpack(), {"refs": ["ref"]}) repo_mock.remote_delete.assert_not_called()
def install_with_tasks(self): """Install the payload. :return: list of tasks """ ostree_source = self._get_source(SourceType.RPM_OSTREE) if not ostree_source: log.debug("No OSTree RPM source is available.") return [] tasks = [ InitOSTreeFsAndRepoTask(physroot=conf.target.physical_root), ChangeOSTreeRemoteTask(physroot=conf.target.physical_root, data=ostree_source.configuration), PullRemoteAndDeleteTask(data=ostree_source.configuration), DeployOSTreeTask(physroot=conf.target.physical_root, data=ostree_source.configuration), SetSystemRootTask(physroot=conf.target.physical_root), CopyBootloaderDataTask(physroot=conf.target.physical_root, sysroot=conf.target.system_root), PrepareOSTreeMountTargetsTask(physroot=conf.target.physical_root, sysroot=conf.target.system_root, data=ostree_source.configuration) ] flatpak_source = self._get_source(SourceType.FLATPAK) if flatpak_source: task = InstallFlatpaksTask(sysroot=conf.target.system_root) tasks.append(task) self._collect_mount_points_on_success(tasks) return tasks
def test_pull_progress_report(self): """Test OSTree remote pull task progress reporting""" data = _make_config_data() with patch.object(PullRemoteAndDeleteTask, "report_progress") as progress_mock: task = PullRemoteAndDeleteTask(data) async_mock = MagicMock() # Mocks below must use side_effect so as not to mix it with return_value. # status is present, outstanding fetches do not matter async_mock.get_status.return_value = "Doing something vague" async_mock.get_uint.side_effect = [0] task._pull_progress_cb(async_mock) progress_mock.assert_called_once_with("Doing something vague") progress_mock.reset_mock() async_mock.get_uint.reset_mock() # no status, no outstanding fetches async_mock.get_status.return_value = "" async_mock.get_uint.side_effect = [0] task._pull_progress_cb(async_mock) progress_mock.assert_called_once_with("Writing objects") progress_mock.reset_mock() async_mock.get_uint.reset_mock() # no status, some outstanding fetches async_mock.get_status.return_value = "" async_mock.get_uint.side_effect = [3, 10, 13] # 3 fetches outstanding, 10 done, requested 13 async_mock.get_uint64.return_value = 42e3 # bytes transferred task._pull_progress_cb(async_mock) progress_mock.assert_called_once_with( "Receiving objects: 76% (10/13) 42.0\xa0kB" ) progress_mock.reset_mock() async_mock.get_uint.reset_mock() # no status, some outstanding fetches, but also nothing requested async_mock.get_status.return_value = "" async_mock.get_uint.side_effect = [3, 10, 0] # 3 fetches outstanding, 10 done, requested 13 async_mock.get_uint64.return_value = 42e3 # bytes transferred task._pull_progress_cb(async_mock) progress_mock.assert_called_once_with( "Receiving objects: 0% (10/0) 42.0\xa0kB" )
def test_run_success(self, sysroot_new_mock, async_new_mock, context_mock): """Test OSTree remote pull task""" data = _make_config_data() sysroot_mock = sysroot_new_mock() repo_mock = MagicMock() sysroot_mock.get_repo.return_value = [None, repo_mock] with patch.object(PullRemoteAndDeleteTask, "report_progress") as progress_mock: task = PullRemoteAndDeleteTask(data) task.run() context_mock.assert_called_once() async_new_mock.assert_called_once() assert len(sysroot_new_mock.mock_calls) == 4 # 1 above, 1 direct in run(), 2 on the result: load(), get_repo() repo_mock.pull_with_options.assert_called_once() name, args, kwargs = repo_mock.pull_with_options.mock_calls[0] opts = args[1] assert type(opts) == Variant assert opts.unpack() == {"refs": ["ref"]} repo_mock.remote_delete.assert_called_once_with("remote", None)
def _install(self, data): log.info("executing ostreesetup=%r", data) from pyanaconda.modules.payloads.payload.rpm_ostree.installation import \ InitOSTreeFsAndRepoTask task = InitOSTreeFsAndRepoTask(conf.target.physical_root) task.run() # Here, we use the physical root as sysroot, because we haven't # yet made a deployment. from pyanaconda.modules.payloads.payload.rpm_ostree.installation import \ ChangeOSTreeRemoteTask task = ChangeOSTreeRemoteTask(data, use_root=False, root=conf.target.physical_root) task.run() from pyanaconda.modules.payloads.payload.rpm_ostree.installation import \ PullRemoteAndDeleteTask task = PullRemoteAndDeleteTask(data) task.progress_changed_signal.connect(self._progress_cb) task.run() from pyanaconda.modules.payloads.payload.rpm_ostree.installation import DeployOSTreeTask task = DeployOSTreeTask(data, conf.target.physical_root) task.progress_changed_signal.connect(self._progress_cb) task.run() # Reload now that we've deployed, find the path to the new deployment from pyanaconda.modules.payloads.payload.rpm_ostree.installation import SetSystemRootTask task = SetSystemRootTask(conf.target.physical_root) task.run() try: from pyanaconda.modules.payloads.payload.rpm_ostree.installation import \ CopyBootloaderDataTask task = CopyBootloaderDataTask(sysroot=conf.target.system_root, physroot=conf.target.physical_root) task.run() except (OSError, RuntimeError) as e: raise PayloadInstallError("Failed to copy bootloader data: %s" % e) from e