From 68f17024fbb14aeafe7c2932fdd26e84917ed871 Mon Sep 17 00:00:00 2001 From: Enrico Usai Date: Mon, 26 Jun 2023 10:23:30 +0200 Subject: [PATCH] Add test-os.sh utility to simplify run of kitchen tests for an OS The script is able to search for all the test suites defined into the functional cookbook and run them sequentially. It must be executed from the root folder of the cookbook repo: bash util/test-os.sh ec2 rhel8 The output will be saved into a `/tmp/kitchen--` folder. To run config tests is required to set a KITCHEN_${os}_AMI environment variable (e.g. KITCHEN_RHEL8_AMI) or have a ParallelCluster AMI in the account. Signed-off-by: Enrico Usai --- util/test-os.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 util/test-os.sh diff --git a/util/test-os.sh b/util/test-os.sh new file mode 100644 index 000000000..45fdbaaad --- /dev/null +++ b/util/test-os.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# This script simplifies run of kitchen tests for a given OS. +# It must be executed from the root folder of the cookbook repo: +# bash util/test-os.sh ec2 rhel8 +# +# It searches for all the test suites defined in the functional cookbook and runs them sequentially. +# The output will be saved into a `/tmp/kitchen--` folder. +# To run config tests is required to set a KITCHEN_${os}_AMI environment variable (e.g. KITCHEN_RHEL8_AMI) +# or have a ParallelCluster AMI in the account. + +[ -z "$1" ] && echo "Missing driver parameter, should be ec2 or docker" && exit 1 +[ -z "$2" ] && echo "Missing OS parameter" && exit 1 +driver=$1 +os=$2 + +this_dir=$( cd -- "$(dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) +date=$(date +"%Y%m%dT%H%M") +test_output="/tmp/kitchen-${os}-${date}" +mkdir -p "${test_output}" + +for dir in "${this_dir}/../cookbooks/aws-parallelcluster-"*/; do + config_files=$(ls "${dir}"*.yml) + if [[ -n ${config_files} ]]; then + for config_file in ${config_files}; do + filename=$(basename "${config_file}") + cookbook=$(basename "$(dirname ${config_file})") + kitchen_config=$(echo "${filename}" | sed "s/kitchen\.\(.*\)\.yml/\1/") + echo "*** Executing tests in the ${kitchen_config} file" + + ami_env_var=$(echo "KITCHEN_${os}_AMI" | tr '[:lower:]' '[:upper:]') + if [[ "${kitchen_config}" == *"-config" ]] && [[ -z ${!ami_env_var} ]]; then + echo "Environment variable ${ami_env_var} not set, skipping ${kitchen_config} test. Look at image_search on kitchen.ec2.yml for more details." + continue + fi + + suites=$(yq e '.suites[].name' "${this_dir}/../cookbooks/${cookbook}/kitchen.${kitchen_config}.yml") + for suite in ${suites}; do + test="${suite//_/-}-${os}" + echo "* Executing ${test}" + bash "${this_dir}/../kitchen.${driver}.sh" "${kitchen_config}" test "${test}" | tee "${test_output}/kitchen-test-${driver}-${kitchen_config}-${test}.txt" + done + done + fi +done