X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Fa1pms_api_functions.sh;h=a114134394ed481bcb759278a3859b04cca8bd38;hb=refs%2Fchanges%2F10%2F11110%2F1;hp=e74c3104bef2e09160833346f7779fee90347be8;hpb=f81090f8f5f1fd1a76bb9feab1f41f03252297c3;p=nonrtric.git diff --git a/test/common/a1pms_api_functions.sh b/test/common/a1pms_api_functions.sh index e74c3104..a1141343 100644 --- a/test/common/a1pms_api_functions.sh +++ b/test/common/a1pms_api_functions.sh @@ -1,7 +1,7 @@ #!/bin/bash # ============LICENSE_START=============================================== -# Copyright (C) 2021 Nordix Foundation. All rights reserved. +# Copyright (C) 2021-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. @@ -25,7 +25,7 @@ # arg: (selects staging, snapshot, release etc) # is present only for images with staging, snapshot,release tags __A1PMS_imagesetup() { - __check_and_create_image_var A1PMS "A1PMS_IMAGE" "A1PMS_IMAGE_BASE" "A1PMS_IMAGE_TAG" $1 "$A1PMS_DISPLAY_NAME" + __check_and_create_image_var A1PMS "A1PMS_IMAGE" "A1PMS_IMAGE_BASE" "A1PMS_IMAGE_TAG" $1 "$A1PMS_DISPLAY_NAME" "" } # Pull image from remote repo or use locally built image @@ -62,12 +62,12 @@ __A1PMS_kube_scale_zero() { } # 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. __A1PMS_kube_scale_zero_and_wait() { __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-policymanagementservice } -# 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. __A1PMS_kube_delete_all() { __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS @@ -75,7 +75,7 @@ __A1PMS_kube_delete_all() { # Store docker logs # This function is called for apps managed by the test script. -# args: +# args: __A1PMS_store_docker_logs() { if [ $RUNMODE == "KUBE" ]; then kubectl $KUBECONF logs -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_a1pms.log 2>&1 @@ -92,11 +92,11 @@ __A1PMS_initial_setup() { export A1PMS_SIDECAR_JWT_FILE="" } -# 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: - -__A1PMS_statisics_setup() { +__A1PMS_statistics_setup() { if [ $RUNMODE == "KUBE" ]; then echo "A1PMS $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE" else @@ -197,9 +197,6 @@ __export_a1pms_vars() { export A1PMS_CONFIG_CONFIGMAP_NAME=$A1PMS_APP_NAME"-config" export A1PMS_DATA_CONFIGMAP_NAME=$A1PMS_APP_NAME"-data" export A1PMS_PKG_NAME - export CONSUL_HOST - export CONSUL_INTERNAL_PORT - export CONFIG_BINDING_SERVICE export A1PMS_CONFIG_KEY export DOCKER_SIM_NWNAME export A1PMS_HOST_MNT_DIR @@ -241,7 +238,7 @@ start_a1pms() { __check_included_image "A1PMS" 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 "A1PMS" retcode_p=$? @@ -459,17 +456,17 @@ start_stopped_a1pms() { } -# Function to perpare the consul configuration according to the current simulator configuration -# args: SDNC|NOSDNC HEADER|NOHEADER +# Function to prepare the a1pms configuration according to the current simulator configuration +# args: SDNC|NOSDNC [ ] # (Function for test scripts) -prepare_consul_config() { - echo -e $BOLD"Prepare Consul config"$EBOLD +prepare_a1pms_config() { + echo -e $BOLD"Prepare A1PMS config"$EBOLD - echo " Writing consul config for "$A1PMS_APP_NAME" to file: "$2 + echo " Writing a1pms config for "$A1PMS_APP_NAME" to file: "$2 - if [ $# != 3 ]; then + if [ $# != 2 ] && [ $# != 4 ]; then ((RES_CONF_FAIL++)) - __print_err "need two args, SDNC|NOSDNC HEADER|NOHEADER" $@ + __print_err "need two or four args, SDNC|NOSDNC [ ]" $@ exit 1 fi @@ -494,23 +491,26 @@ prepare_consul_config() { config_json=$config_json"\n }" config_json=$config_json"\n ]," fi - - config_json=$config_json"\n \"streams_publishes\": {" - config_json=$config_json"\n \"dmaap_publisher\": {" - config_json=$config_json"\n \"type\": \"message-router\"," - config_json=$config_json"\n \"dmaap_info\": {" - config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\"" - config_json=$config_json"\n }" - config_json=$config_json"\n }" - config_json=$config_json"\n }," - config_json=$config_json"\n \"streams_subscribes\": {" - config_json=$config_json"\n \"dmaap_subscriber\": {" - config_json=$config_json"\n \"type\": \"message-router\"," - config_json=$config_json"\n \"dmaap_info\": {" - config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\"" - config_json=$config_json"\n }" - config_json=$config_json"\n }" - config_json=$config_json"\n }," + if [[ "$A1PMS_FEATURE_LEVEL" == *"NO-DMAAP"* ]]; then + : + else + config_json=$config_json"\n \"streams_publishes\": {" + config_json=$config_json"\n \"dmaap_publisher\": {" + config_json=$config_json"\n \"type\": \"message-router\"," + config_json=$config_json"\n \"dmaap_info\": {" + config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\"" + config_json=$config_json"\n }" + config_json=$config_json"\n }" + config_json=$config_json"\n }," + config_json=$config_json"\n \"streams_subscribes\": {" + config_json=$config_json"\n \"dmaap_subscriber\": {" + config_json=$config_json"\n \"type\": \"message-router\"," + config_json=$config_json"\n \"dmaap_info\": {" + config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\"" + config_json=$config_json"\n }" + config_json=$config_json"\n }" + config_json=$config_json"\n }," + fi config_json=$config_json"\n \"ric\": [" @@ -527,16 +527,35 @@ prepare_consul_config() { fi done fi + result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICMEDIATORSIM")].metadata.name}') + oranrics="" + if [ $? -eq 0 ] && [ ! -z "$result" ]; then + for im in $result; do + if [[ $im != *"-0" ]]; then + ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}') + rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE + oranrics=$oranrics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE + let ric_cntr=ric_cntr+1 + fi + done + fi if [ $ric_cntr -eq 0 ]; then echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW fi else - rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}}) + rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=a1sim" --filter "status=running" --format {{.Names}}) if [ $? -ne 0 ] || [ -z "$rics" ]; then echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED ((RES_CONF_FAIL++)) return 1 fi + oranrics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=orana1sim" --filter "status=running" --format {{.Names}}) + if [ $? -ne 0 ] || [ -z "$rics" ]; then + echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED + ((RES_CONF_FAIL++)) + return 1 + fi + rics="$rics $oranrics" fi cntr=0 for ric in $rics; do @@ -556,7 +575,23 @@ prepare_consul_config() { fi echo " Found a1 sim: "$ric_id config_json=$config_json"\n \"name\": \"$ric_id\"," - config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\"," + + xricfound=0 + for xric in $oranrics; do + if [ $xric == $ric ]; then + xricfound=1 + fi + done + if [ $xricfound -eq 0 ]; then + config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\"," + else + config_json=$config_json"\n \"baseUrl\": \"$RICMEDIATOR_SIM_HTTPX://$ric:$RICMEDIATOR_SIM_PORT\"," + fi + if [ ! -z "$3" ]; then + if [[ $ric == "$3"* ]]; then + config_json=$config_json"\n \"customAdapterClass\": \"$4\"," + fi + fi if [ $1 == "SDNC" ]; then config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\"," fi @@ -571,9 +606,7 @@ prepare_consul_config() { config_json=$config_json"\n ]" config_json=$config_json"\n}" - if [ $3 == "HEADER" ]; then - config_json="{\"config\":"$config_json"}" - fi + config_json="{\"config\":"$config_json"}" printf "$config_json">$2