diff --git a/doc/configuration.rst b/doc/configuration.rst index 62d73612..6c08b8b5 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1246,7 +1246,9 @@ they are not scratch builds). This includes ``name``, ``version``, ``scratch`` and ``priority``. 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 diff --git a/pungi/checks.py b/pungi/checks.py index 90544f9e..3c9de33a 100644 --- a/pungi/checks.py +++ b/pungi/checks.py @@ -828,6 +828,8 @@ def _make_schema(): "version": {"type": "string"}, "scratch": {"type": "boolean"}, "priority": {"type": "number"}, + "repo": {"$ref": "#/definitions/strings"}, + "repo_from": {"$ref": "#/definitions/strings"}, }, "required": ["url", "target"] } diff --git a/pungi/phases/osbs.py b/pungi/phases/osbs.py index 6b38a54d..11ed9511 100644 --- a/pungi/phases/osbs.py +++ b/pungi/phases/osbs.py @@ -3,6 +3,7 @@ import json import os from kobo.threads import ThreadPool, WorkerThread +from kobo import shortcuts from .base import ConfigGuardedPhase, PhaseLoggerMixin from .. import util @@ -57,8 +58,12 @@ class OSBSThread(WorkerThread): raise RuntimeError('OSBS: missing config key %s for %s' % (exc, variant.uid)) 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, priority=priority) @@ -106,11 +111,17 @@ class OSBSThread(WorkerThread): self.pool.metadata.setdefault( 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 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, create_dir=False) repo_file = os.path.join(compose.paths.work.tmp_dir(None, variant), diff --git a/tests/test_osbs_phase.py b/tests/test_osbs_phase.py index 39cfee22..007ea3eb 100644 --- a/tests/test_osbs_phase.py +++ b/tests/test_osbs_phase.py @@ -242,6 +242,78 @@ class OSBSThreadTest(helpers.PungiTestCase): self._assertCorrectCalls({'name': 'my-name', 'version': '1.0'}) 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.phases.osbs.kojiwrapper.KojiWrapper') def test_run_with_missing_url(self, KojiWrapper, resolve_git_url):