Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20190714' into staging
[qemu/ar7.git] / tests / vm / openbsd
blobb92c39f89a6f46581a8729b4ed43f070a19c4c9c
1 #!/usr/bin/env python
3 # OpenBSD VM image
5 # Copyright 2017-2019 Red Hat Inc.
7 # Authors:
8 # Fam Zheng <famz@redhat.com>
9 # Gerd Hoffmann <kraxel@redhat.com>
11 # This code is licensed under the GPL version 2 or later. See
12 # the COPYING file in the top-level directory.
15 import os
16 import sys
17 import socket
18 import subprocess
19 import basevm
21 class OpenBSDVM(basevm.BaseVM):
22 name = "openbsd"
23 arch = "x86_64"
25 link = "https://cdn.openbsd.org/pub/OpenBSD/6.5/amd64/install65.iso"
26 csum = "38d1f8cadd502f1c27bf05c5abde6cc505dd28f3f34f8a941048ff9a54f9f608"
27 size = "20G"
28 pkgs = [
29 # tools
30 "git",
31 "pkgconf",
32 "bzip2", "xz",
34 # gnu tools
35 "bash",
36 "gmake",
37 "gsed",
38 "bison",
40 # libs: usb
41 "libusb1",
43 # libs: crypto
44 "gnutls",
46 # libs: images
47 "jpeg",
48 "png",
50 # libs: ui
51 "sdl2",
52 "gtk+3",
53 "libxkbcommon",
56 BUILD_SCRIPT = """
57 set -e;
58 rm -rf /home/qemu/qemu-test.*
59 cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
60 mkdir src build; cd src;
61 tar -xf /dev/rsd1c;
62 cd ../build
63 ../src/configure --cc=cc --python=python3 {configure_opts};
64 gmake --output-sync -j{jobs} {target} {verbose};
65 """
66 poweroff = "halt -p"
68 def build_image(self, img):
69 self.print_step("Downloading install iso")
70 cimg = self._download_with_cache(self.link, sha256sum=self.csum)
71 img_tmp = img + ".tmp"
72 iso = img + ".install.iso"
74 self.print_step("Preparing iso and disk image")
75 subprocess.check_call(["cp", "-f", cimg, iso])
76 subprocess.check_call(["qemu-img", "create", "-f", "qcow2",
77 img_tmp, self.size])
79 self.print_step("Booting installer")
80 self.boot(img_tmp, extra_args = [
81 "-bios", "pc-bios/bios-256k.bin",
82 "-machine", "graphics=off",
83 "-cdrom", iso
85 self.console_init()
86 self.console_wait_send("boot>", "set tty com0\n")
87 self.console_wait_send("boot>", "\n")
89 # pre-install configuration
90 self.console_wait_send("(I)nstall", "i\n")
91 self.console_wait_send("Terminal type", "xterm\n")
92 self.console_wait_send("System hostname", "openbsd\n")
93 self.console_wait_send("Which network interface", "vio0\n")
94 self.console_wait_send("IPv4 address", "dhcp\n")
95 self.console_wait_send("IPv6 address", "none\n")
96 self.console_wait_send("Which network interface", "done\n")
97 self.console_wait_send("DNS domain name", "localnet\n")
98 self.console_wait("Password for root account")
99 self.console_send("%s\n" % self.ROOT_PASS)
100 self.console_wait("Password for root account")
101 self.console_send("%s\n" % self.ROOT_PASS)
102 self.console_wait_send("Start sshd(8)", "yes\n")
103 self.console_wait_send("X Window System", "\n")
104 self.console_wait_send("xenodm", "\n")
105 self.console_wait_send("console to com0", "\n")
106 self.console_wait_send("Which speed", "\n")
108 self.console_wait("Setup a user")
109 self.console_send("%s\n" % self.GUEST_USER)
110 self.console_wait("Full name")
111 self.console_send("%s\n" % self.GUEST_USER)
112 self.console_wait("Password")
113 self.console_send("%s\n" % self.GUEST_PASS)
114 self.console_wait("Password")
115 self.console_send("%s\n" % self.GUEST_PASS)
117 self.console_wait_send("Allow root ssh login", "yes\n")
118 self.console_wait_send("timezone", "UTC\n")
119 self.console_wait_send("root disk", "\n")
120 self.console_wait_send("(W)hole disk", "\n")
121 self.console_wait_send("(A)uto layout", "\n")
122 self.console_wait_send("Location of sets", "cd0\n")
123 self.console_wait_send("Pathname to the sets", "\n")
124 self.console_wait_send("Set name(s)", "\n")
125 self.console_wait_send("without verification", "yes\n")
127 self.print_step("Installation started now, this will take a while")
128 self.console_wait_send("Location of sets", "done\n")
130 self.console_wait("successfully completed")
131 self.print_step("Installation finished, rebooting")
132 self.console_wait_send("(R)eboot", "reboot\n")
134 # setup qemu user
135 prompt = "$"
136 self.console_ssh_init(prompt, self.GUEST_USER, self.GUEST_PASS)
137 self.console_wait_send(prompt, "exit\n")
139 # setup root user
140 prompt = "openbsd#"
141 self.console_ssh_init(prompt, "root", self.ROOT_PASS)
142 self.console_sshd_config(prompt)
144 # setup virtio-blk #1 (tarfile)
145 self.console_wait(prompt)
146 self.console_send("echo 'chmod 666 /dev/rsd1c' >> /etc/rc.local\n")
148 # enable w+x for /home
149 self.console_wait(prompt)
150 self.console_send("sed -i -e '/home/s/rw,/rw,wxallowed,/' /etc/fstab\n")
152 # tweak datasize limit
153 self.console_wait(prompt)
154 self.console_send("sed -i -e 's/\\(datasize[^=]*\\)=[^:]*/\\1=infinity/' /etc/login.conf\n")
156 # use http (be proxy cache friendly)
157 self.console_wait(prompt)
158 self.console_send("sed -i -e 's/https/http/' /etc/installurl\n")
160 self.print_step("Configuration finished, rebooting")
161 self.console_wait_send(prompt, "reboot\n")
162 self.console_wait("login:")
163 self.wait_ssh()
165 self.print_step("Installing packages")
166 self.ssh_root_check("pkg_add %s\n" % " ".join(self.pkgs))
168 # shutdown
169 self.ssh_root(self.poweroff)
170 self.wait()
172 if os.path.exists(img):
173 os.remove(img)
174 os.rename(img_tmp, img)
175 os.remove(iso)
176 self.print_step("All done")
178 if __name__ == "__main__":
179 sys.exit(basevm.main(OpenBSDVM))