Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20190714' into staging
[qemu/ar7.git] / tests / vm / freebsd
blob2a19461a909815fbf6b133aad631b572ab4063e5
1 #!/usr/bin/env python
3 # FreeBSD VM image
5 # Copyright 2017-2019 Red Hat Inc.
7 # Authors:
8 # Fam Zheng <famz@redhat.com>
9 # Gerd Hoffmann <kraxel@redhat.com>
11 # This code is licensed under the GPL version 2 or later. See
12 # the COPYING file in the top-level directory.
15 import os
16 import re
17 import sys
18 import time
19 import socket
20 import subprocess
21 import basevm
23 class FreeBSDVM(basevm.BaseVM):
24 name = "freebsd"
25 arch = "x86_64"
27 link = "https://download.freebsd.org/ftp/releases/ISO-IMAGES/12.0/FreeBSD-12.0-RELEASE-amd64-disc1.iso.xz"
28 csum = "1d40015bea89d05b8bd13e2ed80c40b522a9ec1abd8e7c8b80954fb485fb99db"
29 size = "20G"
30 pkgs = [
31 # build tools
32 "git",
33 "pkgconf",
34 "bzip2",
36 # gnu tools
37 "bash",
38 "gmake",
39 "gsed",
40 "flex", "bison",
42 # libs: crypto
43 "gnutls",
45 # libs: images
46 "jpeg-turbo",
47 "png",
49 # libs: ui
50 "sdl2",
51 "gtk3",
52 "libxkbcommon",
54 # libs: opengl
55 "libepoxy",
56 "mesa-libs",
59 BUILD_SCRIPT = """
60 set -e;
61 rm -rf /home/qemu/qemu-test.*
62 cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
63 mkdir src build; cd src;
64 tar -xf /dev/vtbd1;
65 cd ../build
66 ../src/configure --python=python3.6 {configure_opts};
67 gmake --output-sync -j{jobs} {target} {verbose};
68 """
70 def console_boot_serial(self):
71 self.console_wait_send("Autoboot", "3")
72 self.console_wait_send("OK", "set console=comconsole\n")
73 self.console_wait_send("OK", "boot\n")
75 def build_image(self, img):
76 self.print_step("Downloading install iso")
77 cimg = self._download_with_cache(self.link, sha256sum=self.csum)
78 img_tmp = img + ".tmp"
79 iso = img + ".install.iso"
80 iso_xz = iso + ".xz"
82 self.print_step("Preparing iso and disk image")
83 subprocess.check_call(["cp", "-f", cimg, iso_xz])
84 subprocess.check_call(["xz", "-dvf", iso_xz])
85 subprocess.check_call(["qemu-img", "create", "-f", "qcow2",
86 img_tmp, self.size])
88 self.print_step("Booting installer")
89 self.boot(img_tmp, extra_args = [
90 "-bios", "pc-bios/bios-256k.bin",
91 "-machine", "graphics=off",
92 "-cdrom", iso
94 self.console_init()
95 self.console_boot_serial()
96 self.console_wait_send("Console type", "xterm\n")
98 # pre-install configuration
99 self.console_wait_send("Welcome", "\n")
100 self.console_wait_send("Keymap Selection", "\n")
101 self.console_wait_send("Set Hostname", "freebsd\n")
102 self.console_wait_send("Distribution Select", "\n")
103 self.console_wait_send("Partitioning", "\n")
104 self.console_wait_send("Partition", "\n")
105 self.console_wait_send("Scheme", "\n")
106 self.console_wait_send("Editor", "f")
107 self.console_wait_send("Confirmation", "c")
109 self.print_step("Installation started now, this will take a while")
111 # post-install configuration
112 self.console_wait("New Password:")
113 self.console_send("%s\n" % self.ROOT_PASS)
114 self.console_wait("Retype New Password:")
115 self.console_send("%s\n" % self.ROOT_PASS)
117 self.console_wait_send("Network Configuration", "\n")
118 self.console_wait_send("IPv4", "y")
119 self.console_wait_send("DHCP", "y")
120 self.console_wait_send("IPv6", "n")
121 self.console_wait_send("Resolver", "\n")
123 self.console_wait_send("Time Zone Selector", "a\n")
124 self.console_wait_send("Confirmation", "y")
125 self.console_wait_send("Time & Date", "\n")
126 self.console_wait_send("Time & Date", "\n")
128 self.console_wait_send("System Configuration", "\n")
129 self.console_wait_send("System Hardening", "\n")
131 # qemu user
132 self.console_wait_send("Add User Accounts", "y")
133 self.console_wait("Username")
134 self.console_send("%s\n" % self.GUEST_USER)
135 self.console_wait("Full name")
136 self.console_send("%s\n" % self.GUEST_USER)
137 self.console_wait_send("Uid", "\n")
138 self.console_wait_send("Login group", "\n")
139 self.console_wait_send("Login group", "\n")
140 self.console_wait_send("Login class", "\n")
141 self.console_wait_send("Shell", "\n")
142 self.console_wait_send("Home directory", "\n")
143 self.console_wait_send("Home directory perm", "\n")
144 self.console_wait_send("Use password", "\n")
145 self.console_wait_send("Use an empty password", "\n")
146 self.console_wait_send("Use a random password", "\n")
147 self.console_wait("Enter password:")
148 self.console_send("%s\n" % self.GUEST_PASS)
149 self.console_wait("Enter password again:")
150 self.console_send("%s\n" % self.GUEST_PASS)
151 self.console_wait_send("Lock out", "\n")
152 self.console_wait_send("OK", "yes\n")
153 self.console_wait_send("Add another user", "no\n")
155 self.console_wait_send("Final Configuration", "\n")
156 self.console_wait_send("Manual Configuration", "\n")
157 self.console_wait_send("Complete", "\n")
159 self.print_step("Installation finished, rebooting")
160 self.console_boot_serial()
162 # setup qemu user
163 prompt = "$"
164 self.console_ssh_init(prompt, self.GUEST_USER, self.GUEST_PASS)
165 self.console_wait_send(prompt, "exit\n")
167 # setup root user
168 prompt = "root@freebsd:~ #"
169 self.console_ssh_init(prompt, "root", self.ROOT_PASS)
170 self.console_sshd_config(prompt)
172 # setup serial console
173 self.console_wait(prompt)
174 self.console_send("echo 'console=comconsole' >> /boot/loader.conf\n")
176 # setup boot delay
177 self.console_wait(prompt)
178 self.console_send("echo 'autoboot_delay=1' >> /boot/loader.conf\n")
180 # setup virtio-blk #1 (tarfile)
181 self.console_wait(prompt)
182 self.console_send("echo 'chmod 666 /dev/vtbd1' >> /etc/rc.local\n")
184 self.print_step("Configuration finished, rebooting")
185 self.console_wait_send(prompt, "reboot\n")
186 self.console_wait("login:")
187 self.wait_ssh()
189 self.print_step("Installing packages")
190 self.ssh_root_check("pkg install -y %s\n" % " ".join(self.pkgs))
192 # shutdown
193 self.ssh_root(self.poweroff)
194 self.console_wait("Uptime:")
195 self.wait()
197 if os.path.exists(img):
198 os.remove(img)
199 os.rename(img_tmp, img)
200 os.remove(iso)
201 self.print_step("All done")
203 if __name__ == "__main__":
204 sys.exit(basevm.main(FreeBSDVM))