Fix Fabric recovery and readback diagnostics
parent
63b4741ff2
commit
a45a0da682
@ -0,0 +1,338 @@
|
||||
"""Execute the production-rendered final readback with real CLI serialization.
|
||||
|
||||
Only external tools are replaced. The final shell body, nft owner checks,
|
||||
tenant-set matcher and firewall-zone enumerator are the production code.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from virsh_panel.fabric import (
|
||||
_FABRIC_NFT_VALIDATION_SH,
|
||||
_FABRIC_WG_READBACK_SH,
|
||||
_BOOT_HELPER,
|
||||
_FIREWALL_MODE_GUARD_SH,
|
||||
_TRANSACTION_SCRIPT,
|
||||
_VPC_STATE_LOADER,
|
||||
_apply_script,
|
||||
_config_text,
|
||||
_nft_rules_text,
|
||||
parse_fabric_plan,
|
||||
)
|
||||
|
||||
|
||||
def _between(text: str, start: str, end: str) -> str:
|
||||
begin = text.index(start)
|
||||
return text[begin:text.index(end, begin)]
|
||||
|
||||
|
||||
_TOOLS = r'''import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
root = Path(os.environ["VC_FINAL_ROOT"])
|
||||
name = Path(sys.argv[0]).name
|
||||
args = sys.argv[1:]
|
||||
with (root / "calls").open("a", encoding="utf-8") as log:
|
||||
log.write(json.dumps([name, *args]) + "\n")
|
||||
fixture = json.loads((root / "responses").read_text())
|
||||
call = json.dumps([name, *args])
|
||||
if call not in fixture:
|
||||
print("unexpected test tool invocation", file=sys.stderr)
|
||||
raise SystemExit(99)
|
||||
if name == "wg" and args == ["pubkey"]:
|
||||
if sys.stdin.read() != "test-only-private-identity\n":
|
||||
raise SystemExit(98)
|
||||
response = fixture[call]
|
||||
sys.stdout.write(response["stdout"])
|
||||
raise SystemExit(response["status"])
|
||||
'''
|
||||
|
||||
|
||||
class FinalFixture:
|
||||
def __init__(self, tmp_path: Path, manager: str, peers: int = 1):
|
||||
self.root = tmp_path
|
||||
self.manager = manager
|
||||
self.plan = parse_fabric_plan({
|
||||
"fabric_id": "final-readback", "region": "hk",
|
||||
"overlay_cidr": "100.64.1.0/24", "revision": 1,
|
||||
"nodes": [
|
||||
{"host_id": str(index), "overlay_ip": f"100.64.1.{index}",
|
||||
"endpoint": f"203.0.113.{index}:51820"}
|
||||
for index in range(1, peers + 2)
|
||||
],
|
||||
})
|
||||
self.keys = {
|
||||
node.host_id: base64.b64encode(bytes([index]) * 32).decode()
|
||||
for index, node in enumerate(self.plan.nodes, 1)
|
||||
}
|
||||
self.responses: dict[str, dict[str, object]] = {}
|
||||
self.routes = ""
|
||||
tool = tmp_path / "tool"
|
||||
tool.write_text(f"#!{sys.executable}\n" + _TOOLS, encoding="utf-8")
|
||||
tool.chmod(0o700)
|
||||
for name in ("ip", "wg", "nft", "firewall-cmd"):
|
||||
(tmp_path / name).symlink_to(tool)
|
||||
(tmp_path / "private").write_text("test-only-private-identity\n")
|
||||
(tmp_path / "config").write_text(_config_text(
|
||||
self.plan, self.plan.nodes[0], self.keys, "firewalld_nft"))
|
||||
for filename in ("vpc-peers", "vpc-routes", "vpc-tenants"):
|
||||
(tmp_path / filename).write_text("")
|
||||
|
||||
self.respond("nft", ["-s", "list", "table", "inet",
|
||||
"virt_cloud_wg_fabric"],
|
||||
_nft_rules_text(self.plan.digest))
|
||||
self.respond("nft", ["list", "set", "inet", "virt_cloud_wg_fabric",
|
||||
"vpc_tenant_ips"],
|
||||
"table inet virt_cloud_wg_fabric {\n"
|
||||
"\tset vpc_tenant_ips {\n\t\ttype ipv4_addr\n"
|
||||
"\t\tflags interval\n\t}\n}\n")
|
||||
self.respond("wg", ["show", "wg-fabric0"], "")
|
||||
self.respond("wg", ["pubkey"], self.keys["1"] + "\n")
|
||||
self.respond("wg", ["show", "wg-fabric0", "public-key"],
|
||||
self.keys["1"] + "\n")
|
||||
self.respond("wg", ["show", "wg-fabric0", "listen-port"], "51820\n")
|
||||
self.respond("ip", ["-o", "link", "show", "dev", "wg-fabric0"],
|
||||
"16: wg-fabric0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 "
|
||||
"qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000\n")
|
||||
# ip -o replaces the line break between address and lifetime by a
|
||||
# backslash. The entire address record must remain one physical line.
|
||||
self.respond("ip", ["-o", "-4", "address", "show", "dev", "wg-fabric0"],
|
||||
"16: wg-fabric0 inet 100.64.1.1/32 scope global wg-fabric0\\"
|
||||
" valid_lft forever preferred_lft forever\n")
|
||||
live_peers = self.plan.nodes[1:]
|
||||
self.respond("wg", ["show", "wg-fabric0", "peers"],
|
||||
"".join(self.keys[node.host_id] + "\n" for node in live_peers))
|
||||
self.respond("wg", ["show", "wg-fabric0", "endpoints"],
|
||||
"".join(self.keys[node.host_id] + "\t" + node.endpoint + "\n"
|
||||
for node in reversed(live_peers)))
|
||||
self.respond("wg", ["show", "wg-fabric0", "allowed-ips"],
|
||||
"".join(self.keys[node.host_id] + "\t" + node.allowed_ip + "\n"
|
||||
for node in reversed(live_peers)))
|
||||
metric = " metric 50" if manager == "networkmanager_nmcli" else ""
|
||||
self.routes = "".join(node.overlay_ip + " scope link" + metric + "\n"
|
||||
for node in live_peers)
|
||||
self.routes += ("local 100.64.1.1 table local proto kernel scope host "
|
||||
"src 100.64.1.1\n")
|
||||
self.respond("ip", ["-o", "route", "show", "table", "all", "dev",
|
||||
"wg-fabric0"], self.routes)
|
||||
for node in live_peers:
|
||||
self.respond("ip", ["route", "get", node.overlay_ip,
|
||||
"from", "100.64.1.1"],
|
||||
node.overlay_ip + " from 100.64.1.1 dev wg-fabric0 uid 0\n"
|
||||
" cache\n")
|
||||
for permanent in (False, True):
|
||||
prefix = ["--permanent"] if permanent else []
|
||||
self.respond("firewall-cmd", prefix + ["--get-zones"], "public trusted\n")
|
||||
for zone in ("public", "trusted"):
|
||||
active = not permanent and zone == "trusted"
|
||||
self.respond("firewall-cmd", prefix + [f"--zone={zone}",
|
||||
"--query-interface=wg-fabric0"],
|
||||
"yes\n" if active else "no\n", 0 if active else 1)
|
||||
|
||||
def respond(self, tool: str, args: list[str], stdout: str, status: int = 0):
|
||||
self.responses[json.dumps([tool, *args])] = {
|
||||
"stdout": stdout, "status": status,
|
||||
}
|
||||
|
||||
def add_vpc_member(self):
|
||||
key = self.keys["2"]
|
||||
(self.root / "vpc-peers").write_text(key + "|10.1.0.3/32\n")
|
||||
(self.root / "vpc-tenants").write_text("10.1.0.3/32\n")
|
||||
(self.root / "vpc-routes").write_text(
|
||||
"10.1.0.3/32|wg-fabric0|100|100.64.1.2|100\n")
|
||||
self.respond("nft", ["-s", "list", "table", "inet", "virt_cloud_wg_fabric"],
|
||||
_nft_rules_text(self.plan.digest).replace(
|
||||
"flags interval;", "flags interval;\n elements = { 10.1.0.3 }", 1))
|
||||
self.respond("nft", ["list", "set", "inet", "virt_cloud_wg_fabric", "vpc_tenant_ips"],
|
||||
"table inet virt_cloud_wg_fabric {\n\tset vpc_tenant_ips {\n"
|
||||
"\t\ttype ipv4_addr\n\t\tflags interval\n"
|
||||
"\t\telements = { 10.1.0.3 }\n\t}\n}\n")
|
||||
self.respond("ip", ["-o", "route", "show", "table", "all", "dev", "wg-fabric0"],
|
||||
self.routes + "10.1.0.3 via 100.64.1.2 table 100 proto 186 metric 100\n")
|
||||
|
||||
def run(self):
|
||||
rendered = _apply_script(
|
||||
self.plan, self.plan.nodes[0], self.keys,
|
||||
deployment_mode=self.manager, firewall_mode="firewalld_nft")
|
||||
final = _between(rendered, "vc_fabric_operation_checkpoint final_readback\n",
|
||||
"_txn_state_tmp=$(mktemp")
|
||||
final = final.split("\n", 1)[1]
|
||||
functions = "\n".join((
|
||||
_FABRIC_NFT_VALIDATION_SH,
|
||||
_FABRIC_WG_READBACK_SH,
|
||||
_between(_TRANSACTION_SCRIPT, "nft_panel_owned() {", "snapshot_file() {"),
|
||||
_between(_VPC_STATE_LOADER, "vpc_state_allowed_for_peer() {",
|
||||
"vpc_state_route_owned() {"),
|
||||
_VPC_STATE_LOADER[_VPC_STATE_LOADER.index("vpc_state_nft_set_matches() {"):],
|
||||
_between(_FIREWALL_MODE_GUARD_SH, "vc_firewall_zone() {",
|
||||
"vc_firewall_zone_exists() {"),
|
||||
))
|
||||
env = {**os.environ, "VC_FINAL_ROOT": str(self.root),
|
||||
"IFACE": "wg-fabric0", "EXPECTED_DIGEST": self.plan.digest,
|
||||
"FIREWALL_MODE": "firewalld_nft",
|
||||
"MANAGED_PEERS": " ".join(self.keys[n.host_id] for n in self.plan.nodes[1:]),
|
||||
"MANAGED_ROUTES": " ".join(n.allowed_ip for n in self.plan.nodes[1:]),
|
||||
"KEY": str(self.root / "private"), "CONF": str(self.root / "config"),
|
||||
"VPC_PEER_FILE": str(self.root / "vpc-peers"),
|
||||
"VPC_ROUTE_FILE": str(self.root / "vpc-routes"),
|
||||
"VPC_TENANT_FILE": str(self.root / "vpc-tenants")}
|
||||
env.update({name: str(self.root / tool) for name, tool in (
|
||||
("WG", "wg"), ("IP", "ip"), ("NFT", "nft"),
|
||||
("FIREWALL_CMD", "firewall-cmd"))})
|
||||
(self.root / "responses").write_text(json.dumps(self.responses))
|
||||
result = subprocess.run(["/bin/sh", "-eu", "-c", functions + "\n" + final],
|
||||
capture_output=True, text=True, env=env, check=False)
|
||||
assert "unexpected test tool invocation" not in result.stderr
|
||||
return result
|
||||
|
||||
|
||||
@pytest.mark.parametrize("manager", ["ifupdown", "networkmanager_nmcli"])
|
||||
@pytest.mark.parametrize("peers", [1, 2])
|
||||
def test_actual_final_slice_accepts_debian_and_alma_serialization(tmp_path, manager, peers):
|
||||
fixture = FinalFixture(tmp_path, manager, peers)
|
||||
if manager == "networkmanager_nmcli":
|
||||
rules = _nft_rules_text(fixture.plan.digest).replace(
|
||||
"hook output priority -100;", "hook output priority dstnat;")
|
||||
rules = "\n".join(line.replace(" ", "\t") for line in rules.splitlines()) + "\n"
|
||||
fixture.respond("nft", ["-s", "list", "table", "inet",
|
||||
"virt_cloud_wg_fabric"], rules)
|
||||
result = fixture.run()
|
||||
assert result.returncode == 0, result.stderr
|
||||
|
||||
|
||||
@pytest.mark.parametrize("drift", ["nft", "public-key", "listen-port", "down", "address",
|
||||
"extra-peer", "endpoint", "allowed", "route", "path", "zone"])
|
||||
def test_actual_final_slice_rejects_mutable_readback_drift(tmp_path, drift):
|
||||
fixture = FinalFixture(tmp_path, "ifupdown")
|
||||
key = fixture.keys["2"]
|
||||
if drift == "nft":
|
||||
fixture.respond("nft", ["-s", "list", "table", "inet", "virt_cloud_wg_fabric"],
|
||||
_nft_rules_text(fixture.plan.digest).replace("counter drop", "counter accept", 1))
|
||||
elif drift in ("public-key", "listen-port"):
|
||||
fixture.respond("wg", ["show", "wg-fabric0", drift], "wrong\n")
|
||||
elif drift == "down":
|
||||
fixture.respond("ip", ["-o", "link", "show", "dev", "wg-fabric0"],
|
||||
"16: wg-fabric0: <POINTOPOINT,NOARP> mtu 1420\n")
|
||||
elif drift == "address":
|
||||
fixture.respond("ip", ["-o", "-4", "address", "show", "dev", "wg-fabric0"],
|
||||
"16: wg-fabric0 inet 100.64.1.1/24 scope global wg-fabric0\n")
|
||||
elif drift == "extra-peer":
|
||||
fixture.respond("wg", ["show", "wg-fabric0", "peers"], key + "\nforeign\n")
|
||||
elif drift == "endpoint":
|
||||
fixture.respond("wg", ["show", "wg-fabric0", "endpoints"], key + "\t203.0.113.9:51820\n")
|
||||
elif drift == "allowed":
|
||||
fixture.respond("wg", ["show", "wg-fabric0", "allowed-ips"], key + "\t100.64.1.9/32\n")
|
||||
elif drift == "route":
|
||||
fixture.respond("ip", ["-o", "route", "show", "table", "all", "dev", "wg-fabric0"],
|
||||
fixture.routes + "100.64.1.3 scope link\n")
|
||||
elif drift == "path":
|
||||
fixture.respond("ip", ["route", "get", "100.64.1.2", "from", "100.64.1.1"],
|
||||
"100.64.1.2 from 100.64.1.1 dev br0 uid 0\n cache\n")
|
||||
else:
|
||||
fixture.respond("firewall-cmd", ["--zone=trusted", "--query-interface=wg-fabric0"], "no\n", 1)
|
||||
result = fixture.run()
|
||||
assert result.returncode in (71, 78), result.stderr
|
||||
|
||||
|
||||
@pytest.mark.parametrize("manager", ["ifupdown", "networkmanager_nmcli"])
|
||||
@pytest.mark.parametrize("reverse", [False, True])
|
||||
@pytest.mark.parametrize("peers", [1, 2])
|
||||
def test_actual_final_slice_accepts_official_multiple_allowed_ips_serialization(tmp_path, manager, reverse, peers):
|
||||
fixture = FinalFixture(tmp_path, manager, peers)
|
||||
key = fixture.keys["2"]
|
||||
fixture.add_vpc_member()
|
||||
prefixes = ["100.64.1.2/32", "10.1.0.3/32"]
|
||||
if reverse:
|
||||
prefixes.reverse()
|
||||
fixture.respond("wg", ["show", "wg-fabric0", "allowed-ips"],
|
||||
key + "\t" + " ".join(prefixes) + "\n" + "".join(
|
||||
fixture.keys[node.host_id] + "\t" + node.allowed_ip + "\n"
|
||||
for node in fixture.plan.nodes[2:]))
|
||||
assert fixture.run().returncode == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("drift", ["missing", "extra", "duplicate", "unknown", "multiple-key-fields"])
|
||||
def test_actual_final_slice_requires_complete_unique_peer_records(tmp_path, drift):
|
||||
fixture = FinalFixture(tmp_path, "ifupdown", 2)
|
||||
first, second = fixture.keys["2"], fixture.keys["3"]
|
||||
if drift == "missing":
|
||||
actual = first + "\n"
|
||||
elif drift == "extra":
|
||||
actual = first + "\n" + second + "\n" + base64.b64encode(bytes([9]) * 32).decode() + "\n"
|
||||
elif drift == "duplicate":
|
||||
actual = first + "\n" + second + "\n" + first + "\n"
|
||||
elif drift == "unknown":
|
||||
actual = first + "\n" + "bad-key\n"
|
||||
else:
|
||||
actual = first + "\t" + second + "\n"
|
||||
fixture.respond("wg", ["show", "wg-fabric0", "peers"], actual)
|
||||
assert fixture.run().returncode == 71
|
||||
|
||||
|
||||
@pytest.mark.parametrize("drift", ["wide", "public", "duplicate", "missing", "extra", "csv",
|
||||
"malformed", "ipv6", "duplicate-peer", "unknown-peer"])
|
||||
def test_actual_final_slice_multiple_allowed_ips_remains_fail_closed(tmp_path, drift):
|
||||
fixture = FinalFixture(tmp_path, "ifupdown")
|
||||
key = fixture.keys["2"]
|
||||
fixture.add_vpc_member()
|
||||
values = ["100.64.1.2/32", "10.1.0.3/32"]
|
||||
if drift == "wide":
|
||||
values[1] = "10.1.0.3/24"
|
||||
elif drift == "public":
|
||||
values[1] = "203.0.113.9/32"
|
||||
elif drift == "duplicate":
|
||||
values.append(values[1])
|
||||
elif drift == "missing":
|
||||
values.pop()
|
||||
elif drift == "extra":
|
||||
values.append("10.1.0.4/32")
|
||||
elif drift == "malformed":
|
||||
values[1] = "10.1.0.256/32"
|
||||
elif drift == "ipv6":
|
||||
values[1] = "fd00::3/128"
|
||||
actual = key + "\t" + ("," if drift == "csv" else " ").join(values) + "\n"
|
||||
if drift == "duplicate-peer":
|
||||
actual += actual
|
||||
elif drift == "unknown-peer":
|
||||
actual += base64.b64encode(bytes([9]) * 32).decode() + "\t10.1.0.9/32\n"
|
||||
fixture.respond("wg", ["show", "wg-fabric0", "allowed-ips"], actual)
|
||||
assert fixture.run().returncode == 71
|
||||
|
||||
|
||||
@pytest.mark.parametrize("peers", [1, 2])
|
||||
@pytest.mark.parametrize("reverse", [False, True])
|
||||
@pytest.mark.parametrize("vpc", [False, True])
|
||||
def test_boot_actual_peer_readback_uses_identical_record_validator(tmp_path, peers, reverse, vpc):
|
||||
fixture = FinalFixture(tmp_path, "ifupdown", peers)
|
||||
if vpc:
|
||||
fixture.add_vpc_member()
|
||||
fixture.respond("wg", ["show", "wg-fabric0", "allowed-ips"],
|
||||
fixture.keys["2"] + "\t10.1.0.3/32 100.64.1.2/32\n" + "".join(
|
||||
fixture.keys[node.host_id] + "\t" + node.allowed_ip + "\n"
|
||||
for node in fixture.plan.nodes[2:]))
|
||||
live_keys = [fixture.keys[node.host_id] for node in fixture.plan.nodes[1:]]
|
||||
if reverse:
|
||||
live_keys.reverse()
|
||||
fixture.respond("wg", ["show", "wg-fabric0", "peers"], "\n".join(live_keys) + "\n")
|
||||
(tmp_path / "responses").write_text(json.dumps(fixture.responses))
|
||||
peer_body = _between(_BOOT_HELPER, 'actual_peers=$("$WG" show "$IFACE" peers',
|
||||
"actual_fabric_routes=")
|
||||
allowed = _between(_VPC_STATE_LOADER, "vpc_state_allowed_for_peer() {",
|
||||
"vpc_state_route_owned() {")
|
||||
result = subprocess.run(["/bin/sh", "-eu", "-c", _FABRIC_WG_READBACK_SH + "\n" + allowed + "\n" + peer_body],
|
||||
capture_output=True, text=True, check=False,
|
||||
env={**os.environ, "VC_FINAL_ROOT": str(tmp_path),
|
||||
"WG": str(tmp_path / "wg"), "IFACE": "wg-fabric0",
|
||||
"seen_peers": " ".join(live_keys),
|
||||
"CONF": str(tmp_path / "config"),
|
||||
"VPC_PEER_FILE": str(tmp_path / "vpc-peers")})
|
||||
assert result.returncode == 0, result.stderr
|
||||
@ -0,0 +1,243 @@
|
||||
"""Execute rendered async journal plumbing without running host mutations.
|
||||
|
||||
The runner, update state machine, logger, helper EXIT trap and committed
|
||||
rollback branch are production-rendered code. Only stat's platform-specific
|
||||
ownership report and sync are external-tool doubles inside temporary files.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from virsh_panel.fabric import (
|
||||
FABRIC_OPERATION_ROOT,
|
||||
_TRANSACTION_SCRIPT,
|
||||
_apply_script,
|
||||
_fabric_operation_runner_script,
|
||||
_fabric_operation_update_script,
|
||||
parse_fabric_plan,
|
||||
)
|
||||
|
||||
|
||||
_SECRET = "NEVER_LOG_raw_private_fixture_or_sensitive_path"
|
||||
_OPERATION = "a" * 32
|
||||
_DIGEST = "b" * 64
|
||||
|
||||
|
||||
def _write(path: Path, body: str, mode: int = 0o700):
|
||||
path.write_text(body, encoding="utf-8")
|
||||
path.chmod(mode)
|
||||
|
||||
|
||||
def _render(manager="ifupdown", firewall="firewalld_nft"):
|
||||
plan = parse_fabric_plan({
|
||||
"fabric_id": "safe-log-test", "region": "hk",
|
||||
"overlay_cidr": "100.64.1.0/24", "revision": 1,
|
||||
"nodes": [
|
||||
{"host_id": "a", "overlay_ip": "100.64.1.1",
|
||||
"endpoint": "203.0.113.1:51820"},
|
||||
{"host_id": "b", "overlay_ip": "100.64.1.2",
|
||||
"endpoint": "203.0.113.2:51820"},
|
||||
],
|
||||
})
|
||||
keys = {node.host_id: base64.b64encode(bytes([index]) * 32).decode()
|
||||
for index, node in enumerate(plan.nodes, 1)}
|
||||
return _apply_script(plan, plan.nodes[0], keys,
|
||||
deployment_mode=manager, firewall_mode=firewall)
|
||||
|
||||
|
||||
def _apply_logger(rendered):
|
||||
start = rendered.index("vc_fabric_apply_failure_log() {")
|
||||
return rendered[start:rendered.index("vc_fabric_operation_checkpoint() {", start)]
|
||||
|
||||
|
||||
def _helper_entry(rendered):
|
||||
# This is the helper actually embedded in apply, not a retyped logger.
|
||||
start = rendered.index("#!/bin/sh\n# virt-cloud-wg-fabric-v1\n# fabric-plan-digest=")
|
||||
end = rendered.index("BASE=/etc/virt-cloud\n", start)
|
||||
prefix = rendered[start:end]
|
||||
assert "__VC_FABRIC_DIGEST__" not in prefix
|
||||
assert "trap cleanup EXIT HUP INT TERM\n" in prefix
|
||||
return prefix
|
||||
|
||||
|
||||
def _run(script, *, env=None, args=()):
|
||||
return subprocess.run(["/bin/sh", "-eu", "-c", script, "safe-log-test", *args],
|
||||
capture_output=True, text=True, check=False,
|
||||
env={**os.environ, **(env or {})})
|
||||
|
||||
|
||||
def _journal_wrapper(body):
|
||||
return ("exec 3>&1\nexec >/dev/null 2>&1\n"
|
||||
"VC_FABRIC_SAFE_LOG=1\nexport VC_FABRIC_SAFE_LOG\n" + body)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("detail", [
|
||||
"entry", "final_acl", "final_tenants", "final_identity", "final_link",
|
||||
"final_addresses", "final_peers", "final_endpoints", "final_allowed_ips",
|
||||
"final_routes", "final_overlay_paths", "final_zone", "commit", "convergence",
|
||||
"complete",
|
||||
])
|
||||
def test_rendered_apply_logger_has_one_fixed_fd3_record(detail):
|
||||
script = _journal_wrapper(_apply_logger(_render()) + (
|
||||
f"VC_FABRIC_APPLY_DETAIL={shlex.quote(detail)}\n"
|
||||
f"printf '%s\\n' {shlex.quote(_SECRET)}\n"
|
||||
f"printf '%s\\n' {shlex.quote(_SECRET)} >&2\n"
|
||||
"vc_fabric_apply_failure_log 71\n"
|
||||
))
|
||||
result = _run(script)
|
||||
assert result.returncode == 0
|
||||
assert result.stdout == (
|
||||
f"virt-cloud-fabric apply_state=failed apply_check={detail} exit_status=71\n")
|
||||
assert result.stderr == ""
|
||||
|
||||
|
||||
@pytest.mark.parametrize("logger", ["apply", "helper"])
|
||||
@pytest.mark.parametrize("status", ["", "-1", "256", "9" * 100, _SECRET])
|
||||
def test_unknown_phase_and_invalid_status_are_sanitized(logger, status):
|
||||
rendered = _render()
|
||||
phase = "unknown\n" + _SECRET + "=/sensitive/path"
|
||||
if logger == "apply":
|
||||
body = (_apply_logger(rendered)
|
||||
+ f"VC_FABRIC_APPLY_DETAIL={shlex.quote(phase)}\n"
|
||||
+ f"vc_fabric_apply_failure_log {shlex.quote(status)}\n")
|
||||
line = "virt-cloud-fabric apply_state=failed apply_check=unknown exit_status=1\n"
|
||||
else:
|
||||
body = (_helper_entry(rendered)
|
||||
+ f"VC_FABRIC_HELPER_PHASE={shlex.quote(phase)}\n"
|
||||
+ f"vc_fabric_helper_failure_log {shlex.quote(status)}\nexit 0\n")
|
||||
line = "virt-cloud-fabric helper_state=failed helper_phase=unknown exit_status=1\n"
|
||||
result = _run(_journal_wrapper(body))
|
||||
assert result.returncode == 0
|
||||
assert result.stdout == line
|
||||
assert result.stderr == ""
|
||||
assert _SECRET not in result.stdout
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status", [1, 70, 71, 79, 127, 143, 255])
|
||||
def test_rendered_child_helper_preserves_exit_status_without_duplicate_fd3_log(status):
|
||||
body = (_helper_entry(_render()) + "VC_FABRIC_HELPER_PHASE=final\n"
|
||||
+ f"printf '%s\\n' {shlex.quote(_SECRET)}\n"
|
||||
+ f"printf '%s\\n' {shlex.quote(_SECRET)} >&2\n"
|
||||
+ f"exit {status}\n")
|
||||
result = _run(_journal_wrapper(body))
|
||||
assert result.returncode == status
|
||||
assert result.stdout == (
|
||||
f"virt-cloud-fabric helper_state=failed helper_phase=final exit_status={status}\n")
|
||||
assert result.stderr == ""
|
||||
|
||||
|
||||
def _runner_fixture(tmp_path: Path, apply_body: str):
|
||||
directory = tmp_path / _OPERATION
|
||||
directory.mkdir(mode=0o700)
|
||||
stat_tool = tmp_path / "stat"
|
||||
_write(stat_tool, f"#!{sys.executable}\n" + (
|
||||
"import os, stat, sys\n"
|
||||
"assert sys.argv[1:3] == ['-c', '%u:%a']\n"
|
||||
"print('0:' + format(stat.S_IMODE(os.stat(sys.argv[3]).st_mode), 'o'))\n"
|
||||
))
|
||||
sync_tool = tmp_path / "sync"
|
||||
_write(sync_tool, "#!/bin/sh\nexit 0\n")
|
||||
updater = _fabric_operation_update_script(_OPERATION, _DIGEST).replace(
|
||||
FABRIC_OPERATION_ROOT, str(tmp_path)).replace(
|
||||
"stat -c", shlex.quote(str(stat_tool)) + " -c").replace(
|
||||
"\nsync\n", "\n" + shlex.quote(str(sync_tool)) + "\n")
|
||||
_write(directory / "update", updater)
|
||||
_write(directory / "apply", "#!/bin/sh\n" + apply_body)
|
||||
_write(directory / "manifest", (
|
||||
f"schema=1\noperation_id={_OPERATION}\nplan_digest={_DIGEST}\n"), 0o600)
|
||||
now = int(time.time())
|
||||
_write(directory / "status", (
|
||||
f"schema=1\noperation_id={_OPERATION}\nstatus=queued\nphase=apply\n"
|
||||
"checkpoint=dispatch\nreason=none\n"
|
||||
f"created_at={now}\nstarted_at=0\nupdated_at={now}\nfinished_at=0\n"), 0o600)
|
||||
runner = _fabric_operation_runner_script(_OPERATION, _DIGEST).replace(
|
||||
FABRIC_OPERATION_ROOT, str(tmp_path))
|
||||
return runner, directory
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status", [0, 71, 79])
|
||||
def test_rendered_runner_propagates_safe_descriptor_and_never_raw_output(tmp_path, status):
|
||||
helper = tmp_path / "child-helper"
|
||||
_write(helper, _helper_entry(_render()) + (
|
||||
"VC_FABRIC_HELPER_PHASE=gate\n"
|
||||
f"printf '%s\\n' {shlex.quote(_SECRET)}\n"
|
||||
f"printf '%s\\n' {shlex.quote(_SECRET)} >&2\nexit {status}\n"
|
||||
))
|
||||
body = (f"printf '%s\\n' {shlex.quote(_SECRET)}\n"
|
||||
+ f"printf '%s\\n' {shlex.quote(_SECRET)} >&2\n"
|
||||
+ f"exec /bin/sh {shlex.quote(str(helper))}\n")
|
||||
runner, directory = _runner_fixture(tmp_path, body)
|
||||
result = _run(runner)
|
||||
assert result.returncode == (0 if status == 0 else 1)
|
||||
assert result.stderr == ""
|
||||
assert _SECRET not in result.stdout
|
||||
assert str(tmp_path) not in result.stdout
|
||||
lines = result.stdout.splitlines()
|
||||
assert len(lines) == (2 if status == 0 else 3)
|
||||
assert lines[0] == (
|
||||
f"virt-cloud-fabric operation={_OPERATION} state=running checkpoint=dispatch reason=none")
|
||||
if status:
|
||||
assert lines[1] == (
|
||||
f"virt-cloud-fabric helper_state=failed helper_phase=gate exit_status={status}")
|
||||
state = (directory / "status").read_text()
|
||||
assert ("status=succeeded\n" if status == 0 else "status=failed\n") in state
|
||||
assert lines[-1].startswith(f"virt-cloud-fabric operation={_OPERATION} state=")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status", [71, 79])
|
||||
def test_first_apply_failure_precedes_secondary_rollback_cleanup_record(tmp_path, status):
|
||||
rendered = _render()
|
||||
helper = tmp_path / "secondary-helper"
|
||||
_write(helper, _helper_entry(rendered) + "VC_FABRIC_HELPER_PHASE=gate\nexit 79\n")
|
||||
start = _TRANSACTION_SCRIPT.index("rollback() {")
|
||||
end = _TRANSACTION_SCRIPT.index("\ntrap rollback EXIT HUP INT TERM", start)
|
||||
rollback = _TRANSACTION_SCRIPT[start:end]
|
||||
body = ("COMMITTED=yes\n" + _apply_logger(rendered) + rollback + (
|
||||
"\ncleanup() {\n"
|
||||
f" printf '%s\\n' {shlex.quote(_SECRET)} >&2\n"
|
||||
f" /bin/sh {shlex.quote(str(helper))} >/dev/null 2>&1 || true\n"
|
||||
"}\ntrap rollback EXIT HUP INT TERM\n"
|
||||
f"VC_FABRIC_APPLY_DETAIL=final_routes\nexit {status}\n"
|
||||
))
|
||||
result = _run(_journal_wrapper(body))
|
||||
assert result.returncode == status
|
||||
assert result.stderr == ""
|
||||
assert result.stdout.splitlines() == [
|
||||
f"virt-cloud-fabric apply_state=failed apply_check=final_routes exit_status={status}",
|
||||
"virt-cloud-fabric helper_state=failed helper_phase=gate exit_status=79",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("manager", ["ifupdown", "networkmanager_nmcli"])
|
||||
@pytest.mark.parametrize("firewall", ["native_nftables", "firewalld_nft"])
|
||||
def test_rendered_timer_start_strictly_follows_durable_commit(manager, firewall):
|
||||
rendered = _render(manager, firewall)
|
||||
timer_command = '"$SYSTEMCTL" start virt-cloud-wg-fabric-reconcile.timer >/dev/null'
|
||||
assert rendered.count(timer_command) == 1
|
||||
commit_marker = rendered.rindex('committed > "$_txn_state_tmp"')
|
||||
publish = rendered.index('mv -f "$_txn_state_tmp" "$TXN/state"', commit_marker)
|
||||
durable_sync = rendered.index("\nsync\n", publish)
|
||||
committed_flag = rendered.index("COMMITTED=yes", durable_sync)
|
||||
timer_start = rendered.index(timer_command)
|
||||
unlock = rendered.index("exec 9>&-", timer_start)
|
||||
assert commit_marker < publish < durable_sync < committed_flag < timer_start < unlock
|
||||
|
||||
|
||||
def test_success_and_disabled_safe_logging_do_not_invent_failure_records():
|
||||
logger = _apply_logger(_render())
|
||||
result = _run(_journal_wrapper(logger + "VC_FABRIC_APPLY_DETAIL=complete\n"
|
||||
"vc_fabric_apply_failure_log 0\n"))
|
||||
assert result.returncode == 0
|
||||
assert result.stdout == result.stderr == ""
|
||||
result = _run(_journal_wrapper(logger + "VC_FABRIC_SAFE_LOG=0\n"
|
||||
"vc_fabric_apply_failure_log 71\n"))
|
||||
assert result.returncode == 0
|
||||
assert result.stdout == result.stderr == ""
|
||||
@ -0,0 +1,272 @@
|
||||
"""Recover a same-plan ready journal without redispatching its old helper."""
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import json
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
from test_fabric_first_deploy_entry import _write
|
||||
from test_fabric_nm_runtime_shadow_recovery import _failed_first_deploy
|
||||
from virsh_panel.fabric import (
|
||||
FIREWALL_MODE_FIREWALLD,
|
||||
FIREWALL_MODE_NATIVE,
|
||||
_FABRIC_NFT_VALIDATION_SH,
|
||||
_FABRIC_SYSCTL_VALIDATION_SH,
|
||||
_FIREWALL_MODE_GUARD_SH,
|
||||
_NMCLI_FILENAME_RESOLVER_SH,
|
||||
_apply_script,
|
||||
)
|
||||
|
||||
|
||||
def _baseline_fixture(tmp_path):
|
||||
values = _failed_first_deploy(tmp_path)
|
||||
_, _, installed, _, _, _, journal, _ = values
|
||||
# The real Alma host now has a journaled old helper baseline, not the
|
||||
# helper.absent case covered by the first-deployment recovery path.
|
||||
(journal / "helper.absent").unlink()
|
||||
_write(journal / "helper.present", "")
|
||||
_write(journal / "helper", installed.read_text(encoding="utf-8"), 0o700)
|
||||
return values
|
||||
|
||||
|
||||
def _rendered_driver(values, root, firewall_mode=FIREWALL_MODE_FIREWALLD):
|
||||
plan, current, installed, base, runtime, roots, _, _ = values
|
||||
keys = {host.host_id: base64.b64encode(bytes([index]) * 32).decode()
|
||||
for index, host in enumerate(plan.nodes, start=1)}
|
||||
rendered = _apply_script(
|
||||
plan, plan.nodes[0], keys, deployment_mode="networkmanager_nmcli",
|
||||
firewall_mode=firewall_mode,
|
||||
)
|
||||
start = rendered.index("COMMITTED=no\nROLLBACK_FAILED=no")
|
||||
end = rendered.index("vc_fabric_operation_checkpoint preflight\n", start)
|
||||
# Execute the actual rendered outer recovery functions and dispatch, then
|
||||
# the complete current helper. Only host resources and CLI paths redirect
|
||||
# to fixture doubles; no ownership/recovery shell function is replaced.
|
||||
recovery = rendered[start:end]
|
||||
body = (_NMCLI_FILENAME_RESOLVER_SH + "\n" + _FABRIC_NFT_VALIDATION_SH + "\n"
|
||||
+ _FABRIC_SYSCTL_VALIDATION_SH + "\n" + _FIREWALL_MODE_GUARD_SH + "\n"
|
||||
+ recovery)
|
||||
for source, destination in roots.items():
|
||||
body = body.replace(source, str(destination))
|
||||
body = body.replace("in /run ", "in " + shlex.quote(str(root / "run")) + " ")
|
||||
tools = root / "tools"
|
||||
identity = re.search(r'^CONNECTION_UUID="([^"]+)"$', current.read_text(), re.MULTILINE)[1]
|
||||
variables = {
|
||||
"BASE": base, "HELPER": installed, "_tmp_helper": current,
|
||||
"OWNER": base / "wg-fabric0.owner", "CONF": base / "wg-fabric0.conf",
|
||||
"NM_PROFILE": roots["/etc/NetworkManager"] / "system-connections" /
|
||||
"virt-cloud-wg-fabric0.nmconnection",
|
||||
"EMERGENCY_OWNER": runtime / "wg-fabric-emergency.owner",
|
||||
"EXPECTED_DIGEST": plan.digest, "DEPLOYMENT_MODE": "networkmanager_nmcli",
|
||||
"FIREWALL_MODE": firewall_mode, "IFACE": "wg-fabric0",
|
||||
"CONNECTION": "virt-cloud-wg-fabric0", "CONNECTION_UUID": identity,
|
||||
"CMP": "/usr/bin/cmp",
|
||||
}
|
||||
for variable, name in (("STAT", "stat"), ("NFT", "nft"), ("IP", "ip"),
|
||||
("WG", "wg"), ("SYSTEMCTL", "systemctl"),
|
||||
("NMCLI", "nmcli"), ("FIREWALL_CMD", "firewall-cmd")):
|
||||
variables[variable] = tools / name
|
||||
prefix = "\n".join(key + "=" + shlex.quote(str(value)) for key, value in variables.items())
|
||||
prefix += ("\nfind_tool() { printf '%s' " + shlex.quote(str(tools / "sha256sum")) + "; }\n"
|
||||
"vc_fabric_operation_checkpoint() { :; }\n"
|
||||
"PATH=" + shlex.quote(str(tools)) + ":/usr/bin:/bin; export PATH\n")
|
||||
return "set -eu\n" + prefix + body
|
||||
|
||||
|
||||
def _run(values, root, firewall_mode=FIREWALL_MODE_FIREWALLD):
|
||||
return subprocess.run(
|
||||
["/bin/sh", "-c", _rendered_driver(values, root, firewall_mode)], check=False,
|
||||
capture_output=True, text=True,
|
||||
env={"VC_ENTRY_ROOT": str(root), "VC_FABRIC_LOCK_HELD": "1"}, timeout=45,
|
||||
)
|
||||
|
||||
|
||||
def _native_baseline_fixture(tmp_path, *, empty_header=False):
|
||||
values = _baseline_fixture(tmp_path)
|
||||
_, current, _, _, _, roots, journal, shadow = values
|
||||
# Rendered helper implementation is identical for both owners; the
|
||||
# explicit literal backend selects the native branch. No shell function
|
||||
# or recovery conditional is replaced in this fixture.
|
||||
content = current.read_text().replace(
|
||||
'FIREWALL_MODE="firewalld_nft"', 'FIREWALL_MODE="native_nftables"', 1,
|
||||
)
|
||||
native_main = tmp_path / "nftables.conf"
|
||||
roots["/etc/nftables.conf"] = native_main
|
||||
content = content.replace("/etc/nftables.conf", str(native_main))
|
||||
if empty_header:
|
||||
content = content.replace('UNDERLAY_ENDPOINT="203.0.113.1"', 'UNDERLAY_ENDPOINT=""')
|
||||
content = content.replace('UNDERLAY_PORT="51820"', 'UNDERLAY_PORT=""')
|
||||
_write(current, content, 0o700)
|
||||
metadata = dict(line.split("=", 1) for line in (journal / "meta").read_text().splitlines())
|
||||
metadata.update({
|
||||
"firewall_mode": FIREWALL_MODE_NATIVE, "nft_main": str(native_main),
|
||||
"firewalld_runtime_zone_before": "na", "firewalld_permanent_zone_before": "na",
|
||||
"underlay_endpoint": "", "underlay_port": "", "underlay_zone": "",
|
||||
"underlay_rule_owner": "none", "underlay_rule_runtime_before": "na",
|
||||
"underlay_rule_permanent_before": "na",
|
||||
})
|
||||
_write(journal / "meta", "".join(f"{key}={value}\n" for key, value in metadata.items()))
|
||||
distribution_rules = '# distribution-owned main file\ninclude "/etc/nftables.d/*.nft"\n'
|
||||
_write(native_main, distribution_rules, 0o644)
|
||||
(journal / "nft_main.absent").unlink()
|
||||
_write(journal / "nft_main.present", "")
|
||||
_write(journal / "nft_main", distribution_rules, 0o644)
|
||||
_write(shadow, shadow.read_text().replace("zone=trusted", "zone="))
|
||||
_write(tmp_path / "nm-zone", "")
|
||||
(tmp_path / "runtime-zone").unlink()
|
||||
# Native owner fixture: nftables enabled/running, firewalld masked and
|
||||
# inactive. Only external systemctl evidence differs from firewalld.
|
||||
tool = tmp_path / "tools" / "external-tool"
|
||||
external = tool.read_text().replace(
|
||||
'print("active" if args[1] == "firewalld" else "inactive")',
|
||||
'print("inactive" if args[1] == "firewalld" else "active")',
|
||||
).replace(
|
||||
'print("enabled" if args[1] == "firewalld" else "disabled")',
|
||||
'print("masked" if args[1] == "firewalld" else "enabled")',
|
||||
)
|
||||
_write(tool, external, 0o700)
|
||||
return values
|
||||
|
||||
|
||||
@pytest.mark.parametrize("empty_header", [False, True])
|
||||
@pytest.mark.parametrize("failure", [None, "endpoint", "port"])
|
||||
def test_native_same_plan_handoff_requires_empty_underlay_metadata_not_unused_header(
|
||||
tmp_path, empty_header, failure):
|
||||
values = _native_baseline_fixture(tmp_path, empty_header=empty_header)
|
||||
_, _, installed, _, runtime, _, journal, shadow = values
|
||||
historical = installed.read_bytes()
|
||||
if failure:
|
||||
_write(journal / "meta", (journal / "meta").read_text().replace(
|
||||
f"underlay_{failure}=\n",
|
||||
f"underlay_{failure}=" + ("203.0.113.1" if failure == "endpoint" else "51820") + "\n",
|
||||
1,
|
||||
))
|
||||
live = tmp_path / "tables" / "inet--virt_cloud_wg_fabric"
|
||||
original = live.read_bytes()
|
||||
result = _run(values, tmp_path, FIREWALL_MODE_NATIVE)
|
||||
assert result.returncode == (0 if failure is None else 79), result.stderr
|
||||
assert "LEGACY_HELPER_EXECUTED" not in result.stdout + result.stderr
|
||||
assert installed.read_bytes() == historical
|
||||
assert (runtime / "wg-fabric-emergency.owner").is_file()
|
||||
if failure is None:
|
||||
assert not journal.exists()
|
||||
assert not live.exists()
|
||||
assert not shadow.exists()
|
||||
assert not (tmp_path / "link-present").exists()
|
||||
else:
|
||||
assert journal.is_dir()
|
||||
assert live.read_bytes() == original
|
||||
assert shadow.is_file()
|
||||
|
||||
|
||||
def test_rendered_outer_replays_same_plan_old_baseline_with_current_helper(tmp_path):
|
||||
values = _baseline_fixture(tmp_path)
|
||||
_, current, installed, base, runtime, _, journal, shadow = values
|
||||
historical = installed.read_bytes()
|
||||
assert current.read_bytes() != historical
|
||||
assert "vc_fabric_nm_profile_semantics_match" not in historical.decode()
|
||||
result = _run(values, tmp_path)
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert "LEGACY_HELPER_EXECUTED" not in result.stdout + result.stderr
|
||||
assert not journal.exists()
|
||||
# Complete recovery preserves its pre-existing, precisely journaled old
|
||||
# helper but must not execute it again under --recover-current.
|
||||
assert installed.read_bytes() == historical
|
||||
assert not shadow.exists()
|
||||
assert not (tmp_path / "link-present").exists()
|
||||
assert not (base / "wg-fabric0.owner").exists()
|
||||
assert not (tmp_path / "tables" / "inet--virt_cloud_wg_fabric").exists()
|
||||
assert (runtime / "wg-fabric-emergency.owner").is_file()
|
||||
for family in ("inet", "bridge"):
|
||||
assert (tmp_path / "tables" / f"{family}--virt_cloud_fabric_emergency").is_file()
|
||||
calls = [json.loads(line) for line in (tmp_path / "calls").read_text().splitlines()]
|
||||
assert not any(call[0] == "systemctl" and call[1] in ("start", "enable") for call in calls)
|
||||
assert not any(call[:5] == ["ip", "link", "set", "dev", "wg-fabric0"]
|
||||
and call[-1] == "up" for call in calls)
|
||||
|
||||
|
||||
def test_normal_boot_recovery_still_reenters_verified_historical_helper(tmp_path):
|
||||
values = _baseline_fixture(tmp_path)
|
||||
_, current, installed, _, runtime, _, journal, _ = values
|
||||
historical = installed.read_bytes()
|
||||
result = subprocess.run(
|
||||
["/bin/sh", str(current)], check=False, capture_output=True, text=True,
|
||||
env={"VC_ENTRY_ROOT": str(tmp_path), "VC_FABRIC_LOCK_HELD": "1"}, timeout=45,
|
||||
)
|
||||
# This complete non-recovery-only entry still uses the restored old
|
||||
# implementation. Its deliberate exit99 proves the normal exec contract
|
||||
# was preserved instead of silently treating a regular boot as finished.
|
||||
assert result.returncode == 99, result.stderr
|
||||
assert "LEGACY_HELPER_EXECUTED" in result.stderr
|
||||
assert not journal.exists()
|
||||
assert installed.read_bytes() == historical
|
||||
assert (runtime / "wg-fabric-emergency.owner").is_file()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("failure", [
|
||||
"foreign_helper", "baseline_and_desired_drift", "temporary_mode", "temporary_digest",
|
||||
"endpoint", "port", "runtime_key", "live_nft_verdict",
|
||||
])
|
||||
def test_rendered_same_plan_handoff_rejects_unproved_ownership_or_plan(tmp_path, failure):
|
||||
values = _baseline_fixture(tmp_path)
|
||||
plan, current, installed, _, runtime, _, journal, shadow = values
|
||||
if failure == "foreign_helper":
|
||||
_write(installed, installed.read_text() + "# external replacement\n", 0o700)
|
||||
elif failure == "baseline_and_desired_drift":
|
||||
for name in ("helper", "helper.desired"):
|
||||
_write(journal / name, (journal / name).read_text() + "# changed snapshot\n", 0o700)
|
||||
elif failure == "temporary_mode":
|
||||
current.chmod(0o600)
|
||||
elif failure == "temporary_digest":
|
||||
_write(current, current.read_text().replace(plan.digest, "a" * 64), 0o700)
|
||||
elif failure in ("endpoint", "port"):
|
||||
old, new = (("underlay_endpoint=203.0.113.1", "underlay_endpoint=203.0.113.9")
|
||||
if failure == "endpoint" else ("underlay_port=51820", "underlay_port=51821"))
|
||||
_write(journal / "meta", (journal / "meta").read_text().replace(old, new))
|
||||
elif failure == "runtime_key":
|
||||
old = base64.b64encode(bytes([7]) * 32).decode()
|
||||
_write(shadow, shadow.read_text().replace(old, base64.b64encode(bytes([8]) * 32).decode()))
|
||||
else:
|
||||
live = tmp_path / "tables" / "inet--virt_cloud_wg_fabric"
|
||||
_write(live, live.read_text().replace("counter drop comment", "counter accept comment", 1))
|
||||
live = tmp_path / "tables" / "inet--virt_cloud_wg_fabric"
|
||||
original = live.read_bytes()
|
||||
result = _run(values, tmp_path)
|
||||
assert result.returncode == 79, result.stderr
|
||||
assert "LEGACY_HELPER_EXECUTED" not in result.stdout + result.stderr
|
||||
assert journal.is_dir()
|
||||
assert installed.is_file()
|
||||
assert live.read_bytes() == original
|
||||
assert (runtime / "wg-fabric-emergency.owner").is_file()
|
||||
calls = [json.loads(line) for line in (tmp_path / "calls").read_text().splitlines()]
|
||||
assert not any(call[0] == "nft" and call[1] == "-f" for call in calls)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("field,value", [
|
||||
("plan_digest", "f" * 64),
|
||||
("connection_uuid", "ffffffff-ffff-ffff-ffff-ffffffffffff"),
|
||||
("deployment_mode", "ifupdown"),
|
||||
("firewall_mode", "native_nftables"),
|
||||
])
|
||||
def test_different_plan_keeps_historical_recovery_contract_without_current_handoff(
|
||||
tmp_path, field, value):
|
||||
values = _baseline_fixture(tmp_path)
|
||||
_, _, _, _, runtime, _, journal, _ = values
|
||||
text = (journal / "meta").read_text()
|
||||
_write(journal / "meta", re.sub(rf"^{field}=.*$", f"{field}={value}", text,
|
||||
flags=re.MULTILINE))
|
||||
before = (tmp_path / "tables" / "inet--virt_cloud_wg_fabric").read_bytes()
|
||||
result = _run(values, tmp_path)
|
||||
assert result.returncode == 79, result.stderr
|
||||
# This controlled historical helper rejects at exit99. Existing cross-
|
||||
# revision dispatch stays intact, and the current template never assumes
|
||||
# authority over the other journal identity.
|
||||
assert "LEGACY_HELPER_EXECUTED" in result.stderr
|
||||
assert "helper_state=failed" not in result.stderr
|
||||
assert journal.is_dir()
|
||||
assert (tmp_path / "tables" / "inet--virt_cloud_wg_fabric").read_bytes() == before
|
||||
assert (runtime / "wg-fabric-emergency.owner").is_file()
|
||||
Loading…
Reference in New Issue