Previously, the osbuild executor had its internal temporary directory that served as the output directory. However, this approach gives no power to the caller to control the lifetime of the produced artifacts. When more images are built using one executor, the results will accumulate in one place possibly leading to exhaustion of disk space. This commit removes the executor's internal output directory. The output directory can now be passed to osbuild.compile, so the caller can control its lifetime. If no directory is passed in, the compile method will use its own temporary directory - this is useful in cases when the caller doesn't care about the built artifacts or the manifest doesn't have any outputs.
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
#
|
|
# Runtime Tests for Bootable Pipelines
|
|
#
|
|
|
|
import os
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
from .. import test
|
|
|
|
|
|
@unittest.skipUnless(test.TestBase.have_test_data(), "no test-data access")
|
|
class TestBoot(test.TestBase):
|
|
def setUp(self):
|
|
self.osbuild = test.OSBuild(self)
|
|
|
|
def test_boot(self):
|
|
#
|
|
# Build an image and test-boot it.
|
|
#
|
|
|
|
manifest = os.path.join(self.locate_test_data(),
|
|
"manifests/fedora-boot.json")
|
|
|
|
with self.osbuild as osb:
|
|
with tempfile.TemporaryDirectory(dir="/var/tmp") as temp_dir:
|
|
osb.compile_file(manifest, output_dir=temp_dir)
|
|
qcow2 = os.path.join(temp_dir, "fedora-boot.qcow2")
|
|
output_file = os.path.join(temp_dir, "output")
|
|
|
|
subprocess.run(["qemu-system-x86_64",
|
|
"-snapshot",
|
|
"-m", "1024",
|
|
"-M", "accel=kvm:hvf:tcg",
|
|
|
|
# be silent
|
|
"-nographic",
|
|
"-monitor", "none",
|
|
"-serial", "none",
|
|
|
|
# create /dev/vport0p1
|
|
"-chardev", f"file,path={output_file},id=stdio",
|
|
"-device", "virtio-serial",
|
|
"-device", "virtserialport,chardev=stdio",
|
|
|
|
qcow2],
|
|
encoding="utf-8",
|
|
check=True)
|
|
with open(output_file, "r") as f:
|
|
self.assertEqual(f.read().strip(), "running")
|