1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00
Files
installer/hack/openstack/test-manifests.sh
2023-03-12 17:39:56 +01:00

137 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -Eeuo pipefail
[[ $(type -P yq) ]] || { >&2 echo "Required tool 'yq' not found in PATH" ; exit 1; }
declare \
tests_dir='./scripts/openstack/manifest-tests' \
openshift_install='./bin/openshift-install' \
api_fip='' \
os_cloud='' \
external_network='' \
compute_flavor='' \
persist='NO' \
run='.*' \
test_counter=0
# Let install-config describe a configuration that is incompatible with the
# target CI infrastructure
export OPENSHIFT_INSTALL_SKIP_PREFLIGHT_VALIDATIONS=1
print_help() {
set +x
echo -e "Test the OpenStack manifest generation."
echo
echo -e "Required configuration:"
echo
echo -e "\\t-c\\tOS_CLOUD"
echo -e "\\t-e\\tExternal network"
echo -e "\\t-f\\tA valid flavor"
echo
echo -e "Use:"
echo -e "\\t${0} -c <cloud> -e <external network> -f <flavor> [-a <fip>] [-i <openshift-install>] [-t <test-dir>] [-p]"
echo
echo -e 'Additional arguments:'
echo -e "\\t-a\\t\\tapiFloatingIP"
echo -e "\\t-i\\t\\tpath to openshift-install (defaults to '${openshift_install}')"
echo -e "\\t-t\\t\\tpath to the tests to be run (defaults to '${tests_dir}')"
echo -e "\\t-p\\t\\tpersist artifacts: do not delete files generated by openshift-install"
echo -e "\\t-r <regexp>\\trun: only run test cases that match the given regular expression"
}
fill_install_config() {
declare -r \
template="$1" \
pull_secret="'"'{"auths":{"registry.svc.ci.openshift.org":{"auth":"QW4gYWN0dWFsIHB1bGwgc2VjcmV0IGlzIG5vdCBuZWNlc3NhcnkK"}}}'"'"
sed '
s|${\?OS_CLOUD}\?|'"${os_cloud}"'|;
s|${\?EXTERNAL_NETWORK}\?|'"${external_network}"'|;
s|${\?COMPUTE_FLAVOR}\?|'"${compute_flavor}"'|;
s|${\?API_FIP}\?|'"${api_fip}"'|;
s|${\?PULL_SECRET}\?|'"${pull_secret}"'|;
' "$template"
}
validate_configuration() {
declare -a required_values=("os_cloud" "external_network" "compute_flavor")
declare fail=false
for val in "${required_values[@]}"; do
declare required=${!val:-}
if [ -z "${required}" ]; then
>&2 echo "Missing required argument '${val}'."
fail=true
fi
done
if [ "$fail" = true ]; then
print_help
exit 1
fi
}
while getopts a:c:e:f:i:t:pr:h o; do
case "$o" in
a) api_fip="$OPTARG" ;;
c) os_cloud="$OPTARG" ;;
e) external_network="$OPTARG" ;;
f) compute_flavor="$OPTARG" ;;
i) openshift_install="$OPTARG" ;;
t) tests_dir="$OPTARG" ;;
p) persist='YES' ;;
r) run="$OPTARG" ;;
h) print_help; exit 0 ;;
*) print_help; exit 1 ;;
esac
done
readonly api_fip os_cloud external_network compute_flavor openshift_install tests_dir persist run
declare -a temp_dirs
cleanup() {
if [[ "$persist" == 'NO' ]]; then
for temp_dir in "${temp_dirs[@]}"; do
rm -rf "$temp_dir"
done
fi
}
trap cleanup EXIT
validate_configuration
>&2 echo "Running the tests from '${tests_dir}' against the Installer binary '${openshift_install}'."
declare result='PASS'
for testcase in "${tests_dir}"/* ; do
if [ -d "$testcase" ] && [[ "$testcase" =~ $run ]]; then
echo
echo "*** TEST CASE: $(basename -- "$testcase")"
assets_dir="$(mktemp -d)"
if [[ "$persist" != 'NO' ]]; then
echo "Generated assets for this test can be found in ${assets_dir}"
fi
((test_counter+=1))
temp_dirs+=("$assets_dir")
fill_install_config "${testcase}/install-config.yaml" > "${assets_dir}/install-config.yaml"
"$openshift_install" --log-level warn create manifests --dir "$assets_dir"
for t in "${testcase}"/test_*; do
if $t "$assets_dir"; then
echo "PASS: '$t'"
else
result='FAIL'
echo "FAIL: '$t'"
fi
done
fi
done
echo "Ran ${test_counter} test cases."
if [ "$result" != 'PASS' ]; then
echo "FAIL"
exit 1
fi
echo 'PASS'