lab5 done

This commit is contained in:
Khakimov Dmitrij
2026-11-10 22:13:40 +03:00
parent b2bd7501d3
commit cbe9d8748c
63 changed files with 8907 additions and 307 deletions
+21 -8
View File
@@ -14,7 +14,7 @@ ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT / 'tests'))
from client import Client, check
STACK = os.environ.get('STACK_NAME', 'mtusi-lab4')
STACK = os.environ.get('STACK_NAME', 'mtusi-lab5')
MC = os.environ.get('S3_CLIENT_IMAGE', 'mtusi-mc:RELEASE.2025-08-13T08-35-41Z')
@@ -43,11 +43,11 @@ def reconcile(apply=False, grace='90s'):
return json.loads(docker(*args).stdout)
def upload(c, actor, chat, content, filename='sample.png', mime='image/png', expected=201):
def upload(c, actor, chat, content, filename='sample.png', mime='image/png', expected=202):
from urllib.parse import quote
return c.call('POST', '/api/v1/chats/'+chat['id']+'/attachments?filename='+quote(filename, safe=''),
expected, actor=actor, raw=content, headers={'Content-Type': mime},
schema='Attachment' if expected == 201 else None)
schema='Attachment' if expected == 202 else None)
def png(width=320, height=200, noisy=False):
@@ -72,13 +72,26 @@ def save(name, result):
def wait_ready(timeout=90):
deadline = time.monotonic()+timeout
stable_since = None
previous = None
while time.monotonic() < deadline:
try:
Client(timeout=2).call('GET', '/health/ready', schema='Health')
return
except AssertionError:
time.sleep(.5)
raise AssertionError('readiness did not recover')
ids=docker('service','ps','--filter','desired-state=running','-q',STACK+'_api').stdout.decode().split()
wanted=json.loads(docker('service','inspect',STACK+'_api').stdout)[0]['Spec']['Mode']['Replicated']['Replicas']
check(wanted>0 and len(ids)==wanted,'API count')
ts=json.loads(docker('inspect',*ids).stdout)
check(all(t['Status']['State']=='running' for t in ts),'API task state')
cs=json.loads(docker('inspect',*[t['Status']['ContainerStatus']['ContainerID'] for t in ts]).stdout)
check(all(c['State'].get('Health',{}).get('Status')=='healthy' for c in cs),'API health')
Client(timeout=2).call('GET','/health/ready',schema='Health')
current=frozenset(ids)
if current!=previous: stable_since=time.monotonic()
previous=current
if stable_since is not None and time.monotonic()-stable_since>=5:return
except (AssertionError,subprocess.CalledProcessError,KeyError):
stable_since=None;previous=None
time.sleep(.5)
raise AssertionError('all API replicas and LB did not stabilize')
class Probe: