mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-22 17:59:31 +00:00
Merge pull request #114 from jodh-intel/kata-manager-update
tests: Update kata-manager command
This commit is contained in:
commit
ae5b40ab88
@ -23,8 +23,3 @@ run_static_checks()
|
|||||||
clone_tests_repo
|
clone_tests_repo
|
||||||
bash "$tests_repo_dir/.ci/static-checks.sh" "github.com/kata-containers/osbuilder"
|
bash "$tests_repo_dir/.ci/static-checks.sh" "github.com/kata-containers/osbuilder"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_bats()
|
|
||||||
{
|
|
||||||
bash "$tests_repo_dir/.ci/install_bats.sh"
|
|
||||||
}
|
|
||||||
|
@ -12,4 +12,4 @@ export GOPATH="${GOPATH:-/tmp/go}"
|
|||||||
|
|
||||||
script_dir="$(dirname $(readlink -f $0))"
|
script_dir="$(dirname $(readlink -f $0))"
|
||||||
|
|
||||||
sudo -E PATH="$PATH" bats "${script_dir}/../tests/image_creation.bats"
|
sudo -E PATH="$PATH" bash "${script_dir}/../tests/image_creation.sh"
|
||||||
|
@ -15,8 +15,6 @@ bash "${cidir}/static-checks.sh"
|
|||||||
#Note: If add clearlinux as supported CI use a stateless os-release file
|
#Note: If add clearlinux as supported CI use a stateless os-release file
|
||||||
source /etc/os-release
|
source /etc/os-release
|
||||||
|
|
||||||
install_bats
|
|
||||||
|
|
||||||
if [ "$ID" == fedora ];then
|
if [ "$ID" == fedora ];then
|
||||||
sudo -E dnf -y install automake yamllint coreutils moreutils
|
sudo -E dnf -y install automake yamllint coreutils moreutils
|
||||||
elif [ "$ID" == centos ];then
|
elif [ "$ID" == centos ];then
|
||||||
|
201
tests/image_creation.bats → tests/image_creation.sh
Normal file → Executable file
201
tests/image_creation.bats → tests/image_creation.sh
Normal file → Executable file
@ -1,12 +1,16 @@
|
|||||||
#!/usr/bin/env bats
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# Copyright (c) 2018 Intel Corporation
|
# Copyright (c) 2018 Intel Corporation
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
readonly rootfs_sh="$BATS_TEST_DIRNAME/../rootfs-builder/rootfs.sh"
|
set -e
|
||||||
readonly image_builder_sh="$BATS_TEST_DIRNAME/../image-builder/image_builder.sh"
|
|
||||||
readonly initrd_builder_sh="$BATS_TEST_DIRNAME/../initrd-builder/initrd_builder.sh"
|
readonly script_dir="$(dirname $(readlink -f $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"
|
||||||
@ -14,53 +18,16 @@ 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 docker_config_file="/etc/systemd/system/docker.service.d/kata-containers.conf"
|
||||||
readonly tests_repo="github.com/kata-containers/tests"
|
readonly tests_repo="github.com/kata-containers/tests"
|
||||||
readonly tests_repo_dir="$BATS_TEST_DIRNAME/../../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"
|
||||||
readonly RUNTIME=${RUNTIME:-kata-runtime}
|
readonly RUNTIME=${RUNTIME:-kata-runtime}
|
||||||
|
|
||||||
# "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"
|
||||||
|
|
||||||
info()
|
exit_handler()
|
||||||
{
|
{
|
||||||
s="$*"
|
if [ "$?" -eq 0 ]
|
||||||
echo -e "INFO: $s\n" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
set_runtime()
|
|
||||||
{
|
|
||||||
local name="$1"
|
|
||||||
|
|
||||||
# Travis doesn't support VT-x
|
|
||||||
[ -n "$TRAVIS" ] && return
|
|
||||||
|
|
||||||
sudo -E sed -i "s/--default-runtime=[^ ][^ ]*/--default-runtime=${name}/g" \
|
|
||||||
"${docker_config_file}"
|
|
||||||
sudo -E systemctl daemon-reload
|
|
||||||
sudo -E systemctl restart docker
|
|
||||||
}
|
|
||||||
|
|
||||||
setup()
|
|
||||||
{
|
|
||||||
mkdir -p "${images_dir}"
|
|
||||||
|
|
||||||
export USE_DOCKER=true
|
|
||||||
|
|
||||||
# Travis doesn't support VT-x
|
|
||||||
[ -n "$TRAVIS" ] && return
|
|
||||||
|
|
||||||
[ ! -d "${tests_repo_dir}" ] && git clone "https://${tests_repo}" "${tests_repo_dir}"
|
|
||||||
|
|
||||||
chronic $mgr install-packages
|
|
||||||
chronic $mgr enable-debug
|
|
||||||
|
|
||||||
# Ensure "docker build" works
|
|
||||||
set_runtime "${docker_build_runtime}"
|
|
||||||
}
|
|
||||||
|
|
||||||
teardown()
|
|
||||||
{
|
|
||||||
if [ "$BATS_ERROR_STATUS" -eq 0 ]
|
|
||||||
then
|
then
|
||||||
# Rootfs and images are owned by root
|
# Rootfs and images are owned by root
|
||||||
sudo -E rm -rf "${tmp_rootfs}"
|
sudo -E rm -rf "${tmp_rootfs}"
|
||||||
@ -94,11 +61,63 @@ teardown()
|
|||||||
sudo -E ps -efwww | egrep "docker|kata" >&2
|
sudo -E ps -efwww | egrep "docker|kata" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trap exit_handler EXIT ERR
|
||||||
|
|
||||||
|
die()
|
||||||
|
{
|
||||||
|
msg="$*"
|
||||||
|
echo "ERROR: $msg" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
info()
|
||||||
|
{
|
||||||
|
s="$*"
|
||||||
|
echo -e "INFO: $s\n" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
set_runtime()
|
||||||
|
{
|
||||||
|
local name="$1"
|
||||||
|
|
||||||
|
[ -z "$name" ] && die "need name"
|
||||||
|
|
||||||
|
# Travis doesn't support VT-x
|
||||||
|
[ -n "$TRAVIS" ] && return
|
||||||
|
|
||||||
|
sudo -E sed -i "s/--default-runtime=[^ ][^ ]*/--default-runtime=${name}/g" \
|
||||||
|
"${docker_config_file}"
|
||||||
|
sudo -E systemctl daemon-reload
|
||||||
|
sudo -E systemctl restart docker
|
||||||
|
}
|
||||||
|
|
||||||
|
setup()
|
||||||
|
{
|
||||||
|
[ -z "$images_dir" ] && die "need images directory"
|
||||||
|
mkdir -p "${images_dir}"
|
||||||
|
|
||||||
|
export USE_DOCKER=true
|
||||||
|
|
||||||
|
# Travis doesn't support VT-x
|
||||||
|
[ -n "$TRAVIS" ] && return
|
||||||
|
|
||||||
|
[ ! -d "${tests_repo_dir}" ] && git clone "https://${tests_repo}" "${tests_repo_dir}"
|
||||||
|
|
||||||
|
chronic $mgr install-docker-system
|
||||||
|
chronic $mgr enable-debug
|
||||||
|
|
||||||
|
# Ensure "docker build" works
|
||||||
|
set_runtime "${docker_build_runtime}"
|
||||||
|
}
|
||||||
|
|
||||||
build_rootfs()
|
build_rootfs()
|
||||||
{
|
{
|
||||||
local distro="$1"
|
local distro="$1"
|
||||||
local rootfs="$2"
|
local rootfs="$2"
|
||||||
|
|
||||||
|
[ -z "$distro" ] && die "need distro"
|
||||||
|
[ -z "$rootfs" ] && die "need rootfs"
|
||||||
|
|
||||||
local full="${rootfs}${osbuilder_file}"
|
local full="${rootfs}${osbuilder_file}"
|
||||||
|
|
||||||
# clean up from any previous runs
|
# clean up from any previous runs
|
||||||
@ -118,6 +137,9 @@ build_image()
|
|||||||
local file="$1"
|
local file="$1"
|
||||||
local rootfs="$2"
|
local rootfs="$2"
|
||||||
|
|
||||||
|
[ -z "$file" ] && die "need file"
|
||||||
|
[ -z "$rootfs" ] && die "need rootfs"
|
||||||
|
|
||||||
sudo -E ${image_builder_sh} -o "${file}" "${rootfs}"
|
sudo -E ${image_builder_sh} -o "${file}" "${rootfs}"
|
||||||
|
|
||||||
info "built image file '$file' for rootfs '$rootfs':"
|
info "built image file '$file' for rootfs '$rootfs':"
|
||||||
@ -129,6 +151,9 @@ build_initrd()
|
|||||||
local file="$1"
|
local file="$1"
|
||||||
local rootfs="$2"
|
local rootfs="$2"
|
||||||
|
|
||||||
|
[ -z "$file" ] && die "need file"
|
||||||
|
[ -z "$rootfs" ] && die "need rootfs"
|
||||||
|
|
||||||
sudo -E ${initrd_builder_sh} -o "${file}" "${rootfs}"
|
sudo -E ${initrd_builder_sh} -o "${file}" "${rootfs}"
|
||||||
|
|
||||||
info "built initrd file '$file' for rootfs '$rootfs':"
|
info "built initrd file '$file' for rootfs '$rootfs':"
|
||||||
@ -156,6 +181,9 @@ install_image_create_container()
|
|||||||
{
|
{
|
||||||
local file="$1"
|
local file="$1"
|
||||||
|
|
||||||
|
[ -z "$file" ] && die "need 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
|
||||||
|
|
||||||
@ -168,6 +196,9 @@ install_initrd_create_container()
|
|||||||
{
|
{
|
||||||
local file="$1"
|
local file="$1"
|
||||||
|
|
||||||
|
[ -z "$file" ] && die "need 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
|
||||||
|
|
||||||
@ -182,6 +213,9 @@ handle_options()
|
|||||||
local type="$2"
|
local type="$2"
|
||||||
local options="$3"
|
local options="$3"
|
||||||
|
|
||||||
|
[ -z "$distro" ] && die "need distro"
|
||||||
|
[ -z "$type" ] && die "need type"
|
||||||
|
|
||||||
local opt
|
local opt
|
||||||
local rootfs
|
local rootfs
|
||||||
|
|
||||||
@ -241,7 +275,9 @@ create_and_run()
|
|||||||
local image_options="$2"
|
local image_options="$2"
|
||||||
local initrd_options="$3"
|
local initrd_options="$3"
|
||||||
|
|
||||||
[ -n "$distro" ]
|
[ -z "$distro" ] && die "need distro"
|
||||||
|
[ -z "$image_options" ] && die "need image options"
|
||||||
|
[ -z "$initrd_options" ] && die "need initrd options"
|
||||||
|
|
||||||
local opt
|
local opt
|
||||||
|
|
||||||
@ -256,27 +292,72 @@ create_and_run()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Can create and run fedora image" {
|
run_test()
|
||||||
create_and_run fedora "service" "no"
|
{
|
||||||
|
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"
|
||||||
|
[ -z "$distro" ] && die "need distro"
|
||||||
|
[ -z "$image_options" ] && die "need image options"
|
||||||
|
[ -z "$initrd_options" ] && die "need initrd options"
|
||||||
|
|
||||||
|
[ -n "$skip" ] && info "Skipping test $name: $skip" && return
|
||||||
|
|
||||||
|
info "Running test: ${name}"
|
||||||
|
|
||||||
|
create_and_run "${distro}" "${image_options}" "${initrd_options}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Can create and run clearlinux image" {
|
test_fedora()
|
||||||
create_and_run clearlinux "service" "no"
|
{
|
||||||
|
local -r name="Can create and run fedora image"
|
||||||
|
run_test "${name}" "" "fedora" "service" "no"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Can create and run centos image" {
|
test_clearlinux()
|
||||||
create_and_run centos "service" "no"
|
{
|
||||||
|
local -r name="Can create and run clearlinux image"
|
||||||
|
|
||||||
|
run_test "${name}" "" "clearlinux" "service" "no"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Can create and run euleros image" {
|
test_centos()
|
||||||
if [ "$TRAVIS" = true ]
|
{
|
||||||
then
|
local -r name="Can create and run centos image"
|
||||||
skip "travis timeout, see: https://github.com/kata-containers/osbuilder/issues/46"
|
run_test "${name}" "" "centos" "service" "no"
|
||||||
fi
|
|
||||||
|
|
||||||
create_and_run euleros "service" "no"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Can create and run alpine image" {
|
test_euleros()
|
||||||
create_and_run alpine "no" "init"
|
{
|
||||||
|
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_alpine()
|
||||||
|
{
|
||||||
|
local -r name="Can create and run alpine image"
|
||||||
|
run_test "${name}" "" "alpine" "no" "init"
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
setup
|
||||||
|
|
||||||
|
test_fedora
|
||||||
|
test_clearlinux
|
||||||
|
test_centos
|
||||||
|
test_alpine
|
||||||
|
|
||||||
|
# Run last as EulerOS servers can be slow and we don't want to fail the
|
||||||
|
# previous tests.
|
||||||
|
test_euleros
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
Loading…
Reference in New Issue
Block a user