# This is a script that contains container/service management functions and test functions for A1 Controller API
+################ Test engine functions ################
+
+# Create the image var used during the test
+# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
+# <image-tag-suffix> is present only for images with staging, snapshot,release tags
+__SDNC_imagesetup() {
+
+ sdnc_suffix_tag=$1
+
+ for oia_name in $ONAP_IMAGES_APP_NAMES; do
+ if [ "$oia_name" == "SDNC" ]; then
+ 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"
+
+}
+
+# Pull image from remote repo or use locally built image
+# arg: <pull-policy-override> <pull-policy-original>
+# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
+# <pull-policy-original> Shall be used for images that does not allow overriding
+# Both var may contain: 'remote', 'remote-remove' or 'local'
+__SDNC_imagepull() {
+ __check_and_pull_image $1 "$SDNC_DISPLAY_NAME" $SDNC_APP_NAME SDNC_A1_CONTROLLER_IMAGE
+ __check_and_pull_image $2 "SDNC DB" $SDNC_APP_NAME SDNC_DB_IMAGE
+}
+
+# Build image (only for simulator or interfaces stubs owned by the test environment)
+# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
+# <image-tag-suffix> is present only for images with staging, snapshot,release tags
+__SDNC_imagebuild() {
+ echo -e $RED" Image for app SDNC shall never be built"$ERED
+}
+
+# Generate a string for each included image using the app display name and a docker images format string
+# If a custom image repo is used then also the source image from the local repo is listed
+# arg: <docker-images-format-string> <file-to-append>
+__SDNC_image_data() {
+ echo -e "$SDNC_DISPLAY_NAME\t$(docker images --format $1 $SDNC_A1_CONTROLLER_IMAGE)" >> $2
+ if [ ! -z "$SDNC_A1_CONTROLLER_IMAGE_SOURCE" ]; then
+ echo -e "-- source image --\t$(docker images --format $1 $SDNC_A1_CONTROLLER_IMAGE_SOURCE)" >> $2
+ fi
+ echo -e "SDNC DB\t$(docker images --format $1 $SDNC_DB_IMAGE)" >> $2
+ if [ ! -z "$SDNC_DB_IMAGE_SOURCE" ]; then
+ echo -e "-- source image --\t$(docker images --format $1 $SDNC_DB_IMAGE_SOURCE)" >> $2
+ fi
+}
+
+# Scale kubernetes resources to zero
+# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
+# This function is called for apps fully managed by the test script
+__SDNC_kube_scale_zero() {
+ __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest SDNC
+}
+
+# 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.
+__SDNC_kube_scale_zero_and_wait() {
+ echo -e " SDNC replicas kept as is"
+}
+
+# Delete all kube resouces for the app
+# This function is called for apps managed by the test script.
+__SDNC_kube_delete_all() {
+ __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest SDNC
+}
+
+# Store docker logs
+# This function is called for apps managed by the test script.
+# args: <log-dir> <file-prexix>
+__SDNC_store_docker_logs() {
+ docker exec -t $SDNC_APP_NAME cat $SDNC_KARAF_LOG> $1$2_SDNC_karaf.log 2>&1
+}
+
+#######################################################
+
+
SDNC_HTTPX="http"
SDNC_HOST_NAME=$LOCALHOST_NAME
SDNC_PATH=$SDNC_HTTPX"://"$SDNC_HOST_NAME":"$SDNC_EXTERNAL_PORT
export SDNC_A1_TRUSTSTORE_PASSWORD
export SDNC_DB_APP_NAME
export SDNC_DB_IMAGE
+ export SDNC_USER
+ export SDNC_PWD
# Create service
input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"svc.yaml
__kube_create_instance service $SDNC_APP_NAME $input_yaml $output_yaml
# Create app
- input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"app.yaml
+ input_yaml=$SIM_GROUP"/"$SDNC_COMPOSE_DIR"/"$SDNC_KUBE_APP_FILE
output_yaml=$PWD/tmp/sdnc_app.yaml
__kube_create_instance app $SDNC_APP_NAME $input_yaml $output_yaml
export SDNC_EXTERNAL_SECURE_PORT
export SDNC_A1_TRUSTSTORE_PASSWORD
export DOCKER_SIM_NWNAME
+ export SDNC_DISPLAY_NAME
+ export SDNC_USER
+ export SDNC_PWD
- __start_container $SDNC_COMPOSE_DIR NODOCKERARGS 1 $SDNC_APP_NAME
+ __start_container $SDNC_COMPOSE_DIR $SDNC_COMPOSE_FILE NODOCKERARGS 1 $SDNC_APP_NAME
__check_service_start $SDNC_APP_NAME $SDNC_PATH$SDNC_ALIVE_URL
fi
}
+# Stop the sndc
+# args: -
+# args: -
+# (Function for test scripts)
+stop_sdnc() {
+ echo -e $BOLD"Stopping $SDNC_DISPLAY_NAME"$EBOLD
+
+ if [ $RUNMODE == "KUBE" ]; then
+ __log_conf_fail_not_supported " Cannot stop sndc in KUBE mode"
+ return 1
+ else
+ docker stop $SDNC_APP_NAME &> ./tmp/.dockererr
+ if [ $? -ne 0 ]; then
+ __print_err "Could not stop $SDNC_APP_NAME" $@
+ cat ./tmp/.dockererr
+ ((RES_CONF_FAIL++))
+ return 1
+ fi
+ fi
+ echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
+ echo ""
+ return 0
+}
+
+# Start a previously stopped sdnc
+# args: -
+# (Function for test scripts)
+start_stopped_sdnc() {
+ echo -e $BOLD"Starting (the previously stopped) $SDNC_DISPLAY_NAME"$EBOLD
+
+ if [ $RUNMODE == "KUBE" ]; then
+ __log_conf_fail_not_supported " Cannot restart sndc in KUBE mode"
+ return 1
+ else
+ docker start $SDNC_APP_NAME &> ./tmp/.dockererr
+ if [ $? -ne 0 ]; then
+ __print_err "Could not start (the stopped) $SDNC_APP_NAME" $@
+ cat ./tmp/.dockererr
+ ((RES_CONF_FAIL++))
+ return 1
+ fi
+ fi
+ __check_service_start $SDNC_APP_NAME $SDNC_PATH$SDNC_ALIVE_URL
+ if [ $? -ne 0 ]; then
+ return 1
+ fi
+ echo ""
+ return 0
+}
+
+# Check the agent logs for WARNINGs and ERRORs
+# args: -
+# (Function for test scripts)
+check_sdnc_logs() {
+ __check_container_logs "SDNC A1 Controller" $SDNC_APP_NAME $SDNC_KARAF_LOG WARN ERROR
+}
# Generic function to query the RICs via the A1-controller API.
# args: <operation> <url> [<body>]
payload="./tmp/.sdnc.payload.json"
echo "$json" > $payload
echo " FILE ($payload) : $json" >> $HTTPLOG
- curlString="curl -skw %{http_code} -X POST $SDNC_API_PATH$1 -H accept:application/json -H Content-Type:application/json --data-binary @$payload"
+ proxyflag=""
+ if [ $RUNMODE == "KUBE" ]; then
+ if [ ! -z "$KUBE_PROXY_PATH" ]; then
+ if [ $KUBE_PROXY_HTTPX == "http" ]; then
+ proxyflag=" --proxy $KUBE_PROXY_PATH"
+ else
+ proxyflag=" --proxy-insecure --proxy $KUBE_PROXY_PATH"
+ fi
+ fi
+ fi
+ curlString="curl -skw %{http_code} $proxyflag -X POST $SDNC_API_PATH$1 -H accept:application/json -H Content-Type:application/json --data-binary @$payload"
echo " CMD: "$curlString >> $HTTPLOG
res=$($curlString)
retcode=$?
echo " JSON: "$body >> $HTTPLOG
reply="./tmp/.sdnc-reply.json"
echo "$body" > $reply
- res=$(python3 ../common/extract_sdnc_reply.py $reply)
+ res=$(python3 ../common/extract_sdnc_reply.py $SDNC_RESPONSE_JSON_KEY $reply)
echo " EXTRACED BODY+CODE: "$res >> $HTTPLOG
echo "$res"
return 0