mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-05 03:26:37 +00:00
tests: support parallel building of artifacts
Rework test_images.sh and Makefile to allow building artifacts in parallel for faster tests execution. Add new targets to Makefile ({rootfs,image,initrd}-<distro name>). Fixes: #168 Signed-off-by: Marco Vedovati <mvedovati@suse.com>
This commit is contained in:
parent
5bbbd2abf9
commit
562be90907
82
Makefile
82
Makefile
@ -3,59 +3,87 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
#
|
#
|
||||||
MK_DIR :=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
MK_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
|
TEST_RUNNER := $(MK_DIR)/tests/test_images.sh
|
||||||
|
ROOTFS_BUILDER := $(MK_DIR)/rootfs-builder/rootfs.sh
|
||||||
|
INITRD_BUILDER := $(MK_DIR)/initrd-builder/initrd_builder.sh
|
||||||
|
IMAGE_BUILDER := $(MK_DIR)/image-builder/image_builder.sh
|
||||||
|
|
||||||
DISTRO ?= centos
|
IMG_SIZE = 500
|
||||||
DISTRO_ROOTFS := $(PWD)/$(DISTRO)_rootfs
|
AGENT_INIT ?= no
|
||||||
DISTRO_ROOTFS_MARKER := .$(shell basename $(DISTRO_ROOTFS)).done
|
DISTRO ?= centos
|
||||||
IMAGE := kata-containers.img
|
ROOTFS_BUILD_DEST := $(PWD)
|
||||||
INITRD_IMAGE := kata-containers-initrd.img
|
IMAGES_BUILD_DEST := $(PWD)
|
||||||
IMG_SIZE=500
|
DISTRO_ROOTFS := $(ROOTFS_BUILD_DEST)/$(DISTRO)_rootfs
|
||||||
AGENT_INIT ?= no
|
DISTRO_ROOTFS_MARKER := $(ROOTFS_BUILD_DEST)/.$(DISTRO)_rootfs.done
|
||||||
|
DISTRO_IMAGE := $(IMAGES_BUILD_DEST)/kata-containers.img
|
||||||
|
DISTRO_INITRD := $(IMAGES_BUILD_DEST)/kata-containers-initrd.img
|
||||||
|
|
||||||
VERSION_FILE := ./VERSION
|
VERSION_FILE := ./VERSION
|
||||||
VERSION := $(shell grep -v ^\# $(VERSION_FILE))
|
VERSION := $(shell grep -v ^\# $(VERSION_FILE))
|
||||||
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
|
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
|
||||||
COMMIT := $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO})
|
COMMIT := $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO})
|
||||||
VERSION_COMMIT := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION))
|
VERSION_COMMIT := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION))
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
rootfs-%: $(ROOTFS_BUILD_DEST)/.%_rootfs.done
|
||||||
|
@ # DONT remove. This is not cancellation rule.
|
||||||
|
|
||||||
|
.PRECIOUS: $(ROOTFS_BUILD_DEST)/.%_rootfs.done
|
||||||
|
$(ROOTFS_BUILD_DEST)/.%_rootfs.done:: rootfs-builder/%
|
||||||
|
@echo Creating rootfs for "$*"
|
||||||
|
$(ROOTFS_BUILDER) -o $(VERSION_COMMIT) -r $(ROOTFS_BUILD_DEST)/$*_rootfs $*
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
image-%: $(IMAGES_BUILD_DEST)/kata-containers-image-%.img
|
||||||
|
@ # DONT remove. This is not cancellation rule.
|
||||||
|
|
||||||
|
.PRECIOUS: $(IMAGES_BUILD_DEST)/kata-containers-image-%.img
|
||||||
|
$(IMAGES_BUILD_DEST)/kata-containers-image-%.img: rootfs-%
|
||||||
|
@echo Creating image based on $^
|
||||||
|
$(IMAGE_BUILDER) -s $(IMG_SIZE) -o $@ $(ROOTFS_BUILD_DEST)/$*_rootfs
|
||||||
|
|
||||||
|
initrd-%: $(IMAGES_BUILD_DEST)/kata-containers-initrd-%.img
|
||||||
|
@ # DONT remove. This is not cancellation rule.
|
||||||
|
|
||||||
|
.PRECIOUS: $(IMAGES_BUILD_DEST)/kata-containers-initrd-%.img
|
||||||
|
$(IMAGES_BUILD_DEST)/kata-containers-initrd-%.img: rootfs-%
|
||||||
|
@echo Creating initrd image for $*
|
||||||
|
$(INITRD_BUILDER) -o $@ $(ROOTFS_BUILD_DEST)/$*_rootfs
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: image initrd
|
all: image initrd
|
||||||
|
|
||||||
.PHONY: rootfs
|
.PHONY: rootfs
|
||||||
rootfs: $(DISTRO_ROOTFS_MARKER)
|
rootfs: $(DISTRO_ROOTFS_MARKER)
|
||||||
|
|
||||||
$(DISTRO_ROOTFS_MARKER):
|
|
||||||
@echo Creating rootfs based on "$(DISTRO)"
|
|
||||||
"$(MK_DIR)/rootfs-builder/rootfs.sh" -o $(VERSION_COMMIT) -r $(DISTRO_ROOTFS) $(DISTRO)
|
|
||||||
touch $@
|
|
||||||
|
|
||||||
.PHONY: image
|
.PHONY: image
|
||||||
image: $(IMAGE)
|
image: $(DISTRO_IMAGE)
|
||||||
|
|
||||||
$(IMAGE): rootfs
|
$(DISTRO_IMAGE): $(DISTRO_ROOTFS_MARKER)
|
||||||
@echo Creating image based on "$(DISTRO_ROOTFS)"
|
@echo Creating image based on "$(DISTRO_ROOTFS)"
|
||||||
"$(MK_DIR)/image-builder/image_builder.sh" -s "$(IMG_SIZE)" "$(DISTRO_ROOTFS)"
|
$(IMAGE_BUILDER) -s "$(IMG_SIZE)" "$(DISTRO_ROOTFS)"
|
||||||
|
|
||||||
.PHONY: initrd
|
.PHONY: initrd
|
||||||
initrd: $(INITRD_IMAGE)
|
initrd: $(DISTRO_INITRD)
|
||||||
|
|
||||||
$(INITRD_IMAGE): rootfs
|
$(DISTRO_INITRD): $(DISTRO_ROOTFS_MARKER)
|
||||||
@echo Creating initrd image based on "$(DISTRO_ROOTFS)"
|
@echo Creating initrd image based on "$(DISTRO_ROOTFS)"
|
||||||
"$(MK_DIR)/initrd-builder/initrd_builder.sh" "$(DISTRO_ROOTFS)"
|
$(INITRD_BUILDER) "$(DISTRO_ROOTFS)"
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
"$(MK_DIR)/tests/test_images.sh" "$(DISTRO)"
|
$(TEST_RUNNER) "$(DISTRO)"
|
||||||
|
|
||||||
.PHONY: test-image-only
|
.PHONY: test-image-only
|
||||||
test-image-only:
|
test-image-only:
|
||||||
"$(MK_DIR)/tests/test_images.sh" --test-images-only "$(DISTRO)"
|
$(TEST_RUNNER) --test-images-only "$(DISTRO)"
|
||||||
|
|
||||||
.PHONY: test-initrd-only
|
.PHONY: test-initrd-only
|
||||||
test-initrd-only:
|
test-initrd-only:
|
||||||
"$(MK_DIR)/tests/test_images.sh" --test-initrds-only "$(DISTRO)"
|
$(TEST_RUNNER) --test-initrds-only "$(DISTRO)"
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(DISTRO_ROOTFS_MARKER) $(DISTRO_ROOTFS) $(IMAGE) $(INITRD_IMAGE)
|
rm -rf $(DISTRO_ROOTFS_MARKER) $(DISTRO_ROOTFS) $(DISTRO_IMAGE) $(DISTRO_INITRD)
|
||||||
|
@ -53,7 +53,7 @@ Refer the Platform-OS Compatibility Matrix: https://github.com/kata-containers/o
|
|||||||
|
|
||||||
Options:
|
Options:
|
||||||
-a : agent version DEFAULT: ${AGENT_VERSION} ENV: AGENT_VERSION
|
-a : agent version DEFAULT: ${AGENT_VERSION} ENV: AGENT_VERSION
|
||||||
-h : Show this help message
|
-h : show this help message
|
||||||
-o : specify version of osbuilder
|
-o : specify version of osbuilder
|
||||||
-r : rootfs directory DEFAULT: ${ROOTFS_DIR} ENV: ROOTFS_DIR
|
-r : rootfs directory DEFAULT: ${ROOTFS_DIR} ENV: ROOTFS_DIR
|
||||||
|
|
||||||
|
17
tests/test_config.sh
Normal file
17
tests/test_config.sh
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#
|
||||||
|
# Copyright (c) 2018 SUSE LLC
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
distrosSystemd=(fedora centos ubuntu debian)
|
||||||
|
distrosAgent=(alpine)
|
||||||
|
|
||||||
|
if [ $MACHINE_TYPE != "ppc64le" ]; then
|
||||||
|
distrosSystemd+=(clearlinux)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# "Not testing eurleros on Travis: (timeout, see: https://github.com/kata-containers/osbuilder/issues/46)"
|
||||||
|
if [ -z "${TRAVIS:-}" ]; then
|
||||||
|
distrosSystemd+=(euleros)
|
||||||
|
fi
|
||||||
|
|
@ -4,20 +4,17 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
set -e
|
set -euo pipefail
|
||||||
|
|
||||||
readonly script_dir="$(dirname $(readlink -f $0))"
|
readonly script_dir="$(dirname $(readlink -f $0))"
|
||||||
readonly script_name=${0##*/}
|
readonly script_name=${0##*/}
|
||||||
|
|
||||||
readonly rootfs_sh="${script_dir}/../rootfs-builder/rootfs.sh"
|
|
||||||
readonly image_builder_sh="${script_dir}/../image-builder/image_builder.sh"
|
|
||||||
readonly initrd_builder_sh="${script_dir}/../initrd-builder/initrd_builder.sh"
|
|
||||||
readonly tmp_dir=$(mktemp -t -d osbuilder-test.XXXXXXX)
|
readonly tmp_dir=$(mktemp -t -d osbuilder-test.XXXXXXX)
|
||||||
readonly tmp_rootfs="${tmp_dir}/rootfs-osbuilder"
|
readonly tmp_rootfs="${tmp_dir}/rootfs-osbuilder"
|
||||||
readonly images_dir="${tmp_dir}/images"
|
readonly images_dir="${tmp_dir}/images"
|
||||||
readonly osbuilder_file="/var/lib/osbuilder/osbuilder.yaml"
|
readonly osbuilder_file="/var/lib/osbuilder/osbuilder.yaml"
|
||||||
readonly docker_image="busybox"
|
readonly docker_image="busybox"
|
||||||
readonly docker_config_file="/etc/systemd/system/docker.service.d/kata-containers.conf"
|
readonly systemd_docker_config_file="/etc/systemd/system/docker.service.d/kata-containers.conf"
|
||||||
|
readonly sysconfig_docker_config_file="/etc/sysconfig/docker"
|
||||||
readonly tests_repo="github.com/kata-containers/tests"
|
readonly tests_repo="github.com/kata-containers/tests"
|
||||||
readonly tests_repo_dir="${script_dir}/../../tests"
|
readonly tests_repo_dir="${script_dir}/../../tests"
|
||||||
readonly mgr="${tests_repo_dir}/cmd/kata-manager/kata-manager.sh"
|
readonly mgr="${tests_repo_dir}/cmd/kata-manager/kata-manager.sh"
|
||||||
@ -30,8 +27,10 @@ readonly test_func_prefix="test_distro_"
|
|||||||
# "docker build" does not work with a VM-based runtime
|
# "docker build" does not work with a VM-based runtime
|
||||||
readonly docker_build_runtime="runc"
|
readonly docker_build_runtime="runc"
|
||||||
|
|
||||||
test_images_only="false"
|
build_images=1
|
||||||
test_initrds_only="false"
|
build_initrds=1
|
||||||
|
|
||||||
|
source ${script_dir}/test_config.sh
|
||||||
|
|
||||||
# Hashes used to keep track of image sizes.
|
# Hashes used to keep track of image sizes.
|
||||||
# - Key: name of distro.
|
# - Key: name of distro.
|
||||||
@ -138,14 +137,15 @@ exit_handler()
|
|||||||
|
|
||||||
rm -rf "${tmp_dir}"
|
rm -rf "${tmp_dir}"
|
||||||
|
|
||||||
|
# Restore the default image in config file
|
||||||
|
[ -n "${TRAVIS:-}" ] || chronic $mgr configure-image
|
||||||
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "ERROR: test failed"
|
info "ERROR: test failed"
|
||||||
|
|
||||||
# The test failed so dump what we can
|
# The test failed so dump what we can
|
||||||
info "AGENT_INIT: '${AGENT_INIT}'"
|
|
||||||
|
|
||||||
info "images:"
|
info "images:"
|
||||||
sudo -E ls -l "${images_dir}" >&2
|
sudo -E ls -l "${images_dir}" >&2
|
||||||
|
|
||||||
@ -163,6 +163,9 @@ exit_handler()
|
|||||||
|
|
||||||
info "processes:"
|
info "processes:"
|
||||||
sudo -E ps -efwww | egrep "docker|kata" >&2
|
sudo -E ps -efwww | egrep "docker|kata" >&2
|
||||||
|
|
||||||
|
# Restore the default image in config file
|
||||||
|
[ -n "${TRAVIS:-}" ] || chronic $mgr configure-image
|
||||||
}
|
}
|
||||||
|
|
||||||
die()
|
die()
|
||||||
@ -185,7 +188,15 @@ set_runtime()
|
|||||||
[ -z "$name" ] && die "need name"
|
[ -z "$name" ] && die "need name"
|
||||||
|
|
||||||
# Travis doesn't support VT-x
|
# Travis doesn't support VT-x
|
||||||
[ -n "$TRAVIS" ] && return
|
[ -n "${TRAVIS:-}" ] && return
|
||||||
|
|
||||||
|
source /etc/os-release
|
||||||
|
|
||||||
|
if [[ "${ID_LIKE:-}" =~ suse ]]; then
|
||||||
|
docker_config_file="$sysconfig_docker_config_file"
|
||||||
|
else
|
||||||
|
docker_config_file="$systemd_docker_config_file"
|
||||||
|
fi
|
||||||
|
|
||||||
sudo -E sed -i "s/--default-runtime=[^ ][^ ]*/--default-runtime=${name}/g" \
|
sudo -E sed -i "s/--default-runtime=[^ ][^ ]*/--default-runtime=${name}/g" \
|
||||||
"${docker_config_file}"
|
"${docker_config_file}"
|
||||||
@ -201,7 +212,7 @@ setup()
|
|||||||
export USE_DOCKER=true
|
export USE_DOCKER=true
|
||||||
|
|
||||||
# Travis doesn't support VT-x
|
# Travis doesn't support VT-x
|
||||||
[ -n "$TRAVIS" ] && return
|
[ -n "${TRAVIS:-}" ] && return
|
||||||
|
|
||||||
[ ! -d "${tests_repo_dir}" ] && git clone "https://${tests_repo}" "${tests_repo_dir}"
|
[ ! -d "${tests_repo_dir}" ] && git clone "https://${tests_repo}" "${tests_repo_dir}"
|
||||||
|
|
||||||
@ -212,56 +223,6 @@ setup()
|
|||||||
set_runtime "${docker_build_runtime}"
|
set_runtime "${docker_build_runtime}"
|
||||||
}
|
}
|
||||||
|
|
||||||
build_rootfs()
|
|
||||||
{
|
|
||||||
local distro="$1"
|
|
||||||
local rootfs="$2"
|
|
||||||
|
|
||||||
[ -z "$distro" ] && die "need distro"
|
|
||||||
[ -z "$rootfs" ] && die "need rootfs"
|
|
||||||
|
|
||||||
local full="${rootfs}${osbuilder_file}"
|
|
||||||
|
|
||||||
# clean up from any previous runs
|
|
||||||
[ -d "${rootfs}" ] && sudo -E rm -rf "${rootfs}"
|
|
||||||
|
|
||||||
sudo -E ${rootfs_sh} -r "${rootfs}" "${distro}"
|
|
||||||
|
|
||||||
yamllint "${full}"
|
|
||||||
|
|
||||||
info "built rootfs for distro '$distro' at '$rootfs'"
|
|
||||||
info "osbuilder metadata file:"
|
|
||||||
cat "${full}" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
build_image()
|
|
||||||
{
|
|
||||||
local file="$1"
|
|
||||||
local rootfs="$2"
|
|
||||||
|
|
||||||
[ -z "$file" ] && die "need file"
|
|
||||||
[ -z "$rootfs" ] && die "need rootfs"
|
|
||||||
|
|
||||||
sudo -E ${image_builder_sh} -o "${file}" "${rootfs}"
|
|
||||||
|
|
||||||
info "built image file '$file' for rootfs '$rootfs':"
|
|
||||||
sudo -E ls -l "$file" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
build_initrd()
|
|
||||||
{
|
|
||||||
local file="$1"
|
|
||||||
local rootfs="$2"
|
|
||||||
|
|
||||||
[ -z "$file" ] && die "need file"
|
|
||||||
[ -z "$rootfs" ] && die "need rootfs"
|
|
||||||
|
|
||||||
sudo -E ${initrd_builder_sh} -o "${file}" "${rootfs}"
|
|
||||||
|
|
||||||
info "built initrd file '$file' for rootfs '$rootfs':"
|
|
||||||
sudo -E ls -l "$file" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
create_container()
|
create_container()
|
||||||
{
|
{
|
||||||
out=$(mktemp)
|
out=$(mktemp)
|
||||||
@ -287,7 +248,7 @@ install_image_create_container()
|
|||||||
[ ! -e "$file" ] && die "file does not exist: $file"
|
[ ! -e "$file" ] && die "file does not exist: $file"
|
||||||
|
|
||||||
# Travis doesn't support VT-x
|
# Travis doesn't support VT-x
|
||||||
[ -n "$TRAVIS" ] && return
|
[ -n "${TRAVIS:-}" ] && return
|
||||||
|
|
||||||
chronic $mgr reset-config
|
chronic $mgr reset-config
|
||||||
chronic $mgr configure-image "$file"
|
chronic $mgr configure-image "$file"
|
||||||
@ -302,246 +263,192 @@ install_initrd_create_container()
|
|||||||
[ ! -e "$file" ] && die "file does not exist: $file"
|
[ ! -e "$file" ] && die "file does not exist: $file"
|
||||||
|
|
||||||
# Travis doesn't support VT-x
|
# Travis doesn't support VT-x
|
||||||
[ -n "$TRAVIS" ] && return
|
[ -n "${TRAVIS:-}" ] && return
|
||||||
|
|
||||||
chronic $mgr reset-config
|
chronic $mgr reset-config
|
||||||
chronic $mgr configure-initrd "$file"
|
chronic $mgr configure-initrd "$file"
|
||||||
create_container
|
create_container
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_options()
|
# Displays a list of distros which can be tested
|
||||||
|
list_distros()
|
||||||
{
|
{
|
||||||
local distro="$1"
|
tr " " "\n" <<< "${distrosSystemd[@]} ${distrosAgent[@]}" | sort
|
||||||
local type="$2"
|
|
||||||
local options="$3"
|
|
||||||
|
|
||||||
[ -z "$distro" ] && die "need distro"
|
|
||||||
[ -z "$type" ] && die "need type"
|
|
||||||
|
|
||||||
local opt
|
|
||||||
local rootfs
|
|
||||||
|
|
||||||
for opt in $options
|
|
||||||
do
|
|
||||||
# Set the crucial variable to determine if the agent will be
|
|
||||||
# PID 1 in the image or initrd.
|
|
||||||
case "$opt" in
|
|
||||||
init) export AGENT_INIT="yes";;
|
|
||||||
*) export AGENT_INIT="no";;
|
|
||||||
esac
|
|
||||||
|
|
||||||
rootfs="${tmp_rootfs}/${distro}-agent-init-${AGENT_INIT}"
|
|
||||||
|
|
||||||
build_rootfs "${distro}" "${rootfs}"
|
|
||||||
|
|
||||||
local rootfs_size=$(du -sb "${rootfs}" | awk '{print $1}')
|
|
||||||
|
|
||||||
if [ "$type" = "image" ]
|
|
||||||
then
|
|
||||||
# Images need systemd
|
|
||||||
[ "$opt" = "init" ] && continue
|
|
||||||
|
|
||||||
local image_path="${images_dir}/${type}-${distro}-agent-init-${AGENT_INIT}.img"
|
|
||||||
|
|
||||||
build_image "${image_path}" "${rootfs}"
|
|
||||||
local image_size=$(stat -c "%s" "${image_path}")
|
|
||||||
|
|
||||||
built_images["${distro}"]="${rootfs_size}:${image_size}"
|
|
||||||
|
|
||||||
install_image_create_container "${image_path}"
|
|
||||||
elif [ "$type" = "initrd" ]
|
|
||||||
then
|
|
||||||
local initrd_path="${images_dir}/${type}-${distro}-agent-init-${AGENT_INIT}.img"
|
|
||||||
|
|
||||||
build_initrd "${initrd_path}" "${rootfs}"
|
|
||||||
local initrd_size=$(stat -c "%s" "${initrd_path}")
|
|
||||||
|
|
||||||
built_initrds["${distro}"]="${rootfs_size}:${initrd_size}"
|
|
||||||
|
|
||||||
install_initrd_create_container "${initrd_path}"
|
|
||||||
else
|
|
||||||
die "invalid type: '$type' for distro $distro option $opt"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create an image and/or initrd for the specified distribution,
|
#
|
||||||
|
# Calls the `GNU make` utility with the set of passed arguments.
|
||||||
|
# Arguments can either be make targets or make variables assignments (in the form of VARIABLE=<value>)
|
||||||
|
#
|
||||||
|
call_make() {
|
||||||
|
targetType=$1
|
||||||
|
shift
|
||||||
|
makeVars=()
|
||||||
|
makeTargets=()
|
||||||
|
# Split args between make variable and targets
|
||||||
|
for t in $@; do
|
||||||
|
# RE to match a make variable assignment
|
||||||
|
pattern="^\w+\="
|
||||||
|
if [[ "$t" =~ $pattern ]]; then
|
||||||
|
makeVars+=("$t")
|
||||||
|
else
|
||||||
|
makeTargets+=($targetType-$t)
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
makeJobs=
|
||||||
|
if [ -z "${CI:-}" ]; then
|
||||||
|
((makeJobs=$(nproc) / 2))
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "Starting make with \n\
|
||||||
|
# of // jobs: ${makeJobs:-[unlimited]} \n\
|
||||||
|
targets: ${makeTargets[@]} \n\
|
||||||
|
variables: ${makeVars[@]}"
|
||||||
|
|
||||||
|
sudo -E make -j $makeJobs ${makeTargets[@]} ${makeVars[@]}
|
||||||
|
}
|
||||||
|
|
||||||
|
make_rootfs() {
|
||||||
|
call_make rootfs $@
|
||||||
|
}
|
||||||
|
|
||||||
|
make_image() {
|
||||||
|
call_make image $@
|
||||||
|
}
|
||||||
|
|
||||||
|
make_initrd() {
|
||||||
|
call_make initrd $@
|
||||||
|
}
|
||||||
|
|
||||||
|
get_rootfs_size() {
|
||||||
|
[ $# -ne 1 ] && die "get_rootfs_size with wrong invalid argument"
|
||||||
|
|
||||||
|
local rootfs_dir=$1
|
||||||
|
! [ -d "$rootfs_dir" ] && die "$rootfs_dir is not a valid rootfs path"
|
||||||
|
|
||||||
|
sudo -E du -sb "${rootfs_dir}" | awk '{print $1}'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create an image and/or initrd for the available distributions,
|
||||||
# then test each by configuring the runtime and creating a container.
|
# then test each by configuring the runtime and creating a container.
|
||||||
#
|
#
|
||||||
# The second and third parameters take the form of a space separated list of
|
# When passing the name of a distribution, tests are run against that
|
||||||
# values which represent whether the agent should be the init daemon in the
|
# distribution only.
|
||||||
# image/initrd. "init" means the agent should be configured to be the init
|
|
||||||
# daemon and "service" means it should run as a systemd service.
|
|
||||||
#
|
|
||||||
# The list value should be set to "no" if the image/initrd should not
|
|
||||||
# be built+tested.
|
|
||||||
#
|
#
|
||||||
# Parameters:
|
# Parameters:
|
||||||
#
|
#
|
||||||
# 1: distro name.
|
# 1: distro name.
|
||||||
# 2: image options.
|
#
|
||||||
# 3: initrd options.
|
test_distros()
|
||||||
create_and_run()
|
|
||||||
{
|
{
|
||||||
local distro="$1"
|
local distro="$1"
|
||||||
local image_options="$2"
|
local separator="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
|
||||||
local initrd_options="$3"
|
|
||||||
|
|
||||||
[ -z "$distro" ] && die "need distro"
|
echo -e "$separator"
|
||||||
[ -z "$image_options" ] && die "need image options"
|
|
||||||
[ -z "$initrd_options" ] && die "need initrd options"
|
|
||||||
|
|
||||||
local opt
|
# If a distro was specified, filter out the distro list to only include that distro
|
||||||
|
if [ -n "$distro" ]; then
|
||||||
if [ "$image_options" != "no" ]
|
pattern="\<$distro\>"
|
||||||
then
|
if [[ "${distrosAgent[@]}" =~ $pattern ]]; then
|
||||||
if [ "${test_initrds_only}" = "true" ]
|
distrosAgent=($distro)
|
||||||
then
|
distrosSystemd=()
|
||||||
info "only testing initrds: skipping image test for distro $distro"
|
elif [[ "${distrosSystemd[@]}" =~ $pattern ]]; then
|
||||||
|
distrosSystemd=($distro)
|
||||||
|
distrosAgent=()
|
||||||
|
build_initrds=
|
||||||
else
|
else
|
||||||
handle_options "$distro" "image" "$image_options"
|
die "Not a valid distro: $distro"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
info "Running tests for distro: $distro"
|
||||||
|
|
||||||
|
else
|
||||||
|
info "Running tests for all distros"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$initrd_options" != "no" ]
|
# distro with systemd as init -> normal rootfs image
|
||||||
then
|
# distro with kata-agent as init -> normal rootfs image AND initrd image
|
||||||
if [ "${test_images_only}" = "true" ]
|
|
||||||
then
|
|
||||||
info "only testing images: skipping initrd test for distro $distro"
|
|
||||||
else
|
|
||||||
handle_options "$distro" "initrd" "$initrd_options"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
run_test()
|
# If user does not need rootfs images, then do not build systemd rootfses
|
||||||
{
|
[ -z "$build_images" ] && distrosSystemd=()
|
||||||
local -r name="$1"
|
|
||||||
local -r skip="$2"
|
|
||||||
local -r distro="$3"
|
|
||||||
local -r image_options="$4"
|
|
||||||
local -r initrd_options="$5"
|
|
||||||
|
|
||||||
[ -z "$name" ] && die "need name"
|
commonMakeVars=( \
|
||||||
[ -z "$distro" ] && die "need distro"
|
USE_DOCKER=true \
|
||||||
[ -z "$image_options" ] && die "need image options"
|
ROOTFS_BUILD_DEST="$tmp_rootfs" \
|
||||||
[ -z "$initrd_options" ] && die "need initrd options"
|
IMAGES_BUILD_DEST="$images_dir" )
|
||||||
|
|
||||||
[ -n "$skip" ] && info "Skipping test $name: $skip" && return
|
# Build systemd and agent rootfs with 2 separate jobs
|
||||||
|
bgJobs=()
|
||||||
|
|
||||||
info "Running test: ${name}"
|
if [ ${#distrosSystemd[@]} -gt 0 ]; then
|
||||||
|
info "building rootfses with systemd as init: ${distrosSystemd[@]}"
|
||||||
create_and_run "${distro}" "${image_options}" "${initrd_options}"
|
make_rootfs ${commonMakeVars[@]} "${distrosSystemd[@]}" &
|
||||||
}
|
bgJobs+=($!)
|
||||||
|
|
||||||
test_distro_ubuntu()
|
|
||||||
{
|
|
||||||
local -r name="Can create and run ubuntu image"
|
|
||||||
run_test "${name}" "" "ubuntu" "service" "no"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_distro_debian()
|
|
||||||
{
|
|
||||||
local -r name="Can create and run debian image"
|
|
||||||
run_test "${name}" "" "debian" "service" "no"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
test_distro_fedora()
|
|
||||||
{
|
|
||||||
local -r name="Can create and run fedora image"
|
|
||||||
run_test "${name}" "" "fedora" "service" "no"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_distro_clearlinux()
|
|
||||||
{
|
|
||||||
local -r name="Can create and run clearlinux image"
|
|
||||||
|
|
||||||
run_test "${name}" "" "clearlinux" "service" "no"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_distro_centos()
|
|
||||||
{
|
|
||||||
local -r name="Can create and run centos image"
|
|
||||||
run_test "${name}" "" "centos" "service" "no"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_distro_euleros()
|
|
||||||
{
|
|
||||||
local -r name="Can create and run euleros image"
|
|
||||||
|
|
||||||
[ "$TRAVIS" = true ] && skip="travis timeout, see: https://github.com/kata-containers/osbuilder/issues/46"
|
|
||||||
|
|
||||||
run_test "${name}" "$skip" "euleros" "service" "no"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_distro_alpine()
|
|
||||||
{
|
|
||||||
local -r name="Can create and run alpine image"
|
|
||||||
run_test "${name}" "" "alpine" "no" "init"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Displays a list of all distro test functions
|
|
||||||
get_distro_test_names()
|
|
||||||
{
|
|
||||||
typeset -F | awk '{print $3}' |\
|
|
||||||
grep "^${test_func_prefix}" | sort
|
|
||||||
}
|
|
||||||
|
|
||||||
# Displays a list of distros which can be tested
|
|
||||||
list_distros()
|
|
||||||
{
|
|
||||||
get_distro_test_names | sed "s/${test_func_prefix}//g"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_single_distro()
|
|
||||||
{
|
|
||||||
local -r distro="$1"
|
|
||||||
|
|
||||||
[ -z "$distro" ] && die "distro cannot be blank"
|
|
||||||
|
|
||||||
local -r expected_func="${test_func_prefix}${distro}"
|
|
||||||
|
|
||||||
local test_funcs
|
|
||||||
test_funcs=$(get_distro_test_names)
|
|
||||||
|
|
||||||
local defined_func
|
|
||||||
defined_func=$(echo "$test_funcs" | grep "^${expected_func}$" || true)
|
|
||||||
|
|
||||||
if [ -z "$defined_func" ]
|
|
||||||
then
|
|
||||||
local distros
|
|
||||||
|
|
||||||
# make a comma-separated list
|
|
||||||
distros=$(list_distros | tr '\n' ',' | sed 's/,$//g')
|
|
||||||
|
|
||||||
die "no test for distro '$distro' (try one of $distros)"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "only running tests for distro $distro"
|
if [ ${#distrosAgent[@]} -gt 0 ]; then
|
||||||
|
info "building all rootfses with kata-agent as init"
|
||||||
# run the test
|
make_rootfs ${commonMakeVars[@]} AGENT_INIT=yes "${distrosAgent[@]}" &
|
||||||
$defined_func
|
bgJobs+=($!)
|
||||||
}
|
|
||||||
|
|
||||||
test_all_distros()
|
|
||||||
{
|
|
||||||
info "running tests for all distros"
|
|
||||||
|
|
||||||
test_distro_fedora
|
|
||||||
test_distro_centos
|
|
||||||
test_distro_alpine
|
|
||||||
test_distro_ubuntu
|
|
||||||
test_distro_debian
|
|
||||||
if [ $MACHINE_TYPE != "ppc64le" ]; then
|
|
||||||
test_distro_clearlinux
|
|
||||||
|
|
||||||
# Run last as EulerOS servers can be slow and we don't want to fail the
|
|
||||||
# previous tests.
|
|
||||||
test_distro_euleros
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check for build failures (`wait` remembers up to CHILD_MAX bg processes exit status)
|
||||||
|
for j in ${bgJobs[@]}; do
|
||||||
|
wait $j || die "Background build job failed"
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
for d in ${distrosSystemd[@]} ${distrosAgent[@]}; do
|
||||||
|
local rootfs_path="${tmp_rootfs}/${d}_rootfs"
|
||||||
|
osbuilder_file_fullpath="${rootfs_path}/${osbuilder_file}"
|
||||||
|
echo -e "$separator"
|
||||||
|
yamllint "${osbuilder_file_fullpath}"
|
||||||
|
|
||||||
|
info "osbuilder metadata file for $d:"
|
||||||
|
cat "${osbuilder_file_fullpath}" >&2
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: once support for rootfs images with kata-agent as init is in place,
|
||||||
|
# uncomment the following line
|
||||||
|
# for d in ${distrosSystemd[@]} ${distrosAgent[@]}; do
|
||||||
|
for d in ${distrosSystemd[@]}; do
|
||||||
|
local rootfs_path="${tmp_rootfs}/${d}_rootfs"
|
||||||
|
local image_path="${images_dir}/kata-containers-image-$d.img"
|
||||||
|
local rootfs_size=$(get_rootfs_size "$rootfs_path")
|
||||||
|
|
||||||
|
echo -e "$separator"
|
||||||
|
info "Making rootfs image for ${d}"
|
||||||
|
make_image ${commonMakeVars[@]} $d
|
||||||
|
local image_size=$(stat -c "%s" "${image_path}")
|
||||||
|
|
||||||
|
echo -e "$separator"
|
||||||
|
built_images["${d}"]="${rootfs_size}:${image_size}"
|
||||||
|
info "Creating container for ${d}"
|
||||||
|
install_image_create_container $image_path
|
||||||
|
done
|
||||||
|
|
||||||
|
for d in ${distrosAgent[@]}; do
|
||||||
|
local rootfs_path="${tmp_rootfs}/${d}_rootfs"
|
||||||
|
local initrd_path="${images_dir}/kata-containers-initrd-$d.img"
|
||||||
|
local rootfs_size=$(get_rootfs_size "$rootfs_path")
|
||||||
|
|
||||||
|
echo -e "$separator"
|
||||||
|
info "Making initrd image for ${d}"
|
||||||
|
make_initrd ${commonMakeVars[@]} AGENT_INIT=yes $d
|
||||||
|
local initrd_size=$(stat -c "%s" "${initrd_path}")
|
||||||
|
|
||||||
|
echo -e "$separator"
|
||||||
|
built_initrds["${d}"]="${rootfs_size}:${initrd_size}"
|
||||||
|
info "Creating container for ${d}"
|
||||||
|
install_initrd_create_container $initrd_path
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e "$separator"
|
||||||
show_stats
|
show_stats
|
||||||
|
|
||||||
|
echo -e "$separator"
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
@ -566,13 +473,11 @@ main()
|
|||||||
--list) list_distros; exit 0;;
|
--list) list_distros; exit 0;;
|
||||||
|
|
||||||
--test-images-only)
|
--test-images-only)
|
||||||
test_images_only="true"
|
build_initrds=
|
||||||
test_initrds_only="false"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
--test-initrds-only)
|
--test-initrds-only)
|
||||||
test_initrds_only="true"
|
build_images=
|
||||||
test_images_only="false"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
--) shift; break ;;
|
--) shift; break ;;
|
||||||
@ -584,21 +489,16 @@ main()
|
|||||||
# Consume getopt cruft
|
# Consume getopt cruft
|
||||||
[ "$1" = "--" ] && shift
|
[ "$1" = "--" ] && shift
|
||||||
|
|
||||||
case "$1" in
|
case "${1:-}" in
|
||||||
help) usage; exit 0;;
|
help) usage; exit 0;;
|
||||||
|
|
||||||
*) distro="$1";;
|
*) distro="${1:-}";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
trap exit_handler EXIT ERR
|
trap exit_handler EXIT ERR
|
||||||
setup
|
setup
|
||||||
|
|
||||||
if [ -n "$distro" ]
|
test_distros "$distro"
|
||||||
then
|
|
||||||
test_single_distro "$distro"
|
|
||||||
else
|
|
||||||
test_all_distros
|
|
||||||
fi
|
|
||||||
|
|
||||||
# We shouldn't really need a message like this but the CI can fail in
|
# We shouldn't really need a message like this but the CI can fail in
|
||||||
# mysterious ways so make it clear!
|
# mysterious ways so make it clear!
|
||||||
|
Loading…
Reference in New Issue
Block a user