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