mac_newworld: don't use legacy fw_cfg_init_mem() function
[qemu.git] / tests / vm / centos
blobafd560c564ac08f55aef5191bf2db02915adcd41
1 #!/usr/bin/env python
3 # CentOS image
5 # Copyright 2018 Red Hat Inc.
7 # Authors:
8 # Fam Zheng <famz@redhat.com>
10 # This code is licensed under the GPL version 2 or later. See
11 # the COPYING file in the top-level directory.
14 import os
15 import sys
16 import subprocess
17 import basevm
18 import time
20 class CentosVM(basevm.BaseVM):
21 name = "centos"
22 BUILD_SCRIPT = """
23 set -e;
24 cd $(mktemp -d);
25 export SRC_ARCHIVE=/dev/vdb;
26 sudo chmod a+r $SRC_ARCHIVE;
27 tar -xf $SRC_ARCHIVE;
28 make docker-test-block@centos7 V={verbose} J={jobs};
29 make docker-test-quick@centos7 V={verbose} J={jobs};
30 make docker-test-mingw@fedora V={verbose} J={jobs};
31 """
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: centos-vm-0\n",
37 "local-hostname: centos-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")
64 def build_image(self, img):
65 cimg = self._download_with_cache("https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1802.qcow2.xz")
66 img_tmp = img + ".tmp"
67 subprocess.check_call(["cp", "-f", cimg, img_tmp + ".xz"])
68 subprocess.check_call(["xz", "-df", img_tmp + ".xz"])
69 subprocess.check_call(["qemu-img", "resize", img_tmp, "50G"])
70 self.boot(img_tmp, extra_args = ["-cdrom", self._gen_cloud_init_iso()])
71 self.wait_ssh()
72 self.ssh_root_check("touch /etc/cloud/cloud-init.disabled")
73 self.ssh_root_check("yum update -y")
74 self.ssh_root_check("yum install -y docker make git")
75 self.ssh_root_check("systemctl enable docker")
76 self.ssh_root("poweroff")
77 self.wait()
78 if os.path.exists(img):
79 os.remove(img)
80 os.rename(img_tmp, img)
81 return 0
83 if __name__ == "__main__":
84 sys.exit(basevm.main(CentosVM))