#!/bin/sh # Compare the same verified HTTPS load profile through host forwarding and LB namespace. set -eu ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) cd "$ROOT_DIR" exec "${PYTHON:-python3}" - "$@" <<'PY' import json import os from pathlib import Path import subprocess import sys import time sys.path.insert(0, str(Path.cwd() / 'scripts')) from lab7_environment import Environment, ROOT from lab7_http import BASE_URL, CA_FILE environment = Environment() output = Path(os.environ.get('OUT', 'evidence/path-overhead')).resolve() output.mkdir(parents=True, exist_ok=True) duration = os.environ.get('DURATION', '60') concurrency = os.environ.get('CONCURRENCY', '8') warmup = os.environ.get('WARMUP', '15') image = os.environ.get('CLIENT_IMAGE', 'python:3.12-alpine') lbs = environment.compose('ps', '-q', 'lb').stdout.split() if len(lbs) != 1: raise SystemExit('expected one running Compose LB') ca = Path(CA_FILE).resolve(strict=True) def run_profile(location, seconds, destination=None): if location == 'outside': command = [sys.executable, str(ROOT / 'tests/load.py'), '--base-url', BASE_URL, '--ca-file', str(ca)] else: # Only public tests, contract and CA are mounted; no operator private key. command = ['docker', 'run', '--rm', '--network', 'container:' + lbs[0], '--cap-drop', 'ALL', '--security-opt', 'no-new-privileges:true', '--read-only', '--tmpfs', '/tmp', '--mount', f'type=bind,source={ROOT / "tests"},target=/repo/tests,readonly', '--mount', f'type=bind,source={ROOT / "contracts"},target=/repo/contracts,readonly', '--mount', f'type=bind,source={ROOT / "lab.json"},target=/repo/lab.json,readonly', '--mount', f'type=bind,source={ca},target=/ca.crt,readonly', '--mount', f'type=bind,source={output},target=/out', '-e', 'NO_PROXY=localhost,127.0.0.1', '-e', 'PYTHONDONTWRITEBYTECODE=1', image, 'python', '/repo/tests/load.py', '--base-url', 'https://localhost:8443', '--ca-file', '/ca.crt'] command += ['--duration', seconds, '--concurrency', concurrency] if destination: command += ['--output', str(output / destination) if location == 'outside' else '/out/' + destination] return subprocess.run(command, cwd=ROOT, env=environment.process_env, capture_output=True, text=True, check=True) summary = [time.strftime('# generated: %Y-%m-%dT%H:%M:%SZ', time.gmtime()), 'host URL: ' + BASE_URL, 'inside URL: https://localhost:8443 (LB network namespace)', 'client image: ' + image, 'VM generator shares the VM CPU budget with the stand'] for location in ('outside', 'inside'): run_profile(location, warmup) result = run_profile(location, duration, 'load-' + location + '.json') (output / (location + '.txt')).write_text(result.stdout + result.stderr) summary.append(location + ': ' + json.dumps(json.loads((output / ('load-' + location + '.json')).read_text()))) (output / 'summary.txt').write_text('\n'.join(summary) + '\n') print('\n'.join(summary)) PY