Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Publish served agent installers as a complete bundle

pulse-triage[bot]8412544af585
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index fba4dd38f2..2351440724 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -16,6 +16,45 @@
## Purpose
+### Served agent installers publish as a complete script bundle
+
+The archive and source server installers share one script-publication path.
+Copying a supplied script or detached signature, setting its required mode or
+ownership, reserving the old bundle and publishing the new one must propagate
+failure explicitly, including through conditional callers that disable Bash
+`errexit`. None can issue a script-deployed or whole-install completion message
+over that failure. These checks do not replace release signature admission.
+
+Prepare scripts and their supplied `.sig`/`.sshsig` files in a private enclosure
+on the install filesystem before changing the served directory. Preserve other
+local files and absent script families. An overwritten file's symlink must not
+redirect the staged write. Newly supplied unsigned source/legacy scripts must
+not inherit old release sidecars; this does not make them signed releases.
+A symlinked or non-directory destination is left unchanged and needs manual
+reconciliation, rather than an automatic restart with unknown served content.
+
+Once the consumer has confirmed the server stopped, publish by same-filesystem
+directory renames with non-overwrite and source-disappearance checks. A failed
+or skipped publication restores the captured previous bundle when possible.
+If reservation/restore becomes uncertain, retain the previous bundle under its
+private stage, report its exact recovery location and do not restart Pulse.
+Do not overwrite an unexpected destination to force restoration. This is not
+a concurrent-writer or power-loss transaction guarantee: there is a short gap
+between the two directory renames while the server is stopped.
+
+Ordinary preparation failures and successful bundle restoration can use only
+the existing prior-active recovery-start path. The server binary has already
+been replaced at this point; a recovery start runs that admitted new binary,
+not the previous binary. Configuration, keys and identity are not restored or
+deleted, and the install still returns failure. Native recovery, sustained
+health, full-runtime rollback and historical stopped updates remain separate.
+
+`TestRootInstallAgentScriptPublicationPreservesPreviousBundle` registers the
+ordinary private-file failure/success controls, both real archive/source
+consumers and all five CLI completion paths. Ownership, service, signature,
+transport and source-build inputs in these controls are confined doubles, not
+published-artifact, native-service or customer-acceptance evidence.
+
### Completion requires confirmed server startup
All five server installer entry paths require successful `start_pulse` before
diff --git a/install.sh b/install.sh
index f5cbf72cb5..9e3e7a390d 100644
--- a/install.sh
+++ b/install.sh
@@ -3780,7 +3780,18 @@ install_pulse_archive() {
rm -rf "$binary_stage"
install_additional_agent_binaries "$expected_release" "$temp_extract"
- deploy_agent_scripts "$temp_extract"
+ local script_status=0
+ deploy_agent_scripts "$temp_extract" || script_status=$?
+ if [[ "$script_status" -ne 0 ]]; then
+ print_error "Pulse binary was installed, but agent script deployment is incomplete; installation has not completed"
+ rm -rf "$temp_extract"
+ if [[ "$script_status" -eq 1 ]]; then
+ recover_pulse_after_failed_replacement "$service_name"
+ else
+ print_error "Agent script destination needs manual reconciliation; Pulse has not been restarted"
+ fi
+ return 1
+ fi
chown_install_dir_for_pulse
print_success "Pulse binary installed to $INSTALL_DIR/bin/pulse"
@@ -4021,47 +4032,101 @@ deploy_agent_scripts() {
return
fi
- mkdir -p "$INSTALL_DIR/scripts"
-
local scripts=(
"install-container-agent.sh"
"install-docker.sh"
"install.sh"
"install.ps1"
)
+ local deployed=0 script sidecar stage="" live="$INSTALL_DIR/scripts"
+ for script in "${scripts[@]}"; do
+ [[ ! -f "$extract_dir/scripts/$script" ]] || deployed=$((deployed + 1))
+ done
+ if [[ $deployed -eq 0 ]]; then
+ print_warn "No agent installation scripts found in archive"
+ return 0
+ fi
- local deployed=0
+ # A script and its detached signatures are one served bundle. Prepare all
+ # bytes/permissions in a private enclosure before touching the old bundle;
+ # cp failure must never truncate the currently served installer. Preserve
+ # unrelated local scripts, but never follow an overridden file's symlink.
+ if [[ -L "$live" || ( -e "$live" && ! -d "$live" ) ]]; then
+ print_error "Agent script destination is not a regular directory; existing path is unchanged"
+ return 2
+ fi
+ if ! stage=$(mktemp -d -- "$INSTALL_DIR/.pulse-scripts-XXXXXX"); then
+ print_error "Could not stage agent scripts; existing scripts are unchanged"
+ return 1
+ fi
+ if ! mkdir -- "$stage/next" ||
+ { [[ -d "$live" ]] && ! cp -a -- "$live/." "$stage/next/"; }; then
+ rm -rf -- "$stage"
+ print_error "Could not prepare agent scripts; existing scripts are unchanged"
+ return 1
+ fi
for script in "${scripts[@]}"; do
- if [[ -f "$extract_dir/scripts/$script" ]]; then
- cp "$extract_dir/scripts/$script" "$INSTALL_DIR/scripts/$script"
- chmod 755 "$INSTALL_DIR/scripts/$script"
- chown pulse:pulse "$INSTALL_DIR/scripts/$script"
- # Deploy the detached release signatures next to the script. The
- # running server serves these local copies at /install.sh and
- # /install.ps1 (the "Install on Linux/Windows" agent wizard), and for
- # published releases the handler only serves the local file when its
- # .sig and .sshsig sidecars are present. Without them it falls back to
- # proxying the top-level GitHub install.sh asset, which is the SERVER
- # installer, not the agent installer, so the wizard's --url/--token-file
- # command is rejected with "Unknown option". The Docker image deploys
- # these same sidecars (see Dockerfile); LXC/systemd installs must match.
- local sidecar
- for sidecar in "${script}.sig" "${script}.sshsig"; do
- if [[ -f "$extract_dir/scripts/$sidecar" ]]; then
- cp "$extract_dir/scripts/$sidecar" "$INSTALL_DIR/scripts/$sidecar"
- chmod 644 "$INSTALL_DIR/scripts/$sidecar"
- chown pulse:pulse "$INSTALL_DIR/scripts/$sidecar"
- fi
- done
- deployed=$((deployed + 1))
+ [[ -f "$extract_dir/scripts/$script" ]] || continue
+ if ! cp --remove-destination -- "$extract_dir/scripts/$script" "$stage/next/$script" ||
+ ! chmod 755 -- "$stage/next/$script" || ! chown pulse:pulse "$stage/next/$script"; then
+ rm -rf -- "$stage"
+ print_error "Could not prepare agent script $script; existing scripts are unchanged"
+ return 1
fi
+ # Published archives carry both sidecars for the local /install.sh and
+ # /install.ps1 routes. Source/legacy scripts may have neither: do not
+ # attach a previous release's signature to newly copied unsigned bytes.
+ for sidecar in "${script}.sig" "${script}.sshsig"; do
+ if [[ -f "$extract_dir/scripts/$sidecar" ]]; then
+ if ! cp --remove-destination -- "$extract_dir/scripts/$sidecar" "$stage/next/$sidecar" ||
+ ! chmod 644 -- "$stage/next/$sidecar" || ! chown pulse:pulse "$stage/next/$sidecar"; then
+ rm -rf -- "$stage"
+ print_error "Could not prepare agent script signature $sidecar; existing scripts are unchanged"
+ return 1
+ fi
+ elif ! rm -f -- "$stage/next/$sidecar"; then
+ rm -rf -- "$stage"
+ print_error "Could not remove a stale agent script signature; existing scripts are unchanged"
+ return 1
+ fi
+ done
done
+ if ! chown pulse:pulse "$stage/next"; then
+ rm -rf -- "$stage"
+ print_error "Could not prepare agent script directory ownership; existing scripts are unchanged"
+ return 1
+ fi
- if [[ $deployed -gt 0 ]]; then
- print_success "Deployed $deployed agent installation script(s)"
- else
- print_warn "No agent installation scripts found in archive"
+ # Consumers have already confirmed the server stopped. These are same-
+ # filesystem renames, not a recursive copy onto live files. Never overwrite
+ # an unexpected destination, including mv -n's successful no-op result.
+ if [[ -d "$live" ]]; then
+ if ! mv -T -n -- "$live" "$stage/previous" || [[ -e "$live" || -L "$live" ]]; then
+ if [[ -e "$stage/previous" || -L "$stage/previous" ]]; then
+ print_error "Agent script reservation is incomplete; previous scripts retained at $stage/previous. Reconcile the destination before recovery."
+ return 2
+ fi
+ rm -rf -- "$stage"
+ print_error "Could not reserve the previous agent scripts; publication is incomplete"
+ return 1
+ fi
fi
+ if ! mv -T -n -- "$stage/next" "$live" || [[ -e "$stage/next" || -L "$stage/next" ]]; then
+ if [[ -d "$stage/previous" ]] &&
+ { ! mv -T -n -- "$stage/previous" "$live" || [[ -e "$stage/previous" || -L "$stage/previous" ]]; }; then
+ print_error "Agent script publication and restore are incomplete; previous scripts retained at $stage/previous. Reconcile the destination before recovery."
+ return 2
+ fi
+ rm -rf -- "$stage"
+ print_error "Could not publish agent scripts; previous scripts were not replaced"
+ return 1
+ fi
+ if ! rm -rf -- "$stage"; then
+ print_error "Agent scripts published, but previous-bundle cleanup is incomplete at $stage"
+ return 1
+ fi
+ print_success "Deployed $deployed agent installation script(s)"
+ return 0
}
build_from_source() {
@@ -4243,14 +4308,19 @@ build_from_source() {
fi
rm -rf "$binary_stage"
- mkdir -p "$INSTALL_DIR/scripts"
-
- for script_name in install-container-agent.sh install-docker.sh install.sh install.ps1; do
- if [[ -f "scripts/$script_name" ]]; then
- cp "scripts/$script_name" "$INSTALL_DIR/scripts/$script_name"
- chmod 755 "$INSTALL_DIR/scripts/$script_name"
+ local script_status=0
+ deploy_agent_scripts "$temp_build/Pulse" || script_status=$?
+ if [[ "$script_status" -ne 0 ]]; then
+ print_error "Built Pulse binary was installed, but agent script deployment is incomplete; installation has not completed"
+ cd "$original_dir" >/dev/null 2>&1 || true
+ rm -rf "$temp_build"
+ if [[ "$script_status" -eq 1 ]]; then
+ recover_pulse_after_failed_replacement "$service_name"
+ else
+ print_error "Agent script destination needs manual reconciliation; Pulse has not been restarted"
fi
- done
+ return 1
+ fi
install_binary_symlink "$INSTALL_DIR/bin/pulse" "$BINARY_LINK_PATH"
diff --git a/scripts/installtests/root_install_sh_test.go b/scripts/installtests/root_install_sh_test.go
index 41e3a67043..35e7c7b7e0 100644
--- a/scripts/installtests/root_install_sh_test.go
+++ b/scripts/installtests/root_install_sh_test.go
@@ -1509,6 +1509,25 @@ func TestRootInstallDeployAgentScriptsDeploysSignatureSidecars(t *testing.T) {
}
}
+// Script bytes and their detached signatures publish as one directory bundle.
+// Real archive/source producers and all main consumers use confined files and
+// manager/build doubles; no host service or published payload is exercised.
+func TestRootInstallAgentScriptPublicationPreservesPreviousBundle(t *testing.T) {
+ runPythonFixtureControls(t, repoFile("scripts", "tests", "test_server_script_publication.py"), "ServerScriptPublication", []string{
+ "test_preparation_failures_preserve_the_complete_old_bundle",
+ "test_failed_or_skipped_publication_restores_old_bundle",
+ "test_failed_restore_retains_original_bundle_and_names_its_location",
+ "test_symlinked_script_is_replaced_without_writing_its_target",
+ "test_symlinked_bundle_directory_is_not_replaced",
+ "test_success_publishes_scripts_and_both_sidecars_preserving_other_files",
+ "test_unsigned_source_scripts_do_not_inherit_stale_release_sidecars",
+ "test_archive_and_source_consumers_fail_and_only_recover_prior_active_service",
+ "test_uncertain_bundle_restore_does_not_restart_the_server",
+ "test_every_main_consumer_stops_before_markers_or_completion",
+ "test_archive_source_and_main_consumers_complete_with_a_whole_bundle",
+ }, 30*time.Second, "PULSE_INSTALLER_UNDER_TEST="+repoFile("install.sh"))
+}
+
// Regression test for the corrupted ExecCondition: setup_auto_updates used to
// render the pulse-update.service unit through an unquoted heredoc containing
// `$${PULSE_SERVICE_NAME}`, which bash expanded to the installer's PID. The
diff --git a/scripts/tests/test_server_script_publication.py b/scripts/tests/test_server_script_publication.py
new file mode 100644
index 0000000000..4950d1d420
--- /dev/null
+++ b/scripts/tests/test_server_script_publication.py
@@ -0,0 +1,334 @@
+#!/usr/bin/env python3
+"""Real installer-script publication with private files and inert service doubles.
+
+The archive and source consumers use synthetic payloads, not release acceptance.
+No host service, transport, ownership or customer state is operated here.
+"""
+import os
+from pathlib import Path
+import stat
+import subprocess
+import tarfile
+import tempfile
+import unittest
+
+
+ROOT = Path(__file__).resolve().parents[2]
+INSTALLER = Path(os.environ.get("PULSE_INSTALLER_UNDER_TEST", ROOT / "install.sh")).resolve()
+NAMES = ("install-container-agent.sh", "install-docker.sh", "install.sh", "install.ps1")
+
+HARNESS = r'''
+set -euo pipefail
+source "$INSTALLER"
+print_info() { printf 'INFO %s\n' "$*"; }
+print_warn() { printf 'WARN %s\n' "$*" >&2; }
+print_error() { printf 'ERROR %s\n' "$*" >&2; }
+print_success() { printf 'SUCCESS %s\n' "$*"; }
+record() { printf '%s\n' "$*" >> "$FIXTURE/events"; }
+cp() {
+ local source="${@: -2:1}" destination="${@: -1}"
+ if [[ "$FAULT" == copy && "$source" == */input/scripts/install.ps1 ]]; then
+ printf partial > "$destination"
+ return 23
+ fi
+ [[ "$FAULT" != sidecar-copy || "$source" != */install.ps1.sshsig ]] || return 23
+ [[ "$FAULT" != preserve-copy || "$source" != "$INSTALL_DIR/scripts/." ]] || return 23
+ command cp "$@"
+}
+chmod() {
+ [[ "$FAULT" != mode || "${@: -1}" != */install.ps1 ]] || return 24
+ [[ "$FAULT" != sidecar-mode || "${@: -1}" != */install.ps1.sshsig ]] || return 24
+ command chmod "$@"
+}
+chown() {
+ [[ "$FAULT" != owner || "${@: -1}" != */install.ps1 ]] || return 25
+ [[ "$FAULT" != sidecar-owner || "${@: -1}" != */install.ps1.sshsig ]] || return 25
+ # No actual ownership change, even inside the fixture.
+ :
+}
+mkdir() {
+ [[ "$FAULT" != directory || "$*" != *scripts* ]] || return 26
+ command mkdir "$@"
+}
+mktemp() {
+ [[ "$FAULT" != allocation || "$*" != *pulse-scripts-* ]] || return 27
+ command mktemp "$@"
+}
+mv() {
+ local source="${@: -2:1}" destination="${@: -1}"
+ if [[ "$source" == */next && "$destination" == "$INSTALL_DIR/scripts" ]]; then
+ record publish
+ case "$FAULT" in
+ publish|rollback) return 28 ;;
+ publish-skipped) return 0 ;;
+ conflict) mkdir "$destination"; printf foreign > "$destination/foreign"; return 0 ;;
+ esac
+ fi
+ [[ "$FAULT" != rollback || "$source" != */previous ]] || return 29
+ if [[ "$source" == "$INSTALL_DIR/scripts" ]]; then
+ [[ "$FAULT" != reserve ]] || return 30
+ [[ "$FAULT" != reserve-skipped ]] || return 0
+ if [[ "$FAULT" == reserve-conflict ]]; then
+ command mv "$@"
+ command mkdir "$INSTALL_DIR/scripts"
+ printf foreign > "$INSTALL_DIR/scripts/foreign"
+ return 0
+ fi
+ fi
+ command mv "$@"
+}
+if [[ "$FLOW" == direct ]]; then
+ deploy_agent_scripts "$FIXTURE/input" || exit "$?"
+elif [[ "$FLOW" == plain ]]; then
+ deploy_agent_scripts "$FIXTURE/input"
+else
+ CURRENT_VERSION=v6.5.0
+ FORCE_VERSION=v6.6.0
+ ARCHIVE_OVERRIDE="$FIXTURE/input.tgz"
+ detect_service_name() { printf 'pulse-script-fixture\n'; }
+ detect_pulse_architecture() { printf 'amd64\n'; }
+ ensure_update_disk_headroom() { :; }
+ run_upgrade_readiness_preflight() { :; }
+ verify_release_signature() { :; } # synthetic archive only
+ validate_pulse_binary_architecture() { :; }
+ install_additional_agent_binaries() { :; }
+ install_binary_symlink() { :; }
+ restore_selinux_contexts() { :; }
+ systemctl() {
+ record "$*"
+ case "$1" in
+ cat|enable) return 0 ;;
+ show) if [[ -e "$FIXTURE/stopped" || "$PRIOR" == false ]]; then echo inactive; else echo active; fi ;;
+ stop) touch "$FIXTURE/stopped" ;;
+ start) touch "$FIXTURE/restarted" ;;
+ is-active) [[ -e "$FIXTURE/restarted" ]] ;;
+ *) return 98 ;;
+ esac
+ }
+ timeout() { shift; "$@"; }
+ sleep() { :; }
+ # Inject the same failure at the actual extracted script, not only a
+ # direct helper. Archive installation is itself always an if/OR callee.
+ cp() {
+ local source="${@: -2:1}" destination="${@: -1}"
+ if [[ "$FAULT" == copy && "$source" == */scripts/install.ps1 ]]; then
+ printf partial > "$destination"; return 23
+ fi
+ [[ "$FAULT" != sidecar-copy || "$source" != */scripts/install.ps1.sshsig ]] || return 23
+ command cp "$@"
+ }
+ if [[ "$FLOW" == archive ]]; then
+ download_pulse
+ fi
+ if [[ "$FLOW" != archive ]]; then
+ apt-get() { :; }
+ go() { echo 'go version go1.99.0 linux/amd64'; }
+ npm() { :; }
+ make() { :; }
+ git() {
+ if [[ "$1" == clone ]]; then
+ local target="${@: -1}"
+ command cp -a "$FIXTURE/input" "$target"
+ command mkdir "$target/frontend-modern"
+ command cp "$FIXTURE/input/bin/pulse" "$target/pulse"
+ else
+ echo abc1234
+ fi
+ }
+ if [[ "$FLOW" == source ]]; then
+ build_from_source fixture || exit "$?"
+ else
+ IN_CONTAINER=true
+ IN_DOCKER=false
+ FORCE_VERSION=""
+ FORCE_CHANNEL=stable
+ FRONTEND_PORT=7655
+ BUILD_FROM_SOURCE=false
+ [[ "$FLOW" != main-pinned ]] || FORCE_VERSION=v6.6.0
+ [[ "$FLOW" != main-source ]] || BUILD_FROM_SOURCE=true
+ for fn in print_header check_root detect_os check_docker_environment offer_existing_auto_updates backup_existing install_dependencies create_user setup_directories setup_update_command install_systemd_service ensure_systemd_service_installed setup_auto_updates refresh_auto_updates; do
+ eval "$fn() { :; }"
+ done
+ check_proxmox_host() { return 1; }
+ check_existing_installation() { [[ "$FLOW" != main-fresh ]]; }
+ resolve_latest_release_tag_for_channel() { echo v6.6.0; }
+ safe_read() { local selection=1; [[ "$FLOW" != main-reinstall ]] || selection=2; printf -v "$2" '%s' "$selection"; }
+ update_timer_exists() { return 1; }
+ create_marker_file() { record marker; }
+ print_completion() { record completion; }
+ main || exit "$?"
+ fi
+ fi
+fi
+record completion
+'''
+
+
+class ServerScriptPublication(unittest.TestCase):
+ def exercise(self, fault="", flow="direct", prior=True, existing=True, sidecars=True, target="directory"):
+ with tempfile.TemporaryDirectory(prefix="pulse-script-publication-") as temporary:
+ f = Path(temporary)
+ install = f / "install"
+ for directory in [install / "bin", f / "config", f / "input/scripts", f / "input/bin"]:
+ directory.mkdir(parents=True)
+ original = {}
+ if existing:
+ (install / "scripts").mkdir()
+ for name in [n + suffix for n in NAMES for suffix in ("", ".sig", ".sshsig")] + ["custom-helper"]:
+ p = install / "scripts" / name
+ p.write_bytes(("old-" + name).encode())
+ p.chmod(0o640)
+ original[name] = p.read_bytes()
+ for name in NAMES:
+ (f / "input/scripts" / name).write_bytes(("new-" + name).encode())
+ if sidecars:
+ for suffix in (".sig", ".sshsig"):
+ (f / "input/scripts" / (name + suffix)).write_bytes(("new-" + name + suffix).encode())
+ outside = f / "outside"
+ outside.write_bytes(b"unrelated file")
+ if target == "file-link":
+ (install / "scripts/install.ps1").unlink()
+ (install / "scripts/install.ps1").symlink_to(outside)
+ elif target == "directory-link":
+ (install / "scripts").rename(f / "original-scripts")
+ (install / "scripts").symlink_to(f / "original-scripts")
+ binary = f / "input/bin/pulse"
+ binary.write_text("#!/bin/sh\necho 'Pulse v6.6.0'\n")
+ binary.chmod(0o755)
+ (install / "bin/pulse").write_bytes(b"old executable")
+ (install / "VERSION").write_text("v6.5.0\n")
+ saved = f / "config/.encryption.key"
+ saved.write_bytes(b"synthetic saved key and identity")
+ saved.chmod(0o600)
+ with tarfile.open(f / "input.tgz", "w:gz") as archive:
+ for child in (f / "input").iterdir():
+ archive.add(child, arcname=child.name)
+ (f / "input.tgz.sshsig").write_text("synthetic sidecar")
+ env = {k: v for k, v in os.environ.items() if not k.startswith("PULSE_")}
+ env.update(INSTALLER=str(INSTALLER), FIXTURE=str(f), FLOW=flow, FAULT=fault,
+ PRIOR=str(prior).lower(), PULSE_INSTALL_DIR=str(install),
+ PULSE_CONFIG_DIR=str(f / "config"), PULSE_SERVICE_NAME="pulse-script-fixture")
+ result = subprocess.run(["bash", "-c", HARNESS], cwd=f, env=env,
+ text=True, capture_output=True, timeout=15)
+ self.assertEqual(saved.read_bytes(), b"synthetic saved key and identity")
+ self.assertEqual(stat.S_IMODE(saved.stat().st_mode), 0o600)
+ self.assertEqual(outside.read_bytes(), b"unrelated file")
+ live = install / "scripts"
+ contents = {p.name: p.read_bytes() for p in live.iterdir()} if live.is_dir() else {}
+ modes = {p.name: stat.S_IMODE(p.stat().st_mode) for p in live.iterdir()} if live.is_dir() else {}
+ retained = {str(p.relative_to(install)): p.read_bytes()
+ for p in install.glob(".pulse-scripts-*/previous/*")}
+ events = (f / "events").read_text().splitlines() if (f / "events").exists() else []
+ return dict(result=result, original=original, contents=contents, modes=modes,
+ stages=list(install.glob(".pulse-scripts-*")), retained=retained,
+ events=events, restarted=(f / "restarted").exists())
+
+ def test_preparation_failures_preserve_the_complete_old_bundle(self):
+ for fault in ("copy", "mode", "owner", "directory", "allocation", "sidecar-copy", "sidecar-mode", "sidecar-owner", "preserve-copy"):
+ for flow in ("plain", "direct"):
+ with self.subTest(fault=fault, flow=flow):
+ e = self.exercise(fault, flow)
+ self.assertNotEqual(e["result"].returncode, 0, e["result"].stdout + e["result"].stderr)
+ self.assertEqual(e["contents"], e["original"])
+ self.assertTrue(all(mode == 0o640 for mode in e["modes"].values()))
+ self.assertEqual(e["stages"], [])
+ self.assertNotIn("completion", e["events"])
+
+ def test_failed_or_skipped_publication_restores_old_bundle(self):
+ for fault in ("publish", "publish-skipped", "reserve", "reserve-skipped"):
+ for existing in ((True,) if fault.startswith("reserve") else (False, True)):
+ with self.subTest(fault=fault, existing=existing):
+ e = self.exercise(fault, existing=existing)
+ self.assertNotEqual(e["result"].returncode, 0)
+ self.assertEqual(e["contents"], e["original"])
+ self.assertEqual(e["stages"], [])
+
+ def test_failed_restore_retains_original_bundle_and_names_its_location(self):
+ for fault in ("rollback", "conflict", "reserve-conflict"):
+ with self.subTest(fault=fault):
+ e = self.exercise(fault)
+ self.assertNotEqual(e["result"].returncode, 0)
+ self.assertEqual({k.split("/previous/")[1]: v for k, v in e["retained"].items()}, e["original"])
+ self.assertEqual(len(e["stages"]), 1)
+ self.assertIn(str(e["stages"][0]) + "/previous", e["result"].stderr)
+ self.assertEqual(e["contents"], {"foreign": b"foreign"} if "conflict" in fault else {})
+
+ def test_symlinked_script_is_replaced_without_writing_its_target(self):
+ e = self.exercise(target="file-link")
+ self.assertEqual(e["result"].returncode, 0, e["result"].stderr)
+ self.assertEqual(e["contents"]["install.ps1"], b"new-install.ps1")
+
+ def test_symlinked_bundle_directory_is_not_replaced(self):
+ e = self.exercise(target="directory-link")
+ self.assertEqual(e["result"].returncode, 2, e["result"].stderr)
+ self.assertEqual(e["contents"], e["original"])
+ self.assertEqual(e["stages"], [])
+
+ def test_success_publishes_scripts_and_both_sidecars_preserving_other_files(self):
+ for existing in (False, True):
+ with self.subTest(existing=existing):
+ e = self.exercise(existing=existing)
+ self.assertEqual(e["result"].returncode, 0, e["result"].stderr)
+ for name in NAMES:
+ for suffix in ("", ".sig", ".sshsig"):
+ self.assertEqual(e["contents"][name + suffix], ("new-" + name + suffix).encode())
+ self.assertEqual(e["modes"][name + suffix], 0o755 if not suffix else 0o644)
+ if existing:
+ self.assertEqual(e["contents"]["custom-helper"], b"old-custom-helper")
+ self.assertEqual(e["modes"]["custom-helper"], 0o640)
+ self.assertEqual(e["stages"], [])
+
+ def test_archive_source_and_main_consumers_complete_with_a_whole_bundle(self):
+ for flow in ("archive", "source", "main-pinned", "main-update", "main-reinstall", "main-fresh", "main-source"):
+ with self.subTest(flow=flow):
+ e = self.exercise(flow=flow)
+ self.assertEqual(e["result"].returncode, 0, e["result"].stdout + e["result"].stderr)
+ self.assertIn("completion", e["events"])
+ for name in NAMES:
+ for suffix in ("", ".sig", ".sshsig"):
+ self.assertEqual(e["contents"][name + suffix], ("new-" + name + suffix).encode())
+ self.assertEqual(e["stages"], [])
+
+ def test_unsigned_source_scripts_do_not_inherit_stale_release_sidecars(self):
+ e = self.exercise(sidecars=False)
+ self.assertEqual(e["result"].returncode, 0, e["result"].stderr)
+ for name in NAMES:
+ self.assertEqual(e["contents"][name], ("new-" + name).encode())
+ self.assertNotIn(name + ".sig", e["contents"])
+ self.assertNotIn(name + ".sshsig", e["contents"])
+
+ def test_archive_and_source_consumers_fail_and_only_recover_prior_active_service(self):
+ for flow in ("archive", "source"):
+ for fault in ("copy", "mode", "owner", "sidecar-copy", "sidecar-mode", "sidecar-owner"):
+ for prior in (False, True):
+ with self.subTest(flow=flow, fault=fault, prior=prior):
+ e = self.exercise(fault, flow, prior)
+ self.assertNotEqual(e["result"].returncode, 0, e["result"].stdout + e["result"].stderr)
+ self.assertEqual(e["contents"], e["original"])
+ self.assertEqual(e["restarted"], prior)
+ self.assertNotIn("completion", e["events"])
+ self.assertNotIn("Version verified:", e["result"].stdout)
+ self.assertNotIn("Successfully built and installed", e["result"].stdout)
+
+ def test_uncertain_bundle_restore_does_not_restart_the_server(self):
+ for flow in ("archive", "source"):
+ for fault in ("rollback", "conflict", "reserve-conflict"):
+ with self.subTest(flow=flow, fault=fault):
+ e = self.exercise(fault, flow)
+ self.assertNotEqual(e["result"].returncode, 0)
+ self.assertFalse(e["restarted"])
+ self.assertIn("Pulse has not been restarted", e["result"].stderr)
+ self.assertNotIn("completion", e["events"])
+
+ def test_every_main_consumer_stops_before_markers_or_completion(self):
+ for flow in ("main-pinned", "main-update", "main-reinstall", "main-fresh", "main-source"):
+ with self.subTest(flow=flow):
+ e = self.exercise("copy", flow)
+ self.assertNotEqual(e["result"].returncode, 0, e["result"].stdout + e["result"].stderr)
+ self.assertEqual(e["contents"], e["original"])
+ self.assertNotIn("marker", e["events"])
+ self.assertNotIn("completion", e["events"])
+
+
+if __name__ == "__main__":
+ unittest.main(verbosity=2)