Fix post-merge audit findings; unify staging teardown
Audit ----- - create_task.py verify failed on a DEFAULT install. hook_status.json emitted a per-file entry for the nested module with ok:false whenever the feature was switched off -- the default -- so verify printed [FAIL] and exited 1, right after the README tells users to run it. Status is now per MODULE with an `active` flag, and verify renders an inactive module as [SKIP]. - A partial apply suppressed the middlewared restart. The exit code conflated "nothing applied" with "one module applied, one failed", so a failing providers patch would prevent the restart that a freshly-applied nested patch needs, leaving it on disk and never loaded. Exit 2 now means partial and the restart still fires. - The native-nested probe could never fire. It scanned crud.py for the guard message, but our own injected block quotes that message, so once applied the probe would always conclude the guard was still present. It now reads only the stock portion of the file. - recover.sh did not unmount staging trees, so an emergency recovery left bind mounts pinning ZFS snapshots that could then never be destroyed. - uninstall.sh deleted sidecar files without reading them. A sidecar is the only record that an interrupted run's snapshot tree is still on disk; both scripts now name the snapshot before clearing it. - Removed a dead branch in the restart gate (unreachable: the kill switch exits). Refactor -------- - Staging teardown had been copy-pasted into uninstall.sh and recover.sh -- two untested shell copies of the fiddly depth-ordering and lazy-umount logic. Both now call `python3 patch/truecloud_nested.py cleanup`, so there is exactly one implementation and it is the one under test. - Dropped the in-memory ACTIVE dict. The sidecar file was already the source of truth; a second in-process record could only desync -- and it is precisely the middlewared-restart case (which empties it) that must not orphan a snapshot tree. One record, on disk, or none. Not done: the overlay-unmount loop is duplicated across apply.sh/uninstall.sh/ recover.sh. It is pre-existing, and apply.sh runs at PREINIT under a tight timeout -- giving it a source dependency would trade 10 lines of duplication for a boot-time failure mode. 74 tests, ruff and shellcheck clean.
This commit is contained in:
+13
-1
@@ -127,13 +127,21 @@ def cmd_verify():
|
||||
print(f"Hook status (recorded at {status.get('patched_at', 'unknown')})")
|
||||
print()
|
||||
all_ok = True
|
||||
any_active = False
|
||||
for module, info in status.get("patches", {}).items():
|
||||
ok = info.get("ok", False)
|
||||
# A module can be inactive because TrueNAS now does it natively, or
|
||||
# because it is opt-in and switched off. Neither is a failure.
|
||||
active = info.get("active", True)
|
||||
label = "OK " if ok else "FAIL"
|
||||
if ok and not active:
|
||||
label = "SKIP"
|
||||
detail = f" — {info['detail']}" if info.get("detail") else ""
|
||||
print(f" [{label}] {module}{detail}")
|
||||
if not ok:
|
||||
all_ok = False
|
||||
if active:
|
||||
any_active = True
|
||||
|
||||
# The disk status alone can false-positive: at boot the files are patched
|
||||
# while middlewared is already running with the stock modules imported.
|
||||
@@ -146,7 +154,11 @@ def cmd_verify():
|
||||
mw_start = _middlewared_start_epoch()
|
||||
|
||||
proc_stale = False
|
||||
if patched_epoch is None or mw_start is None:
|
||||
if not any_active:
|
||||
# Nothing is patched into middlewared, so whether it restarted since is
|
||||
# irrelevant -- there is nothing for it to have loaded.
|
||||
print(" [-- ] running middlewared process — no active module; nothing to load")
|
||||
elif patched_epoch is None or mw_start is None:
|
||||
print(" [?? ] running middlewared process — could not compare start time;")
|
||||
print(" the results above reflect the on-disk state only")
|
||||
elif mw_start + 2 < patched_epoch:
|
||||
|
||||
Reference in New Issue
Block a user