+# 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
+ . $TEST_ENV_VAR_FILE
+ if [ ! -z "$TEST_ENV_VAR_FILE_OVERRIDE" ]; then
+ echo -e $BOLD"Sourcing override env vars from: "$TEST_ENV_VAR_FILE_OVERRIDE$EBOLD
+ . $TEST_ENV_VAR_FILE_OVERRIDE
+ fi
+
+ if [ -z "$TEST_ENV_PROFILE" ] || [ -z "$SUPPORTED_PROFILES" ]; then
+ echo -e $YELLOW"This test case may not work with selected test env file. TEST_ENV_PROFILE is missing in test_env file or SUPPORTED_PROFILES is missing in test case file"$EYELLOW
+ else
+ found_profile=0
+ for prof in $SUPPORTED_PROFILES; do
+ if [ "$TEST_ENV_PROFILE" == "$prof" ]; then
+ echo -e $GREEN"Test case supports the selected test env file"$EGREEN
+ found_profile=1
+ fi
+ done
+ if [ $found_profile -ne 1 ]; then
+ echo -e $RED"Test case does not support the selected test env file"$ERED
+ echo "Profile: "$TEST_ENV_PROFILE" Supported profiles: "$SUPPORTED_PROFILES
+ echo -e $RED"Exiting...."$ERED
+ exit 1
+ fi
+ fi
+else
+ echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED
+ echo " Select one of following env var file matching the intended target of the test"
+ echo " Restart the test using the flag '--env-file <path-to-env-file>"
+ ls $AUTOTEST_HOME/../common/test_env* | indent1
+ exit 1
+fi
+
+#This var need be preserved from the command line option, if set, when env var is sourced.
+if [ ! -z "$TMP_RIC_SIM_PREFIX" ]; then
+ RIC_SIM_PREFIX=$TMP_RIC_SIM_PREFIX
+fi
+
+if [ -z "$PROJECT_IMAGES_APP_NAMES" ]; then
+ echo -e $RED"Var PROJECT_IMAGES_APP_NAMES must be defined in: "$TEST_ENV_VAR_FILE $ERED
+ exit 1
+fi
+
+if [[ $SUPPORTED_RUNMODES != *"$RUNMODE"* ]]; then
+ echo -e $RED"This test script does not support RUNMODE $RUNMODE"$ERED
+ echo "Supported RUNMODEs: "$SUPPORTED_RUNMODES
+ exit 1
+fi
+
+# Choose list of included apps depending on run-mode
+if [ $RUNMODE == "KUBE" ]; then
+ INCLUDED_IMAGES=$KUBE_INCLUDED_IMAGES
+else
+ INCLUDED_IMAGES=$DOCKER_INCLUDED_IMAGES
+fi
+
+echo ""
+# auto adding system apps
+__added_apps=""
+echo -e $BOLD"Auto adding system apps"$EBOLD
+if [ $RUNMODE == "KUBE" ]; then
+ INCLUDED_IMAGES=$INCLUDED_IMAGES" "$TESTENV_KUBE_SYSTEM_APPS
+ TMP_APPS=$TESTENV_KUBE_SYSTEM_APPS
+else
+ INCLUDED_IMAGES=$INCLUDED_IMAGES" "$TESTENV_DOCKER_SYSTEM_APPS
+ TMP_APPS=$TESTENV_DOCKER_SYSTEM_APPS
+fi
+if [ ! -z "$TMP_APPS" ]; then
+ for iapp in "$TMP_APPS"; do
+ file_pointer=$(echo $iapp | tr '[:upper:]' '[:lower:]')
+ file_pointer="../common/"$file_pointer"_api_functions.sh"
+ padded_iapp=$iapp
+ while [ ${#padded_iapp} -lt 16 ]; do
+ padded_iapp=$padded_iapp" "
+ done
+ echo " Auto-adding system app $padded_iapp Sourcing $file_pointer"
+ . $file_pointer
+ if [ $? -ne 0 ]; then
+ echo " Include file $file_pointer contain errors. Exiting..."
+ exit 1
+ fi
+ __added_apps=" $iapp "$__added_apps
+ done
+else
+ echo " None"
+fi
+
+if [ $RUNMODE == "KUBE" ]; then
+ TMP_APPS=$INCLUDED_IMAGES" "$KUBE_PRESTARTED_IMAGES
+else
+ TMP_APPS=$INCLUDED_IMAGES
+fi
+
+echo -e $BOLD"Auto adding included apps"$EBOLD
+ for iapp in $TMP_APPS; do
+ if [[ "$__added_apps" != *"$iapp"* ]]; then
+ file_pointer=$(echo $iapp | tr '[:upper:]' '[:lower:]')
+ file_pointer="../common/"$file_pointer"_api_functions.sh"
+ padded_iapp=$iapp
+ while [ ${#padded_iapp} -lt 16 ]; do
+ padded_iapp=$padded_iapp" "
+ done
+ echo " Auto-adding included app $padded_iapp Sourcing $file_pointer"
+ if [ ! -f "$file_pointer" ]; then
+ echo " Include file $file_pointer for app $iapp does not exist"
+ exit 1
+ fi
+ . $file_pointer
+ if [ $? -ne 0 ]; then
+ echo " Include file $file_pointer contain errors. Exiting..."
+ exit 1
+ fi
+ fi
+ done
+echo ""
+
+echo -e $BOLD"Test environment info"$EBOLD
+
+# Check needed installed sw
+
+tmp=$(which bash)
+if [ $? -ne 0 ] || [ -z "$tmp" ]; then
+ echo -e $RED"bash is required to run the test environment, pls install"$ERED
+ exit 1
+fi
+echo " bash is installed and using version:"
+echo "$(bash --version)" | indent2
+
+tmp=$(which python3)
+if [ $? -ne 0 ] || [ -z "$tmp" ]; then
+ echo -e $RED"python3 is required to run the test environment, pls install"$ERED
+ exit 1
+fi
+echo " python3 is installed and using version: $(python3 --version)"
+
+tmp=$(which docker)
+if [ $? -ne 0 ] || [ -z "$tmp" ]; then
+ echo -e $RED"docker is required to run the test environment, pls install"$ERED
+ exit 1
+fi
+echo " docker is installed and using versions:"
+echo " $(docker version --format 'Client version {{.Client.Version}} Server version {{.Server.Version}}')"
+
+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
+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
+ else
+ echo " kubectl is installed and using versions:"
+ echo $(kubectl $KUBECONF version --short=true) | indent2
+ res=$(kubectl $KUBECONF cluster-info 2>&1)
+ if [ $? -ne 0 ]; then
+ echo -e "$BOLD$RED############################################# $ERED$EBOLD"
+ echo -e $BOLD$RED"Command 'kubectl '$KUBECONF' cluster-info' returned error $ERED$EBOLD"
+ echo -e "$BOLD$RED############################################# $ERED$EBOLD"
+ echo " "
+ echo "kubectl response:"
+ echo $res
+ echo " "
+ echo "This script may have been started with user with no permission to run kubectl"
+ echo "Try running with 'sudo', set env KUBECONFIG or set '--kubeconfig' parameter"
+ echo "Do either 1, 2 or 3 "
+ echo " "
+ echo "1"
+ echo "Run with sudo"
+ echo -e $BOLD"sudo <test-script-and-parameters>"$EBOLD
+ echo " "
+ echo "2"
+ echo "Export KUBECONFIG and pass env to sudo - (replace user)"
+ echo -e $BOLD"export KUBECONFIG='/home/<user>/.kube/config'"$EBOLD
+ echo -e $BOLD"sudo -E <test-script-and-parameters>"$EBOLD
+ echo " "
+ echo "3"
+ echo "Set KUBECONFIG via script parameter"
+ echo -e $BOLD"sudo ... --kubeconfig /home/<user>/.kube/<config-file> ...."$EBOLD
+ echo "The config file need to downloaded from the cluster"
+
+ exit 1
+ fi
+ echo " Node(s) and container runtime config"
+ kubectl $KUBECONF get nodes -o wide | indent2
+ echo ""
+ if [ -z "$HOST_PATH_BASE_DIR" ]; then
+ HOST_PATH_BASE_DIR="/tmp"
+ echo " Persistent volumes will be mounted to $HOST_PATH_BASE_DIR on applicable node"
+ echo " No guarantee that persistent volume data is available on all nodes in the cluster"
+ else
+ echo "Persistent volumes will be mounted to base dir: $HOST_PATH_BASE_DIR"
+ echo "Assuming this dir is mounted from each node to a dir on the localhost or other"
+ echo "file system available to all nodes"
+ fi
+ fi
+fi
+
+echo ""
+
+echo -e $BOLD"Checking configured image setting for this test case"$EBOLD
+
+#Temp var to check for image variable name errors
+IMAGE_ERR=0
+#Create a file with image info for later printing as a table
+image_list_file="./tmp/.image-list"
+echo -e "Application\tApp short name\tImage\ttag\ttag-switch" > $image_list_file
+
+# Check if image env var is set and if so export the env var with image to use (used by docker compose files)
+# arg: <app-short-name> <target-variable-name> <image-variable-name> <image-tag-variable-name> <tag-suffix> <image name>
+__check_and_create_image_var() {
+
+ if [ $# -ne 6 ]; then
+ echo "Expected arg: <app-short-name> <target-variable-name> <image-variable-name> <image-tag-variable-name> <tag-suffix> <image name>"
+ ((IMAGE_ERR++))
+ return
+ fi
+
+ __check_included_image $1
+ if [ $? -ne 0 ]; then
+ echo -e "$6\t$1\t<image-excluded>\t<no-tag>" >> $image_list_file
+ # Image is excluded since the corresponding app is not used in this test
+ return
+ fi
+ tmp=${6}"\t"${1}"\t"
+ #Create var from the input var names
+ image="${!3}"
+ tmptag=$4"_"$5
+ tag="${!tmptag}"
+
+ optional_image_repo_target=""
+
+ if [ -z $image ]; then
+ __check_ignore_image $1
+ if [ $? -eq 0 ]; then
+ app_ds=$6
+ if [ -z "$6" ]; then
+ app_ds="<app ignored>"
+ fi
+ echo -e "$app_ds\t$1\t<image-ignored>\t<no-tag>" >> $image_list_file
+ # Image is ignored since the corresponding the images is not set in the env file
+ __remove_included_image $1 # Remove the image from the list of included images
+ return
+ fi
+ echo -e $RED"\$"$3" not set in $TEST_ENV_VAR_FILE"$ERED
+ ((IMAGE_ERR++))
+ echo ""
+ tmp=$tmp"<no-image>\t"
+ else
+
+ optional_image_repo_target=$image
+
+ #Add repo depending on image type
+ if [ "$5" == "REMOTE_RELEASE" ]; then
+ image=$NEXUS_RELEASE_REPO$image
+ fi
+ if [ "$5" == "REMOTE" ]; then
+ image=$NEXUS_STAGING_REPO$image
+ fi
+ if [ "$5" == "REMOTE_SNAPSHOT" ]; then
+ image=$NEXUS_SNAPSHOT_REPO$image
+ fi
+ if [ "$5" == "REMOTE_PROXY" ]; then
+ image=$NEXUS_PROXY_REPO$image
+ fi
+ if [ "$5" == "REMOTE_RELEASE_ONAP" ]; then
+ image=$NEXUS_RELEASE_REPO_ONAP$image
+ fi
+ if [ "$5" == "REMOTE_RELEASE_ORAN" ]; then
+ image=$NEXUS_RELEASE_REPO_ORAN$image
+ fi
+ #No nexus repo added for local images, tag: LOCAL
+ tmp=$tmp$image"\t"
+ fi
+ if [ -z $tag ]; then
+ echo -e $RED"\$"$tmptag" not set in $TEST_ENV_VAR_FILE"$ERED
+ ((IMAGE_ERR++))
+ echo ""
+ tmp=$tmp"<no-tag>\t"
+ else
+ tmp=$tmp$tag
+ fi
+ tmp=$tmp"\t"$5
+ echo -e "$tmp" >> $image_list_file
+ #Export the env var
+ export "${2}"=$image":"$tag #Note, this var may be set to the value of the target value below in __check_and_pull_image
+
+ remote_or_local_push=false
+ if [ ! -z "$IMAGE_REPO_ADR" ] && [[ $5 != *"PROXY"* ]]; then
+ if [ $5 == "LOCAL" ]; then
+ remote_or_local_push=true
+ fi
+ if [[ $5 == *"REMOTE"* ]]; then
+ if [ "$IMAGE_REPO_POLICY" == "remote" ]; then
+ remote_or_local_push=true
+ fi
+ fi
+ fi
+ if $remote_or_local_push; then # Only re-tag and push images according to policy, if repo is given
+ export "${2}_SOURCE"=$image":"$tag #Var to keep the actual source image
+ if [[ $optional_image_repo_target == *"/"* ]]; then # Replace all / with _ for images to push to external repo
+ optional_image_repo_target_tmp=${optional_image_repo_target//\//_}
+ optional_image_repo_target=$optional_image_repo_target_tmp
+ fi
+ export "${2}_TARGET"=$IMAGE_REPO_ADR"/"$optional_image_repo_target":"$tag #Create image + tag for optional image repo - pushed later if needed
+ else
+ export "${2}_SOURCE"=""
+ export "${2}_TARGET"=""
+ fi
+}
+
+# Check if app uses image included in this test run
+# Returns 0 if image is included, 1 if not
+__check_included_image() {
+ for im in $INCLUDED_IMAGES; do
+ if [ "$1" == "$im" ]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+# Check if app uses a project image
+# Returns 0 if image is included, 1 if not
+__check_project_image() {
+ for im in $PROJECT_IMAGES; do
+ if [ "$1" == "$im" ]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+# Check if app uses image built by the test script
+# Returns 0 if image is included, 1 if not
+__check_image_local_build() {
+ for im in $LOCAL_IMAGE_BUILD; do
+ if [ "$1" == "$im" ]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+# Check if app image is conditionally ignored in this test run
+# Returns 0 if image is conditionally ignored, 1 if not
+__check_ignore_image() {
+ for im in $CONDITIONALLY_IGNORED_IMAGES; do
+ if [ "$1" == "$im" ]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+# Removed image from included list of included images
+# Used when an image is marked as conditionally ignored
+__remove_included_image() {
+ tmp_img_rem_list=""
+ for im in $INCLUDED_IMAGES; do
+ if [ "$1" != "$im" ]; then
+ tmp_img_rem_list=$tmp_img_rem_list" "$im
+ fi
+ done
+ INCLUDED_IMAGES=$tmp_img_rem_list
+ return 0
+}
+
+# Check if app is included in the prestarted set of apps
+# Returns 0 if image is included, 1 if not
+__check_prestarted_image() {
+ for im in $KUBE_PRESTARTED_IMAGES; do
+ if [ "$1" == "$im" ]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+# Check if an app shall use a local image, based on the cmd parameters
+__check_image_local_override() {
+ for im in $USE_LOCAL_IMAGES; do
+ if [ "$1" == "$im" ]; then
+ return 1
+ fi
+ done
+ return 0
+}