]> git.proxmox.com Git - mirror_qemu.git/blame - tests/vm/netbsd
Merge tag 'pull-request-2024-01-19' of https://gitlab.com/thuth/qemu into staging
[mirror_qemu.git] / tests / vm / netbsd
CommitLineData
c88ee46c 1#!/usr/bin/env python3
5cd2b138
FZ
2#
3# NetBSD VM image
4#
af093bc9 5# Copyright 2017-2019 Red Hat Inc.
5cd2b138
FZ
6#
7# Authors:
8# Fam Zheng <famz@redhat.com>
af093bc9 9# Gerd Hoffmann <kraxel@redhat.com>
5cd2b138
FZ
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
15import os
16import sys
af093bc9 17import time
5cd2b138
FZ
18import subprocess
19import basevm
20
21class NetBSDVM(basevm.BaseVM):
22 name = "netbsd"
31719c37 23 arch = "x86_64"
af093bc9 24
5bf06025
BS
25 link = "https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.3/images/NetBSD-9.3-amd64.iso"
26 csum = "2bfce544f762a579f61478e7106c436fc48731ff25cf6f79b392ba5752e6f5ec130364286f7471716290a5f033637cf56aacee7fedb91095face59adf36300c3"
af093bc9
GH
27 size = "20G"
28 pkgs = [
29 # tools
30 "git-base",
31 "pkgconf",
32 "xz",
00ac955b 33 "python311",
345d7053 34 "ninja-build",
af093bc9
GH
35
36 # gnu tools
37 "bash",
38 "gmake",
39 "gsed",
844d35b9 40 "gettext-tools",
af093bc9 41
a6b75c9f
PB
42 # libs: basic
43 "dtc",
44
af093bc9
GH
45 # libs: crypto
46 "gnutls",
47
48 # libs: images
49 "jpeg",
50 "png",
51
28e7e95e
TH
52 # libs: ui
53 "capstone",
af093bc9
GH
54 "SDL2",
55 "gtk3+",
56 "libxkbcommon",
3a678481
JQ
57
58 # libs: migration
59 "zstd",
0026be1d
TH
60
61 # libs: networking
62 "libslirp",
af093bc9
GH
63 ]
64
5cd2b138
FZ
65 BUILD_SCRIPT = """
66 set -e;
af093bc9
GH
67 rm -rf /home/qemu/qemu-test.*
68 cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
69 mkdir src build; cd src;
5cd2b138 70 tar -xf /dev/rld1a;
af093bc9 71 cd ../build
a6b75c9f
PB
72 ../src/configure --disable-opengl --extra-ldflags=-L/usr/pkg/lib \
73 --extra-cflags=-I/usr/pkg/include {configure_opts};
5c2ec9b6 74 gmake --output-sync -j{jobs} {target} {verbose};
5cd2b138 75 """
af093bc9 76 poweroff = "/sbin/poweroff"
5cd2b138 77
6d46e602
EH
78 # Workaround for NetBSD + IPv6 + slirp issues.
79 # NetBSD seems to ignore the ICMPv6 Destination Unreachable
80 # messages generated by slirp. When the host has no IPv6
81 # connectivity, this causes every connection to ftp.NetBSD.org
82 # take more than a minute to be established.
83 ipv6 = False
84
5cd2b138 85 def build_image(self, img):
5b4b4865 86 cimg = self._download_with_cache(self.link, sha512sum=self.csum)
5cd2b138 87 img_tmp = img + ".tmp"
af093bc9
GH
88 iso = img + ".install.iso"
89
90 self.print_step("Preparing iso and disk image")
91 subprocess.check_call(["ln", "-f", cimg, iso])
1e48931c 92 self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size)
af093bc9
GH
93
94 self.print_step("Booting installer")
95 self.boot(img_tmp, extra_args = [
af093bc9
GH
96 "-machine", "graphics=off",
97 "-cdrom", iso
98 ])
99 self.console_init()
2cc3e591
GH
100 self.console_wait_send("3. Drop to boot prompt", "3")
101 self.console_wait_send("> ", "consdev com0\n")
af093bc9
GH
102 self.console_wait_send("> ", "boot\n")
103
104 self.console_wait_send("Terminal type", "xterm\n")
105 self.console_wait_send("a: Installation messages", "a\n")
af093bc9
GH
106 self.console_wait_send("a: Install NetBSD", "a\n")
107 self.console_wait("Shall we continue?")
108 self.console_wait_send("b: Yes", "b\n")
109
110 self.console_wait_send("a: ld0", "a\n")
2cc3e591 111 self.console_wait_send("a: Guid Partition Table", "a\n")
af093bc9 112 self.console_wait_send("a: This is the correct", "a\n")
2cc3e591 113 self.console_wait_send("b: Use default part", "b\n")
af093bc9 114 self.console_wait_send("x: Partition sizes ok", "x\n")
af093bc9
GH
115 self.console_wait("Shall we continue?")
116 self.console_wait_send("b: Yes", "b\n")
117
118 self.console_wait_send("b: Use serial port com0", "b\n")
119 self.console_wait_send("f: Set serial baud rate", "f\n")
120 self.console_wait_send("a: 9600", "a\n")
2cc3e591 121 self.console_wait_send("x: Continue", "x\n")
af093bc9
GH
122
123 self.console_wait_send("a: Full installation", "a\n")
124 self.console_wait_send("a: CD-ROM", "a\n")
125
126 self.print_step("Installation started now, this will take a while")
127 self.console_wait_send("Hit enter to continue", "\n")
128
129 self.console_wait_send("d: Change root password", "d\n")
130 self.console_wait_send("a: Yes", "a\n")
131 self.console_wait("New password:")
df001680 132 self.console_send("%s\n" % self._config["root_pass"])
af093bc9 133 self.console_wait("New password:")
df001680 134 self.console_send("%s\n" % self._config["root_pass"])
af093bc9 135 self.console_wait("Retype new password:")
df001680 136 self.console_send("%s\n" % self._config["root_pass"])
af093bc9
GH
137
138 self.console_wait_send("o: Add a user", "o\n")
139 self.console_wait("username")
df001680 140 self.console_send("%s\n" % self._config["guest_user"])
af093bc9
GH
141 self.console_wait("to group wheel")
142 self.console_wait_send("a: Yes", "a\n")
143 self.console_wait_send("a: /bin/sh", "a\n")
144 self.console_wait("New password:")
df001680 145 self.console_send("%s\n" % self._config["guest_pass"])
af093bc9 146 self.console_wait("New password:")
df001680 147 self.console_send("%s\n" % self._config["guest_pass"])
af093bc9 148 self.console_wait("Retype new password:")
df001680 149 self.console_send("%s\n" % self._config["guest_pass"])
af093bc9
GH
150
151 self.console_wait_send("a: Configure network", "a\n")
152 self.console_wait_send("a: vioif0", "a\n")
153 self.console_wait_send("Network media type", "\n")
154 self.console_wait("autoconfiguration")
155 self.console_wait_send("a: Yes", "a\n")
156 self.console_wait_send("DNS domain", "localnet\n")
157 self.console_wait("Are they OK?")
158 self.console_wait_send("a: Yes", "a\n")
159 self.console_wait("installed in /etc")
160 self.console_wait_send("a: Yes", "a\n")
161
162 self.console_wait_send("e: Enable install", "e\n")
163 proxy = os.environ.get("http_proxy")
164 if not proxy is None:
165 self.console_wait_send("f: Proxy", "f\n")
166 self.console_wait("Proxy")
167 self.console_send("%s\n" % proxy)
168 self.console_wait_send("x: Install pkgin", "x\n")
169 self.console_init(1200)
170 self.console_wait_send("Hit enter to continue", "\n")
171 self.console_init()
172
173 self.console_wait_send("g: Enable sshd", "g\n")
174 self.console_wait_send("x: Finished conf", "x\n")
175 self.console_wait_send("Hit enter to continue", "\n")
176
177 self.print_step("Installation finished, rebooting")
178 self.console_wait_send("d: Reboot the computer", "d\n")
179
180 # setup qemu user
181 prompt = "localhost$"
df001680
RF
182 self.console_ssh_init(prompt, self._config["guest_user"],
183 self._config["guest_pass"])
af093bc9
GH
184 self.console_wait_send(prompt, "exit\n")
185
186 # setup root user
187 prompt = "localhost#"
df001680 188 self.console_ssh_init(prompt, "root", self._config["root_pass"])
af093bc9
GH
189 self.console_sshd_config(prompt)
190
191 # setup virtio-blk #1 (tarfile)
192 self.console_wait(prompt)
193 self.console_send("echo 'chmod 666 /dev/rld1a' >> /etc/rc.local\n")
194
195 # turn off mprotect (conflicts with tcg)
196 self.console_wait(prompt)
197 self.console_send("echo security.pax.mprotect.enabled=0 >> /etc/sysctl.conf\n")
198
199 self.print_step("Configuration finished, rebooting")
200 self.console_wait_send(prompt, "reboot\n")
201 self.console_wait("login:")
202 self.wait_ssh()
203
204 self.print_step("Installing packages")
205 self.ssh_root_check("pkgin update\n")
206 self.ssh_root_check("pkgin -y install %s\n" % " ".join(self.pkgs))
207
208 # shutdown
209 self.ssh_root(self.poweroff)
210 self.console_wait("entering state S5")
211 self.wait()
212
5cd2b138 213 os.rename(img_tmp, img)
af093bc9
GH
214 os.remove(iso)
215 self.print_step("All done")
5cd2b138
FZ
216
217if __name__ == "__main__":
218 sys.exit(basevm.main(NetBSDVM))