Use libmodulemd instead of modulemd Python module

Merges: https://pagure.io/pungi/pull-request/851
Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
This commit is contained in:
Jan Kaluza 2018-02-20 15:24:11 +01:00 committed by Lubomír Sedlář
parent 56e00505e0
commit 340ae4d286
4 changed files with 21 additions and 14 deletions

View File

@ -74,7 +74,7 @@ class GatherPhase(PhaseBase):
# Modules are not supported, check if we need them # Modules are not supported, check if we need them
for variant in self.compose.variants.values(): for variant in self.compose.variants.values():
if variant.modules: 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: if errors:
raise ValueError('\n'.join(errors)) raise ValueError('\n'.join(errors))

View File

@ -50,7 +50,7 @@ class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase):
# Generate architecture specific modulemd metadata, so we can # Generate architecture specific modulemd metadata, so we can
# store per-architecture artifacts there later. # store per-architecture artifacts there later.
for mmd in variant.mmds: 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]: if mmd_id not in variant.arch_mmds[arch]:
arch_mmd = yaml.safe_load(mmd.dumps()) arch_mmd = yaml.safe_load(mmd.dumps())
variant.arch_mmds[arch][mmd_id] = arch_mmd variant.arch_mmds[arch][mmd_id] = arch_mmd
@ -71,13 +71,13 @@ class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase):
continue continue
for mmd in variant.mmds: 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] arch_mmd = variant.arch_mmds[arch][mmd_id]
srpm = kobo.rpmlib.parse_nvr(rpm_obj.sourcerpm)["name"] srpm = kobo.rpmlib.parse_nvr(rpm_obj.sourcerpm)["name"]
if (srpm in mmd.components.rpms.keys() and if (srpm in mmd.get_rpm_components().keys() and
rpm_obj.name not in mmd.filter.rpms and rpm_obj.name not in mmd.get_rpm_filter().get() and
rpm_obj.nevra in mmd.artifacts.rpms): rpm_obj.nevra in mmd.get_rpm_artifacts().get()):
packages.add((rpm_obj, None)) packages.add((rpm_obj, None))
added_rpms.setdefault(mmd_id, []) added_rpms.setdefault(mmd_id, [])
added_rpms[mmd_id].append(str(rpm_obj.nevra)) added_rpms[mmd_id].append(str(rpm_obj.nevra))

View File

@ -34,7 +34,9 @@ import pungi.phases.pkgset.source
try: try:
from pdc_client import PDCClient from pdc_client import PDCClient
import modulemd import gi
gi.require_version('Modulemd', '1.0') # noqa
from gi.repository import Modulemd
WITH_MODULES = True WITH_MODULES = True
except: except:
WITH_MODULES = False WITH_MODULES = False
@ -42,7 +44,8 @@ except:
def get_pdc_client_session(compose): def get_pdc_client_session(compose):
if not WITH_MODULES: 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") "support for modules is disabled")
return None return None
try: try:
@ -240,12 +243,12 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event_id):
for module in variant.get_modules(): for module in variant.get_modules():
pdc_module = get_module(compose, session, module["name"]) pdc_module = get_module(compose, session, module["name"])
pdc_modules.append(pdc_module) pdc_modules.append(pdc_module)
mmd = modulemd.ModuleMetadata() mmd = Modulemd.Module.new_from_string(pdc_module["modulemd"])
mmd.loads(pdc_module["modulemd"]) mmd.upgrade()
# Catch the issue when PDC does not contain RPMs, but # Catch the issue when PDC does not contain RPMs, but
# the module definition says there should be some. # 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( raise ValueError(
"Module %s does not have any rpms in 'rpms' PDC field," "Module %s does not have any rpms in 'rpms' PDC field,"
"but according to modulemd, there should be some." "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 # Add RPMs from PDC response to modulemd, so we can track
# what RPM is in which module later in gather phase. # what RPM is in which module later in gather phase.
rpm_artifacts = mmd.get_rpm_artifacts()
for rpm_nevra in pdc_module["rpms"]: for rpm_nevra in pdc_module["rpms"]:
if rpm_nevra.endswith(".rpm"): if rpm_nevra.endswith(".rpm"):
rpm_nevra = rpm_nevra[:-len(".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"] tag = pdc_module["koji_tag"]
variant.mmds.append(mmd) variant.mmds.append(mmd)

View File

@ -11,7 +11,9 @@ import re
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
try: try:
import modulemd # noqa import gi # noqa
gi.require_version('Modulemd', '1.0') # noqa
from gi.repository import Modulemd # noqa
import pdc_client # noqa import pdc_client # noqa
HAS_MODULE_SUPPORT = True HAS_MODULE_SUPPORT = True
except ImportError: except ImportError:
@ -130,7 +132,7 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase):
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet') @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_module')
@mock.patch('pungi.phases.pkgset.sources.source_koji.get_pdc_client_session') @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): def test_pdc_log(self, modulemd, get_pdc_client_session, get_module, KojiPackageSet, pickle_dumps):
pickle_dumps.return_value = b'DATA' pickle_dumps.return_value = b'DATA'