#!/usr/bin/env python3
# tests/phase-03/make_fixtures.py [OUTDIR]  -- juju status JSON fixtures for phase-03 3.1.
import json, copy, os, sys
OUTDIR = sys.argv[1] if len(sys.argv) > 1 else "."
def unit(cur, msg, agent="idle", subs=None):
    u = {"workload-status": {"current": cur, "message": msg}, "juju-status": {"current": agent}}
    if subs: u["subordinates"] = subs
    return u
base = {"applications": {
    "keystone": {"units": {"keystone/0": unit("active", "PO (broken): Unit is ready",
        subs={"keystone-hacluster/0": unit("active", "Unit is ready and clustered"),
              "keystone-mysql-router/0": unit("active", "Unit is ready")})}},
    "glance": {"units": {"glance/0": unit("active", "Unit is ready")}},
    "nova-cloud-controller": {"units": {"nova-cloud-controller/0": unit("active", "Unit is ready")}},
    "neutron-api": {"units": {"neutron-api/0": unit("active", "Unit is ready")}},
    "octavia": {"units": {"octavia/0": unit("blocked",
        "Awaiting end-user execution of `configure-resources` action to create required resources")}},
    "glance-simplestreams-sync": {"units": {"glance-simplestreams-sync/0": unit("unknown", "")}},
    "vault": {"units": {"vault/0": unit("active", "Unit is ready (active: true, mlock: disabled)")}},
}}
def dump(n, o):
    p = os.path.join(OUTDIR, n); json.dump(o, open(p, "w"), indent=2); print("  wrote", p)
dump("pass.json", base)
f = copy.deepcopy(base)  # an UNEXPECTED blocked unit must fail the identity gate
f["applications"]["neutron-api"]["units"]["neutron-api/0"]["workload-status"] = {"current": "blocked", "message": "some real problem"}
dump("fail-accept.json", f)
