From 340ae4d286f4322a322c352dd8657f671b7aa70e Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Tue, 20 Feb 2018 15:24:11 +0100 Subject: [PATCH] Use libmodulemd instead of modulemd Python module Merges: https://pagure.io/pungi/pull-request/851 Signed-off-by: Jan Kaluza --- pungi/phases/gather/__init__.py | 2 +- pungi/phases/gather/sources/source_module.py | 10 +++++----- pungi/phases/pkgset/sources/source_koji.py | 17 +++++++++++------ tests/test_pkgset_source_koji.py | 6 ++++-- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/pungi/phases/gather/__init__.py b/pungi/phases/gather/__init__.py index bc056e25..d7082b97 100644 --- a/pungi/phases/gather/__init__.py +++ b/pungi/phases/gather/__init__.py @@ -74,7 +74,7 @@ class GatherPhase(PhaseBase): # Modules are not supported, check if we need them for variant in self.compose.variants.values(): if variant.modules: - errors.append('Modular compose requires pdc_client and modulemd packages.') + errors.append('Modular compose requires pdc_client and libmodulemd packages.') if errors: raise ValueError('\n'.join(errors)) diff --git a/pungi/phases/gather/sources/source_module.py b/pungi/phases/gather/sources/source_module.py index a3c3599d..4fdaa7d6 100644 --- a/pungi/phases/gather/sources/source_module.py +++ b/pungi/phases/gather/sources/source_module.py @@ -50,7 +50,7 @@ class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase): # Generate architecture specific modulemd metadata, so we can # store per-architecture artifacts there later. for mmd in variant.mmds: - mmd_id = "%s-%s" % (mmd.name, mmd.stream) + mmd_id = "%s-%s" % (mmd.get_name(), mmd.get_stream()) if mmd_id not in variant.arch_mmds[arch]: arch_mmd = yaml.safe_load(mmd.dumps()) variant.arch_mmds[arch][mmd_id] = arch_mmd @@ -71,13 +71,13 @@ class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase): continue for mmd in variant.mmds: - mmd_id = "%s-%s" % (mmd.name, mmd.stream) + mmd_id = "%s-%s" % (mmd.get_name(), mmd.get_stream()) arch_mmd = variant.arch_mmds[arch][mmd_id] srpm = kobo.rpmlib.parse_nvr(rpm_obj.sourcerpm)["name"] - if (srpm in mmd.components.rpms.keys() and - rpm_obj.name not in mmd.filter.rpms and - rpm_obj.nevra in mmd.artifacts.rpms): + if (srpm in mmd.get_rpm_components().keys() and + rpm_obj.name not in mmd.get_rpm_filter().get() and + rpm_obj.nevra in mmd.get_rpm_artifacts().get()): packages.add((rpm_obj, None)) added_rpms.setdefault(mmd_id, []) added_rpms[mmd_id].append(str(rpm_obj.nevra)) diff --git a/pungi/phases/pkgset/sources/source_koji.py b/pungi/phases/pkgset/sources/source_koji.py index ffa75cf2..4582a7fc 100644 --- a/pungi/phases/pkgset/sources/source_koji.py +++ b/pungi/phases/pkgset/sources/source_koji.py @@ -34,7 +34,9 @@ import pungi.phases.pkgset.source try: from pdc_client import PDCClient - import modulemd + import gi + gi.require_version('Modulemd', '1.0') # noqa + from gi.repository import Modulemd WITH_MODULES = True except: WITH_MODULES = False @@ -42,7 +44,8 @@ except: def get_pdc_client_session(compose): if not WITH_MODULES: - compose.log_warning("pdc_client or modulemd module is not installed, " + compose.log_warning("pdc_client module, pygobject module or " + "libmodulemd library is not installed, " "support for modules is disabled") return None try: @@ -240,12 +243,12 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event_id): 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"]) + mmd = Modulemd.Module.new_from_string(pdc_module["modulemd"]) + mmd.upgrade() # Catch the issue when PDC does not contain RPMs, but # the module definition says there should be some. - if not pdc_module["rpms"] and mmd.components.rpms: + if not pdc_module["rpms"] and mmd.get_rpm_components(): raise ValueError( "Module %s does not have any rpms in 'rpms' PDC field," "but according to modulemd, there should be some." @@ -253,10 +256,12 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event_id): # Add RPMs from PDC response to modulemd, so we can track # what RPM is in which module later in gather phase. + rpm_artifacts = mmd.get_rpm_artifacts() for rpm_nevra in pdc_module["rpms"]: if rpm_nevra.endswith(".rpm"): rpm_nevra = rpm_nevra[:-len(".rpm")] - mmd.artifacts.add_rpm(str(rpm_nevra)) + rpm_artifacts.add(str(rpm_nevra)) + mmd.set_rpm_artifacts(rpm_artifacts) tag = pdc_module["koji_tag"] variant.mmds.append(mmd) diff --git a/tests/test_pkgset_source_koji.py b/tests/test_pkgset_source_koji.py index 53670843..7a9f4460 100644 --- a/tests/test_pkgset_source_koji.py +++ b/tests/test_pkgset_source_koji.py @@ -11,7 +11,9 @@ import re sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) try: - import modulemd # noqa + import gi # noqa + gi.require_version('Modulemd', '1.0') # noqa + from gi.repository import Modulemd # noqa import pdc_client # noqa HAS_MODULE_SUPPORT = True except ImportError: @@ -130,7 +132,7 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase): @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') + @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'