45 lines
1.9 KiB
Python
45 lines
1.9 KiB
Python
"""Явная готовность API, stores и процессов; smoke проверяет обработку задания."""
|
|
import argparse
|
|
import json
|
|
import subprocess
|
|
import time
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--project', default='lyakhonov-lab5')
|
|
parser.add_argument('--base-url', default='http://127.0.0.1:8085')
|
|
args = parser.parse_args()
|
|
deadline = time.monotonic()+120
|
|
observed = set()
|
|
while time.monotonic() < deadline:
|
|
ids = subprocess.check_output(['docker','compose','-p',args.project,'ps','-q'], text=True).split()
|
|
if not ids:
|
|
time.sleep(1)
|
|
continue
|
|
rows = json.loads(subprocess.check_output(['docker','inspect',*ids], text=True))
|
|
services = {}
|
|
for row in rows:
|
|
name = row['Config']['Labels']['com.docker.compose.service']
|
|
services.setdefault(name, []).append(row['State'])
|
|
running = all(services.get(name) and all(s['Running'] for s in services[name])
|
|
for name in ('api','db','s3','broker','dispatcher','worker','staging-cleaner','lb'))
|
|
healthy = all(services.get(name) and all(s.get('Health',{}).get('Status') == 'healthy' for s in services[name])
|
|
for name in ('db','broker','api'))
|
|
try:
|
|
with urllib.request.urlopen(args.base_url+'/health/ready', timeout=2) as response:
|
|
observed.add(response.headers.get('X-Instance-Id'))
|
|
except (urllib.error.URLError, TimeoutError, OSError):
|
|
pass
|
|
if running and healthy and len(services.get('api', [])) >= 2 and len(observed - {None}) >= 2:
|
|
print('PASS: two ready API instances, healthy DB/broker, required background containers running')
|
|
return
|
|
time.sleep(.5)
|
|
raise SystemExit('Readiness deadline exceeded')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|