2020-01-30 19:32:24 +03:00
|
|
|
#!/usr/bin/env python3
|
2017-09-05 05:11:55 +03:00
|
|
|
#
|
|
|
|
# FreeBSD VM image
|
|
|
|
#
|
2019-06-17 07:38:55 +03:00
|
|
|
# Copyright 2017-2019 Red Hat Inc.
|
2017-09-05 05:11:55 +03:00
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Fam Zheng <famz@redhat.com>
|
2019-06-17 07:38:55 +03:00
|
|
|
# Gerd Hoffmann <kraxel@redhat.com>
|
2017-09-05 05:11:55 +03: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 07:38:55 +03:00
|
|
|
import re
|
2017-09-05 05:11:55 +03:00
|
|
|
import sys
|
2019-06-17 07:38:55 +03:00
|
|
|
import time
|
|
|
|
import socket
|
2017-09-05 05:11:55 +03:00
|
|
|
import subprocess
|
|
|
|
import basevm
|
|
|
|
|
2021-03-07 18:56:54 +03:00
|
|
|
FREEBSD_CONFIG = {
|
|
|
|
'cpu' : "max,sse4.2=off",
|
|
|
|
}
|
|
|
|
|
2017-09-05 05:11:55 +03:00
|
|
|
class FreeBSDVM(basevm.BaseVM):
|
|
|
|
name = "freebsd"
|
2018-10-13 03:40:30 +03:00
|
|
|
arch = "x86_64"
|
2019-06-17 07:38:55 +03:00
|
|
|
|
2023-04-19 17:45:53 +03: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 07:38:55 +03:00
|
|
|
size = "20G"
|
|
|
|
|
2017-09-05 05:11:55 +03:00
|
|
|
BUILD_SCRIPT = """
|
|
|
|
set -e;
|
2019-06-17 07:38:55 +03:00
|
|
|
rm -rf /home/qemu/qemu-test.*
|
|
|
|
cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
|
|
|
|
mkdir src build; cd src;
|
2017-09-05 05:11:55 +03:00
|
|
|
tar -xf /dev/vtbd1;
|
2023-10-16 19:10:53 +03:00
|
|
|
cd ../build;
|
|
|
|
../src/configure --python=python3.9 --extra-ldflags=-L/usr/local/lib \
|
|
|
|
--extra-cflags=-I/usr/local/include {configure_opts};
|
2019-01-21 19:48:15 +03:00
|
|
|
gmake --output-sync -j{jobs} {target} {verbose};
|
2017-09-05 05:11:55 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
def build_image(self, img):
|
2023-04-19 17:45:53 +03:00
|
|
|
self.print_step("Downloading disk image")
|
2019-06-17 07:38:55 +03:00
|
|
|
cimg = self._download_with_cache(self.link, sha256sum=self.csum)
|
2023-04-19 17:45:53 +03: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 07:38:55 +03:00
|
|
|
self.boot(img_tmp, extra_args = [
|
|
|
|
"-machine", "graphics=off",
|
2023-04-19 17:45:53 +03:00
|
|
|
"-vga", "none"
|
2019-06-17 07:38:55 +03:00
|
|
|
])
|
|
|
|
self.console_init()
|
2023-04-19 17:45:53 +03: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 07:38:55 +03:00
|
|
|
self.console_wait("New Password:")
|
2020-07-01 16:56:23 +03:00
|
|
|
self.console_send("%s\n" % self._config["root_pass"])
|
2019-06-17 07:38:55 +03:00
|
|
|
self.console_wait("Retype New Password:")
|
2020-07-01 16:56:23 +03:00
|
|
|
self.console_send("%s\n" % self._config["root_pass"])
|
2019-06-17 07:38:55 +03:00
|
|
|
|
|
|
|
# qemu user
|
2023-04-19 17:45:53 +03:00
|
|
|
self.console_wait_send("~ #", "adduser\n")
|
2019-06-17 07:38:55 +03:00
|
|
|
self.console_wait("Username")
|
2020-07-01 16:56:23 +03:00
|
|
|
self.console_send("%s\n" % self._config["guest_user"])
|
2019-06-17 07:38:55 +03:00
|
|
|
self.console_wait("Full name")
|
2020-07-01 16:56:23 +03:00
|
|
|
self.console_send("%s\n" % self._config["guest_user"])
|
2019-06-17 07:38:55 +03: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 16:56:23 +03:00
|
|
|
self.console_send("%s\n" % self._config["guest_pass"])
|
2019-06-17 07:38:55 +03:00
|
|
|
self.console_wait("Enter password again:")
|
2020-07-01 16:56:23 +03:00
|
|
|
self.console_send("%s\n" % self._config["guest_pass"])
|
2019-06-17 07:38:55 +03: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 17:45:53 +03:00
|
|
|
self.console_wait_send("~ #", "exit\n")
|
2019-06-17 07:38:55 +03:00
|
|
|
|
|
|
|
# setup qemu user
|
|
|
|
prompt = "$"
|
2020-07-01 16:56:23 +03:00
|
|
|
self.console_ssh_init(prompt, self._config["guest_user"], self._config["guest_pass"])
|
2019-06-17 07:38:55 +03:00
|
|
|
self.console_wait_send(prompt, "exit\n")
|
|
|
|
|
|
|
|
# setup root user
|
|
|
|
prompt = "root@freebsd:~ #"
|
2020-07-01 16:56:23 +03:00
|
|
|
self.console_ssh_init(prompt, "root", self._config["root_pass"])
|
2019-06-17 07:38:55 +03:00
|
|
|
self.console_sshd_config(prompt)
|
2024-02-06 03:22:01 +03:00
|
|
|
self.console_wait_send(prompt, "service sshd reload\n")
|
2019-06-17 07:38:55 +03:00
|
|
|
|
|
|
|
# setup virtio-blk #1 (tarfile)
|
|
|
|
self.console_wait(prompt)
|
|
|
|
self.console_send("echo 'chmod 666 /dev/vtbd1' >> /etc/rc.local\n")
|
|
|
|
|
2023-07-11 17:49:22 +03:00
|
|
|
pkgs = self.get_qemu_packages_from_lcitool_json()
|
2019-06-17 07:38:55 +03:00
|
|
|
self.print_step("Installing packages")
|
2023-07-11 17:49:22 +03:00
|
|
|
self.ssh_root_check("pkg install -y %s\n" % " ".join(pkgs))
|
2019-06-17 07:38:55 +03:00
|
|
|
|
|
|
|
# shutdown
|
|
|
|
self.ssh_root(self.poweroff)
|
|
|
|
self.wait()
|
|
|
|
|
|
|
|
if os.path.exists(img):
|
|
|
|
os.remove(img)
|
2017-09-05 05:11:55 +03:00
|
|
|
os.rename(img_tmp, img)
|
2019-06-17 07:38:55 +03:00
|
|
|
self.print_step("All done")
|
2017-09-05 05:11:55 +03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-03-07 18:56:54 +03:00
|
|
|
sys.exit(basevm.main(FreeBSDVM, config=FREEBSD_CONFIG))
|