stages: add test stage

Adds a new systemd unit to the image that will be pulled in by default,
run a given command, forward the output to a virtio serial port and
shutdown the machine.

We add a sample that uses this to verify that systemd conciders the
machine successfully booted. A simple way to run this test from the
commandline is to use
  `$ socat UNIX-LISTEN:qemu.sock -`
to listen for either `running` for success or `degraded` or
`maintenance` for failure.

The image should then be booted using something like
  `$ qemu-kvm -m 1024 -nographic -monitor none -serial none -chardev socket,path=qemu.sock,id=char0 -device virtio-serial -device virtserialport,chardev=char0,id=test0 -snapshot  base.qcow2`

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-08-28 23:05:11 +02:00 committed by msehnout
parent a914627c89
commit fc838a8e20
3 changed files with 114 additions and 6 deletions

View file

@ -53,12 +53,6 @@
"kernel_opts": "ro biosdevname=0 net.ifnames=0"
}
},
{
"name": "org.osbuild.debug-shell",
"options": {
"tty": "/dev/ttyS0"
}
},
{
"name": "org.osbuild.selinux",
"options": {

80
samples/base-test.json Normal file
View file

@ -0,0 +1,80 @@
{
"name": "base-qcow2",
"stages": [
{
"name": "org.osbuild.dnf",
"options": {
"releasever": "30",
"install_weak_deps": true,
"repos": {
"fedora": {
"name": "Fedora",
"metalink": "https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch",
"gpgkey": "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch"
}
},
"packages": [
"@Core",
"chrony",
"kernel",
"selinux-policy-targeted",
"grub2-pc",
"spice-vdagent",
"qemu-guest-agent",
"xen-libs",
"langpacks-en"
]
}
},
{
"name": "org.osbuild.locale",
"options": {
"language": "en_US"
}
},
{
"name": "org.osbuild.fstab",
"options": {
"filesystems": [
{
"uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac",
"vfs_type": "ext4",
"path": "/",
"freq": "1",
"passno": "1"
}
]
}
},
{
"name": "org.osbuild.grub2",
"options": {
"root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac",
"kernel_opts": "ro biosdevname=0 net.ifnames=0"
}
},
{
"name": "org.osbuild.test",
"options": {
"script": "/usr/bin/systemctl is-system-running --wait"
}
},
{
"name": "org.osbuild.selinux",
"options": {
"file_contexts": "etc/selinux/targeted/contexts/files/file_contexts"
}
},
{
"name": "org.osbuild.fix-bls"
}
],
"assembler":
{
"name": "org.osbuild.qcow2",
"options": {
"filename": "base.qcow2",
"root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac"
}
}
}

34
stages/org.osbuild.test Executable file
View file

@ -0,0 +1,34 @@
#!/usr/bin/python3
import json
import os
import sys
def main(tree, options):
script = options["script"]
unit = f"""
[Unit]
Description=Boot Test
Wants=dev-vport0p1.device
After=dev-vport0p1.device
[Service]
StandardOutput=file:/dev/vport0p1
ExecStart={script}
ExecStopPost=/usr/bin/systemctl poweroff
"""
with open(f"{tree}/etc/systemd/system/osbuild-test.service", "w") as f:
f.write(unit)
os.symlink("../osbuild-test.service",
f"{tree}/etc/systemd/system/multi-user.target.wants/osbuild-test.service")
return 0
if __name__ == '__main__':
args = json.load(sys.stdin)
r = main(args["tree"], args["options"])
sys.exit(r)