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>
This commit is contained in:
parent
aa0aae3d3e
commit
0d3cd150bd
@ -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),
|
||||
)
|
||||
)
|
||||
|
@ -905,6 +905,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
|
||||
|
||||
@ -914,7 +920,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.
|
||||
@ -923,20 +931,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):
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user