feat: add checks and limits for 4 grade
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import json
|
||||
|
||||
from rolling_update import COMPOSE, ROOT, command
|
||||
|
||||
|
||||
def main():
|
||||
records = []
|
||||
for service in ("db", "redis", "migrate", "api", "haproxy", "frontend"):
|
||||
ids = command(COMPOSE + ["ps", "--all", "-q", service]).split()
|
||||
assert ids, "missing service: " + service
|
||||
for container in ids:
|
||||
info = json.loads(
|
||||
command(
|
||||
[
|
||||
"docker",
|
||||
"inspect",
|
||||
"--format",
|
||||
'{"hostname":{{json .Config.Hostname}},"cpu":{{.HostConfig.NanoCpus}},"memory":{{.HostConfig.Memory}},"ports":{{json .HostConfig.PortBindings}},"networks":{{json .NetworkSettings.Networks}},"mounts":{{json .Mounts}}}',
|
||||
container,
|
||||
]
|
||||
)
|
||||
)
|
||||
assert info["cpu"] > 0 and info["memory"] > 0, "missing effective limits"
|
||||
networks = set(info["networks"])
|
||||
if service in ("api", "db", "redis"):
|
||||
assert not info["ports"], "unexpected public storage/API port"
|
||||
if service == "frontend":
|
||||
assert networks == {"highload-lab3_edge"}
|
||||
if service == "haproxy":
|
||||
assert "highload-lab3_data" not in networks
|
||||
if service == "api":
|
||||
assert not info["mounts"], "API must not mount persistent state"
|
||||
records.append(
|
||||
{
|
||||
"service": service,
|
||||
"instance": info["hostname"],
|
||||
"cpu_limit": info["cpu"] / 1e9,
|
||||
"memory_mib": info["memory"] // (1024 * 1024),
|
||||
"networks": sorted(networks),
|
||||
"public_ports": info["ports"],
|
||||
}
|
||||
)
|
||||
assert len([row for row in records if row["service"] == "api"]) == 2
|
||||
ROOT.joinpath(".memory/grade4").mkdir(parents=True, exist_ok=True)
|
||||
ROOT.joinpath(".memory/grade4/resources.json").write_text(
|
||||
json.dumps(records, indent=2) + "\n"
|
||||
)
|
||||
print(json.dumps(records, indent=2))
|
||||
print(
|
||||
"PASS: effective CPU/RAM limits, two API replicas, private storage/API, isolated frontend"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user