Treat outputs like we treat trees: store them in the object store. This simplifies using osbuild and allows returning a cached version if one is available. This makes the `--output` parameter redundant. Remove it.
28 lines
949 B
Python
28 lines
949 B
Python
import contextlib
|
|
import logging
|
|
import subprocess
|
|
from os import path
|
|
|
|
from .config import *
|
|
|
|
|
|
def run_image(file_name: str):
|
|
acceleration = ["-accel", "kvm:hvf:tcg"]
|
|
silence = ["-nographic", "-monitor", "none", "-serial", "none"]
|
|
serial = ["-chardev", "stdio,id=stdio", "-device", "virtio-serial", "-device", "virtserialport,chardev=stdio"]
|
|
cmd = ["qemu-system-x86_64", "-m", "1024", "-snapshot"] + \
|
|
acceleration + silence + serial + [file_name]
|
|
logging.info(f"Booting image: {cmd}")
|
|
return subprocess.run(cmd, capture_output=True, timeout=EXPECTED_TIME_TO_BOOT, encoding="utf-8", check=True)
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def extract_image(file_name: str):
|
|
extract_dir = tempfile.mkdtemp(prefix="osbuild-")
|
|
archive = path.join(os.getcwd(), file_name)
|
|
subprocess.run(["tar", "xf", archive], cwd=extract_dir, check=True)
|
|
try:
|
|
yield extract_dir
|
|
finally:
|
|
# Clean up?
|
|
pass
|