diff --git a/test-lib-openshift.sh b/test-lib-openshift.sh index 1f3e806c..46822ea8 100644 --- a/test-lib-openshift.sh +++ b/test-lib-openshift.sh @@ -554,3 +554,47 @@ function ct_os_test_template_app() { "${other_images}" } +# ct_os_test_image_update IMAGE IS CHECK_CMD OC_ARGS +# -------------------- +# Runs an image update test with [image] uploaded to [is] imagestream +# and checks the services using an arbitrary function provided in [check_cmd]. +# Arguments: image - prefix or whole ID of the pod to run the cmd in (compulsory) +# Arguments: is - imagestream to upload the images into (compulsory) +# Arguments: check_cmd - command to be run to check functionality of created services (compulsory) +# Arguments: oc_args - arguments to use during oc new-app (compulsory) +ct_os_test_image_update() { + local image_name=$1; shift + local istag=$1; shift + local check_function=$1; shift + local service_name=${image_name##*/} + local old_image="" ip="" check_command_exp="" registry="" + registry=$(ct_registry_from_os "$OS") + old_image="$registry/$image_name" + + echo "Running image update test for: $image_name" + ct_os_new_project + + # Get current image from repository and create an imagestream + docker pull "$old_image" 2>/dev/null + ct_os_upload_image "$old_image" "$istag" + + # Setup example application with curent image + oc new-app "$@" --name "$service_name" + ct_os_wait_pod_ready "$service_name" 60 + + # Check application output + ip=$(ct_os_get_service_ip "$service_name") + check_command_exp=${check_function///$ip} + ct_assert_cmd_success "$check_command_exp" + + # Tag built image into the imagestream and wait for rebuild + ct_os_upload_image "$image_name" "$istag" + ct_os_wait_pod_ready "${service_name}-2" 60 + + # Check application output + ip=$(ct_os_get_service_ip "$service_name") + check_command_exp=${check_function///$ip} + ct_assert_cmd_success "$check_command_exp" + + ct_os_delete_project +} diff --git a/test-lib.sh b/test-lib.sh index 09869b42..2f83d91c 100644 --- a/test-lib.sh +++ b/test-lib.sh @@ -340,3 +340,47 @@ ct_test_response() { return ${result} } +# ct_registry_from_os OS +# ---------------- +# Transform operating system string [os] into registry url +# Argument: OS - string containing the os version +ct_registry_from_os() { + local registry="" + case $1 in + rhel7) + registry=registry.access.redhat.com + ;; + *) + registry=docker.io + ;; + esac + echo "$registry" +} + +# ct_assert_cmd_success CMD +# ---------------- +# Evaluates [cmd] and fails if it does not succeed. +# Argument: CMD - Command to be run +function ct_assert_cmd_success() { + echo "Checking '$*' for success ..." + if ! eval "$@" &>/dev/null; then + echo " FAIL" + return 1 + fi + echo " PASS" + return 0 +} + +# ct_assert_cmd_failure CMD +# ---------------- +# Evaluates [cmd] and fails if it succeeds. +# Argument: CMD - Command to be run +function ct_assert_cmd_failure() { + echo "Checking '$*' for failure ..." + if eval "$@" &>/dev/null; then + echo " FAIL" + return 1 + fi + echo " PASS" + return 0 +}