mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-07-17 11:30:19 +08:00
Allow building module in --offline module with dependencies from local repositories.
There are following changes introduced in this commit: - The `koji_tag` of module builds imported from the local repositories is now in `repofile:///etc/yum.repos.d/some.repo` format to store the repository from which the module was imported to local MBS DB. - The `koji_tag` of fake base module is set to empty `repofile://` and in `MockModuleBuilder` the `conf.base_module_repofiles` list is used as source for the repositories defining platform. We can't simply use single repository, because there might be fedora.repo and fedora-update.repo and so on. - The list of default .repo files for platform are passed using the `-r` switch in `build_module_locally` `mbs-manager` command. - The LocalResolver (subclass of DBResolver) is added which is used to resolve the build dependencies when building modules offline locally. - The `MockModuleBuilder` enables the buildrequired modules and repositories from which they come in the mock config. With this commit, it is possible to build testmodule locally without any external infra.
This commit is contained in:
@@ -8,11 +8,12 @@ from module_build_service.utils import to_text_type
|
||||
|
||||
import kobo.rpmlib
|
||||
|
||||
from module_build_service import conf
|
||||
from module_build_service import conf, db
|
||||
from module_build_service.models import ModuleBuild, ComponentBuild, make_session
|
||||
from module_build_service.builder.MockModuleBuilder import MockModuleBuilder
|
||||
from module_build_service import glib, Modulemd
|
||||
from tests import clean_database
|
||||
from module_build_service.utils import import_fake_base_module
|
||||
from tests import clean_database, make_module
|
||||
|
||||
|
||||
class TestMockModuleBuilder:
|
||||
@@ -176,3 +177,46 @@ class TestMockModuleBuilder:
|
||||
with open(os.path.join(self.resultdir, "pkglist"), "r") as fd:
|
||||
pkglist = fd.read().strip()
|
||||
assert not pkglist
|
||||
|
||||
|
||||
class TestMockModuleBuilderAddRepos:
|
||||
|
||||
def setup_method(self, test_method):
|
||||
clean_database(add_platform_module=False)
|
||||
import_fake_base_module("platform:f29:1:000000")
|
||||
self.platform = ModuleBuild.get_last_build_in_stream(db.session, "platform", "f29")
|
||||
self.foo = make_module("foo:1:1:1", {"platform": ["f29"]}, {"platform": ["f29"]})
|
||||
self.app = make_module("app:1:1:1", {"platform": ["f29"]}, {"platform": ["f29"]})
|
||||
|
||||
@mock.patch("module_build_service.conf.system", new="mock")
|
||||
@mock.patch(
|
||||
'module_build_service.config.Config.base_module_repofiles',
|
||||
new_callable=mock.PropertyMock,
|
||||
return_value=["/etc/yum.repos.d/bar.repo", "/etc/yum.repos.d/bar-updates.repo"],
|
||||
create=True)
|
||||
@mock.patch("module_build_service.builder.MockModuleBuilder.open", create=True)
|
||||
@mock.patch(
|
||||
"module_build_service.builder.MockModuleBuilder.MockModuleBuilder._load_mock_config")
|
||||
@mock.patch(
|
||||
"module_build_service.builder.MockModuleBuilder.MockModuleBuilder._write_mock_config")
|
||||
def test_buildroot_add_repos(self, write_config, load_config, patched_open,
|
||||
base_module_repofiles):
|
||||
patched_open.side_effect = [
|
||||
mock.mock_open(read_data="[fake]\nrepofile 1\n").return_value,
|
||||
mock.mock_open(read_data="[fake]\nrepofile 2\n").return_value,
|
||||
mock.mock_open(read_data="[fake]\nrepofile 3\n").return_value]
|
||||
|
||||
builder = MockModuleBuilder("user", self.app, conf, "module-app", [])
|
||||
|
||||
dependencies = {
|
||||
"repofile://": [self.platform.mmd()],
|
||||
"repofile:///etc/yum.repos.d/foo.repo": [self.foo.mmd(), self.app.mmd()]
|
||||
}
|
||||
|
||||
builder.buildroot_add_repos(dependencies)
|
||||
|
||||
assert "repofile 1" in builder.yum_conf
|
||||
assert "repofile 2" in builder.yum_conf
|
||||
assert "repofile 3" in builder.yum_conf
|
||||
|
||||
assert set(builder.enabled_modules) == set(["foo:1", "app:1"])
|
||||
|
||||
76
tests/test_resolver/test_local.py
Normal file
76
tests/test_resolver/test_local.py
Normal file
@@ -0,0 +1,76 @@
|
||||
# Copyright (c) 2019 Red Hat, Inc.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
#
|
||||
# Written by Jan Kaluza <jkaluza@redhat.com>
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
from module_build_service.utils import to_text_type
|
||||
import module_build_service.resolver as mbs_resolver
|
||||
from module_build_service import db
|
||||
from module_build_service.utils import import_mmd, load_mmd
|
||||
from module_build_service.models import ModuleBuild
|
||||
import tests
|
||||
|
||||
|
||||
base_dir = os.path.join(os.path.dirname(__file__), "..")
|
||||
|
||||
|
||||
class TestLocalResolverModule:
|
||||
|
||||
def setup_method(self):
|
||||
tests.reuse_component_init_data()
|
||||
|
||||
def test_get_buildrequired_modulemds(self):
|
||||
mmd = load_mmd(os.path.join(base_dir, 'staged_data', 'platform.yaml'), True)
|
||||
mmd.set_stream('f8')
|
||||
import_mmd(db.session, mmd)
|
||||
platform_f8 = ModuleBuild.query.filter_by(stream='f8').one()
|
||||
mmd.set_name("testmodule")
|
||||
mmd.set_stream("master")
|
||||
mmd.set_version(20170109091357)
|
||||
mmd.set_context("123")
|
||||
build = ModuleBuild(
|
||||
name='testmodule',
|
||||
stream='master',
|
||||
version=20170109091357,
|
||||
state=5,
|
||||
build_context='dd4de1c346dcf09ce77d38cd4e75094ec1c08ec3',
|
||||
runtime_context='ec4de1c346dcf09ce77d38cd4e75094ec1c08ef7',
|
||||
context='7c29193d',
|
||||
koji_tag='module-testmodule-master-20170109091357-7c29193d',
|
||||
scmurl='https://src.stg.fedoraproject.org/modules/testmodule.git?#ff1ea79',
|
||||
batch=3,
|
||||
owner='Dr. Pepper',
|
||||
time_submitted=datetime(2018, 11, 15, 16, 8, 18),
|
||||
time_modified=datetime(2018, 11, 15, 16, 19, 35),
|
||||
rebuild_strategy='changed-and-after',
|
||||
modulemd=to_text_type(mmd.dumps())
|
||||
)
|
||||
db.session.add(build)
|
||||
db.session.commit()
|
||||
|
||||
resolver = mbs_resolver.GenericResolver.create(tests.conf, backend='local')
|
||||
result = resolver.get_buildrequired_modulemds(
|
||||
"testmodule", "master", platform_f8.mmd().dup_nsvc())
|
||||
nsvcs = set([m.dup_nsvc() for m in result])
|
||||
assert nsvcs == set(['testmodule:master:20170109091357:9c690d0e',
|
||||
'testmodule:master:20170109091357:123'])
|
||||
@@ -191,7 +191,7 @@ class TestModuleWait:
|
||||
resolver.backend = 'db'
|
||||
resolver.get_module_tag.return_value = "module-testmodule-master-20170109091357"
|
||||
resolver.get_module_build_dependencies.return_value = {
|
||||
"module-bootstrap-tag": base_mmd}
|
||||
"module-bootstrap-tag": [base_mmd]}
|
||||
|
||||
with patch.object(module_build_service.resolver, 'system_resolver', new=resolver):
|
||||
msg = module_build_service.messaging.MBSModule(msg_id=None, module_build_id=2,
|
||||
@@ -239,7 +239,7 @@ class TestModuleWait:
|
||||
resolver.backend = 'db'
|
||||
resolver.get_module_tag.return_value = "module-testmodule-master-20170109091357"
|
||||
resolver.get_module_build_dependencies.return_value = {
|
||||
"module-bootstrap-tag": base_mmd}
|
||||
"module-bootstrap-tag": [base_mmd]}
|
||||
|
||||
with patch.object(module_build_service.scheduler.handlers.modules.conf,
|
||||
'koji_cg_tag_build', new=koji_cg_tag_build):
|
||||
|
||||
@@ -1247,7 +1247,7 @@ class TestOfflineLocalBuilds:
|
||||
'mbs': {
|
||||
'buildrequires': {},
|
||||
'commit': 'ref_000000',
|
||||
'koji_tag': 'local_build',
|
||||
'koji_tag': 'repofile://',
|
||||
'mse': 'true',
|
||||
'requires': {}}}
|
||||
|
||||
@@ -1260,6 +1260,7 @@ class TestOfflineLocalBuilds:
|
||||
|
||||
with patch("dnf.Base") as dnf_base:
|
||||
repo = mock.MagicMock()
|
||||
repo.repofile = "/etc/yum.repos.d/foo.repo"
|
||||
with open(path.join(BASE_DIR, '..', 'staged_data', 'formatted_testmodule.yaml')) as f:
|
||||
repo.get_metadata_content.return_value = f.read()
|
||||
base = dnf_base.return_value
|
||||
@@ -1277,5 +1278,8 @@ class TestOfflineLocalBuilds:
|
||||
module_build = models.ModuleBuild.get_build_from_nsvc(
|
||||
db.session, "testmodule", "master", 20180205135154, "9c690d0e")
|
||||
assert module_build
|
||||
assert module_build.koji_tag == "repofile:///etc/yum.repos.d/foo.repo"
|
||||
|
||||
module_build = models.ModuleBuild.get_build_from_nsvc(
|
||||
db.session, "platform", "x", 1, "000000")
|
||||
assert module_build
|
||||
|
||||
Reference in New Issue
Block a user