From 096075848b5adc4acbecd8c823574bebb78a2eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Fri, 22 Jun 2018 11:22:54 +0200 Subject: [PATCH] createrepo: Include empty modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A module without any RPMs is still valid and should be included. It should also be in the metadata. Signed-off-by: Lubomír Sedlář --- pungi/phases/createrepo.py | 36 ++++++++++++++++------------------- tests/test_createrepophase.py | 8 ++++++-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pungi/phases/createrepo.py b/pungi/phases/createrepo.py index e3c9c830..7f8f292b 100644 --- a/pungi/phases/createrepo.py +++ b/pungi/phases/createrepo.py @@ -224,27 +224,23 @@ def create_variant_repo(compose, arch, variant, pkg_type, modules_metadata=None) artifacts = repo_mmd.get_rpm_artifacts() # Modules without RPMs are also valid. - if not artifacts or artifacts.size() == 0: - continue - module_rpms = set() - repo_artifacts = Modulemd.SimpleSet() - rpm_licenses = Modulemd.SimpleSet() - for rpm_nevra in rpm_nevras: - if artifacts.contains(rpm_nevra): - repo_artifacts.add(rpm_nevra) - module_rpms.add(rpm_nevra) - # Not all RPMs have license data (*-debuginfo does not), - # so add any that do and don't worry about the remainder. - if rpm_nevra in license_data: - rpm_licenses.add(license_data[rpm_nevra]) - repo_mmd.set_rpm_artifacts(repo_artifacts) - repo_mmd.set_content_licenses(rpm_licenses) - if module_rpms: # do not create metadata if there is empty rpm list - if modules_metadata: # some unittests call this method without parameter modules_metadata and its default is None - metadata.append((module_id, module_rpms)) - else: - raise AttributeError("module_metadata parameter was not passed and it is needed for module processing") + if artifacts and artifacts.size() > 0: + repo_artifacts = Modulemd.SimpleSet() + rpm_licenses = Modulemd.SimpleSet() + for rpm_nevra in rpm_nevras: + if artifacts.contains(rpm_nevra): + repo_artifacts.add(rpm_nevra) + module_rpms.add(rpm_nevra) + # Not all RPMs have license data (*-debuginfo does not), + # so add any that do and don't worry about the remainder. + if rpm_nevra in license_data: + rpm_licenses.add(license_data[rpm_nevra]) + repo_mmd.set_rpm_artifacts(repo_artifacts) + repo_mmd.set_content_licenses(rpm_licenses) + + if modules_metadata: + metadata.append((module_id, module_rpms)) modules.append(repo_mmd) module_names = set([x.get_name() for x in modules]) diff --git a/tests/test_createrepophase.py b/tests/test_createrepophase.py index e16eb24c..34f5b38f 100644 --- a/tests/test_createrepophase.py +++ b/tests/test_createrepophase.py @@ -745,10 +745,12 @@ class TestCreateVariantRepo(PungiTestCase): self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.src.rpm\n') @unittest.skipUnless(Modulemd is not None, 'Skipped test, no module support.') + @mock.patch('pungi.phases.createrepo.find_file_in_repodata') @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') def test_variant_repo_modules_artifacts_not_in_compose( - self, CreaterepoWrapperCls, run): + self, CreaterepoWrapperCls, run, modulemd_filename + ): compose = DummyCompose(self.topdir, { 'createrepo_checksum': 'sha256', }) @@ -778,8 +780,10 @@ class TestCreateVariantRepo(PungiTestCase): repodata_dir = os.path.join( compose.paths.compose.os_tree('x86_64', compose.variants['Server']), 'repodata') + modulemd_filename.return_value = "Server/x86_64/os/repodata/3511d16a7-modules.yaml.gz" + modules_metadata = mock.Mock() - create_variant_repo(compose, 'x86_64', compose.variants['Server'], 'rpm') + create_variant_repo(compose, 'x86_64', compose.variants['Server'], 'rpm', modules_metadata) self.assertItemsEqual( repo.get_modifyrepo_cmd.mock_calls,