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