Merge pull request #415 from phracek/fix_typo_run_openshift
Fix typo in OpenShift 3 tests
This commit is contained in:
parent
6a69db45eb
commit
abffd4737c
11 changed files with 279 additions and 62 deletions
|
|
@ -1,5 +1,27 @@
|
|||
#!/bin/env python3
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2018-2019 Red Hat, Inc.
|
||||
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
import sys
|
||||
import json
|
||||
import logging
|
||||
|
|
|
|||
|
|
@ -150,6 +150,16 @@ function ct_os_get_build_pod_status() {
|
|||
| sort -u | awk '{print $2}' | tail -n 1
|
||||
}
|
||||
|
||||
# ct_os_get_buildconfig_pod_name POD_PREFIX
|
||||
# ----------------------------
|
||||
# Returns status of the buildconfig pod specified by prefix [pod_prefix].
|
||||
# Argument: pod_prefix - prefix
|
||||
function ct_os_get_buildconfig_pod_name() {
|
||||
local pod_prefix="${1}" ; shift
|
||||
local query="custom-columns=NAME:.metadata.name"
|
||||
oc get bc -o "$query" | grep -e "${pod_prefix}" | sort -u | tail -n 1
|
||||
}
|
||||
|
||||
# ct_os_get_pod_name POD_PREFIX
|
||||
# --------------------
|
||||
# Returns the full name of pods specified by prefix [pod_prefix].
|
||||
|
|
@ -169,6 +179,22 @@ function ct_os_get_pod_ip() {
|
|||
oc get pod "$pod_name" --no-headers -o custom-columns=IP:status.podIP
|
||||
}
|
||||
|
||||
# ct_os_get_sti_build_logs
|
||||
# -----------------
|
||||
# Return logs from sti_build
|
||||
# Arguments: pod_name
|
||||
function ct_os_get_sti_build_logs() {
|
||||
local pod_prefix="${1}"
|
||||
pod_name=$(ct_os_get_buildconfig_pod_name "${pod_prefix}")
|
||||
# Print logs but do not failed. Just for traces
|
||||
if [ x"${pod_name}" != "x" ]; then
|
||||
oc logs "bc/$pod_name" || return 0
|
||||
else
|
||||
echo "Build config bc/$pod_name does not exist for some reason."
|
||||
echo "Import probably failed."
|
||||
fi
|
||||
}
|
||||
|
||||
# ct_os_check_pod_readiness POD_PREFIX STATUS
|
||||
# --------------------
|
||||
# Checks whether the pod is ready.
|
||||
|
|
@ -195,7 +221,12 @@ function ct_os_wait_pod_ready() {
|
|||
echo -n "Waiting for ${pod_prefix} build pod to finish ..."
|
||||
while ! [ "$(ct_os_get_build_pod_status "${pod_prefix}")" == "Succeeded" ] ; do
|
||||
echo -n "."
|
||||
[ "${SECONDS}" -gt "${timeout}0" ] && echo " FAIL" && return 1
|
||||
if [ "${SECONDS}" -gt "${timeout}0" ]; then
|
||||
echo " FAIL"
|
||||
ct_os_print_logs || :
|
||||
ct_os_get_sti_build_logs "${pod_prefix}" || :
|
||||
return 1
|
||||
fi
|
||||
sleep 3
|
||||
done
|
||||
echo " DONE"
|
||||
|
|
@ -204,7 +235,12 @@ function ct_os_wait_pod_ready() {
|
|||
echo -n "Waiting for ${pod_prefix} pod becoming ready ..."
|
||||
while ! ct_os_check_pod_readiness "${pod_prefix}" "true" ; do
|
||||
echo -n "."
|
||||
[ "${SECONDS}" -gt "${timeout}" ] && echo " FAIL" && return 1
|
||||
if [ "${SECONDS}" -gt "${timeout}" ]; then
|
||||
echo " FAIL";
|
||||
ct_os_print_logs || :
|
||||
ct_os_get_sti_build_logs "${pod_prefix}" || :
|
||||
return 1
|
||||
fi
|
||||
sleep 3
|
||||
done
|
||||
echo " DONE"
|
||||
|
|
@ -223,7 +259,12 @@ function ct_os_wait_rc_ready() {
|
|||
while ! test "$( (oc get --no-headers statefulsets; oc get --no-headers rc) 2>/dev/null \
|
||||
| grep "^${pod_prefix}" | awk '$2==$3 {print "ready"}')" == "ready" ; do
|
||||
echo -n "."
|
||||
[ "${SECONDS}" -gt "${timeout}" ] && echo " FAIL" && return 1
|
||||
if [ "${SECONDS}" -gt "${timeout}" ]; then
|
||||
echo " FAIL";
|
||||
ct_os_print_logs || :
|
||||
ct_os_get_sti_build_logs "${pod_prefix}" || :
|
||||
return 1
|
||||
fi
|
||||
sleep 3
|
||||
done
|
||||
echo " DONE"
|
||||
|
|
@ -331,7 +372,12 @@ function ct_os_delete_project() {
|
|||
return
|
||||
fi
|
||||
local project_name="${1:-$(oc project -q)}" ; shift || :
|
||||
oc delete project "${project_name}"
|
||||
if oc delete project "${project_name}" ; then
|
||||
echo "Project ${project_name} was deleted properly"
|
||||
else
|
||||
echo "Project ${project_name} was not delete properly. But it does not block CI."
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# ct_delete_all_objects
|
||||
|
|
@ -617,20 +663,21 @@ function ct_os_test_s2i_app_func() {
|
|||
ct_os_new_project
|
||||
|
||||
namespace=${CT_NAMESPACE:-"$(oc project -q)"}
|
||||
local image_tagged="${image_name_no_namespace%:*}:${VERSION}"
|
||||
|
||||
if [ "${CT_EXTERNAL_REGISTRY:-false}" == 'true' ] ; then
|
||||
ct_os_import_image_ocp4 "${image_name}" "${image_name_no_namespace}"
|
||||
ct_os_import_image_ocp4 "${image_name}" "${image_tagged}"
|
||||
else
|
||||
# Create a specific imagestream tag for the image so that oc cannot use anything else
|
||||
if [ "${CT_SKIP_UPLOAD_IMAGE:-false}" == 'true' ] ; then
|
||||
echo "Importing image ${image_name} as ${namespace}/${image_name_no_namespace}"
|
||||
echo "Importing image ${image_name} as ${namespace}/${image_tagged}"
|
||||
# Use --reference-policy=local to pull remote image content to the cluster
|
||||
# Works around the issue of builder pods not having access to registry.redhat.io
|
||||
oc tag --source=docker "${image_name}" "${namespace}/${image_name_no_namespace}" --insecure=true --reference-policy=local
|
||||
ct_os_wait_stream_ready "${image_name_no_namespace}" "${namespace}"
|
||||
oc tag --source=docker "${image_name}" "${namespace}/${image_tagged}" --insecure=true --reference-policy=local
|
||||
ct_os_wait_stream_ready "${image_tagged}" "${namespace}"
|
||||
else
|
||||
echo "Uploading image ${image_name} as ${image_name_no_namespace}"
|
||||
ct_os_upload_image "${image_name}" "${image_name_no_namespace}"
|
||||
echo "Uploading image ${image_name} as ${image_tagged}"
|
||||
ct_os_upload_image "${image_name}" "${image_tagged}"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
@ -642,7 +689,7 @@ function ct_os_test_s2i_app_func() {
|
|||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ct_os_deploy_s2i_image "${image_name_no_namespace}" "${app_param}" \
|
||||
ct_os_deploy_s2i_image "${image_tagged}" "${app_param}" \
|
||||
--context-dir="${context_dir}" \
|
||||
--name "${service_name}" \
|
||||
${oc_args}
|
||||
|
|
@ -793,6 +840,8 @@ function ct_os_test_template_app_func() {
|
|||
local local_template
|
||||
|
||||
local_template=$(ct_obtain_input "${template}" 2>/dev/null || echo "--template=${template}")
|
||||
|
||||
echo "Creating a new-app with name ${name_in_template} in namespace ${namespace} with args ${oc_args}."
|
||||
# shellcheck disable=SC2086
|
||||
oc new-app "${local_template}" \
|
||||
--name "${name_in_template}" \
|
||||
|
|
@ -928,7 +977,7 @@ ct_os_test_image_update() {
|
|||
function ct_os_deploy_cmd_image() {
|
||||
local image_name=${1}
|
||||
oc get pod command-app &>/dev/null && echo "command POD already running" && return 0
|
||||
echo "command POD not running yet, will start one called command-app"
|
||||
echo "command POD not running yet, will start one called command-app ${image_name}"
|
||||
oc create -f - <<EOF
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
|
|
@ -946,6 +995,8 @@ EOF
|
|||
SECONDS=0
|
||||
echo -n "Waiting for command POD ."
|
||||
while [ $SECONDS -lt 180 ] ; do
|
||||
# Let's show status of all pods. Not only command-container for tracking issues
|
||||
oc get pods
|
||||
# shellcheck disable=SC2016
|
||||
sout="$(ct_os_cmd_image_run 'echo $((11*11))' 2>/dev/null)"
|
||||
# shellcheck disable=SC2015
|
||||
|
|
@ -992,7 +1043,7 @@ ct_os_test_response_internal() {
|
|||
local status
|
||||
local response_code
|
||||
local response_file
|
||||
local util_image_name='python:3.6'
|
||||
local util_image_name='ubi7/ubi'
|
||||
|
||||
response_file=$(mktemp /tmp/ct_test_response_XXXXXX)
|
||||
ct_os_deploy_cmd_image "${util_image_name}"
|
||||
|
|
@ -1231,16 +1282,30 @@ function ct_os_test_image_stream_quickstart() {
|
|||
local local_template_file
|
||||
|
||||
echo "Running image stream test for stream ${image_stream_file} and quickstart template ${template_file}"
|
||||
|
||||
echo "Image name is ${IMAGE_NAME}"
|
||||
# shellcheck disable=SC2119
|
||||
ct_os_new_project
|
||||
|
||||
local_image_stream_file=$(ct_obtain_input "${image_stream_file}")
|
||||
local_template_file=$(ct_obtain_input "${template_file}")
|
||||
oc create -f "${local_image_stream_file}"
|
||||
|
||||
# ct_os_test_template_app creates a new project, but we already need
|
||||
# it before for the image stream import, so tell it to skip this time
|
||||
namespace=${CT_NAMESPACE:-"$(oc project -q)"}
|
||||
|
||||
# Add namespace into openshift arguments
|
||||
if [[ $oc_args != *"NAMESPACE"* ]]; then
|
||||
oc_args="${oc_args} -p NAMESPACE=${namespace}"
|
||||
fi
|
||||
oc create -f "${local_image_stream_file}"
|
||||
|
||||
# In case we are testing on OpenShift 4 export variable for mirror image
|
||||
# which means, that image is going to be mirrored from an internal registry into OpenShift 4
|
||||
if [ "${CT_EXTERNAL_REGISTRY:-false}" == 'true' ]; then
|
||||
export CT_TAG_IMAGE=true
|
||||
fi
|
||||
# ct_os_test_template_app creates a new project, but we already need
|
||||
# it before for the image stream import, so tell it to skip this time
|
||||
|
||||
CT_SKIP_NEW_PROJECT=true \
|
||||
ct_os_test_template_app "${image_name}" \
|
||||
"${local_template_file}" \
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ EXPECTED_EXIT_CODE=0
|
|||
function ct_cleanup() {
|
||||
ct_show_resources
|
||||
for cid_file in "$CID_FILE_DIR"/* ; do
|
||||
[ -f "$cid_file" ] || continue
|
||||
local container
|
||||
container=$(cat "$cid_file")
|
||||
|
||||
|
|
@ -83,11 +84,12 @@ function ct_check_envs_set {
|
|||
if [ -n "${filtered_envs##${env_format//VALUE/$value}}" ]; then
|
||||
echo " Value $value is missing from variable $var_name"
|
||||
echo "$filtered_envs"
|
||||
IFS=$old_IFS
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
IFS=$old_IFS
|
||||
done <<< "$(echo "$loop_envs" | grep "$env_filter" | grep -v "^PWD=")"
|
||||
IFS=$old_IFS
|
||||
}
|
||||
|
||||
# ct_get_cid [name]
|
||||
|
|
@ -341,7 +343,7 @@ function ct_binary_found_from_df() {
|
|||
# Create Dockerfile that looks for the binary
|
||||
cat <<EOF >"$tmpdir/Dockerfile"
|
||||
FROM $IMAGE_NAME
|
||||
RUN which $binary | grep "$binary_path"
|
||||
RUN command -v $binary | grep "$binary_path"
|
||||
EOF
|
||||
# Build an image, looking for expected path in the output
|
||||
if ! docker build -f "$tmpdir/Dockerfile" --no-cache "$tmpdir"; then
|
||||
|
|
@ -559,7 +561,7 @@ ct_registry_from_os() {
|
|||
registry=registry.redhat.io
|
||||
;;
|
||||
*)
|
||||
registry=docker.io
|
||||
registry=quay.io
|
||||
;;
|
||||
esac
|
||||
echo "$registry"
|
||||
|
|
@ -585,9 +587,9 @@ ct_get_public_image_name() {
|
|||
elif [ "x$os" == "xrhel8" ]; then
|
||||
public_image_name=$registry/rhel8/$base_image_name-${version//./}
|
||||
elif [ "x$os" == "xcentos7" ]; then
|
||||
public_image_name=$registry/centos/$base_image_name-${version//./}-centos7
|
||||
public_image_name=$registry/centos7/$base_image_name-${version//./}-centos7
|
||||
elif [ "x$os" == "xcentos8" ]; then
|
||||
public_image_name=$registry/centos/$base_image_name-${version//./}-centos8
|
||||
public_image_name=$registry/centos8/$base_image_name-${version//./}-centos8
|
||||
fi
|
||||
|
||||
echo "$public_image_name"
|
||||
|
|
@ -816,7 +818,7 @@ ct_show_resources()
|
|||
echo "Memory:"
|
||||
free -h
|
||||
echo "Storage:"
|
||||
df -h
|
||||
df -h || :
|
||||
echo "CPU"
|
||||
lscpu
|
||||
}
|
||||
|
|
@ -825,7 +827,7 @@ ct_show_resources()
|
|||
# -----------------------------
|
||||
# Argument: dockerfile - path to a Dockerfile that will be used for building an image
|
||||
# (must work with an application directory called 'app-src')
|
||||
# Argument: app_url - git URI with a testing application
|
||||
# Argument: app_url - git URI with a testing application, supports "@" to indicate a different branch
|
||||
# Argument: body_regexp - PCRE regular expression that must match the response body
|
||||
# Argument: app_dir - name of the application directory that is used in the Dockerfile
|
||||
# Argument: port - Optional port number (default: 8080)
|
||||
|
|
@ -863,7 +865,17 @@ ct_test_app_dockerfile() {
|
|||
echo "Using this Dockerfile:"
|
||||
cat Dockerfile
|
||||
|
||||
if ! git clone "${app_url}" "${app_dir}" ; then
|
||||
# If app_url contains @, the string after @ is considered
|
||||
# as a name of a branch to clone instead of the main/master branch
|
||||
IFS='@' read -ra git_url_parts <<< "${app_url}"
|
||||
|
||||
if [ -n "${git_url_parts[1]}" ]; then
|
||||
git_clone_cmd="git clone --branch ${git_url_parts[1]} ${git_url_parts[0]} ${app_dir}"
|
||||
else
|
||||
git_clone_cmd="git clone ${app_url} ${app_dir}"
|
||||
fi
|
||||
|
||||
if ! $git_clone_cmd ; then
|
||||
echo "ERROR: Git repository ${app_url} cannot be cloned into ${app_dir}."
|
||||
echo "Terminating the Dockerfile build."
|
||||
return 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue