+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--use-staging-image" ]; then
+ USE_STAGING_IMAGES=""
+ shift
+ while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
+ USE_STAGING_IMAGES=$USE_STAGING_IMAGES" "$1
+ if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="App name $1 is not available for staging override for flag: '--use-staging-image'"
+ fi
+ fi
+ shift;
+ done
+ foundparm=0
+ if [ -z "$USE_STAGING_IMAGES" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No app name found for flag: '--use-staging-image'"
+ fi
+ else
+ echo "Option set - Overriding with staging images for app(s):"$USE_STAGING_IMAGES
+ fi
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--use-release-image" ]; then
+ USE_RELEASE_IMAGES=""
+ shift
+ while [ $# -gt 0 ] && [[ "$1" != "--"* ]]; do
+ USE_RELEASE_IMAGES=$USE_RELEASE_IMAGES" "$1
+ if [[ "$AVAILABLE_IMAGES_OVERRIDE" != *"$1"* ]]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="App name $1 is not available for release override for flag: '--use-release-image'"
+ fi
+ fi
+ shift;
+ done
+ foundparm=0
+ if [ -z "$USE_RELEASE_IMAGES" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No app name found for flag: '--use-release-image'"
+ fi
+ else
+ echo "Option set - Overriding with release images for app(s):"$USE_RELEASE_IMAGES
+ fi
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--image-repo" ]; then
+ shift;
+ IMAGE_REPO_ADR=$1
+ if [ -z "$1" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No image repo url found for : '--image-repo'"
+ fi
+ else
+ echo "Option set - Image repo url: "$1
+ shift;
+ foundparm=0
+ fi
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--repo-policy" ]; then
+ shift;
+ IMAGE_REPO_POLICY=$1
+ if [ -z "$1" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No policy found for : '--repo-policy'"
+ fi
+ else
+ if [ "$1" == "local" ] || [ "$1" == "remote" ]; then
+ echo "Option set - Image repo policy: "$1
+ shift;
+ foundparm=0
+ else
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="Repo policy shall be 'local' or 'remote'"
+ fi
+ fi
+ fi
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--cluster-timeout" ]; then
+ shift;
+ CLUSTER_TIME_OUT=$1
+ if [ -z "$1" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No timeout value found for : '--cluster-timeout'"
+ fi
+ else
+ #Check if positive int
+ case ${CLUSTER_TIME_OUT#[+]} in
+ *[!0-9]* | '')
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="Value for '--cluster-timeout' not an int : "$CLUSTER_TIME_OUT
+ fi
+ ;;
+ * ) ;; # Ok
+ esac
+ echo "Option set - Cluster timeout: "$1
+ shift;
+ foundparm=0
+ fi
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--override" ]; then
+ shift;
+ TEST_ENV_VAR_FILE_OVERRIDE=$1
+ if [ -z "$1" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No env file found for flag: '--override'"
+ fi
+ else
+ if [ ! -f $TEST_ENV_VAR_FILE_OVERRIDE ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="File for '--override' does not exist : "$TEST_ENV_VAR_FILE_OVERRIDE
+ fi
+ fi
+ echo "Option set - Override env from: "$1
+ shift;
+ foundparm=0
+ fi
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--pre-clean" ]; then
+ PRE_CLEAN=1
+ echo "Option set - Pre-clean of kube/docker resouces"
+ shift;
+ foundparm=0
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--print-stats" ]; then
+ PRINT_CURRENT_STATS=1
+ echo "Option set - Print stats after every test-case and config"
+ shift;
+ foundparm=0
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--gen-stats" ]; then
+ COLLECT_RUNTIME_STATS=1
+ echo "Option set - Collect runtime statistics"
+ shift;
+ foundparm=0
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--delete-namespaces" ]; then
+ if [ $RUNMODE == "DOCKER" ]; then
+ DELETE_KUBE_NAMESPACES=0
+ echo "Option ignored - Delete namespaces (ignored when running docker)"
+ else
+ if [ -z "KUBE_PRESTARTED_IMAGES" ]; then
+ DELETE_KUBE_NAMESPACES=0
+ echo "Option ignored - Delete namespaces (ignored when using prestarted apps)"
+ else
+ DELETE_KUBE_NAMESPACES=1
+ echo "Option set - Delete namespaces"
+ fi
+ fi
+ shift;
+ foundparm=0
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--delete-containers" ]; then
+ if [ $RUNMODE == "DOCKER" ]; then
+ DELETE_CONTAINERS=1
+ echo "Option set - Delete containers started by previous test(s)"
+ else
+ echo "Option ignored - Delete containers (ignored when running kube)"
+ fi
+ shift;
+ foundparm=0
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--endpoint-stats" ]; then
+ COLLECT_ENDPOINT_STATS=1
+ echo "Option set - Collect endpoint statistics"
+ shift;
+ foundparm=0
+ fi
+ fi
+
+done
+echo ""
+
+#Still params left?
+if [ $paramerror -eq 0 ] && [ $# -gt 0 ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="Unknown parameter(s): "$@
+ fi
+fi
+
+if [ $paramerror -eq 1 ]; then
+ echo -e $RED"Incorrect arg list: "$paramerror_str$ERED
+ __print_args
+ exit 1
+fi
+
+# 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}}')"
+
+tmp=$(which docker-compose)
+if [ $? -ne 0 ] || [ -z "$tmp" ]; then
+ if [ $RUNMODE == "DOCKER" ]; then
+ echo -e $RED"docker-compose is required to run the test environment, pls install"$ERED
+ exit 1
+ 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
+ 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
+ echo " kubectl is installed and using versions:"
+ echo $(kubectl version --short=true) | indent2
+ res=$(kubectl cluster-info 2>&1)
+ if [ $? -ne 0 ]; then
+ echo -e "$BOLD$RED############################################# $ERED$EBOLD"
+ echo -e $BOLD$RED"Command 'kubectl 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' or set 'KUBECONFIG'"
+ 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 inline (replace user)"
+ echo -e $BOLD"sudo KUBECONFIG='/home/<user>/.kube/config' <test-script-and-parameters>"$EBOLD
+
+ exit 1
+ fi
+ echo " Node(s) and container runtime config"
+ kubectl get nodes -o wide | indent2
+ 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
+}
+
+# Check if app uses image override
+# Returns the image/tag suffix LOCAL for local image or REMOTE/REMOTE_RELEASE/REMOTE_SNAPSHOT for staging/release/snapshot image
+__check_image_override() {
+
+ for im in $ORAN_IMAGES_APP_NAMES; do
+ if [ "$1" == "$im" ]; then
+ echo "REMOTE_RELEASE_ORAN"
+ return 0
+ fi
+ done
+
+ for im in $ONAP_IMAGES_APP_NAMES; do
+ if [ "$1" == "$im" ]; then
+ echo "REMOTE_RELEASE_ONAP"
+ return 0
+ fi
+ done
+
+ found=0
+ for im in $PROJECT_IMAGES_APP_NAMES; do
+ if [ "$1" == "$im" ]; then
+ found=1
+ fi
+ done
+
+ if [ $found -eq 0 ]; then
+ echo "REMOTE_PROXY"
+ return 0
+ fi
+
+ suffix=""
+ if [ $IMAGE_CATEGORY == "RELEASE" ]; then
+ suffix="REMOTE_RELEASE"
+ fi
+ if [ $IMAGE_CATEGORY == "DEV" ]; then
+ suffix="REMOTE"
+ fi
+ CTR=0
+ for im in $USE_STAGING_IMAGES; do
+ if [ "$1" == "$im" ]; then
+ suffix="REMOTE"
+ ((CTR++))
+ fi
+ done
+ for im in $USE_RELEASE_IMAGES; do
+ if [ "$1" == "$im" ]; then
+ suffix="REMOTE_RELEASE"
+ ((CTR++))
+ fi
+ done
+ for im in $USE_SNAPSHOT_IMAGES; do
+ if [ "$1" == "$im" ]; then
+ suffix="REMOTE_SNAPSHOT"
+ ((CTR++))
+ fi
+ done
+ for im in $USE_LOCAL_IMAGES; do
+ if [ "$1" == "$im" ]; then
+ suffix="LOCAL"
+ ((CTR++))
+ fi
+ done
+ echo $suffix
+ if [ $CTR -gt 1 ]; then
+ exit 1
+ fi
+ return 0
+}
+
+# Function to re-tag and image and push to another image repo
+__retag_and_push_image() {
+ if [ ! -z "$IMAGE_REPO_ADR" ]; then
+ source_image="${!1}"
+ trg_var_name=$1_"TARGET" # This var is created in func __check_and_create_image_var
+ target_image="${!trg_var_name}"
+
+ if [ -z $target_image ]; then
+ return 0 # Image with no target shall not be pushed
+ fi
+
+ echo -ne " Attempt to re-tag image to: ${BOLD}${target_image}${EBOLD}${SAMELINE}"
+ tmp=$(docker image tag $source_image ${target_image} )
+ if [ $? -ne 0 ]; then
+ docker stop $tmp &> ./tmp/.dockererr
+ ((IMAGE_ERR++))
+ echo ""
+ echo -e " Attempt to re-tag image to: ${BOLD}${target_image}${EBOLD} - ${RED}Failed${ERED}"
+ cat ./tmp/.dockererr
+ return 1
+ else
+ echo -e " Attempt to re-tag image to: ${BOLD}${target_image}${EBOLD} - ${GREEN}OK${EGREEN}"
+ fi
+ echo -ne " Attempt to push re-tagged image: ${BOLD}${target_image}${EBOLD}${SAMELINE}"
+ tmp=$(docker push ${target_image} )
+ if [ $? -ne 0 ]; then
+ docker stop $tmp &> ./tmp/.dockererr
+ ((IMAGE_ERR++))
+ echo ""
+ echo -e " Attempt to push re-tagged image: ${BOLD}${target_image}${EBOLD} - ${RED}Failed${ERED}"
+ cat ./tmp/.dockererr
+ return 1
+ else
+ echo -e " Attempt to push re-tagged image: ${BOLD}${target_image}${EBOLD} - ${GREEN}OK${EGREEN}"
+ fi
+ export "${1}"=$target_image
+ fi
+ return 0
+}
+
+#Function to check if image exist and stop+remove the container+pull new images as needed
+#args <script-start-arg> <descriptive-image-name> <container-base-name> <image-with-tag-var-name>
+__check_and_pull_image() {
+
+ source_image="${!4}"
+
+ echo -e " Checking $BOLD$2$EBOLD container(s) with basename: $BOLD$3$EBOLD using image: $BOLD$source_image$EBOLD"
+ format_string="\"{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\""
+ tmp_im=$(docker images --format $format_string $source_image)
+
+ if [ $1 == "local" ]; then
+ if [ -z "$tmp_im" ]; then
+ echo -e " "$2" (local image): \033[1m"$source_image"\033[0m $RED does not exist in local registry, need to be built (or manually pulled)"$ERED
+ ((IMAGE_ERR++))
+ return 1
+ else
+ echo -e " "$2" (local image): \033[1m"$source_image"\033[0m "$GREEN"OK"$EGREEN
+ fi
+ elif [ $1 == "remote" ] || [ $1 == "remote-remove" ]; then
+ if [ $1 == "remote-remove" ]; then
+ if [ $RUNMODE == "DOCKER" ]; then
+ echo -ne " Attempt to stop and remove container(s), if running - ${SAMELINE}"
+ tmp=$(docker ps -aq --filter name=${3} --filter network=${DOCKER_SIM_NWNAME})
+ if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
+ docker stop $tmp &> ./tmp/.dockererr
+ if [ $? -ne 0 ]; then
+ ((IMAGE_ERR++))
+ echo ""
+ echo -e $RED" Container(s) could not be stopped - try manual stopping the container(s)"$ERED
+ cat ./tmp/.dockererr
+ return 1
+ fi
+ fi
+ echo -ne " Attempt to stop and remove container(s), if running - "$GREEN"stopped"$EGREEN"${SAMELINE}"
+ tmp=$(docker ps -aq --filter name=${3} --filter network=${DOCKER_SIM_NWNAME}) &> /dev/null
+ if [ $? -eq 0 ] && [ ! -z "$tmp" ]; then
+ docker rm $tmp &> ./tmp/.dockererr
+ if [ $? -ne 0 ]; then
+ ((IMAGE_ERR++))
+ echo ""
+ echo -e $RED" Container(s) could not be removed - try manual removal of the container(s)"$ERED
+ cat ./tmp/.dockererr
+ return 1
+ fi
+ fi
+ echo -e " Attempt to stop and remove container(s), if running - "$GREEN"stopped removed"$EGREEN
+ tmp_im=""
+ else
+ tmp_im=""
+ fi
+ fi
+ if [ -z "$tmp_im" ]; then
+ echo -ne " Pulling image${SAMELINE}"
+ out=$(docker pull $source_image)
+ if [ $? -ne 0 ]; then
+ echo ""
+ echo -e " Pulling image -$RED could not be pulled"$ERED
+ ((IMAGE_ERR++))
+ echo $out > ./tmp/.dockererr
+ echo $out
+ return 1
+ fi
+ echo $out > ./tmp/.dockererr
+ if [[ $out == *"up to date"* ]]; then
+ echo -e " Pulling image -$GREEN Image is up to date $EGREEN"
+ elif [[ $out == *"Downloaded newer image"* ]]; then
+ echo -e " Pulling image -$GREEN Newer image pulled $EGREEN"
+ else
+ echo -e " Pulling image -$GREEN Pulled $EGREEN"
+ fi
+ else
+ echo -e " Pulling image -$GREEN OK $EGREEN(exists in local repository)"
+ fi
+ fi
+
+ __retag_and_push_image $4
+
+ return $?
+}
+
+setup_testenvironment() {
+ # Check that image env setting are available
+ echo ""
+
+ # Image var setup for all project images included in the test
+ for imagename in $APP_SHORT_NAMES; do
+ __check_included_image $imagename
+ incl=$?
+ __check_project_image $imagename
+ proj=$?
+ if [ $incl -eq 0 ]; then
+ if [ $proj -eq 0 ]; then
+ IMAGE_SUFFIX=$(__check_image_override $imagename)
+ if [ $? -ne 0 ]; then
+ echo -e $RED"Image setting from cmd line not consistent for $imagename."$ERED
+ ((IMAGE_ERR++))
+ fi
+ else
+ IMAGE_SUFFIX="none"
+ fi
+ # A function name is created from the app short name
+ # for example app short name 'ICS' -> produce the function
+ # name __ICS_imagesetup
+ # This function is called and is expected to exist in the imported
+ # file for the ics test functions
+ # The resulting function impl will call '__check_and_create_image_var' function
+ # with appropriate parameters
+ # If the image suffix is none, then the component decides the suffix
+ function_pointer="__"$imagename"_imagesetup"
+ $function_pointer $IMAGE_SUFFIX
+
+ function_pointer="__"$imagename"_test_requirements"
+ $function_pointer
+ fi
+ done
+
+ #Errors in image setting - exit
+ if [ $IMAGE_ERR -ne 0 ]; then
+ exit 1
+ fi
+
+ #Print a tables of the image settings
+ echo -e $BOLD"Images configured for start arg: "$START_ARG $EBOLD
+ column -t -s $'\t' $image_list_file | indent1
+
+ echo ""
+
+ #Set the SIM_GROUP var
+ echo -e $BOLD"Setting var to main dir of all container/simulator scripts"$EBOLD
+ if [ -z "$SIM_GROUP" ]; then
+ SIM_GROUP=$AUTOTEST_HOME/../simulator-group
+ if [ ! -d $SIM_GROUP ]; then
+ echo "Trying to set env var SIM_GROUP to dir 'simulator-group' in the nontrtric repo, but failed."
+ echo -e $RED"Please set the SIM_GROUP manually in the applicable $TEST_ENV_VAR_FILE"$ERED
+ exit 1
+ else
+ echo " SIM_GROUP auto set to: " $SIM_GROUP
+ fi
+ elif [ $SIM_GROUP = *simulator_group ]; then
+ echo -e $RED"Env var SIM_GROUP does not seem to point to dir 'simulator-group' in the repo, check $TEST_ENV_VAR_FILE"$ERED
+ exit 1
+ else
+ echo " SIM_GROUP env var already set to: " $SIM_GROUP
+ fi
+
+ echo ""
+
+ #Temp var to check for image pull errors
+ IMAGE_ERR=0
+
+ # Delete namespaces
+ echo -e $BOLD"Deleting namespaces"$EBOLD
+
+
+ if [ "$DELETE_KUBE_NAMESPACES" -eq 1 ]; then
+ test_env_namespaces=$(kubectl get ns --no-headers -o custom-columns=":metadata.name" -l autotest=engine) #Get list of ns created by the test env
+ if [ $? -ne 0 ]; then
+ echo " Cannot get list of namespaces...ignoring delete"
+ else
+ for test_env_ns in $test_env_namespaces; do
+ __kube_delete_namespace $test_env_ns
+ done
+ fi
+ else
+ echo " Namespace delete option not set"
+ fi
+ echo ""
+
+ # Delete containers
+ echo -e $BOLD"Deleting containers"$EBOLD
+
+ if [ "$DELETE_CONTAINERS" -eq 1 ]; then
+ echo " Stopping containers label 'nrttest_app'..."
+ docker stop $(docker ps -qa --filter "label=nrttest_app") 2> /dev/null
+ echo " Removing stopped containers..."
+ docker rm $(docker ps -qa --filter "label=nrttest_app") 2> /dev/null
+ else
+ echo " Contatiner delete option not set"
+ fi
+ echo ""
+
+ # The following sequence pull the configured images
+ echo -e $BOLD"Pulling configured images, if needed"$EBOLD
+ if [ ! -z "$IMAGE_REPO_ADR" ] && [ $IMAGE_REPO_POLICY == "local" ]; then
+ echo -e $YELLOW" Excluding all remote image check/pull when running with image repo: $IMAGE_REPO_ADR and image policy $IMAGE_REPO_POLICY"$EYELLOW
+ else
+ for imagename in $APP_SHORT_NAMES; do
+ __check_included_image $imagename
+ incl=$?
+ __check_project_image $imagename
+ proj=$?
+ if [ $incl -eq 0 ]; then
+ if [ $proj -eq 0 ]; then
+ START_ARG_MOD=$START_ARG
+ __check_image_local_override $imagename
+ if [ $? -eq 1 ]; then
+ START_ARG_MOD="local"
+ fi
+ else
+ START_ARG_MOD=$START_ARG
+ fi
+ __check_image_local_build $imagename
+ #No pull of images built locally
+ if [ $? -ne 0 ]; then
+ # A function name is created from the app short name
+ # for example app short name 'HTTPPROXY' -> produce the function
+ # name __HTTPPROXY_imagesetup
+ # This function is called and is expected to exist in the imported
+ # file for the httpproxy test functions
+ # The resulting function impl will call '__check_and_pull_image' function
+ # with appropriate parameters
+ function_pointer="__"$imagename"_imagepull"
+ $function_pointer $START_ARG_MOD $START_ARG
+ fi
+ else
+ echo -e $YELLOW" Excluding $imagename image from image check/pull"$EYELLOW
+ fi
+ done
+ fi
+
+ #Errors in image setting - exit
+ if [ $IMAGE_ERR -ne 0 ]; then
+ echo ""
+ echo "#################################################################################################"
+ echo -e $RED"One or more images could not be pulled or containers using the images could not be stopped/removed"$ERED
+ echo -e $RED"Or local image, overriding remote image, does not exist"$ERED
+ if [ $IMAGE_CATEGORY == "DEV" ]; then
+ echo ""
+ echo -e $RED"Note that SNAPSHOT and staging images may be purged from nexus after a certain period."$ERED
+ echo -e $RED"In addition, the image may not have been updated in the current release so no SNAPSHOT or staging image exists"$ERED
+ echo -e $RED"In these cases, switch to use a released image instead, use the flag '--use-release-image <App-short-name>'"$ERED
+ echo -e $RED"Use the 'App-short-name' for the applicable image from the above table: 'Images configured for start arg'."$ERED
+ fi
+ echo "#################################################################################################"
+ echo ""
+ exit 1
+ fi
+
+ echo ""
+
+ echo -e $BOLD"Building images needed for test"$EBOLD
+
+ for imagename in $APP_SHORT_NAMES; do
+ cd $AUTOTEST_HOME #Always reset to orig dir
+ __check_image_local_build $imagename
+ if [ $? -eq 0 ]; then
+ __check_included_image $imagename
+ if [ $? -eq 0 ]; then
+ # A function name is created from the app short name
+ # for example app short name 'MR' -> produce the function
+ # name __MR_imagebuild
+ # This function is called and is expected to exist in the imported
+ # file for the mr test functions
+ # The resulting function impl shall build the imagee
+ function_pointer="__"$imagename"_imagebuild"
+ $function_pointer
+
+ else
+ echo -e $YELLOW" Excluding image for app $imagename from image build"$EYELLOW
+ fi
+ fi
+ done
+
+ cd $AUTOTEST_HOME # Just to make sure...
+
+ echo ""
+
+ # Create a table of the images used in the script - from local repo
+ echo -e $BOLD"Local docker registry images used in this test script"$EBOLD
+
+ docker_tmp_file=./tmp/.docker-images-table
+ format_string="{{.Repository}}\\t{{.Tag}}\\t{{.CreatedSince}}\\t{{.Size}}\\t{{.CreatedAt}}"
+ echo -e "Application\tRepository\tTag\tCreated since\tSize\tCreated at" > $docker_tmp_file
+
+ for imagename in $APP_SHORT_NAMES; do
+ __check_included_image $imagename
+ if [ $? -eq 0 ]; then
+ # Only print image data if image repo is null, or if image repo is set and image is local
+ print_image_data=0
+ if [ -z "$IMAGE_REPO_ADR" ]; then
+ print_image_data=1
+ else
+ __check_image_local_build $imagename
+ if [ $? -eq 0 ]; then
+ print_image_data=1
+ fi
+ fi
+ if [ $print_image_data -eq 1 ]; then
+ # A function name is created from the app short name
+ # for example app short name 'MR' -> produce the function
+ # name __MR_imagebuild
+ # This function is called and is expected to exist in the imported
+ # file for the mr test functions
+ # The resulting function impl shall build the imagee
+ function_pointer="__"$imagename"_image_data"
+ $function_pointer "$format_string" $docker_tmp_file
+ fi
+ fi
+ done
+
+ column -t -s $'\t' $docker_tmp_file | indent1
+
+ echo ""
+
+ if [ ! -z "$IMAGE_REPO_ADR" ]; then
+
+ # Create a table of the images used in the script - from remote repo
+ echo -e $BOLD"Remote repo images used in this test script"$EBOLD
+ echo -e $YELLOW"-- Note: These image will be pulled when the container starts. Images not managed by the test engine --"$EYELLOW
+
+ docker_tmp_file=./tmp/.docker-images-table
+ format_string="{{.Repository}}\\t{{.Tag}}"
+ echo -e "Application\tRepository\tTag" > $docker_tmp_file
+
+ for imagename in $APP_SHORT_NAMES; do
+ __check_included_image $imagename
+ if [ $? -eq 0 ]; then
+ # Only print image data if image repo is null, or if image repo is set and image is local
+ __check_image_local_build $imagename
+ if [ $? -ne 0 ]; then
+ # A function name is created from the app short name
+ # for example app short name 'MR' -> produce the function
+ # name __MR_imagebuild
+ # This function is called and is expected to exist in the imported
+ # file for the mr test functions
+ # The resulting function impl shall build the imagee
+ function_pointer="__"$imagename"_image_data"
+ $function_pointer "$format_string" $docker_tmp_file
+ fi
+ fi
+ done
+
+ column -t -s $'\t' $docker_tmp_file | indent1
+
+ echo ""
+ fi
+
+ if [ $RUNMODE == "KUBE" ]; then
+
+ echo "================================================================================="
+ echo "================================================================================="
+
+ if [ -z "$IMAGE_REPO_ADR" ]; then
+ echo -e $YELLOW" The image pull policy is set to 'Never' - assuming a local image repo is available for all images"$EYELLOW
+ echo -e " This setting only works on single node clusters on the local machine"
+ echo -e " It does not work with multi-node clusters or remote clusters. "
+ export KUBE_IMAGE_PULL_POLICY="Never"
+ else
+ echo -e $YELLOW" The image pull policy is set to 'Always'"$EYELLOW
+ echo -e " This setting work on local clusters, multi-node clusters and remote cluster. "
+ echo -e " Only locally built images are managed. Remote images are always pulled from remote repos"
+ 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 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 "================================================================================="
+ echo ""
+ fi
+
+ echo -e $BOLD"======================================================="$EBOLD
+ echo -e $BOLD"== Common test setup completed - test script begins =="$EBOLD
+ echo -e $BOLD"======================================================="$EBOLD
+ echo ""
+
+ LOG_STAT_ARGS=""
+
+ for imagename in $APP_SHORT_NAMES; do
+ __check_included_image $imagename
+ retcode_i=$?
+ __check_prestarted_image $imagename
+ retcode_p=$?
+ if [ $retcode_i -eq 0 ] || [ $retcode_p -eq 0 ]; then
+ # A function name is created from the app short name
+ # for example app short name 'RICMSIM' -> produce the function
+ # name __RICSIM__initial_setup
+ # This function is called and is expected to exist in the imported
+ # file for the ricsim test functions
+ # The resulting function impl shall perform initial setup of port, host etc
+
+ function_pointer="__"$imagename"_initial_setup"
+ $function_pointer
+
+ function_pointer="__"$imagename"_statisics_setup"
+ LOG_STAT_ARGS=$LOG_STAT_ARGS" "$($function_pointer)
+ fi
+ done
+
+ if [ $COLLECT_RUNTIME_STATS -eq 1 ]; then
+ ../common/genstat.sh $RUNMODE $SECONDS $TESTLOGS/$ATC/stat_data.csv $LOG_STAT_ARGS &
+ COLLECT_RUNTIME_STATS_PID=$!
+ fi
+
+}
+
+# Function to print the test result, shall be the last cmd in a test script