35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
"""Serve an isolated synthetic database through a loopback-only test proxy."""
|
|
|
|
import argparse
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
import types
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--database', required=True, help='Existing disposable synthetic SQLite database')
|
|
parser.add_argument('--port', type=int, default=5059)
|
|
args = parser.parse_args()
|
|
database = Path(args.database).resolve(strict=True)
|
|
if not database.is_file():
|
|
raise ValueError('The synthetic database must be an existing file')
|
|
os.environ.update(CAMA_DATABASE_URL='sqlite:///' + database.as_posix(),
|
|
MLFLOW_DISABLE_AGENT_HINT='1',
|
|
MLFLOW_DISABLE_TELEMETRY='true')
|
|
for domain in ('CACU', 'TEA', 'GOVERNANCE'):
|
|
os.environ[domain + '_DATABASE_URL'] = 'sqlite:///:memory:'
|
|
if os.name == 'nt':
|
|
fcntl = types.ModuleType('fcntl')
|
|
fcntl.LOCK_EX, fcntl.LOCK_UN = 2, 8
|
|
def unavailable(*_args):
|
|
raise RuntimeError('POSIX locking is unavailable in this Windows test harness')
|
|
fcntl.flock = unavailable
|
|
sys.modules['fcntl'] = fcntl
|
|
|
|
from webapi import create_app
|
|
from werkzeug.serving import make_server
|
|
|
|
app = create_app()
|
|
print(f'Isolated synthetic test proxy: http://127.0.0.1:{args.port}', flush=True)
|
|
make_server('127.0.0.1', args.port, app, threaded=True).serve_forever()
|