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.

Keep server recovery data until removal has completed

pulse-triage[bot]47250b2b857a
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index ba3ec8489e..59d5f766b0 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -832,6 +832,28 @@ the original key file rather than reporting completion after an ignored error.
`TestRootInstallSensorProxyCleanupRejectsFailedKeyReplacement` executes that
boundary. Native systemd/removal acceptance remains separate from source fixtures.
+Quiescence alone is not completed removal. Both entries explicitly check every
+runtime-file deletion and the bounded systemd reload, without the update-time
+best-effort reload exception. Runtime paths are checked as a complete set before
+deletion: unresolved, root, equal or overlapping configuration paths (including
+symlinked parents) stop rather than consume recovery state in the runtime phase.
+The menu retains its separate data/account choices; `--uninstall` retains its
+existing full-removal intent. Account-removal failure is incomplete, not an
+ignored success. Configuration/credentials are deleted last, after applicable
+runtime, local legacy, reload, account and log work succeeds. Any earlier failure
+retains that configuration and stops; previously removed runtime files are not
+claimed restored. Failure during data deletion may itself be partial and must
+not claim intact data, successful removal or automatic restart/retry.
+
+`TestRootInstallRemovalFilesystemFailures` runs the repository-discovered
+`scripts/tests/test_server_removal_failures.py` against both actual sourced
+entries, directly and in conditional callers. It exercises each runtime-file
+failure, real ordinary-user permission denial, reload/account/legacy/log errors,
+partial data deletion, separate successful default/custom-instance removal,
+declined data/account deletion and unsafe layouts. It compares retained data
+bytes/modes and other-instance files. These confined controls do not establish
+native installed removal, signed forward/reverse recovery or incident recovery.
+
### Legacy installer identity recovery is a whole-file decision
An installer recovering a pre-descriptor-helper agent-ID file accepts exactly
diff --git a/install.sh b/install.sh
index fe28eb4eaa..6c8093b453 100644
--- a/install.sh
+++ b/install.sh
@@ -753,6 +753,75 @@ quiesce_pulse_for_removal() {
done
}
+# These helpers are explicitly checked by both removal entries. Bash suppresses
+# errexit inside a function called from an if/OR-list; set -e is not a deletion
+# result. Stop at the first failure, without restarting or claiming rollback.
+remove_pulse_path_for_removal() {
+ local path="$1" kind="${2:-file}"
+ if [[ "$kind" == directory ]]; then
+ if rm -rf -- "$path"; then return 0; fi
+ else
+ if rm -f -- "$path"; then return 0; fi
+ fi
+ print_error "Cannot remove $path; Pulse removal is incomplete. Some files may already have been removed. Inspect retained files before recovery; no automatic restart will be attempted."
+ return 1
+}
+
+remove_pulse_runtime_files() {
+ local service_name="$1" path resolved config_path
+ local paths=("/etc/systemd/system/${service_name%.service}.service"
+ "$UPDATE_SERVICE_PATH" "$UPDATE_TIMER_PATH"
+ "$BINARY_LINK_PATH" "$AUTO_UPDATE_DEST")
+ if [[ "$SERVICE_NAME_EXPLICIT" != true ]]; then
+ paths+=(/etc/systemd/system/pulse.service /etc/systemd/system/pulse-backend.service)
+ fi
+ if [[ "$UPDATE_HELPER_PATH" != /bin/update ]]; then
+ paths+=("$UPDATE_HELPER_PATH")
+ fi
+ paths+=("$INSTALL_DIR")
+
+ # Configuration is a separate, last deletion phase. Custom paths (including
+ # symlinked parents) must not let runtime removal consume it before consent
+ # or a later failure. Validate the whole layout before the first deletion.
+ if ! config_path=$(readlink -m -- "$CONFIG_DIR") || [[ "$config_path" == / ]]; then
+ print_error "Cannot safely separate configuration from runtime files; refusing removal"
+ return 1
+ fi
+ for path in "${paths[@]}"; do
+ if ! resolved=$(readlink -m -- "$path") ||
+ [[ "$resolved" == / || "$resolved" == "$config_path" ||
+ "$resolved" == "$config_path/"* || "$config_path" == "$resolved/"* ]]; then
+ print_error "Runtime path overlaps configuration or is unsafe ($path); refusing removal. No files have been removed."
+ return 1
+ fi
+ done
+ for path in "${paths[@]}"; do
+ if [[ "$path" == "$INSTALL_DIR" ]]; then
+ remove_pulse_path_for_removal "$path" directory || return 1
+ else
+ remove_pulse_path_for_removal "$path" || return 1
+ fi
+ done
+}
+
+reload_pulse_units_after_removal() {
+ # Unlike update-time best-effort reloads, removal cannot declare completion
+ # while systemd's view of deleted units is unknown.
+ if ! timeout -k 1 5 systemctl daemon-reload; then
+ print_error "Cannot reload service definitions; Pulse removal is incomplete. Configuration is retained; reconcile service state before recovery."
+ return 1
+ fi
+}
+
+remove_pulse_user_for_removal() {
+ if id pulse &>/dev/null; then
+ if ! userdel pulse; then
+ print_error "Cannot remove the pulse account; Pulse removal is incomplete. Configuration is retained; inspect remaining account use before recovery."
+ return 1
+ fi
+ fi
+}
+
# Called only after a confirmed stop and a failed atomic rename. The previous
# executable is still in place. An uncertain stop never reaches this recovery,
# and an intentionally inactive/failed service must not be started for the user.
@@ -5536,43 +5605,18 @@ main() {
return 1
fi
- # Remove service files
- rm -f "/etc/systemd/system/$SERVICE_NAME.service"
- if [[ "$SERVICE_NAME_EXPLICIT" != "true" ]]; then
- rm -f /etc/systemd/system/pulse.service
- rm -f /etc/systemd/system/pulse-backend.service
- fi
- rm -f "$UPDATE_SERVICE_PATH"
- rm -f "$UPDATE_TIMER_PATH"
- # Reload systemd daemon
- safe_systemctl daemon-reload
-
- # Remove installation directory
- rm -rf "$INSTALL_DIR"
-
- # Remove symlink
- rm -f "$BINARY_LINK_PATH"
- rm -f "$AUTO_UPDATE_DEST"
- if [[ "$UPDATE_HELPER_PATH" != "/bin/update" ]]; then
- rm -f "$UPDATE_HELPER_PATH"
- fi
+ remove_pulse_runtime_files "$SERVICE_NAME" || return 1
+ reload_pulse_units_after_removal || return 1
# Ask about config/data removal
echo
print_info "Config and data files exist in $CONFIG_DIR"
safe_read_with_default "Remove all configuration and data? (y/N): " remove_config "n"
- if [[ "$remove_config" =~ ^[Yy]$ ]]; then
- rm -rf "$CONFIG_DIR"
- print_success "Configuration and data removed"
- else
- print_info "Configuration preserved in $CONFIG_DIR"
- fi
-
# Ask about user removal
if id "pulse" &>/dev/null; then
safe_read_with_default "Remove pulse user account? (y/N): " remove_user "n"
if [[ "$remove_user" =~ ^[Yy]$ ]]; then
- userdel pulse 2>/dev/null || true
+ remove_pulse_user_for_removal || return 1
print_success "User account removed"
else
print_info "User account preserved"
@@ -5580,9 +5624,21 @@ main() {
fi
# Remove any log files
- rm -f /var/log/pulse*.log 2>/dev/null || true
+ local log_path
+ for log_path in /var/log/pulse*.log; do
+ remove_pulse_path_for_removal "$log_path" || return 1
+ done
if [[ "$SERVICE_NAME_EXPLICIT" != "true" ]]; then
- rm -f /opt/pulse.log 2>/dev/null || true
+ remove_pulse_path_for_removal /opt/pulse.log || return 1
+ fi
+
+ # Data deletion is last: any earlier incomplete removal leaves
+ # recovery state intact. A deletion error can itself be partial.
+ if [[ "$remove_config" =~ ^[Yy]$ ]]; then
+ remove_pulse_path_for_removal "$CONFIG_DIR" directory || return 1
+ print_success "Configuration and data removed"
+ else
+ print_info "Configuration preserved in $CONFIG_DIR"
fi
print_success "Pulse removed successfully"
@@ -5782,33 +5838,20 @@ uninstall_pulse() {
# Remove files
echo "Removing Pulse files..."
- rm -rf "$INSTALL_DIR"
- rm -rf "$CONFIG_DIR"
- rm -f "/etc/systemd/system/$service_name.service"
- if [[ "$SERVICE_NAME_EXPLICIT" != "true" ]]; then
- rm -f /etc/systemd/system/pulse.service
- rm -f /etc/systemd/system/pulse-backend.service
- fi
- rm -f "$UPDATE_SERVICE_PATH"
- rm -f "$UPDATE_TIMER_PATH"
- rm -f "$BINARY_LINK_PATH"
- rm -f "$AUTO_UPDATE_DEST"
- if [[ "$UPDATE_HELPER_PATH" != "/bin/update" ]]; then
- rm -f "$UPDATE_HELPER_PATH"
- fi
-
- # Remove user (if it exists and isn't being used by other services)
- if id "pulse" &>/dev/null; then
- echo "Removing pulse user..."
- userdel pulse 2>/dev/null || true
- fi
+ remove_pulse_runtime_files "$service_name" || return 1
# Remove any leftover legacy pulse-sensor-proxy footprint on this host so a
# full uninstall on a v5-upgraded Proxmox host leaves nothing behind.
cleanup_local_sensor_proxy || return 1
# Reload systemd
- systemctl daemon-reload
+ reload_pulse_units_after_removal || return 1
+
+ # Keep configuration/credentials until runtime, legacy cleanup, systemd and
+ # account removal have all completed. Never turn a partial deletion into a
+ # successful uninstall when this entry is called conditionally.
+ remove_pulse_user_for_removal || return 1
+ remove_pulse_path_for_removal "$CONFIG_DIR" directory || return 1
echo
echo -e "\033[0;32m✓ Pulse has been completely uninstalled\033[0m"
diff --git a/scripts/installtests/root_install_sh_test.go b/scripts/installtests/root_install_sh_test.go
index 1f124716a9..37ce9e0974 100644
--- a/scripts/installtests/root_install_sh_test.go
+++ b/scripts/installtests/root_install_sh_test.go
@@ -162,6 +162,33 @@ func TestRootInstallProxmoxFailurePreservesRecovery(t *testing.T) {
}
}
+// Both sourced entries must propagate removal failures even when a conditional
+// caller disables errexit. The fixture confines every mutation to temporary
+// ordinary-user files; native systemd acceptance stays with the existing job.
+func TestRootInstallRemovalFilesystemFailures(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("Unix server removal fixture")
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
+ defer cancel()
+ cmd := exec.CommandContext(ctx, "python3", repoFile("scripts", "tests", "test_server_removal_failures.py"), "-v")
+ cmd.Env = append(os.Environ(), "PULSE_INSTALLER_UNDER_TEST="+repoFile("install.sh"))
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("server removal filesystem/account/reload controls: %v\n%s", err, out)
+ }
+ for _, control := range []string{
+ "test_each_runtime_deletion_failure_preserves_data_and_stops",
+ "test_reload_or_account_failure_preserves_data",
+ "test_partial_data_deletion_is_not_completion_or_intact_state",
+ "test_unsafe_or_unreadable_layout_refuses_all_file_deletion",
+ } {
+ if !strings.Contains(string(out), control) {
+ t.Fatalf("required removal control %s did not run:\n%s", control, out)
+ }
+ }
+}
+
func TestRootInstallScriptVersionFlagRequiresValue(t *testing.T) {
scriptPath := filepath.Join("..", "..", "install.sh")
diff --git a/scripts/installtests/server_removal_safety_test.go b/scripts/installtests/server_removal_safety_test.go
index 0f6d0cd957..0e6d659825 100644
--- a/scripts/installtests/server_removal_safety_test.go
+++ b/scripts/installtests/server_removal_safety_test.go
@@ -240,7 +240,7 @@ rm() {
# must be in the fixture; unexpected options are a fixture error.
local arg
for arg in "$@"; do
- case "$arg" in -f|-rf) ;; "$FIXTURE_DIR"/*) /bin/rm -rf -- "$arg" ;; /etc/systemd/system/*|/usr/local/bin/pulse-sensor-cleanup.sh|/var/log/pulse*.log|/opt/pulse.log) ;; *) return 91 ;; esac
+ case "$arg" in -f|-rf|--) ;; "$FIXTURE_DIR"/*) /bin/rm -rf -- "$arg" ;; /etc/systemd/system/*|/usr/local/bin/pulse-sensor-cleanup.sh|/var/log/pulse*.log|/opt/pulse.log) ;; *) return 91 ;; esac
done
}
safe_read() { printf -v "$2" '%s' 2; }
diff --git a/scripts/tests/test_server_removal_failures.py b/scripts/tests/test_server_removal_failures.py
new file mode 100644
index 0000000000..1f3c7c6c58
--- /dev/null
+++ b/scripts/tests/test_server_removal_failures.py
@@ -0,0 +1,297 @@
+#!/usr/bin/env python3
+"""Actual removal entries, confined to ordinary-user files and inert services.
+
+The existing Go removal suite owns real quiescence/timeout control. This suite
+owns the subsequent filesystem/account/reload boundaries, including conditional
+callers for which Bash disables errexit. No installed service or guest is used.
+"""
+
+import os
+from pathlib import Path
+import stat
+import subprocess
+import tempfile
+import unittest
+
+
+ROOT = Path(__file__).resolve().parents[2]
+INSTALLER = Path(os.environ.get("PULSE_INSTALLER_UNDER_TEST", ROOT / "install.sh"))
+
+HARNESS = r'''
+source "$INSTALLER"
+CONFIG_DIR="$FIXTURE/config"
+INSTALL_DIR="$FIXTURE/install"
+BINARY_LINK_PATH="$FIXTURE/link"
+AUTO_UPDATE_DEST="$FIXTURE/updater"
+UPDATE_HELPER_PATH="$FIXTURE/helper"
+UPDATE_SERVICE_PATH="$FIXTURE/units/$SERVICE-update.service"
+UPDATE_TIMER_PATH="$FIXTURE/units/$SERVICE-update.timer"
+UPDATE_SERVICE_UNIT="$SERVICE-update.service"
+UPDATE_TIMER_UNIT="$SERVICE-update.timer"
+SERVICE_NAME="$SERVICE"
+SERVICE_NAME_EXPLICIT="$CUSTOM"
+case "$LAYOUT" in
+ nested) CONFIG_DIR="$INSTALL_DIR/data" ;;
+ parent) INSTALL_DIR="$CONFIG_DIR/runtime" ;;
+ same) INSTALL_DIR="$CONFIG_DIR" ;;
+ symlink) INSTALL_DIR="$FIXTURE/install-link" ;;
+ helper-symlink) UPDATE_HELPER_PATH="$FIXTURE/config-link/.key" ;;
+ root) CONFIG_DIR=/ ;;
+esac
+IN_CONTAINER=true
+IN_DOCKER=false
+CURRENT_VERSION=v6.5.0
+FORCE_VERSION=""
+for fn in print_header check_root detect_os check_docker_environment; do
+ eval "$fn() { :; }"
+done
+check_existing_installation() { return 0; }
+detect_service_name() { echo "$SERVICE"; }
+resolve_latest_release_tag_for_channel() { :; }
+read_configured_update_channel() { echo stable; }
+curl() { :; }
+quiesce_pulse_for_removal() { echo QUIESCE >> "$FIXTURE/actions"; }
+cleanup_local_sensor_proxy() {
+ echo LEGACY >> "$FIXTURE/actions"
+ [[ "$FAULT" != legacy ]]
+}
+id() { [[ "$USER_PRESENT" == true && "$1" == pulse ]]; }
+userdel() {
+ echo USER_DELETE >> "$FIXTURE/actions"
+ [[ "$FAULT" != user ]]
+}
+systemctl() {
+ [[ "$*" == daemon-reload ]] || return 91
+ echo RELOAD >> "$FIXTURE/actions"
+ [[ "$FAULT" != reload ]]
+}
+timeout() {
+ # This suite's only timeout target is an inert shell service double; the
+ # existing Go suite independently exercises the real timeout executable.
+ if [[ "$1" == -k ]]; then shift 3; else shift; fi
+ "$@"
+}
+readlink() {
+ [[ "$FAULT" != path-read ]] || return 22
+ # Do not inspect the host's /etc. Mirror the fixed unit paths inside the
+ # fixture; all other canonicalization uses the real coreutils executable.
+ local path="${@: -1}"
+ case "$path" in
+ /etc/systemd/system/*) path="$FIXTURE/units/${path##*/}" ;;
+ esac
+ command readlink -m -- "$path"
+}
+rm() {
+ local path
+ for path in "$@"; do
+ case "$path" in -f|-rf|--) continue ;; esac
+ case "$path" in
+ /etc/systemd/system/*) path="$FIXTURE/units/${path##*/}" ;;
+ /var/log/pulse*.log|/opt/pulse.log)
+ echo LOG_DELETE >> "$FIXTURE/actions"
+ [[ "$FAULT" != log ]] || return 23
+ continue ;;
+ "$FIXTURE"/*) ;;
+ *) echo "UNSAFE_DELETE $path" >> "$FIXTURE/actions"; return 91 ;;
+ esac
+ echo "DELETE ${path#"$FIXTURE/"}" >> "$FIXTURE/actions"
+ if [[ "$FAULT" == delete && "$path" == "$FIXTURE/$TARGET" ]]; then
+ echo "fixture deletion failure" >&2
+ return 23
+ fi
+ if [[ "$FAULT" == partial-data && "$path" == "$CONFIG_DIR" ]]; then
+ /bin/rm -f -- "$CONFIG_DIR/system.json"
+ echo "fixture partial data deletion" >&2
+ return 24
+ fi
+ /bin/rm -rf -- "$path" || return 25
+ done
+}
+safe_read() { printf -v "$2" '%s' 2; }
+safe_read_with_default() {
+ case "$1" in
+ 'Remove all configuration'*) printf -v "$2" '%s' "$REMOVE_CONFIG" ;;
+ 'Remove pulse user'*) printf -v "$2" '%s' "$REMOVE_USER" ;;
+ *) return 92 ;;
+ esac
+}
+if [[ "$GUARDED" == true ]]; then
+ if [[ "$FLOW" == menu ]]; then main || exit $?; else uninstall_pulse || exit $?; fi
+else
+ if [[ "$FLOW" == menu ]]; then main; else uninstall_pulse; fi
+fi
+'''
+
+
+class ServerRemovalFailures(unittest.TestCase):
+ def exercise(self, flow, *, fault="normal", target="", guarded=True,
+ remove_config="y", remove_user="y", user_present=True,
+ custom=False, layout="separate"):
+ with tempfile.TemporaryDirectory(prefix="pulse-removal-failure-") as directory:
+ f = Path(directory)
+ service = "pulse-other" if custom else "pulse"
+ for name in ["install", "config", "units", "other-install", "other-config"]:
+ (f / name).mkdir(mode=0o700)
+ for name in ["install/pulse", "config/system.json", "config/.key",
+ "other-install/pulse", "other-config/system.json",
+ "other-config/.key", "link", "updater", "helper"]:
+ (f / name).write_bytes(("original-" + name).encode())
+ (f / name).chmod(0o600)
+ for unit in {service + ".service", service + "-update.service",
+ service + "-update.timer", "pulse.service", "pulse-backend.service"}:
+ (f / "units" / unit).write_text("original-" + unit)
+ (f / "install-link").symlink_to(f / "config", target_is_directory=True)
+ (f / "config-link").symlink_to(f / "config", target_is_directory=True)
+ config = f / "config"
+ if layout == "nested":
+ config.rename(f / "install/data")
+ config = f / "install/data"
+ elif layout == "parent":
+ (f / "install").rename(config / "runtime")
+ before = self.snapshot(config)
+ other_before = (self.snapshot(f / "other-install"), self.snapshot(f / "other-config"))
+ if fault == "permission":
+ (f / "units").chmod(0o500)
+ env = dict(os.environ, INSTALLER=str(INSTALLER), FIXTURE=str(f), FLOW=flow,
+ FAULT=fault, TARGET=target, GUARDED=str(guarded).lower(),
+ REMOVE_CONFIG=remove_config, REMOVE_USER=remove_user,
+ USER_PRESENT=str(user_present).lower(), SERVICE=service,
+ CUSTOM=str(custom).lower(), LAYOUT=layout)
+ try:
+ result = subprocess.run(["bash", "-c", HARNESS], env=env, text=True,
+ capture_output=True, timeout=10)
+ finally:
+ (f / "units").chmod(0o700)
+ actions = (f / "actions").read_text().splitlines()
+ self.assertFalse(any("UNSAFE" in action for action in actions), actions)
+ self.assertEqual(other_before, (self.snapshot(f / "other-install"),
+ self.snapshot(f / "other-config")))
+ return {"result": result, "actions": actions, "before": before,
+ "after": self.snapshot(config),
+ "runtime_present": (f / "install/pulse").exists()}
+
+ @staticmethod
+ def snapshot(directory):
+ if not directory.exists():
+ return None
+ return {str(p.relative_to(directory)): (stat.S_IMODE(p.stat().st_mode),
+ p.read_bytes() if p.is_file() else None)
+ for p in [directory, *sorted(directory.rglob("*"))]}
+
+ def assert_incomplete(self, evidence, *, preserves_config=True):
+ result = evidence["result"]
+ text = result.stdout + result.stderr
+ self.assertNotEqual(result.returncode, 0, text + str(evidence["actions"]))
+ self.assertNotIn("Pulse removed successfully", text)
+ self.assertNotIn("completely uninstalled", text)
+ self.assertNotIn("Configuration and data removed", text)
+ if preserves_config:
+ self.assertEqual(evidence["before"], evidence["after"], text)
+ self.assertNotIn("DELETE config", evidence["actions"])
+ self.assertFalse(any("start" in action for action in evidence["actions"]))
+
+ def test_each_runtime_deletion_failure_preserves_data_and_stops(self):
+ targets = ["units/pulse.service", "units/pulse-update.service",
+ "units/pulse-update.timer", "units/pulse-backend.service",
+ "link", "updater", "helper", "install"]
+ for flow in ("menu", "uninstall"):
+ for guarded in (False, True):
+ for target in targets:
+ with self.subTest(flow=flow, guarded=guarded, target=target):
+ e = self.exercise(flow, fault="delete", target=target, guarded=guarded)
+ self.assert_incomplete(e)
+ self.assertEqual(e["actions"][-1], "DELETE " + target)
+ self.assertIn("Cannot remove", e["result"].stderr)
+ self.assertIn("Some files may already have been removed", e["result"].stderr)
+
+ def test_reload_or_account_failure_preserves_data(self):
+ for flow in ("menu", "uninstall"):
+ for guarded in (False, True):
+ for fault, last in (("reload", "RELOAD"), ("user", "USER_DELETE")):
+ with self.subTest(flow=flow, guarded=guarded, fault=fault):
+ e = self.exercise(flow, fault=fault, guarded=guarded)
+ self.assert_incomplete(e)
+ self.assertEqual(e["actions"][-1], last)
+ self.assertIn("Configuration is retained", e["result"].stderr)
+
+ @unittest.skipIf(os.geteuid() == 0, "requires ordinary-user filesystem permissions")
+ def test_real_filesystem_permission_failure_preserves_data(self):
+ for flow in ("menu", "uninstall"):
+ for guarded in (False, True):
+ with self.subTest(flow=flow, guarded=guarded):
+ e = self.exercise(flow, fault="permission", guarded=guarded)
+ self.assert_incomplete(e)
+ self.assertEqual(e["actions"][-1], "DELETE units/pulse.service")
+ self.assertIn("Permission denied", e["result"].stderr)
+
+ def test_full_legacy_cleanup_failure_precedes_config_and_account_deletion(self):
+ for guarded in (False, True):
+ with self.subTest(guarded=guarded):
+ e = self.exercise("uninstall", fault="legacy", guarded=guarded)
+ self.assert_incomplete(e)
+ self.assertEqual(e["actions"][-1], "LEGACY")
+ self.assertNotIn("USER_DELETE", e["actions"])
+
+ def test_menu_log_failure_preserves_data(self):
+ for guarded in (False, True):
+ with self.subTest(guarded=guarded):
+ e = self.exercise("menu", fault="log", guarded=guarded)
+ self.assert_incomplete(e)
+ self.assertEqual(e["actions"][-1], "LOG_DELETE")
+
+ def test_partial_data_deletion_is_not_completion_or_intact_state(self):
+ for flow in ("menu", "uninstall"):
+ for guarded in (False, True):
+ with self.subTest(flow=flow, guarded=guarded):
+ e = self.exercise(flow, fault="partial-data", guarded=guarded)
+ self.assert_incomplete(e, preserves_config=False)
+ self.assertNotIn("system.json", e["after"])
+ self.assertEqual(e["after"][".key"], e["before"][".key"])
+ self.assertEqual(e["actions"][-1], "DELETE config")
+ self.assertNotIn("Configuration is retained", e["result"].stderr)
+
+ def test_data_is_last_on_success_for_both_entries_and_instances(self):
+ for flow in ("menu", "uninstall"):
+ for custom in (False, True):
+ for guarded in (False, True):
+ for user_present in (False, True):
+ with self.subTest(flow=flow, custom=custom, guarded=guarded,
+ user_present=user_present):
+ e = self.exercise(flow, custom=custom, guarded=guarded,
+ user_present=user_present)
+ self.assertEqual(e["result"].returncode, 0, e["result"].stderr)
+ self.assertIsNone(e["after"])
+ self.assertFalse(e["runtime_present"])
+ self.assertEqual(e["actions"][-1], "DELETE config")
+ self.assertEqual("USER_DELETE" in e["actions"], user_present)
+ self.assertIn("RELOAD", e["actions"])
+ self.assertIn("Pulse removed successfully" if flow == "menu" else
+ "completely uninstalled", e["result"].stdout)
+ if custom:
+ self.assertNotIn("DELETE units/pulse.service", e["actions"])
+ self.assertNotIn("DELETE units/pulse-backend.service", e["actions"])
+
+ def test_menu_preserves_declined_data_and_account(self):
+ for user_present in (False, True):
+ for guarded in (False, True):
+ with self.subTest(user_present=user_present, guarded=guarded):
+ e = self.exercise("menu", remove_config="n", remove_user="n",
+ user_present=user_present, guarded=guarded)
+ self.assertEqual(e["result"].returncode, 0, e["result"].stderr)
+ self.assertEqual(e["before"], e["after"])
+ self.assertNotIn("DELETE config", e["actions"])
+ self.assertNotIn("USER_DELETE", e["actions"])
+ self.assertIn("Configuration preserved", e["result"].stdout)
+
+ def test_unsafe_or_unreadable_layout_refuses_all_file_deletion(self):
+ for flow in ("menu", "uninstall"):
+ for layout in ("nested", "parent", "same", "symlink", "helper-symlink", "root", "separate"):
+ with self.subTest(flow=flow, layout=layout):
+ e = self.exercise(flow, layout=layout,
+ fault="path-read" if layout == "separate" else "normal")
+ self.assert_incomplete(e)
+ self.assertEqual(e["actions"], ["QUIESCE"])
+
+
+if __name__ == "__main__":
+ unittest.main()