From 2ca002d60223747d91fc9548ff4f405df420f28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 10 Mar 2016 15:20:20 +0100 Subject: [PATCH] [init] Add config option for keeping original comps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The configuration can specify a list of variants for which the original comps file will be copied without any modification. Signed-off-by: Lubomír Sedlář --- pungi/phases/init.py | 21 ++++++++++++++++- tests/test_initphase.py | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/pungi/phases/init.py b/pungi/phases/init.py index 9ffec4a3..b99affcc 100644 --- a/pungi/phases/init.py +++ b/pungi/phases/init.py @@ -144,6 +144,12 @@ class InitPhase(PhaseBase): "optional": True, }, + { + "name": "keep_original_comps", + "expected_types": [list], + "optional": True, + }, + ) @@ -164,8 +170,12 @@ class InitPhase(PhaseBase): # write variant comps for variant in self.compose.get_variants(): + should_preserve = variant.uid in self.compose.conf.get('keep_original_comps', []) for arch in variant.arches: - write_variant_comps(self.compose, arch, variant) + if should_preserve: + copy_variant_comps(self.compose, arch, variant) + else: + write_variant_comps(self.compose, arch, variant) # download variants.xml / product.xml? @@ -242,6 +252,15 @@ def write_variant_comps(compose, arch, variant): comps.write_comps() +def copy_variant_comps(compose, arch, variant): + if not compose.has_comps: + return + + global_comps = compose.paths.work.comps(arch="global") + comps_file = compose.paths.work.comps(arch=arch, variant=variant) + shutil.copy(global_comps, comps_file) + + def create_comps_repo(compose, arch): if not compose.has_comps: return diff --git a/tests/test_initphase.py b/tests/test_initphase.py index 85a6c6b6..59992b8e 100755 --- a/tests/test_initphase.py +++ b/tests/test_initphase.py @@ -50,6 +50,34 @@ class TestInitPhase(PungiTestCase): mock.call(compose, 'x86_64', compose.variants['Everything']), mock.call(compose, 'amd64', compose.variants['Everything'])]) + @mock.patch('pungi.phases.init.copy_variant_comps') + @mock.patch('pungi.phases.init.write_global_comps') + @mock.patch('pungi.phases.init.write_arch_comps') + @mock.patch('pungi.phases.init.create_comps_repo') + @mock.patch('pungi.phases.init.write_variant_comps') + @mock.patch('pungi.phases.init.write_prepopulate_file') + def test_run_with_preserve(self, write_prepopulate, write_variant, create_comps, + write_arch, write_global, copy_comps): + compose = DummyCompose(self.topdir, { + 'keep_original_comps': ['Everything'], + }) + phase = init.InitPhase(compose) + phase.run() + + self.assertEqual(write_global.mock_calls, [mock.call(compose)]) + self.assertEqual(write_prepopulate.mock_calls, [mock.call(compose)]) + self.assertItemsEqual(write_arch.mock_calls, + [mock.call(compose, 'x86_64'), mock.call(compose, 'amd64')]) + self.assertItemsEqual(create_comps.mock_calls, + [mock.call(compose, 'x86_64'), mock.call(compose, 'amd64')]) + self.assertItemsEqual(write_variant.mock_calls, + [mock.call(compose, 'x86_64', compose.variants['Server']), + mock.call(compose, 'amd64', compose.variants['Server']), + mock.call(compose, 'amd64', compose.variants['Client'])]) + self.assertItemsEqual(copy_comps.mock_calls, + [mock.call(compose, 'x86_64', compose.variants['Everything']), + mock.call(compose, 'amd64', compose.variants['Everything'])]) + def test_validate_keep_original_comps_missing(self): compose = DummyCompose(self.topdir, MIN_CONFIG) phase = init.InitPhase(compose) @@ -246,5 +274,29 @@ class TestWriteVariantComps(PungiTestCase): self.assertEqual(comps.write_comps.mock_calls, []) +class TestCopyVariantComps(PungiTestCase): + + @mock.patch('shutil.copy') + def test_does_not_run_without_comps(self, copy): + compose = DummyCompose(self.topdir, {}) + compose.has_comps = False + + init.copy_variant_comps(compose, 'x86_64', compose.variants['Server']) + + self.assertEqual(copy.mock_calls, []) + + @mock.patch('shutil.copy') + def test_run(self, copy): + compose = DummyCompose(self.topdir, {}) + compose.has_comps = True + variant = compose.variants['Server'] + + init.copy_variant_comps(compose, 'x86_64', variant) + + self.assertEqual(copy.mock_calls, + [mock.call(self.topdir + '/work/global/comps/comps-global.xml', + self.topdir + '/work/x86_64/comps/comps-Server.x86_64.xml')]) + + if __name__ == "__main__": unittest.main()