From 18bd37ff2c69bfead7f4799489bfd64932f3fb73 Mon Sep 17 00:00:00 2001 From: Qixiang Wan Date: Tue, 27 Jun 2017 19:48:02 +0800 Subject: [PATCH] pkgset: Allow populating packages from multiple koji tags One of the use cases is https://pagure.io/odcs/issue/7. Merges: #660 Signed-off-by: Qixiang Wan --- doc/configuration.rst | 2 +- pungi/checks.py | 2 +- pungi/phases/pkgset/sources/source_koji.py | 5 ++-- tests/test_config.py | 8 ++++++ tests/test_pkgset_source_koji.py | 30 ++++++++++++++++++++++ 5 files changed, 43 insertions(+), 4 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index e7454442..86408c77 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -405,7 +405,7 @@ Options (*str*) -- "koji" (any koji instance) or "repos" (arbitrary yum repositories) **pkgset_koji_tag** [mandatory] - (*str*) -- tag to read package set from + (*str|[str]*) -- tag(s) to read package set from **pkgset_koji_inherit** = True (*bool*) -- inherit builds from parent tags; we can turn it off only if we diff --git a/pungi/checks.py b/pungi/checks.py index 190779f2..f9a5671a 100644 --- a/pungi/checks.py +++ b/pungi/checks.py @@ -718,7 +718,7 @@ def _make_schema(): "koji_profile": {"type": "string"}, - "pkgset_koji_tag": {"type": "string"}, + "pkgset_koji_tag": {"$ref": "#/definitions/strings"}, "pkgset_koji_inherit": { "type": "boolean", "default": True diff --git a/pungi/phases/pkgset/sources/source_koji.py b/pungi/phases/pkgset/sources/source_koji.py index bf87ef2a..291e314d 100644 --- a/pungi/phases/pkgset/sources/source_koji.py +++ b/pungi/phases/pkgset/sources/source_koji.py @@ -18,6 +18,7 @@ import os import cPickle as pickle import json import re +from kobo.shortcuts import force_list import pungi.wrappers.kojiwrapper import pungi.phases.pkgset.pkgsets @@ -196,12 +197,12 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event_id): compose_tags.append(tag) if not variant_tags[variant]: - variant_tags[variant].append(compose.conf["pkgset_koji_tag"]) + variant_tags[variant].extend(force_list(compose.conf["pkgset_koji_tag"])) # In case we have no compose tag from module, use the default # one from config. if not compose_tags: - compose_tags.append(compose.conf["pkgset_koji_tag"]) + compose_tags.extend(force_list(compose.conf["pkgset_koji_tag"])) inherit = compose.conf["pkgset_koji_inherit"] global_pkgset_path = os.path.join( diff --git a/tests/test_config.py b/tests/test_config.py index 772f3ed9..24bc72d6 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -65,6 +65,14 @@ class PkgsetConfigTestCase(ConfigTestCase): [checks.REQUIRES.format('pkgset_source', 'koji', 'pkgset_koji_tag'), checks.CONFLICTS.format('pkgset_source', 'koji', 'pkgset_repos')]) + def test_pkgset_multiple_koji_tags(self): + cfg = load_config( + pkgset_source='koji', + pkgset_koji_tag=['f25', 'f25-extra'], + pkgset_koji_inherit=False, + ) + self.assertValidation(cfg) + class ReleaseConfigTestCase(ConfigTestCase): def test_layered_without_base_product(self): diff --git a/tests/test_pkgset_source_koji.py b/tests/test_pkgset_source_koji.py index d2b43516..892aac2b 100644 --- a/tests/test_pkgset_source_koji.py +++ b/tests/test_pkgset_source_koji.py @@ -117,6 +117,36 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase): with open(self.pkgset_path) as f: self.assertEqual(f.read(), 'DATA') + @mock.patch('cPickle.dumps') + @mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet') + def test_populate_with_multiple_koji_tags(self, KojiPackageSet, pickle_dumps): + self.compose = helpers.DummyCompose(self.topdir, { + 'pkgset_koji_tag': ['f25', 'f25-extra'], + 'sigkeys': mock.Mock(), + }) + self.compose.DEBUG = False + + pickle_dumps.return_value = 'DATA' + + orig_pkgset = KojiPackageSet.return_value + + pkgset = source_koji.populate_global_pkgset( + self.compose, self.koji_wrapper, '/prefix', 123456) + + self.assertIs(pkgset, orig_pkgset) + pkgset.assert_has_calls([mock.call.populate('f25', 123456, inherit=True, + logfile=self.topdir + '/logs/global/packages_from_f25.global.log')]) + pkgset.assert_has_calls([mock.call.populate('f25-extra', 123456, inherit=True, + logfile=self.topdir + '/logs/global/packages_from_f25-extra.global.log')]) + pkgset.assert_has_calls([mock.call.save_file_list(self.topdir + '/work/global/package_list/global.conf', + remove_path_prefix='/prefix')]) + # for each tag, call pkgset.merge once for each variant and once for global pkgset + self.assertEqual(pkgset.merge.call_count, 2 * (len(self.compose.all_variants.values()) + 1)) + self.assertItemsEqual(pickle_dumps.call_args_list, + [mock.call(orig_pkgset)]) + with open(self.pkgset_path) as f: + self.assertEqual(f.read(), 'DATA') + @mock.patch('cPickle.load') def test_populate_in_debug_mode(self, pickle_load): helpers.touch(self.pkgset_path, 'DATA')