#!/usr/bin/env python3 """Run inside an API container while the RustFS service is stopped.""" import os, urllib.error, urllib.request from pathlib import Path base='http://127.0.0.1:8080' headers={'Authorization':'Bearer '+os.environ['LAB_TEST_TOKEN'],'Content-Type':'image/png'} def call(req): try: with urllib.request.urlopen(req,timeout=10) as response: return response.status except urllib.error.HTTPError as exc: return exc.code ready=call(urllib.request.Request(base+'/health/ready')) image=(Path('/app/tests/fixtures/sample.png')).read_bytes() req=urllib.request.Request(base+'/api/v1/chats/'+os.environ['LAB_TEST_CHAT']+'/attachments?filename=outage.png',data=image,headers=headers,method='POST') upload=call(req) if (ready,upload)!=(503,503): raise SystemExit('expected readiness/upload HTTP 503; got %d/%d'%(ready,upload)) print('PASS: RustFS outage gives API readiness 503 and upload 503')