2020-07-01 16:56:22 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# Centos aarch64 image
|
|
|
|
#
|
|
|
|
# Copyright 2020 Linaro
|
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Robert Foley <robert.foley@linaro.org>
|
|
|
|
# Originally based on ubuntu.aarch64
|
|
|
|
#
|
|
|
|
# This code is licensed under the GPL version 2 or later. See
|
|
|
|
# the COPYING file in the top-level directory.
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import basevm
|
|
|
|
import time
|
|
|
|
import traceback
|
|
|
|
import aarch64vm
|
|
|
|
|
2022-07-08 18:34:55 +03:00
|
|
|
|
2020-07-01 16:56:22 +03:00
|
|
|
DEFAULT_CONFIG = {
|
|
|
|
'cpu' : "max",
|
|
|
|
'machine' : "virt,gic-version=max",
|
2022-07-08 18:34:55 +03:00
|
|
|
'install_cmds' : (
|
|
|
|
"dnf config-manager --set-enabled powertools, "
|
|
|
|
"dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo, "
|
|
|
|
"dnf install -y make ninja-build git python38 gcc gcc-c++ flex bison "\
|
2023-01-24 21:01:03 +03:00
|
|
|
"glib2-devel pixman-devel zlib-devel docker-ce.aarch64, "
|
2022-07-08 18:34:55 +03:00
|
|
|
"systemctl enable docker, "
|
|
|
|
),
|
2020-07-01 16:56:22 +03:00
|
|
|
# We increase beyond the default time since during boot
|
|
|
|
# it can take some time (many seconds) to log into the VM.
|
|
|
|
'ssh_timeout' : 60,
|
|
|
|
}
|
|
|
|
|
2022-07-08 18:34:55 +03:00
|
|
|
|
2020-07-01 16:56:22 +03:00
|
|
|
class CentosAarch64VM(basevm.BaseVM):
|
2022-07-08 18:34:55 +03:00
|
|
|
name = "centos8.aarch64"
|
2020-07-01 16:56:22 +03:00
|
|
|
arch = "aarch64"
|
2022-07-08 18:34:55 +03:00
|
|
|
image_name = "CentOS-Stream-GenericCloud-8-20220125.1.aarch64.qcow2"
|
|
|
|
image_link = "https://cloud.centos.org/centos/8-stream/aarch64/images/"
|
2020-07-01 16:56:22 +03:00
|
|
|
image_link += image_name
|
|
|
|
BUILD_SCRIPT = """
|
|
|
|
set -e;
|
|
|
|
cd $(mktemp -d);
|
2022-07-08 18:34:55 +03:00
|
|
|
export SRC_ARCHIVE=/dev/vdb;
|
|
|
|
sudo chmod a+r $SRC_ARCHIVE;
|
|
|
|
tar -xf $SRC_ARCHIVE;
|
2020-07-01 16:56:22 +03:00
|
|
|
./configure {configure_opts};
|
|
|
|
make --output-sync {target} -j{jobs} {verbose};
|
|
|
|
"""
|
|
|
|
|
|
|
|
def boot(self, img, extra_args=None):
|
|
|
|
aarch64vm.create_flash_images(self._tmpdir, self._efi_aarch64)
|
|
|
|
default_args = aarch64vm.get_pflash_args(self._tmpdir)
|
|
|
|
if extra_args:
|
|
|
|
extra_args.extend(default_args)
|
|
|
|
else:
|
|
|
|
extra_args = default_args
|
|
|
|
# We always add these performance tweaks
|
|
|
|
# because without them, we boot so slowly that we
|
|
|
|
# can time out finding the boot efi device.
|
|
|
|
if '-smp' not in extra_args and \
|
|
|
|
'-smp' not in self._config['extra_args'] and \
|
|
|
|
'-smp' not in self._args:
|
|
|
|
# Only add if not already there to give caller option to change it.
|
|
|
|
extra_args.extend(["-smp", "8"])
|
|
|
|
# We have overridden boot() since aarch64 has additional parameters.
|
|
|
|
# Call down to the base class method.
|
|
|
|
super(CentosAarch64VM, self).boot(img, extra_args=extra_args)
|
|
|
|
|
|
|
|
def build_image(self, img):
|
2022-07-08 18:34:55 +03:00
|
|
|
cimg = self._download_with_cache(self.image_link)
|
2020-07-01 16:56:22 +03:00
|
|
|
img_tmp = img + ".tmp"
|
2022-07-08 18:34:55 +03:00
|
|
|
subprocess.run(['cp', '-f', cimg, img_tmp])
|
|
|
|
self.exec_qemu_img("resize", img_tmp, "50G")
|
|
|
|
self.boot(img_tmp, extra_args = ["-cdrom", self.gen_cloud_init_iso()])
|
2020-07-01 16:56:22 +03:00
|
|
|
self.wait_ssh(wait_root=True)
|
2022-07-08 18:34:55 +03:00
|
|
|
self.ssh_root_check("touch /etc/cloud/cloud-init.disabled")
|
2020-07-01 16:56:22 +03:00
|
|
|
|
|
|
|
# If the user chooses *not* to do the second phase,
|
|
|
|
# then we will jump right to the graceful shutdown
|
|
|
|
if self._config['install_cmds'] != "":
|
|
|
|
install_cmds = self._config['install_cmds'].split(',')
|
|
|
|
for cmd in install_cmds:
|
2022-07-08 18:34:55 +03:00
|
|
|
self.ssh_root_check(cmd)
|
|
|
|
|
2020-07-01 16:56:22 +03:00
|
|
|
self.ssh_root("poweroff")
|
2022-07-08 18:34:55 +03:00
|
|
|
self.wait()
|
2020-07-01 16:56:22 +03:00
|
|
|
os.rename(img_tmp, img)
|
|
|
|
print("image creation complete: {}".format(img))
|
|
|
|
return 0
|
|
|
|
|
2022-07-08 18:34:55 +03:00
|
|
|
|
2020-07-01 16:56:22 +03:00
|
|
|
if __name__ == "__main__":
|
|
|
|
defaults = aarch64vm.get_config_defaults(CentosAarch64VM, DEFAULT_CONFIG)
|
|
|
|
sys.exit(basevm.main(CentosAarch64VM, defaults))
|