Remove the filtered RPMs from module metadata even in case all RPMs are filtered out.

Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
This commit is contained in:
Jan Kaluza 2018-03-13 14:29:13 +01:00
parent 5c902592ae
commit fedce5dff1
3 changed files with 116 additions and 3 deletions

View File

@ -74,15 +74,23 @@ class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase):
mmd_id = "%s-%s" % (mmd.get_name(), mmd.get_stream())
arch_mmd = variant.arch_mmds[arch][mmd_id]
# Skip this mmd if this RPM does not belong to it.
srpm = kobo.rpmlib.parse_nvr(rpm_obj.sourcerpm)["name"]
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()):
if (srpm not in mmd.get_rpm_components().keys() or
rpm_obj.nevra not in mmd.get_rpm_artifacts().get()):
continue
# If the RPM is not filtered out, add it to compose,
# otherwise remove it from arch_mmd artifacts section.
if rpm_obj.name not in mmd.get_rpm_filter().get():
packages.add((rpm_obj, None))
added_rpms.setdefault(mmd_id, [])
added_rpms[mmd_id].append(str(rpm_obj.nevra))
log.write('Adding %s because it is in %s\n'
% (rpm_obj, mmd_id))
elif rpm_obj.nevra in arch_mmd["data"]["artifacts"]["rpms"]:
arch_mmd["data"]["artifacts"]["rpms"].remove(
rpm_obj.nevra)
# GatherSource returns all the packages in variant and does not
# care which package is in which module, but for modular metadata

View File

@ -11,10 +11,19 @@ import shutil
import errno
import imp
import six
from kobo.rpmlib import parse_nvr
from pungi.util import get_arch_variant_data
from pungi import paths, checks
try:
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:
HAS_MODULE_SUPPORT = False
class PungiTestCase(unittest.TestCase):
def setUp(self):
@ -51,6 +60,39 @@ class MockVariant(mock.Mock):
def get_modules(self, arch=None, types=None):
return []
def add_fake_module(self, nsvc, rpm_nvrs=None):
if not HAS_MODULE_SUPPORT:
return
name, stream, version, context = nsvc.split(":")
mmd = Modulemd.Module()
mmd.set_mdversion(2)
mmd.set_name(name)
mmd.set_stream(stream)
mmd.set_version(int(version))
mmd.set_context(context)
mmd.set_summary("foo")
mmd.set_description("foo")
licenses = Modulemd.SimpleSet()
licenses.add("GPL")
mmd.set_module_licenses(licenses)
if rpm_nvrs:
artifacts = Modulemd.SimpleSet()
for rpm_nvr in rpm_nvrs:
artifacts.add(rpm_nvr)
rpm_name = parse_nvr(rpm_nvr)["name"]
component = Modulemd.ComponentRpm()
component.set_name(rpm_name)
component.set_rationale("Needed for test")
mmd.add_rpm_component(component)
mmd.set_rpm_artifacts(artifacts)
if self.modules is None:
self.modules = []
self.modules.append(":".join([name, stream, version]))
self.mmds.append(mmd)
return mmd
class IterableMock(mock.Mock):
def __iter__(self):

View File

@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
import mock
import os
import sys
import unittest
try:
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:
HAS_MODULE_SUPPORT = False
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from pungi.phases.gather.sources.source_module import GatherSourceModule
from tests import helpers
@unittest.skipUnless(HAS_MODULE_SUPPORT, 'Skipped test, no module support.')
class TestGatherSourceModule(helpers.PungiTestCase):
def setUp(self):
super(TestGatherSourceModule, self).setUp()
self.compose = helpers.DummyCompose(self.topdir, {})
self.compose.DEBUG = False
self.mmd = self.compose.variants["Server"].add_fake_module(
"testmodule:master:1:2017", rpm_nvrs=["pkg-1.0.0-1"])
mock_rpm = mock.Mock(version='1.0.0', release='1',
epoch=0, excludearch=None, exclusivearch=None,
sourcerpm='pkg-1.0.0-1', nevra='pkg-1.0.0-1')
mock_rpm.name = 'pkg'
self.compose.variants['Server'].pkgset.rpms_by_arch['x86_64'] = [mock_rpm]
def test_gather_module(self):
source = GatherSourceModule(self.compose)
packages, groups = source("x86_64", self.compose.variants["Server"])
self.assertEqual(len(packages), 1)
self.assertEqual(list(packages)[0][0].nevra, "pkg-1.0.0-1")
self.assertEqual(len(groups), 0)
variant = self.compose.variants["Server"]
arch_mmd = variant.arch_mmds["x86_64"]["testmodule-master"]
self.assertEqual(set(arch_mmd["data"]["artifacts"]["rpms"]),
set(["pkg-1.0.0-1"]))
def test_gather_filtered_module(self):
filter_set = Modulemd.SimpleSet()
filter_set.add("pkg")
self.mmd.set_rpm_filter(filter_set)
source = GatherSourceModule(self.compose)
packages, groups = source("x86_64", self.compose.variants["Server"])
self.assertEqual(len(packages), 0)
self.assertEqual(len(groups), 0)
variant = self.compose.variants["Server"]
arch_mmd = variant.arch_mmds["x86_64"]["testmodule-master"]
self.assertEqual(len(arch_mmd["data"]["artifacts"]["rpms"]), 0)