echo " [--repo-policy local|remote] [--cluster-timeout <timeout-in seconds>] [--print-stats]"
echo " [--override <override-environment-filename>] [--pre-clean] [--gen-stats] [--delete-namespaces]"
echo " [--delete-containers] [--endpoint-stats] [--kubeconfig <config-file>] [--host-path-dir <local-host-dir>]"
+ echo " [--kubecontext <context-name>] [--docker-host <docker-host-url>] [--docker-proxy <host-or-ip>]"
}
if [ $# -eq 1 ] && [ "$1" == "help" ]; then
echo "--endpoint-stats - Collect endpoint statistics"
echo "--kubeconfig - Configure kubectl to use cluster specific cluster config file"
echo "--host-path-dir - (Base-)path on local-hostmounted to all VMs (nodes), for hostpath volumes in kube"
+ echo "--kubecontext - Configure kubectl to use a certain context, e.g 'minikube'"
+ echo "--docker-host - Configure docker to use docker in e.g. a VM"
+ echo "--docker-proxy - Configure ip/host to docker when docker is running in a VM"
echo ""
echo "List of app short names supported: "$APP_SHORT_NAMES
exit 0
echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@
-#Localhost constants
-LOCALHOST_NAME="localhost"
-LOCALHOST_HTTP="http://localhost"
-LOCALHOST_HTTPS="https://localhost"
-
# Var to hold 'auto' in case containers shall be stopped when test case ends
AUTO_CLEAN=""
#Var to control if containers shall be delete before test setup
DELETE_CONTAINERS=0
-#Var to configure kubectl from a config file.
+#Var to configure kubectl from a config file or context
KUBECONF=""
+#Localhost, may be set to another host/ip by cmd parameter
+LOCALHOST_NAME="localhost"
+
+#Reseting vars related to token/keys used by kubeproxy when istio is enabled
+#The vars are populated if istio is used in the testcase
+KUBE_PROXY_CURL_JWT=""
+KUBE_PROXY_ISTIO_JWKS_KEYS=""
+
#Var pointing to dir mounted to each kubernetes node (master and workers)
#Persistent volumes using "hostpath" are allocated beneath the point.
#Typically it is a dir on local host mounted to each VM running the master and worker.
return
fi
ENDPOINT_STAT_FILE=$TESTLOGS/$ATC/imageinfo_$ATC_$1".log"
- echo $POLICY_AGENT_IMAGE > $ENDPOINT_STAT_FILE
+ echo $A1PMS_IMAGE > $ENDPOINT_STAT_FILE
}
#Var for measuring execution time
fi
else
if [ -f $1 ]; then
- KUBECONF="--kubeconfig $1"
- echo "Option set - Kubeconfig path: "$1
- shift;
- foundparm=0
+ if [ ! -z "$KUBECONF" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="Only one of --kubeconfig/--kubecontext can be set"
+ fi
+ else
+ KUBECONF="--kubeconfig $1"
+ echo "Option set - Kubeconfig path: "$1
+ shift;
+ foundparm=0
+ fi
else
paramerror=1
if [ -z "$paramerror_str" ]; then
fi
fi
fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--kubecontext" ]; then
+ shift;
+ if [ -z "$1" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No context-name found for : '--kubecontext'"
+ fi
+ else
+ if [ ! -z "$KUBECONF" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="Only one of --kubeconfig or --kubecontext can be set"
+ fi
+ else
+ KUBECONF="--context $1"
+ echo "Option set - Kubecontext name: "$1
+ shift;
+ foundparm=0
+ fi
+ fi
+ fi
+ fi
if [ $paramerror -eq 0 ]; then
if [ "$1" == "--host-path-dir" ]; then
shift;
fi
else
HOST_PATH_BASE_DIR=$1
+ echo "Option set - Host path for kube set to: "$1
+ shift
+ foundparm=0
+ fi
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--docker-host" ]; then
+ shift;
+ if [ -z "$1" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No url found for : '--docker-host'"
+ fi
+ else
+ export DOCKER_HOST="$1"
+ echo "Option set - DOCKER_HOST set to: "$1
+ shift
+ foundparm=0
+ fi
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--docker-host" ]; then
+ shift;
+ if [ -z "$1" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No url found for : '--docker-host'"
+ fi
+ else
+ export DOCKER_HOST="$1"
+ echo "Option set - DOCKER_HOST set to: "$1
+ shift
+ foundparm=0
+ fi
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--docker-proxy" ]; then
+ shift;
+ if [ -z "$1" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No ip/host found for : '--docker-proxy'"
+ fi
+ else
+ export LOCALHOST_NAME=$1
+ echo "Option set - docker proxy set to: "$1
shift
foundparm=0
fi
exit 1
fi
+LOCALHOST_HTTP="http://$LOCALHOST_NAME"
+LOCALHOST_HTTPS="https://$LOCALHOST_NAME"
+
# sourcing the selected env variables for the test case
if [ -f "$TEST_ENV_VAR_FILE" ]; then
echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD
echo " docker is installed and using versions:"
echo " $(docker version --format 'Client version {{.Client.Version}} Server version {{.Server.Version}}')"
-tmp=$(which docker-compose)
-if [ $? -ne 0 ] || [ -z "$tmp" ]; then
- if [ $RUNMODE == "DOCKER" ]; then
+if [ $RUNMODE == "DOCKER" ]; then
+ tmp=$(which docker-compose)
+ if [ $? -ne 0 ] || [ -z "$tmp" ]; then
echo -e $RED"docker-compose is required to run the test environment, pls install"$ERED
exit 1
+ else
+ tmp=$(docker-compose version --short)
+ echo " docker-compose installed and using version $tmp"
+ if [[ "$tmp" == *'v2'* ]]; then
+ DOCKER_COMPOSE_VERION="V2"
+ fi
fi
fi
-tmp=$(docker-compose version --short)
-echo " docker-compose installed and using version $tmp"
-if [[ "$tmp" == *'v2'* ]]; then
- DOCKER_COMPOSE_VERION="V2"
-fi
-
-tmp=$(which kubectl)
-if [ $? -ne 0 ] || [ -z tmp ]; then
- if [ $RUNMODE == "KUBE" ]; then
+if [ $RUNMODE == "KUBE" ]; then
+ tmp=$(which kubectl)
+ if [ $? -ne 0 ] || [ -z tmp ]; then
echo -e $RED"kubectl is required to run the test environment in kubernetes mode, pls install"$ERED
exit 1
- fi
-else
- if [ $RUNMODE == "KUBE" ]; then
+ else
echo " kubectl is installed and using versions:"
echo $(kubectl $KUBECONF version --short=true) | indent2
res=$(kubectl $KUBECONF cluster-info 2>&1)
echo -e " Pulling remote snapshot or staging images my in some case result in pulling newer image versions outside the control of the test engine"
export KUBE_IMAGE_PULL_POLICY="Always"
fi
- CLUSTER_IP=$(kubectl $KUBECONF config view -o jsonpath={.clusters[0].cluster.server} | awk -F[/:] '{print $4}')
- echo -e $YELLOW" The cluster hostname/ip is: $CLUSTER_IP"$EYELLOW
+ #CLUSTER_IP=$(kubectl $KUBECONF config view -o jsonpath={.clusters[0].cluster.server} | awk -F[/:] '{print $4}')
+ #echo -e $YELLOW" The cluster hostname/ip is: $CLUSTER_IP"$EYELLOW
echo "================================================================================="
echo "================================================================================="
namespace=$1
labelname=$2
labelid=$3
- resources="deployments replicaset statefulset services pods configmaps persistentvolumeclaims persistentvolumes serviceaccounts clusterrolebindings"
+ resources="deployments replicaset statefulset services pods configmaps persistentvolumeclaims persistentvolumes serviceaccounts clusterrolebindings secrets authorizationpolicies requestauthentications"
deleted_resourcetypes=""
for restype in $resources; do
ns_flag="-n $namespace"
echo " Message: $(<./tmp/kubeerr)"
return 1
else
- kubectl $KUBECONF label ns $1 autotest=engine
+ kubectl $KUBECONF label ns $1 autotest=engine > /dev/null
echo -e " Creating namespace $1 $GREEN$BOLD OK $EBOLD$EGREEN"
fi
else
return 0
}
-# Removes a namespace
+# Removes and re-create a namespace
# args: <namespace>
# (Not for test scripts)
clean_and_create_namespace() {
if [ $? -ne 0 ]; then
return 1
fi
+}
+# Add/remove label on non-namespaced kube object
+# args: <api> <instance> <label>
+# (Not for test scripts)
+__kube_label_non_ns_instance() {
+ kubectl $KUBECONF label $1 $2 "$3" 1> /dev/null 2> ./tmp/kubeerr
+ return $?
+}
+
+# Add/remove label on namespaced kube object
+# args: <api> <instance> <namespace> <label>
+# (Not for test scripts)
+__kube_label_ns_instance() {
+ kubectl $KUBECONF label $1 $2 -n $3 "$4" 1> /dev/null 2> ./tmp/kubeerr
+ return $?
}
# Find the host ip of an app (using the service resource)
__clean_kube
if [ $PRE_CLEAN -eq 1 ]; then
echo " Cleaning docker resouces to free up resources, may take time..."
- ../common/clean_docker.sh 2>&1 /dev/null
+ ../common/clean_docker.sh 2>&1 > /dev/null
echo ""
fi
else
__clean_containers
if [ $PRE_CLEAN -eq 1 ]; then
echo " Cleaning kubernetes resouces to free up resources, may take time..."
- ../common/clean_kube.sh $KUBECONF 2>&1 /dev/null
+ ../common/clean_kube.sh $KUBECONF 2>&1 > /dev/null
echo ""
fi
fi
echo -ne " Container $BOLD${appname}$EBOLD starting${SAMELINE}"
- pa_st=false
+ a1pmsst=false
echo -ne " Waiting for ${ENTITY} ${appname} service status...${SAMELINE}"
TSTART=$SECONDS
loop_ctr=0
fi
echo -ne " Waiting for {ENTITY} $BOLD${appname}$EBOLD service status on ${3}, result: $result${SAMELINE}"
echo -ne " The ${ENTITY} $BOLD${appname}$EBOLD$GREEN is alive$EGREEN, responds to service status:$GREEN $result $EGREEN on ${url} after $(($SECONDS-$TSTART)) seconds"
- pa_st=true
+ a1pmsst=true
break
else
TS_TMP=$SECONDS
let loop_ctr=loop_ctr+1
done
- if [ "$pa_st" = "false" ]; then
+ if [ "$a1pmsst" = "false" ]; then
((RES_CONF_FAIL++))
echo -e $RED" The ${ENTITY} ${appname} did not respond to service status on ${url} in $(($SECONDS-$TSTART)) seconds"$ERED
return 1
#tmp=$(docker ps | grep $appname)
tmp=$(docker ps -q --filter name=$appname) #get the container id
- if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
+ if [ -z "$tmp" ]; then #Only check logs for running A1PMS apps
echo " "$dispname" is not running, no check made"
return
fi
## Generic curl
###############
# Generic curl function, assumes all 200-codes are ok
+# Used proxy, set
# args: <valid-curl-args-including full url>
# returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
# returns: The return code is 0 for ok and 1 for not ok
proxyflag=" --proxy-insecure --proxy $KUBE_PROXY_PATH"
fi
fi
- curlString="curl -skw %{http_code} $proxyflag $@"
+
+ if [ ! -z "$KUBE_PROXY_CURL_JWT" ]; then
+ jwt="-H "\""Authorization: Bearer $KUBE_PROXY_CURL_JWT"\"
+ curlString="curl -skw %{http_code} $proxyflag $@"
+ echo " CMD: $curlString $jwt" >> $HTTPLOG
+ res=$($curlString -H "Authorization: Bearer $KUBE_PROXY_CURL_JWT")
+ retcode=$?
+ else
+ curlString="curl -skw %{http_code} $proxyflag $@"
+ echo " CMD: $curlString" >> $HTTPLOG
+ res=$($curlString)
+ retcode=$?
+ fi
+ echo " RESP: $res" >> $HTTPLOG
+ echo " RETCODE: $retcode" >> $HTTPLOG
+ if [ $retcode -ne 0 ]; then
+ echo "<no-response-from-server>"
+ return 1
+ fi
+ http_code="${res:${#res}-3}"
+ if [ ${#res} -eq 3 ]; then
+ if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
+ echo "<no-response-from-server>"
+ return 1
+ else
+ return 0
+ fi
+ else
+ if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
+ echo "<not found, resp:${http_code}>"
+ return 1
+ fi
+ if [ $# -eq 2 ]; then
+ echo "${res:0:${#res}-3}" | xargs
+ else
+ echo "${res:0:${#res}-3}"
+ fi
+
+ return 0
+ fi
+
+}
+
+# Generic curl function, assumes all 200-codes are ok
+# Uses no proxy, even if it is set
+# args: <valid-curl-args-including full url>
+# returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
+# returns: The return code is 0 for ok and 1 for not ok
+__do_curl_no_proxy() {
+ echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
+ curlString="curl -skw %{http_code} $@"
echo " CMD: $curlString" >> $HTTPLOG
res=$($curlString)
retcode=$?
return 1
fi
if [ $# -eq 2 ]; then
- echo "${res:0:${#res}-3}" | xargs
+ echo "${res:0:${#res}-3}" | xargs
else
- echo "${res:0:${#res}-3}"
+ echo "${res:0:${#res}-3}"
fi
return 0