]> git.proxmox.com Git - mirror_qemu.git/blame - tests/vm/ubuntu.i386
migration: use migration_is_active to represent active state
[mirror_qemu.git] / tests / vm / ubuntu.i386
CommitLineData
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 <famz@redhat.com>
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
14import os
15import sys
16import subprocess
17import basevm
18import time
19
20class 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};
5c2ec9b6 29 make --output-sync {target} -j{jobs} {verbose};
fb15a570
FZ
30 """
31
32 def _gen_cloud_init_iso(self):
33 cidir = self._tmpdir
34 mdata = open(os.path.join(cidir, "meta-data"), "w")
35 mdata.writelines(["instance-id: ubuntu-vm-0\n",
36 "local-hostname: ubuntu-guest\n"])
37 mdata.close()
38 udata = open(os.path.join(cidir, "user-data"), "w")
39 udata.writelines(["#cloud-config\n",
40 "chpasswd:\n",
41 " list: |\n",
42 " root:%s\n" % self.ROOT_PASS,
43 " %s:%s\n" % (self.GUEST_USER, self.GUEST_PASS),
44 " expire: False\n",
45 "users:\n",
46 " - name: %s\n" % self.GUEST_USER,
47 " sudo: ALL=(ALL) NOPASSWD:ALL\n",
48 " ssh-authorized-keys:\n",
49 " - %s\n" % basevm.SSH_PUB_KEY,
50 " - name: root\n",
51 " ssh-authorized-keys:\n",
52 " - %s\n" % basevm.SSH_PUB_KEY,
53 "locale: en_US.UTF-8\n"])
c9b423d6
GH
54 proxy = os.environ.get("http_proxy")
55 if not proxy is None:
56 udata.writelines(["apt:\n",
57 " proxy: %s" % proxy])
fb15a570
FZ
58 udata.close()
59 subprocess.check_call(["genisoimage", "-output", "cloud-init.iso",
60 "-volid", "cidata", "-joliet", "-rock",
61 "user-data", "meta-data"],
62 cwd=cidir,
63 stdin=self._devnull, stdout=self._stdout,
64 stderr=self._stdout)
65 return os.path.join(cidir, "cloud-init.iso")
66
67 def build_image(self, img):
40309abb
CR
68 cimg = self._download_with_cache(
69 "https://cloud-images.ubuntu.com/releases/16.04/release-20190605/ubuntu-16.04-server-cloudimg-i386-disk1.img",
70 sha256sum="e30091144c73483822b7c27193e9d47346dd1064229da577c3fedcf943f7cfcc")
fb15a570
FZ
71 img_tmp = img + ".tmp"
72 subprocess.check_call(["cp", "-f", cimg, img_tmp])
73 subprocess.check_call(["qemu-img", "resize", img_tmp, "50G"])
74 self.boot(img_tmp, extra_args = ["-cdrom", self._gen_cloud_init_iso()])
75 self.wait_ssh()
76 self.ssh_root_check("touch /etc/cloud/cloud-init.disabled")
77 self.ssh_root_check("apt-get update")
78 self.ssh_root_check("apt-get install -y cloud-initramfs-growroot")
79 # Don't check the status in case the guest hang up too quickly
80 self.ssh_root("sync && reboot")
81 time.sleep(5)
82 self.wait_ssh()
83 # The previous update sometimes doesn't survive a reboot, so do it again
95c44c25 84 self.ssh_root_check("sed -ie s/^#\ deb-src/deb-src/g /etc/apt/sources.list")
fb15a570
FZ
85 self.ssh_root_check("apt-get update")
86 self.ssh_root_check("apt-get build-dep -y qemu")
a3f9f64b 87 self.ssh_root_check("apt-get install -y libfdt-dev flex bison")
fb15a570
FZ
88 self.ssh_root("poweroff")
89 self.wait()
fb15a570
FZ
90 os.rename(img_tmp, img)
91 return 0
92
93if __name__ == "__main__":
94 sys.exit(basevm.main(UbuntuX86VM))