2016-06-20 13:43:55 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import mock
|
|
|
|
import json
|
|
|
|
|
2017-01-04 08:35:31 +00:00
|
|
|
import copy
|
2016-06-20 13:43:55 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
from tests import helpers
|
2017-01-04 08:35:31 +00:00
|
|
|
from pungi import checks
|
2016-06-20 13:43:55 +00:00
|
|
|
from pungi.phases import osbs
|
|
|
|
|
|
|
|
|
|
|
|
class OSBSPhaseTest(helpers.PungiTestCase):
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.ThreadPool")
|
2016-06-20 13:43:55 +00:00
|
|
|
def test_run(self, ThreadPool):
|
2017-03-27 21:53:08 +00:00
|
|
|
cfg = helpers.IterableMock()
|
2020-01-22 10:02:22 +00:00
|
|
|
compose = helpers.DummyCompose(self.topdir, {"osbs": {"^Everything$": cfg}})
|
2016-06-20 13:43:55 +00:00
|
|
|
|
|
|
|
pool = ThreadPool.return_value
|
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
phase = osbs.OSBSPhase(compose, None, None)
|
2016-06-20 13:43:55 +00:00
|
|
|
phase.run()
|
|
|
|
|
|
|
|
self.assertEqual(len(pool.add.call_args_list), 1)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
pool.queue_put.call_args_list,
|
|
|
|
[mock.call((compose, compose.variants["Everything"], cfg))],
|
|
|
|
)
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.ThreadPool")
|
2016-06-20 13:43:55 +00:00
|
|
|
def test_skip_without_config(self, ThreadPool):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
compose.just_phases = None
|
|
|
|
compose.skip_phases = []
|
2021-09-09 05:58:32 +00:00
|
|
|
phase = osbs.OSBSPhase(compose, None, None)
|
2016-06-20 13:43:55 +00:00
|
|
|
self.assertTrue(phase.skip())
|
|
|
|
|
2019-02-07 13:17:09 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.ThreadPool")
|
|
|
|
def test_request_push(self, ThreadPool):
|
2020-01-22 10:02:22 +00:00
|
|
|
compose = helpers.DummyCompose(self.topdir, {"osbs": {"^Everything$": {}}})
|
2019-02-07 13:17:09 +00:00
|
|
|
compose.just_phases = None
|
|
|
|
compose.skip_phases = []
|
|
|
|
compose.notifier = mock.Mock()
|
2021-09-09 05:58:32 +00:00
|
|
|
phase = osbs.OSBSPhase(compose, None, None)
|
2019-02-07 13:17:09 +00:00
|
|
|
phase.start()
|
|
|
|
phase.stop()
|
|
|
|
phase.pool.registries = {"foo": "bar"}
|
|
|
|
phase.request_push()
|
|
|
|
|
|
|
|
with open(os.path.join(self.topdir, "logs/global/osbs-registries.json")) as f:
|
|
|
|
data = json.load(f)
|
|
|
|
self.assertEqual(data, phase.pool.registries)
|
|
|
|
|
|
|
|
self.assertEqual(
|
2021-03-02 10:19:05 +00:00
|
|
|
compose.notifier.call_args_list,
|
|
|
|
[],
|
2019-02-07 13:17:09 +00:00
|
|
|
)
|
|
|
|
|
2016-06-20 13:43:55 +00:00
|
|
|
|
|
|
|
TASK_RESULT = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"koji_builds": ["54321"],
|
|
|
|
"repositories": [
|
|
|
|
"registry.example.com:8888/rcm/buildroot:f24-docker-candidate-20160617141632",
|
|
|
|
],
|
2016-06-20 13:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BUILD_INFO = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"completion_time": "2016-06-17 18:25:30",
|
|
|
|
"completion_ts": 1466187930.0,
|
|
|
|
"creation_event_id": 13227702,
|
|
|
|
"creation_time": "2016-06-17 18:25:57.611172",
|
|
|
|
"creation_ts": 1466187957.61117,
|
|
|
|
"epoch": None,
|
|
|
|
"extra": {"container_koji_task_id": "12345", "image": {}},
|
|
|
|
"id": 54321,
|
|
|
|
"name": "my-name",
|
|
|
|
"nvr": "my-name-1.0-1",
|
|
|
|
"owner_id": 3436,
|
|
|
|
"owner_name": "osbs",
|
|
|
|
"package_id": 50072,
|
|
|
|
"package_name": "my-name",
|
|
|
|
"release": "1",
|
|
|
|
"source": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"start_time": "2016-06-17 18:16:37",
|
|
|
|
"start_ts": 1466187397.0,
|
|
|
|
"state": 1,
|
|
|
|
"task_id": None,
|
|
|
|
"version": "1.0",
|
|
|
|
"volume_id": 0,
|
|
|
|
"volume_name": "DEFAULT",
|
2016-06-20 13:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ARCHIVES = [
|
2020-01-22 10:02:22 +00:00
|
|
|
{
|
|
|
|
"build_id": 54321,
|
|
|
|
"buildroot_id": 2955357,
|
|
|
|
"checksum": "a2922842dc80873ac782da048c54f6cc",
|
|
|
|
"checksum_type": 0,
|
|
|
|
"extra": {
|
|
|
|
"docker": {
|
2020-02-06 07:09:32 +00:00
|
|
|
"id": "408c4cd37a87a807bec65dd13b049a32fe090d2fa1a8e891f65e3e3e683996d7", # noqa: E501
|
|
|
|
"parent_id": "6c3a84d798dc449313787502060b6d5b4694d7527d64a7c99ba199e3b2df834e", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
"repositories": ["registry.example.com:8888/rcm/buildroot:1.0-1"],
|
|
|
|
},
|
|
|
|
"image": {"arch": "x86_64"},
|
|
|
|
},
|
2020-02-06 07:09:32 +00:00
|
|
|
"filename": "docker-image-408c4cd37a87a807bec65dd13b049a32fe090d2fa1a8e891f65e3e3e683996d7.x86_64.tar.gz", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
"id": 1436049,
|
|
|
|
"metadata_only": False,
|
|
|
|
"size": 174038795,
|
|
|
|
"type_description": "Tar file",
|
|
|
|
"type_extensions": "tar tar.gz tar.bz2 tar.xz",
|
|
|
|
"type_id": 4,
|
|
|
|
"type_name": "tar",
|
|
|
|
}
|
2016-06-20 13:43:55 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
METADATA = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"Server": {
|
|
|
|
"x86_64": [
|
|
|
|
{
|
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
|
|
|
"release": "1",
|
|
|
|
"nvr": "my-name-1.0-1",
|
|
|
|
"creation_time": BUILD_INFO["creation_time"],
|
|
|
|
"filename": ARCHIVES[0]["filename"],
|
|
|
|
"size": ARCHIVES[0]["size"],
|
|
|
|
"docker": {
|
2020-02-06 07:09:32 +00:00
|
|
|
"id": "408c4cd37a87a807bec65dd13b049a32fe090d2fa1a8e891f65e3e3e683996d7", # noqa: E501
|
|
|
|
"parent_id": "6c3a84d798dc449313787502060b6d5b4694d7527d64a7c99ba199e3b2df834e", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
"repositories": ["registry.example.com:8888/rcm/buildroot:1.0-1"],
|
|
|
|
},
|
|
|
|
"image": {"arch": "x86_64"},
|
|
|
|
"checksum": ARCHIVES[0]["checksum"],
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2016-06-20 13:43:55 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
RPMS = []
|
|
|
|
|
2017-03-02 13:10:16 +00:00
|
|
|
SCRATCH_TASK_RESULT = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"koji_builds": [],
|
|
|
|
"repositories": [
|
|
|
|
"registry.example.com:8888/rcm/buildroot:f24-docker-candidate-20160617141632",
|
|
|
|
],
|
2017-03-02 13:10:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SCRATCH_METADATA = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"Server": {
|
|
|
|
"scratch": [
|
|
|
|
{
|
|
|
|
"koji_task": 12345,
|
|
|
|
"repositories": [
|
2020-02-06 07:09:32 +00:00
|
|
|
"registry.example.com:8888/rcm/buildroot:f24-docker-candidate-20160617141632", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
],
|
|
|
|
}
|
2017-03-02 13:10:16 +00:00
|
|
|
]
|
2020-01-22 10:02:22 +00:00
|
|
|
}
|
2017-03-02 13:10:16 +00:00
|
|
|
}
|
|
|
|
|
2016-06-20 13:43:55 +00:00
|
|
|
|
|
|
|
class OSBSThreadTest(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(OSBSThreadTest, self).setUp()
|
2021-02-08 10:42:07 +00:00
|
|
|
self.pool = mock.Mock(registries={})
|
2016-06-20 13:43:55 +00:00
|
|
|
self.t = osbs.OSBSThread(self.pool)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.compose = helpers.DummyCompose(
|
|
|
|
self.topdir,
|
|
|
|
{
|
|
|
|
"koji_profile": "koji",
|
2023-07-19 10:16:29 +00:00
|
|
|
"koji_cache": "/tmp",
|
2020-01-22 10:02:22 +00:00
|
|
|
"translate_paths": [(self.topdir, "http://root")],
|
|
|
|
},
|
|
|
|
)
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2018-11-21 09:56:22 +00:00
|
|
|
def _setupMock(self, KojiWrapper, scratch=False):
|
2016-06-20 13:43:55 +00:00
|
|
|
self.wrapper = KojiWrapper.return_value
|
|
|
|
self.wrapper.koji_proxy.buildContainer.return_value = 12345
|
2017-03-02 13:10:16 +00:00
|
|
|
if scratch:
|
|
|
|
self.wrapper.koji_proxy.getTaskResult.return_value = SCRATCH_TASK_RESULT
|
|
|
|
else:
|
|
|
|
self.wrapper.koji_proxy.getTaskResult.return_value = TASK_RESULT
|
|
|
|
self.wrapper.koji_proxy.getBuild.return_value = BUILD_INFO
|
|
|
|
self.wrapper.koji_proxy.listArchives.return_value = ARCHIVES
|
2021-09-09 05:58:32 +00:00
|
|
|
self.wrapper.koji_proxy.listRPMs.return_value = RPMS
|
2020-01-22 10:02:22 +00:00
|
|
|
self.wrapper.koji_proxy.getLatestBuilds.return_value = [
|
|
|
|
mock.Mock(),
|
|
|
|
mock.Mock(),
|
|
|
|
]
|
2016-06-20 13:43:55 +00:00
|
|
|
self.wrapper.koji_proxy.getNextRelease.return_value = 3
|
|
|
|
self.wrapper.watch_task.return_value = 0
|
|
|
|
|
2017-03-02 13:10:16 +00:00
|
|
|
def _assertCorrectMetadata(self, scratch=False):
|
2016-06-20 13:43:55 +00:00
|
|
|
self.maxDiff = None
|
2017-03-02 13:10:16 +00:00
|
|
|
if scratch:
|
|
|
|
metadata = copy.deepcopy(SCRATCH_METADATA)
|
2020-01-22 10:02:22 +00:00
|
|
|
metadata["Server"]["scratch"][0]["compose_id"] = self.compose.compose_id
|
|
|
|
metadata["Server"]["scratch"][0]["koji_task"] = 12345
|
2017-03-02 13:10:16 +00:00
|
|
|
else:
|
|
|
|
metadata = copy.deepcopy(METADATA)
|
2020-01-22 10:02:22 +00:00
|
|
|
metadata["Server"]["x86_64"][0]["compose_id"] = self.compose.compose_id
|
|
|
|
metadata["Server"]["x86_64"][0]["koji_task"] = 12345
|
2021-02-08 10:42:07 +00:00
|
|
|
self.assertEqual(self.compose.containers_metadata, metadata)
|
2017-03-02 13:10:16 +00:00
|
|
|
|
|
|
|
def _assertCorrectCalls(self, opts, setupCalls=None, scratch=False):
|
2016-06-20 13:43:55 +00:00
|
|
|
setupCalls = setupCalls or []
|
2020-01-22 10:02:22 +00:00
|
|
|
options = {
|
|
|
|
"yum_repourls": [
|
|
|
|
"http://root/work/global/tmp-Server/compose-rpms-Server-1.repo"
|
|
|
|
]
|
|
|
|
}
|
2017-03-02 13:10:16 +00:00
|
|
|
if scratch:
|
2020-01-22 10:02:22 +00:00
|
|
|
options["scratch"] = True
|
2016-06-20 13:43:55 +00:00
|
|
|
options.update(opts)
|
2017-03-02 13:10:16 +00:00
|
|
|
expect_calls = [mock.call.login()] + setupCalls
|
2020-01-22 10:02:22 +00:00
|
|
|
expect_calls.extend(
|
|
|
|
[
|
|
|
|
mock.call.koji_proxy.buildContainer(
|
|
|
|
"git://example.com/repo?#BEEFCAFE",
|
|
|
|
"f24-docker-candidate",
|
|
|
|
options,
|
|
|
|
priority=None,
|
|
|
|
),
|
2021-03-22 07:52:47 +00:00
|
|
|
mock.call.save_task_id(12345),
|
2020-01-22 10:02:22 +00:00
|
|
|
mock.call.watch_task(
|
|
|
|
12345, self.topdir + "/logs/global/osbs/Server-1-watch-task.log"
|
|
|
|
),
|
|
|
|
mock.call.koji_proxy.getTaskResult(12345),
|
|
|
|
]
|
|
|
|
)
|
2017-03-02 13:10:16 +00:00
|
|
|
|
|
|
|
if not scratch:
|
2020-01-22 10:02:22 +00:00
|
|
|
expect_calls.extend(
|
|
|
|
[
|
|
|
|
mock.call.koji_proxy.getBuild(54321),
|
osbs: only handle archives of type "image"
Prior to this change, if a container image used Cachito with OSBS, then
OSBS would store additional "remote-sources" files in the Koji archives
for the build. Pungi cannot parse the metadata for these archive
entries, so it would crash in add_metadata():
File "pungi/phases/osbs.py", line 81, in process
self.worker(compose, variant, config)
File "pungi/phases/osbs.py", line 141, in worker
nvr, archive_ids = add_metadata(variant, task_id, compose, scratch)
File "pungi/phases/osbs.py", line 447, in add_metadata
arch = archive["extra"]["image"]["arch"]
KeyError: 'image'
Tell Koji to only return container image archives, and ignore these
remote-source archives.
Signed-off-by: Ken Dreyer <kdreyer@redhat.com>
2022-03-17 15:04:02 +00:00
|
|
|
mock.call.koji_proxy.listArchives(54321, type="image"),
|
2021-09-09 05:58:32 +00:00
|
|
|
mock.call.koji_proxy.listRPMs(imageID=1436049),
|
2020-01-22 10:02:22 +00:00
|
|
|
]
|
|
|
|
)
|
2017-03-02 13:10:16 +00:00
|
|
|
self.assertEqual(self.wrapper.mock_calls, expect_calls)
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2017-01-17 04:54:41 +00:00
|
|
|
def _assertRepoFile(self, variants=None, gpgkey=None):
|
2020-01-22 10:02:22 +00:00
|
|
|
variants = variants or ["Server"]
|
2017-01-04 08:19:25 +00:00
|
|
|
for variant in variants:
|
2020-01-22 10:02:22 +00:00
|
|
|
with open(
|
|
|
|
self.topdir
|
|
|
|
+ "/work/global/tmp-%s/compose-rpms-%s-1.repo" % (variant, variant)
|
|
|
|
) as f:
|
|
|
|
lines = f.read().split("\n")
|
|
|
|
self.assertIn(
|
|
|
|
"baseurl=http://root/compose/%s/$basearch/os" % variant, lines
|
|
|
|
)
|
2017-01-17 04:54:41 +00:00
|
|
|
if gpgkey:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertIn("gpgcheck=1", lines)
|
|
|
|
self.assertIn("gpgkey=%s" % gpgkey, lines)
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2017-01-04 08:35:31 +00:00
|
|
|
def _assertConfigCorrect(self, cfg):
|
|
|
|
config = copy.deepcopy(self.compose.conf)
|
2020-01-22 10:02:22 +00:00
|
|
|
config["osbs"] = {"^Server$": cfg}
|
2018-11-21 09:56:22 +00:00
|
|
|
self.assertEqual(([], []), checks.validate(config, offline=True))
|
2017-01-04 08:35:31 +00:00
|
|
|
|
|
|
|
def _assertConfigMissing(self, cfg, key):
|
|
|
|
config = copy.deepcopy(self.compose.conf)
|
2020-01-22 10:02:22 +00:00
|
|
|
config["osbs"] = {"^Server$": cfg}
|
2019-06-25 10:50:07 +00:00
|
|
|
errors, warnings = checks.validate(config, offline=True)
|
|
|
|
self.assertIn(
|
2020-02-06 07:09:32 +00:00
|
|
|
"Failed validation in osbs.^Server$: %r is not valid under any of the given schemas" # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
% cfg,
|
2019-06-25 10:50:07 +00:00
|
|
|
errors,
|
|
|
|
)
|
|
|
|
self.assertIn(" Possible reason: %r is a required property" % key, errors)
|
|
|
|
self.assertEqual([], warnings)
|
2017-01-04 08:35:31 +00:00
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.get_file_from_scm")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2021-09-09 05:58:32 +00:00
|
|
|
def test_minimal_run(self, KojiWrapper, get_file_from_scm):
|
2016-06-20 13:43:55 +00:00
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "f24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
2016-06-20 13:43:55 +00:00
|
|
|
}
|
2018-11-21 09:56:22 +00:00
|
|
|
self._setupMock(KojiWrapper)
|
2017-01-04 08:35:31 +00:00
|
|
|
self._assertConfigCorrect(cfg)
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self._assertCorrectCalls({"git_branch": "f24-docker"})
|
2016-06-20 13:43:55 +00:00
|
|
|
self._assertCorrectMetadata()
|
2017-01-04 08:19:25 +00:00
|
|
|
self._assertRepoFile()
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.get_file_from_scm")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2021-09-09 05:58:32 +00:00
|
|
|
def test_run_failable(self, KojiWrapper, get_file_from_scm):
|
2016-06-24 07:44:40 +00:00
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "f24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"failable": ["*"],
|
2016-06-24 07:44:40 +00:00
|
|
|
}
|
2018-11-21 09:56:22 +00:00
|
|
|
self._setupMock(KojiWrapper)
|
2017-01-04 08:35:31 +00:00
|
|
|
self._assertConfigCorrect(cfg)
|
2016-06-24 07:44:40 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
2016-06-24 07:44:40 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self._assertCorrectCalls({"git_branch": "f24-docker"})
|
2016-06-24 07:44:40 +00:00
|
|
|
self._assertCorrectMetadata()
|
2017-01-04 08:19:25 +00:00
|
|
|
self._assertRepoFile()
|
2016-06-24 07:44:40 +00:00
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.get_file_from_scm")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2021-09-09 05:58:32 +00:00
|
|
|
def test_run_with_more_args(self, KojiWrapper, get_file_from_scm):
|
2016-06-20 13:43:55 +00:00
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "f24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
2016-06-20 13:43:55 +00:00
|
|
|
}
|
2018-11-21 09:56:22 +00:00
|
|
|
self._setupMock(KojiWrapper)
|
2017-01-04 08:35:31 +00:00
|
|
|
self._assertConfigCorrect(cfg)
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self._assertCorrectCalls(
|
|
|
|
{"name": "my-name", "version": "1.0", "git_branch": "f24-docker"}
|
|
|
|
)
|
2016-06-20 13:43:55 +00:00
|
|
|
self._assertCorrectMetadata()
|
2017-01-04 08:19:25 +00:00
|
|
|
self._assertRepoFile()
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.get_file_from_scm")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2021-09-09 05:58:32 +00:00
|
|
|
def test_run_with_extra_repos(self, KojiWrapper, get_file_from_scm):
|
2017-01-04 08:15:27 +00:00
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "f24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
2021-09-09 06:49:31 +00:00
|
|
|
"repo": [
|
|
|
|
"Everything",
|
|
|
|
"http://pkgs.example.com/my.repo",
|
|
|
|
"/extra/repo",
|
|
|
|
"http://cts.localhost/$COMPOSE_ID/repo",
|
|
|
|
],
|
2017-01-04 08:15:27 +00:00
|
|
|
}
|
2019-02-21 10:04:38 +00:00
|
|
|
self.compose.conf["translate_paths"].append(("/extra", "http://example.com"))
|
2018-11-21 09:56:22 +00:00
|
|
|
self._setupMock(KojiWrapper)
|
2017-01-04 08:35:31 +00:00
|
|
|
self._assertConfigCorrect(cfg)
|
2017-01-04 08:15:27 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
2017-01-04 08:15:27 +00:00
|
|
|
|
|
|
|
options = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"yum_repourls": [
|
|
|
|
"http://root/work/global/tmp-Server/compose-rpms-Server-1.repo",
|
|
|
|
"http://root/work/global/tmp-Everything/compose-rpms-Everything-1.repo",
|
|
|
|
"http://pkgs.example.com/my.repo",
|
2019-02-21 10:04:38 +00:00
|
|
|
"http://root/work/global/tmp/compose-rpms-local-1.repo",
|
2021-09-09 06:49:31 +00:00
|
|
|
"http://cts.localhost/%s/repo" % self.compose.compose_id,
|
2020-01-22 10:02:22 +00:00
|
|
|
],
|
2017-01-04 08:15:27 +00:00
|
|
|
}
|
|
|
|
self._assertCorrectCalls(options)
|
|
|
|
self._assertCorrectMetadata()
|
2020-01-22 10:02:22 +00:00
|
|
|
self._assertRepoFile(["Server", "Everything"])
|
2017-01-04 08:15:27 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
with open(
|
|
|
|
os.path.join(self.topdir, "work/global/tmp/compose-rpms-local-1.repo")
|
|
|
|
) as f:
|
2019-02-21 10:04:38 +00:00
|
|
|
self.assertIn("baseurl=http://example.com/repo\n", f)
|
|
|
|
|
2021-10-21 11:34:37 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.get_file_from_scm")
|
2021-09-24 08:17:40 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2021-10-21 11:34:37 +00:00
|
|
|
def test_run_with_extra_repos_with_cts(self, KojiWrapper, get_file_from_scm):
|
2021-09-24 08:17:40 +00:00
|
|
|
cfg = {
|
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "f24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
|
|
|
"repo": [
|
|
|
|
"Everything",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
self.compose.conf["cts_url"] = "http://cts.localhost"
|
|
|
|
self._setupMock(KojiWrapper)
|
|
|
|
self._assertConfigCorrect(cfg)
|
|
|
|
|
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
|
|
|
|
|
|
|
cts_url = "http://cts.localhost/api/1/composes/%s" % self.compose.compose_id
|
|
|
|
options = {
|
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"yum_repourls": [
|
|
|
|
"%s/repo/?variant=Server" % cts_url,
|
|
|
|
"%s/repo/?variant=Everything" % cts_url,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
self._assertCorrectCalls(options)
|
|
|
|
self._assertCorrectMetadata()
|
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.get_file_from_scm")
|
2019-02-07 13:17:09 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2021-09-09 05:58:32 +00:00
|
|
|
def test_run_with_deprecated_registry(self, KojiWrapper, get_file_from_scm):
|
2019-02-07 13:17:09 +00:00
|
|
|
cfg = {
|
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "f24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
|
|
|
"repo": ["Everything", "http://pkgs.example.com/my.repo"],
|
|
|
|
"registry": {"foo": "bar"},
|
|
|
|
}
|
|
|
|
self._setupMock(KojiWrapper)
|
|
|
|
self._assertConfigCorrect(cfg)
|
|
|
|
|
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
|
|
|
|
|
|
|
options = {
|
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"yum_repourls": [
|
|
|
|
"http://root/work/global/tmp-Server/compose-rpms-Server-1.repo",
|
|
|
|
"http://root/work/global/tmp-Everything/compose-rpms-Everything-1.repo",
|
|
|
|
"http://pkgs.example.com/my.repo",
|
2020-01-22 10:02:22 +00:00
|
|
|
],
|
2019-02-07 13:17:09 +00:00
|
|
|
}
|
|
|
|
self._assertCorrectCalls(options)
|
|
|
|
self._assertCorrectMetadata()
|
|
|
|
self._assertRepoFile(["Server", "Everything"])
|
|
|
|
self.assertEqual(self.t.pool.registries, {"my-name-1.0-1": {"foo": "bar"}})
|
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.get_file_from_scm")
|
2019-04-05 08:23:37 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2021-09-09 05:58:32 +00:00
|
|
|
def test_run_with_registry(self, KojiWrapper, get_file_from_scm):
|
2019-04-05 08:23:37 +00:00
|
|
|
cfg = {
|
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "f24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
|
|
|
"repo": ["Everything", "http://pkgs.example.com/my.repo"],
|
|
|
|
}
|
|
|
|
self.compose.conf["osbs_registries"] = {"my-name-1.0-*": [{"foo": "bar"}]}
|
|
|
|
self._setupMock(KojiWrapper)
|
|
|
|
self._assertConfigCorrect(cfg)
|
|
|
|
|
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
|
|
|
|
|
|
|
options = {
|
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"yum_repourls": [
|
|
|
|
"http://root/work/global/tmp-Server/compose-rpms-Server-1.repo",
|
|
|
|
"http://root/work/global/tmp-Everything/compose-rpms-Everything-1.repo",
|
|
|
|
"http://pkgs.example.com/my.repo",
|
2020-01-22 10:02:22 +00:00
|
|
|
],
|
2019-04-05 08:23:37 +00:00
|
|
|
}
|
|
|
|
self._assertCorrectCalls(options)
|
|
|
|
self._assertCorrectMetadata()
|
|
|
|
self._assertRepoFile(["Server", "Everything"])
|
|
|
|
self.assertEqual(self.t.pool.registries, {"my-name-1.0-1": [{"foo": "bar"}]})
|
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.get_file_from_scm")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2021-09-09 05:58:32 +00:00
|
|
|
def test_run_with_extra_repos_in_list(self, KojiWrapper, get_file_from_scm):
|
2017-01-04 08:15:27 +00:00
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "f24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
|
|
|
"repo": ["Everything", "Client", "http://pkgs.example.com/my.repo"],
|
2017-01-04 08:15:27 +00:00
|
|
|
}
|
2017-01-04 08:35:31 +00:00
|
|
|
self._assertConfigCorrect(cfg)
|
2018-11-21 09:56:22 +00:00
|
|
|
self._setupMock(KojiWrapper)
|
2017-01-04 08:15:27 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
2017-01-04 08:15:27 +00:00
|
|
|
|
|
|
|
options = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"yum_repourls": [
|
|
|
|
"http://root/work/global/tmp-Server/compose-rpms-Server-1.repo",
|
|
|
|
"http://root/work/global/tmp-Everything/compose-rpms-Everything-1.repo",
|
|
|
|
"http://root/work/global/tmp-Client/compose-rpms-Client-1.repo",
|
|
|
|
"http://pkgs.example.com/my.repo",
|
|
|
|
],
|
2017-01-04 08:15:27 +00:00
|
|
|
}
|
|
|
|
self._assertCorrectCalls(options)
|
|
|
|
self._assertCorrectMetadata()
|
2020-01-22 10:02:22 +00:00
|
|
|
self._assertRepoFile(["Server", "Everything", "Client"])
|
2017-01-04 08:15:27 +00:00
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.get_file_from_scm")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2021-09-09 05:58:32 +00:00
|
|
|
def test_run_with_gpgkey_enabled(self, KojiWrapper, get_file_from_scm):
|
2020-01-22 10:02:22 +00:00
|
|
|
gpgkey = "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release"
|
2017-01-17 04:54:41 +00:00
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "f24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
|
|
|
"repo": ["Everything", "Client", "http://pkgs.example.com/my.repo"],
|
|
|
|
"gpgkey": gpgkey,
|
2017-01-17 04:54:41 +00:00
|
|
|
}
|
|
|
|
self._assertConfigCorrect(cfg)
|
2018-11-21 09:56:22 +00:00
|
|
|
self._setupMock(KojiWrapper)
|
2017-01-17 04:54:41 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
2017-01-17 04:54:41 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self._assertRepoFile(["Server", "Everything", "Client"], gpgkey=gpgkey)
|
2017-01-17 04:54:41 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2018-11-21 09:56:22 +00:00
|
|
|
def test_run_with_extra_repos_missing_variant(self, KojiWrapper):
|
2017-01-04 08:15:27 +00:00
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "f24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"name": "my-name",
|
|
|
|
"version": "1.0",
|
|
|
|
"repo": "Gold",
|
2017-01-04 08:15:27 +00:00
|
|
|
}
|
2017-01-04 08:35:31 +00:00
|
|
|
self._assertConfigCorrect(cfg)
|
2018-11-21 09:56:22 +00:00
|
|
|
self._setupMock(KojiWrapper)
|
2017-01-04 08:15:27 +00:00
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
2017-01-04 08:15:27 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertIn("no variant Gold", str(ctx.exception))
|
2017-01-04 08:15:27 +00:00
|
|
|
|
2017-01-04 08:35:31 +00:00
|
|
|
def test_run_with_missing_url(self):
|
2016-06-20 13:43:55 +00:00
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"target": "f24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"name": "my-name",
|
2016-06-20 13:43:55 +00:00
|
|
|
}
|
2020-01-22 10:02:22 +00:00
|
|
|
self._assertConfigMissing(cfg, "url")
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2017-01-04 08:35:31 +00:00
|
|
|
def test_run_with_missing_target(self):
|
2016-06-20 13:43:55 +00:00
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"name": "my-name",
|
2016-06-20 13:43:55 +00:00
|
|
|
}
|
2020-01-22 10:02:22 +00:00
|
|
|
self._assertConfigMissing(cfg, "target")
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2017-04-24 07:55:24 +00:00
|
|
|
def test_run_with_missing_git_branch(self):
|
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "f24-docker-candidate",
|
2017-04-24 07:55:24 +00:00
|
|
|
}
|
2020-01-22 10:02:22 +00:00
|
|
|
self._assertConfigMissing(cfg, "git_branch")
|
2017-04-24 07:55:24 +00:00
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.get_file_from_scm")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2021-09-09 05:58:32 +00:00
|
|
|
def test_failing_task(self, KojiWrapper, get_file_from_scm):
|
2016-06-20 13:43:55 +00:00
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "fedora-24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
2016-06-20 13:43:55 +00:00
|
|
|
}
|
2017-01-04 08:35:31 +00:00
|
|
|
self._assertConfigCorrect(cfg)
|
2018-11-21 09:56:22 +00:00
|
|
|
self._setupMock(KojiWrapper)
|
2016-06-20 13:43:55 +00:00
|
|
|
self.wrapper.watch_task.return_value = 1
|
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(str(ctx.exception), r"task 12345 failed: see .+ for details")
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.get_file_from_scm")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2021-09-09 05:58:32 +00:00
|
|
|
def test_failing_task_with_failable(self, KojiWrapper, get_file_from_scm):
|
2016-06-20 13:43:55 +00:00
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "fedora-24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"failable": ["*"],
|
2016-06-20 13:43:55 +00:00
|
|
|
}
|
2017-01-04 08:35:31 +00:00
|
|
|
self._assertConfigCorrect(cfg)
|
2018-11-21 09:56:22 +00:00
|
|
|
self._setupMock(KojiWrapper)
|
2016-06-20 13:43:55 +00:00
|
|
|
self.wrapper.watch_task.return_value = 1
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2021-09-09 05:58:32 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.get_file_from_scm")
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
2021-09-09 05:58:32 +00:00
|
|
|
def test_scratch_metadata(self, KojiWrapper, get_file_from_scm):
|
2016-06-20 13:43:55 +00:00
|
|
|
cfg = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"url": "git://example.com/repo?#BEEFCAFE",
|
|
|
|
"target": "f24-docker-candidate",
|
|
|
|
"git_branch": "f24-docker",
|
|
|
|
"scratch": True,
|
2016-06-20 13:43:55 +00:00
|
|
|
}
|
2018-11-21 09:56:22 +00:00
|
|
|
self._setupMock(KojiWrapper, scratch=True)
|
2017-01-04 08:35:31 +00:00
|
|
|
self._assertConfigCorrect(cfg)
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.t.process((self.compose, self.compose.variants["Server"], cfg), 1)
|
2016-06-20 13:43:55 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self._assertCorrectCalls({"git_branch": "f24-docker"}, scratch=True)
|
2017-03-02 13:10:16 +00:00
|
|
|
self._assertCorrectMetadata(scratch=True)
|
|
|
|
self._assertRepoFile()
|