forked from mtusi2026/mtusi2026lab3
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""A live but frozen API must be removed by active readiness, then restored."""
|
|
from pathlib import Path
|
|
import sys
|
|
import time
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0,str(ROOT/'scripts'))
|
|
import manage
|
|
|
|
container=manage.containers('api-a')[0]
|
|
started=time.monotonic()
|
|
try:
|
|
manage.command(['docker','pause',container])
|
|
while True:
|
|
config=manage.compose('exec','-T','nginx','cat','/etc/nginx/upstreams.conf',capture=True)
|
|
if any('api-a:' in line and ' down;' in line for line in config.splitlines()):
|
|
break
|
|
assert time.monotonic()-started < 5, 'readiness did not remove frozen backend within 5s'
|
|
time.sleep(.2)
|
|
print('PASS: frozen api-a excluded in %.3fs' % (time.monotonic()-started))
|
|
finally:
|
|
manage.command(['docker','unpause',container])
|
|
started=time.monotonic()
|
|
while True:
|
|
config=manage.compose('exec','-T','nginx','cat','/etc/nginx/upstreams.conf',capture=True)
|
|
if not any('api-a:' in line and ' down;' in line for line in config.splitlines()):
|
|
break
|
|
assert time.monotonic()-started<10, 'healthy backend did not return'
|
|
time.sleep(.2)
|
|
print('PASS: healthy backend restored in %.3fs' % (time.monotonic()-started))
|
|
|
|
manage.wait_healthy('api-a')
|