Test refactoring

The testing script is getting too big and not very well organized. In
this commit a new module `integration_tests` is introduced that contains
parts of the original testing script split into multiple files. The
content should be the same, the only difference is that now you can run
the tests by invoking `python3 -m test`.
This commit is contained in:
Martin Sehnoutka 2019-08-06 09:53:11 +02:00 committed by Tom Gundersen
parent c27cdd5928
commit ea68bb0c26
14 changed files with 204 additions and 201 deletions

View file

@ -0,0 +1,32 @@
import contextlib
import logging
import subprocess
import time
from .config import *
@contextlib.contextmanager
def boot_image(file_name: str):
acceleration = ["-accel", "kvm:hvf:tcg"]
network = ["-net", "nic,model=rtl8139", "-net", "user,hostfwd=tcp::8888-:8888"]
cmd = ["qemu-system-x86_64", "-nographic", "-m", "1024", "-snapshot"] + \
acceleration + [f"{OUTPUT_DIR}/{file_name}"] + network
logging.info(f"Booting image: {cmd}")
vm = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
try:
time.sleep(EXPECTED_TIME_TO_BOOT)
yield None
finally:
vm.kill()
@contextlib.contextmanager
def extract_image(file_name: str):
extract_dir = tempfile.mkdtemp(prefix="osbuild-")
subprocess.run(["tar", "xf", f"{OUTPUT_DIR}/{file_name}"], cwd=extract_dir, check=True)
try:
yield extract_dir
finally:
# Clean up?
pass