mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
tests: common: Move a few utility functions to common.bash
Those functions were originally introduced as part of the `metrics/gha-run.sh` file, but those will be very hand at the time we start adding more tests. Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
parent
bb2ef4ca34
commit
3ffd48bc16
@ -254,3 +254,74 @@ function compress_metrics_results_dir()
|
||||
cd "${path_results}" && tar -czf "${tarball_fname}" *.json && cd -
|
||||
info "tarball generated: ${tarball_fname}"
|
||||
}
|
||||
|
||||
function create_symbolic_links() {
|
||||
local KATA_HYPERVISOR="${1}"
|
||||
|
||||
local link_configuration_file="/opt/kata/share/defaults/kata-containers/configuration.toml"
|
||||
local source_configuration_file="/opt/kata/share/defaults/kata-containers/configuration-${KATA_HYPERVISOR}.toml"
|
||||
|
||||
if [ "${KATA_HYPERVISOR}" != 'qemu' ] && [ "${KATA_HYPERVISOR}" != 'clh' ]; then
|
||||
die "Failed to set the configuration.toml: '${KATA_HYPERVISOR}' is not recognized as a valid hypervisor name."
|
||||
fi
|
||||
|
||||
sudo ln -sf "${source_configuration_file}" "${link_configuration_file}"
|
||||
}
|
||||
|
||||
# Configures containerd
|
||||
function overwrite_containerd_config() {
|
||||
containerd_config="/etc/containerd/config.toml"
|
||||
sudo rm "${containerd_config}"
|
||||
sudo tee "${containerd_config}" << EOF
|
||||
version = 2
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
|
||||
SystemdCgroup = true
|
||||
|
||||
[plugins]
|
||||
[plugins."io.containerd.grpc.v1.cri"]
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd]
|
||||
default_runtime_name = "kata"
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.kata]
|
||||
runtime_type = "io.containerd.kata.v2"
|
||||
EOF
|
||||
}
|
||||
|
||||
function install_kata() {
|
||||
local kata_tarball="kata-static.tar.xz"
|
||||
declare -r katadir="/opt/kata"
|
||||
declare -r destdir="/"
|
||||
declare -r local_bin_dir="/usr/local/bin/"
|
||||
|
||||
# Removing previous kata installation
|
||||
sudo rm -rf "${katadir}"
|
||||
|
||||
pushd "${kata_tarball_dir}"
|
||||
sudo tar -xvf "${kata_tarball}" -C "${destdir}"
|
||||
popd
|
||||
|
||||
# create symbolic links to kata components
|
||||
for b in "${katadir}/bin/*" ; do
|
||||
sudo ln -sf "${b}" "${local_bin_dir}/$(basename $b)"
|
||||
done
|
||||
|
||||
check_containerd_config_for_kata
|
||||
restart_containerd_service
|
||||
install_checkmetrics
|
||||
}
|
||||
|
||||
function check_containerd_config_for_kata() {
|
||||
# check containerd config
|
||||
declare -r line1="default_runtime_name = \"kata\""
|
||||
declare -r line2="runtime_type = \"io.containerd.kata.v2\""
|
||||
declare -r num_lines_containerd=2
|
||||
declare -r containerd_path="/etc/containerd/config.toml"
|
||||
local count_matches=$(grep -ic "$line1\|$line2" "${containerd_path}")
|
||||
|
||||
if [ "${count_matches}" = "${num_lines_containerd}" ]; then
|
||||
info "containerd ok"
|
||||
else
|
||||
info "overwriting containerd configuration w/ a valid one"
|
||||
overwrite_containerd_config
|
||||
fi
|
||||
}
|
||||
|
@ -18,59 +18,6 @@ declare -r results_dir="${metrics_dir}/results"
|
||||
declare -r checkmetrics_dir="${metrics_dir}/cmd/checkmetrics"
|
||||
declare -r checkmetrics_config_dir="${checkmetrics_dir}/ci_worker"
|
||||
|
||||
function create_symbolic_links() {
|
||||
local link_configuration_file="/opt/kata/share/defaults/kata-containers/configuration.toml"
|
||||
local source_configuration_file="/opt/kata/share/defaults/kata-containers/configuration-${KATA_HYPERVISOR}.toml"
|
||||
|
||||
if [ "${KATA_HYPERVISOR}" != 'qemu' ] && [ "${KATA_HYPERVISOR}" != 'clh' ]; then
|
||||
die "Failed to set the configuration.toml: '${KATA_HYPERVISOR}' is not recognized as a valid hypervisor name."
|
||||
fi
|
||||
|
||||
sudo ln -sf "${source_configuration_file}" "${link_configuration_file}"
|
||||
}
|
||||
|
||||
# Configures containerd
|
||||
function overwrite_containerd_config() {
|
||||
containerd_config="/etc/containerd/config.toml"
|
||||
sudo rm "${containerd_config}"
|
||||
sudo tee "${containerd_config}" << EOF
|
||||
version = 2
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
|
||||
SystemdCgroup = true
|
||||
|
||||
[plugins]
|
||||
[plugins."io.containerd.grpc.v1.cri"]
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd]
|
||||
default_runtime_name = "kata"
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
|
||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.kata]
|
||||
runtime_type = "io.containerd.kata.v2"
|
||||
EOF
|
||||
}
|
||||
|
||||
function install_kata() {
|
||||
local kata_tarball="kata-static.tar.xz"
|
||||
declare -r katadir="/opt/kata"
|
||||
declare -r destdir="/"
|
||||
declare -r local_bin_dir="/usr/local/bin/"
|
||||
|
||||
# Removing previous kata installation
|
||||
sudo rm -rf "${katadir}"
|
||||
|
||||
pushd "${kata_tarball_dir}"
|
||||
sudo tar -xvf "${kata_tarball}" -C "${destdir}"
|
||||
popd
|
||||
|
||||
# create symbolic links to kata components
|
||||
for b in "${katadir}/bin/*" ; do
|
||||
sudo ln -sf "${b}" "${local_bin_dir}/$(basename $b)"
|
||||
done
|
||||
|
||||
check_containerd_config_for_kata
|
||||
restart_containerd_service
|
||||
install_checkmetrics
|
||||
}
|
||||
|
||||
function install_checkmetrics() {
|
||||
# Ensure we have the latest checkmetrics
|
||||
pushd "${checkmetrics_dir}"
|
||||
@ -79,22 +26,6 @@ function install_checkmetrics() {
|
||||
popd
|
||||
}
|
||||
|
||||
function check_containerd_config_for_kata() {
|
||||
# check containerd config
|
||||
declare -r line1="default_runtime_name = \"kata\""
|
||||
declare -r line2="runtime_type = \"io.containerd.kata.v2\""
|
||||
declare -r num_lines_containerd=2
|
||||
declare -r containerd_path="/etc/containerd/config.toml"
|
||||
local count_matches=$(grep -ic "$line1\|$line2" "${containerd_path}")
|
||||
|
||||
if [ "${count_matches}" = "${num_lines_containerd}" ]; then
|
||||
info "containerd ok"
|
||||
else
|
||||
info "overwriting containerd configuration w/ a valid one"
|
||||
overwrite_containerd_config
|
||||
fi
|
||||
}
|
||||
|
||||
function check_metrics() {
|
||||
local cm_base_file="${checkmetrics_config_dir}/checkmetrics-json-${KATA_HYPERVISOR}-kata-metric8.toml"
|
||||
checkmetrics --debug --percentage --basefile "${cm_base_file}" --metricsdir "${results_dir}"
|
||||
@ -111,21 +42,21 @@ function make_tarball_results() {
|
||||
function run_test_launchtimes() {
|
||||
info "Running Launch Time test using ${KATA_HYPERVISOR} hypervisor"
|
||||
|
||||
create_symbolic_links
|
||||
create_symbolic_links ${KATA_HYPERVISOR}
|
||||
bash tests/metrics/time/launch_times.sh -i public.ecr.aws/ubuntu/ubuntu:latest -n 20
|
||||
}
|
||||
|
||||
function run_test_memory_usage() {
|
||||
info "Running memory-usage test using ${KATA_HYPERVISOR} hypervisor"
|
||||
|
||||
create_symbolic_links
|
||||
create_symbolic_links ${KATA_HYPERVISOR}
|
||||
bash tests/metrics/density/memory_usage.sh 20 5
|
||||
}
|
||||
|
||||
function run_test_memory_usage_inside_container() {
|
||||
info "Running memory-usage inside the container test using ${KATA_HYPERVISOR} hypervisor"
|
||||
|
||||
create_symbolic_links
|
||||
create_symbolic_links ${KATA_HYPERVISOR}
|
||||
bash tests/metrics/density/memory_usage_inside_container.sh 5
|
||||
|
||||
check_metrics
|
||||
@ -136,7 +67,7 @@ function run_test_blogbench() {
|
||||
|
||||
# ToDo: remove the exit once the metrics workflow is stable
|
||||
exit 0
|
||||
create_symbolic_links
|
||||
create_symbolic_links ${KATA_HYPERVISOR}
|
||||
bash tests/metrics/storage/blogbench.sh
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user