createrepo: Stop processing modulemd

The file we get from Koji has all important bits already filled in.
There is no need to add anything.

This patch also stops filtering the artifacts to only contain packages
that are actually in the repo. Thus debuginfo and source packages will
appear there.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2019-03-07 09:57:37 +01:00
parent 9229699078
commit 9939d09643
2 changed files with 3 additions and 85 deletions

View File

@ -40,13 +40,10 @@ from ..util import (
temp_dir, temp_dir,
) )
from pungi import Modulemd from pungi import Modulemd
from pungi.arch import tree_arch_to_yum_arch
import productmd.rpms import productmd.rpms
import productmd.modules import productmd.modules
import createrepo_c as cr
createrepo_lock = threading.Lock() createrepo_lock = threading.Lock()
createrepo_dirs = set() createrepo_dirs = set()
@ -89,21 +86,6 @@ class CreaterepoPhase(PhaseBase):
self.modules_metadata.write_modules_metadata() self.modules_metadata.write_modules_metadata()
def get_licenses_from_repo(repo_path):
result = {}
md = cr.Metadata()
md.locate_and_load_xml(repo_path)
for key in md.keys():
pkg = md.get(key)
nevra = "%s-%s:%s-%s.%s" % (pkg.name,
pkg.epoch if pkg.epoch else "0",
pkg.version,
pkg.release,
pkg.arch)
result[nevra] = pkg.rpm_license
return result
def create_variant_repo(compose, arch, variant, pkg_type, modules_metadata=None): def create_variant_repo(compose, arch, variant, pkg_type, modules_metadata=None):
types = { types = {
'rpm': ('binary', 'rpm': ('binary',
@ -217,37 +199,11 @@ def create_variant_repo(compose, arch, variant, pkg_type, modules_metadata=None)
modules = [] modules = []
metadata = [] metadata = []
# Interrogate the RPM repodata and add all licenses for these RPMs to the
# module metadata
license_data = get_licenses_from_repo(
compose.paths.work.arch_repo(arch))
for module_id, mmd in variant.arch_mmds[arch].items(): for module_id, mmd in variant.arch_mmds[arch].items():
# Create copy of architecture specific mmd to filter out packages
# which are not part of this particular repo.
repo_mmd = mmd.copy()
repo_mmd.set_arch(tree_arch_to_yum_arch(arch))
artifacts = repo_mmd.get_rpm_artifacts()
# Modules without RPMs are also valid.
module_rpms = set()
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: if modules_metadata:
module_rpms = mmd.peek_rpm_artifacts().dup()
metadata.append((module_id, module_rpms)) metadata.append((module_id, module_rpms))
modules.append(repo_mmd) modules.append(mmd)
module_names = set([x.get_name() for x in modules]) module_names = set([x.get_name() for x in modules])
for mmddef in iter_module_defaults(compose.paths.work.module_defaults_dir()): for mmddef in iter_module_defaults(compose.paths.work.module_defaults_dir()):

View File

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from collections import namedtuple
try: try:
import unittest2 as unittest import unittest2 as unittest
except ImportError: except ImportError:
@ -18,7 +17,6 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from pungi.phases.createrepo import (CreaterepoPhase, from pungi.phases.createrepo import (CreaterepoPhase,
create_variant_repo, create_variant_repo,
get_productids_from_scm, get_productids_from_scm,
get_licenses_from_repo,
ModulesMetadata) ModulesMetadata)
from tests.helpers import DummyCompose, PungiTestCase, copy_fixture, touch from tests.helpers import DummyCompose, PungiTestCase, copy_fixture, touch
from pungi import Modulemd from pungi import Modulemd
@ -120,7 +118,6 @@ class TestCreaterepoPhase(PungiTestCase):
mock.call((compose, None, compose.variants['Everything'], 'srpm', phase.modules_metadata))]) mock.call((compose, None, compose.variants['Everything'], 'srpm', phase.modules_metadata))])
@mock.patch("pungi.phases.createrepo.get_licenses_from_repo", new=lambda path: {})
class TestCreateVariantRepo(PungiTestCase): class TestCreateVariantRepo(PungiTestCase):
@mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.run')
@ -808,7 +805,7 @@ class TestCreateVariantRepo(PungiTestCase):
["f27", "f28"]) ["f27", "f28"])
self.assertItemsEqual( self.assertItemsEqual(
[m.get_rpm_artifacts().get() for m in modules], [m.get_rpm_artifacts().get() for m in modules],
[["bash-0:4.3.30-2.fc21.x86_64"], []]) [["bash-0:4.3.30-2.fc21.x86_64"], ["pkg-0:2.0.0-1.x86_64"]])
repo = CreaterepoWrapperCls.return_value repo = CreaterepoWrapperCls.return_value
repo.get_modifyrepo_cmd.side_effect = mocked_modifyrepo_cmd repo.get_modifyrepo_cmd.side_effect = mocked_modifyrepo_cmd
@ -948,38 +945,3 @@ class TestGetProductIds(PungiTestCase):
self.assertRegexpMatches( self.assertRegexpMatches(
str(ctx.exception), str(ctx.exception),
'Multiple product certificates found.+') 'Multiple product certificates found.+')
class TestGetLicenses(unittest.TestCase):
@mock.patch("pungi.phases.createrepo.cr.Metadata")
def test_get_licenses(self, MockMetadata):
path = "/my/path"
md = MockMetadata.return_value
md.keys.return_value = ["k1", "k2"]
Pkg = namedtuple(
"Pkg", ["name", "epoch", "version", "release", "arch", "rpm_license"]
)
md.get.side_effect = [
Pkg("foo", None, "1.0", "1", "x86_64", "GPLv2"),
Pkg("bar", "2", "1.0", "2", "src", "WTFPL"),
]
res = get_licenses_from_repo(path)
self.assertEqual(
md.mock_calls,
[
mock.call.locate_and_load_xml(path),
mock.call.keys(),
mock.call.get("k1"),
mock.call.get("k2"),
]
)
self.assertEqual(
res, {"foo-0:1.0-1.x86_64": "GPLv2", "bar-2:1.0-2.src": "WTFPL"}
)
if __name__ == "__main__":
unittest.main()