osbuild: don't use util.get_repo_urls()
Don't use `util.get_repo_urls()` to resolve provided repositories, but implement osbuild-specific variant of the function named `_get_repo_urls(). The reason is that the function from `utils` transforms repositories defined as dicts to strings, which is undesired for osbuild. The requirement for osbuild is to preserve the dict as is, just to resolve the string in `baseurl` to the actual repository URL. Add a unit test covering the newly added function. It is inspired by a similar test from `test_util.py`. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
parent
ef6d40dce4
commit
e3072c3d5f
@ -27,6 +27,35 @@ class OSBuildPhase(
|
||||
arches = set(image_conf["arches"]) & arches
|
||||
return sorted(arches)
|
||||
|
||||
@staticmethod
|
||||
def _get_repo_urls(compose, repos, arch="$basearch"):
|
||||
"""
|
||||
Get list of repos with resolved repo URLs. Preserve repos defined
|
||||
as dicts.
|
||||
"""
|
||||
resolved_repos = []
|
||||
|
||||
for repo in repos:
|
||||
if isinstance(repo, dict):
|
||||
try:
|
||||
url = repo["baseurl"]
|
||||
except KeyError:
|
||||
raise RuntimeError(
|
||||
"`baseurl` is required in repo dict %s" % str(repo)
|
||||
)
|
||||
url = util.get_repo_url(compose, url, arch=arch)
|
||||
if url is None:
|
||||
raise RuntimeError("Failed to resolve repo URL for %s" % str(repo))
|
||||
repo["baseurl"] = url
|
||||
resolved_repos.append(repo)
|
||||
else:
|
||||
repo = util.get_repo_url(compose, repo, arch=arch)
|
||||
if repo is None:
|
||||
raise RuntimeError("Failed to resolve repo URL for %s" % repo)
|
||||
resolved_repos.append(repo)
|
||||
|
||||
return resolved_repos
|
||||
|
||||
def _get_repo(self, image_conf, variant):
|
||||
"""
|
||||
Get a list of repos. First included are those explicitly listed in
|
||||
@ -38,7 +67,7 @@ class OSBuildPhase(
|
||||
if not variant.is_empty and variant.uid not in repos:
|
||||
repos.append(variant.uid)
|
||||
|
||||
return util.get_repo_urls(self.compose, repos, arch="$arch")
|
||||
return OSBuildPhase._get_repo_urls(self.compose, repos, arch="$arch")
|
||||
|
||||
def run(self):
|
||||
for variant in self.compose.get_variants():
|
||||
|
@ -3,14 +3,76 @@
|
||||
import mock
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import koji as orig_koji
|
||||
|
||||
from tests import helpers
|
||||
from pungi import compose
|
||||
from pungi.phases import osbuild
|
||||
from pungi.checks import validate
|
||||
|
||||
|
||||
class OSBuildPhaseHelperFuncsTest(unittest.TestCase):
|
||||
@mock.patch("pungi.compose.ComposeInfo")
|
||||
def setUp(self, ci):
|
||||
self.tmp_dir = tempfile.mkdtemp()
|
||||
conf = {"translate_paths": [(self.tmp_dir, "http://example.com")]}
|
||||
ci.return_value.compose.respin = 0
|
||||
ci.return_value.compose.id = "RHEL-8.0-20180101.n.0"
|
||||
ci.return_value.compose.date = "20160101"
|
||||
ci.return_value.compose.type = "nightly"
|
||||
ci.return_value.compose.type_suffix = ".n"
|
||||
ci.return_value.compose.label = "RC-1.0"
|
||||
ci.return_value.compose.label_major_version = "1"
|
||||
|
||||
compose_dir = os.path.join(self.tmp_dir, ci.return_value.compose.id)
|
||||
self.compose = compose.Compose(conf, compose_dir)
|
||||
server_variant = mock.Mock(uid="Server", type="variant")
|
||||
client_variant = mock.Mock(uid="Client", type="variant")
|
||||
self.compose.all_variants = {
|
||||
"Server": server_variant,
|
||||
"Client": client_variant,
|
||||
}
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.tmp_dir)
|
||||
|
||||
def test__get_repo_urls(self):
|
||||
repos = [
|
||||
"http://example.com/repo",
|
||||
"Server",
|
||||
{
|
||||
"baseurl": "Client",
|
||||
"package_sets": ["build"],
|
||||
},
|
||||
{
|
||||
"baseurl": "ftp://example.com/linux/repo",
|
||||
"package_sets": ["build"],
|
||||
},
|
||||
]
|
||||
|
||||
expect = [
|
||||
"http://example.com/repo",
|
||||
"http://example.com/RHEL-8.0-20180101.n.0/compose/Server/$basearch/os",
|
||||
{
|
||||
"baseurl": "http://example.com/RHEL-8.0-20180101.n.0/compose/Client/"
|
||||
+ "$basearch/os",
|
||||
"package_sets": ["build"],
|
||||
},
|
||||
{
|
||||
"baseurl": "ftp://example.com/linux/repo",
|
||||
"package_sets": ["build"],
|
||||
},
|
||||
]
|
||||
|
||||
self.assertEqual(
|
||||
osbuild.OSBuildPhase._get_repo_urls(self.compose, repos), expect
|
||||
)
|
||||
|
||||
|
||||
class OSBuildPhaseTest(helpers.PungiTestCase):
|
||||
@mock.patch("pungi.phases.osbuild.ThreadPool")
|
||||
def test_run(self, ThreadPool):
|
||||
|
Loading…
Reference in New Issue
Block a user