#!/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.
# args: -
__A1PMS_initial_setup() {
use_a1pms_rest_http
+ export A1PMS_SIDECAR_JWT_FILE=""
}
# Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
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
# Create app
input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"app.yaml
output_yaml=$PWD/tmp/a1pmsapp.yaml
+ if [ -z "$A1PMS_SIDECAR_JWT_FILE" ]; then
+ cat $input_yaml | sed '/#A1PMS_JWT_START/,/#A1PMS_JWT_STOP/d' > $PWD/tmp/a1pmsapp_tmp.yaml
+ input_yaml=$PWD/tmp/a1pmsapp_tmp.yaml
+ fi
__kube_create_instance app $A1PMS_APP_NAME $input_yaml $output_yaml
fi
fi
else
echo " No files in mounted dir or dir does not exists"
+ mkdir db
fi
cd $curdir
# Function to perpare the consul configuration according to the current simulator configuration
-# args: SDNC|NOSDNC <output-file>
+# args: SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]
# (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
- if [ $# != 2 ]; then
+ if [ $# != 2 ] && [ $# != 4 ]; then
((RES_CONF_FAIL++))
- __print_err "need two args, SDNC|NOSDNC <output-file>" $@
+ __print_err "need two or four args, SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]" $@
exit 1
fi
echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
else
((RES_CONF_FAIL++))
- __print_err "need two args, SDNC|NOSDNC <output-file>" $@
+ __print_err "need three args, SDNC|NOSDNC <output-file> HEADER|NOHEADER" $@
exit 1
fi
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\": ["
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
ric_id=${ric%.*.*} #extract pod id from full hosthame
ric_id=$(echo "$ric_id" | tr '-' '_')
else
- if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
+ if [ $DOCKER_COMPOSE_VERSION == "V1" ]; then
ric_id=$ric
else
ric_id=$(echo "$ric" | tr '-' '_') #ric id still needs underscore as it is different from the container name
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
config_json=$config_json"\n ]"
config_json=$config_json"\n}"
- if [ $RUNMODE == "KUBE" ]; then
- config_json="{\"config\":"$config_json"}"
- fi
+ config_json="{\"config\":"$config_json"}"
printf "$config_json">$2
return 1
fi
inputJson=$(< $2)
- if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
- inputJson="{\"config\":"$inputJson"}"
- fi
+ # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
+ # inputJson="{\"config\":"$inputJson"}"
+ # fi
file="./tmp/.config.json"
echo $inputJson > $file
query="/v2/configuration"
body=${res:0:${#res}-3}
targetJson=$(< $2)
- targetJson="{\"config\":"$targetJson"}"
+ # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
+ # inputJson="{\"config\":"$inputJson"}"
+ # fi
echo "TARGET JSON: $targetJson" >> $HTTPLOG
res=$(python3 ../common/compare_json.py "$targetJson" "$body")
__log_test_pass
return 0
+}
+
+# args: <realm> <client-name> <client-secret>
+a1pms_configure_sec() {
+ export A1PMS_CREDS_GRANT_TYPE="client_credentials"
+ export A1PMS_CREDS_CLIENT_SECRET=$3
+ export A1PMS_CREDS_CLIENT_ID=$2
+ export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
+ export A1PMS_SIDECAR_MOUNT="/token-cache"
+ export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
+
+ export AUTHSIDECAR_APP_NAME
+ export AUTHSIDECAR_DISPLAY_NAME
}
\ No newline at end of file