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