mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-24 02:32:26 +08:00
Add list of built RPMs to architecture specific modulemd files in CG builds.
This commit is contained in:
@@ -27,9 +27,10 @@ from os import path
|
||||
|
||||
import module_build_service.messaging
|
||||
import module_build_service.scheduler.handlers.repos # noqa
|
||||
from module_build_service import models, conf, build_logs
|
||||
from module_build_service import models, conf, build_logs, Modulemd
|
||||
|
||||
from mock import patch, Mock, MagicMock, call, mock_open
|
||||
import kobo.rpmlib
|
||||
|
||||
from tests import init_data
|
||||
|
||||
@@ -301,3 +302,220 @@ class TestBuild:
|
||||
'filesize': 315,
|
||||
'type': 'file'
|
||||
}
|
||||
|
||||
@patch("module_build_service.builder.KojiContentGenerator.get_session")
|
||||
def test_koji_rpms_in_tag(self, get_session):
|
||||
koji_session = MagicMock()
|
||||
koji_session.getUser.return_value = GET_USER_RV
|
||||
koji_session.getTag.return_value = {"arches": "x86_64"}
|
||||
|
||||
rpms = [
|
||||
{
|
||||
'id': 1,
|
||||
'arch': 'src',
|
||||
'build_id': 875991,
|
||||
'name': 'module-build-macros',
|
||||
'release': '1.module_92011fe6',
|
||||
'version': '0.1'
|
||||
},
|
||||
{
|
||||
'id': 2,
|
||||
'arch': 'noarch',
|
||||
'build_id': 875991,
|
||||
'name': 'module-build-macros',
|
||||
'release': '1.module_92011fe6',
|
||||
'version': '0.1'
|
||||
},
|
||||
{
|
||||
'id': 3,
|
||||
'arch': 'src',
|
||||
'build_id': 875636,
|
||||
'name': 'ed',
|
||||
'release': '2.module_bd6e0eb1',
|
||||
'version': '1.14.1'
|
||||
},
|
||||
{
|
||||
'id': 4,
|
||||
'arch': 'x86_64',
|
||||
'build_id': 875636,
|
||||
'name': 'ed',
|
||||
'release': '2.module_bd6e0eb1',
|
||||
'version': '1.14.1'
|
||||
},
|
||||
]
|
||||
|
||||
builds = [
|
||||
{
|
||||
'build_id': 875636,
|
||||
'name': 'ed',
|
||||
'release': '2.module_bd6e0eb1',
|
||||
'version': '1.14.1',
|
||||
'nvr': 'ed-2.module_bd6e0eb1-1.14.1',
|
||||
},
|
||||
{
|
||||
'build_id': 875991,
|
||||
'name': 'module-build-macros',
|
||||
'release': '1.module_92011fe6',
|
||||
'version': '0.1',
|
||||
'nvr': 'module-build-macros-0.1-1.module_92011fe6',
|
||||
}
|
||||
]
|
||||
|
||||
koji_session.listTaggedRPMS.return_value = (rpms, builds)
|
||||
koji_session.multiCall.side_effect = [
|
||||
# getRPMHeaders response
|
||||
[[{'excludearch': ["x86_64"], 'exclusivearch': []}],
|
||||
[{'excludearch': [], 'exclusivearch': ["x86_64"]}]]
|
||||
]
|
||||
get_session.return_value = koji_session
|
||||
|
||||
rpms = self.cg._koji_rpms_in_tag("tag")
|
||||
for rpm in rpms:
|
||||
# We want to mainly check the excludearch and exclusivearch code.
|
||||
if rpm["name"] == "module-build-macros":
|
||||
assert rpm["excludearch"] == ["x86_64"]
|
||||
else:
|
||||
assert rpm["exclusivearch"] == ["x86_64"]
|
||||
|
||||
def _add_test_rpm(self, nevra, srpm_name=None, multilib=None,
|
||||
koji_srpm_name=None, excludearch=None, exclusivearch=None):
|
||||
"""
|
||||
Helper method to add test RPM to ModuleBuild used by KojiContentGenerator
|
||||
and also to Koji tag used to generate the Content Generator build.
|
||||
|
||||
:param str nevra: NEVRA of the RPM to add.
|
||||
:param str srpm_name: Name of SRPM the added RPM is built from.
|
||||
:param list multilib: List of architecture for which the multilib should be turned on.
|
||||
:param str koji_srpm_name: If set, overrides the `srpm_name` in Koji tag. This is
|
||||
needed to test the case when the built "src" package has different name than
|
||||
the package in Koji. This is for example case of software collections where
|
||||
`srpm_name` is "httpd" but `koji_srpm_name` would be "httpd24-httpd".
|
||||
:param list excludearch: List of architectures this package is excluded from.
|
||||
:param list exclusivearch: List of architectures this package is exclusive for.
|
||||
"""
|
||||
parsed_nevra = kobo.rpmlib.parse_nvra(nevra)
|
||||
parsed_nevra["payloadhash"] = "hash"
|
||||
if koji_srpm_name:
|
||||
parsed_nevra["srpm_name"] = koji_srpm_name
|
||||
else:
|
||||
parsed_nevra["srpm_name"] = srpm_name
|
||||
parsed_nevra["excludearch"] = excludearch or []
|
||||
parsed_nevra["exclusivearch"] = exclusivearch or []
|
||||
self.cg.rpms.append(parsed_nevra)
|
||||
self.cg.rpms_dict[nevra] = parsed_nevra
|
||||
|
||||
mmd = self.cg.module.mmd()
|
||||
if srpm_name not in mmd.get_rpm_components().keys():
|
||||
component = Modulemd.ComponentRpm()
|
||||
component.set_name(srpm_name)
|
||||
component.set_rationale("foo")
|
||||
|
||||
if multilib:
|
||||
multilib_set = Modulemd.SimpleSet()
|
||||
for arch in multilib:
|
||||
multilib_set.add(arch)
|
||||
component.set_multilib(multilib_set)
|
||||
|
||||
mmd.add_rpm_component(component)
|
||||
self.cg.module.modulemd = mmd.dumps()
|
||||
self.cg.modulemd = mmd.dumps()
|
||||
|
||||
def test_fill_in_rpms_list(self):
|
||||
self._add_test_rpm("dhcp-libs-12:4.3.5-5.module_2118aef6.x86_64", "dhcp")
|
||||
self._add_test_rpm("dhcp-libs-12:4.3.5-5.module_2118aef6.i686", "dhcp")
|
||||
self._add_test_rpm("perl-Tangerine-12:4.3.5-5.module_2118aef6.x86_64", "perl-Tangerine")
|
||||
self._add_test_rpm("perl-Tangerine-12:4.3.5-5.module_2118aef6.i686", "perl-Tangerine")
|
||||
|
||||
mmd = self.cg.module.mmd()
|
||||
mmd = self.cg._fill_in_rpms_list(mmd, "x86_64")
|
||||
|
||||
# Only x86_64 packages should be filled in, because we requested x86_64 arch.
|
||||
assert set(mmd.get_rpm_artifacts().get()) == set([
|
||||
"dhcp-libs-12:4.3.5-5.module_2118aef6.x86_64",
|
||||
"perl-Tangerine-12:4.3.5-5.module_2118aef6.x86_64"])
|
||||
|
||||
def test_fill_in_rpms_exclusivearch(self):
|
||||
self._add_test_rpm("dhcp-libs-12:4.3.5-5.module_2118aef6.noarch", "dhcp",
|
||||
exclusivearch=["x86_64"])
|
||||
self._add_test_rpm("perl-Tangerine-12:4.3.5-5.module_2118aef6.noarch", "perl-Tangerine",
|
||||
exclusivearch=["ppc64le"])
|
||||
|
||||
mmd = self.cg.module.mmd()
|
||||
mmd = self.cg._fill_in_rpms_list(mmd, "x86_64")
|
||||
|
||||
# Only dhcp-libs should be filled in, because perl-Tangerine has different
|
||||
# exclusivearch.
|
||||
assert set(mmd.get_rpm_artifacts().get()) == set([
|
||||
"dhcp-libs-12:4.3.5-5.module_2118aef6.noarch"])
|
||||
|
||||
def test_fill_in_rpms_excludearch(self):
|
||||
self._add_test_rpm("dhcp-libs-12:4.3.5-5.module_2118aef6.noarch", "dhcp",
|
||||
excludearch=["x86_64"])
|
||||
self._add_test_rpm("perl-Tangerine-12:4.3.5-5.module_2118aef6.noarch", "perl-Tangerine",
|
||||
excludearch=["ppc64le"])
|
||||
|
||||
mmd = self.cg.module.mmd()
|
||||
mmd = self.cg._fill_in_rpms_list(mmd, "x86_64")
|
||||
|
||||
# Only perl-Tangerine should be filled in, because dhcp-libs is excluded from x86_64.
|
||||
assert set(mmd.get_rpm_artifacts().get()) == set([
|
||||
"perl-Tangerine-12:4.3.5-5.module_2118aef6.noarch"])
|
||||
|
||||
def test_fill_in_rpms_rpm_whitelist(self):
|
||||
self._add_test_rpm("dhcp-libs-12:4.3.5-5.module_2118aef6.x86_64", "dhcp",
|
||||
koji_srpm_name="python27-dhcp")
|
||||
self._add_test_rpm("dhcp-libs-12:4.3.5-5.module_2118aef6.i686", "dhcp",
|
||||
koji_srpm_name="python27-dhcp")
|
||||
self._add_test_rpm("perl-Tangerine-12:4.3.5-5.module_2118aef6.x86_64", "perl-Tangerine",
|
||||
koji_srpm_name="foo-perl-Tangerine")
|
||||
self._add_test_rpm("perl-Tangerine-12:4.3.5-5.module_2118aef6.i686", "perl-Tangerine",
|
||||
koji_srpm_name="foo-perl-Tangerine")
|
||||
|
||||
mmd = self.cg.module.mmd()
|
||||
opts = mmd.get_buildopts()
|
||||
opts.set_rpm_whitelist(["python27-dhcp"])
|
||||
mmd.set_buildopts(opts)
|
||||
|
||||
mmd = self.cg._fill_in_rpms_list(mmd, "x86_64")
|
||||
|
||||
# Only x86_64 dhcp-libs should be filled in, because only python27-dhcp is whitelisted
|
||||
# srpm name.
|
||||
assert set(mmd.get_rpm_artifacts().get()) == set([
|
||||
"dhcp-libs-12:4.3.5-5.module_2118aef6.x86_64"])
|
||||
|
||||
def test_fill_in_rpms_list_filters(self):
|
||||
self._add_test_rpm("dhcp-libs-12:4.3.5-5.module_2118aef6.x86_64", "dhcp")
|
||||
self._add_test_rpm("dhcp-libs-12:4.3.5-5.module_2118aef6.i686", "dhcp")
|
||||
self._add_test_rpm("perl-Tangerine-12:4.3.5-5.module_2118aef6.x86_64", "perl-Tangerine")
|
||||
self._add_test_rpm("perl-Tangerine-12:4.3.5-5.module_2118aef6.i686", "perl-Tangerine")
|
||||
|
||||
mmd = self.cg.module.mmd()
|
||||
filter_list = Modulemd.SimpleSet()
|
||||
filter_list.add("dhcp-libs")
|
||||
mmd.set_rpm_filter(filter_list)
|
||||
|
||||
mmd = self.cg._fill_in_rpms_list(mmd, "x86_64")
|
||||
|
||||
# Only x86_64 perl-Tangerine should be filled in, because dhcp-libs is filtered out.
|
||||
assert set(mmd.get_rpm_artifacts().get()) == set([
|
||||
"perl-Tangerine-12:4.3.5-5.module_2118aef6.x86_64"])
|
||||
|
||||
def test_fill_in_rpms_list_multilib(self):
|
||||
self._add_test_rpm("dhcp-libs-12:4.3.5-5.module_2118aef6.x86_64", "dhcp",
|
||||
multilib=["x86_64"])
|
||||
self._add_test_rpm("dhcp-libs-12:4.3.5-5.module_2118aef6.i686", "dhcp",
|
||||
multilib=["x86_64"])
|
||||
self._add_test_rpm("perl-Tangerine-12:4.3.5-5.module_2118aef6.x86_64", "perl-Tangerine",
|
||||
multilib=["ppc64le"])
|
||||
self._add_test_rpm("perl-Tangerine-12:4.3.5-5.module_2118aef6.i686", "perl-Tangerine",
|
||||
multilib=["ppc64le"])
|
||||
|
||||
mmd = self.cg.module.mmd()
|
||||
mmd = self.cg._fill_in_rpms_list(mmd, "x86_64")
|
||||
|
||||
# Only i686 package for dhcp-libs should be added, because perl-Tangerine does not have
|
||||
# multilib set.
|
||||
assert set(mmd.get_rpm_artifacts().get()) == set([
|
||||
"dhcp-libs-12:4.3.5-5.module_2118aef6.x86_64",
|
||||
"dhcp-libs-12:4.3.5-5.module_2118aef6.i686",
|
||||
"perl-Tangerine-12:4.3.5-5.module_2118aef6.x86_64"])
|
||||
|
||||
Reference in New Issue
Block a user