alibuild 2.0.0__tar.gz → 2.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {alibuild-2.0.0 → alibuild-2.0.2}/PKG-INFO +1 -1
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild.egg-info/PKG-INFO +1 -1
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/_version.py +3 -3
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/build.py +1 -1
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/log.py +17 -1
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/reconstruct.py +48 -6
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/sync.py +20 -1
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/sync_reapi.py +40 -18
- {alibuild-2.0.0 → alibuild-2.0.2}/alienv +22 -6
- alibuild-2.0.2/tests/test_log.py +90 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_reconstruct.py +60 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_sync.py +47 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_sync_reapi.py +109 -3
- alibuild-2.0.0/tests/test_log.py +0 -50
- {alibuild-2.0.0 → alibuild-2.0.2}/.claude/skills/s3-conditional-writes/SKILL.md +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/.claude/skills/support-architecture/SKILL.md +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/.flake8 +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/.github/dependabot.yml +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/.github/workflows/documentation.yml +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/.github/workflows/homebrew.yml +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/.github/workflows/pr-check.yml +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/.github/workflows/release.yml +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/.gitignore +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/.pylintrc +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/ANALYTICS.md +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/DESIGN.md +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/LICENSE.md +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/PACKAGING.md +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/README.rst +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/REMOTE_STORE_CAS_AC.md +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alfaBuild +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/aliBuild +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/aliDeps +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/aliDoctor +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild.egg-info/SOURCES.txt +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild.egg-info/dependency_links.txt +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild.egg-info/requires.txt +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild.egg-info/top_level.txt +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/__init__.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/analytics.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/args.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/build_template.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/clean.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/cmd.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/completion.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/completions/__init__.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/completions/bash.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/completions/zsh.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/deps.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/doctor.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/git.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/init.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/install.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/keyring.json +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/migrate.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/sandbox.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/scm.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/signing.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/sl.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/source.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/templating_plugin.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/utilities.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/alibuild_helpers/workarea.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/codecov.yml +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/debian/changelog +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/debian/compat +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/debian/control +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/debian/copyright +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/debian/files +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/debian/rules +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/docs/SUPPORT +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/docs/docs/alice_logo.png +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/docs/docs/deps.png +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/docs/docs/index.md +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/docs/docs/quick.md +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/docs/docs/reference.md +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/docs/docs/stylesheets/extra.css +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/docs/docs/troubleshooting.md +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/docs/docs/user.md +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/docs/mkdocs.yml +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/extras/nix/alibuild_nix.jnj +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/extras/nix/alidist-aliphysics.nix +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/extras/nix/alidist-helpers.nix +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/extras/nix/alidist.nix +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/extras/nix/flake.lock +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/extras/nix/flake.nix +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/extras/nix/hyperloop.nix +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/extras/nix/hyperloopTest.nix +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/extras/nix/nix-interactive.bash +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/extras/nix/update-envs.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/pb +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/pyproject.toml +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/requirements.txt +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/setup.cfg +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/setup.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/templates/alibuild_nix.jnj +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/templates/alibuild_to_please.jnj +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_analytics.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_args.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_build.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_clean.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_cmd.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_completion.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_deps.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_doctor.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_git.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_hashing.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_init.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_install.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_migrate.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_packagelist.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_parseRecipe.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_sandbox.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_signing.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_source.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_utilities.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/test_workarea.py +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/testdist/broken1.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/testdist/broken2.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/testdist/broken3.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/testdist/broken4.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/testdist/broken5.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/testdist/broken6.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/testdist/broken7.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/testdist/clobber-initdotsh.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/testdist/defaults-o2.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/testdist/delete-etc.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tests/testdist/tracking-env.sh +0 -0
- {alibuild-2.0.0 → alibuild-2.0.2}/tox.ini +0 -0
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '2.0.
|
|
32
|
-
__version_tuple__ = version_tuple = (2, 0,
|
|
31
|
+
__version__ = version = '2.0.2'
|
|
32
|
+
__version_tuple__ = version_tuple = (2, 0, 2)
|
|
33
33
|
|
|
34
|
-
__commit_id__ = commit_id = '
|
|
34
|
+
__commit_id__ = commit_id = 'g523c3af01'
|
|
@@ -1382,7 +1382,7 @@ def doBuild(args, parser):
|
|
|
1382
1382
|
published = True
|
|
1383
1383
|
if fileHash == spec["hash"] and not spec["is_devel_pkg"] and \
|
|
1384
1384
|
isinstance(syncHelper, REAPIRemoteSync) and getattr(syncHelper, "writeStore", ""):
|
|
1385
|
-
published = syncHelper.is_published(spec["remote_revision_hash"])
|
|
1385
|
+
published = syncHelper.is_published(spec["remote_revision_hash"], keep_alive=True)
|
|
1386
1386
|
if not published:
|
|
1387
1387
|
bound_unpublished_rebuild(p, rebuilt_unpublished, syncHelper.acWriteStore)
|
|
1388
1388
|
info("%s is built locally but not published to %s; rebuilding it so it can "
|
|
@@ -10,6 +10,22 @@ def dieOnError(err, msg) -> None:
|
|
|
10
10
|
error("%s", msg)
|
|
11
11
|
sys.exit(1)
|
|
12
12
|
|
|
13
|
+
# Credentials reach the log through command lines: the docker invocation carries
|
|
14
|
+
# every -e NAME=VALUE, and CI passes JALIEN_TOKEN_KEY (a PEM private key) and
|
|
15
|
+
# CCDB auth tokens that way. The value may be shell-quoted or, where the command
|
|
16
|
+
# is " ".join()ed, bare and spanning several lines. A key whose END marker is
|
|
17
|
+
# not in the same message is redacted to the end of the message.
|
|
18
|
+
_PRIVATE_KEY_RE = re.compile(
|
|
19
|
+
r"-----BEGIN ([A-Z ]*)PRIVATE KEY-----.*?(?:-----END \1PRIVATE KEY-----|\Z)", re.DOTALL)
|
|
20
|
+
_SECRET_ASSIGNMENT_RE = re.compile(
|
|
21
|
+
r"\b([A-Za-z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD)[A-Za-z0-9_]*=)"
|
|
22
|
+
r"('[^']*'|\"[^\"]*\"|[^\s'\"]+)")
|
|
23
|
+
|
|
24
|
+
def redact_secrets(msg):
|
|
25
|
+
"""Hide private keys and the values of *TOKEN*/*SECRET*/*PASSWORD* assignments."""
|
|
26
|
+
msg = _PRIVATE_KEY_RE.sub(r"-----BEGIN \1PRIVATE KEY----- <redacted>", msg)
|
|
27
|
+
return _SECRET_ASSIGNMENT_RE.sub(r"\1<redacted>", msg)
|
|
28
|
+
|
|
13
29
|
class LogFormatter(logging.Formatter):
|
|
14
30
|
def __init__(self, fmtstr) -> None:
|
|
15
31
|
self.fmtstr = fmtstr
|
|
@@ -25,7 +41,7 @@ class LogFormatter(logging.Formatter):
|
|
|
25
41
|
# args to an already-expanded string -- "not all arguments converted".
|
|
26
42
|
# Harmless with only our handler attached, which is why it went unnoticed;
|
|
27
43
|
# under pytest, whose logging plugin adds its own handler, it aborts.
|
|
28
|
-
msg = record.getMessage()
|
|
44
|
+
msg = redact_secrets(record.getMessage())
|
|
29
45
|
if record.levelno == logging.BANNER and sys.stdout.isatty():
|
|
30
46
|
lines = msg.split("\n")
|
|
31
47
|
return "\n\033[1;34m==>\033[m \033[1m%s\033[m" % lines[0] + \
|
|
@@ -93,6 +93,25 @@ def add_parser(subparsers, detected_arch, work_dir_default):
|
|
|
93
93
|
choices=("ephemeral", "permanent"),
|
|
94
94
|
help="Retention tag for a blob restored by --persist. Default '%(default)s' (a "
|
|
95
95
|
"deliberately reconstructed blob should not be LRU-expired).")
|
|
96
|
+
# Publishing options, spelt as `aliBuild build` spells them: --rebaseline --apply
|
|
97
|
+
# rewrites the legacy store object and link, and the AC entry it re-signs.
|
|
98
|
+
p.add_argument("--legacy-links-store", dest="legacyStore", default="", metavar="STORE",
|
|
99
|
+
help="As for 'aliBuild build': where the legacy TARS/<arch>/ links and "
|
|
100
|
+
"store objects live, if not in the artifact store.")
|
|
101
|
+
p.add_argument("--cas-public-url", dest="casPublicUrl", default="", metavar="URL",
|
|
102
|
+
help="As for 'aliBuild build': public base URL of the CAS bucket, which "
|
|
103
|
+
"the store objects in --legacy-links-store redirect to.")
|
|
104
|
+
p.add_argument("--sign-url", dest="signUrl", default="", metavar="URL",
|
|
105
|
+
help="Security-proxy sign route for the re-baselined AC entry. "
|
|
106
|
+
"--rebaseline --apply requires it unless --no-sign.")
|
|
107
|
+
p.add_argument("--sign-token", dest="signToken", default="", metavar="TOKEN",
|
|
108
|
+
help="Gate token presented to --sign-url.")
|
|
109
|
+
p.add_argument("--sign-token-file", dest="signTokenFile", default="", metavar="FILE",
|
|
110
|
+
help="Read the credential for --sign-url from FILE, for every request.")
|
|
111
|
+
p.add_argument("--signer", dest="signer", default="alibuild", metavar="NAME",
|
|
112
|
+
help="Signer label recorded in the signature. Default '%(default)s'.")
|
|
113
|
+
p.add_argument("--no-sign", dest="noSign", action="store_true",
|
|
114
|
+
help="Re-baseline without signing: the AC entry is left unsigned.")
|
|
96
115
|
return p
|
|
97
116
|
|
|
98
117
|
|
|
@@ -456,9 +475,12 @@ def verify_rebuild(args, sync, closure, build_runner=None):
|
|
|
456
475
|
or defaults_from_closure(sync, closure) or "release")
|
|
457
476
|
|
|
458
477
|
# Read-only remote store (no ::rw) => dependencies are fetched and reused,
|
|
459
|
-
# nothing is uploaded.
|
|
460
|
-
#
|
|
461
|
-
#
|
|
478
|
+
# nothing is uploaded. The action hash and the revision are in the tarball
|
|
479
|
+
# (.meta.json, init.sh, relocate-me.sh), so a rebuild can only reproduce the
|
|
480
|
+
# recorded bytes under the recorded ones: a missing blob is rebuilt anyway, and
|
|
481
|
+
# with the legacy links in view the recorded revision is reused. Only a present
|
|
482
|
+
# blob needs --force-rebuild, which randomises the hash and takes a localN
|
|
483
|
+
# revision, so that rebuild never matches. Propagate -d so the rebuild
|
|
462
484
|
# streams a debug build log when reconstruct is run with --debug (-d is a
|
|
463
485
|
# global flag, so it must precede the "build" subcommand).
|
|
464
486
|
# Re-invoke through the *same interpreter*, not just the same script: executing
|
|
@@ -476,10 +498,14 @@ def verify_rebuild(args, sync, closure, build_runner=None):
|
|
|
476
498
|
# dependency (e.g. alibuild-recipe-tools under the cwd) would otherwise
|
|
477
499
|
# be picked up as a development package -- rebuilt from local sources and,
|
|
478
500
|
# worse, disabling the remote write store for the whole build.
|
|
479
|
-
"--force-tracked",
|
|
480
|
-
|
|
501
|
+
"--force-tracked", "--defaults", defaults]
|
|
502
|
+
if sync.artifact_blob_exists(recorded_hash, algo):
|
|
503
|
+
cmd += ["--force-rebuild", args.package]
|
|
481
504
|
if ac_store:
|
|
482
505
|
cmd += ["--ac-store", ac_store]
|
|
506
|
+
if getattr(args, "legacyStore", ""):
|
|
507
|
+
cmd += ["--legacy-links-store", args.legacyStore,
|
|
508
|
+
"--cas-public-url", args.casPublicUrl]
|
|
483
509
|
if getattr(args, "insecure", False):
|
|
484
510
|
cmd += ["--insecure"]
|
|
485
511
|
if os.path.isdir(reference_dir):
|
|
@@ -686,10 +712,26 @@ def doReconstruct(args, parser):
|
|
|
686
712
|
ac_store = (getattr(args, "acStore", "") or "").rstrip()
|
|
687
713
|
if ac_store.endswith("::rw"):
|
|
688
714
|
ac_store = ac_store[:-4]
|
|
715
|
+
# A re-baseline changes the digest the AC entry's signature covers, so it must
|
|
716
|
+
# re-sign it: refuse to write without a way to, as `aliBuild build` does.
|
|
717
|
+
no_sign = getattr(args, "noSign", False)
|
|
718
|
+
dieOnError(getattr(args, "rebaseline", False) and getattr(args, "apply", False) and
|
|
719
|
+
not no_sign and not (getattr(args, "signUrl", "") and
|
|
720
|
+
(getattr(args, "signToken", "") or
|
|
721
|
+
getattr(args, "signTokenFile", ""))),
|
|
722
|
+
"--rebaseline --apply re-signs the rewritten Action Cache entry: pass "
|
|
723
|
+
"--sign-url and --sign-token (or --sign-token-file), or --no-sign to "
|
|
724
|
+
"leave it unsigned.")
|
|
689
725
|
sync = remote_from_url(args.remoteStore, args.remoteStore, args.architecture,
|
|
690
726
|
args.workDir, getattr(args, "insecure", False),
|
|
691
727
|
ac_url=ac_store, ac_write_url=ac_store,
|
|
692
|
-
storage=getattr(args, "storage", "permanent")
|
|
728
|
+
storage=getattr(args, "storage", "permanent"),
|
|
729
|
+
sign_url="" if no_sign else getattr(args, "signUrl", ""),
|
|
730
|
+
sign_token=getattr(args, "signToken", ""),
|
|
731
|
+
sign_token_file=getattr(args, "signTokenFile", ""),
|
|
732
|
+
signer=getattr(args, "signer", "alibuild"),
|
|
733
|
+
legacy_url=getattr(args, "legacyStore", ""),
|
|
734
|
+
cas_public_url=getattr(args, "casPublicUrl", ""))
|
|
693
735
|
dieOnError(not isinstance(sync, REAPIRemoteSync),
|
|
694
736
|
"'aliBuild reconstruct' requires a reapi:// remote store, but got %r" %
|
|
695
737
|
(args.remoteStore or "(none)"))
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Sync backends for alibuild."""
|
|
2
2
|
|
|
3
3
|
import glob
|
|
4
|
+
import hashlib
|
|
4
5
|
import os
|
|
5
6
|
import os.path
|
|
6
7
|
import re
|
|
@@ -93,6 +94,7 @@ class HttpRemoteSync:
|
|
|
93
94
|
# Destination specified -- file (dest) or buffer (returnResult).
|
|
94
95
|
# Use requests in stream mode
|
|
95
96
|
resp = get(url, stream=True, verify=not self.insecure, timeout=self.httpTimeoutSec)
|
|
97
|
+
cas_digest = None
|
|
96
98
|
if redirect_base:
|
|
97
99
|
# S3 only turns x-amz-website-redirect-location into a 301 when the
|
|
98
100
|
# bucket is served as a website; on the REST endpoint the object is
|
|
@@ -115,6 +117,16 @@ class HttpRemoteSync:
|
|
|
115
117
|
debug("Following store redirect to %s", url)
|
|
116
118
|
resp = get(url, stream=True, verify=not self.insecure,
|
|
117
119
|
timeout=self.httpTimeoutSec)
|
|
120
|
+
# A content-addressed target names its own digest: check against it.
|
|
121
|
+
cas_digest = re.search(r"(?:^|/)cas/sha256/[0-9a-f]{2}/([0-9a-f]{64})$", target)
|
|
122
|
+
if resp.status_code == 404:
|
|
123
|
+
# Retrying will not bring it back. After a store redirect this is a
|
|
124
|
+
# stub whose CAS blob is gone (an expired ephemeral artifact): not
|
|
125
|
+
# available, so the package is rebuilt, as the reapi backend does.
|
|
126
|
+
(warning if redirect_base else debug)("GET %s: not found", url)
|
|
127
|
+
return None
|
|
128
|
+
resp.raise_for_status()
|
|
129
|
+
sha256 = hashlib.sha256()
|
|
118
130
|
size = int(resp.headers.get("content-length", "-1"))
|
|
119
131
|
downloaded = 0
|
|
120
132
|
reportTime = time.time()
|
|
@@ -125,6 +137,8 @@ class HttpRemoteSync:
|
|
|
125
137
|
for chunk in filter(bool, resp.iter_content(chunk_size=32768)):
|
|
126
138
|
if destFp:
|
|
127
139
|
destFp.write(chunk)
|
|
140
|
+
if cas_digest:
|
|
141
|
+
sha256.update(chunk)
|
|
128
142
|
if returnResult:
|
|
129
143
|
result.append(chunk)
|
|
130
144
|
downloaded += len(chunk)
|
|
@@ -141,6 +155,11 @@ class HttpRemoteSync:
|
|
|
141
155
|
|
|
142
156
|
if size not in (downloaded, -1):
|
|
143
157
|
raise PartialDownloadError(downloaded, size)
|
|
158
|
+
if cas_digest and sha256.hexdigest() != cas_digest.group(1):
|
|
159
|
+
warning("GET %s: content does not match its sha256, ignoring it", url)
|
|
160
|
+
if dest:
|
|
161
|
+
os.unlink(dest+".tmp")
|
|
162
|
+
return None
|
|
144
163
|
if dest:
|
|
145
164
|
os.rename(dest+".tmp", dest) # we should not have errors here
|
|
146
165
|
return b''.join(result) if returnResult else True
|
|
@@ -240,7 +259,7 @@ class HttpRemoteSync:
|
|
|
240
259
|
# Fetch manifest file with initial symlinks. This file is updated
|
|
241
260
|
# regularly; we use it to avoid many small network requests.
|
|
242
261
|
manifest = self.getRetry(f"{self.remoteStore}/{links_path}.manifest",
|
|
243
|
-
returnResult=True, session=session)
|
|
262
|
+
returnResult=True, session=session) or b""
|
|
244
263
|
symlinks = {
|
|
245
264
|
linkname.decode("utf-8"): target.decode("utf-8")
|
|
246
265
|
for linkname, sep, target in (line.partition(b"\t")
|
|
@@ -520,7 +520,7 @@ class REAPIRemoteSync(Boto3RemoteSync):
|
|
|
520
520
|
return None
|
|
521
521
|
return json.loads(obj["Body"].read())
|
|
522
522
|
|
|
523
|
-
def is_published(self, action_hash):
|
|
523
|
+
def is_published(self, action_hash, keep_alive=False):
|
|
524
524
|
"""Whether an action is fully published: its Action Cache entry exists *and* the
|
|
525
525
|
CAS blob that entry names is present.
|
|
526
526
|
|
|
@@ -531,7 +531,12 @@ class REAPIRemoteSync(Boto3RemoteSync):
|
|
|
531
531
|
entry and bytes) is not something a dependent can be published against either.
|
|
532
532
|
|
|
533
533
|
Two HEAD-class requests, no download -- the blob is checked by presence, since it
|
|
534
|
-
is content-addressed and its key is its own digest.
|
|
534
|
+
is content-addressed and its key is its own digest.
|
|
535
|
+
|
|
536
|
+
keep_alive also promotes or LRU-refreshes the blob (see _maybe_promote). The
|
|
537
|
+
build asks this for every package it reuses, rebuilt, fetched or installed
|
|
538
|
+
already: a fetched one never reaches the upload, which is the only other
|
|
539
|
+
place a blob is kept alive."""
|
|
535
540
|
entry = self.read_ac_entry(action_hash)
|
|
536
541
|
if entry is None:
|
|
537
542
|
return False
|
|
@@ -539,7 +544,12 @@ class REAPIRemoteSync(Boto3RemoteSync):
|
|
|
539
544
|
if not content_hash:
|
|
540
545
|
# validate-system nodes produce no tarball: the entry alone is the artifact.
|
|
541
546
|
return (entry.get("action") or {}).get("kind") == "validate-system"
|
|
542
|
-
|
|
547
|
+
cas_path = resolve_cas_path(content_hash, algo)
|
|
548
|
+
if not self._exists(self.remoteStore, cas_path):
|
|
549
|
+
return False
|
|
550
|
+
if keep_alive:
|
|
551
|
+
self._maybe_promote(cas_path)
|
|
552
|
+
return True
|
|
543
553
|
|
|
544
554
|
def download_blob(self, content_hash, dest, algo="sha256"):
|
|
545
555
|
"""Download a ledger (input) blob -- e.g. a source bundle -- to dest."""
|
|
@@ -601,8 +611,10 @@ class REAPIRemoteSync(Boto3RemoteSync):
|
|
|
601
611
|
|
|
602
612
|
def _maybe_promote(self, cas_path):
|
|
603
613
|
"""When uploading as 'permanent' and the blob already exists tagged
|
|
604
|
-
ephemeral, promote it to permanent so it is no longer LRU-expired.
|
|
614
|
+
ephemeral, promote it to permanent so it is no longer LRU-expired.
|
|
615
|
+
Otherwise LRU-refresh it: reusing a blob must keep it alive."""
|
|
605
616
|
if self.storage != "permanent":
|
|
617
|
+
self._touch_if_expiring(cas_path)
|
|
606
618
|
return
|
|
607
619
|
if self._retention_of(self.writeStore, cas_path) == "ephemeral":
|
|
608
620
|
self.s3.put_object_tagging(
|
|
@@ -628,21 +640,25 @@ class REAPIRemoteSync(Boto3RemoteSync):
|
|
|
628
640
|
def _touch_if_expiring(self, cas_path):
|
|
629
641
|
"""LRU-refresh: if the blob is ephemeral and within REFRESH_WITHIN_DAYS of
|
|
630
642
|
its EPHEMERAL_TTL_DAYS expiry, copy it onto itself (preserving the tag) to
|
|
631
|
-
reset last-modified. Best-effort
|
|
643
|
+
reset last-modified. Best-effort, in the bucket we write: an upload that
|
|
644
|
+
dedups needs its blob there to stay, wherever it reads from."""
|
|
632
645
|
from botocore.exceptions import ClientError
|
|
633
|
-
if not self.writeStore
|
|
646
|
+
if not self.writeStore:
|
|
634
647
|
return
|
|
635
648
|
try:
|
|
636
|
-
|
|
637
|
-
return
|
|
638
|
-
head = self.s3.head_object(Bucket=self.remoteStore, Key=cas_path)
|
|
649
|
+
head = self.s3.head_object(Bucket=self.writeStore, Key=cas_path)
|
|
639
650
|
age_days = (datetime.now(timezone.utc) - head["LastModified"]).days
|
|
640
|
-
if age_days < self.EPHEMERAL_TTL_DAYS - self.REFRESH_WITHIN_DAYS
|
|
651
|
+
if age_days < self.EPHEMERAL_TTL_DAYS - self.REFRESH_WITHIN_DAYS or \
|
|
652
|
+
self._retention_of(self.writeStore, cas_path) != "ephemeral":
|
|
641
653
|
return
|
|
642
654
|
debug("Refreshing ephemeral %s (%d days old)", cas_path, age_days)
|
|
655
|
+
# REPLACE, with the same metadata: S3 and Ceph RGW refuse to copy an
|
|
656
|
+
# object onto itself with MetadataDirective=COPY (InvalidRequest).
|
|
643
657
|
self.s3.copy_object(Bucket=self.writeStore, Key=cas_path,
|
|
644
|
-
CopySource={"Bucket": self.
|
|
645
|
-
MetadataDirective="
|
|
658
|
+
CopySource={"Bucket": self.writeStore, "Key": cas_path},
|
|
659
|
+
MetadataDirective="REPLACE", Metadata=head.get("Metadata", {}),
|
|
660
|
+
ContentType=head.get("ContentType", "binary/octet-stream"),
|
|
661
|
+
TaggingDirective="COPY")
|
|
646
662
|
except ClientError as exc:
|
|
647
663
|
debug("Could not refresh %s: %s", cas_path, exc)
|
|
648
664
|
|
|
@@ -845,7 +861,7 @@ class REAPIRemoteSync(Boto3RemoteSync):
|
|
|
845
861
|
match = re.search(r"store/[0-9a-f]{2}/([0-9a-f]+)/", target)
|
|
846
862
|
return match.group(1) if match else None
|
|
847
863
|
|
|
848
|
-
def migrate_put(self, ac_entry, tarball_path, recipe_text):
|
|
864
|
+
def migrate_put(self, ac_entry, tarball_path, recipe_text, sign=False):
|
|
849
865
|
"""Write a migrated legacy release into the reapi store: the tarball as a
|
|
850
866
|
CAS blob, the recovered recipe blob, the Action Cache entry, plus the legacy
|
|
851
867
|
store redirect and per-package link so it stays installable and
|
|
@@ -854,7 +870,8 @@ class REAPIRemoteSync(Boto3RemoteSync):
|
|
|
854
870
|
Migrated entries are intentionally left *unsigned*: their provenance is
|
|
855
871
|
reconstructed after the fact, so a signature would falsely assert a trusted
|
|
856
872
|
signer built them. They are consumed as legacy (tolerated under
|
|
857
|
-
--require-signature=warn, refused under require).
|
|
873
|
+
--require-signature=warn, refused under require). Only a re-baseline, which
|
|
874
|
+
rebuilt the tarball itself, passes sign=True."""
|
|
858
875
|
action = ac_entry["action"]
|
|
859
876
|
arch, pkg = action["architecture"], action["package"]
|
|
860
877
|
action_hash = action["actionHash"]
|
|
@@ -876,6 +893,8 @@ class REAPIRemoteSync(Boto3RemoteSync):
|
|
|
876
893
|
"outputDigest": "%s:%s" % (self.CAS_ALGO, content_hash),
|
|
877
894
|
"size": os.path.getsize(tarball_path),
|
|
878
895
|
})
|
|
896
|
+
if sign:
|
|
897
|
+
entry = self._sign_ac_entry(entry)
|
|
879
898
|
ac_path = resolve_ac_path(arch, action_hash)
|
|
880
899
|
debug("S3 put_object %s/%s (AC entry)", self.acWriteStore, ac_path)
|
|
881
900
|
self.s3.put_object(Bucket=self.acWriteStore, Key=ac_path,
|
|
@@ -883,14 +902,14 @@ class REAPIRemoteSync(Boto3RemoteSync):
|
|
|
883
902
|
ContentType="application/json")
|
|
884
903
|
|
|
885
904
|
store_key = os.path.join(resolve_store_path(arch, action_hash), tarball)
|
|
886
|
-
debug("S3 put_object %s/%s (store redirect)", self.
|
|
905
|
+
debug("S3 put_object %s/%s (store redirect)", self.legacyWriteStore, store_key)
|
|
887
906
|
self.s3.put_object(Bucket=self.legacyWriteStore, Key=store_key,
|
|
888
907
|
Body=os.fsencode(cas_path),
|
|
889
908
|
WebsiteRedirectLocation=self._cas_redirect(cas_path))
|
|
890
909
|
|
|
891
910
|
link_target = "../../%s/store/%s/%s/%s" % (arch, action_hash[:2], action_hash, tarball)
|
|
892
911
|
link_key = os.path.join(resolve_links_path(arch, pkg), tarball)
|
|
893
|
-
debug("S3 put_object %s/%s (link)", self.
|
|
912
|
+
debug("S3 put_object %s/%s (link)", self.legacyWriteStore, link_key)
|
|
894
913
|
# The link stays RELATIVE: it points at the store object beside it in the
|
|
895
914
|
# same tree, and the client reads its body rather than following the header.
|
|
896
915
|
self.s3.put_object(Bucket=self.legacyWriteStore, Key=link_key,
|
|
@@ -955,7 +974,9 @@ class REAPIRemoteSync(Boto3RemoteSync):
|
|
|
955
974
|
is an in-place pointer swap. The new blob is stored *before* the AC entry is
|
|
956
975
|
repointed, so a failure never leaves the entry dangling; the old blob is left
|
|
957
976
|
orphaned (delete it separately via delete_artifact_blob). The retention of the
|
|
958
|
-
blob being replaced is preserved (untagged == keep-forever == permanent).
|
|
977
|
+
blob being replaced is preserved (untagged == keep-forever == permanent). The
|
|
978
|
+
old signatures covered the old digest: they are dropped, and the entry is
|
|
979
|
+
signed afresh when signing is configured.
|
|
959
980
|
Returns (old_hash, new_hash, old_cas_path)."""
|
|
960
981
|
old_digest = (entry.get("result") or {}).get("outputDigest", "")
|
|
961
982
|
old_hash = old_digest.split(":", 1)[-1]
|
|
@@ -966,7 +987,8 @@ class REAPIRemoteSync(Boto3RemoteSync):
|
|
|
966
987
|
self.storage = self._retention_of(self.writeStore, old_cas_path) or "permanent"
|
|
967
988
|
try:
|
|
968
989
|
new_hash = self.migrate_put(
|
|
969
|
-
{k: v for k, v in entry.items() if k
|
|
990
|
+
{k: v for k, v in entry.items() if k not in ("result", "signatures")},
|
|
991
|
+
tarball_path, recipe_text, sign=True)
|
|
970
992
|
finally:
|
|
971
993
|
self.storage = prev_storage
|
|
972
994
|
return old_hash, new_hash, old_cas_path
|
|
@@ -122,10 +122,21 @@ function detectShell() {
|
|
|
122
122
|
|
|
123
123
|
function collectModules() {
|
|
124
124
|
if [[ -z "$NO_REFRESH" ]]; then
|
|
125
|
-
# Collect all modulefiles in one place
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
# Collect all modulefiles in one place. Other alienv calls may read the
|
|
126
|
+
# directory meanwhile, so it is never emptied: each modulefile is written
|
|
127
|
+
# next to it and renamed into place, and only then are the modulefiles of
|
|
128
|
+
# packages which are gone removed.
|
|
129
|
+
local DEST=$WORK_DIR/MODULES/$ARCHITECTURE STAGE PKG PKGVER PKGNAME MODFILE MODNAME
|
|
130
|
+
mkdir -p "$DEST"
|
|
131
|
+
STAGE=$(mktemp -d "$WORK_DIR/MODULES/.refresh-$ARCHITECTURE.XXXXXX") || return 1
|
|
132
|
+
function publish() {
|
|
133
|
+
# Install $1 (a file, or - for stdin) as the modulefile $2, relative to $DEST.
|
|
134
|
+
mkdir -p "$DEST/${2%/*}"
|
|
135
|
+
if [[ $1 == - ]]; then cat > "$STAGE/file"; else cp "$1" "$STAGE/file"; fi
|
|
136
|
+
mv -f "$STAGE/file" "$DEST/$2"
|
|
137
|
+
echo "$2" >> "$STAGE/published"
|
|
138
|
+
}
|
|
139
|
+
publish - BASE/1.0 <<EOF
|
|
129
140
|
#%Module1.0
|
|
130
141
|
set base_path $WORK_DIR/$ARCHITECTURE
|
|
131
142
|
setenv BASEDIR \$base_path
|
|
@@ -144,10 +155,15 @@ EOF
|
|
|
144
155
|
for MODFILE in "$PKG"/etc/modulefiles/*; do
|
|
145
156
|
[[ -f "$MODFILE" ]] || continue
|
|
146
157
|
MODNAME=${MODFILE##*/}
|
|
147
|
-
|
|
148
|
-
cp "$MODFILE" "$WORK_DIR/MODULES/$ARCHITECTURE/$MODNAME/$PKGVER"
|
|
158
|
+
publish "$MODFILE" "$MODNAME/$PKGVER"
|
|
149
159
|
done
|
|
150
160
|
done < <(find $WORK_DIR/$ARCHITECTURE -maxdepth 2 -mindepth 2 2> /dev/null)
|
|
161
|
+
# BASE/1.0 is always published, so the list is never empty here.
|
|
162
|
+
(cd "$DEST" && find . -type f ! -name '.*' | sed -e 's|^\./||') | grep -vxF -f "$STAGE/published" | \
|
|
163
|
+
while read MODFILE; do rm -f "$DEST/$MODFILE"; done
|
|
164
|
+
find "$DEST" -mindepth 1 -type d -empty -delete 2> /dev/null
|
|
165
|
+
rm -rf "$STAGE"
|
|
166
|
+
unset -f publish
|
|
151
167
|
else
|
|
152
168
|
printf "${EY}WARNING: not updating modulefiles${EZ}\n" >&2
|
|
153
169
|
fi
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from unittest.mock import MagicMock, patch
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
from alibuild_helpers.log import dieOnError, ProgressPrint, LogFormatter, redact_secrets
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
FAKE_KEY = ("-----BEGIN RSA PRIVATE KEY-----\nMIIEfakefakefake\nAAAAsecretbody\n"
|
|
10
|
+
"-----END RSA PRIVATE KEY-----")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LogTestCase(unittest.TestCase):
|
|
14
|
+
def test_redact_docker_command(self) -> None:
|
|
15
|
+
"""The docker command line, joined unquoted, must not show the key."""
|
|
16
|
+
cmd = " ".join(["docker", "run", "-e", "JALIEN_TOKEN_KEY=" + FAKE_KEY,
|
|
17
|
+
"-e", "ALICEO2_CCDB_AUTH_TOKEN=abc123", "-e", "ARCHITECTURE=slc9_x86-64",
|
|
18
|
+
"-e", "ALIBUILD_PREFER_SYSTEM_KEY=gcc", "image"])
|
|
19
|
+
out = redact_secrets(cmd)
|
|
20
|
+
self.assertNotIn("secretbody", out)
|
|
21
|
+
self.assertNotIn("MIIEfake", out)
|
|
22
|
+
self.assertNotIn("abc123", out)
|
|
23
|
+
self.assertIn("ARCHITECTURE=slc9_x86-64", out)
|
|
24
|
+
self.assertIn("ALIBUILD_PREFER_SYSTEM_KEY=gcc", out)
|
|
25
|
+
self.assertIn("image", out)
|
|
26
|
+
|
|
27
|
+
def test_redact_quoted(self) -> None:
|
|
28
|
+
"""Shell-quoted values are redacted whole, including the quotes."""
|
|
29
|
+
out = redact_secrets("env GITHUB_TOKEN='tok en' JALIEN_TOKEN_KEY=\"%s\" bash" % FAKE_KEY)
|
|
30
|
+
self.assertEqual(out.count("<redacted>"), 2)
|
|
31
|
+
self.assertNotIn("tok en", out)
|
|
32
|
+
self.assertNotIn("secretbody", out)
|
|
33
|
+
self.assertTrue(out.endswith(" bash"))
|
|
34
|
+
|
|
35
|
+
def test_redact_unterminated_key(self) -> None:
|
|
36
|
+
"""A key cut off before its END marker is redacted to the end."""
|
|
37
|
+
out = redact_secrets("before " + FAKE_KEY.split("-----END")[0])
|
|
38
|
+
self.assertEqual(out, "before -----BEGIN RSA PRIVATE KEY----- <redacted>")
|
|
39
|
+
|
|
40
|
+
def test_formatter_redacts(self) -> None:
|
|
41
|
+
"""Everything going through the formatter is redacted, args included."""
|
|
42
|
+
record = logging.LogRecord("alibuild", logging.DEBUG, __file__, 1,
|
|
43
|
+
"Build command: %s", ("docker run -e JALIEN_TOKEN_KEY=" + FAKE_KEY,), None)
|
|
44
|
+
out = LogFormatter("%(levelname)s: %(message)s").format(record)
|
|
45
|
+
self.assertNotIn("secretbody", out)
|
|
46
|
+
self.assertIn("Build command: docker run -e JALIEN_TOKEN_KEY=<redacted>", out)
|
|
47
|
+
|
|
48
|
+
@patch("alibuild_helpers.log.error")
|
|
49
|
+
@patch("alibuild_helpers.log.sys")
|
|
50
|
+
def test_dieOnError(self, mock_sys, mock_error):
|
|
51
|
+
"""Check dieOnError dies on error."""
|
|
52
|
+
dieOnError(True, "Message")
|
|
53
|
+
mock_sys.exit.assert_called_once_with(1)
|
|
54
|
+
mock_error.assert_called_once_with("%s", "Message")
|
|
55
|
+
mock_sys.reset_mock()
|
|
56
|
+
mock_error.reset_mock()
|
|
57
|
+
dieOnError(False, "Message")
|
|
58
|
+
mock_error.assert_not_called()
|
|
59
|
+
mock_sys.exit.assert_not_called()
|
|
60
|
+
|
|
61
|
+
@patch("sys.stdout.isatty", new=MagicMock(return_value=True))
|
|
62
|
+
@patch("sys.stderr", new=MagicMock(return_value=True))
|
|
63
|
+
def test_ProgressPrint(self) -> None:
|
|
64
|
+
"""Make sure ProgressPrint updates correctly."""
|
|
65
|
+
# ProgressPrint only parses messages every 0.5s. Trick it into thinking
|
|
66
|
+
# the last message was <interval> seconds ago.
|
|
67
|
+
interval = 0.6
|
|
68
|
+
p = ProgressPrint("begin")
|
|
69
|
+
p("%s", "First message")
|
|
70
|
+
self.assertEqual(p.percent, -1)
|
|
71
|
+
p("%s", "[100/200] Update too fast")
|
|
72
|
+
self.assertEqual(p.percent, -1) # unchanged
|
|
73
|
+
p.lasttime -= interval
|
|
74
|
+
p("%s", "Has percentage: 80%")
|
|
75
|
+
self.assertEqual(p.percent, 80)
|
|
76
|
+
p.lasttime -= interval
|
|
77
|
+
p("%s", "No percentage")
|
|
78
|
+
self.assertEqual(p.percent, 80) # unchanged
|
|
79
|
+
p.lasttime -= interval
|
|
80
|
+
p("%s", "[100/200] Building CXX object this/is/a/ninja/test")
|
|
81
|
+
self.assertEqual(p.percent, 50)
|
|
82
|
+
p.lasttime -= interval
|
|
83
|
+
p("%s", "[100/0] Wrong-styled Ninja progress")
|
|
84
|
+
self.assertEqual(p.percent, 50) # unchanged
|
|
85
|
+
p.lasttime -= interval
|
|
86
|
+
p("%s", "Last message")
|
|
87
|
+
p.end()
|
|
88
|
+
|
|
89
|
+
if __name__ == '__main__':
|
|
90
|
+
unittest.main()
|
|
@@ -551,6 +551,66 @@ class ReconstructTestCase(unittest.TestCase):
|
|
|
551
551
|
workDir="/sw", outputConfig=None)
|
|
552
552
|
self.assertRaises(SystemExit, doReconstruct, args, None)
|
|
553
553
|
|
|
554
|
+
def _publish_args(self, **kw):
|
|
555
|
+
return Namespace(package="zlib", version="v1", revision="1", architecture=ARCH,
|
|
556
|
+
remoteStore="reapi://proxy/cas", acStore="reapi://proxy/ac::rw",
|
|
557
|
+
insecure=True, workDir="/sw", outputConfig=None,
|
|
558
|
+
rebaseline=True, apply=True, legacyStore="reapi://proxy/repo",
|
|
559
|
+
casPublicUrl="https://example/cas", **kw)
|
|
560
|
+
|
|
561
|
+
def test_doReconstruct_refuses_rebaseline_apply_without_signer(self):
|
|
562
|
+
with patch("alibuild_helpers.reconstruct.remote_from_url") as remote:
|
|
563
|
+
self.assertRaises(SystemExit, doReconstruct, self._publish_args(), None)
|
|
564
|
+
remote.assert_not_called() # refused before touching any store
|
|
565
|
+
|
|
566
|
+
def test_doReconstruct_passes_publishing_options_like_build(self):
|
|
567
|
+
# Stop right after the store is built: it is not a REAPIRemoteSync.
|
|
568
|
+
for no_sign, sign_url in ((False, "https://proxy/sign"), (True, "")):
|
|
569
|
+
args = self._publish_args(signUrl="https://proxy/sign", signToken="",
|
|
570
|
+
signTokenFile="/tok", signer="ci", noSign=no_sign)
|
|
571
|
+
with patch("alibuild_helpers.reconstruct.remote_from_url",
|
|
572
|
+
return_value=object()) as remote:
|
|
573
|
+
self.assertRaises(SystemExit, doReconstruct, args, None)
|
|
574
|
+
kw = remote.call_args.kwargs
|
|
575
|
+
self.assertEqual((kw["legacy_url"], kw["cas_public_url"]),
|
|
576
|
+
("reapi://proxy/repo", "https://example/cas"))
|
|
577
|
+
self.assertEqual((kw["sign_url"], kw["sign_token_file"], kw["signer"]),
|
|
578
|
+
(sign_url, "/tok", "ci"))
|
|
579
|
+
|
|
580
|
+
@patch("alibuild_helpers.signing.sign_via_proxy")
|
|
581
|
+
@patch("alibuild_helpers.sync_reapi.REAPIRemoteSync._s3_init", new=MagicMock())
|
|
582
|
+
def test_do_rebaseline_reproduced_digest_leaves_ac_entry_untouched(self, sign_via_proxy):
|
|
583
|
+
s = sync_reapi.REAPIRemoteSync(
|
|
584
|
+
"reapi://proxy/cas", "reapi://proxy/cas", ARCH, "/sw",
|
|
585
|
+
legacyStore="reapi://proxy/repo", casPublicUrl="https://example/cas",
|
|
586
|
+
sign_url="https://proxy/sign", sign_token="tok")
|
|
587
|
+
s.s3 = MagicMock()
|
|
588
|
+
result = RebuildResult(True, kind="match", algo="sha256",
|
|
589
|
+
recorded="a" * 64, rebuilt="a" * 64, tarball="/x")
|
|
590
|
+
self.assertTrue(do_rebaseline(Namespace(package="zlib", version="v1", apply=True,
|
|
591
|
+
delete_old=False), s,
|
|
592
|
+
[self._rebaseline_entry()], result))
|
|
593
|
+
sign_via_proxy.assert_not_called()
|
|
594
|
+
s.s3.put_object.assert_not_called()
|
|
595
|
+
s.s3.upload_file.assert_not_called()
|
|
596
|
+
|
|
597
|
+
def test_verify_rebuild_keeps_the_recorded_hash_and_revision(self):
|
|
598
|
+
"""A missing blob is rebuilt under its recorded action hash and revision,
|
|
599
|
+
which are in the tarball: no --force-rebuild, and the legacy links in view."""
|
|
600
|
+
closure = [make_entry("zlib", "v1", "1", "c" * 64, "rz")]
|
|
601
|
+
args = self._rebuild_args()
|
|
602
|
+
args.legacyStore, args.casPublicUrl = "reapi://x/repo", "https://example/cas"
|
|
603
|
+
for present, forced in ((False, False), (True, True)):
|
|
604
|
+
commands = []
|
|
605
|
+
with patch("alibuild_helpers.reconstruct.materialize_recipes"), \
|
|
606
|
+
patch("alibuild_helpers.reconstruct.restore_sources", return_value=([], [])), \
|
|
607
|
+
patch("alibuild_helpers.reconstruct.GitSourceStore"):
|
|
608
|
+
verify_rebuild(args, self.make_sync({"c" * 64} if present else ()), closure,
|
|
609
|
+
build_runner=lambda cmd: commands.append(cmd) or 1)
|
|
610
|
+
self.assertEqual("--force-rebuild" in commands[0], forced)
|
|
611
|
+
self.assertIn("--legacy-links-store", commands[0])
|
|
612
|
+
self.assertIn("https://example/cas", commands[0])
|
|
613
|
+
|
|
554
614
|
|
|
555
615
|
if __name__ == "__main__":
|
|
556
616
|
unittest.main()
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import hashlib
|
|
1
2
|
import os
|
|
2
3
|
import os.path
|
|
3
4
|
import sys
|
|
5
|
+
import tempfile
|
|
4
6
|
import unittest
|
|
5
7
|
from io import BytesIO
|
|
6
8
|
|
|
@@ -219,6 +221,51 @@ class SyncTestCase(unittest.TestCase):
|
|
|
219
221
|
self.assertFalse([u for u in requested if u.startswith(store + "/https")],
|
|
220
222
|
"the absolute target was joined onto the store: %s" % requested)
|
|
221
223
|
|
|
224
|
+
def fetch_through_stub(self, cas_response):
|
|
225
|
+
"""Fetch GOOD_SPEC from a store whose object redirects to a CAS blob, which
|
|
226
|
+
answers with cas_response. Returns (requested URLs, files left behind)."""
|
|
227
|
+
store = "https://localhost/legacy"
|
|
228
|
+
blob = "https://localhost/cas/cas/sha256/%s/%s" % (self.digest[:2], self.digest)
|
|
229
|
+
requested = []
|
|
230
|
+
|
|
231
|
+
def get(url, *args, **kw):
|
|
232
|
+
requested.append(url)
|
|
233
|
+
if url.endswith(tarball_name(GOOD_SPEC)) and "/store/" in url:
|
|
234
|
+
return MockRequest([{"name": tarball_name(GOOD_SPEC)}], redirect=blob)
|
|
235
|
+
if url == blob:
|
|
236
|
+
return cas_response
|
|
237
|
+
return self.mock_get(url, *args, **kw)
|
|
238
|
+
|
|
239
|
+
with tempfile.TemporaryDirectory() as workdir, \
|
|
240
|
+
patch("requests.Session.get", side_effect=get):
|
|
241
|
+
syncer = sync.HttpRemoteSync(remoteStore=store, architecture=ARCHITECTURE,
|
|
242
|
+
workdir=workdir, insecure=False)
|
|
243
|
+
syncer.httpBackoff = 0
|
|
244
|
+
syncer.fetch_tarball(GOOD_SPEC)
|
|
245
|
+
left = [f for _, _, files in os.walk(workdir) for f in files]
|
|
246
|
+
return [u for u in requested if u == blob], left
|
|
247
|
+
|
|
248
|
+
@patch("alibuild_helpers.sync.warning", new=MagicMock())
|
|
249
|
+
def test_http_missing_cas_blob_is_not_a_tarball(self):
|
|
250
|
+
"""A stub whose CAS blob is gone (expired) gives no tarball, no retries and
|
|
251
|
+
no exception, so the package is rebuilt. Writing the 404 body as the
|
|
252
|
+
tarball is what made a build fail with "gzip: not in gzip format"."""
|
|
253
|
+
self.digest = "fa" * 32
|
|
254
|
+
gone = MockRequest(None)
|
|
255
|
+
gone.iter_content = lambda chunk_size=10: iter([b"NoSuchKey"])
|
|
256
|
+
gone.headers["content-length"] = "9"
|
|
257
|
+
requested, left = self.fetch_through_stub(gone)
|
|
258
|
+
self.assertEqual(len(requested), 1)
|
|
259
|
+
self.assertEqual(left, [])
|
|
260
|
+
|
|
261
|
+
@patch("alibuild_helpers.sync.warning", new=MagicMock())
|
|
262
|
+
def test_http_cas_blob_checked_against_its_digest(self):
|
|
263
|
+
"""Bytes behind a cas/sha256/<digest> redirect must hash to <digest>."""
|
|
264
|
+
good = hashlib.sha256(b"x" * 123456).hexdigest()
|
|
265
|
+
for self.digest, kept in ((good, [tarball_name(GOOD_SPEC)]), ("ab" * 32, [])):
|
|
266
|
+
_, left = self.fetch_through_stub(MockRequest([{"name": "blob"}]))
|
|
267
|
+
self.assertEqual(left, kept)
|
|
268
|
+
|
|
222
269
|
def test_s3cmd_follows_store_redirect(self):
|
|
223
270
|
"""s3cmd cannot see the redirect header, so the stub is spotted by content."""
|
|
224
271
|
commands = []
|