From 4473b05f1004af7e2f1b439c3b2b0dd0af065bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 18 Nov 2019 11:17:37 +0100 Subject: [PATCH] gather: Use fresh cache for each sequence of fus runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each depsolved tree will be using its own cache for fus. This should still allow for faster loading of metadata after first iteration, but should prevent errors from using cached files meant for another variant or architecture. The cache is deleted after the last iteration. JIRA: COMPOSE-3959 Signed-off-by: Lubomír Sedlář --- pungi/phases/gather/methods/method_hybrid.py | 11 ++++++++--- tests/test_gather_method_hybrid.py | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pungi/phases/gather/methods/method_hybrid.py b/pungi/phases/gather/methods/method_hybrid.py index 448fd267..aec4017a 100644 --- a/pungi/phases/gather/methods/method_hybrid.py +++ b/pungi/phases/gather/methods/method_hybrid.py @@ -27,7 +27,7 @@ from pungi import multilib_dnf from pungi.module_util import Modulemd from pungi.arch import get_valid_arches, tree_arch_to_yum_arch from pungi.phases.gather import _mk_pkg_map -from pungi.util import get_arch_variant_data, pkg_is_debug +from pungi.util import get_arch_variant_data, pkg_is_debug, temp_dir from pungi.wrappers import fus from pungi.wrappers.comps import CompsWrapper @@ -210,7 +210,11 @@ class GatherMethodHybrid(pungi.phases.gather.method.GatherMethodBase): # strings. filters = [_fmt_pkg(*p) for p in filter_packages] - nvrs, out_modules = self.run_solver(variant, arch, packages, platform, filters) + cache_prefix = "fus-cache-%s-%s-%s-" % (self.compose.compose_id, variant, arch) + with temp_dir(prefix=cache_prefix) as cache_dir: + nvrs, out_modules = self.run_solver( + variant, arch, packages, platform, filters, cache_dir=cache_dir + ) filter_modules(variant, arch, out_modules) return expand_packages( self._get_pkg_map(arch), @@ -228,7 +232,7 @@ class GatherMethodHybrid(pungi.phases.gather.method.GatherMethodBase): repos.append(pkgset.paths[self.arch]) return repos - def run_solver(self, variant, arch, packages, platform, filter_packages): + def run_solver(self, variant, arch, packages, platform, filter_packages, cache_dir): repos = self.get_repos() results = set() result_modules = set() @@ -263,6 +267,7 @@ class GatherMethodHybrid(pungi.phases.gather.method.GatherMethodBase): # useless for us anyway). env = os.environ.copy() env["G_MESSAGES_PREFIXED"] = "" + env["XDG_CACHE_HOME"] = cache_dir self.compose.log_debug("[BEGIN] Running fus") run(cmd, logfile=logfile, show_cmd=True, env=env) output, out_modules = fus.parse_output(logfile) diff --git a/tests/test_gather_method_hybrid.py b/tests/test_gather_method_hybrid.py index 585f8e62..c60d420a 100644 --- a/tests/test_gather_method_hybrid.py +++ b/tests/test_gather_method_hybrid.py @@ -27,12 +27,13 @@ class NamedMock(mock.Mock): class TestMethodHybrid(helpers.PungiTestCase): + @mock.patch("pungi.phases.gather.methods.method_hybrid.temp_dir") @mock.patch("pungi.phases.gather.methods.method_hybrid.CompsWrapper") @mock.patch("pungi.phases.gather.get_lookaside_repos") @mock.patch("pungi.phases.gather.methods.method_hybrid.expand_groups") @mock.patch("pungi.phases.gather.methods.method_hybrid.expand_packages") @mock.patch("pungi.phases.gather.methods.method_hybrid.get_platform") - def test_call_method(self, gp, ep, eg, glr, CW): + def test_call_method(self, gp, ep, eg, glr, CW, td): compose = helpers.DummyCompose(self.topdir, {}) m = hybrid.GatherMethodHybrid(compose) m.run_solver = mock.Mock(return_value=(mock.Mock(), mock.Mock())) @@ -73,9 +74,14 @@ class TestMethodHybrid(helpers.PungiTestCase): set(["pkg", "foo", "bar", ("prep", "noarch")]), gp.return_value, [], + cache_dir=td.return_value.__enter__.return_value, ) ], ) + self.assertIn( + [mock.call(prefix="fus-cache-Test-20151203.0.t-Server-x86_64-")], + td.mock_calls, + ) self.assertEqual( ep.call_args_list, [ @@ -331,6 +337,7 @@ class TestRunSolver(HelperMixin, helpers.PungiTestCase): [], platform="pl", filter_packages=[("foo", None)], + cache_dir="/cache", ) self.assertEqual(res[0], set()) @@ -386,6 +393,7 @@ class TestRunSolver(HelperMixin, helpers.PungiTestCase): [], platform="pl", filter_packages=["foo"], + cache_dir="/cache", ) self.assertEqual(res, (set([("p-1-1", "x86_64", frozenset())]), set(["m1"]))) @@ -426,6 +434,7 @@ class TestRunSolver(HelperMixin, helpers.PungiTestCase): [("pkg", None)], platform=None, filter_packages=[], + cache_dir="/cache", ) six.assertCountEqual(self, res[0], po.return_value[0]) @@ -481,6 +490,7 @@ class TestRunSolver(HelperMixin, helpers.PungiTestCase): [("pkg", None)], platform=None, filter_packages=[], + cache_dir="/cache", ) six.assertCountEqual( @@ -553,6 +563,7 @@ class TestRunSolver(HelperMixin, helpers.PungiTestCase): [("pkg", None)], platform=None, filter_packages=["foo"], + cache_dir="/cache", ) six.assertCountEqual(self, res[0], final) @@ -640,6 +651,7 @@ class TestRunSolver(HelperMixin, helpers.PungiTestCase): [("pkg-devel", None), ("foo", None)], platform=None, filter_packages=[], + cache_dir="/cache", ) six.assertCountEqual( @@ -762,6 +774,7 @@ class TestRunSolver(HelperMixin, helpers.PungiTestCase): [("pkg-devel", None), ("foo", None)], platform=None, filter_packages=[], + cache_dir="/cache", ) six.assertCountEqual(