]> Git Repo - qemu.git/blame - tests/vm/centos
tests/vm: Allow to set qemu-img path
[qemu.git] / tests / vm / centos
CommitLineData
1bd26988
FZ
1#!/usr/bin/env python
2#
3# CentOS image
4#
5# Copyright 2018 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
14import os
15import sys
16import subprocess
17import basevm
18import time
19
20class CentosVM(basevm.BaseVM):
21 name = "centos"
31719c37 22 arch = "x86_64"
1bd26988
FZ
23 BUILD_SCRIPT = """
24 set -e;
25 cd $(mktemp -d);
26 export SRC_ARCHIVE=/dev/vdb;
27 sudo chmod a+r $SRC_ARCHIVE;
28 tar -xf $SRC_ARCHIVE;
aea43913
WSM
29 make docker-test-block@centos7 {verbose} J={jobs} NETWORK=1;
30 make docker-test-quick@centos7 {verbose} J={jobs} NETWORK=1;
31 make docker-test-mingw@fedora {verbose} J={jobs} NETWORK=1;
1bd26988
FZ
32 """
33
34 def _gen_cloud_init_iso(self):
35 cidir = self._tmpdir
36 mdata = open(os.path.join(cidir, "meta-data"), "w")
37 mdata.writelines(["instance-id: centos-vm-0\n",
38 "local-hostname: centos-guest\n"])
39 mdata.close()
40 udata = open(os.path.join(cidir, "user-data"), "w")
41 udata.writelines(["#cloud-config\n",
42 "chpasswd:\n",
43 " list: |\n",
44 " root:%s\n" % self.ROOT_PASS,
45 " %s:%s\n" % (self.GUEST_USER, self.GUEST_PASS),
46 " expire: False\n",
47 "users:\n",
48 " - name: %s\n" % self.GUEST_USER,
49 " sudo: ALL=(ALL) NOPASSWD:ALL\n",
50 " ssh-authorized-keys:\n",
51 " - %s\n" % basevm.SSH_PUB_KEY,
52 " - name: root\n",
53 " ssh-authorized-keys:\n",
54 " - %s\n" % basevm.SSH_PUB_KEY,
55 "locale: en_US.UTF-8\n"])
56 udata.close()
57 subprocess.check_call(["genisoimage", "-output", "cloud-init.iso",
58 "-volid", "cidata", "-joliet", "-rock",
59 "user-data", "meta-data"],
60 cwd=cidir,
61 stdin=self._devnull, stdout=self._stdout,
62 stderr=self._stdout)
63 return os.path.join(cidir, "cloud-init.iso")
64
65 def build_image(self, img):
66 cimg = self._download_with_cache("https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1802.qcow2.xz")
67 img_tmp = img + ".tmp"
920fff90 68 sys.stderr.write("Extracting the image...\n")
676d1f3e
CR
69 subprocess.check_call(["ln", "-f", cimg, img_tmp + ".xz"])
70 subprocess.check_call(["xz", "--keep", "-dvf", img_tmp + ".xz"])
1e48931c 71 self.exec_qemu_img("resize", img_tmp, "50G")
1bd26988
FZ
72 self.boot(img_tmp, extra_args = ["-cdrom", self._gen_cloud_init_iso()])
73 self.wait_ssh()
74 self.ssh_root_check("touch /etc/cloud/cloud-init.disabled")
75 self.ssh_root_check("yum update -y")
6cd7b608 76 self.ssh_root_check("yum install -y docker make git python3")
1bd26988
FZ
77 self.ssh_root_check("systemctl enable docker")
78 self.ssh_root("poweroff")
79 self.wait()
1bd26988
FZ
80 os.rename(img_tmp, img)
81 return 0
82
83if __name__ == "__main__":
84 sys.exit(basevm.main(CentosVM))
This page took 0.132904 seconds and 4 git commands to generate.