]>
Commit | Line | Data |
---|---|---|
fb15a570 FZ |
1 | #!/usr/bin/env python |
2 | # | |
3 | # Ubuntu i386 image | |
4 | # | |
5 | # Copyright 2017 Red Hat Inc. | |
6 | # | |
7 | # Authors: | |
8 | # Fam Zheng <[email protected]> | |
9 | # | |
10 | # This code is licensed under the GPL version 2 or later. See | |
11 | # the COPYING file in the top-level directory. | |
12 | # | |
13 | ||
14 | import os | |
15 | import sys | |
16 | import subprocess | |
17 | import basevm | |
18 | import time | |
19 | ||
20 | class UbuntuX86VM(basevm.BaseVM): | |
21 | name = "ubuntu.i386" | |
31719c37 | 22 | arch = "i386" |
fb15a570 FZ |
23 | BUILD_SCRIPT = """ |
24 | set -e; | |
25 | cd $(mktemp -d); | |
26 | sudo chmod a+r /dev/vdb; | |
27 | tar -xf /dev/vdb; | |
28 | ./configure {configure_opts}; | |
f2d4becd PM |
29 | make --output-sync -j{jobs}; |
30 | make --output-sync check -j{jobs} {verbose}; | |
fb15a570 FZ |
31 | """ |
32 | ||
33 | def _gen_cloud_init_iso(self): | |
34 | cidir = self._tmpdir | |
35 | mdata = open(os.path.join(cidir, "meta-data"), "w") | |
36 | mdata.writelines(["instance-id: ubuntu-vm-0\n", | |
37 | "local-hostname: ubuntu-guest\n"]) | |
38 | mdata.close() | |
39 | udata = open(os.path.join(cidir, "user-data"), "w") | |
40 | udata.writelines(["#cloud-config\n", | |
41 | "chpasswd:\n", | |
42 | " list: |\n", | |
43 | " root:%s\n" % self.ROOT_PASS, | |
44 | " %s:%s\n" % (self.GUEST_USER, self.GUEST_PASS), | |
45 | " expire: False\n", | |
46 | "users:\n", | |
47 | " - name: %s\n" % self.GUEST_USER, | |
48 | " sudo: ALL=(ALL) NOPASSWD:ALL\n", | |
49 | " ssh-authorized-keys:\n", | |
50 | " - %s\n" % basevm.SSH_PUB_KEY, | |
51 | " - name: root\n", | |
52 | " ssh-authorized-keys:\n", | |
53 | " - %s\n" % basevm.SSH_PUB_KEY, | |
54 | "locale: en_US.UTF-8\n"]) | |
55 | udata.close() | |
56 | subprocess.check_call(["genisoimage", "-output", "cloud-init.iso", | |
57 | "-volid", "cidata", "-joliet", "-rock", | |
58 | "user-data", "meta-data"], | |
59 | cwd=cidir, | |
60 | stdin=self._devnull, stdout=self._stdout, | |
61 | stderr=self._stdout) | |
62 | return os.path.join(cidir, "cloud-init.iso") | |
63 | ||
64 | def build_image(self, img): | |
65 | cimg = self._download_with_cache("https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-i386-disk1.img") | |
66 | img_tmp = img + ".tmp" | |
67 | subprocess.check_call(["cp", "-f", cimg, img_tmp]) | |
68 | subprocess.check_call(["qemu-img", "resize", img_tmp, "50G"]) | |
69 | self.boot(img_tmp, extra_args = ["-cdrom", self._gen_cloud_init_iso()]) | |
70 | self.wait_ssh() | |
71 | self.ssh_root_check("touch /etc/cloud/cloud-init.disabled") | |
72 | self.ssh_root_check("apt-get update") | |
73 | self.ssh_root_check("apt-get install -y cloud-initramfs-growroot") | |
74 | # Don't check the status in case the guest hang up too quickly | |
75 | self.ssh_root("sync && reboot") | |
76 | time.sleep(5) | |
77 | self.wait_ssh() | |
78 | # The previous update sometimes doesn't survive a reboot, so do it again | |
79 | self.ssh_root_check("apt-get update") | |
80 | self.ssh_root_check("apt-get build-dep -y qemu") | |
a3f9f64b | 81 | self.ssh_root_check("apt-get install -y libfdt-dev flex bison") |
fb15a570 FZ |
82 | self.ssh_root("poweroff") |
83 | self.wait() | |
84 | if os.path.exists(img): | |
85 | os.remove(img) | |
86 | os.rename(img_tmp, img) | |
87 | return 0 | |
88 | ||
89 | if __name__ == "__main__": | |
90 | sys.exit(basevm.main(UbuntuX86VM)) |