87 lines
3.5 KiB
Python
87 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Qualify disposable Laravel failure boundaries and verify acceptance evidence."""
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
FAILURES = ("backup", "tamper", "health", "crash")
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def read(path):
|
|
return json.loads(path.read_text())
|
|
|
|
|
|
def require(condition, message):
|
|
if not condition:
|
|
raise RuntimeError(message)
|
|
|
|
|
|
def inject(args):
|
|
args.output.mkdir(mode=0o700)
|
|
for scenario in FAILURES:
|
|
with (args.output / f"{scenario}.json").open("x") as report:
|
|
subprocess.run(
|
|
[sys.executable, "-B", str(ROOT / "scripts/dev3-laravel.py"),
|
|
"--dependencies", str(args.dependencies), "--php", str(args.php),
|
|
"--root", str(args.output / scenario), "--scenario", scenario],
|
|
stdout=report, stdin=subprocess.DEVNULL, check=True,
|
|
)
|
|
|
|
|
|
def accept(args):
|
|
success = read(args.success)
|
|
require(success["scenario"] == "success" and
|
|
success["release"] == success["queue"] == success["scheduler"] == "2" and
|
|
success["transaction"]["phase"] == "VERIFIED",
|
|
"Successful deployment evidence is incomplete")
|
|
report = {"scope": "disposable loopback Laravel with SQLite", "deployment": success,
|
|
"production_ready": False, "production_execution_enabled": False}
|
|
failures = {name: read(args.failures / f"{name}.json") for name in FAILURES}
|
|
for name, item in failures.items():
|
|
require(item["scenario"] == name, "Failure evidence scenario mismatch")
|
|
require(item["dependency_lock_sha256"] == success["dependency_lock_sha256"],
|
|
"Laravel dependency lock changed between integration phases")
|
|
if name in ("backup", "tamper"):
|
|
require(item["active_release"] == "1", "Preactivation failure switched release")
|
|
else:
|
|
expected_phase = "ACTIVATING" if name == "crash" else "FAILED"
|
|
require(item["phase"] == expected_phase and item["rollback"]["status"] == "ROLLED_BACK"
|
|
and item["rollback"]["active_release"] == "1", "Rollback evidence is incomplete")
|
|
report["failure_injection"] = failures
|
|
capabilities = json.loads(subprocess.check_output(
|
|
[sys.executable, "-B", str(ROOT / "bin/absdev-deploy"), "capabilities"],
|
|
stdin=subprocess.DEVNULL, timeout=15,
|
|
))
|
|
for name in ("production_ready", "deployment_execution_enabled",
|
|
"migration_execution_enabled", "provisioning_execution_enabled",
|
|
"database_restore_enabled", "permanent_deletion_enabled"):
|
|
require(capabilities.get(name) is False, f"Production policy enabled: {name}")
|
|
report["capabilities"] = capabilities
|
|
print(json.dumps(report, indent=2, sort_keys=True))
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
modes = parser.add_subparsers(required=True)
|
|
failure = modes.add_parser("inject")
|
|
failure.add_argument("--output", type=Path, required=True)
|
|
failure.add_argument("--dependencies", type=Path, required=True)
|
|
failure.add_argument("--php", type=Path, required=True)
|
|
failure.set_defaults(action=inject)
|
|
acceptance = modes.add_parser("accept")
|
|
acceptance.add_argument("--success", type=Path, required=True)
|
|
acceptance.add_argument("--failures", type=Path, required=True)
|
|
acceptance.set_defaults(action=accept)
|
|
args = parser.parse_args()
|
|
os.umask(0o077)
|
|
args.action(args)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|