diff --git a/.gitignore b/.gitignore index 612accb7..97e12f37 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ tests/data/repo-krb5-lookaside tests/_composes htmlcov/ .coverage +.idea/ diff --git a/pungi/phases/pkgset/sources/source_koji.py b/pungi/phases/pkgset/sources/source_koji.py index 0217ef99..19872cbb 100644 --- a/pungi/phases/pkgset/sources/source_koji.py +++ b/pungi/phases/pkgset/sources/source_koji.py @@ -219,12 +219,15 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event_id): koji_wrapper, compose.conf["sigkeys"], logger=compose._logger, arches=all_arches) variant_tags[variant] = [] - + pdc_module_file = os.path.join(compose.paths.work.topdir(arch="global"), + "pdc-module-%s.json" % variant.uid) + pdc_modules = [] # Find out all modules in every variant and add their compose tags # to compose_tags list. if session: for module in variant.get_modules(): pdc_module = get_module(compose, session, module["name"]) + pdc_modules.append(pdc_module) mmd = modulemd.ModuleMetadata() mmd.loads(pdc_module["modulemd"]) @@ -248,7 +251,9 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event_id): variant_tags[variant].append(tag) if tag not in compose_tags: compose_tags.append(tag) - + if pdc_modules: + with open(pdc_module_file, 'w') as f: + json.dump(pdc_modules, f) if not variant_tags[variant]: variant_tags[variant].extend(force_list(compose.conf["pkgset_koji_tag"])) diff --git a/tests/helpers.py b/tests/helpers.py index 38c2e25c..3f258ba9 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -46,6 +46,9 @@ class MockVariant(mock.Mock): return [v for v in list(self.variants.values()) if (not arch or arch in v.arches) and (not types or v.type in types)] + def get_modules(self, arch=None, types=None): + return [] + class IterableMock(mock.Mock): def __iter__(self): diff --git a/tests/test_pkgset_source_koji.py b/tests/test_pkgset_source_koji.py index 91f4e78d..8d7b51f4 100644 --- a/tests/test_pkgset_source_koji.py +++ b/tests/test_pkgset_source_koji.py @@ -93,6 +93,7 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase): self.compose.DEBUG = False self.koji_wrapper = mock.Mock() self.pkgset_path = os.path.join(self.topdir, 'work', 'global', 'pkgset_global.pickle') + self.pdc_module_path = os.path.join(self.topdir, 'work', 'global', 'pdc-module-Server.json') @mock.patch('six.moves.cPickle.dumps') @mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet') @@ -117,6 +118,27 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase): with open(self.pkgset_path) as f: self.assertEqual(f.read(), 'DATA') + @mock.patch('six.moves.cPickle.dumps') + @mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet') + @mock.patch('pungi.phases.pkgset.sources.source_koji.get_module') + @mock.patch('pungi.phases.pkgset.sources.source_koji.get_pdc_client_session') + @mock.patch('pungi.phases.pkgset.sources.source_koji.modulemd') + def test_pdc_log(self, modulemd, get_pdc_client_session, get_module, KojiPackageSet, pickle_dumps): + + pickle_dumps.return_value = b'DATA' + + get_module.return_value = {'abc': 'def', 'modulemd': 'sth', 'rpms': ['dummy'], 'koji_tag': 'taggg'} + for name, variant in self.compose.variants.items(): + variant.get_modules = mock.MagicMock() + if name == 'Server': + variant.get_modules.return_value = [{'name': 'a'}] + + source_koji.populate_global_pkgset( + self.compose, self.koji_wrapper, '/prefix', 123456) + with open(self.pdc_module_path, 'r') as pdc_f: + self.assertEqual(json.load(pdc_f), + [{"rpms": ["dummy"], "abc": "def", "koji_tag": "taggg", "modulemd": "sth"}]) + @mock.patch('six.moves.cPickle.dumps') @mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet') def test_populate_with_multiple_koji_tags(self, KojiPackageSet, pickle_dumps):