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