summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-04-30 10:10:35 +0300
committerLars Wirzenius <liw@liw.fi>2023-04-30 10:10:35 +0300
commita2882eca83cad33ca046fbdc47cac16108cb2bd4 (patch)
tree396fe9723a1969b1a5eb4d169e7ca4856ccdbb6b
parent985b63baecceec5db779f5299b35b54bc1071273 (diff)
downloadvmdb2-a2882eca83cad33ca046fbdc47cac16108cb2bd4.tar.gz
optionally boot the image
Sponsored-by: author
-rwxr-xr-xcheck-one75
1 files changed, 74 insertions, 1 deletions
diff --git a/check-one b/check-one
index 4e72640..3cad080 100755
--- a/check-one
+++ b/check-one
@@ -2,6 +2,7 @@
import argparse
import os
+import shutil
import subprocess
import sys
import tempfile
@@ -16,6 +17,10 @@ KERNELS = {
"ppc64el": "linux-image-powerpc64le",
}
+QEMUS = {
+ "amd64": "qemu-system-x86_64",
+}
+
class Config:
def __init__(self):
@@ -27,12 +32,21 @@ class Config:
p.add_argument("--grub", action="store", choices=["bios", "uefi", "ieee1275"])
p.add_argument("--mklabel", action="store", choices=["msdos", "gpt"])
p.add_argument("--arch", action="store")
+ p.add_argument("--boot", action="store_true")
+ p.add_argument("--verbose", action="store_true")
args = p.parse_args()
self.dump = args.dump
self.tarball_directory = args.tarball_directory
self.vmdb_filename = args.vmdb
self.vmdb = yaml.safe_load(open(self.vmdb_filename))
+ self.boot = args.boot
+ self.verbose = args.verbose
+
+ if args.arch:
+ self.qemu = QEMUS.get(args.arch)
+ else:
+ self.qemu = QEMUS.get(self.default_arch())
mklabel = self._step("mklabel")
debootstrap = self._step("debootstrap")
@@ -92,6 +106,7 @@ class Config:
def run_vmdb2(config):
+ print(f"building image {config.image()}")
fd, vmdb = tempfile.mkstemp(dir=config.tarball_directory, suffix=".vmdb")
config.write_vmdb(vmdb)
os.close(fd)
@@ -107,9 +122,65 @@ def run_vmdb2(config):
config.image(),
vmdb,
]
- subprocess.run(argv, check=True)
+ subprocess.run(argv, check=True, capture_output=not config.verbose)
os.remove(vmdb)
+ print(f"built image {config.image()} OK")
+
+
+def smoke_test(config):
+ print(f"booting image {config.image()}")
+
+ assert config.qemu
+ tmp = tempfile.mkdtemp()
+ qemu_sh = os.path.join(tmp, "run.sh")
+ expect_txt = os.path.join(tmp, "expect.txt")
+
+ qemu_script = f"""\
+#!/bin/bash
+
+set -euo pipefail
+cd {tmp}
+cp /usr/share/OVMF/OVMF_VARS.fd .
+qemu-system-x86_64 \
+ -m 1024 \
+ -drive if=pflash,format=raw,unit=0,file=/usr/share/ovmf/OVMF.fd,readonly=on \
+ -drive if=pflash,format=raw,unit=1,file=OVMF_VARS.fd \
+ -drive format=raw,file="{config.image()}" \
+ -nographic
+"""
+
+ expect_script = f"""\
+set timeout 300
+proc abort {{}} {{
+ puts "ERROR ERROR\n"
+ exit 1
+}}
+spawn {qemu_sh}
+expect "login: "
+send "root\n"
+expect "# "
+send "poweroff\r"
+set timeout 5
+expect {{
+ "reboot: Power down" {{puts poweroffing\n}}
+ eof abort
+ timeout abort
+}}
+expect eof
+"""
+
+ with open(qemu_sh, "w") as f:
+ f.write(qemu_script)
+ os.chmod(qemu_sh, 0o755)
+ with open(expect_txt, "w") as f:
+ f.write(expect_script)
+
+ subprocess.run(
+ ["expect", "-d", expect_txt], check=True, capture_output=not config.verbose
+ )
+ shutil.rmtree(tmp)
+ print(f"verified that {config.image()} boots OK")
def main():
@@ -118,6 +189,8 @@ def main():
config.write_vmdb("/dev/stdout")
else:
run_vmdb2(config)
+ if config.boot:
+ smoke_test(config)
main()