osbs: Enable specifying extra repos

The same way live_media and image_build accept additional external repos
or variants list, there is now a `repo` and `repo_from` configuration
key to add these.

Fixes: #486
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2017-01-04 09:15:27 +01:00
parent 2d404c88e6
commit 814bf4484b
4 changed files with 90 additions and 3 deletions

View File

@ -1246,7 +1246,9 @@ they are not scratch builds).
This includes ``name``, ``version``, ``scratch`` and ``priority``. This includes ``name``, ``version``, ``scratch`` and ``priority``.
A value for ``yum_repourls`` will be created automatically and point at a A value for ``yum_repourls`` will be created automatically and point at a
repository in the current compose. repository in the current compose. You can add extra repositories with
``repo`` key having a list of urls pointing to ``.repo`` files or
``repo_from`` as a list of variants in current compose.
Example config Example config

View File

@ -828,6 +828,8 @@ def _make_schema():
"version": {"type": "string"}, "version": {"type": "string"},
"scratch": {"type": "boolean"}, "scratch": {"type": "boolean"},
"priority": {"type": "number"}, "priority": {"type": "number"},
"repo": {"$ref": "#/definitions/strings"},
"repo_from": {"$ref": "#/definitions/strings"},
}, },
"required": ["url", "target"] "required": ["url", "target"]
} }

View File

@ -3,6 +3,7 @@
import json import json
import os import os
from kobo.threads import ThreadPool, WorkerThread from kobo.threads import ThreadPool, WorkerThread
from kobo import shortcuts
from .base import ConfigGuardedPhase, PhaseLoggerMixin from .base import ConfigGuardedPhase, PhaseLoggerMixin
from .. import util from .. import util
@ -57,8 +58,12 @@ class OSBSThread(WorkerThread):
raise RuntimeError('OSBS: missing config key %s for %s' raise RuntimeError('OSBS: missing config key %s for %s'
% (exc, variant.uid)) % (exc, variant.uid))
priority = config.pop('priority', None) priority = config.pop('priority', None)
repos = shortcuts.force_list(config.pop('repo', []))
compose_repos = [self._get_repo(compose, v)
for v in [variant.uid] + shortcuts.force_list(
config.pop('repo_from', []))]
config['yum_repourls'] = [self._get_repo(compose, variant)] config['yum_repourls'] = compose_repos + repos
task_id = koji.koji_proxy.buildContainer(source, target, config, task_id = koji.koji_proxy.buildContainer(source, target, config,
priority=priority) priority=priority)
@ -106,11 +111,17 @@ class OSBSThread(WorkerThread):
self.pool.metadata.setdefault( self.pool.metadata.setdefault(
variant.uid, {}).setdefault(arch, []).append(data) variant.uid, {}).setdefault(arch, []).append(data)
def _get_repo(self, compose, variant): def _get_repo(self, compose, variant_uid):
""" """
Write a .repo file pointing to current variant and return URL to the Write a .repo file pointing to current variant and return URL to the
file. file.
""" """
try:
variant = compose.all_variants[variant_uid]
except KeyError:
raise RuntimeError(
'There is no variant %s to get repo from to pass to OSBS.'
% (variant_uid))
os_tree = compose.paths.compose.os_tree('$basearch', variant, os_tree = compose.paths.compose.os_tree('$basearch', variant,
create_dir=False) create_dir=False)
repo_file = os.path.join(compose.paths.work.tmp_dir(None, variant), repo_file = os.path.join(compose.paths.work.tmp_dir(None, variant),

View File

@ -242,6 +242,78 @@ class OSBSThreadTest(helpers.PungiTestCase):
self._assertCorrectCalls({'name': 'my-name', 'version': '1.0'}) self._assertCorrectCalls({'name': 'my-name', 'version': '1.0'})
self._assertCorrectMetadata() self._assertCorrectMetadata()
@mock.patch('pungi.util.resolve_git_url')
@mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper')
def test_run_with_extra_repos(self, KojiWrapper, resolve_git_url):
cfg = {
'url': 'git://example.com/repo?#HEAD',
'target': 'f24-docker-candidate',
'name': 'my-name',
'version': '1.0',
'repo': 'http://pkgs.example.com/my.repo',
'repo_from': 'Everything',
}
self._setupMock(KojiWrapper, resolve_git_url)
self.t.process((self.compose, self.compose.variants['Server'], cfg), 1)
options = {
'name': 'my-name',
'version': '1.0',
'yum_repourls': [
'http://root/work/global/tmp-Server/compose-rpms-1.repo',
'http://root/work/global/tmp-Everything/compose-rpms-1.repo',
'http://pkgs.example.com/my.repo',
]
}
self._assertCorrectCalls(options)
self._assertCorrectMetadata()
@mock.patch('pungi.util.resolve_git_url')
@mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper')
def test_run_with_extra_repos_in_list(self, KojiWrapper, resolve_git_url):
cfg = {
'url': 'git://example.com/repo?#HEAD',
'target': 'f24-docker-candidate',
'name': 'my-name',
'version': '1.0',
'repo': ['http://pkgs.example.com/my.repo'],
'repo_from': ['Everything', 'Client'],
}
self._setupMock(KojiWrapper, resolve_git_url)
self.t.process((self.compose, self.compose.variants['Server'], cfg), 1)
options = {
'name': 'my-name',
'version': '1.0',
'yum_repourls': [
'http://root/work/global/tmp-Server/compose-rpms-1.repo',
'http://root/work/global/tmp-Everything/compose-rpms-1.repo',
'http://root/work/global/tmp-Client/compose-rpms-1.repo',
'http://pkgs.example.com/my.repo',
]
}
self._assertCorrectCalls(options)
self._assertCorrectMetadata()
@mock.patch('pungi.util.resolve_git_url')
@mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper')
def test_run_with_extra_repos_missing_variant(self, KojiWrapper, resolve_git_url):
cfg = {
'url': 'git://example.com/repo?#HEAD',
'target': 'f24-docker-candidate',
'name': 'my-name',
'version': '1.0',
'repo_from': 'Gold',
}
self._setupMock(KojiWrapper, resolve_git_url)
with self.assertRaises(RuntimeError) as ctx:
self.t.process((self.compose, self.compose.variants['Server'], cfg), 1)
self.assertIn('no variant Gold', str(ctx.exception))
@mock.patch('pungi.util.resolve_git_url') @mock.patch('pungi.util.resolve_git_url')
@mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper')
def test_run_with_missing_url(self, KojiWrapper, resolve_git_url): def test_run_with_missing_url(self, KojiWrapper, resolve_git_url):