From 210705e7015b4a150ae8c4555728d6cc584d78ce Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Mon, 30 Oct 2023 15:41:11 +0100 Subject: [PATCH] Revert "Reduce verbosity in mirrors.yaml (#34210)" This reverts commit 7659912dc40bc42df3eb108471974260b3e3b6e8. --- lib/spack/spack/ci.py | 10 ++-------- lib/spack/spack/cmd/ci.py | 10 ++++------ lib/spack/spack/cmd/mirror.py | 21 +-------------------- lib/spack/spack/mirror.py | 25 +++++++++++++++++-------- 4 files changed, 24 insertions(+), 42 deletions(-) diff --git a/lib/spack/spack/ci.py b/lib/spack/spack/ci.py index 320812cb638..154f73ef384 100644 --- a/lib/spack/spack/ci.py +++ b/lib/spack/spack/ci.py @@ -911,19 +911,13 @@ def generate_gitlab_ci_yaml( # --check-index-only, then the override mirror needs to be added to # the configured mirrors when bindist.update() is run, or else we # won't fetch its index and include in our local cache. - spack.mirror.add( - spack.mirror.Mirror(remote_mirror_override, name="ci_pr_mirror"), - cfg.default_modify_scope(), - ) + spack.mirror.add("ci_pr_mirror", remote_mirror_override, cfg.default_modify_scope()) shared_pr_mirror = None if spack_pipeline_type == "spack_pull_request": stack_name = os.environ.get("SPACK_CI_STACK_NAME", "") shared_pr_mirror = url_util.join(SHARED_PR_MIRROR_URL, stack_name) - spack.mirror.add( - spack.mirror.Mirror(shared_pr_mirror, name="ci_shared_pr_mirror"), - cfg.default_modify_scope(), - ) + spack.mirror.add("ci_shared_pr_mirror", shared_pr_mirror, cfg.default_modify_scope()) pipeline_artifacts_dir = artifacts_root if not pipeline_artifacts_dir: diff --git a/lib/spack/spack/cmd/ci.py b/lib/spack/spack/cmd/ci.py index 42d61d438ab..2834cbea323 100644 --- a/lib/spack/spack/cmd/ci.py +++ b/lib/spack/spack/cmd/ci.py @@ -449,8 +449,9 @@ def ci_rebuild(args): # mirror now so it's used when we check for a hash match already # built for this spec. if pipeline_mirror_url: - mirror = spack.mirror.Mirror(pipeline_mirror_url, name=spack_ci.TEMP_STORAGE_MIRROR_NAME) - spack.mirror.add(mirror, cfg.default_modify_scope()) + spack.mirror.add( + spack_ci.TEMP_STORAGE_MIRROR_NAME, pipeline_mirror_url, cfg.default_modify_scope() + ) pipeline_mirrors.append(pipeline_mirror_url) # Check configured mirrors for a built spec with a matching hash @@ -465,10 +466,7 @@ def ci_rebuild(args): # could be installed from either the override mirror or any other configured # mirror (e.g. remote_mirror_url which is defined in the environment or # pipeline_mirror_url), which is also what we want. - spack.mirror.add( - spack.mirror.Mirror(remote_mirror_override, name="mirror_override"), - cfg.default_modify_scope(), - ) + spack.mirror.add("mirror_override", remote_mirror_override, cfg.default_modify_scope()) pipeline_mirrors.append(remote_mirror_override) if spack_pipeline_type == "spack_pull_request": diff --git a/lib/spack/spack/cmd/mirror.py b/lib/spack/spack/cmd/mirror.py index 582627cbe26..d444616fa74 100644 --- a/lib/spack/spack/cmd/mirror.py +++ b/lib/spack/spack/cmd/mirror.py @@ -145,26 +145,7 @@ def setup_parser(subparser): def mirror_add(args): """Add a mirror to Spack.""" - if ( - args.s3_access_key_id - or args.s3_access_key_secret - or args.s3_access_token - or args.s3_profile - or args.s3_endpoint_url - ): - connection = {"url": args.url} - if args.s3_access_key_id and args.s3_access_key_secret: - connection["access_pair"] = (args.s3_access_key_id, args.s3_access_key_secret) - if args.s3_access_token: - connection["access_token"] = args.s3_access_token - if args.s3_profile: - connection["profile"] = args.s3_profile - if args.s3_endpoint_url: - connection["endpoint_url"] = args.s3_endpoint_url - mirror = spack.mirror.Mirror(fetch_url=connection, push_url=connection, name=args.name) - else: - mirror = spack.mirror.Mirror(args.url, name=args.name) - spack.mirror.add(mirror, args.scope) + spack.mirror.add(args.name, args.url, args.scope, args) def mirror_remove(args): diff --git a/lib/spack/spack/mirror.py b/lib/spack/spack/mirror.py index f81cf6fd880..ed6eff39d29 100644 --- a/lib/spack/spack/mirror.py +++ b/lib/spack/spack/mirror.py @@ -114,10 +114,6 @@ def from_url(url: str): return Mirror(fetch_url=url) def to_dict(self): - # Keep it a key-value pair : when possible. - if isinstance(self._fetch_url, str) and self._push_url is None: - return self._fetch_url - if self._push_url is None: return syaml_dict([("fetch", self._fetch_url), ("push", self._fetch_url)]) else: @@ -552,17 +548,30 @@ def mirror_cache_and_stats(path, skip_unstable_versions=False): return mirror_cache, mirror_stats -def add(mirror: Mirror, scope=None): +def add(name, url, scope, args={}): """Add a named mirror in the given scope""" mirrors = spack.config.get("mirrors", scope=scope) if not mirrors: mirrors = syaml_dict() - if mirror.name in mirrors: - tty.die("Mirror with name {} already exists.".format(mirror.name)) + if name in mirrors: + tty.die("Mirror with name %s already exists." % name) items = [(n, u) for n, u in mirrors.items()] - items.insert(0, (mirror.name, mirror.to_dict())) + mirror_data = url + key_values = ["s3_access_key_id", "s3_access_token", "s3_profile"] + # On creation, assume connection data is set for both + if any(value for value in key_values if value in args): + url_dict = { + "url": url, + "access_pair": (args.s3_access_key_id, args.s3_access_key_secret), + "access_token": args.s3_access_token, + "profile": args.s3_profile, + "endpoint_url": args.s3_endpoint_url, + } + mirror_data = {"fetch": url_dict, "push": url_dict} + + items.insert(0, (name, mirror_data)) mirrors = syaml_dict(items) spack.config.set("mirrors", mirrors, scope=scope)