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