xref: /openbmc/qemu/tests/vm/centos (revision b081986c)
1c88ee46cSPhilippe Mathieu-Daudé#!/usr/bin/env python3
21bd26988SFam Zheng#
31bd26988SFam Zheng# CentOS image
41bd26988SFam Zheng#
51bd26988SFam Zheng# Copyright 2018 Red Hat Inc.
61bd26988SFam Zheng#
71bd26988SFam Zheng# Authors:
81bd26988SFam Zheng#  Fam Zheng <famz@redhat.com>
91bd26988SFam Zheng#
101bd26988SFam Zheng# This code is licensed under the GPL version 2 or later.  See
111bd26988SFam Zheng# the COPYING file in the top-level directory.
121bd26988SFam Zheng#
131bd26988SFam Zheng
141bd26988SFam Zhengimport os
151bd26988SFam Zhengimport sys
161bd26988SFam Zhengimport subprocess
171bd26988SFam Zhengimport basevm
181bd26988SFam Zhengimport time
191bd26988SFam Zheng
201bd26988SFam Zhengclass CentosVM(basevm.BaseVM):
211bd26988SFam Zheng    name = "centos"
2231719c37SPhilippe Mathieu-Daudé    arch = "x86_64"
231bd26988SFam Zheng    BUILD_SCRIPT = """
241bd26988SFam Zheng        set -e;
251bd26988SFam Zheng        cd $(mktemp -d);
261bd26988SFam Zheng        export SRC_ARCHIVE=/dev/vdb;
271bd26988SFam Zheng        sudo chmod a+r $SRC_ARCHIVE;
281bd26988SFam Zheng        tar -xf $SRC_ARCHIVE;
29aea43913SWainer dos Santos Moschetta        make docker-test-block@centos7 {verbose} J={jobs} NETWORK=1;
30aea43913SWainer dos Santos Moschetta        make docker-test-quick@centos7 {verbose} J={jobs} NETWORK=1;
31aea43913SWainer dos Santos Moschetta        make docker-test-mingw@fedora  {verbose} J={jobs} NETWORK=1;
321bd26988SFam Zheng    """
331bd26988SFam Zheng
341bd26988SFam Zheng    def build_image(self, img):
351bd26988SFam Zheng        cimg = self._download_with_cache("https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1802.qcow2.xz")
361bd26988SFam Zheng        img_tmp = img + ".tmp"
37920fff90SPhilippe Mathieu-Daudé        sys.stderr.write("Extracting the image...\n")
38676d1f3eSCleber Rosa        subprocess.check_call(["ln", "-f", cimg, img_tmp + ".xz"])
39676d1f3eSCleber Rosa        subprocess.check_call(["xz", "--keep", "-dvf", img_tmp + ".xz"])
401e48931cSWainer dos Santos Moschetta        self.exec_qemu_img("resize", img_tmp, "50G")
41*b081986cSRobert Foley        self.boot(img_tmp, extra_args = ["-cdrom", self.gen_cloud_init_iso()])
421bd26988SFam Zheng        self.wait_ssh()
431bd26988SFam Zheng        self.ssh_root_check("touch /etc/cloud/cloud-init.disabled")
441bd26988SFam Zheng        self.ssh_root_check("yum update -y")
456cd7b608SAlex Bennée        self.ssh_root_check("yum install -y docker make git python3")
461bd26988SFam Zheng        self.ssh_root_check("systemctl enable docker")
471bd26988SFam Zheng        self.ssh_root("poweroff")
481bd26988SFam Zheng        self.wait()
491bd26988SFam Zheng        os.rename(img_tmp, img)
501bd26988SFam Zheng        return 0
511bd26988SFam Zheng
521bd26988SFam Zhengif __name__ == "__main__":
531bd26988SFam Zheng    sys.exit(basevm.main(CentosVM))
54