From 68d94ff488c81a5fb052e8e1ab36d86abd37b619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 19 Jul 2023 11:47:17 +0200 Subject: [PATCH] kojiwrapper: Stop being smart about local access MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rather than trying to use local access when it's accessible, let user make the decision: * if koji_cache is configured use it and download stuff * if not, fall back to local access Signed-off-by: Lubomír Sedlář (cherry picked from commit 0d3cd150bd7d96007d6409df3ec2abe88670fcb0) --- pungi/phases/pkgset/sources/source_koji.py | 4 ++-- pungi/wrappers/kojiwrapper.py | 25 ++++++++++++++++------ tests/helpers.py | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pungi/phases/pkgset/sources/source_koji.py b/pungi/phases/pkgset/sources/source_koji.py index 6c05e353..e15c8d08 100644 --- a/pungi/phases/pkgset/sources/source_koji.py +++ b/pungi/phases/pkgset/sources/source_koji.py @@ -194,7 +194,7 @@ class PkgsetSourceKoji(pungi.phases.pkgset.source.PkgsetSourceBase): compose = self.compose self.koji_wrapper = pungi.wrappers.kojiwrapper.KojiWrapper(compose) package_sets = get_pkgset_from_koji(self.compose, self.koji_wrapper) - return (package_sets, self.compose.koji_downloader.cache_dir) + return (package_sets, self.compose.koji_downloader.path_prefix) def get_pkgset_from_koji(compose, koji_wrapper): @@ -920,7 +920,7 @@ def populate_global_pkgset(compose, koji_wrapper, event): MaterializedPackageSet.create, compose, pkgset, - compose.koji_downloader.cache_dir, + compose.koji_downloader.path_prefix, mmd=tag_to_mmd.get(pkgset.name), ) ) diff --git a/pungi/wrappers/kojiwrapper.py b/pungi/wrappers/kojiwrapper.py index 889b80dc..1b3f21ae 100644 --- a/pungi/wrappers/kojiwrapper.py +++ b/pungi/wrappers/kojiwrapper.py @@ -945,6 +945,12 @@ def get_buildroot_rpms(compose, task_id): class KojiDownloadProxy: def __init__(self, topdir, topurl, cache_dir, logger): if not topdir: + # This will only happen if there is either no koji_profile + # configured, or the profile doesn't have a topdir. In the first + # case there will be no koji interaction, and the second indicates + # broken koji configuration. + # We can pretend to have local access in both cases to avoid any + # external requests. self.has_local_access = True return @@ -954,7 +960,9 @@ class KojiDownloadProxy: self.topdir = topdir self.topurl = topurl - self.has_local_access = os.path.isdir(self.topdir) + # If cache directory is configured, we want to use it (even if we + # actually have local access to the storage). + self.has_local_access = not bool(cache_dir) # This is used for temporary downloaded files. The suffix is unique # per-process. To prevent threads in the same process from colliding, a # thread id is added later. @@ -963,20 +971,25 @@ class KojiDownloadProxy: if not self.has_local_access: self.session = requests.Session() + @property + def path_prefix(self): + dir = self.topdir if self.has_local_access else self.cache_dir + return dir.rstrip("/") + "/" + @classmethod def from_config(klass, conf, logger): topdir = None topurl = None - path_prefix = None + cache_dir = None if "koji_profile" in conf: koji_module = koji.get_profile_module(conf["koji_profile"]) topdir = koji_module.config.topdir topurl = koji_module.config.topurl - path_prefix = topdir.rstrip("/") + "/" - if not os.path.exists(path_prefix): - path_prefix = conf["koji_cache"].rstrip("/") + "/" - return klass(topdir, topurl, path_prefix, logger) + cache_dir = conf.get("koji_cache") + if cache_dir: + cache_dir = cache_dir.rstrip("/") + "/" + return klass(topdir, topurl, cache_dir, logger) @util.retry(wait_on=requests.exceptions.RequestException) def _download(self, url, dest): diff --git a/tests/helpers.py b/tests/helpers.py index 00035c8a..6d3cb30e 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -256,7 +256,7 @@ class DummyCompose(object): self.containers_metadata = {} self.load_old_compose_config = mock.Mock(return_value=None) self.koji_downloader = DummyKojiDownloader() - self.koji_downloader.cache_dir = "/prefix" + self.koji_downloader.path_prefix = "/prefix" def setup_optional(self): self.all_variants["Server-optional"] = MockVariant(