Skip to content

Commit 1f774c8

Browse files
authored
Get rid of OpenShift 3 functions (#366)
* Get rid of OpenShift 3 functions This needs to be tested on several container manually and reported here. * Disable checking target in test.sh Remove variable OS_CLUSTER_STARTED_BY_TEST. It is not used at all https://github.com/search?q=org%3Asclorg%20CT_SKIP_UPLOAD_IMAGE&type=code * Add support for building also images that are not released yet; Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 0a46964 commit 1f774c8

File tree

4 files changed

+41
-280
lines changed

4 files changed

+41
-280
lines changed

test-lib-openshift.sh

+27-264
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ source "$(dirname "${BASH_SOURCE[0]}")"/test-lib.sh
1717
# And the following trap must be set, in the beginning of the test script:
1818
# trap ct_os_cleanup EXIT SIGINT
1919
TESTSUITE_RESULT=0
20-
OS_CLUSTER_STARTED_BY_TEST=0
2120

2221
function ct_os_cleanup() {
2322
local exit_code=$?
@@ -423,23 +422,6 @@ function ct_delete_all_objects() {
423422
sleep 10
424423
}
425424

426-
# ct_os_docker_login_v3
427-
# --------------------
428-
# Logs in into docker daemon
429-
# Uses global REGISRTY_ADDRESS environment variable for arbitrary registry address.
430-
# Does not do anything if REGISTRY_ADDRESS is set.
431-
function ct_os_docker_login_v3() {
432-
[ -n "${REGISTRY_ADDRESS:-}" ] && echo "REGISTRY_ADDRESS set, not trying to docker login." && return 0
433-
# docker login fails with "404 page not found" error sometimes, just try it more times
434-
# shellcheck disable=SC2034
435-
for i in $(seq 12) ; do
436-
# shellcheck disable=SC2015
437-
docker login -u developer -p "$(oc whoami -t)" "${REGISRTY_ADDRESS:-172.30.1.1:5000}" && return 0 || :
438-
sleep 5
439-
done
440-
return 1
441-
}
442-
443425
# ct_os_docker_login_v4
444426
# --------------------
445427
# Logs in into docker daemon
@@ -468,34 +450,18 @@ function ct_os_docker_login_v4() {
468450
# In the format of name:tag ($image_name:latest by default)
469451
# Uses global REGISRTY_ADDRESS environment variable for arbitrary registry address.
470452
function ct_os_upload_image() {
471-
local os_version="${1}" ; shift
472453
local input_name="${1}" ; shift
473454
local image_name=${1}
474455
local output_name
475456
local source_name
476457

477-
if [ "${os_version}" != "v3" ] && [ "${os_version}" != "v4" ]; then
478-
echo "You have to specify OpenShift version to upload an image."
479-
echo "Either 'v3' or 'v4' is allowed"
458+
source_name="${input_name}"
459+
# Variable OCP4_REGISTER is set in function ct_os_docker_login_v4
460+
if ! ct_os_docker_login_v4; then
480461
return 1
481462
fi
463+
output_name="$OCP4_REGISTER/$namespace/$image_name"
482464

483-
source_name="${input_name}"
484-
if [ "${os_version}" == "v3" ]; then
485-
output_name="${REGISRTY_ADDRESS:-172.30.1.1:5000}/$(oc project -q)/$image_name"
486-
487-
if ! ct_os_docker_login_v3; then
488-
return 1
489-
fi
490-
491-
fi
492-
if [ "${os_version}" == "v4" ]; then
493-
# Variable OCP4_REGISTER is set in function ct_os_docker_login_v4
494-
if ! ct_os_docker_login_v4; then
495-
return 1
496-
fi
497-
output_name="$OCP4_REGISTER/$namespace/$image_name"
498-
fi
499465
docker tag "${source_name}" "${output_name}"
500466
docker push "${output_name}"
501467
}
@@ -520,91 +486,6 @@ function ct_os_template_exists() {
520486
oc get templates -n openshift | grep -q "^${t_name}\s"
521487
}
522488

523-
# ct_os_install_in_centos
524-
# --------------------
525-
# Installs os cluster in CentOS
526-
function ct_os_install_in_centos() {
527-
yum install -y centos-release-openshift-origin
528-
yum install -y wget git net-tools bind-utils iptables-services bridge-utils\
529-
bash-completion origin-clients docker origin-clients
530-
}
531-
532-
533-
# ct_os_cluster_up [DIR, IS_PUBLIC, CLUSTER_VERSION]
534-
# --------------------
535-
# Runs the local OpenShift cluster using 'oc cluster up' and logs in as developer.
536-
# Arguments: dir - directory to keep configuration data in, random if omitted
537-
# Arguments: is_public - sets either private or public hostname for web-UI,
538-
# use "true" for allow remote access to the web-UI,
539-
# "false" is default
540-
# Arguments: cluster_version - version of the OpenShift cluster to use, empty
541-
# means default version of `oc`; example value: 3.7;
542-
# also can be specified outside by OC_CLUSTER_VERSION
543-
function ct_os_cluster_up() {
544-
ct_os_cluster_running && echo "Cluster already running. Nothing is done." && return 0
545-
ct_os_logged_in && echo "Already logged in to a cluster. Nothing is done." && return 0
546-
547-
mkdir -p /var/tmp/openshift
548-
local dir="${1:-$(mktemp -d /var/tmp/openshift/os-data-XXXXXX)}" ; shift || :
549-
local is_public="${1:-'false'}" ; shift || :
550-
local default_cluster_version=${OC_CLUSTER_VERSION:-}
551-
local cluster_version=${1:-${default_cluster_version}} ; shift || :
552-
if ! grep -qe '--insecure-registry.*172\.30\.0\.0' /etc/sysconfig/docker ; then
553-
sed -i "s|OPTIONS='|OPTIONS='--insecure-registry 172.30.0.0/16 |" /etc/sysconfig/docker
554-
fi
555-
556-
systemctl stop firewalld || :
557-
setenforce 0
558-
iptables -F
559-
560-
systemctl restart docker
561-
local cluster_ip="127.0.0.1"
562-
[ "${is_public}" == "true" ] && cluster_ip=$(ct_get_public_ip)
563-
564-
if [ -n "${cluster_version}" ] ; then
565-
# if $cluster_version is not set, we simply use oc that is available
566-
ct_os_set_path_oc "${cluster_version}"
567-
fi
568-
569-
mkdir -p "${dir}"/{config,data,pv}
570-
case $(oc version| head -n 1) in
571-
"oc v3.1"?.*)
572-
oc cluster up --base-dir="${dir}/data" --public-hostname="${cluster_ip}"
573-
;;
574-
"oc v3."*)
575-
oc cluster up --host-data-dir="${dir}/data" --host-config-dir="${dir}/config" \
576-
--host-pv-dir="${dir}/pv" --use-existing-config --public-hostname="${cluster_ip}"
577-
;;
578-
*)
579-
echo "ERROR: Unexpected oc version." >&2
580-
return 1
581-
;;
582-
esac
583-
oc version
584-
oc login -u system:admin
585-
oc project default
586-
ct_os_wait_rc_ready docker-registry 180
587-
ct_os_wait_rc_ready router 30
588-
oc login -u developer -p developer
589-
OS_CLUSTER_STARTED_BY_TEST=1
590-
# let openshift cluster to sync to avoid some race condition errors
591-
sleep 3
592-
}
593-
594-
# ct_os_cluster_down
595-
# --------------------
596-
# Shuts down the local OpenShift cluster using 'oc cluster down'
597-
function ct_os_cluster_down() {
598-
if [ "${OS_CLUSTER_STARTED_BY_TEST:-0}" -eq 1 ] ; then
599-
echo "Switching user to system:admin before cluster is going down."
600-
oc login -u system:admin
601-
echo "Cluster started by the test, shutting down."
602-
oc cluster down
603-
else
604-
echo "Cluster not started by the test, shutting down skipped."
605-
fi
606-
}
607-
608489
# ct_os_cluster_running
609490
# --------------------
610491
# Returns 0 if oc cluster is running
@@ -619,91 +500,6 @@ function ct_os_logged_in() {
619500
oc whoami >/dev/null
620501
}
621502

622-
# ct_os_set_path_oc OC_VERSION
623-
# --------------------
624-
# This is a trick that helps using correct version of the `oc`:
625-
# The input is version of the openshift in format v3.6.0 etc.
626-
# If the currently available version of oc is not of this version,
627-
# it first takes a look into /usr/local/oc-<ver>/bin directory,
628-
# and if not found there it downloads the community release from github.
629-
# In the end the PATH variable is changed, so the other tests can still use just 'oc'.
630-
# Arguments: oc_version - X.Y part of the version of OSE (e.g. 3.9)
631-
function ct_os_set_path_oc() {
632-
local oc_version
633-
local oc_path
634-
635-
oc_version=$(ct_os_get_latest_ver "$1")
636-
637-
if oc version | grep -q "oc ${oc_version%.*}." ; then
638-
echo "Binary oc found already available in version ${oc_version}: $(command -v oc) Doing noting."
639-
return 0
640-
fi
641-
642-
# first check whether we already have oc available in /usr/local
643-
local installed_oc_path="/usr/local/oc-${oc_version%.*}/bin"
644-
645-
if [ -x "${installed_oc_path}/oc" ] ; then
646-
oc_path="${installed_oc_path}"
647-
echo "Binary oc found in ${installed_oc_path}" >&2
648-
else
649-
# oc not available in /usr/local, try to download it from github (community release)
650-
oc_path="/tmp/oc-${oc_version}-bin"
651-
ct_os_download_upstream_oc "${oc_version}" "${oc_path}"
652-
fi
653-
if [ -z "${oc_path}" ] ; then
654-
echo "ERROR: oc not found installed, nor downloaded" >&1
655-
return 1
656-
fi
657-
export PATH="${oc_path}:${PATH}"
658-
if ! oc version | grep -q "oc ${oc_version%.*}." ; then
659-
echo "ERROR: something went wrong, oc located at ${oc_path}, but oc of version ${oc_version} not found in PATH ($PATH)" >&1
660-
return 1
661-
else
662-
echo "PATH set correctly, binary oc found in version ${oc_version}: $(command -v oc)"
663-
fi
664-
}
665-
666-
# ct_os_get_latest_ver VERSION_PART_X
667-
# --------------------
668-
# Returns full version (vX.Y.Z) from part of the version (X.Y)
669-
# Arguments: vxy - X.Y part of the version
670-
# Returns vX.Y.Z variant of the version
671-
function ct_os_get_latest_ver(){
672-
local vxy="v$1"
673-
for vz in {3..0} ; do
674-
curl -sif "https://github.com/openshift/origin/releases/tag/${vxy}.${vz}" >/dev/null && echo "${vxy}.${vz}" && return 0
675-
done
676-
echo "ERROR: version ${vxy} not found in https://github.com/openshift/origin/tags" >&2
677-
return 1
678-
}
679-
680-
# ct_os_download_upstream_oc OC_VERSION OUTPUT_DIR
681-
# --------------------
682-
# Downloads a particular version of openshift-origin-client-tools from
683-
# github into specified output directory
684-
# Arguments: oc_version - version of OSE (e.g. v3.7.2)
685-
# Arguments: output_dir - output directory
686-
function ct_os_download_upstream_oc() {
687-
local oc_version=$1
688-
local output_dir=$2
689-
690-
# check whether we already have the binary in place
691-
[ -x "${output_dir}/oc" ] && return 0
692-
693-
mkdir -p "${output_dir}"
694-
# using html output instead of https://api.github.com/repos/openshift/origin/releases/tags/${oc_version},
695-
# because API is limited for number of queries if not authenticated
696-
tarball=$(curl -si "https://github.com/openshift/origin/releases/tag/${oc_version}" | grep -o -e "openshift-origin-client-tools-${oc_version}-[a-f0-9]*-linux-64bit.tar.gz" | head -n 1)
697-
698-
# download, unpack the binaries and then put them into output directory
699-
echo "Downloading https://github.com/openshift/origin/releases/download/${oc_version}/${tarball} into ${output_dir}/" >&2
700-
curl -sL https://github.com/openshift/origin/releases/download/"${oc_version}"/"${tarball}" | tar -C "${output_dir}" -xz
701-
mv -f "${output_dir}"/"${tarball%.tar.gz}"/* "${output_dir}/"
702-
703-
rmdir "${output_dir}"/"${tarball%.tar.gz}"
704-
}
705-
706-
707503
# ct_os_test_s2i_app_func IMAGE APP CONTEXT_DIR CHECK_CMD [OC_ARGS]
708504
# --------------------
709505
# Runs [image] and [app] in the openshift and optionally specifies env_params
@@ -738,22 +534,8 @@ function ct_os_test_s2i_app_func() {
738534
local image_tagged="${image_name_no_namespace%:*}:${VERSION}"
739535

740536
if [ "${CVP:-0}" -eq "0" ]; then
741-
if [ "${CT_OCP4_TEST:-false}" == 'true' ] ; then
742-
echo "Uploading image ${image_name} as ${image_tagged} into OpenShift internal registry."
743-
ct_os_upload_image "v4" "${image_name}" "${image_tagged}"
744-
else
745-
# Create a specific imagestream tag for the image so that oc cannot use anything else
746-
if [ "${CT_SKIP_UPLOAD_IMAGE:-false}" == 'true' ] ; then
747-
echo "Importing image ${image_name} as ${namespace}/${image_tagged}"
748-
# Use --reference-policy=local to pull remote image content to the cluster
749-
# Works around the issue of builder pods not having access to registry.redhat.io
750-
oc tag --source=docker "${image_name}" "${namespace}/${image_tagged}" --insecure=true --reference-policy=local
751-
ct_os_wait_stream_ready "${image_tagged}" "${namespace}"
752-
else
753-
echo "Uploading image ${image_name} as ${image_tagged}"
754-
ct_os_upload_image "v3" "${image_name}" "${image_tagged}"
755-
fi
756-
fi
537+
echo "Uploading image ${image_name} as ${image_tagged} into OpenShift internal registry."
538+
ct_os_upload_image "${image_name}" "${image_tagged}"
757539
else
758540
echo "Testing image ${image_name} in CVP pipeline."
759541
fi
@@ -883,50 +665,31 @@ function ct_os_test_template_app_func() {
883665
# Upload main image is already done by CVP pipeline. No need to do it twice.
884666
if [ "${CVP:-0}" -eq "0" ]; then
885667
# Create a specific imagestream tag for the image so that oc cannot use anything else
886-
if [ "${CT_OCP4_TEST:-false}" == 'true' ] ; then
887-
echo "Uploading image ${image_name} as ${image_tagged} into OpenShift internal registry."
888-
ct_os_upload_image "v4" "${image_name}" "${image_tagged}"
889-
else
890-
if [ "${CT_SKIP_UPLOAD_IMAGE:-false}" == 'true' ] ; then
891-
echo "Importing image ${image_name} as ${image_tagged}"
892-
# Use --reference-policy=local to pull remote image content to the cluster
893-
# Works around the issue of builder pods not having access to registry.redhat.io
894-
oc tag --source=docker "${image_name}" "${namespace}/${image_tagged}" --insecure=true --reference-policy=local
895-
ct_os_wait_stream_ready "${image_tagged}" "${namespace}"
896-
else
897-
echo "Uploading image ${image_name} as ${image_tagged}"
898-
ct_os_upload_image "v3" "${image_name}" "${image_tagged}"
899-
fi
900-
fi
668+
echo "Uploading image ${image_name} as ${image_tagged} into OpenShift internal registry."
669+
ct_os_upload_image "${image_name}" "${image_tagged}"
901670
else
902671
echo "Import is already done by CVP pipeline."
903672
fi
904673
# Upload main image is already done by CVP pipeline. No need to do it twice.
905674
if [ "${CVP:-0}" -eq "0" ]; then
906675
# Other images are not uploaded by CVP pipeline. We need to do it.
907-
if [ "${CT_SKIP_UPLOAD_IMAGE:-false}" == 'false' ] ; then
908-
# upload also other images, that template might need (list of pairs in the format <image>|<tag>
909-
local image_tag_a
910-
local i_t
911-
for i_t in ${other_images} ; do
912-
echo "${i_t}"
913-
IFS='|' read -ra image_tag_a <<< "${i_t}"
914-
if [[ "$(docker images -q "$image_name" 2>/dev/null)" == "" ]]; then
915-
echo "ERROR: Image $image_name is not pulled yet."
916-
docker images
917-
echo "Add to the beginning of scripts run-openshift-remote-cluster and run-openshift row"
918-
echo "'ct_pull_image $image_name true'."
919-
exit 1
920-
fi
921-
922-
if [ "${CT_OCP4_TEST:-false}" == 'true' ] ; then
923-
echo "Uploading image ${image_tag_a[0]} as ${image_tag_a[1]} into OpenShift internal registry."
924-
ct_os_upload_image "v4" "${image_tag_a[0]}" "${image_tag_a[1]}"
925-
else
926-
ct_os_upload_image "v3" "${image_tag_a[0]}" "${image_tag_a[1]}"
927-
fi
928-
done
929-
fi
676+
# upload also other images, that template might need (list of pairs in the format <image>|<tag>
677+
local image_tag_a
678+
local i_t
679+
for i_t in ${other_images} ; do
680+
echo "${i_t}"
681+
IFS='|' read -ra image_tag_a <<< "${i_t}"
682+
if [[ "$(docker images -q "$image_name" 2>/dev/null)" == "" ]]; then
683+
echo "ERROR: Image $image_name is not pulled yet."
684+
docker images
685+
echo "Add to the beginning of scripts run-openshift-remote-cluster and run-openshift row"
686+
echo "'ct_pull_image $image_name true'."
687+
exit 1
688+
fi
689+
690+
echo "Uploading image ${image_tag_a[0]} as ${image_tag_a[1]} into OpenShift internal registry."
691+
ct_os_upload_image "${image_tag_a[0]}" "${image_tag_a[1]}"
692+
done
930693
fi
931694

932695
# get the template file from remote or local location; if not found, it is
@@ -1039,7 +802,7 @@ ct_os_test_image_update() {
1039802

1040803
# Get current image from repository and create an imagestream
1041804
docker pull "$old_image:latest" 2>/dev/null
1042-
ct_os_upload_image "v3" "$old_image" "$istag"
805+
ct_os_upload_image "$old_image" "$istag"
1043806

1044807
# Setup example application with curent image
1045808
oc new-app "$@" --name "$service_name"
@@ -1051,7 +814,7 @@ ct_os_test_image_update() {
1051814
ct_assert_cmd_success "$check_command_exp"
1052815

1053816
# Tag built image into the imagestream and wait for rebuild
1054-
ct_os_upload_image "v3" "$image_name" "$istag"
817+
ct_os_upload_image "$image_name" "$istag"
1055818
ct_os_wait_pod_ready "${service_name}-2" 60
1056819

1057820
# Check application output

test-lib-remote-openshift.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function ct_os_import_image_ocp4() {
116116
local imagestream=${1:-$image_name:latest}
117117

118118
echo "Uploading image ${image_name} as ${imagestream} into OpenShift internal registry."
119-
ct_os_upload_image "v4" "${image_name}" "${imagestream}"
119+
ct_os_upload_image "${image_name}" "${imagestream}"
120120

121121
}
122122

test.sh

-14
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,6 @@ for dir in ${VERSIONS}; do
5353

5454
fi
5555

56-
if [ -n "${TEST_OPENSHIFT_MODE}" ]; then
57-
# In case only imagestream is deprecated
58-
# and the other tests should be working
59-
if [ -e ".exclude-openshift" ]; then
60-
echo "-> .exclude-openshift file exists for version $dir, skipping OpenShift tests."
61-
else
62-
if [[ -x test/run-openshift ]]; then
63-
VERSION=$dir test/run-openshift
64-
else
65-
echo "-> OpenShift 3 tests are not present, skipping"
66-
fi
67-
fi
68-
fi
69-
7056
if [ -n "${TEST_UPSTREAM}" ]; then
7157
if [[ -x test/run-upstream ]]; then
7258
VERSION=$dir test/run-upstream

0 commit comments

Comments
 (0)