Merge pull request #525 from sclorg/use_internal_openshift_registry
Use internal openshift registry
This commit is contained in:
parent
aa1ec203ed
commit
3e1d82ec39
12 changed files with 471 additions and 242 deletions
175
test/test-lib.sh
175
test/test-lib.sh
|
|
@ -16,6 +16,11 @@
|
|||
|
||||
# may be redefined in the specific container testfile
|
||||
EXPECTED_EXIT_CODE=0
|
||||
export TESTSUITE_RESULT=0
|
||||
|
||||
# define UNSTABLE_TESTS if not already defined, as this variable
|
||||
# is not mandatory for containers
|
||||
UNSTABLE_TESTS="${UNSTABLE_TESTS:-""}"
|
||||
|
||||
# ct_cleanup
|
||||
# --------------------
|
||||
|
|
@ -24,6 +29,7 @@ EXPECTED_EXIT_CODE=0
|
|||
# unexpectedly. Removes the cid_files and CID_FILE_DIR as well.
|
||||
# Uses: $CID_FILE_DIR - path to directory containing cid_files
|
||||
# Uses: $EXPECTED_EXIT_CODE - expected container exit code
|
||||
# Uses: $TESTSUITE_RESULT - overall result of all tests
|
||||
function ct_cleanup() {
|
||||
ct_show_resources
|
||||
for cid_file in "$CID_FILE_DIR"/* ; do
|
||||
|
|
@ -33,16 +39,47 @@ function ct_cleanup() {
|
|||
|
||||
: "Stopping and removing container $container..."
|
||||
docker stop "$container"
|
||||
exit_status=$(docker inspect -f '{{.State.ExitCode}}' "$container")
|
||||
if [ "$exit_status" != "$EXPECTED_EXIT_CODE" ]; then
|
||||
: "Dumping logs for $container"
|
||||
docker logs "$container"
|
||||
|
||||
# Container has not been removed by `docker stop` and still exists
|
||||
if [ "$( docker ps -a -f "id=$container" | wc -l )" -eq 2 ]; then
|
||||
exit_status=$(docker inspect -f '{{.State.ExitCode}}' "$container")
|
||||
if [ "$exit_status" != "$EXPECTED_EXIT_CODE" ]; then
|
||||
: "Dumping logs for $container"
|
||||
docker logs "$container"
|
||||
fi
|
||||
docker rm -v "$container"
|
||||
fi
|
||||
docker rm -v "$container"
|
||||
|
||||
rm "$cid_file"
|
||||
done
|
||||
rmdir "$CID_FILE_DIR"
|
||||
: "Done."
|
||||
|
||||
ct_show_results
|
||||
exit "${TESTSUITE_RESULT:-0}"
|
||||
}
|
||||
|
||||
# ct_show_results
|
||||
# ---------------
|
||||
# Prints results of all test cases that are stored into TEST_SUMMARY variable.
|
||||
# Uses: $TEST_SUMMARY - text info about test-cases
|
||||
# Uses: $TESTSUITE_RESULT - overall result of all tests
|
||||
function ct_show_results() {
|
||||
echo
|
||||
echo "==============================================="
|
||||
echo "Test cases results:"
|
||||
echo
|
||||
echo "${TEST_SUMMARY:-}"
|
||||
|
||||
if [ -n "${TESTSUITE_RESULT:-}" ] ; then
|
||||
if [ "$TESTSUITE_RESULT" -eq 0 ] ; then
|
||||
# shellcheck disable=SC2153
|
||||
echo "Tests for ${IMAGE_NAME} succeeded."
|
||||
else
|
||||
# shellcheck disable=SC2153
|
||||
echo "Tests for ${IMAGE_NAME} failed."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# ct_enable_cleanup
|
||||
|
|
@ -125,6 +162,7 @@ function ct_check_envs_set {
|
|||
for value in $stripped; do
|
||||
# If the falue checked does not go through env_filter we do not care about it
|
||||
echo "$value" | grep -q "$env_filter" || continue
|
||||
# shellcheck disable=SC2295
|
||||
if [ -n "${filtered_envs##${env_format//VALUE/$value}}" ]; then
|
||||
echo " Value $value is missing from variable $var_name"
|
||||
echo "$filtered_envs"
|
||||
|
|
@ -284,7 +322,7 @@ function ct_doc_content_old() {
|
|||
docker run --rm "${IMAGE_NAME}" /bin/bash -c "cat /${f}" >"${tmpdir}/$(basename "${f}")"
|
||||
# Check whether the files contain some important information
|
||||
for term in "$@" ; do
|
||||
if ! grep -F -q -e "${term}" "${tmpdir}/$(basename "${f}")" ; then
|
||||
if ! grep -E -q -e "${term}" "${tmpdir}/$(basename "${f}")" ; then
|
||||
echo "ERROR: File /${f} does not include '${term}'." >&2
|
||||
return 1
|
||||
fi
|
||||
|
|
@ -489,21 +527,6 @@ ct_path_foreach ()
|
|||
}
|
||||
|
||||
|
||||
# ct_run_test_list
|
||||
# --------------------
|
||||
# Execute the tests specified by TEST_LIST
|
||||
# Uses: $TEST_LIST - list of test names
|
||||
function ct_run_test_list() {
|
||||
for test_case in $TEST_LIST; do
|
||||
: "Running test $test_case"
|
||||
# shellcheck source=/dev/null
|
||||
[ -f "test/$test_case" ] && source "test/$test_case"
|
||||
# shellcheck source=/dev/null
|
||||
[ -f "../test/$test_case" ] && source "../test/$test_case"
|
||||
$test_case
|
||||
done;
|
||||
}
|
||||
|
||||
# ct_gen_self_signed_cert_pem
|
||||
# ---------------------------
|
||||
# Generates a self-signed PEM certificate pair into specified directory.
|
||||
|
|
@ -631,10 +654,14 @@ ct_get_public_image_name() {
|
|||
public_image_name=$registry/rhscl/$base_image_name-${version//./}-rhel7
|
||||
elif [ "$os" == "rhel8" ]; then
|
||||
public_image_name=$registry/rhel8/$base_image_name-${version//./}
|
||||
elif [ "$os" == "rhel9" ]; then
|
||||
public_image_name=$registry/rhel9/$base_image_name-${version//./}
|
||||
elif [ "$os" == "centos7" ]; then
|
||||
public_image_name=$registry/centos7/$base_image_name-${version//./}-centos7
|
||||
elif [ "$os" == "centos8" ]; then
|
||||
public_image_name=$registry/centos8/$base_image_name-${version//./}-centos8
|
||||
elif [ "$os" == "c8s" ]; then
|
||||
public_image_name=$registry/sclorg/$base_image_name-${version//./}-c8s
|
||||
elif [ "$os" == "c9s" ]; then
|
||||
public_image_name=$registry/sclorg/$base_image_name-${version//./}-c9s
|
||||
fi
|
||||
|
||||
echo "$public_image_name"
|
||||
|
|
@ -646,6 +673,7 @@ ct_get_public_image_name() {
|
|||
# Argument: CMD - Command to be run
|
||||
function ct_assert_cmd_success() {
|
||||
echo "Checking '$*' for success ..."
|
||||
# shellcheck disable=SC2294
|
||||
if ! eval "$@" &>/dev/null; then
|
||||
echo " FAIL"
|
||||
return 1
|
||||
|
|
@ -660,6 +688,7 @@ function ct_assert_cmd_success() {
|
|||
# Argument: CMD - Command to be run
|
||||
function ct_assert_cmd_failure() {
|
||||
echo "Checking '$*' for failure ..."
|
||||
# shellcheck disable=SC2294
|
||||
if eval "$@" &>/dev/null; then
|
||||
echo " FAIL"
|
||||
return 1
|
||||
|
|
@ -935,6 +964,7 @@ ct_check_latest_imagestreams() {
|
|||
# Prints the available resources
|
||||
ct_show_resources()
|
||||
{
|
||||
echo
|
||||
echo "Resources info:"
|
||||
echo "Memory:"
|
||||
free -h
|
||||
|
|
@ -1059,6 +1089,8 @@ ct_test_app_dockerfile() {
|
|||
ct_test_response "http://$ip:${port}" 200 "${expected_text}"
|
||||
ret=$?
|
||||
|
||||
[[ $ret -eq 0 ]] || docker logs "$(ct_get_cid "${cname}")"
|
||||
|
||||
# cleanup
|
||||
docker kill "$(ct_get_cid "${cname}")"
|
||||
sleep 2
|
||||
|
|
@ -1069,4 +1101,101 @@ ct_test_app_dockerfile() {
|
|||
return $ret
|
||||
}
|
||||
|
||||
# ct_check_testcase_result
|
||||
# -----------------------------
|
||||
# Check if testcase ended in success or error
|
||||
# Argument: result - testcase result value
|
||||
# Uses: $TESTCASE_RESULT - result of the testcase
|
||||
# Uses: $IMAGE_NAME - name of the image being tested
|
||||
ct_check_testcase_result() {
|
||||
local result="$1"
|
||||
if [[ "$result" != "0" ]]; then
|
||||
echo "Test for image '${IMAGE_NAME}' FAILED (exit code: ${result})"
|
||||
TESTCASE_RESULT=1
|
||||
fi
|
||||
return "$result"
|
||||
}
|
||||
|
||||
# ct_run_tests_from_testset
|
||||
# -----------------------------
|
||||
# Runs all tests in $TEST_SET, prints result to
|
||||
# the $TEST_SUMMARY variable
|
||||
# Argument: app_name - application name to log
|
||||
# Uses: $TEST_SET - set of test cases to run
|
||||
# Uses: $TEST_SUMMARY - variable for storing test results
|
||||
# Uses: $IMAGE_NAME - name of the image being tested
|
||||
# Uses: $UNSTABLE_TESTS - set of tests, whose result can be ignored
|
||||
# Uses: $IGNORE_UNSTABLE_TESTS - flag to ignore unstable tests
|
||||
ct_run_tests_from_testset() {
|
||||
local app_name="${1:-appnamenotset}"
|
||||
local time_beg_pretty
|
||||
local time_beg
|
||||
local time_end
|
||||
local time_diff
|
||||
local test_msg
|
||||
local is_unstable
|
||||
|
||||
# Let's store in the log what change do we test
|
||||
echo
|
||||
git show -s
|
||||
echo
|
||||
|
||||
for test_case in $TEST_SET; do
|
||||
TESTCASE_RESULT=0
|
||||
# shellcheck disable=SC2076
|
||||
if [[ " ${UNSTABLE_TESTS[*]} " =~ " ${app_name} " ]]; then
|
||||
is_unstable=1
|
||||
else
|
||||
is_unstable=0
|
||||
fi
|
||||
time_beg_pretty=$(ct_timestamp_pretty)
|
||||
time_beg=$(ct_timestamp_s)
|
||||
echo "-----------------------------------------------"
|
||||
echo "Running test $test_case (starting at $time_beg_pretty) ... "
|
||||
echo "-----------------------------------------------"
|
||||
$test_case
|
||||
ct_check_testcase_result $?
|
||||
time_end=$(ct_timestamp_s)
|
||||
if [ $TESTCASE_RESULT -eq 0 ]; then
|
||||
test_msg="[PASSED]"
|
||||
else
|
||||
if [ -n "${IGNORE_UNSTABLE_TESTS:-""}" ] && [ $is_unstable -eq 1 ]; then
|
||||
test_msg="[FAILED][UNSTABLE-IGNORED]"
|
||||
else
|
||||
test_msg="[FAILED]"
|
||||
TESTSUITE_RESULT=1
|
||||
fi
|
||||
fi
|
||||
time_diff=$(ct_timestamp_diff "$time_beg" "$time_end")
|
||||
printf -v TEST_SUMMARY "%s %s for '%s' %s (%s)\n" "${TEST_SUMMARY:-}" "${test_msg}" "${app_name}" "$test_case" "$time_diff"
|
||||
[ -n "${FAIL_QUICKLY:-}" ] && return 1
|
||||
done;
|
||||
}
|
||||
|
||||
# ct_timestamp_s
|
||||
# --------------
|
||||
# Returns timestamp in seconds since unix era -- a large integer
|
||||
function ct_timestamp_s() {
|
||||
date '+%s'
|
||||
}
|
||||
|
||||
# ct_timestamp_pretty
|
||||
# -----------------
|
||||
# Returns timestamp readable to a human, like 2022-05-18 10:52:44+02:00
|
||||
function ct_timestamp_pretty() {
|
||||
date --rfc-3339=seconds
|
||||
}
|
||||
|
||||
# ct_timestamp_diff
|
||||
# -----------------
|
||||
# Computes a time diff between two timestamps
|
||||
# Argument: start_date - Beginning (in seconds since unix era -- a large integer)
|
||||
# Argument: final_date - End (in seconds since unix era -- a large integer)
|
||||
# Returns: Time difference in format HH:MM:SS
|
||||
function ct_timestamp_diff() {
|
||||
local start_date=$1
|
||||
local final_date=$2
|
||||
date -u -d "0 $final_date seconds - $start_date seconds" +"%H:%M:%S"
|
||||
}
|
||||
|
||||
# vim: set tabstop=2:shiftwidth=2:expandtab:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue