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