Commit fb013939 authored by Kamil Dzieżyk's avatar Kamil Dzieżyk
Browse files

ewaol-tests: Move common test files to separate package



This patch brings the following changes:
 - Replaces 'sed' substitution calls with 'envsubst'.
 - Removes unused variable 'TEST_SUITE_PREFIX'.
 - Reworks '*-integration-tests.bb' recipes:
   * Moves common code to 'runtime-integration-tests.inc'.
   * Moves common runtime test files into a new package
     'runtime-integration-tests-common.bb'.
   * Allows to execute tests 'bats' files from any path.

Issue-Id: SCM-4421
Signed-off-by: Kamil Dzieżyk's avatarKamil Dziezyk <kamil.dziezyk@arm.com>
Change-Id: Ic2a251e7ba41e263ac7c5b0e705e7b910601df6a
parent 9ba49b5c
# Copyright (c) 2021-2022, Arm Limited.
#
# SPDX-License-Identifier: MIT
# This class holds common variables and functions for
# runtime integration tests.
inherit ptest allarch
RDEPENDS:${PN}:append = " bats runtime-integration-tests-common"
DEPENDS:append = " gettext-native"
# ptest aborts if it cannot find libgcc for pthread_cancel
RDEPENDS:${PN}-ptest += "libgcc"
EWAOL_TEST_ACCOUNT ??= "test"
TEST_DIR = "${datadir}/${BPN}"
TEST_SUITE_NAME = "${BPN}"
SRC_URI = "${TEST_FILES} \
file://run-test-suite \
file://run-ptest.in"
ENVSUBST_VARS = "\$TEST_SUITE_NAME \
\$EWAOL_TEST_ACCOUNT \
\$TEST_DIR \
\$EWAOL_GUEST_VM_HOSTNAME"
export TEST_SUITE_NAME
export EWAOL_TEST_ACCOUNT
export TEST_DIR
export EWAOL_GUEST_VM_HOSTNAME
do_install() {
install -d "${D}/${TEST_DIR}"
test_files=`echo ${TEST_FILES} | sed 's/file:\/\///g'`
for test_file in ${test_files}; do
envsubst "${ENVSUBST_VARS}" < "${WORKDIR}/${test_file}" \
> "${D}/${TEST_DIR}/${test_file}"
done
envsubst "${ENVSUBST_VARS}" < "${WORKDIR}/run-test-suite" \
> "${D}/${TEST_DIR}/run-${TEST_SUITE_NAME}"
chmod +x "${D}/${TEST_DIR}/run-${TEST_SUITE_NAME}"
envsubst "${ENVSUBST_VARS}" < "${WORKDIR}/run-ptest.in" \
> "${WORKDIR}/run-ptest"
additional_tests="$(find "${WORKDIR}" -maxdepth 1 \
-name *additional-*-tests.bats -printf "%f ")"
for test in ${additional_tests}; do
# Append the additional tests to the deployed test suite
# Skip the first 2 lines to omit the shebang
tail -n +3 "${D}/${TEST_DIR}/${test}" \
>> "${D}/${TEST_DIR}/${TEST_SUITE_NAME}.bats"
rm -fv "${D}/${TEST_DIR}/${test}"
done
}
......@@ -13,40 +13,13 @@ LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda
OVERRIDES:append = "${EWAOL_OVERRIDES}"
TEST_SUITE_NAME = "container-engine-integration-tests"
TEST_SUITE_PREFIX = "CE"
TEST_FILES = "file://container-engine-integration-tests.bats \
file://container-engine-funcs.sh \
file://integration-tests-common-funcs.sh"
file://container-engine-funcs.sh"
TEST_FILES:append:ewaol-virtualization = " \
file://integration-tests-common-virtual-funcs.sh \
file://login-console-funcs.expect \
file://run-command.expect \
file://container-engine-additional-virtual-tests.bats \
file://container-engine-virtualization-funcs.sh \
"
SRC_URI = "${TEST_FILES} \
file://run-test-suite \
file://run-ptest"
RDEPENDS:${PN}:ewaol-virtualization += "expect"
inherit runtime-integration-tests
require runtime-integration-tests.inc
do_install:append:ewaol-virtualization() {
# Append the virtualization tests to the deployed test suite
# Skip the first 2 lines to omit the shebang
tail -n +3 \
"${D}/${TEST_DIR}/container-engine-additional-virtual-tests.bats" \
>> "${D}/${TEST_DIR}/container-engine-integration-tests.bats"
sed -i "s#%GUESTNAME%#${EWAOL_GUEST_VM_HOSTNAME}#g" \
"${D}/${TEST_DIR}/container-engine-virtualization-funcs.sh"
rm "${D}/${TEST_DIR}/container-engine-additional-virtual-tests.bats"
}
......@@ -7,8 +7,8 @@
# Additional tests to be added to the container engine test suite, if running on
# a virtualization image
load integration-tests-common-virtual-funcs.sh
load container-engine-virtualization-funcs.sh
load "${TEST_COMMON_DIR}/integration-tests-common-virtual-funcs.sh"
load "${TEST_DIR}/container-engine-virtualization-funcs.sh"
@test 'run container engine integration tests on the Guest VM from the Control VM' {
......
......@@ -28,8 +28,8 @@ fi
export TEST_CLEAN_ENV="${CE_TEST_CLEAN_ENV:=1}"
load integration-tests-common-funcs.sh
load container-engine-funcs.sh
load "${TEST_COMMON_DIR}/integration-tests-common-funcs.sh"
load "${TEST_DIR}/container-engine-funcs.sh"
# Ensure that the state of the container environment is ready for the test
# suite
......
......@@ -5,11 +5,11 @@
# SPDX-License-Identifier: MIT
if [ -z "${CE_TEST_GUEST_VM_NAME}" ]; then
CE_TEST_GUEST_VM_NAME="%GUESTNAME%1"
CE_TEST_GUEST_VM_NAME="${EWAOL_GUEST_VM_HOSTNAME}1"
fi
run_tests_on_guest_vm() {
expect run-command.expect \
expect "${TEST_COMMON_DIR}/run-command.expect" \
-hostname "${CE_TEST_GUEST_VM_NAME}" \
-command "ptest-runner container-engine-integration-tests" \
-timeout "120" \
......
......@@ -127,7 +127,7 @@ if {"${logon_func}" == "guest_vm_logon"} {
puts "Setting timeout to '${timeout}' seconds."
source "login-console-funcs.expect"
source "${TEST_COMMON_DIR}/login-console-funcs.expect"
# Default timeout handler logs that a time out occured, but allows the script
# to continue. This may be overriden by adding a timeout handler to a particular
......
......@@ -4,4 +4,4 @@
#
# SPDX-License-Identifier: MIT
cd TESTDIR && ./run-TESTNAME
"${TEST_DIR}/run-${TEST_SUITE_NAME}"
......@@ -4,12 +4,10 @@
#
# SPDX-License-Identifier: MIT
SCRIPT_DIR=$(dirname "$(readlink -f "${0}")")
if sudo -HEnu "TESTUSER" bats "${SCRIPT_DIR}/TESTNAME.bats"; then
echo "PASS:TESTNAME"
if sudo -HEnu "${EWAOL_TEST_ACCOUNT}" bats "${TEST_DIR}/${TEST_SUITE_NAME}.bats"; then
echo "PASS:${TEST_SUITE_NAME}"
exit 0
else
echo "FAIL:TESTNAME"
echo "FAIL:${TEST_SUITE_NAME}"
exit 1
fi
......@@ -13,48 +13,32 @@ LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda
OVERRIDES:append = "${EWAOL_OVERRIDES}"
TEST_SUITE_NAME = "k3s-integration-tests"
TEST_SUITE_PREFIX = "K3S"
TEST_FILES = "file://k3s-integration-tests.bats \
file://k3s-funcs.sh \
file://k3s-test-deployment.yaml \
file://integration-tests-common-funcs.sh"
file://k3s-test-deployment.yaml"
TEST_FILES:append:ewaol-virtualization = " \
file://integration-tests-common-virtual-funcs.sh \
file://login-console-funcs.expect \
file://run-command.expect \
file://k3s-virtualization-funcs.sh \
"
SRC_URI = "${TEST_FILES} \
file://run-test-suite \
file://run-ptest"
inherit runtime-integration-tests
require runtime-integration-tests.inc
RDEPENDS:${PN}:ewaol-virtualization += "expect"
K3S_TEST_DESC = "local deployment of K3s pods"
K3S_TEST_DESC:ewaol-virtualization = "remote deployment of K3s pods on the Guest VM, from the Control VM"
do_install:append() {
# Append a more informative architecture-specific description of the K3s
# test scenario
sed -i "s#%K3S_TEST_DESC%#${K3S_TEST_DESC}#g" \
"${D}/${TEST_DIR}/k3s-integration-tests.bats"
}
K3S_LOAD_VIRT_FUNCS = ""
K3S_LOAD_VIRT_FUNCS:ewaol-virtualization = 'load \"${TEST_DIR}/k3s-virtualization-funcs.sh\"${@"\n"}'
do_install:append:ewaol-virtualization() {
export K3S_TEST_DESC
ENVSUBST_VARS:append = " \$K3S_TEST_DESC \$K3S_LOAD_VIRT_FUNCS"
# Load virtualization-specific overrides to the K3s functions
sed -i "s#load k3s-funcs.sh#load k3s-funcs.sh\nload k3s-virtualization-funcs.sh#g" \
"${D}/${TEST_DIR}/k3s-integration-tests.bats"
do_install:prepend() {
# export variable here to keep multiline string
export K3S_LOAD_VIRT_FUNCS="${K3S_LOAD_VIRT_FUNCS}"
}
# Set the hostname of the Guest VM that should run the workload
sed -i "s#%GUESTNAME%#${EWAOL_GUEST_VM_HOSTNAME}#g" \
"${D}/${TEST_DIR}/k3s-virtualization-funcs.sh"
do_install:append:ewaol-virtualization() {
# Add a condition to the deployment to make it only schedulable on the Guest
# VM
......@@ -62,5 +46,4 @@ do_install:append:ewaol-virtualization() {
nodeSelector:
ewaol.node-type: guest-vm
EOF
}
......@@ -24,9 +24,9 @@ export TEST_RUN_FILE="${TEST_RUNTIME_DIR}/k3s-integration-tests.pgid"
export TEST_CLEAN_ENV="${K3S_TEST_CLEAN_ENV:=1}"
load integration-tests-common-funcs.sh
load k3s-funcs.sh
load "${TEST_COMMON_DIR}/integration-tests-common-funcs.sh"
load "${TEST_DIR}/k3s-funcs.sh"
${K3S_LOAD_VIRT_FUNCS}
# Ensure that the state of the orchestration service is reset to its
# out-of-the-box state, not polluted by a previous test suite execution
clean_test_environment() {
......@@ -86,10 +86,11 @@ teardown_file() {
_run test_suite_teardown clean_test_environment
}
@test 'K3s orchestration of containerized web service (%K3S_TEST_DESC%)' {
# shellcheck disable=SC2016
@test 'K3s orchestration of containerized web service ${K3S_TEST_DESC}' {
subtest="Deploy workload"
_run apply_workload "k3s-test-deployment.yaml"
_run apply_workload "${TEST_DIR}/k3s-test-deployment.yaml"
if [ "${status}" -ne 0 ]; then
log "FAIL" "${subtest}"
return 1
......
......@@ -4,10 +4,10 @@
#
# SPDX-License-Identifier: MIT
load integration-tests-common-virtual-funcs.sh
load "${TEST_COMMON_DIR}/integration-tests-common-virtual-funcs.sh"
if [ -z "${K3S_TEST_GUEST_VM_NAME}" ]; then
K3S_TEST_GUEST_VM_NAME="%GUESTNAME%1"
K3S_TEST_GUEST_VM_NAME="${EWAOL_GUEST_VM_HOSTNAME}1"
fi
K3S_AGENT_OVERRIDE_FILENAME="/lib/systemd/system/k3s-agent.service.d/01-test-connect.conf"
......@@ -62,14 +62,14 @@ get_target_node_ip() {
cleanup_k3s_agent_on_guest_vm() {
# Stop the agent
expect run-command.expect \
expect "${TEST_COMMON_DIR}/run-command.expect" \
-hostname "${K3S_TEST_GUEST_VM_NAME}" \
-command "sudo -n systemctl stop k3s-agent" \
-console "guest_vm" \
2>"${TEST_STDERR_FILE}"
# Remove the systemd override if it exists
expect run-command.expect \
expect "${TEST_COMMON_DIR}/run-command.expect" \
-hostname "${K3S_TEST_GUEST_VM_NAME}" \
-command "sudo -n rm -f ${K3S_AGENT_OVERRIDE_FILENAME} && \
sudo -n systemctl daemon-reload" \
......@@ -103,7 +103,7 @@ ExecStart=/usr/local/bin/k3s agent --server=https://${ip}:6443 --token=${token}
| sudo -n tee ${K3S_AGENT_OVERRIDE_FILENAME} > /dev/null \
&& sudo -n systemctl daemon-reload"
expect run-command.expect \
expect "${TEST_COMMON_DIR}/run-command.expect" \
-hostname "${K3S_TEST_GUEST_VM_NAME}" \
-command "${cmd}" \
-console "guest_vm" \
......@@ -113,7 +113,7 @@ ExecStart=/usr/local/bin/k3s agent --server=https://${ip}:6443 --token=${token}
start_k3s_agent_on_guest_vm() {
expect run-command.expect \
expect "${TEST_COMMON_DIR}/run-command.expect" \
-hostname "${K3S_TEST_GUEST_VM_NAME}" \
-command "sudo -n systemctl start k3s-agent" \
-console "guest_vm" \
......@@ -156,7 +156,7 @@ extra_cleanup() {
extra_setup() {
# Check if the agent is already running
_run expect run-command.expect \
_run expect "${TEST_COMMON_DIR}/run-command.expect" \
-hostname "${K3S_TEST_GUEST_VM_NAME}" \
-command "systemctl is-active k3s-agent" \
-console "guest_vm" \
......
......@@ -3,7 +3,7 @@
# SPDX-License-Identifier: MIT
SUMMARY = "Creates an 'EWAOL_TEST_ACCOUNT' account used for running EWAOL \
runtime integration tests"
runtime integration tests and installs common include files."
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
......@@ -16,6 +16,7 @@ EWAOL_ADMIN_GROUP ??= "sudo"
EWAOL_TEST_GROUPS = "${EWAOL_ADMIN_GROUP}"
inherit allarch useradd
require runtime-integration-tests.inc
USERADD_PACKAGES = "${PN}"
USERADD_PARAM:${PN} = "--create-home \
......@@ -23,11 +24,33 @@ USERADD_PARAM:${PN} = "--create-home \
--groups ${EWAOL_TEST_GROUPS} \
--user-group ${EWAOL_TEST_ACCOUNT};"
ALLOW_EMPTY:${PN} = "1"
OVERRIDES:append = "${EWAOL_OVERRIDES}"
RDEPENDS:${PN}:append:ewaol-virtualization = " expect"
RDEPENDS:${PN}:append:ewaol-security = " expect"
DEPENDS:append = " gettext-native"
SRC_URI = "file://integration-tests-common-funcs.sh \
file://integration-tests-common-virtual-funcs.sh \
file://login-console-funcs.expect \
file://run-command.expect"
do_fetch[noexec] = "1"
do_unpack[noexec] = "1"
do_patch[noexec] = "1"
do_configure[noexec] = "1"
do_compile[noexec] = "1"
do_install[noexec] = "1"
do_install() {
install -d "${D}/${TEST_COMMON_DIR}"
install --mode="644" "${WORKDIR}/integration-tests-common-funcs.sh" \
"${D}/${TEST_COMMON_DIR}"
install --mode="644" "${WORKDIR}/integration-tests-common-virtual-funcs.sh" \
"${D}/${TEST_COMMON_DIR}"
install --mode="644" "${WORKDIR}/login-console-funcs.expect" \
"${D}/${TEST_COMMON_DIR}"
envsubst '$TEST_COMMON_DIR' < "${WORKDIR}/run-command.expect" \
> "${D}/${TEST_COMMON_DIR}/run-command.expect"
}
FILES:${PN} += "${TEST_COMMON_DIR}"
# Copyright (c) 2021-2022, Arm Limited.
# Copyright (c) 2022, Arm Limited.
#
# SPDX-License-Identifier: MIT
inherit ptest
RDEPENDS:${PN}:append = " bats runtime-integration-tests-common"
# ptest aborts if it cannot find libgcc for pthread_cancel
RDEPENDS:${PN}-ptest += "libgcc"
EWAOL_TEST_ACCOUNT ??= "test"
TEST_DIR ?= "${datadir}/${BPN}"
do_install() {
install -d "${D}/${TEST_DIR}"
test_files=`echo ${TEST_FILES} | sed 's/file:\/\///g'`
for test_file in ${test_files}; do
install "${WORKDIR}/${test_file}" "${D}/${TEST_DIR}"
done
install -m 755 "${WORKDIR}/run-test-suite" \
"${D}/${TEST_DIR}/run-${TEST_SUITE_NAME}"
sed -i "s#TESTNAME#${TEST_SUITE_NAME}#g" \
"${D}/${TEST_DIR}/run-${TEST_SUITE_NAME}"
sed -i "s#TESTUSER#${EWAOL_TEST_ACCOUNT}#g" \
"${D}/${TEST_DIR}/run-${TEST_SUITE_NAME}"
}
do_install_ptest() {
# Point the deployed run-ptest script to the test suite install directory
# Use '#' as delimiter for sed as we are replacing with a path
sed -i "s#TESTDIR#${TEST_DIR}#g" ${D}${PTEST_PATH}/run-ptest
sed -i "s#TESTNAME#${TEST_SUITE_NAME}#g" ${D}${PTEST_PATH}/run-ptest
sed -i "s#TESTPREFIX#${TEST_SUITE_PREFIX}#g" ${D}${PTEST_PATH}/run-ptest
}
export TEST_COMMON_DIR = "${datadir}/runtime-integration-tests-common"
ENVSUBST_VARS:append = " \$TEST_COMMON_DIR"
......@@ -13,62 +13,22 @@ LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda
OVERRIDES:append = "${EWAOL_OVERRIDES}"
TEST_SUITE_NAME = "user-accounts-integration-tests"
TEST_SUITE_PREFIX = "USR_ACC"
TEST_FILES = "file://user-accounts-integration-tests.bats \
file://user-accounts-funcs.sh \
file://integration-tests-common-funcs.sh \
"
TEST_FILES:append:ewaol-virtualization = " \
file://user-accounts-additional-virtualization-tests.bats \
file://user-accounts-virtualization-funcs.sh \
file://integration-tests-common-virtual-funcs.sh \
file://run-command.expect \
file://login-console-funcs.expect \
"
TEST_FILES:append:ewaol-security = " \
file://user-accounts-additional-security-tests.bats \
file://user-accounts-security-funcs.sh \
file://run-command.expect \
file://login-console-funcs.expect \
"
SRC_URI = "${TEST_FILES} \
file://run-test-suite \
file://run-ptest"
inherit runtime-integration-tests
require runtime-integration-tests.inc
RDEPENDS:${PN}:ewaol-virtualization += "expect"
RDEPENDS:${PN}:ewaol-security += "expect"
do_install:append:ewaol-security() {
# Append the security tests to the deployed test suite
# Skip the first 2 lines to omit the shebang
tail -n +3 \
"${D}/${TEST_DIR}/user-accounts-additional-security-tests.bats" \
>> "${D}/${TEST_DIR}/user-accounts-integration-tests.bats"
sed -i "s#%EWAOL_SECURITY_UMASK%#${EWAOL_SECURITY_UMASK}#g" \
"${D}/${TEST_DIR}/user-accounts-security-funcs.sh"
rm "${D}/${TEST_DIR}/user-accounts-additional-security-tests.bats"
}
do_install:append:ewaol-virtualization() {
# Append the virtualization tests to the deployed test suite
# Skip the first 2 lines to omit the shebang
tail -n +3 \
"${D}/${TEST_DIR}/user-accounts-additional-virtualization-tests.bats" \
>> "${D}/${TEST_DIR}/user-accounts-integration-tests.bats"
sed -i "s#%GUESTNAME%#${EWAOL_GUEST_VM_HOSTNAME}#g" \
"${D}/${TEST_DIR}/user-accounts-virtualization-funcs.sh"
rm "${D}/${TEST_DIR}/user-accounts-additional-virtualization-tests.bats"
}
export EWAOL_SECURITY_UMASK
ENVSUBST_VARS:append:ewaol-security = " \$EWAOL_SECURITY_UMASK"
......@@ -9,7 +9,7 @@
export ROOT_USER="root"
load user-accounts-security-funcs.sh
load "${TEST_DIR}/user-accounts-security-funcs.sh"
@test 'user accounts management additional security tests' {
......
......@@ -7,8 +7,8 @@
# Additional tests to be added to the user accounts test suite, if running on
# a virtualization image
load integration-tests-common-virtual-funcs.sh
load user-accounts-virtualization-funcs.sh
load "${TEST_COMMON_DIR}/integration-tests-common-virtual-funcs.sh"
load "${TEST_DIR}/user-accounts-virtualization-funcs.sh"
@test 'run user accounts integration tests on the Guest VM from the Control VM' {
......
......@@ -26,8 +26,8 @@ export NORMAL_USER="user"
export TEST_CLEAN_ENV="${UA_TEST_CLEAN_ENV:=1}"
load integration-tests-common-funcs.sh
load user-accounts-funcs.sh
load "${TEST_COMMON_DIR}/integration-tests-common-funcs.sh"
load "${TEST_DIR}/user-accounts-funcs.sh"
# Runs once before the first test
setup_file() {
......
......@@ -33,7 +33,7 @@ teardown_file() {
# run ${1} command as ${2} user
check_user_local_access() {
expect run-command.expect \
expect "${TEST_COMMON_DIR}/run-command.expect" \
-user "${1}" \
-command "echo OK" \
-console "local" \
......@@ -42,7 +42,7 @@ check_user_local_access() {
# run ${1} command as ${2} user at ${3} remote via ssh
check_user_remote_access() {
expect run-command.expect \
expect "${TEST_COMMON_DIR}/run-command.expect" \
-hostname "${2}" \
-user "${1}" \
-command "echo OK" \
......@@ -50,15 +50,15 @@ check_user_remote_access() {
2>"${TEST_STDERR_FILE}"
}
EWAOL_SECURITY_UMASK="%EWAOL_SECURITY_UMASK%"
EWAOL_UMASK="${EWAOL_SECURITY_UMASK}"
check_umask() {
umask_val="$(umask 2>"${TEST_STDERR_FILE}")"
if [ "${umask_val}" = "${EWAOL_SECURITY_UMASK}" ]; then
if [ "${umask_val}" = "${EWAOL_UMASK}" ]; then
return 0
else
echo "Wrong umask setting! current: '${umask_val}'," \
"expected: '${EWAOL_SECURITY_UMASK}'."
"expected: '${EWAOL_UMASK}'."
return 1
fi
}
......@@ -5,11 +5,11 @@
# SPDX-License-Identifier: MIT
if [ -z "${UA_TEST_GUEST_VM_NAME}" ]; then
UA_TEST_GUEST_VM_NAME="%GUESTNAME%1"
UA_TEST_GUEST_VM_NAME="${EWAOL_GUEST_VM_HOSTNAME}1"
fi