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