Preserve registry transfer diagnostics and prevent sudo prompts
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-11-02 21:53:42 -06:00
parent c6a2758d35
commit 40aff369bf
1 changed files with 22 additions and 4 deletions

View File

@ -262,14 +262,32 @@ def prepare_local(args, path, existing_pv):
if special:
raise RuntimeError("Source registry contains non-regular files; refusing unsafe archive extraction")
print(f"Copying registry data from {args.source_host}:{args.source_path} into staging storage", flush=True)
with tempfile.TemporaryFile() as errors:
source = subprocess.Popen(source_ssh("sudo -n tar -C " + shlex.quote(args.source_path) + " -cpf - ."), stdout=subprocess.PIPE, stderr=errors)
diagnostics = state / "diagnostics"
diagnostics.mkdir(parents=True, exist_ok=True, mode=0o700)
transfer_id = str(time.time_ns())
source_log = diagnostics / f"registry-transfer-{transfer_id}-source.log"
destination_log = diagnostics / f"registry-transfer-{transfer_id}-destination.log"
with source_log.open("w+b") as source_errors, destination_log.open("w+b") as destination_errors:
source_log.chmod(0o600)
destination_log.chmod(0o600)
source = subprocess.Popen(source_ssh("sudo -n tar -C " + shlex.quote(args.source_path) + " -cpf - ."), stdout=subprocess.PIPE, stderr=source_errors)
try:
destination = subprocess.run(["sudo", "tar", "-C", stage, "-xpf", "-", "--no-same-owner"], stdin=source.stdout, stderr=errors, timeout=1800)
destination = subprocess.run(["sudo", "-n", "tar", "-C", stage, "-xpf", "-", "--no-same-owner"], stdin=source.stdout, stderr=destination_errors, timeout=1800)
source.stdout.close()
source_status = source.wait(timeout=30)
if destination.returncode or source_status:
raise RuntimeError("Registry archive transfer failed; source preserved")
print(f"Registry archive exit codes: source={source_status}, destination={destination.returncode}", file=sys.stderr)
for label, stream, filename in (("source", source_errors, source_log), ("destination", destination_errors, destination_log)):
stream.flush()
stream.seek(0, 2)
stream.seek(max(0, stream.tell() - 8192))
for line in stream.read().decode("utf-8", errors="replace").splitlines()[-4:]:
print(f" tar {label}: {line[:300]}", file=sys.stderr)
print(f"Private {label} diagnostic: {filename}", file=sys.stderr)
raise RuntimeError("Registry archive transfer failed; detailed tar diagnostics retained, source preserved")
except subprocess.TimeoutExpired:
print(f"Archive transfer timed out; private diagnostics: {source_log}, {destination_log}", file=sys.stderr)
raise
finally:
if source.poll() is None:
source.kill()