#!/usr/bin/env python3 """Run exact make targets in Linux on Windows/Linux, retaining safe evidence.""" import json from pathlib import Path import subprocess from run_experiments import compose, containers, docker, runner, snapshot, wait_instances ROOT = Path(__file__).resolve().parents[1] def save(name, text): (ROOT / 'evidence' / name).write_text(text + '\n', encoding='utf-8') print('Saved ' + name if name.endswith('.json') else text, flush=True) def main(): save('checks.txt', runner('make', 'check', 'validate', 'test')) save('student-tests.txt', runner('python', 'student-tests/integration.py')) before = snapshot() save('restart-hook.txt', runner('python', 'scripts/stack_control.py', 'restart')) wait_instances(2) save('restart-processes.json', json.dumps({'before': before, 'after': snapshot()}, indent=2)) save('persistence.txt', runner('make', 'test-persistence', 'ACTION_SCRIPT=scripts/restart.sh')) wait_instances(2) ids = {c['Id'] for c in containers('api')} stopped = set() rounds = [] for i in range(1, 3): before = snapshot() text = runner('make', 'test-failover', 'ACTION_SCRIPT=scripts/stop-one.sh') after = snapshot() dead = [c for c in containers('api', True) if not c['State']['Running']] if len(dead) != 1: raise RuntimeError('Hook did not leave exactly one API stopped') stopped.add(dead[0]['Id']) rounds.append({'round': i, 'stopped_id': dead[0]['Id'][:12], 'before': before, 'after': after}) save('failover-%d.txt' % i, text) docker('start', dead[0]['Id']) wait_instances(2) if stopped == ids: break save('failover-processes.json', json.dumps(rounds, indent=2)) # The public scenario chooses its target via LB, so its two runs may select # the same process. The next tests deterministically cover EVERY replica. for index, container in enumerate(containers('api'), 1): before = snapshot() text = runner('python', 'student-tests/mixed_failover.py', '--target-hostname', container['Config']['Hostname']) save('mixed-failover-%d.json' % index, text) save('mixed-processes-%d.json' % index, json.dumps({'before': before, 'after': snapshot()}, indent=2)) docker('start', container['Id']) wait_instances(2) save('final-smoke.txt', runner('make', 'test')) if __name__ == '__main__': main()