]> git.proxmox.com Git - mirror_qemu.git/blame - tests/vm/openbsd
iotests/303: use dot slash for qcow2.py running
[mirror_qemu.git] / tests / vm / openbsd
CommitLineData
c88ee46c 1#!/usr/bin/env python3
fdfaa332
FZ
2#
3# OpenBSD VM image
4#
12745eaa 5# Copyright 2017-2019 Red Hat Inc.
fdfaa332
FZ
6#
7# Authors:
8# Fam Zheng <famz@redhat.com>
12745eaa 9# Gerd Hoffmann <kraxel@redhat.com>
fdfaa332
FZ
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
15import os
16import sys
12745eaa 17import socket
fdfaa332
FZ
18import subprocess
19import basevm
20
21class OpenBSDVM(basevm.BaseVM):
22 name = "openbsd"
31719c37 23 arch = "x86_64"
12745eaa 24
45716765
BS
25 link = "https://cdn.openbsd.org/pub/OpenBSD/6.8/amd64/install68.iso"
26 csum = "47e291fcc2d0c1a8ae0b66329f040b33af755b6adbd21739e20bb5ad56f62b6c"
12745eaa
GH
27 size = "20G"
28 pkgs = [
29 # tools
30 "git",
31 "pkgconf",
32 "bzip2", "xz",
345d7053 33 "ninja",
12745eaa
GH
34
35 # gnu tools
36 "bash",
37 "gmake",
38 "gsed",
45716765 39 "gettext-tools",
12745eaa
GH
40
41 # libs: usb
45716765 42 "libusb1--",
12745eaa
GH
43
44 # libs: crypto
45 "gnutls",
46
47 # libs: images
48 "jpeg",
49 "png",
50
51 # libs: ui
52 "sdl2",
53 "gtk+3",
54 "libxkbcommon",
3a678481
JQ
55
56 # libs: migration
57 "zstd",
12745eaa
GH
58 ]
59
fdfaa332
FZ
60 BUILD_SCRIPT = """
61 set -e;
12745eaa
GH
62 rm -rf /home/qemu/qemu-test.*
63 cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
64 mkdir src build; cd src;
fdfaa332 65 tar -xf /dev/rsd1c;
12745eaa
GH
66 cd ../build
67 ../src/configure --cc=cc --python=python3 {configure_opts};
68 gmake --output-sync -j{jobs} {target} {verbose};
fdfaa332 69 """
12745eaa 70 poweroff = "halt -p"
fdfaa332
FZ
71
72 def build_image(self, img):
12745eaa
GH
73 self.print_step("Downloading install iso")
74 cimg = self._download_with_cache(self.link, sha256sum=self.csum)
fdfaa332 75 img_tmp = img + ".tmp"
12745eaa
GH
76 iso = img + ".install.iso"
77
78 self.print_step("Preparing iso and disk image")
79 subprocess.check_call(["cp", "-f", cimg, iso])
1e48931c 80 self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size)
12745eaa
GH
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",
50a06452 86 "-device", "VGA",
12745eaa
GH
87 "-cdrom", iso
88 ])
89 self.console_init()
90 self.console_wait_send("boot>", "set tty com0\n")
91 self.console_wait_send("boot>", "\n")
92
93 # pre-install configuration
94 self.console_wait_send("(I)nstall", "i\n")
95 self.console_wait_send("Terminal type", "xterm\n")
96 self.console_wait_send("System hostname", "openbsd\n")
97 self.console_wait_send("Which network interface", "vio0\n")
98 self.console_wait_send("IPv4 address", "dhcp\n")
99 self.console_wait_send("IPv6 address", "none\n")
100 self.console_wait_send("Which network interface", "done\n")
101 self.console_wait_send("DNS domain name", "localnet\n")
102 self.console_wait("Password for root account")
df001680 103 self.console_send("%s\n" % self._config["root_pass"])
12745eaa 104 self.console_wait("Password for root account")
df001680 105 self.console_send("%s\n" % self._config["root_pass"])
12745eaa
GH
106 self.console_wait_send("Start sshd(8)", "yes\n")
107 self.console_wait_send("X Window System", "\n")
108 self.console_wait_send("xenodm", "\n")
109 self.console_wait_send("console to com0", "\n")
110 self.console_wait_send("Which speed", "\n")
111
112 self.console_wait("Setup a user")
df001680 113 self.console_send("%s\n" % self._config["guest_user"])
12745eaa 114 self.console_wait("Full name")
df001680 115 self.console_send("%s\n" % self._config["guest_user"])
12745eaa 116 self.console_wait("Password")
df001680 117 self.console_send("%s\n" % self._config["guest_pass"])
12745eaa 118 self.console_wait("Password")
df001680 119 self.console_send("%s\n" % self._config["guest_pass"])
12745eaa
GH
120
121 self.console_wait_send("Allow root ssh login", "yes\n")
122 self.console_wait_send("timezone", "UTC\n")
123 self.console_wait_send("root disk", "\n")
124 self.console_wait_send("(W)hole disk", "\n")
125 self.console_wait_send("(A)uto layout", "\n")
126 self.console_wait_send("Location of sets", "cd0\n")
127 self.console_wait_send("Pathname to the sets", "\n")
128 self.console_wait_send("Set name(s)", "\n")
129 self.console_wait_send("without verification", "yes\n")
130
131 self.print_step("Installation started now, this will take a while")
132 self.console_wait_send("Location of sets", "done\n")
133
134 self.console_wait("successfully completed")
135 self.print_step("Installation finished, rebooting")
136 self.console_wait_send("(R)eboot", "reboot\n")
137
138 # setup qemu user
139 prompt = "$"
df001680
RF
140 self.console_ssh_init(prompt, self._config["guest_user"],
141 self._config["guest_pass"])
12745eaa
GH
142 self.console_wait_send(prompt, "exit\n")
143
144 # setup root user
145 prompt = "openbsd#"
df001680 146 self.console_ssh_init(prompt, "root", self._config["root_pass"])
12745eaa
GH
147 self.console_sshd_config(prompt)
148
149 # setup virtio-blk #1 (tarfile)
150 self.console_wait(prompt)
151 self.console_send("echo 'chmod 666 /dev/rsd1c' >> /etc/rc.local\n")
152
153 # enable w+x for /home
154 self.console_wait(prompt)
155 self.console_send("sed -i -e '/home/s/rw,/rw,wxallowed,/' /etc/fstab\n")
156
157 # tweak datasize limit
158 self.console_wait(prompt)
159 self.console_send("sed -i -e 's/\\(datasize[^=]*\\)=[^:]*/\\1=infinity/' /etc/login.conf\n")
160
161 # use http (be proxy cache friendly)
162 self.console_wait(prompt)
163 self.console_send("sed -i -e 's/https/http/' /etc/installurl\n")
164
165 self.print_step("Configuration finished, rebooting")
166 self.console_wait_send(prompt, "reboot\n")
167 self.console_wait("login:")
168 self.wait_ssh()
169
170 self.print_step("Installing packages")
171 self.ssh_root_check("pkg_add %s\n" % " ".join(self.pkgs))
172
173 # shutdown
174 self.ssh_root(self.poweroff)
175 self.wait()
176
177 if os.path.exists(img):
178 os.remove(img)
fdfaa332 179 os.rename(img_tmp, img)
12745eaa
GH
180 os.remove(iso)
181 self.print_step("All done")
fdfaa332
FZ
182
183if __name__ == "__main__":
184 sys.exit(basevm.main(OpenBSDVM))