Реализована лабораторная 4: MinIO и вложения

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-12-02 03:04:36 +03:00
co-authored by Copilot
parent ec540a1a72
commit dd484c90b4
28 changed files with 1718 additions and 34 deletions
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
"""Verify bounded API errors during an S3 outage, then restore the service."""
import os
from pathlib import Path
import subprocess
from urllib.parse import quote
from client import Client, arguments, run
ROOT = Path(__file__).resolve().parents[1]
def compose(*args):
command = [
"docker", "compose", "--project-directory", str(ROOT),
"--env-file", str(ROOT / ".env"), *args,
]
subprocess.run(
command,
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
def main():
args = arguments("Verify API responses when MinIO is unavailable")
client = Client(args.base_url, args.ca_file, timeout=15)
alice, _, _, chat = client.bootstrap()
content = (ROOT / "tests" / "fixtures" / "sample.png").read_bytes()
compose("stop", "s3")
try:
health = client.call("GET", "/health/ready", 503)
if health["elapsed"] > 10:
raise AssertionError("S3 readiness failure exceeded 10 seconds")
upload = client.call(
"POST",
"/api/v1/chats/" + chat["id"] + "/attachments?filename=" + quote("sample.png"),
503,
actor=alice,
raw=content,
headers={"Content-Type": "image/png"},
)
if upload["elapsed"] > 10:
raise AssertionError("S3 upload failure exceeded 10 seconds")
finally:
compose("start", "s3")
compose("up", "-d", "--wait", "s3")
client.call("GET", "/health/ready", 200)
print("PASS: MinIO outage returns bounded 503 errors and recovers")
if __name__ == "__main__":
run(main)