]> Git Repo - qemu.git/blob - tests/vm/ubuntu.i386
block: Don't silently truncate node names
[qemu.git] / tests / vm / ubuntu.i386
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"
22     BUILD_SCRIPT = """
23         set -e;
24         cd $(mktemp -d);
25         sudo chmod a+r /dev/vdb;
26         tar -xf /dev/vdb;
27         ./configure {configure_opts};
28         make -j{jobs};
29         make check;
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"])
54         udata.close()
55         subprocess.check_call(["genisoimage", "-output", "cloud-init.iso",
56                                "-volid", "cidata", "-joliet", "-rock",
57                                "user-data", "meta-data"],
58                                cwd=cidir,
59                                stdin=self._devnull, stdout=self._stdout,
60                                stderr=self._stdout)
61         return os.path.join(cidir, "cloud-init.iso")
62
63     def build_image(self, img):
64         cimg = self._download_with_cache("https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-i386-disk1.img")
65         img_tmp = img + ".tmp"
66         subprocess.check_call(["cp", "-f", cimg, img_tmp])
67         subprocess.check_call(["qemu-img", "resize", img_tmp, "50G"])
68         self.boot(img_tmp, extra_args = ["-cdrom", self._gen_cloud_init_iso()])
69         self.wait_ssh()
70         self.ssh_root_check("touch /etc/cloud/cloud-init.disabled")
71         self.ssh_root_check("apt-get update")
72         self.ssh_root_check("apt-get install -y cloud-initramfs-growroot")
73         # Don't check the status in case the guest hang up too quickly
74         self.ssh_root("sync && reboot")
75         time.sleep(5)
76         self.wait_ssh()
77         # The previous update sometimes doesn't survive a reboot, so do it again
78         self.ssh_root_check("apt-get update")
79         self.ssh_root_check("apt-get build-dep -y qemu")
80         self.ssh_root_check("apt-get install -y libfdt-dev")
81         self.ssh_root("poweroff")
82         self.wait()
83         if os.path.exists(img):
84             os.remove(img)
85         os.rename(img_tmp, img)
86         return 0
87
88 if __name__ == "__main__":
89     sys.exit(basevm.main(UbuntuX86VM))
This page took 0.029973 seconds and 4 git commands to generate.