From 5aa2724f21a3a75725ed7d9cd78e3a9618c8f5e1 Mon Sep 17 00:00:00 2001
From: David Hoese <david.hoese@ssec.wisc.edu>
Date: Wed, 19 Jan 2022 12:34:22 -0600
Subject: [PATCH] Update CI integration tests to run curl on target cluster

---
 ci_tests/_tests_common.sh | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/ci_tests/_tests_common.sh b/ci_tests/_tests_common.sh
index 4cb3cbd..42b1564 100644
--- a/ci_tests/_tests_common.sh
+++ b/ci_tests/_tests_common.sh
@@ -86,6 +86,12 @@ wait_for_pod() {
     kubectl -n $ns wait --for=condition=Ready ${pod_name} --timeout=120s
 }
 
+run_remote_curl_pod() {
+    pod_prefix=$1
+    curl_target=$2
+    kubectl run -it --rm --restart=Never curl-test-${pod_prefix} --image=curlimages/curl:7.81.0 -- curl --fail -N -sS "${curl_target}"
+}
+
 run_grb_checks() {
     count=0
     while true; do
@@ -141,7 +147,7 @@ run_tile_gen_checks() {
 run_mapserver_checks() {
     # Ex: ["2020-11-24T22:23:19", "2020...
     # Get the first element without quotes
-    first_time=$(curl --fail -N -sS "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01" | head -c 21 | tail -c 19)
+    first_time=$(run_remote_curl_pod "$MAPSERVER_RELEASE_NAME" "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01" | head -c 21 | tail -c 19)
     debug "MapServer first time: ${first_time}"
     # if there aren't any times then we failed
     if [[ "${first_time}" == "" ]]; then
@@ -154,9 +160,9 @@ run_mapserver_checks() {
 run_mapserver_postgres_checks() {
     # Ex: ["2020-11-24T22:23:19", "2020...
     # Get the first element without quotes
-    first_time=$(curl --fail -N -sS "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=DESC" | head -c 21 | tail -c 19)
+    first_time=$(run_remote_curl_pod "${MAPSERVER_RELEASE_NAME}1" "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=DESC" | head -c 21 | tail -c 19)
     debug "MapServer first time: ${first_time}"
-    last_time=$(curl --fail -N -sS "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=ASC" | head -c 21 | tail -c 19)
+    last_time=$(run_remote_curl_pod "${MAPSERVER_RELEASE_NAME}2" "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=ASC" | head -c 21 | tail -c 19)
     debug "MapServer last time: ${last_time}"
     # if there aren't any times then we failed
     if [[ "${first_time}" == "" ]]; then
@@ -166,10 +172,10 @@ run_mapserver_postgres_checks() {
         return 1
     fi
 
-    all_times=$(curl --fail -N -sS "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=DESC")
+    all_times=$(run_remote_curl_pod "${MAPSERVER_RELEASE_NAME}3" "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=DESC")
     echo "All times: ${all_times}"
-    one_time=$(curl --fail -N -sS "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=ASC&num_times=1" | wc -m)
-    two_time=$(curl --fail -N -sS "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=ASC&num_times=2" | wc -m)
+    one_time=$(run_remote_curl_pod "${MAPSERVER_RELEASE_NAME}4" "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=ASC&num_times=1" | wc -m)
+    two_time=$(run_remote_curl_pod "${MAPSERVER_RELEASE_NAME}5" "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=ASC&num_times=2" | wc -m)
     debug "MapServer one time size: ${one_time}"
     debug "MapServer two time size: ${two_time}"
     # ["2020-12-25T15:29:25"] + newline(?)
@@ -183,8 +189,8 @@ run_mapserver_postgres_checks() {
 #    fi
 
     # 2020-04-10T17:02:21
-    near_time=$(curl --fail -N -sS "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=ASC&num_times=1&start_time=2020-04-10T17:02:21" | wc -m)
-    too_late_time=$(curl --fail -N -sS "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=ASC&num_times=1&start_time=2020-04-11T17:02:21" | wc -m)
+    near_time=$(run_remote_curl_pod "${MAPSERVER_RELEASE_NAME}6" "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=ASC&num_times=1&start_time=2020-04-10T17:02:21" | wc -m)
+    too_late_time=$(run_remote_curl_pod "${MAPSERVER_RELEASE_NAME}7" "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01?order=ASC&num_times=1&start_time=2020-04-11T17:02:21" | wc -m)
     debug "MapServer near time size: ${near_time}"
     if [[ ${near_time} -ne 24 ]]; then
         return 1
@@ -198,14 +204,14 @@ run_mapserver_postgres_checks() {
 }
 
 run_mapcache_checks() {
-    first_time=$(curl --fail -N -sS "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01" | head -c 21 | tail -c 19)
+    first_time=$(run_remote_curl_pod "${MAPCACHE_RELEASE_NAME}1" "http://${MAPSERVER_RELEASE_NAME}.${ns}/wms_times/g16/abi/radm1/C01" | head -c 21 | tail -c 19)
     debug "MapServer first time: ${first_time}"
-    curl --fail "http://${MAPCACHE_RELEASE_NAME}.${ns}/mapcache/wmts/?TIME=${first_time}Z&TILEMATRIXSET=grid_g16_abi_radf_1000m&LAYER=g16_abi_radm1_l1b_C01&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fpng&TileMatrix=0&TileCol=0&TileRow=0" >/dev/null
+    run_remote_curl_pod "${MAPCACHE_RELEASE_NAME}2" "http://${MAPCACHE_RELEASE_NAME}.${ns}/mapcache/wmts/?TIME=${first_time}Z&TILEMATRIXSET=grid_g16_abi_radf_1000m&LAYER=g16_abi_radm1_l1b_C01&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fpng&TileMatrix=0&TileCol=0&TileRow=0" >/dev/null
 }
 
 run_client_checks() {
     # just try to load the webpage at all
-    curl "http://${CLIENT_RELEASE_NAME}.${ns}/" >/dev/null
+    run_remote_curl_pod "${CLIENT_RELEASE_NAME}" "http://${CLIENT_RELEASE_NAME}.${ns}/" >/dev/null
 }
 
 check_and_uninstall() {
-- 
GitLab