#!/bin/bash
# ============LICENSE_START===============================================
-# Copyright (C) 2020 Nordix Foundation. All rights reserved.
+# Copyright (C) 2020-2023 Nordix Foundation. All rights reserved.
# ========================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
sdnc_suffix_tag="REMOTE_RELEASE_ONAP"
fi
done
- __check_and_create_image_var SDNC "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_IMAGE_BASE" "SDNC_A1_CONTROLLER_IMAGE_TAG" $sdnc_suffix_tag "$SDNC_DISPLAY_NAME"
- __check_and_create_image_var SDNC "SDNC_DB_IMAGE" "SDNC_DB_IMAGE_BASE" "SDNC_DB_IMAGE_TAG" REMOTE_PROXY "SDNC DB"
+ __check_and_create_image_var SDNC "SDNC_A1_CONTROLLER_IMAGE" "SDNC_A1_CONTROLLER_IMAGE_BASE" "SDNC_A1_CONTROLLER_IMAGE_TAG" $sdnc_suffix_tag "$SDNC_DISPLAY_NAME" ""
+ __check_and_create_image_var SDNC "SDNC_DB_IMAGE" "SDNC_DB_IMAGE_BASE" "SDNC_DB_IMAGE_TAG" REMOTE_PROXY "SDNC DB" ""
}
}
# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
-# This function is called for prestarted apps not managed by the test script.
+# This function is called for pre-started apps not managed by the test script.
__SDNC_kube_scale_zero_and_wait() {
echo -e " SDNC replicas kept as is"
}
-# Delete all kube resouces for the app
+# Delete all kube resources for the app
# This function is called for apps managed by the test script.
__SDNC_kube_delete_all() {
__kube_delete_all_resources $KUBE_SDNC_NAMESPACE autotest SDNC
# Store docker logs
# This function is called for apps managed by the test script.
-# args: <log-dir> <file-prexix>
+# args: <log-dir> <file-prefix>
__SDNC_store_docker_logs() {
if [ $RUNMODE == "KUBE" ]; then
- kubectl logs -l "autotest=SDNC" -n $KUBE_SDNC_NAMESPACE --tail=-1 > $1$2_SDNC.log 2>&1
- podname=$(kubectl get pods -n $KUBE_SDNC_NAMESPACE -l "autotest=SDNC" -o custom-columns=":metadata.name")
- kubectl exec -t -n $KUBE_SDNC_NAMESPACE $podname -- cat $SDNC_KARAF_LOG> $1$2_SDNC_karaf.log 2>&1
+ kubectl $KUBECONF logs -l "autotest=SDNC" -n $KUBE_SDNC_NAMESPACE --tail=-1 > $1$2_SDNC.log 2>&1
+ podname=$(kubectl $KUBECONF get pods -n $KUBE_SDNC_NAMESPACE -l "autotest=SDNC" -o custom-columns=":metadata.name")
+ kubectl $KUBECONF exec -t -n $KUBE_SDNC_NAMESPACE $podname -- cat $SDNC_KARAF_LOG> $1$2_SDNC_karaf.log 2>&1
else
docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $1$2_SDNC_karaf.log 2>&1
fi
use_sdnc_http
}
-# Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
+# Set app short-name, app name and namespace for logging runtime statistics of kubernetes pods or docker containers
# For docker, the namespace shall be excluded
-# This function is called for apps managed by the test script as well as for prestarted apps.
+# This function is called for apps managed by the test script as well as for pre-started apps.
# args: -
-__SDNC_statisics_setup() {
+__SDNC_statistics_setup() {
if [ $RUNMODE == "KUBE" ]; then
echo "SDNC $SDNC_APP_NAME $KUBE_SDNC_NAMESPACE"
else
fi
}
+# Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
+# args: -
+__SDNC_test_requirements() {
+ :
+}
+
#######################################################
# Set http as the protocol to use for all communication to SDNC
# args: <protocol> <internal-port> <external-port>
__sdnc_set_protocoll() {
echo -e $BOLD"$SDNC_DISPLAY_NAME protocol setting"$EBOLD
- echo -e " Using $BOLD http $EBOLD towards $SDNC_DISPLAY_NAME"
+ echo -e " Using $BOLD $1 $EBOLD towards $SDNC_DISPLAY_NAME"
## Access to SDNC
SDNC_SERVICE_PATH=$1"://"$SDNC_APP_NAME":"$2 # docker access, container->container and script->container via proxy
- SDNC_SERVICE_API_PATH=$1"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_APP_NAME":"$1$SDNC_API_URL
+ SDNC_SERVICE_API_PATH=$1"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_APP_NAME":"$2$SDNC_API_URL
if [ $RUNMODE == "KUBE" ]; then
SDNC_SERVICE_PATH=$1"://"$SDNC_APP_NAME.$KUBE_SDNC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
- SDNC_SERVICE_API_PATH=$1"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_APP_NAME.KUBE_SDNC_NAMESPACE":"$1$SDNC_API_URL
+ SDNC_SERVICE_API_PATH=$1"://"$SDNC_USER":"$SDNC_PWD"@"$SDNC_APP_NAME.$KUBE_SDNC_NAMESPACE":"$3$SDNC_API_URL
fi
echo ""
__check_included_image "SDNC"
retcode_i=$?
- # Check if app shall only be used by the testscipt
+ # Check if app shall only be used by the test script
__check_prestarted_image "SDNC"
retcode_p=$?
__check_included_image 'SDNC'
if [ $? -eq 1 ]; then
echo -e $RED"The SDNC A1 Controller app is not included in this test script"$ERED
- echo -e $RED"The Policy Agent will not be started"$ERED
+ echo -e $RED"The A1PMS will not be started"$ERED
exit
fi
return 0
}
-# Check the agent logs for WARNINGs and ERRORs
+# Check the sdnc logs for WARNINGs and ERRORs
# args: -
# (Function for test scripts)
check_sdnc_logs() {
controller_api_get_A1_policy_ids() {
__log_test_start $@
- ric_id=$3
- if [ $RUNMODE == "KUBE" ]; then
- ric_id=$(get_kube_sim_host $3)
- fi
+ ric_id=$(__find_sim_host $3)
paramError=1
if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
- url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies"
+ url="$ric_id/a1-p/policytypes/$4/policies"
paramError=0
elif [ $# -gt 2 ] && [ $2 == "STD" ]; then
- url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies"
+ url="$ric_id/A1-P/v1/policies"
paramError=0
fi
controller_api_get_A1_policy_type() {
__log_test_start $@
- ric_id=$3
- if [ $RUNMODE == "KUBE" ]; then
- ric_id=$(get_kube_sim_host $3)
- fi
+ ric_id=$(__find_sim_host $3)
paramError=1
if [ $# -gt 3 ] && [ $2 == "OSC" ]; then
- url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4"
+ url="$ric_id/a1-p/policytypes/$4"
paramError=0
fi
controller_api_delete_A1_policy() {
__log_test_start $@
- ric_id=$3
- if [ $RUNMODE == "KUBE" ]; then
- ric_id=$(get_kube_sim_host $3)
- fi
+ ric_id=$(__find_sim_host $3)
paramError=1
if [ $# -eq 5 ] && [ $2 == "OSC" ]; then
- url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
+ url="$ric_id/a1-p/policytypes/$4/policies/$UUID$5"
paramError=0
elif [ $# -eq 4 ] && [ $2 == "STD" ]; then
- url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
+ url="$ric_id/A1-P/v1/policies/$UUID$4"
paramError=0
fi
controller_api_put_A1_policy() {
__log_test_start $@
- ric_id=$3
- if [ $RUNMODE == "KUBE" ]; then
- ric_id=$(get_kube_sim_host $3)
- fi
+ ric_id=$(__find_sim_host $3)
paramError=1
if [ $# -eq 6 ] && [ $2 == "OSC" ]; then
- url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5"
+ url="$ric_id/a1-p/policytypes/$4/policies/$UUID$5"
body=$(sed 's/XXX/'${5}'/g' $6)
paramError=0
elif [ $# -eq 5 ] && [ $2 == "STD" ]; then
- url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4"
+ url="$ric_id/A1-P/v1/policies/$UUID$4"
body=$(sed 's/XXX/'${4}'/g' $5)
paramError=0
fi
controller_api_get_A1_policy_status() {
__log_test_start $@
- ric_id=$3
- if [ $RUNMODE == "KUBE" ]; then
- ric_id=$(get_kube_sim_host $3)
- fi
+ ric_id=$(__find_sim_host $3)
targetJson=""
paramError=1
if [ $# -ge 5 ] && [ $2 == "OSC" ]; then
- url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/a1-p/policytypes/$4/policies/$UUID$5/status"
+ url="$ric_id/a1-p/policytypes/$4/policies/$UUID$5/status"
if [ $# -gt 5 ]; then
- targetJson="{\"instance_status\":\"$6\""
- targetJson=$targetJson",\"has_been_deleted\":\"$7\""
- targetJson=$targetJson",\"created_at\":\"????\"}"
+ targetJson="{\"enforceStatus\":\"$6\""
+ targetJson=$targetJson",\"enforceReason\":\"$7\"}"
fi
paramError=0
elif [ $# -ge 4 ] && [ $2 == "STD" ]; then
- url="$RIC_SIM_HTTPX://$ric_id:$RIC_SIM_PORT/A1-P/v1/policies/$UUID$4/status"
+ url="$ric_id/A1-P/v1/policies/$UUID$4/status"
if [ $# -gt 4 ]; then
targetJson="{\"enforceStatus\":\"$5\""
if [ $# -eq 6 ]; then
__log_test_pass
return 0
-}
\ No newline at end of file
+}
+
+# Wait for http status on url
+# args: <response-code> <ric-id>
+# (Function for test scripts)
+controller_api_wait_for_status_ok() {
+ __log_conf_start $@
+
+ if [ $# -ne 2 ]; then
+ __print_err "<response-code> <ric-id> " $@
+ return 1
+ fi
+ ric_id=$(__find_sim_host $2)
+ url="$ric_id/"
+
+ TS_START=$SECONDS
+ while [ $(($TS_START+500)) -gt $SECONDS ]; do
+ echo -ne " Waiting for http status $1 on $url via sdnc, waited: $(($SECONDS-$TS_START))"$SAMELINE
+ res=$(__do_curl_to_controller getA1Policy "$url")
+ retcode=$?
+ status=${res:${#res}-3}
+ if [ $retcode -eq 0 ]; then
+ if [ $status -eq $1 ]; then
+ echo ""
+ __log_conf_ok
+ return 0
+ fi
+ fi
+ sleep 5
+ done
+ echo ""
+ __log_conf_fail_general
+ return 1
+}