gather: Keep original rpms.json in debug mode

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ář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2018-08-29 09:25:19 +02:00
parent 7c5020e82d
commit 92968fe52d
2 changed files with 27 additions and 2 deletions

View File

@ -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,

View File

@ -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):