[init] Add config option for keeping original comps
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ář <lsedlar@redhat.com>
This commit is contained in:
parent
6f9f84c4d4
commit
2ca002d602
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user