]>
Commit | Line | Data |
---|---|---|
c88ee46c | 1 | #!/usr/bin/env python3 |
111e30c0 FZ |
2 | # |
3 | # FreeBSD VM image | |
4 | # | |
918fb8fa | 5 | # Copyright 2017-2019 Red Hat Inc. |
111e30c0 FZ |
6 | # |
7 | # Authors: | |
8 | # Fam Zheng <famz@redhat.com> | |
918fb8fa | 9 | # Gerd Hoffmann <kraxel@redhat.com> |
111e30c0 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 | ||
15 | import os | |
918fb8fa | 16 | import re |
111e30c0 | 17 | import sys |
918fb8fa GH |
18 | import time |
19 | import socket | |
111e30c0 FZ |
20 | import subprocess |
21 | import basevm | |
22 | ||
262fd273 WL |
23 | FREEBSD_CONFIG = { |
24 | 'cpu' : "max,sse4.2=off", | |
25 | } | |
26 | ||
111e30c0 FZ |
27 | class FreeBSDVM(basevm.BaseVM): |
28 | name = "freebsd" | |
31719c37 | 29 | arch = "x86_64" |
918fb8fa | 30 | |
ec6fb1c8 TH |
31 | link = "https://download.freebsd.org/releases/CI-IMAGES/13.2-RELEASE/amd64/Latest/FreeBSD-13.2-RELEASE-amd64-BASIC-CI.raw.xz" |
32 | csum = "a4fb3b6c7b75dd4d58fb0d75e4caf72844bffe0ca00e66459c028b198ffb3c0e" | |
918fb8fa | 33 | size = "20G" |
918fb8fa | 34 | |
111e30c0 FZ |
35 | BUILD_SCRIPT = """ |
36 | set -e; | |
918fb8fa GH |
37 | rm -rf /home/qemu/qemu-test.* |
38 | cd $(mktemp -d /home/qemu/qemu-test.XXXXXX); | |
39 | mkdir src build; cd src; | |
111e30c0 | 40 | tar -xf /dev/vtbd1; |
918fb8fa | 41 | cd ../build |
ec6fb1c8 | 42 | ../src/configure --python=python3.9 {configure_opts}; |
5c2ec9b6 | 43 | gmake --output-sync -j{jobs} {target} {verbose}; |
111e30c0 FZ |
44 | """ |
45 | ||
46 | def build_image(self, img): | |
ec6fb1c8 | 47 | self.print_step("Downloading disk image") |
918fb8fa | 48 | cimg = self._download_with_cache(self.link, sha256sum=self.csum) |
ec6fb1c8 TH |
49 | tmp_raw = img + ".tmp.raw" |
50 | tmp_raw_xz = tmp_raw + ".xz" | |
51 | img_tmp = img + ".tmp.qcow2" | |
52 | ||
53 | self.print_step("Preparing disk image") | |
54 | subprocess.check_call(["cp", "-f", cimg, tmp_raw_xz]) | |
55 | subprocess.check_call(["xz", "-dvf", tmp_raw_xz]) | |
56 | self.exec_qemu_img("convert", "-O", "qcow2", tmp_raw, img_tmp) | |
57 | self.exec_qemu_img("resize", img_tmp, self.size) | |
58 | os.remove(tmp_raw) | |
59 | ||
60 | self.print_step("Preparing disk image") | |
918fb8fa | 61 | self.boot(img_tmp, extra_args = [ |
918fb8fa | 62 | "-machine", "graphics=off", |
ec6fb1c8 | 63 | "-vga", "none" |
918fb8fa GH |
64 | ]) |
65 | self.console_init() | |
ec6fb1c8 TH |
66 | self.console_wait_send("login:", "root\n") |
67 | self.console_wait_send("~ #", "service growfs onestart\n") | |
68 | ||
69 | # root user | |
70 | self.console_wait_send("~ #", "passwd\n") | |
918fb8fa | 71 | self.console_wait("New Password:") |
df001680 | 72 | self.console_send("%s\n" % self._config["root_pass"]) |
918fb8fa | 73 | self.console_wait("Retype New Password:") |
df001680 | 74 | self.console_send("%s\n" % self._config["root_pass"]) |
918fb8fa | 75 | |
918fb8fa | 76 | # qemu user |
ec6fb1c8 | 77 | self.console_wait_send("~ #", "adduser\n") |
918fb8fa | 78 | self.console_wait("Username") |
df001680 | 79 | self.console_send("%s\n" % self._config["guest_user"]) |
918fb8fa | 80 | self.console_wait("Full name") |
df001680 | 81 | self.console_send("%s\n" % self._config["guest_user"]) |
918fb8fa GH |
82 | self.console_wait_send("Uid", "\n") |
83 | self.console_wait_send("Login group", "\n") | |
84 | self.console_wait_send("Login group", "\n") | |
85 | self.console_wait_send("Login class", "\n") | |
86 | self.console_wait_send("Shell", "\n") | |
87 | self.console_wait_send("Home directory", "\n") | |
88 | self.console_wait_send("Home directory perm", "\n") | |
89 | self.console_wait_send("Use password", "\n") | |
90 | self.console_wait_send("Use an empty password", "\n") | |
91 | self.console_wait_send("Use a random password", "\n") | |
92 | self.console_wait("Enter password:") | |
df001680 | 93 | self.console_send("%s\n" % self._config["guest_pass"]) |
918fb8fa | 94 | self.console_wait("Enter password again:") |
df001680 | 95 | self.console_send("%s\n" % self._config["guest_pass"]) |
918fb8fa GH |
96 | self.console_wait_send("Lock out", "\n") |
97 | self.console_wait_send("OK", "yes\n") | |
98 | self.console_wait_send("Add another user", "no\n") | |
ec6fb1c8 | 99 | self.console_wait_send("~ #", "exit\n") |
918fb8fa GH |
100 | |
101 | # setup qemu user | |
102 | prompt = "$" | |
df001680 | 103 | self.console_ssh_init(prompt, self._config["guest_user"], self._config["guest_pass"]) |
918fb8fa GH |
104 | self.console_wait_send(prompt, "exit\n") |
105 | ||
106 | # setup root user | |
107 | prompt = "root@freebsd:~ #" | |
df001680 | 108 | self.console_ssh_init(prompt, "root", self._config["root_pass"]) |
918fb8fa GH |
109 | self.console_sshd_config(prompt) |
110 | ||
918fb8fa GH |
111 | # setup virtio-blk #1 (tarfile) |
112 | self.console_wait(prompt) | |
113 | self.console_send("echo 'chmod 666 /dev/vtbd1' >> /etc/rc.local\n") | |
114 | ||
ca2a07f6 | 115 | pkgs = self.get_qemu_packages_from_lcitool_json() |
918fb8fa | 116 | self.print_step("Installing packages") |
ca2a07f6 | 117 | self.ssh_root_check("pkg install -y %s\n" % " ".join(pkgs)) |
918fb8fa GH |
118 | |
119 | # shutdown | |
120 | self.ssh_root(self.poweroff) | |
918fb8fa GH |
121 | self.wait() |
122 | ||
123 | if os.path.exists(img): | |
124 | os.remove(img) | |
111e30c0 | 125 | os.rename(img_tmp, img) |
918fb8fa | 126 | self.print_step("All done") |
111e30c0 FZ |
127 | |
128 | if __name__ == "__main__": | |
262fd273 | 129 | sys.exit(basevm.main(FreeBSDVM, config=FREEBSD_CONFIG)) |