2020-01-30 17:32:24 +01:00
|
|
|
#!/usr/bin/env python3
|
2017-09-05 04:11:55 +02:00
|
|
|
#
|
|
|
|
# FreeBSD VM image
|
|
|
|
#
|
2019-06-17 06:38:55 +02:00
|
|
|
# Copyright 2017-2019 Red Hat Inc.
|
2017-09-05 04:11:55 +02:00
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Fam Zheng <famz@redhat.com>
|
2019-06-17 06:38:55 +02:00
|
|
|
# Gerd Hoffmann <kraxel@redhat.com>
|
2017-09-05 04:11:55 +02:00
|
|
|
#
|
|
|
|
# This code is licensed under the GPL version 2 or later. See
|
|
|
|
# the COPYING file in the top-level directory.
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
2019-06-17 06:38:55 +02:00
|
|
|
import re
|
2017-09-05 04:11:55 +02:00
|
|
|
import sys
|
2019-06-17 06:38:55 +02:00
|
|
|
import time
|
|
|
|
import socket
|
2017-09-05 04:11:55 +02:00
|
|
|
import subprocess
|
|
|
|
import basevm
|
|
|
|
|
2021-03-07 16:56:54 +01:00
|
|
|
FREEBSD_CONFIG = {
|
|
|
|
'cpu' : "max,sse4.2=off",
|
|
|
|
}
|
|
|
|
|
2017-09-05 04:11:55 +02:00
|
|
|
class FreeBSDVM(basevm.BaseVM):
|
|
|
|
name = "freebsd"
|
2018-10-13 02:40:30 +02:00
|
|
|
arch = "x86_64"
|
2019-06-17 06:38:55 +02:00
|
|
|
|
2023-04-19 16:45:53 +02:00
|
|
|
link = "https://download.freebsd.org/releases/CI-IMAGES/13.2-RELEASE/amd64/Latest/FreeBSD-13.2-RELEASE-amd64-BASIC-CI.raw.xz"
|
|
|
|
csum = "a4fb3b6c7b75dd4d58fb0d75e4caf72844bffe0ca00e66459c028b198ffb3c0e"
|
2019-06-17 06:38:55 +02:00
|
|
|
size = "20G"
|
|
|
|
|
2017-09-05 04:11:55 +02:00
|
|
|
BUILD_SCRIPT = """
|
|
|
|
set -e;
|
2019-06-17 06:38:55 +02:00
|
|
|
rm -rf /home/qemu/qemu-test.*
|
|
|
|
cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
|
|
|
|
mkdir src build; cd src;
|
2017-09-05 04:11:55 +02:00
|
|
|
tar -xf /dev/vtbd1;
|
2019-06-17 06:38:55 +02:00
|
|
|
cd ../build
|
2023-04-19 16:45:53 +02:00
|
|
|
../src/configure --python=python3.9 {configure_opts};
|
2019-01-21 17:48:15 +01:00
|
|
|
gmake --output-sync -j{jobs} {target} {verbose};
|
2017-09-05 04:11:55 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
def build_image(self, img):
|
2023-04-19 16:45:53 +02:00
|
|
|
self.print_step("Downloading disk image")
|
2019-06-17 06:38:55 +02:00
|
|
|
cimg = self._download_with_cache(self.link, sha256sum=self.csum)
|
2023-04-19 16:45:53 +02:00
|
|
|
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")
|
2019-06-17 06:38:55 +02:00
|
|
|
self.boot(img_tmp, extra_args = [
|
|
|
|
"-machine", "graphics=off",
|
2023-04-19 16:45:53 +02:00
|
|
|
"-vga", "none"
|
2019-06-17 06:38:55 +02:00
|
|
|
])
|
|
|
|
self.console_init()
|
2023-04-19 16:45:53 +02:00
|
|
|
self.console_wait_send("login:", "root\n")
|
|
|
|
self.console_wait_send("~ #", "service growfs onestart\n")
|
|
|
|
|
|
|
|
# root user
|
|
|
|
self.console_wait_send("~ #", "passwd\n")
|
2019-06-17 06:38:55 +02:00
|
|
|
self.console_wait("New Password:")
|
2020-07-01 15:56:23 +02:00
|
|
|
self.console_send("%s\n" % self._config["root_pass"])
|
2019-06-17 06:38:55 +02:00
|
|
|
self.console_wait("Retype New Password:")
|
2020-07-01 15:56:23 +02:00
|
|
|
self.console_send("%s\n" % self._config["root_pass"])
|
2019-06-17 06:38:55 +02:00
|
|
|
|
|
|
|
# qemu user
|
2023-04-19 16:45:53 +02:00
|
|
|
self.console_wait_send("~ #", "adduser\n")
|
2019-06-17 06:38:55 +02:00
|
|
|
self.console_wait("Username")
|
2020-07-01 15:56:23 +02:00
|
|
|
self.console_send("%s\n" % self._config["guest_user"])
|
2019-06-17 06:38:55 +02:00
|
|
|
self.console_wait("Full name")
|
2020-07-01 15:56:23 +02:00
|
|
|
self.console_send("%s\n" % self._config["guest_user"])
|
2019-06-17 06:38:55 +02:00
|
|
|
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:")
|
2020-07-01 15:56:23 +02:00
|
|
|
self.console_send("%s\n" % self._config["guest_pass"])
|
2019-06-17 06:38:55 +02:00
|
|
|
self.console_wait("Enter password again:")
|
2020-07-01 15:56:23 +02:00
|
|
|
self.console_send("%s\n" % self._config["guest_pass"])
|
2019-06-17 06:38:55 +02:00
|
|
|
self.console_wait_send("Lock out", "\n")
|
|
|
|
self.console_wait_send("OK", "yes\n")
|
|
|
|
self.console_wait_send("Add another user", "no\n")
|
2023-04-19 16:45:53 +02:00
|
|
|
self.console_wait_send("~ #", "exit\n")
|
2019-06-17 06:38:55 +02:00
|
|
|
|
|
|
|
# setup qemu user
|
|
|
|
prompt = "$"
|
2020-07-01 15:56:23 +02:00
|
|
|
self.console_ssh_init(prompt, self._config["guest_user"], self._config["guest_pass"])
|
2019-06-17 06:38:55 +02:00
|
|
|
self.console_wait_send(prompt, "exit\n")
|
|
|
|
|
|
|
|
# setup root user
|
|
|
|
prompt = "root@freebsd:~ #"
|
2020-07-01 15:56:23 +02:00
|
|
|
self.console_ssh_init(prompt, "root", self._config["root_pass"])
|
2019-06-17 06:38:55 +02:00
|
|
|
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")
|
|
|
|
|
2023-07-11 16:49:22 +02:00
|
|
|
pkgs = self.get_qemu_packages_from_lcitool_json()
|
2019-06-17 06:38:55 +02:00
|
|
|
self.print_step("Installing packages")
|
2023-07-11 16:49:22 +02:00
|
|
|
self.ssh_root_check("pkg install -y %s\n" % " ".join(pkgs))
|
2019-06-17 06:38:55 +02:00
|
|
|
|
|
|
|
# shutdown
|
|
|
|
self.ssh_root(self.poweroff)
|
|
|
|
self.wait()
|
|
|
|
|
|
|
|
if os.path.exists(img):
|
|
|
|
os.remove(img)
|
2017-09-05 04:11:55 +02:00
|
|
|
os.rename(img_tmp, img)
|
2019-06-17 06:38:55 +02:00
|
|
|
self.print_step("All done")
|
2017-09-05 04:11:55 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-03-07 16:56:54 +01:00
|
|
|
sys.exit(basevm.main(FreeBSDVM, config=FREEBSD_CONFIG))
|