X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Fcontroller_api_functions.sh;h=d4055018220a380d3a198c513a126afb5a736495;hb=be9a07faf8fbc1030404bbc71f409eb5e19736ba;hp=9e6017518c6541479f6a3ba14bd252da3c6745f7;hpb=1e539490bc37fed791895dd1f2f898caa3b0ca5c;p=nonrtric.git diff --git a/test/common/controller_api_functions.sh b/test/common/controller_api_functions.sh index 9e601751..d4055018 100644 --- a/test/common/controller_api_functions.sh +++ b/test/common/controller_api_functions.sh @@ -19,6 +19,78 @@ # 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: (selects staging, snapshot, release etc) +# 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: +# Shall be used for images allowing overriding. For example use a local image when test is started to use released images +# 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: (selects staging, snapshot, release etc) +# 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 +# arg: +__SDNC_image_data() { + echo -e "$SDNC_DISPLAY_NAME\t$(docker images --format $1 $SDNC_A1_CONTROLLER_IMAGE)" >> $2 + echo -e "SDNC DB\t$(docker images --format $1 $SDNC_DB_IMAGE)" >> $2 +} + +# 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: +__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 @@ -125,6 +197,8 @@ start_sdnc() { 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 @@ -132,7 +206,7 @@ start_sdnc() { __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 @@ -179,8 +253,11 @@ start_sdnc() { 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 @@ -188,7 +265,12 @@ start_sdnc() { 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: [] @@ -215,7 +297,13 @@ __do_curl_to_controller() { 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 "$CLUSTER_KUBE_PROXY_NODEPORT" ]; then + proxyflag=" --proxy http://localhost:$CLUSTER_KUBE_PROXY_NODEPORT" + 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=$? @@ -236,7 +324,7 @@ __do_curl_to_controller() { 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