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:
@@ -144,6 +144,24 @@ class TestIndependentModules:
|
||||
i = sh.index("--- UI patch ---")
|
||||
assert '[ "$_providers_needed" = "0" ]' in sh[i:i + 400]
|
||||
|
||||
def test_status_reports_an_inactive_module_as_ok(self):
|
||||
# `create_task.py verify` fails if any patches[*].ok is false. An opt-in
|
||||
# module that is switched off (the DEFAULT) must not report FAIL, or a
|
||||
# stock install fails verification out of the box.
|
||||
src = heredoc_source()
|
||||
assert "'ok': (not nested_needed) or nested_ok" in src
|
||||
assert "'ok': (not providers_needed) or bool(b2_ok and restic_ok)" in src
|
||||
assert "'active': nested_needed" in src
|
||||
|
||||
def test_nested_native_probe_ignores_our_own_block(self):
|
||||
# CRUD_BLOCK quotes the guard message, so scanning the whole file would
|
||||
# find the string in our own patch and never detect native support.
|
||||
sh = self._sh()
|
||||
assert "split('\\n# TRUECLOUD_PATCH', 1)[0]" in sh
|
||||
assert "no further nesting" in extract_blocks()["CRUD_BLOCK"], (
|
||||
"if this ever stops being true, the probe comment is stale"
|
||||
)
|
||||
|
||||
def test_restart_fires_when_any_needed_module_landed(self):
|
||||
# Keying the restart off providers alone would leave a freshly-patched
|
||||
# nested module on disk and never loaded on a native-B2 box.
|
||||
@@ -153,6 +171,18 @@ class TestIndependentModules:
|
||||
assert '_backend_ok' in tail
|
||||
assert '"$_b2_ok"' not in tail
|
||||
|
||||
def test_partial_failure_still_schedules_the_restart(self):
|
||||
# If providers fails but nested landed (or vice versa), something new IS
|
||||
# on disk. Collapsing that into "nothing to do" would leave the module
|
||||
# that succeeded permanently unloaded.
|
||||
src = heredoc_source()
|
||||
assert "sys.exit(2 if _landed else 1)" in src
|
||||
assert "_landed = (providers_needed and b2_ok and restic_ok) or (nested_needed and nested_ok)" in src
|
||||
|
||||
sh = self._sh()
|
||||
assert '_rc=$?' in sh
|
||||
assert '[ "$_rc" = "2" ]' in sh
|
||||
|
||||
|
||||
class TestOptIn:
|
||||
"""Nested-snapshot support must be opt-in and must never self-enable."""
|
||||
|
||||
Reference in New Issue
Block a user