From 92968fe52d922800c05a3e69afbd179d8b2c2c86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 29 Aug 2018 09:25:19 +0200 Subject: [PATCH] gather: Keep original rpms.json in debug mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we're running in debug mode and the file is already present, it should not be modified. This means that in order to rerun the actual gather phase the file needs to be manually deleted first. However the much more common use is to skip gather phase (because only images should be re-run). In that case the manifest will be preserved correctly. JIRA: COMPOSE-2756 Signed-off-by: Lubomír Sedlář --- pungi/phases/gather/__init__.py | 9 +++++++-- tests/test_gather_phase.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pungi/phases/gather/__init__.py b/pungi/phases/gather/__init__.py index a243cd03..7ed1619f 100644 --- a/pungi/phases/gather/__init__.py +++ b/pungi/phases/gather/__init__.py @@ -87,8 +87,13 @@ class GatherPhase(PhaseBase): raise ValueError('\n'.join(errors)) def _write_manifest(self): - self.compose.log_info("Writing RPM manifest: %s" % self.manifest_file) - self.manifest.dump(self.manifest_file) + if self.compose.DEBUG and os.path.isfile(self.manifest_file): + self.compose.log_info( + "Skipping writing RPM manifest, already exists: %s" % self.manifest_file + ) + else: + self.compose.log_info("Writing RPM manifest: %s" % self.manifest_file) + self.manifest.dump(self.manifest_file) def run(self): pkg_map = gather_wrapper(self.compose, self.pkgset_phase.package_sets, diff --git a/tests/test_gather_phase.py b/tests/test_gather_phase.py index cbcb22e6..d2e492cb 100644 --- a/tests/test_gather_phase.py +++ b/tests/test_gather_phase.py @@ -854,6 +854,26 @@ class TestGatherPhase(helpers.PungiTestCase): self.assertEqual(gather_wrapper.call_args_list, []) self.assertTrue(os.path.isfile(os.path.join(self.topdir, 'compose', 'metadata', 'rpms.json'))) + @mock.patch('pungi.phases.gather.link_files') + @mock.patch('pungi.phases.gather.gather_wrapper') + def test_does_not_write_in_debug_mode(self, gather_wrapper, link_files): + pkgset_phase = mock.Mock() + compose = helpers.DummyCompose(self.topdir, {}) + compose.notifier = mock.Mock() + compose.DEBUG = True + + rpms_file = helpers.touch( + os.path.join(self.topdir, 'compose', 'metadata', 'rpms.json'), "hello" + ) + + phase = gather.GatherPhase(compose, pkgset_phase) + phase.stop() + + self.assertEqual(gather_wrapper.call_args_list, []) + self.assertTrue(os.path.isfile(rpms_file)) + with open(rpms_file) as fh: + self.assertEqual(fh.read(), "hello") + class TestGetPackagesToGather(helpers.PungiTestCase): def setUp(self):