xref: /qemu/tests/vm/netbsd (revision af093bc937ba7813ba3a091ddab64d2f813740ea)
15cd2b138SFam Zheng#!/usr/bin/env python
25cd2b138SFam Zheng#
35cd2b138SFam Zheng# NetBSD VM image
45cd2b138SFam Zheng#
5*af093bc9SGerd Hoffmann# Copyright 2017-2019 Red Hat Inc.
65cd2b138SFam Zheng#
75cd2b138SFam Zheng# Authors:
85cd2b138SFam Zheng#  Fam Zheng <famz@redhat.com>
9*af093bc9SGerd Hoffmann#  Gerd Hoffmann <kraxel@redhat.com>
105cd2b138SFam Zheng#
115cd2b138SFam Zheng# This code is licensed under the GPL version 2 or later.  See
125cd2b138SFam Zheng# the COPYING file in the top-level directory.
135cd2b138SFam Zheng#
145cd2b138SFam Zheng
155cd2b138SFam Zhengimport os
165cd2b138SFam Zhengimport sys
17*af093bc9SGerd Hoffmannimport time
185cd2b138SFam Zhengimport subprocess
195cd2b138SFam Zhengimport basevm
205cd2b138SFam Zheng
215cd2b138SFam Zhengclass NetBSDVM(basevm.BaseVM):
225cd2b138SFam Zheng    name = "netbsd"
2331719c37SPhilippe Mathieu-Daudé    arch = "x86_64"
24*af093bc9SGerd Hoffmann
25*af093bc9SGerd Hoffmann    link = "https://cdn.netbsd.org/pub/NetBSD/NetBSD-8.0/images/NetBSD-8.0-amd64.iso"
26*af093bc9SGerd Hoffmann    size = "20G"
27*af093bc9SGerd Hoffmann    pkgs = [
28*af093bc9SGerd Hoffmann        # tools
29*af093bc9SGerd Hoffmann        "git-base",
30*af093bc9SGerd Hoffmann        "pkgconf",
31*af093bc9SGerd Hoffmann        "xz",
32*af093bc9SGerd Hoffmann        "python37",
33*af093bc9SGerd Hoffmann
34*af093bc9SGerd Hoffmann        # gnu tools
35*af093bc9SGerd Hoffmann        "bash",
36*af093bc9SGerd Hoffmann        "gmake",
37*af093bc9SGerd Hoffmann        "gsed",
38*af093bc9SGerd Hoffmann        "flex", "bison",
39*af093bc9SGerd Hoffmann
40*af093bc9SGerd Hoffmann        # libs: crypto
41*af093bc9SGerd Hoffmann        "gnutls",
42*af093bc9SGerd Hoffmann
43*af093bc9SGerd Hoffmann        # libs: images
44*af093bc9SGerd Hoffmann        "jpeg",
45*af093bc9SGerd Hoffmann        "png",
46*af093bc9SGerd Hoffmann
47*af093bc9SGerd Hoffmann	# libs: ui
48*af093bc9SGerd Hoffmann        "SDL2",
49*af093bc9SGerd Hoffmann        "gtk3+",
50*af093bc9SGerd Hoffmann        "libxkbcommon",
51*af093bc9SGerd Hoffmann    ]
52*af093bc9SGerd Hoffmann
535cd2b138SFam Zheng    BUILD_SCRIPT = """
545cd2b138SFam Zheng        set -e;
55*af093bc9SGerd Hoffmann        rm -rf /home/qemu/qemu-test.*
56*af093bc9SGerd Hoffmann        cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
57*af093bc9SGerd Hoffmann        mkdir src build; cd src;
585cd2b138SFam Zheng        tar -xf /dev/rld1a;
59*af093bc9SGerd Hoffmann        cd ../build
60*af093bc9SGerd Hoffmann        ../src/configure --python=python3.7 --disable-opengl {configure_opts};
615c2ec9b6SAlex Bennée        gmake --output-sync -j{jobs} {target} {verbose};
625cd2b138SFam Zheng    """
63*af093bc9SGerd Hoffmann    poweroff = "/sbin/poweroff"
645cd2b138SFam Zheng
656d46e602SEduardo Habkost    # Workaround for NetBSD + IPv6 + slirp issues.
666d46e602SEduardo Habkost    # NetBSD seems to ignore the ICMPv6 Destination Unreachable
676d46e602SEduardo Habkost    # messages generated by slirp.  When the host has no IPv6
686d46e602SEduardo Habkost    # connectivity, this causes every connection to ftp.NetBSD.org
696d46e602SEduardo Habkost    # take more than a minute to be established.
706d46e602SEduardo Habkost    ipv6 = False
716d46e602SEduardo Habkost
725cd2b138SFam Zheng    def build_image(self, img):
73*af093bc9SGerd Hoffmann        cimg = self._download_with_cache(self.link)
745cd2b138SFam Zheng        img_tmp = img + ".tmp"
75*af093bc9SGerd Hoffmann        iso = img + ".install.iso"
76*af093bc9SGerd Hoffmann
77*af093bc9SGerd Hoffmann        self.print_step("Preparing iso and disk image")
78*af093bc9SGerd Hoffmann        subprocess.check_call(["ln", "-f", cimg, iso])
79*af093bc9SGerd Hoffmann        subprocess.check_call(["qemu-img", "create", "-f", "qcow2",
80*af093bc9SGerd Hoffmann                               img_tmp, self.size])
81*af093bc9SGerd Hoffmann
82*af093bc9SGerd Hoffmann        self.print_step("Booting installer")
83*af093bc9SGerd Hoffmann        self.boot(img_tmp, extra_args = [
84*af093bc9SGerd Hoffmann            "-bios", "pc-bios/bios-256k.bin",
85*af093bc9SGerd Hoffmann            "-machine", "graphics=off",
86*af093bc9SGerd Hoffmann            "-cdrom", iso
87*af093bc9SGerd Hoffmann        ])
88*af093bc9SGerd Hoffmann        self.console_init()
89*af093bc9SGerd Hoffmann        self.console_wait("Primary Bootstrap")
90*af093bc9SGerd Hoffmann
91*af093bc9SGerd Hoffmann        # serial console boot menu output doesn't work for some
92*af093bc9SGerd Hoffmann        # reason, so we have to fly blind ...
93*af093bc9SGerd Hoffmann        for char in list("5consdev com0\n"):
94*af093bc9SGerd Hoffmann            time.sleep(0.2)
95*af093bc9SGerd Hoffmann            self.console_send(char)
96*af093bc9SGerd Hoffmann            self.console_wait("")
97*af093bc9SGerd Hoffmann        self.console_wait_send("> ", "boot\n")
98*af093bc9SGerd Hoffmann
99*af093bc9SGerd Hoffmann        self.console_wait_send("Terminal type",            "xterm\n")
100*af093bc9SGerd Hoffmann        self.console_wait_send("a: Installation messages", "a\n")
101*af093bc9SGerd Hoffmann        self.console_wait_send("b: US-English",            "b\n")
102*af093bc9SGerd Hoffmann        self.console_wait_send("a: Install NetBSD",        "a\n")
103*af093bc9SGerd Hoffmann        self.console_wait("Shall we continue?")
104*af093bc9SGerd Hoffmann        self.console_wait_send("b: Yes",                   "b\n")
105*af093bc9SGerd Hoffmann
106*af093bc9SGerd Hoffmann        self.console_wait_send("a: ld0",                   "a\n")
107*af093bc9SGerd Hoffmann        self.console_wait_send("a: This is the correct",   "a\n")
108*af093bc9SGerd Hoffmann        self.console_wait_send("b: Use the entire disk",   "b\n")
109*af093bc9SGerd Hoffmann        self.console_wait("NetBSD bootcode")
110*af093bc9SGerd Hoffmann        self.console_wait_send("a: Yes",                   "a\n")
111*af093bc9SGerd Hoffmann        self.console_wait_send("b: Use existing part",     "b\n")
112*af093bc9SGerd Hoffmann        self.console_wait_send("x: Partition sizes ok",    "x\n")
113*af093bc9SGerd Hoffmann        self.console_wait_send("for your NetBSD disk",     "\n")
114*af093bc9SGerd Hoffmann        self.console_wait("Shall we continue?")
115*af093bc9SGerd Hoffmann        self.console_wait_send("b: Yes",                   "b\n")
116*af093bc9SGerd Hoffmann
117*af093bc9SGerd Hoffmann        self.console_wait_send("b: Use serial port com0",  "b\n")
118*af093bc9SGerd Hoffmann        self.console_wait_send("f: Set serial baud rate",  "f\n")
119*af093bc9SGerd Hoffmann        self.console_wait_send("a: 9600",                  "a\n")
120*af093bc9SGerd Hoffmann        self.console_wait_send("x: Exit",                  "x\n")
121*af093bc9SGerd Hoffmann
122*af093bc9SGerd Hoffmann        self.console_wait_send("a: Full installation",     "a\n")
123*af093bc9SGerd Hoffmann        self.console_wait_send("a: CD-ROM",                "a\n")
124*af093bc9SGerd Hoffmann
125*af093bc9SGerd Hoffmann        self.print_step("Installation started now, this will take a while")
126*af093bc9SGerd Hoffmann        self.console_wait_send("Hit enter to continue",    "\n")
127*af093bc9SGerd Hoffmann
128*af093bc9SGerd Hoffmann        self.console_wait_send("d: Change root password",  "d\n")
129*af093bc9SGerd Hoffmann        self.console_wait_send("a: Yes",                   "a\n")
130*af093bc9SGerd Hoffmann        self.console_wait("New password:")
131*af093bc9SGerd Hoffmann        self.console_send("%s\n" % self.ROOT_PASS)
132*af093bc9SGerd Hoffmann        self.console_wait("New password:")
133*af093bc9SGerd Hoffmann        self.console_send("%s\n" % self.ROOT_PASS)
134*af093bc9SGerd Hoffmann        self.console_wait("Retype new password:")
135*af093bc9SGerd Hoffmann        self.console_send("%s\n" % self.ROOT_PASS)
136*af093bc9SGerd Hoffmann
137*af093bc9SGerd Hoffmann        self.console_wait_send("o: Add a user",            "o\n")
138*af093bc9SGerd Hoffmann        self.console_wait("username")
139*af093bc9SGerd Hoffmann        self.console_send("%s\n" % self.GUEST_USER)
140*af093bc9SGerd Hoffmann        self.console_wait("to group wheel")
141*af093bc9SGerd Hoffmann        self.console_wait_send("a: Yes",                   "a\n")
142*af093bc9SGerd Hoffmann        self.console_wait_send("a: /bin/sh",               "a\n")
143*af093bc9SGerd Hoffmann        self.console_wait("New password:")
144*af093bc9SGerd Hoffmann        self.console_send("%s\n" % self.GUEST_PASS)
145*af093bc9SGerd Hoffmann        self.console_wait("New password:")
146*af093bc9SGerd Hoffmann        self.console_send("%s\n" % self.GUEST_PASS)
147*af093bc9SGerd Hoffmann        self.console_wait("Retype new password:")
148*af093bc9SGerd Hoffmann        self.console_send("%s\n" % self.GUEST_PASS)
149*af093bc9SGerd Hoffmann
150*af093bc9SGerd Hoffmann        self.console_wait_send("a: Configure network",     "a\n")
151*af093bc9SGerd Hoffmann        self.console_wait_send("a: vioif0",                "a\n")
152*af093bc9SGerd Hoffmann        self.console_wait_send("Network media type",       "\n")
153*af093bc9SGerd Hoffmann        self.console_wait("autoconfiguration")
154*af093bc9SGerd Hoffmann        self.console_wait_send("a: Yes",                   "a\n")
155*af093bc9SGerd Hoffmann        self.console_wait_send("DNS domain",               "localnet\n")
156*af093bc9SGerd Hoffmann        self.console_wait("Are they OK?")
157*af093bc9SGerd Hoffmann        self.console_wait_send("a: Yes",                   "a\n")
158*af093bc9SGerd Hoffmann        self.console_wait("installed in /etc")
159*af093bc9SGerd Hoffmann        self.console_wait_send("a: Yes",                   "a\n")
160*af093bc9SGerd Hoffmann
161*af093bc9SGerd Hoffmann        self.console_wait_send("e: Enable install",        "e\n")
162*af093bc9SGerd Hoffmann        proxy = os.environ.get("http_proxy")
163*af093bc9SGerd Hoffmann        if not proxy is None:
164*af093bc9SGerd Hoffmann            self.console_wait_send("f: Proxy",             "f\n")
165*af093bc9SGerd Hoffmann            self.console_wait("Proxy")
166*af093bc9SGerd Hoffmann            self.console_send("%s\n" % proxy)
167*af093bc9SGerd Hoffmann        self.console_wait_send("x: Install pkgin",         "x\n")
168*af093bc9SGerd Hoffmann        self.console_init(1200)
169*af093bc9SGerd Hoffmann        self.console_wait_send("Hit enter to continue", "\n")
170*af093bc9SGerd Hoffmann        self.console_init()
171*af093bc9SGerd Hoffmann
172*af093bc9SGerd Hoffmann        self.console_wait_send("g: Enable sshd",           "g\n")
173*af093bc9SGerd Hoffmann        self.console_wait_send("x: Finished conf",         "x\n")
174*af093bc9SGerd Hoffmann        self.console_wait_send("Hit enter to continue",    "\n")
175*af093bc9SGerd Hoffmann
176*af093bc9SGerd Hoffmann        self.print_step("Installation finished, rebooting")
177*af093bc9SGerd Hoffmann        self.console_wait_send("d: Reboot the computer",   "d\n")
178*af093bc9SGerd Hoffmann
179*af093bc9SGerd Hoffmann        # setup qemu user
180*af093bc9SGerd Hoffmann        prompt = "localhost$"
181*af093bc9SGerd Hoffmann        self.console_ssh_init(prompt, self.GUEST_USER, self.GUEST_PASS)
182*af093bc9SGerd Hoffmann        self.console_wait_send(prompt, "exit\n")
183*af093bc9SGerd Hoffmann
184*af093bc9SGerd Hoffmann        # setup root user
185*af093bc9SGerd Hoffmann        prompt = "localhost#"
186*af093bc9SGerd Hoffmann        self.console_ssh_init(prompt, "root", self.ROOT_PASS)
187*af093bc9SGerd Hoffmann        self.console_sshd_config(prompt)
188*af093bc9SGerd Hoffmann
189*af093bc9SGerd Hoffmann        # setup virtio-blk #1 (tarfile)
190*af093bc9SGerd Hoffmann        self.console_wait(prompt)
191*af093bc9SGerd Hoffmann        self.console_send("echo 'chmod 666 /dev/rld1a' >> /etc/rc.local\n")
192*af093bc9SGerd Hoffmann
193*af093bc9SGerd Hoffmann        # turn off mprotect (conflicts with tcg)
194*af093bc9SGerd Hoffmann        self.console_wait(prompt)
195*af093bc9SGerd Hoffmann        self.console_send("echo security.pax.mprotect.enabled=0 >> /etc/sysctl.conf\n")
196*af093bc9SGerd Hoffmann
197*af093bc9SGerd Hoffmann        self.print_step("Configuration finished, rebooting")
198*af093bc9SGerd Hoffmann        self.console_wait_send(prompt, "reboot\n")
199*af093bc9SGerd Hoffmann        self.console_wait("login:")
200*af093bc9SGerd Hoffmann        self.wait_ssh()
201*af093bc9SGerd Hoffmann
202*af093bc9SGerd Hoffmann        self.print_step("Installing packages")
203*af093bc9SGerd Hoffmann        self.ssh_root_check("pkgin update\n")
204*af093bc9SGerd Hoffmann        self.ssh_root_check("pkgin -y install %s\n" % " ".join(self.pkgs))
205*af093bc9SGerd Hoffmann
206*af093bc9SGerd Hoffmann        # shutdown
207*af093bc9SGerd Hoffmann        self.ssh_root(self.poweroff)
208*af093bc9SGerd Hoffmann        self.console_wait("entering state S5")
209*af093bc9SGerd Hoffmann        self.wait()
210*af093bc9SGerd Hoffmann
2115cd2b138SFam Zheng        os.rename(img_tmp, img)
212*af093bc9SGerd Hoffmann        os.remove(iso)
213*af093bc9SGerd Hoffmann        self.print_step("All done")
2145cd2b138SFam Zheng
2155cd2b138SFam Zhengif __name__ == "__main__":
2165cd2b138SFam Zheng    sys.exit(basevm.main(NetBSDVM))
217