"""Check readiness and upload when S3 is unavailable; always restore S3.""" import subprocess import base64 import json import time from client import Client, arguments, run def main(): args = arguments('Storage failure') c = Client(args.base_url,args.ca_file) alice,bob,eve,chat = c.bootstrap() data = open('tests/fixtures/sample.png','rb').read() try: subprocess.run(['docker','compose','stop','-t','2','s3'],check=True) for path, probe in [('/health/ready', {'expected':503}), ('/api/v1/chats/'+chat['id']+'/attachments?filename=sample.png', { 'method':'POST','body_b64':base64.b64encode(data).decode(), 'headers':{'Content-Type':'image/png','Authorization':'Bearer '+alice['token']},'expected':503})]: cmd=['docker','compose','run','--rm','-T','--no-deps','tls-probe','--url','https://api1:8443', '--mode','trusted','--path',path] subprocess.run(cmd,input=json.dumps(probe),text=True,check=True) print('PASS: S3 down returns 503 for readiness and upload') finally: subprocess.run(['docker','compose','start','s3'],check=True) for _ in range(60): try: c.call('GET','/health/ready') print('PASS: S3 restored') break except Exception: time.sleep(1) else: raise AssertionError('S3 did not recover') if __name__=='__main__': run(main)