kojiwrapper: Stop being smart about local access

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ář <lsedlar@redhat.com>
(cherry picked from commit 0d3cd150bd)
This commit is contained in:
Lubomír Sedlář 2023-07-19 11:47:17 +02:00 committed by Stepan Oksanichenko
parent ce45fdc39a
commit 68d94ff488
Signed by: soksanichenko
GPG Key ID: AB9983172AB1E45B
3 changed files with 22 additions and 9 deletions

View File

@ -194,7 +194,7 @@ class PkgsetSourceKoji(pungi.phases.pkgset.source.PkgsetSourceBase):
compose = self.compose compose = self.compose
self.koji_wrapper = pungi.wrappers.kojiwrapper.KojiWrapper(compose) self.koji_wrapper = pungi.wrappers.kojiwrapper.KojiWrapper(compose)
package_sets = get_pkgset_from_koji(self.compose, self.koji_wrapper) 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): def get_pkgset_from_koji(compose, koji_wrapper):
@ -920,7 +920,7 @@ def populate_global_pkgset(compose, koji_wrapper, event):
MaterializedPackageSet.create, MaterializedPackageSet.create,
compose, compose,
pkgset, pkgset,
compose.koji_downloader.cache_dir, compose.koji_downloader.path_prefix,
mmd=tag_to_mmd.get(pkgset.name), mmd=tag_to_mmd.get(pkgset.name),
) )
) )

View File

@ -945,6 +945,12 @@ def get_buildroot_rpms(compose, task_id):
class KojiDownloadProxy: class KojiDownloadProxy:
def __init__(self, topdir, topurl, cache_dir, logger): def __init__(self, topdir, topurl, cache_dir, logger):
if not topdir: 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 self.has_local_access = True
return return
@ -954,7 +960,9 @@ class KojiDownloadProxy:
self.topdir = topdir self.topdir = topdir
self.topurl = topurl 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 # This is used for temporary downloaded files. The suffix is unique
# per-process. To prevent threads in the same process from colliding, a # per-process. To prevent threads in the same process from colliding, a
# thread id is added later. # thread id is added later.
@ -963,20 +971,25 @@ class KojiDownloadProxy:
if not self.has_local_access: if not self.has_local_access:
self.session = requests.Session() 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 @classmethod
def from_config(klass, conf, logger): def from_config(klass, conf, logger):
topdir = None topdir = None
topurl = None topurl = None
path_prefix = None cache_dir = None
if "koji_profile" in conf: if "koji_profile" in conf:
koji_module = koji.get_profile_module(conf["koji_profile"]) koji_module = koji.get_profile_module(conf["koji_profile"])
topdir = koji_module.config.topdir topdir = koji_module.config.topdir
topurl = koji_module.config.topurl topurl = koji_module.config.topurl
path_prefix = topdir.rstrip("/") + "/" cache_dir = conf.get("koji_cache")
if not os.path.exists(path_prefix): if cache_dir:
path_prefix = conf["koji_cache"].rstrip("/") + "/" cache_dir = cache_dir.rstrip("/") + "/"
return klass(topdir, topurl, path_prefix, logger) return klass(topdir, topurl, cache_dir, logger)
@util.retry(wait_on=requests.exceptions.RequestException) @util.retry(wait_on=requests.exceptions.RequestException)
def _download(self, url, dest): def _download(self, url, dest):

View File

@ -256,7 +256,7 @@ class DummyCompose(object):
self.containers_metadata = {} self.containers_metadata = {}
self.load_old_compose_config = mock.Mock(return_value=None) self.load_old_compose_config = mock.Mock(return_value=None)
self.koji_downloader = DummyKojiDownloader() self.koji_downloader = DummyKojiDownloader()
self.koji_downloader.cache_dir = "/prefix" self.koji_downloader.path_prefix = "/prefix"
def setup_optional(self): def setup_optional(self):
self.all_variants["Server-optional"] = MockVariant( self.all_variants["Server-optional"] = MockVariant(