createrepo: Include empty modules

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ář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2018-06-22 11:22:54 +02:00
parent 38f1a8509e
commit 096075848b
2 changed files with 22 additions and 22 deletions

View File

@ -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])

View File

@ -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,