diff --git a/pungi/phases/createrepo.py b/pungi/phases/createrepo.py index 042233bc..6489eabd 100644 --- a/pungi/phases/createrepo.py +++ b/pungi/phases/createrepo.py @@ -40,13 +40,10 @@ from ..util import ( temp_dir, ) from pungi import Modulemd -from pungi.arch import tree_arch_to_yum_arch import productmd.rpms import productmd.modules -import createrepo_c as cr - createrepo_lock = threading.Lock() createrepo_dirs = set() @@ -89,21 +86,6 @@ class CreaterepoPhase(PhaseBase): 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): types = { 'rpm': ('binary', @@ -217,37 +199,11 @@ def create_variant_repo(compose, arch, variant, pkg_type, modules_metadata=None) modules = [] 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(): - # 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: + module_rpms = mmd.peek_rpm_artifacts().dup() metadata.append((module_id, module_rpms)) - modules.append(repo_mmd) + modules.append(mmd) module_names = set([x.get_name() for x in modules]) for mmddef in iter_module_defaults(compose.paths.work.module_defaults_dir()): diff --git a/tests/test_createrepophase.py b/tests/test_createrepophase.py index 73069762..83afda4b 100644 --- a/tests/test_createrepophase.py +++ b/tests/test_createrepophase.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- -from collections import namedtuple try: import unittest2 as unittest except ImportError: @@ -18,7 +17,6 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) from pungi.phases.createrepo import (CreaterepoPhase, create_variant_repo, get_productids_from_scm, - get_licenses_from_repo, ModulesMetadata) from tests.helpers import DummyCompose, PungiTestCase, copy_fixture, touch from pungi import Modulemd @@ -120,7 +118,6 @@ class TestCreaterepoPhase(PungiTestCase): 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): @mock.patch('pungi.phases.createrepo.run') @@ -808,7 +805,7 @@ class TestCreateVariantRepo(PungiTestCase): ["f27", "f28"]) self.assertItemsEqual( [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.get_modifyrepo_cmd.side_effect = mocked_modifyrepo_cmd @@ -948,38 +945,3 @@ class TestGetProductIds(PungiTestCase): self.assertRegexpMatches( str(ctx.exception), '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()