infrastructure/tests/storage-http.py
2026-11-04 21:39:11 +00:00

27 lines
1.2 KiB
Python

"""Native OSTree pull from a disposable loopback HTTP repository."""
from functools import partial
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
import subprocess
import sys
import threading
source, target, commit = sys.argv[1:]
server = ThreadingHTTPServer(('127.0.0.1', 0), partial(SimpleHTTPRequestHandler, directory=source))
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
try:
command = ['ostree', '--repo=' + target]
subprocess.run(command + ['init', '--mode=archive'], check=True)
# Explicit unsigned fixture only; this is not a production update client.
subprocess.run(command + ['remote', 'add', '--no-gpg-verify', 'fixture',
f'http://127.0.0.1:{server.server_port}/'], check=True)
subprocess.run(command + ['pull', 'fixture', commit], check=True)
subprocess.run(command + ['fsck'], check=True)
checkout = target + '-checkout'
subprocess.run(command + ['checkout', '--user-mode', commit, checkout], check=True)
assert (Path(checkout) / 'marker').read_text() == 'native OSTree transport fixture\n'
finally:
server.shutdown()
thread.join()
server.server_close()