qemu/tests/vm/freebsd
Thomas Huth ec6fb1c8cd tests/vm/freebsd: Update to FreeBSD 13.2
According to QEMU's support policy, we stop supporting the previous
major release two years after the the new major release has been
published. So we can stop testing FreeBSD 12 now and should switch
our FreeBSD VM to version 13 instead.

Some changes are needed for this update: The downloadable .ISO images
do not use the serial port as console by default anymore, so they
are not usable in the same way as with FreeBSD 12. Fortunately, the
FreeBSD project now also offers some pre-installed CI images that
have the serial console enabled, so we can use those now, with the
benefit that we can skip almost all parts of the previous installation
process.

Message-Id: <20230419144553.719749-1-thuth@redhat.com>
Reviewed-by: Warner Losh <imp@bsdimp.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
2023-04-20 11:28:16 +02:00

168 lines
5.0 KiB
Python
Executable File

#!/usr/bin/env python3
#
# FreeBSD VM image
#
# Copyright 2017-2019 Red Hat Inc.
#
# Authors:
# Fam Zheng <famz@redhat.com>
# Gerd Hoffmann <kraxel@redhat.com>
#
# This code is licensed under the GPL version 2 or later. See
# the COPYING file in the top-level directory.
#
import os
import re
import sys
import time
import socket
import subprocess
import basevm
FREEBSD_CONFIG = {
'cpu' : "max,sse4.2=off",
}
class FreeBSDVM(basevm.BaseVM):
name = "freebsd"
arch = "x86_64"
link = "https://download.freebsd.org/releases/CI-IMAGES/13.2-RELEASE/amd64/Latest/FreeBSD-13.2-RELEASE-amd64-BASIC-CI.raw.xz"
csum = "a4fb3b6c7b75dd4d58fb0d75e4caf72844bffe0ca00e66459c028b198ffb3c0e"
size = "20G"
pkgs = [
# build tools
"git",
"pkgconf",
"bzip2",
"python39",
"ninja",
# gnu tools
"bash",
"gmake",
"gsed",
"gettext",
# libs: crypto
"gnutls",
# libs: images
"jpeg-turbo",
"png",
# libs: ui
"sdl2",
"gtk3",
"libxkbcommon",
# libs: opengl
"libepoxy",
"mesa-libs",
# libs: migration
"zstd",
# libs: networking
"libslirp",
# libs: sndio
"sndio",
]
BUILD_SCRIPT = """
set -e;
rm -rf /home/qemu/qemu-test.*
cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
mkdir src build; cd src;
tar -xf /dev/vtbd1;
cd ../build
../src/configure --python=python3.9 {configure_opts};
gmake --output-sync -j{jobs} {target} {verbose};
"""
def build_image(self, img):
self.print_step("Downloading disk image")
cimg = self._download_with_cache(self.link, sha256sum=self.csum)
tmp_raw = img + ".tmp.raw"
tmp_raw_xz = tmp_raw + ".xz"
img_tmp = img + ".tmp.qcow2"
self.print_step("Preparing disk image")
subprocess.check_call(["cp", "-f", cimg, tmp_raw_xz])
subprocess.check_call(["xz", "-dvf", tmp_raw_xz])
self.exec_qemu_img("convert", "-O", "qcow2", tmp_raw, img_tmp)
self.exec_qemu_img("resize", img_tmp, self.size)
os.remove(tmp_raw)
self.print_step("Preparing disk image")
self.boot(img_tmp, extra_args = [
"-machine", "graphics=off",
"-vga", "none"
])
self.console_init()
self.console_wait_send("login:", "root\n")
self.console_wait_send("~ #", "service growfs onestart\n")
# root user
self.console_wait_send("~ #", "passwd\n")
self.console_wait("New Password:")
self.console_send("%s\n" % self._config["root_pass"])
self.console_wait("Retype New Password:")
self.console_send("%s\n" % self._config["root_pass"])
# qemu user
self.console_wait_send("~ #", "adduser\n")
self.console_wait("Username")
self.console_send("%s\n" % self._config["guest_user"])
self.console_wait("Full name")
self.console_send("%s\n" % self._config["guest_user"])
self.console_wait_send("Uid", "\n")
self.console_wait_send("Login group", "\n")
self.console_wait_send("Login group", "\n")
self.console_wait_send("Login class", "\n")
self.console_wait_send("Shell", "\n")
self.console_wait_send("Home directory", "\n")
self.console_wait_send("Home directory perm", "\n")
self.console_wait_send("Use password", "\n")
self.console_wait_send("Use an empty password", "\n")
self.console_wait_send("Use a random password", "\n")
self.console_wait("Enter password:")
self.console_send("%s\n" % self._config["guest_pass"])
self.console_wait("Enter password again:")
self.console_send("%s\n" % self._config["guest_pass"])
self.console_wait_send("Lock out", "\n")
self.console_wait_send("OK", "yes\n")
self.console_wait_send("Add another user", "no\n")
self.console_wait_send("~ #", "exit\n")
# setup qemu user
prompt = "$"
self.console_ssh_init(prompt, self._config["guest_user"], self._config["guest_pass"])
self.console_wait_send(prompt, "exit\n")
# setup root user
prompt = "root@freebsd:~ #"
self.console_ssh_init(prompt, "root", self._config["root_pass"])
self.console_sshd_config(prompt)
# setup virtio-blk #1 (tarfile)
self.console_wait(prompt)
self.console_send("echo 'chmod 666 /dev/vtbd1' >> /etc/rc.local\n")
self.print_step("Installing packages")
self.ssh_root_check("pkg install -y %s\n" % " ".join(self.pkgs))
# shutdown
self.ssh_root(self.poweroff)
self.wait()
if os.path.exists(img):
os.remove(img)
os.rename(img_tmp, img)
self.print_step("All done")
if __name__ == "__main__":
sys.exit(basevm.main(FreeBSDVM, config=FREEBSD_CONFIG))