xref: /openbmc/qemu/tests/vm/netbsd (revision bdd53274f2c84b56dd4257299024cb97f5b66077)
1c88ee46cSPhilippe Mathieu-Daudé#!/usr/bin/env python3
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
255bf06025SBrad Smith    link = "https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.3/images/NetBSD-9.3-amd64.iso"
265bf06025SBrad Smith    csum = "2bfce544f762a579f61478e7106c436fc48731ff25cf6f79b392ba5752e6f5ec130364286f7471716290a5f033637cf56aacee7fedb91095face59adf36300c3"
27af093bc9SGerd Hoffmann    size = "20G"
28af093bc9SGerd Hoffmann    pkgs = [
29af093bc9SGerd Hoffmann        # tools
30af093bc9SGerd Hoffmann        "git-base",
31af093bc9SGerd Hoffmann        "pkgconf",
32af093bc9SGerd Hoffmann        "xz",
33345d7053SPaolo Bonzini        "ninja-build",
34af093bc9SGerd Hoffmann
35af093bc9SGerd Hoffmann        # gnu tools
36af093bc9SGerd Hoffmann        "bash",
37af093bc9SGerd Hoffmann        "gmake",
38af093bc9SGerd Hoffmann        "gsed",
39844d35b9SBrad Smith        "gettext-tools",
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
4928e7e95eSThomas Huth        "capstone",
50af093bc9SGerd Hoffmann        "SDL2",
51af093bc9SGerd Hoffmann        "gtk3+",
52af093bc9SGerd Hoffmann        "libxkbcommon",
533a678481SJuan Quintela
543a678481SJuan Quintela        # libs: migration
553a678481SJuan Quintela        "zstd",
560026be1dSThomas Huth
570026be1dSThomas Huth        # libs: networking
580026be1dSThomas Huth        "libslirp",
59af093bc9SGerd Hoffmann    ]
60af093bc9SGerd Hoffmann
615cd2b138SFam Zheng    BUILD_SCRIPT = """
625cd2b138SFam Zheng        set -e;
63af093bc9SGerd Hoffmann        rm -rf /home/qemu/qemu-test.*
64af093bc9SGerd Hoffmann        cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
65af093bc9SGerd Hoffmann        mkdir src build; cd src;
665cd2b138SFam Zheng        tar -xf /dev/rld1a;
67af093bc9SGerd Hoffmann        cd ../build
68*bdd53274SDaniel P. Berrangé        ../src/configure --disable-opengl {configure_opts};
695c2ec9b6SAlex Bennée        gmake --output-sync -j{jobs} {target} {verbose};
705cd2b138SFam Zheng    """
71af093bc9SGerd Hoffmann    poweroff = "/sbin/poweroff"
725cd2b138SFam Zheng
736d46e602SEduardo Habkost    # Workaround for NetBSD + IPv6 + slirp issues.
746d46e602SEduardo Habkost    # NetBSD seems to ignore the ICMPv6 Destination Unreachable
756d46e602SEduardo Habkost    # messages generated by slirp.  When the host has no IPv6
766d46e602SEduardo Habkost    # connectivity, this causes every connection to ftp.NetBSD.org
776d46e602SEduardo Habkost    # take more than a minute to be established.
786d46e602SEduardo Habkost    ipv6 = False
796d46e602SEduardo Habkost
805cd2b138SFam Zheng    def build_image(self, img):
815b4b4865SAlex Bennée        cimg = self._download_with_cache(self.link, sha512sum=self.csum)
825cd2b138SFam Zheng        img_tmp = img + ".tmp"
83af093bc9SGerd Hoffmann        iso = img + ".install.iso"
84af093bc9SGerd Hoffmann
85af093bc9SGerd Hoffmann        self.print_step("Preparing iso and disk image")
86af093bc9SGerd Hoffmann        subprocess.check_call(["ln", "-f", cimg, iso])
871e48931cSWainer dos Santos Moschetta        self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size)
88af093bc9SGerd Hoffmann
89af093bc9SGerd Hoffmann        self.print_step("Booting installer")
90af093bc9SGerd Hoffmann        self.boot(img_tmp, extra_args = [
91af093bc9SGerd Hoffmann            "-machine", "graphics=off",
92af093bc9SGerd Hoffmann            "-cdrom", iso
93af093bc9SGerd Hoffmann        ])
94af093bc9SGerd Hoffmann        self.console_init()
952cc3e591SGerd Hoffmann        self.console_wait_send("3. Drop to boot prompt", "3")
962cc3e591SGerd Hoffmann        self.console_wait_send("> ", "consdev com0\n")
97af093bc9SGerd Hoffmann        self.console_wait_send("> ", "boot\n")
98af093bc9SGerd Hoffmann
99af093bc9SGerd Hoffmann        self.console_wait_send("Terminal type",            "xterm\n")
100af093bc9SGerd Hoffmann        self.console_wait_send("a: Installation messages", "a\n")
101af093bc9SGerd Hoffmann        self.console_wait_send("a: Install NetBSD",        "a\n")
102af093bc9SGerd Hoffmann        self.console_wait("Shall we continue?")
103af093bc9SGerd Hoffmann        self.console_wait_send("b: Yes",                   "b\n")
104af093bc9SGerd Hoffmann
105af093bc9SGerd Hoffmann        self.console_wait_send("a: ld0",                   "a\n")
1062cc3e591SGerd Hoffmann        self.console_wait_send("a: Guid Partition Table",  "a\n")
107af093bc9SGerd Hoffmann        self.console_wait_send("a: This is the correct",   "a\n")
1082cc3e591SGerd Hoffmann        self.console_wait_send("b: Use default part",      "b\n")
109af093bc9SGerd Hoffmann        self.console_wait_send("x: Partition sizes ok",    "x\n")
110af093bc9SGerd Hoffmann        self.console_wait("Shall we continue?")
111af093bc9SGerd Hoffmann        self.console_wait_send("b: Yes",                   "b\n")
112af093bc9SGerd Hoffmann
113af093bc9SGerd Hoffmann        self.console_wait_send("b: Use serial port com0",  "b\n")
114af093bc9SGerd Hoffmann        self.console_wait_send("f: Set serial baud rate",  "f\n")
115af093bc9SGerd Hoffmann        self.console_wait_send("a: 9600",                  "a\n")
1162cc3e591SGerd Hoffmann        self.console_wait_send("x: Continue",              "x\n")
117af093bc9SGerd Hoffmann
118af093bc9SGerd Hoffmann        self.console_wait_send("a: Full installation",     "a\n")
119af093bc9SGerd Hoffmann        self.console_wait_send("a: CD-ROM",                "a\n")
120af093bc9SGerd Hoffmann
121af093bc9SGerd Hoffmann        self.print_step("Installation started now, this will take a while")
122af093bc9SGerd Hoffmann        self.console_wait_send("Hit enter to continue",    "\n")
123af093bc9SGerd Hoffmann
124af093bc9SGerd Hoffmann        self.console_wait_send("d: Change root password",  "d\n")
125af093bc9SGerd Hoffmann        self.console_wait_send("a: Yes",                   "a\n")
126af093bc9SGerd Hoffmann        self.console_wait("New password:")
127df001680SRobert Foley        self.console_send("%s\n" % self._config["root_pass"])
128af093bc9SGerd Hoffmann        self.console_wait("New password:")
129df001680SRobert Foley        self.console_send("%s\n" % self._config["root_pass"])
130af093bc9SGerd Hoffmann        self.console_wait("Retype new password:")
131df001680SRobert Foley        self.console_send("%s\n" % self._config["root_pass"])
132af093bc9SGerd Hoffmann
133af093bc9SGerd Hoffmann        self.console_wait_send("o: Add a user",            "o\n")
134af093bc9SGerd Hoffmann        self.console_wait("username")
135df001680SRobert Foley        self.console_send("%s\n" % self._config["guest_user"])
136af093bc9SGerd Hoffmann        self.console_wait("to group wheel")
137af093bc9SGerd Hoffmann        self.console_wait_send("a: Yes",                   "a\n")
138af093bc9SGerd Hoffmann        self.console_wait_send("a: /bin/sh",               "a\n")
139af093bc9SGerd Hoffmann        self.console_wait("New password:")
140df001680SRobert Foley        self.console_send("%s\n" % self._config["guest_pass"])
141af093bc9SGerd Hoffmann        self.console_wait("New password:")
142df001680SRobert Foley        self.console_send("%s\n" % self._config["guest_pass"])
143af093bc9SGerd Hoffmann        self.console_wait("Retype new password:")
144df001680SRobert Foley        self.console_send("%s\n" % self._config["guest_pass"])
145af093bc9SGerd Hoffmann
146af093bc9SGerd Hoffmann        self.console_wait_send("a: Configure network",     "a\n")
147af093bc9SGerd Hoffmann        self.console_wait_send("a: vioif0",                "a\n")
148af093bc9SGerd Hoffmann        self.console_wait_send("Network media type",       "\n")
149af093bc9SGerd Hoffmann        self.console_wait("autoconfiguration")
150af093bc9SGerd Hoffmann        self.console_wait_send("a: Yes",                   "a\n")
151af093bc9SGerd Hoffmann        self.console_wait_send("DNS domain",               "localnet\n")
152af093bc9SGerd Hoffmann        self.console_wait("Are they OK?")
153af093bc9SGerd Hoffmann        self.console_wait_send("a: Yes",                   "a\n")
154af093bc9SGerd Hoffmann        self.console_wait("installed in /etc")
155af093bc9SGerd Hoffmann        self.console_wait_send("a: Yes",                   "a\n")
156af093bc9SGerd Hoffmann
157af093bc9SGerd Hoffmann        self.console_wait_send("e: Enable install",        "e\n")
158af093bc9SGerd Hoffmann        proxy = os.environ.get("http_proxy")
159af093bc9SGerd Hoffmann        if not proxy is None:
160af093bc9SGerd Hoffmann            self.console_wait_send("f: Proxy",             "f\n")
161af093bc9SGerd Hoffmann            self.console_wait("Proxy")
162af093bc9SGerd Hoffmann            self.console_send("%s\n" % proxy)
163af093bc9SGerd Hoffmann        self.console_wait_send("x: Install pkgin",         "x\n")
164af093bc9SGerd Hoffmann        self.console_init(1200)
165af093bc9SGerd Hoffmann        self.console_wait_send("Hit enter to continue", "\n")
166af093bc9SGerd Hoffmann        self.console_init()
167af093bc9SGerd Hoffmann
168af093bc9SGerd Hoffmann        self.console_wait_send("g: Enable sshd",           "g\n")
169af093bc9SGerd Hoffmann        self.console_wait_send("x: Finished conf",         "x\n")
170af093bc9SGerd Hoffmann        self.console_wait_send("Hit enter to continue",    "\n")
171af093bc9SGerd Hoffmann
172af093bc9SGerd Hoffmann        self.print_step("Installation finished, rebooting")
173af093bc9SGerd Hoffmann        self.console_wait_send("d: Reboot the computer",   "d\n")
174af093bc9SGerd Hoffmann
175af093bc9SGerd Hoffmann        # setup qemu user
176af093bc9SGerd Hoffmann        prompt = "localhost$"
177df001680SRobert Foley        self.console_ssh_init(prompt, self._config["guest_user"],
178df001680SRobert Foley                                      self._config["guest_pass"])
179af093bc9SGerd Hoffmann        self.console_wait_send(prompt, "exit\n")
180af093bc9SGerd Hoffmann
181af093bc9SGerd Hoffmann        # setup root user
182af093bc9SGerd Hoffmann        prompt = "localhost#"
183df001680SRobert Foley        self.console_ssh_init(prompt, "root", self._config["root_pass"])
184af093bc9SGerd Hoffmann        self.console_sshd_config(prompt)
185af093bc9SGerd Hoffmann
186af093bc9SGerd Hoffmann        # setup virtio-blk #1 (tarfile)
187af093bc9SGerd Hoffmann        self.console_wait(prompt)
188af093bc9SGerd Hoffmann        self.console_send("echo 'chmod 666 /dev/rld1a' >> /etc/rc.local\n")
189af093bc9SGerd Hoffmann
190af093bc9SGerd Hoffmann        # turn off mprotect (conflicts with tcg)
191af093bc9SGerd Hoffmann        self.console_wait(prompt)
192af093bc9SGerd Hoffmann        self.console_send("echo security.pax.mprotect.enabled=0 >> /etc/sysctl.conf\n")
193af093bc9SGerd Hoffmann
194af093bc9SGerd Hoffmann        self.print_step("Configuration finished, rebooting")
195af093bc9SGerd Hoffmann        self.console_wait_send(prompt, "reboot\n")
196af093bc9SGerd Hoffmann        self.console_wait("login:")
197af093bc9SGerd Hoffmann        self.wait_ssh()
198af093bc9SGerd Hoffmann
199af093bc9SGerd Hoffmann        self.print_step("Installing packages")
200af093bc9SGerd Hoffmann        self.ssh_root_check("pkgin update\n")
201af093bc9SGerd Hoffmann        self.ssh_root_check("pkgin -y install %s\n" % " ".join(self.pkgs))
202af093bc9SGerd Hoffmann
203af093bc9SGerd Hoffmann        # shutdown
204af093bc9SGerd Hoffmann        self.ssh_root(self.poweroff)
205af093bc9SGerd Hoffmann        self.console_wait("entering state S5")
206af093bc9SGerd Hoffmann        self.wait()
207af093bc9SGerd Hoffmann
2085cd2b138SFam Zheng        os.rename(img_tmp, img)
209af093bc9SGerd Hoffmann        os.remove(iso)
210af093bc9SGerd Hoffmann        self.print_step("All done")
2115cd2b138SFam Zheng
2125cd2b138SFam Zhengif __name__ == "__main__":
2135cd2b138SFam Zheng    sys.exit(basevm.main(NetBSDVM))
214