blob: d635e81bfb598139c9c004c63293f0a239a83d20 [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/bin/bash
2
3# ============LICENSE_START===============================================
BjornMagnussonXA7d7cb5f2023-04-11 10:32:56 +02004# Copyright (C) 2021-2023 Nordix Foundation. All rights reserved.
JohnKeeney2f3b2682024-03-22 16:56:46 +00005# Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
BjornMagnussonXA80a92002020-03-19 14:31:06 +01006# ========================================================================
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18# ============LICENSE_END=================================================
19#
20
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010021# This is a script that contains management and test functions for A1PMS
BjornMagnussonXA80a92002020-03-19 14:31:06 +010022
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010023################ Test engine functions ################
24
25# Create the image var used during the test
26# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
27# <image-tag-suffix> is present only for images with staging, snapshot,release tags
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010028__A1PMS_imagesetup() {
raviteja.karumurif6dce272024-05-03 16:50:07 +010029 __check_and_create_image_var A1PMS "A1PMS_IMAGE" "A1PMS_IMAGE_BASE" "A1PMS_IMAGE_TAG" $1 "$A1PMS_DISPLAY_NAME" ""
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010030}
31
32# Pull image from remote repo or use locally built image
33# arg: <pull-policy-override> <pull-policy-original>
34# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
35# <pull-policy-original> Shall be used for images that does not allow overriding
36# Both var may contain: 'remote', 'remote-remove' or 'local'
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010037__A1PMS_imagepull() {
raviteja.karumurif6dce272024-05-03 16:50:07 +010038 __check_and_pull_image $1 "$A1PMS_DISPLAY_NAME" $A1PMS_APP_NAME A1PMS_IMAGE
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010039}
40
41# Build image (only for simulator or interfaces stubs owned by the test environment)
42# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
43# <image-tag-suffix> is present only for images with staging, snapshot,release tags
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010044__A1PMS_imagebuild() {
raviteja.karumurif6dce272024-05-03 16:50:07 +010045 echo -e $RED" Image for app A1PMS shall never be built"$ERED
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010046}
47
48# Generate a string for each included image using the app display name and a docker images format string
BjornMagnussonXA483ee332021-04-08 01:35:24 +020049# If a custom image repo is used then also the source image from the local repo is listed
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010050# arg: <docker-images-format-string> <file-to-append>
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010051__A1PMS_image_data() {
raviteja.karumurif6dce272024-05-03 16:50:07 +010052 echo -e "$A1PMS_DISPLAY_NAME\t$(docker images --format $1 $A1PMS_IMAGE)" >>$2
53 if [ ! -z "$A1PMS_IMAGE_SOURCE" ]; then
54 echo -e "-- source image --\t$(docker images --format $1 $A1PMS_IMAGE_SOURCE)" >>$2
55 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010056}
57
58# Scale kubernetes resources to zero
59# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
60# This function is called for apps fully managed by the test script
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010061__A1PMS_kube_scale_zero() {
raviteja.karumurif6dce272024-05-03 16:50:07 +010062 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010063}
64
65# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
BjornMagnussonXAd54225b2023-04-19 14:03:49 +020066# This function is called for pre-started apps not managed by the test script.
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010067__A1PMS_kube_scale_zero_and_wait() {
raviteja.karumurif6dce272024-05-03 16:50:07 +010068 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-policymanagementservice
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010069}
70
BjornMagnussonXAd54225b2023-04-19 14:03:49 +020071# Delete all kube resources for the app
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010072# This function is called for apps managed by the test script.
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010073__A1PMS_kube_delete_all() {
raviteja.karumurif6dce272024-05-03 16:50:07 +010074 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010075}
76
77# Store docker logs
78# This function is called for apps managed by the test script.
BjornMagnussonXAd54225b2023-04-19 14:03:49 +020079# args: <log-dir> <file-prefix>
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010080__A1PMS_store_docker_logs() {
raviteja.karumurif6dce272024-05-03 16:50:07 +010081 if [ $RUNMODE == "KUBE" ]; then
82 kubectl $KUBECONF logs -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 >$1$2_a1pms.log 2>&1
83 else
84 docker logs $A1PMS_APP_NAME >$1$2_a1pms.log 2>&1
85 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +010086}
87
88# Initial setup of protocol, host and ports
89# This function is called for apps managed by the test script.
90# args: -
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010091__A1PMS_initial_setup() {
raviteja.karumurif6dce272024-05-03 16:50:07 +010092 use_a1pms_rest_http
93 export A1PMS_SIDECAR_JWT_FILE=""
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010094}
95
BjornMagnussonXAd54225b2023-04-19 14:03:49 +020096# Set app short-name, app name and namespace for logging runtime statistics of kubernetes pods or docker containers
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +010097# For docker, the namespace shall be excluded
BjornMagnussonXAd54225b2023-04-19 14:03:49 +020098# This function is called for apps managed by the test script as well as for pre-started apps.
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +010099# args: -
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200100__A1PMS_statistics_setup() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100101 if [ $RUNMODE == "KUBE" ]; then
102 echo "A1PMS $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
103 else
104 echo "A1PMS $A1PMS_APP_NAME"
105 fi
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100106}
107
BjornMagnussonXAe60d04e2021-12-27 13:38:01 +0100108# Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
109# args: -
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100110__A1PMS_test_requirements() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100111 :
BjornMagnussonXAe60d04e2021-12-27 13:38:01 +0100112}
113
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100114#######################################################
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100115
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100116###########################
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100117### A1PMSs functions
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100118###########################
119
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100120# Set http as the protocol to use for all communication to the A1PMS
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100121# args: -
122# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100123use_a1pms_rest_http() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100124 __a1pms_set_protocoll "http" $A1PMS_INTERNAL_PORT $A1PMS_EXTERNAL_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100125}
126
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100127# Set https as the protocol to use for all communication to the A1PMS
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100128# args: -
129# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100130use_a1pms_rest_https() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100131 __a1pms_set_protocoll "https" $A1PMS_INTERNAL_SECURE_PORT $A1PMS_EXTERNAL_SECURE_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100132}
133
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100134# All calls to the a1pms will be directed to the a1pms dmaap interface over http from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100135# args: -
136# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100137use_a1pms_dmaap_http() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100138 echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
139 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
140 A1PMS_ADAPTER_TYPE="MR-HTTP"
141 echo ""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100142}
143
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100144# All calls to the a1pms will be directed to the a1pms dmaap interface over https from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100145# args: -
146# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100147use_a1pms_dmaap_https() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100148 echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
149 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
150 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
151 A1PMS_ADAPTER_TYPE="MR-HTTPS"
152 echo ""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100153}
154
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100155# Setup paths to svc/container for internal and external access
156# args: <protocol> <internal-port> <external-port>
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100157__a1pms_set_protocoll() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100158 echo -e $BOLD"$A1PMS_DISPLAY_NAME protocol setting"$EBOLD
159 echo -e " Using $BOLD $1 $EBOLD towards $A1PMS_DISPLAY_NAME"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100160
raviteja.karumurif6dce272024-05-03 16:50:07 +0100161 ## Access to Dmaap adapter
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100162
raviteja.karumurif6dce272024-05-03 16:50:07 +0100163 A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME":"$2 # docker access, container->container and script->container via proxy
164 if [ $RUNMODE == "KUBE" ]; then
165 A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
166 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100167
raviteja.karumurif6dce272024-05-03 16:50:07 +0100168 # A1PMS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
169 A1PMS_ADAPTER_TYPE="REST"
170 A1PMS_ADAPTER=$A1PMS_SERVICE_PATH
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100171
raviteja.karumurif6dce272024-05-03 16:50:07 +0100172 echo ""
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100173}
174
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100175# Make curl retries towards the a1pms for http response codes set in this env var, space separated list of codes
176A1PMS_RETRY_CODES=""
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100177
178#Save first worker node the pod is started on
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100179__A1PMS_WORKER_NODE=""
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100180
181# Export env vars for config files, docker compose and kube resources
182# args: PROXY|NOPROXY
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100183__export_a1pms_vars() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100184
raviteja.karumurif6dce272024-05-03 16:50:07 +0100185 export A1PMS_APP_NAME
186 export A1PMS_APP_NAME_ALIAS
187 export A1PMS_DISPLAY_NAME
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100188
raviteja.karumurif6dce272024-05-03 16:50:07 +0100189 export KUBE_NONRTRIC_NAMESPACE
190 export A1PMS_IMAGE
191 export A1PMS_INTERNAL_PORT
192 export A1PMS_INTERNAL_SECURE_PORT
193 export A1PMS_EXTERNAL_PORT
194 export A1PMS_EXTERNAL_SECURE_PORT
195 export A1PMS_CONFIG_MOUNT_PATH
196 export A1PMS_DATA_MOUNT_PATH
197 export A1PMS_CONFIG_CONFIGMAP_NAME=$A1PMS_APP_NAME"-config"
198 export A1PMS_DATA_CONFIGMAP_NAME=$A1PMS_APP_NAME"-data"
199 export A1PMS_PKG_NAME
200 export A1PMS_CONFIG_KEY
201 export DOCKER_SIM_NWNAME
202 export A1PMS_HOST_MNT_DIR
203 export A1PMS_CONFIG_FILE
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100204
raviteja.karumurif6dce272024-05-03 16:50:07 +0100205 export A1PMS_DATA_PV_NAME=$A1PMS_APP_NAME"-pv"
206 export A1PMS_DATA_PVC_NAME=$A1PMS_APP_NAME"-pvc"
207 ##Create a unique path for the pv each time to prevent a previous volume to be reused
208 export A1PMS_PV_PATH="a1pmsdata-"$(date +%s)
209 export A1PMS_CONTAINER_MNT_DIR
210 export HOST_PATH_BASE_DIR
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100211
raviteja.karumurif6dce272024-05-03 16:50:07 +0100212 if [ $1 == "PROXY" ]; then
213 export A1PMS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
214 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
215 if [ $A1PMS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$A1PMS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
216 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
217 else
218 echo " Configured with http proxy"
219 fi
220 else
221 export A1PMS_HTTP_PROXY_CONFIG_PORT=0
222 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=""
223 echo " Configured without http proxy"
224 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100225}
226
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100227# Start the ms
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100228# args: (docker) PROXY|NOPROXY <config-file>
229# args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100230# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100231start_a1pms() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100232 echo -e $BOLD"Starting $A1PMS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100233
raviteja.karumurif6dce272024-05-03 16:50:07 +0100234 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100235
raviteja.karumurif6dce272024-05-03 16:50:07 +0100236 # Check if app shall be fully managed by the test script
237 __check_included_image "A1PMS"
238 retcode_i=$?
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100239
raviteja.karumurif6dce272024-05-03 16:50:07 +0100240 # Check if app shall only be used by the test script
241 __check_prestarted_image "A1PMS"
242 retcode_p=$?
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100243
raviteja.karumurif6dce272024-05-03 16:50:07 +0100244 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
245 echo -e $RED"The $A1PMS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
246 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
247 exit
248 fi
249 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
250 echo -e $RED"The $A1PMS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
251 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
252 exit
253 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100254
raviteja.karumurif6dce272024-05-03 16:50:07 +0100255 if [ $retcode_p -eq 0 ]; then
256 echo -e " Using existing $A1PMS_APP_NAME deployment and service"
257 echo " Setting $A1PMS_APP_NAME replicas=1"
258 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
259 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
260 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100261
raviteja.karumurif6dce272024-05-03 16:50:07 +0100262 if [ $retcode_i -eq 0 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100263
raviteja.karumurif6dce272024-05-03 16:50:07 +0100264 echo -e " Creating $A1PMS_APP_NAME app and expose service"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100265
raviteja.karumurif6dce272024-05-03 16:50:07 +0100266 #Check if nonrtric namespace exists, if not create it
267 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100268
raviteja.karumurif6dce272024-05-03 16:50:07 +0100269 __export_a1pms_vars $1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100270
raviteja.karumurif6dce272024-05-03 16:50:07 +0100271 # Create config map for config
272 configfile=$PWD/tmp/$A1PMS_CONFIG_FILE
273 cp $2 $configfile
274 output_yaml=$PWD/tmp/a1pms-cfc.yaml
275 __kube_create_configmap $A1PMS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $configfile $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100276
raviteja.karumurif6dce272024-05-03 16:50:07 +0100277 # Create config map for data
278 data_json=$PWD/tmp/$A1PMS_DATA_FILE
279 if [ $# -lt 3 ]; then
280 #create empty dummy file
281 echo "{}" >$data_json
282 else
283 cp $3 $data_json
284 fi
285 output_yaml=$PWD/tmp/a1pms-cfd.yaml
286 __kube_create_configmap $A1PMS_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100287
raviteja.karumurif6dce272024-05-03 16:50:07 +0100288 ## Create pv
289 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pv.yaml
290 output_yaml=$PWD/tmp/a1pms-pv.yaml
291 __kube_create_instance pv $A1PMS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200292
raviteja.karumurif6dce272024-05-03 16:50:07 +0100293 ## Create pvc
294 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pvc.yaml
295 output_yaml=$PWD/tmp/a1pms-pvc.yaml
296 __kube_create_instance pvc $A1PMS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200297
raviteja.karumurif6dce272024-05-03 16:50:07 +0100298 # Create service
299 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"svc.yaml
300 output_yaml=$PWD/tmp/a1pmssvc.yaml
301 __kube_create_instance service $A1PMS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100302
raviteja.karumurif6dce272024-05-03 16:50:07 +0100303 # Create app
304 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"app.yaml
305 output_yaml=$PWD/tmp/a1pmsapp.yaml
306 if [ -z "$A1PMS_SIDECAR_JWT_FILE" ]; then
307 cat $input_yaml | sed '/#A1PMS_JWT_START/,/#A1PMS_JWT_STOP/d' >$PWD/tmp/a1pmsapp_tmp.yaml
308 input_yaml=$PWD/tmp/a1pmsapp_tmp.yaml
309 fi
310 __kube_create_instance app $A1PMS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100311
raviteja.karumurif6dce272024-05-03 16:50:07 +0100312 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100313
raviteja.karumurif6dce272024-05-03 16:50:07 +0100314 # Keep the initial worker node in case the pod need to be "restarted" - must be made to the same node due to a volume mounted on the host
315 if [ $retcode_i -eq 0 ]; then
316 __A1PMS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
317 if [ -z "$__A1PMS_WORKER_NODE" ]; then
318 echo -e $YELLOW" Cannot find worker node for pod for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
319 fi
320 else
321 echo -e $YELLOW" Persistency may not work for app $A1PMS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
322 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200323
raviteja.karumurif6dce272024-05-03 16:50:07 +0100324 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100325
raviteja.karumurif6dce272024-05-03 16:50:07 +0100326 else
327 __check_included_image 'A1PMS'
328 if [ $? -eq 1 ]; then
329 echo -e $RED"The A1PMS app is not included in this test script"$ERED
330 echo -e $RED"The A1PMS will not be started"$ERED
331 exit
332 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100333
raviteja.karumurif6dce272024-05-03 16:50:07 +0100334 curdir=$PWD
335 cd $SIM_GROUP
336 cd a1pms
337 cd $A1PMS_HOST_MNT_DIR
338 #cd ..
339 if [ -d db ]; then
340 if [ "$(ls -A $DIR)" ]; then
341 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
342 rm -rf db/* &>/dev/null
343 if [ $? -ne 0 ]; then
344 echo -e $RED" Cannot remove database files in: $PWD"$ERED
345 exit 1
346 fi
347 fi
348 else
349 echo " No files in mounted dir or dir does not exists"
raviteja.karumurib4600632024-09-27 12:05:52 +0100350 # The 'db' directory is created with full permissions (777) and is not removed at the end of the script.
351 mkdir -m 777 db
352 echo "Creating directory under $SIM_GROUP/a1pms/$A1PMS_HOST_MNT_DIR/ with 777 permission. This directory will need to be manually removed when tests complete."
raviteja.karumurif6dce272024-05-03 16:50:07 +0100353 fi
354 cd $curdir
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200355
raviteja.karumurif6dce272024-05-03 16:50:07 +0100356 __export_a1pms_vars $1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100357
raviteja.karumurif6dce272024-05-03 16:50:07 +0100358 dest_file=$SIM_GROUP/$A1PMS_COMPOSE_DIR/$A1PMS_HOST_MNT_DIR/application.yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100359
raviteja.karumurif6dce272024-05-03 16:50:07 +0100360 envsubst <$2 >$dest_file
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100361
raviteja.karumurif6dce272024-05-03 16:50:07 +0100362 __start_container $A1PMS_COMPOSE_DIR "" NODOCKERARGS 1 $A1PMS_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100363
raviteja.karumurif6dce272024-05-03 16:50:07 +0100364 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
365 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +0100366
raviteja.karumurif6dce272024-05-03 16:50:07 +0100367 __collect_endpoint_stats_image_info "A1PMS" $A1PMS_IMAGE
368 echo ""
369 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100370}
371
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100372# Stop the a1pms
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200373# args: -
374# args: -
375# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100376stop_a1pms() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100377 echo -e $BOLD"Stopping $A1PMS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200378
raviteja.karumurif6dce272024-05-03 16:50:07 +0100379 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200380
raviteja.karumurif6dce272024-05-03 16:50:07 +0100381 __check_prestarted_image "A1PMS"
382 if [ $? -eq 0 ]; then
383 echo -e $YELLOW" Persistency may not work for app $A1PMS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
384 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
385 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
386 return 0
387 fi
388 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
389 echo " Deleting the replica set - a new will be started when the app is started"
390 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
391 if [ $? -ne 0 ]; then
392 echo -e $RED" Could not delete replica set "$RED
393 ((RES_CONF_FAIL++))
394 return 1
395 fi
396 else
397 docker stop $A1PMS_APP_NAME &>./tmp/.dockererr
398 if [ $? -ne 0 ]; then
399 __print_err "Could not stop $A1PMS_APP_NAME" $@
400 cat ./tmp/.dockererr
401 ((RES_CONF_FAIL++))
402 return 1
403 fi
404 fi
405 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
406 echo ""
407 return 0
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200408}
409
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100410# Start a previously stopped a1pms
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200411# args: -
412# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100413start_stopped_a1pms() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100414 echo -e $BOLD"Starting (the previously stopped) $A1PMS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200415
raviteja.karumurif6dce272024-05-03 16:50:07 +0100416 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200417
raviteja.karumurif6dce272024-05-03 16:50:07 +0100418 __check_prestarted_image "A1PMS"
419 if [ $? -eq 0 ]; then
420 echo -e $YELLOW" Persistency may not work for app $A1PMS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
421 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
422 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
423 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
424 return 0
425 fi
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200426
raviteja.karumurif6dce272024-05-03 16:50:07 +0100427 # Tie the A1PMS to the same worker node it was initially started on
428 # A PVC of type hostPath is mounted to A1PMS, for persistent storage, so the A1PMS must always be on the node which mounted the volume
429 if [ -z "$__A1PMS_WORKER_NODE" ]; then
430 echo -e $RED" No initial worker node found for pod "$RED
431 ((RES_CONF_FAIL++))
432 return 1
433 else
434 echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__A1PMS_WORKER_NODE to deployment for $A1PMS_APP_NAME. Pod will always run on this worker node: $__A1PMS_WORKER_NODE"$BOLD
435 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
436 tmp=$(kubectl $KUBECONF patch deployment $A1PMS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__A1PMS_WORKER_NODE'"}}}}}')
437 if [ $? -ne 0 ]; then
438 echo -e $YELLOW" Cannot set nodeSelector to deployment for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
439 fi
440 __kube_scale deployment $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
441 fi
442 else
443 docker start $A1PMS_APP_NAME &>./tmp/.dockererr
444 if [ $? -ne 0 ]; then
445 __print_err "Could not start (the stopped) $A1PMS_APP_NAME" $@
446 cat ./tmp/.dockererr
447 ((RES_CONF_FAIL++))
448 return 1
449 fi
450 fi
451 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
452 if [ $? -ne 0 ]; then
453 return 1
454 fi
455 echo ""
456 return 0
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200457}
458
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200459# Function to prepare the a1pms configuration according to the current simulator configuration
BjornMagnussonXA7d7cb5f2023-04-11 10:32:56 +0200460# args: SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100461# (Function for test scripts)
BjornMagnussonXAf83c3622023-02-28 10:05:51 +0100462prepare_a1pms_config() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100463 echo -e $BOLD"Prepare A1PMS config"$EBOLD
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100464
raviteja.karumurif6dce272024-05-03 16:50:07 +0100465 echo " Writing a1pms config for "$A1PMS_APP_NAME" to file: "$2
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100466
raviteja.karumurif6dce272024-05-03 16:50:07 +0100467 if [ $# != 2 ] && [ $# != 4 ]; then
468 ((RES_CONF_FAIL++))
469 __print_err "need two or four args, SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]" $@
470 exit 1
471 fi
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100472
raviteja.karumurif6dce272024-05-03 16:50:07 +0100473 if [ $1 == "SDNC" ]; then
474 echo -e " Config$BOLD including SDNC$EBOLD configuration"
475 elif [ $1 == "NOSDNC" ]; then
476 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
477 else
478 ((RES_CONF_FAIL++))
479 __print_err "need three args, SDNC|NOSDNC <output-file> HEADER|NOHEADER" $@
480 exit 1
481 fi
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100482
raviteja.karumurif6dce272024-05-03 16:50:07 +0100483 config_json="\n {"
484 if [ $1 == "SDNC" ]; then
485 config_json=$config_json"\n \"controller\": ["
486 config_json=$config_json"\n {"
487 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
488 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
489 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
490 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
491 config_json=$config_json"\n }"
492 config_json=$config_json"\n ],"
493 fi
494 if [[ "$A1PMS_FEATURE_LEVEL" == *"NO-DMAAP"* ]]; then
495 :
496 else
497 config_json=$config_json"\n \"streams_publishes\": {"
498 config_json=$config_json"\n \"dmaap_publisher\": {"
499 config_json=$config_json"\n \"type\": \"message-router\","
500 config_json=$config_json"\n \"dmaap_info\": {"
501 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
502 config_json=$config_json"\n }"
503 config_json=$config_json"\n }"
504 config_json=$config_json"\n },"
505 config_json=$config_json"\n \"streams_subscribes\": {"
506 config_json=$config_json"\n \"dmaap_subscriber\": {"
507 config_json=$config_json"\n \"type\": \"message-router\","
508 config_json=$config_json"\n \"dmaap_info\": {"
509 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
510 config_json=$config_json"\n }"
511 config_json=$config_json"\n }"
512 config_json=$config_json"\n },"
513 fi
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100514
raviteja.karumurif6dce272024-05-03 16:50:07 +0100515 config_json=$config_json"\n \"ric\": ["
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100516
raviteja.karumurif6dce272024-05-03 16:50:07 +0100517 if [ $RUNMODE == "KUBE" ]; then
518 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
519 rics=""
520 ric_cntr=0
521 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
522 for im in $result; do
523 if [[ $im != *"-0" ]]; then
524 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
525 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
526 let ric_cntr=ric_cntr+1
527 fi
528 done
529 fi
530 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICMEDIATORSIM")].metadata.name}')
531 oranrics=""
532 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
533 for im in $result; do
534 if [[ $im != *"-0" ]]; then
535 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
536 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
537 oranrics=$oranrics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
538 let ric_cntr=ric_cntr+1
539 fi
540 done
541 fi
542 if [ $ric_cntr -eq 0 ]; then
543 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
544 fi
545 else
546 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=a1sim" --filter "status=running" --format {{.Names}})
547 oranrics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=orana1sim" --filter "status=running" --format {{.Names}})
rohithrajneesh931e0342023-11-06 18:02:22 +0000548
raviteja.karumurif6dce272024-05-03 16:50:07 +0100549 rics="$rics $oranrics"
rohithrajneesh931e0342023-11-06 18:02:22 +0000550
raviteja.karumurif6dce272024-05-03 16:50:07 +0100551 if [ $? -ne 0 ] || [ -z "$rics" ]; then
552 echo -e $RED" FAIL - the names of the running RIC Simulator or ORAN RIC cannot be retrieved." $ERED
553 ((RES_CONF_FAIL++))
554 exit 1
555 fi
556 fi
557 cntr=0
558 for ric in $rics; do
559 if [ $cntr -gt 0 ]; then
560 config_json=$config_json"\n ,"
561 fi
562 config_json=$config_json"\n {"
563 if [ $RUNMODE == "KUBE" ]; then
564 ric_id=${ric%.*.*} #extract pod id from full hosthame
565 ric_id=$(echo "$ric_id" | tr '-' '_')
566 else
567 ric_id=$(echo "$ric" | tr '-' '_') #ric var still needs underscore as it is different from the container name
568 fi
569 echo " Found a1 sim: "$ric
570 config_json=$config_json"\n \"name\": \"$ric_id\","
BjornMagnussonXA7d7cb5f2023-04-11 10:32:56 +0200571
raviteja.karumurif6dce272024-05-03 16:50:07 +0100572 xricfound=0
573 for xric in $oranrics; do
574 if [ $xric == $ric ]; then
575 xricfound=1
576 fi
577 done
578 if [ $xricfound -eq 0 ]; then
579 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
580 else
581 config_json=$config_json"\n \"baseUrl\": \"$RICMEDIATOR_SIM_HTTPX://$ric:$RICMEDIATOR_SIM_PORT\","
582 fi
583 if [ ! -z "$3" ]; then
584 if [[ $ric == "$3"* ]]; then
585 config_json=$config_json"\n \"customAdapterClass\": \"$4\","
586 fi
587 fi
588 if [ $1 == "SDNC" ]; then
589 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
590 fi
591 config_json=$config_json"\n \"managedElementIds\": ["
592 config_json=$config_json"\n \"me1_$ric_id\","
593 config_json=$config_json"\n \"me2_$ric_id\""
594 config_json=$config_json"\n ]"
595 config_json=$config_json"\n }"
596 let cntr=cntr+1
597 done
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100598
raviteja.karumurif6dce272024-05-03 16:50:07 +0100599 config_json=$config_json"\n ]"
600 config_json=$config_json"\n}"
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100601
raviteja.karumurif6dce272024-05-03 16:50:07 +0100602 config_json="{\"config\":"$config_json"}"
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100603
raviteja.karumurif6dce272024-05-03 16:50:07 +0100604 printf "$config_json" >$2
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100605
raviteja.karumurif6dce272024-05-03 16:50:07 +0100606 echo ""
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100607}
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200608
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100609# Load the the appl config for the a1pms into a config map
610a1pms_load_config() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100611 echo -e $BOLD"A1PMS - load config from "$EBOLD$1
612 data_json=$PWD/tmp/$A1PMS_DATA_FILE
613 cp $1 $data_json
614 output_yaml=$PWD/tmp/a1pms-cfd.yaml
615 __kube_create_configmap $A1PMS_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
616 echo ""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100617}
618
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100619# Turn on debug level tracing in the a1pms
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100620# args: -
621# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100622set_a1pms_debug() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100623 echo -e $BOLD"Setting a1pms debug logging"$EBOLD
624 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
625 result=$(__do_curl "$curlString")
626 if [ $? -ne 0 ]; then
627 __print_err "could not set debug mode" $@
628 ((RES_CONF_FAIL++))
629 return 1
630 fi
631 echo ""
632 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100633}
634
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100635# Turn on trace level tracing in the a1pms
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100636# args: -
637# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100638set_a1pms_trace() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100639 echo -e $BOLD"Setting a1pms trace logging"$EBOLD
640 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
641 result=$(__do_curl "$curlString")
642 if [ $? -ne 0 ]; then
643 __print_err "could not set trace mode" $@
644 ((RES_CONF_FAIL++))
645 return 1
646 fi
647 echo ""
648 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100649}
650
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100651# Perform curl retries when making direct call to the a1pms for the specified http response codes
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100652# Speace separated list of http response codes
653# args: [<response-code>]*
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100654use_a1pms_retries() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100655 echo -e $BOLD"Do curl retries to the a1pms REST inteface for these response codes:$@"$EBOLD
656 AGENT_RETRY_CODES=$@
657 echo ""
658 return
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100659}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100660
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100661# Check the a1pms logs for WARNINGs and ERRORs
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100662# args: -
663# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100664check_a1pms_logs() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100665 __check_container_logs "A1PMS" $A1PMS_APP_NAME $A1PMS_LOGPATH WARN ERR
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100666}
667
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100668#########################################################
669#### Test case functions A1 Policy management service
670#########################################################
671
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100672# This function compare the size, towards a target value, of a json array returned from <url> of the A1PMS.
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100673# This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
674# args: json:<url> <target-value> [<timeout-in-seconds]
675# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100676a1pms_equal() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100677 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >>$HTTPLOG
678 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
679 if [[ $1 == "json:"* ]]; then
680 if [ "$A1PMS_VERSION" == "V2" ]; then
681 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v2/" $1 "=" $2 $3
682 elif [ "$A1PMS_VERSION" == "V3" ]; then
683 echo "var test execution for V3"
684 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v1/" $1 "=" $2 $3
685 else
686 __var_test "A1PMS" $A1PMS_SERVICE_PATH"/" $1 "=" $2 $3
687 fi
688 return 0
689 fi
690 fi
691 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
692 return 1
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100693}
694
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100695# API Test function: GET /policies and V2 GET /v2/policy-instances
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100696# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*]
697# args(V2): <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <transient> <notification-url> <template-file>]*]
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100698# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100699a1pms_api_get_policies() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100700 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100701
raviteja.karumurif6dce272024-05-03 16:50:07 +0100702 if [ "$A1PMS_VERSION" == "V2" ]; then
703 paramError=0
704 variableParams=$(($# - 4))
705 if [ $# -lt 4 ]; then
706 paramError=1
707 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
708 paramError=1
709 elif [ $# -gt 5 ] && [ $(($variableParams % 7)) -ne 0 ]; then
710 paramError=1
711 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100712
raviteja.karumurif6dce272024-05-03 16:50:07 +0100713 if [ $paramError -ne 0 ]; then
714 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <transient> <notification-url> <template-file>]*]" $@
715 return 1
716 fi
717 else
718 paramError=0
719 variableParams=$(($# - 4))
720 if [ $# -lt 4 ]; then
721 paramError=1
722 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
723 paramError=1
724 elif [ $# -gt 5 ] && [ $(($variableParams % 5)) -ne 0 ]; then
725 paramError=1
726 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100727
raviteja.karumurif6dce272024-05-03 16:50:07 +0100728 if [ $paramError -ne 0 ]; then
729 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*]" $@
730 return 1
731 fi
732 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100733
raviteja.karumurif6dce272024-05-03 16:50:07 +0100734 queryparams=""
735 if [ "$A1PMS_VERSION" == "V2" ]; then
736 if [ $2 != "NORIC" ]; then
737 queryparams="?ric_id="$2
738 fi
739 if [ $3 != "NOSERVICE" ]; then
740 if [ -z $queryparams ]; then
741 queryparams="?service_id="$3
742 else
743 queryparams=$queryparams"&service_id="$3
744 fi
745 fi
746 if [ $4 != "NOTYPE" ]; then
747 if [ -z $queryparams ]; then
748 queryparams="?policytype_id="$4
749 else
750 queryparams=$queryparams"&policytype_id="$4
751 fi
752 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100753
raviteja.karumurif6dce272024-05-03 16:50:07 +0100754 query="/v2/policy-instances"$queryparams
755 res="$(__do_curl_to_api A1PMS GET $query)"
756 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100757
raviteja.karumurif6dce272024-05-03 16:50:07 +0100758 if [ $status -ne $1 ]; then
759 __log_test_fail_status_code $1 $status
760 return 1
761 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100762
raviteja.karumurif6dce272024-05-03 16:50:07 +0100763 if [ $# -gt 4 ]; then
764 body=${res:0:${#res}-3}
765 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
766 targetJson="["
767 else
768 targetJson="["
769 arr=(${@:5})
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100770
raviteja.karumurif6dce272024-05-03 16:50:07 +0100771 for ((i = 0; i < $(($# - 4)); i = i + 7)); do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100772
raviteja.karumurif6dce272024-05-03 16:50:07 +0100773 if [ "$targetJson" != "[" ]; then
774 targetJson=$targetJson","
775 fi
776 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i + 1]}\",\"service_id\":\"${arr[$i + 2]}\",\"policytype_id\":"
777 if [ "${arr[$i + 3]}" == "EMPTY" ]; then
778 targetJson=$targetJson"\"\","
779 else
780 targetJson=$targetJson"\"${arr[$i + 3]}\","
781 fi
782 targetJson=$targetJson"\"transient\":${arr[$i + 4]},\"status_notification_uri\":\"${arr[$i + 5]}\","
783 file="./tmp/.p.json"
784 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i + 6]} >$file
785 json=$(cat $file)
786 targetJson=$targetJson"\"policy_data\":"$json"}"
787 done
788 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100789
raviteja.karumurif6dce272024-05-03 16:50:07 +0100790 targetJson=$targetJson"]"
791 targetJson="{\"policies\": $targetJson}"
792 echo "TARGET JSON: $targetJson" >>$HTTPLOG
793 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100794
raviteja.karumurif6dce272024-05-03 16:50:07 +0100795 if [ $res -ne 0 ]; then
796 __log_test_fail_body
797 return 1
798 fi
799 fi
800 else
801 if [ $2 != "NORIC" ]; then
802 queryparams="?ric="$2
803 fi
804 if [ $3 != "NOSERVICE" ]; then
805 if [ -z $queryparams ]; then
806 queryparams="?service="$3
807 else
808 queryparams=$queryparams"&service="$3
809 fi
810 fi
811 if [ $4 != "NOTYPE" ]; then
812 if [ -z $queryparams ]; then
813 queryparams="?type="$4
814 else
815 queryparams=$queryparams"&type="$4
816 fi
817 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100818
raviteja.karumurif6dce272024-05-03 16:50:07 +0100819 query="/policies"$queryparams
820 res="$(__do_curl_to_api A1PMS GET $query)"
821 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100822
raviteja.karumurif6dce272024-05-03 16:50:07 +0100823 if [ $status -ne $1 ]; then
824 __log_test_fail_status_code $1 $status
825 return 1
826 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100827
raviteja.karumurif6dce272024-05-03 16:50:07 +0100828 if [ $# -gt 4 ]; then
829 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
830 targetJson="["
831 else
832 body=${res:0:${#res}-3}
833 targetJson="["
834 arr=(${@:5})
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100835
raviteja.karumurif6dce272024-05-03 16:50:07 +0100836 for ((i = 0; i < $(($# - 4)); i = i + 5)); do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100837
raviteja.karumurif6dce272024-05-03 16:50:07 +0100838 if [ "$targetJson" != "[" ]; then
839 targetJson=$targetJson","
840 fi
841 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i + 1]}\",\"service\":\"${arr[$i + 2]}\",\"type\":"
842 if [ "${arr[$i + 3]}" == "EMPTY" ]; then
843 targetJson=$targetJson"\"\","
844 else
845 targetJson=$targetJson"\"${arr[$i + 3]}\","
846 fi
847 file="./tmp/.p.json"
848 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i + 4]} >$file
849 json=$(cat $file)
850 targetJson=$targetJson"\"json\":"$json"}"
851 done
852 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100853
raviteja.karumurif6dce272024-05-03 16:50:07 +0100854 targetJson=$targetJson"]"
855 echo "TARGET JSON: $targetJson" >>$HTTPLOG
856 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100857
raviteja.karumurif6dce272024-05-03 16:50:07 +0100858 if [ $res -ne 0 ]; then
859 __log_test_fail_body
860 return 1
861 fi
862 fi
863 fi
864 __collect_endpoint_stats "A1PMS" 00 "GET" $A1PMS_API_PREFIX"/v2/policy-instances" $status
865 __log_test_pass
866 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100867
868}
869
raviteja.karumuri64755e02024-05-29 18:20:42 +0100870# API Test function: GET /policy, V2 GET /v2/policies/{policy_id} and V3 GET a1policymanagement/v1/policies/{policy_id}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100871# args: <response-code> <policy-id> [<template-file>]
872# args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100873# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100874a1pms_api_get_policy() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100875 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100876
raviteja.karumurif6dce272024-05-03 16:50:07 +0100877 if [ "$A1PMS_VERSION" == "V2" ]; then
878 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
879 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
880 return 1
881 fi
882 query="/v2/policies/$UUID$2"
raviteja.karumuri64755e02024-05-29 18:20:42 +0100883 elif [ "$A1PMS_VERSION" == "V3" ]; then
884 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
885 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
886 return 1
887 fi
888 query="/v1/policies/$UUID$2"
raviteja.karumurif6dce272024-05-03 16:50:07 +0100889 else
890 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
891 __print_err "<response-code> <policy-id> [<template-file>] " $@
892 return 1
893 fi
894 query="/policy?id=$UUID$2"
895 fi
896 res="$(__do_curl_to_api A1PMS GET $query)"
897 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100898
raviteja.karumurif6dce272024-05-03 16:50:07 +0100899 if [ $status -ne $1 ]; then
900 __log_test_fail_status_code $1 $status
901 return 1
902 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100903
raviteja.karumurif6dce272024-05-03 16:50:07 +0100904 if [ "$A1PMS_VERSION" == "V2" ]; then
905 if [ $# -eq 8 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100906
raviteja.karumurif6dce272024-05-03 16:50:07 +0100907 #Create a policy json to compare with
908 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100909
raviteja.karumurif6dce272024-05-03 16:50:07 +0100910 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
911 if [ $7 != "NOTRANSIENT" ]; then
912 targetJson=$targetJson", \"transient\":$7"
913 fi
914 if [ $6 != "NOTYPE" ]; then
915 targetJson=$targetJson", \"policytype_id\":\"$6\""
916 else
917 targetJson=$targetJson", \"policytype_id\":\"\""
918 fi
919 if [ $8 != "NOURL" ]; then
920 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
921 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100922
raviteja.karumurif6dce272024-05-03 16:50:07 +0100923 data=$(sed 's/XXX/'${2}'/g' $3)
924 targetJson=$targetJson", \"policy_data\":$data"
925 targetJson="{$targetJson}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100926
raviteja.karumurif6dce272024-05-03 16:50:07 +0100927 echo "TARGET JSON: $targetJson" >>$HTTPLOG
928 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
929 if [ $res -ne 0 ]; then
930 __log_test_fail_body
931 return 1
932 fi
933 fi
raviteja.karumuri64755e02024-05-29 18:20:42 +0100934 elif [ "$A1PMS_VERSION" == "V3" ]; then
935 if [ $# -eq 8 ]; then
936 #Create a policy json to compare with
937 body=${res:0:${#res}-3}
938 data=$(sed 's/XXX/'${2}'/g' $3)
939 targetJson=$data
940
941 echo "TARGET JSON: $targetJson" >>$HTTPLOG
942 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
943 if [ $res -ne 0 ]; then
944 __log_test_fail_body
945 return 1
946 fi
947 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +0100948 else
949 if [ $# -eq 3 ]; then
950 #Create a policy json to compare with
951 body=${res:0:${#res}-3}
952 file="./tmp/.p.json"
953 sed 's/XXX/'${2}'/g' $3 >$file
954 targetJson=$(<$file)
955 echo "TARGET JSON: $targetJson" >>$HTTPLOG
956 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
957 if [ $res -ne 0 ]; then
958 __log_test_fail_body
959 fi
960 fi
961 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100962
raviteja.karumuri64755e02024-05-29 18:20:42 +0100963 __collect_endpoint_stats "A1PMS" 01 "GET" ${A1PMS_API_PREFIX}${query} ${status}
raviteja.karumurif6dce272024-05-03 16:50:07 +0100964 __log_test_pass
965 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100966}
967
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100968# API Test function: PUT /policy and V2 PUT /policies
969# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
970# args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100971# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100972a1pms_api_put_policy() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100973 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100974
raviteja.karumuri64755e02024-05-29 18:20:42 +0100975 if [ "$A1PMS_VERSION" == "V2" ] || [ "$A1PMS_VERSION" == "V3" ]; then
raviteja.karumurif6dce272024-05-03 16:50:07 +0100976 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
977 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
978 return 1
979 fi
980 else
981 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
982 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
983 return 1
984 fi
985 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100986
raviteja.karumurif6dce272024-05-03 16:50:07 +0100987 count=0
988 max=1
989 serv=$2
990 ric=$3
991 pt=$4
992 pid=$5
993 trans=$6
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100994
raviteja.karumurif6dce272024-05-03 16:50:07 +0100995 if [ "$A1PMS_VERSION" == "V2" ]; then
996 noti=$7
997 temp=$8
998 if [ $# -eq 9 ]; then
999 max=$9
1000 fi
1001 else
1002 temp=$7
1003 if [ $# -eq 8 ]; then
1004 max=$8
1005 fi
1006 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001007
raviteja.karumurif6dce272024-05-03 16:50:07 +01001008 while [ $count -lt $max ]; do
1009 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001010
raviteja.karumurif6dce272024-05-03 16:50:07 +01001011 query="/v2/policies"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001012
raviteja.karumurif6dce272024-05-03 16:50:07 +01001013 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1014 if [ $trans != "NOTRANSIENT" ]; then
1015 inputJson=$inputJson", \"transient\":$trans"
1016 fi
1017 if [ $pt != "NOTYPE" ]; then
1018 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1019 else
1020 inputJson=$inputJson", \"policytype_id\":\"\""
1021 fi
1022 if [ $noti != "NOURL" ]; then
1023 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1024 fi
1025 file="./tmp/.p.json"
1026 data=$(sed 's/XXX/'${pid}'/g' $temp)
1027 inputJson=$inputJson", \"policy_data\":$data"
1028 inputJson="{$inputJson}"
1029 echo $inputJson >$file
1030 else
1031 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001032
raviteja.karumurif6dce272024-05-03 16:50:07 +01001033 if [ $pt != "NOTYPE" ]; then
1034 query=$query"&type=$pt"
1035 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001036
raviteja.karumurif6dce272024-05-03 16:50:07 +01001037 if [ $trans != NOTRANSIENT ]; then
1038 query=$query"&transient=$trans"
1039 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001040
raviteja.karumurif6dce272024-05-03 16:50:07 +01001041 file="./tmp/.p.json"
1042 sed 's/XXX/'${pid}'/g' $temp >$file
1043 fi
1044 res="$(__do_curl_to_api A1PMS PUT $query $file)"
1045 status=${res:${#res}-3}
1046 echo -ne " Executing "$count"("$max")${SAMELINE}"
1047 if [ $status -ne $1 ]; then
1048 echo " Executed "$count"?("$max")"
1049 __log_test_fail_status_code $1 $status
1050 return 1
1051 fi
1052 let pid=$pid+1
1053 let count=$count+1
1054 echo -ne " Executed "$count"("$max")${SAMELINE}"
1055 done
raviteja.karumuri64755e02024-05-29 18:20:42 +01001056 __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${query} ${status} ${max}
1057 echo ""
1058
1059 __log_test_pass
1060 return 0
1061}
1062
1063# API Test function: V3 PUT a1policymanagement/v1/policies
1064# args: <response-code> <policy-id> <template-file> [<count>]
1065# args(V2): <response-code> <policy-id> <template-file> [<count>]
1066# (Function for test scripts)
1067a1pms_api_put_policy_v3() {
1068 __log_test_start $@
1069
1070 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1071 __print_err "<response-code> <policy-id> <template-file> [<count>]" $@
1072 return 1
1073 fi
1074
1075 count=0
1076 max=1
1077 pid=$2
1078 temp=$3
1079
1080 if [ $# -eq 4 ]; then
1081 max=$4
1082 fi
1083
1084 while [ $count -lt $max ]; do
1085 query="/v1/policies/$UUID$pid"
1086 file="./tmp/.p_v3.json"
1087 let update_value=$pid+300
1088 data=$(sed 's/XXX/'${update_value}'/g' $temp)
1089 inputJson="$data"
1090 echo $inputJson >$file
1091 res="$(__do_curl_to_api A1PMS PUT $query $file)"
1092 status=${res:${#res}-3}
1093 echo -ne " Executing "$count"("$max")${SAMELINE}"
1094 if [ $status -ne $1 ]; then
1095 echo " Executed "$count"?("$max")"
1096 __log_test_fail_status_code $1 $status
1097 return 1
1098 fi
1099 let pid=$pid+1
1100 let count=$count+1
1101 echo -ne " Executed "$count"("$max")${SAMELINE}"
1102 done
1103 __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${query} ${status} ${max}
1104 echo ""
1105
1106 __log_test_pass
1107 return 0
1108}
1109
1110# API Test function: V£ POST a1policymanagement/v1/policies
1111# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
1112# args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
1113# (Function for test scripts)
1114a1pms_api_post_policy_v3() {
1115 __log_test_start $@
1116
1117 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1118 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
1119 return 1
1120 fi
1121
1122 count=0
1123 max=1
1124 serv=$2
1125 ric=$3
1126 pt=$4
1127 pid=$5
1128 trans=$6
1129 noti=$7
1130 temp=$8
1131 if [ $# -eq 9 ]; then
1132 max=$9
1133 fi
1134
1135 while [ $count -lt $max ]; do
1136 query="/v1/policies"
1137
1138 inputJson="\"nearRtRicId\":\"$ric\""
1139 if [ $pt != "NOTYPE" ]; then
1140 inputJson=$inputJson", \"policyTypeId\":\"$pt\""
1141 else
1142 inputJson=$inputJson", \"policyTypeId\":\"\""
1143 fi
1144 if [ $serv != "NOSERVICE" ]; then
1145 inputJson=$inputJson", \"serviceId\":\"$serv\""
1146 fi
1147 if [ $noti != "NONOTIFYURL" ]; then
1148 inputJson=$inputJson", \"statusNotificationUri\":\"$noti\""
1149 fi
1150 if [ $trans != "NOTRANSIENT" ]; then
1151 inputJson=$inputJson", \"transient\":\"$trans\""
1152 fi
1153 file="./tmp/.p.json"
1154 data=$(sed 's/XXX/'${pid}'/g' $temp)
1155 inputJson=$inputJson", \"policyObject\":$data"
1156 inputJson=$inputJson", \"policyId\":\"$UUID$pid\""
1157 inputJson="{$inputJson}"
1158 echo $inputJson >$file
1159 res="$(__do_curl_to_api A1PMS POST $query $file)"
1160 status=${res:${#res}-3}
1161 echo -ne " Executing "$count"("$max")${SAMELINE}"
1162 if [ $status -ne $1 ]; then
1163 echo " Executed "$count"?("$max")"
1164 __log_test_fail_status_code $1 $status
1165 return 1
1166 fi
1167 let pid=$pid+1
1168 let count=$count+1
1169 echo -ne " Executed "$count"("$max")${SAMELINE}"
1170 done
1171 __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${A1PMS_VERSION} ${status} ${max}
raviteja.karumurif6dce272024-05-03 16:50:07 +01001172 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001173
raviteja.karumurif6dce272024-05-03 16:50:07 +01001174 __log_test_pass
1175 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001176}
1177
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001178# API Test function: PUT /policy and V2 PUT /policies, to run in batch
1179# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1180# args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001181# (Function for test scripts)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001182
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001183a1pms_api_put_policy_batch() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001184 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001185
raviteja.karumurif6dce272024-05-03 16:50:07 +01001186 if [ "$A1PMS_VERSION" == "V2" ]; then
1187 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1188 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1189 return 1
1190 fi
1191 else
1192 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1193 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1194 return 1
1195 fi
1196 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001197
raviteja.karumurif6dce272024-05-03 16:50:07 +01001198 count=0
1199 max=1
1200 serv=$2
1201 ric=$3
1202 pt=$4
1203 pid=$5
1204 trans=$6
1205 if [ "$A1PMS_VERSION" == "V2" ]; then
1206 noti=$7
1207 temp=$8
1208 if [ $# -eq 9 ]; then
1209 max=$9
1210 fi
1211 else
1212 temp=$7
1213 if [ $# -eq 8 ]; then
1214 max=$8
1215 fi
1216 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001217
raviteja.karumurif6dce272024-05-03 16:50:07 +01001218 ARR=""
1219 while [ $count -lt $max ]; do
1220 if [ "$A1PMS_VERSION" == "V2" ]; then
1221 query="/v2/policies"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001222
raviteja.karumurif6dce272024-05-03 16:50:07 +01001223 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1224 if [ $trans != "NOTRANSIENT" ]; then
1225 inputJson=$inputJson", \"transient\":$trans"
1226 fi
1227 if [ $pt != "NOTYPE" ]; then
1228 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1229 else
1230 inputJson=$inputJson", \"policytype_id\":\"\""
1231 fi
1232 if [ $noti != "NOURL" ]; then
1233 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1234 fi
1235 file="./tmp/.p.json"
1236 data=$(sed 's/XXX/'${pid}'/g' $temp)
1237 inputJson=$inputJson", \"policy_data\":$data"
1238 inputJson="{$inputJson}"
1239 echo $inputJson >$file
1240 else
1241 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001242
raviteja.karumurif6dce272024-05-03 16:50:07 +01001243 if [ $pt != "NOTYPE" ]; then
1244 query=$query"&type=$pt"
1245 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001246
raviteja.karumurif6dce272024-05-03 16:50:07 +01001247 if [ $trans != NOTRANSIENT ]; then
1248 query=$query"&transient=$trans"
1249 fi
1250 file="./tmp/.p.json"
1251 sed 's/XXX/'${pid}'/g' $temp >$file
1252 fi
1253 res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)"
1254 status=${res:${#res}-3}
1255 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001256
raviteja.karumurif6dce272024-05-03 16:50:07 +01001257 if [ $status -ne 200 ]; then
1258 echo " Requested(batch) "$count"?("$max")"
1259 __log_test_fail_status_code 200 $status
1260 return 1
1261 fi
1262 cid=${res:0:${#res}-3}
1263 ARR=$ARR" "$cid
1264 let pid=$pid+1
1265 let count=$count+1
1266 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1267 done
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001268
raviteja.karumurif6dce272024-05-03 16:50:07 +01001269 echo ""
1270 count=0
1271 for cid in $ARR; do
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001272
raviteja.karumurif6dce272024-05-03 16:50:07 +01001273 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1274 status=${res:${#res}-3}
1275 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001276
raviteja.karumurif6dce272024-05-03 16:50:07 +01001277 if [ $status -ne $1 ]; then
1278 echo " Accepted(batch) "$count"?("$max")"
1279 __log_test_fail_status_code $1 $status
1280 return 1
1281 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001282
raviteja.karumurif6dce272024-05-03 16:50:07 +01001283 let count=$count+1
1284 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1285 done
1286 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001287
raviteja.karumurif6dce272024-05-03 16:50:07 +01001288 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001289
raviteja.karumurif6dce272024-05-03 16:50:07 +01001290 __log_test_pass
1291 return 0
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001292}
1293
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001294# API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001295# args: <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <template-file> <count-per-ric> <number-of-threads>
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001296# args(V2): <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001297# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001298a1pms_api_put_policy_parallel() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001299 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001300
raviteja.karumurif6dce272024-05-03 16:50:07 +01001301 if [ "$A1PMS_VERSION" == "V2" ]; then
1302 if [ $# -ne 11 ]; then
1303 __print_err "These all arguments needed <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>" $@
1304 return 1
1305 fi
1306 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001307
raviteja.karumurif6dce272024-05-03 16:50:07 +01001308 resp_code=$1
1309 shift
1310 serv=$1
1311 shift
1312 ric_base=$1
1313 shift
1314 num_rics=$1
1315 shift
1316 type=$1
1317 shift
1318 start_id=$1
1319 shift
1320 transient=$1
1321 shift
1322 if [ "$A1PMS_VERSION" == "V2" ]; then
1323 noti=$1
1324 shift
1325 else
1326 noti=""
1327 fi
1328 template=$1
1329 shift
1330 count=$1
1331 shift
1332 pids=$1
1333 shift
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001334
raviteja.karumurif6dce272024-05-03 16:50:07 +01001335 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1336 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1337 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1338 echo " Info - will execute over a1pms REST"
1339 fi
1340 if [ "$A1PMS_VERSION" == "V2" ]; then
1341 if [ $serv == "NOSERVICE" ]; then
1342 serv=""
1343 fi
1344 query="$A1PMS_API_PREFIX/v2/policies"
1345 else
1346 if [ $serv == "NOSERVICE" ]; then
1347 serv=""
1348 fi
1349 query="/policy?service=$serv"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001350
raviteja.karumurif6dce272024-05-03 16:50:07 +01001351 if [ $type != "NOTYPE" ]; then
1352 query=$query"&type=$type"
1353 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001354
raviteja.karumurif6dce272024-05-03 16:50:07 +01001355 if [ $transient != NOTRANSIENT ]; then
1356 query=$query"&transient=$transient"
1357 fi
1358 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001359
raviteja.karumurif6dce272024-05-03 16:50:07 +01001360 urlbase=${A1PMS_ADAPTER}${query}
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001361
raviteja.karumurif6dce272024-05-03 16:50:07 +01001362 httpproxy="NOPROXY"
1363 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1364 httpproxy=$KUBE_PROXY_PATH
1365 fi
1366
1367 for ((i = 1; i <= $pids; i++)); do
1368 uuid=$UUID
1369 if [ -z "$uuid" ]; then
1370 uuid="NOUUID"
1371 fi
1372 echo "" >"./tmp/.pid${i}.res.txt"
1373 if [ "$A1PMS_VERSION" == "V2" ]; then
1374 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1375 else
1376 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1377 fi
1378 echo $i
1379 done | xargs -n 1 -I{} -P $pids bash -c '{
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001380 arg=$(echo {})
1381 echo " Parallel process $arg started"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001382 tmp=$(< "./tmp/.pid${arg}.txt")
1383 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001384 }'
raviteja.karumurif6dce272024-05-03 16:50:07 +01001385 msg=""
1386 for ((i = 1; i <= $pids; i++)); do
1387 file="./tmp/.pid${i}.res.txt"
1388 tmp=$(<$file)
1389 if [ -z "$tmp" ]; then
1390 echo " Process $i : unknown result (result file empty"
1391 msg="failed"
1392 else
1393 res=${tmp:0:1}
1394 if [ $res == "0" ]; then
1395 echo " Process $i : OK - "${tmp:1}
1396 else
1397 echo " Process $i : failed - "${tmp:1}
1398 msg="failed"
1399 fi
1400 fi
1401 done
1402 if [ -z $msg ]; then
1403 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count * $num_rics))
1404 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1405 return 0
1406 fi
1407 __log_test_fail_general "One of more processes failed to execute"
1408 return 1
1409}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001410
raviteja.karumurif6dce272024-05-03 16:50:07 +01001411# API Test function: V3 POST /policies, to run in i parallel for a number of rics
1412# args: <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <template-file> <count-per-ric> <number-of-threads>
1413# args(V3): <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>
1414# (Function for test scripts)
1415a1pms_api_post_policy_parallel() {
1416 __log_test_start $@
1417
1418 if [ $# -ne 11 ]; then
1419 __print_err "These all arguments needed <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>" $@
1420 return 1
1421 fi
1422
1423 resp_code=$1
1424 shift
1425 serv=$1
1426 shift
1427 ric_base=$1
1428 shift
1429 num_rics=$1
1430 shift
1431 type=$1
1432 shift
1433 start_id=$1
1434 shift
1435 transient=$1
1436 shift
1437 noti=$1
1438 shift
1439 template=$1
1440 shift
1441 count=$1
1442 shift
1443 pids=$1
1444 shift
1445
1446 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1447 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1448 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1449 echo " Info - will execute over a1pms REST"
1450 fi
1451
1452 if [ $serv == "NOSERVICE" ]; then
1453 serv=""
1454 fi
1455 query="$A1PMS_API_PREFIX/v1/policies"
1456
1457 urlbase=${A1PMS_ADAPTER}${query}
1458
1459 httpproxy="NOPROXY"
1460 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1461 httpproxy=$KUBE_PROXY_PATH
1462 fi
1463
1464 for ((i = 1; i <= $pids; i++)); do
1465 uuid=$UUID
1466 if [ -z "$uuid" ]; then
1467 uuid="NOUUID"
1468 fi
1469 echo "" >"./tmp/.pid${i}.res.txt"
1470 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1471 echo $i
1472 done | xargs -n 1 -I{} -P $pids bash -c '{
1473 arg=$(echo {})
1474 echo " Parallel process $arg started"
1475 tmp=$(< "./tmp/.pid${arg}.txt")
1476 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1477 }'
1478 msg=""
1479 for ((i = 1; i <= $pids; i++)); do
1480 file="./tmp/.pid${i}.res.txt"
1481 tmp=$(<$file)
1482 if [ -z "$tmp" ]; then
1483 echo " Process $i : unknown result (result file empty"
1484 msg="failed"
1485 else
1486 res=${tmp:0:1}
1487 if [ $res == "0" ]; then
1488 echo " Process $i : OK - "${tmp:1}
1489 else
1490 echo " Process $i : failed - "${tmp:1}
1491 msg="failed"
1492 fi
1493 fi
1494 done
1495 if [ -z $msg ]; then
1496 __collect_endpoint_stats "A1PMS" 02 "POST" $A1PMS_API_PREFIX"/v1/policies" $resp_code $(($count * $num_rics))
1497 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1498 return 0
1499 fi
1500 __log_test_fail_general "One of more processes failed to execute"
1501 return 1
1502}
1503
1504# API Test function: V3 PUT /policies, to run in i parallel for a number of rics
1505# args: <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <template-file> <count-per-ric> <number-of-threads> <policy-ids-file-path>
1506# args(V3): <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads> <policy-ids-file-path>
1507# (Function for test scripts)
1508a1pms_api_update_policy_parallel() {
1509 __log_test_start $@
1510
1511 if [ $# -ne 12 ]; then
1512 __print_err "These all arguments needed <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads> <policy-ids-file-path>" $@
1513 return 1
1514 fi
1515
1516 resp_code=$1
1517 shift
1518 serv=$1
1519 shift
1520 ric_base=$1
1521 shift
1522 num_rics=$1
1523 shift
1524 type=$1
1525 shift
1526 start_id=$1
1527 shift
1528 transient=$1
1529 shift
1530 noti=$1
1531 shift
1532 template=$1
1533 shift
1534 count=$1
1535 shift
1536 pids=$1
1537 shift
1538 policy_ids_file_path=$1
1539 shift
1540
1541 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1542 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1543 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1544 echo " Info - will execute over a1pms REST"
1545 fi
1546
1547 if [ $serv == "NOSERVICE" ]; then
1548 serv=""
1549 fi
1550 query="$A1PMS_API_PREFIX/v1/policies"
1551
1552 urlbase=${A1PMS_ADAPTER}${query}
1553
1554 httpproxy="NOPROXY"
1555 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1556 httpproxy=$KUBE_PROXY_PATH
1557 fi
1558
1559 for ((i = 1; i <= $pids; i++)); do
1560 uuid=$UUID
1561 if [ -z "$uuid" ]; then
1562 uuid="NOUUID"
1563 fi
1564 echo "" >"./tmp/.pid${i}.res.txt"
1565 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy $policy_ids_file_path >"./tmp/.pid${i}.txt"
1566 echo $i
1567 done | xargs -n 1 -I{} -P $pids bash -c '{
1568 arg=$(echo {})
1569 echo " Parallel process $arg started"
1570 tmp=$(< "./tmp/.pid${arg}.txt")
1571 python3 ../common/update_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1572 }'
1573 msg=""
1574 for ((i = 1; i <= $pids; i++)); do
1575 file="./tmp/.pid${i}.res.txt"
1576 tmp=$(<$file)
1577 if [ -z "$tmp" ]; then
1578 echo " Process $i : unknown result (result file empty"
1579 msg="failed"
1580 else
1581 res=${tmp:0:1}
1582 if [ $res == "0" ]; then
1583 echo " Process $i : OK - "${tmp:1}
1584 else
1585 echo " Process $i : failed - "${tmp:1}
1586 msg="failed"
1587 fi
1588 fi
1589 done
1590 if [ -z $msg ]; then
1591 __collect_endpoint_stats "A1PMS" 02 "POST" $A1PMS_API_PREFIX"/v1/policies" $resp_code $(($count * $num_rics))
1592 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1593 return 0
1594 fi
1595 __log_test_fail_general "One of more processes failed to execute"
1596 return 1
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001597}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001598
raviteja.karumuri85d61ba2024-06-12 13:46:45 +01001599# API Test function: DELETE /policy, V2 DELETE /v2/policies/{policy_id} and V3 DELETE a1policymanagement/v1/policies/{policy_id}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001600# args: <response-code> <policy-id> [count]
1601# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001602a1pms_api_delete_policy() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001603 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001604
raviteja.karumurif6dce272024-05-03 16:50:07 +01001605 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1606 __print_err "<response-code> <policy-id> [count]" $@
1607 return 1
1608 fi
1609
1610 count=0
1611 max=1
1612
1613 if [ $# -eq 3 ]; then
1614 max=$3
1615 fi
1616
1617 pid=$2
1618
1619 while [ $count -lt $max ]; do
1620 if [ "$A1PMS_VERSION" == "V2" ]; then
1621 query="/v2/policies/"$UUID$pid
raviteja.karumuri64755e02024-05-29 18:20:42 +01001622 elif [ "$A1PMS_VERSION" == "V3" ]; then
1623 query="/v1/policies/"$UUID$pid
raviteja.karumurif6dce272024-05-03 16:50:07 +01001624 else
1625 query="/policy?id="$UUID$pid
1626 fi
1627 res="$(__do_curl_to_api A1PMS DELETE $query)"
1628 status=${res:${#res}-3}
raviteja.karumuri64755e02024-05-29 18:20:42 +01001629 echo -ne " Executing "${count}"("${max}")${SAMELINE}"
raviteja.karumurif6dce272024-05-03 16:50:07 +01001630
1631 if [ $status -ne $1 ]; then
raviteja.karumuri64755e02024-05-29 18:20:42 +01001632 echo " Executed "${count}"?("${max}")"
raviteja.karumurif6dce272024-05-03 16:50:07 +01001633 __log_test_fail_status_code $1 $status
1634 return 1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001635 fi
1636
raviteja.karumurif6dce272024-05-03 16:50:07 +01001637 let pid=$pid+1
1638 let count=$count+1
raviteja.karumuri64755e02024-05-29 18:20:42 +01001639 echo -ne " Executed "${count}"("${max}")${SAMELINE}"
raviteja.karumurif6dce272024-05-03 16:50:07 +01001640 done
raviteja.karumuri64755e02024-05-29 18:20:42 +01001641 __collect_endpoint_stats "A1PMS" 03 "DELETE" ${A1PMS_API_PREFIX}${query} ${status} ${max}
raviteja.karumurif6dce272024-05-03 16:50:07 +01001642 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001643
raviteja.karumurif6dce272024-05-03 16:50:07 +01001644 __log_test_pass
1645 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001646}
1647
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001648# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001649# args: <response-code> <policy-id> [count]
1650# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001651a1pms_api_delete_policy_batch() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001652 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001653
raviteja.karumurif6dce272024-05-03 16:50:07 +01001654 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1655 __print_err "<response-code> <policy-id> [count]" $@
1656 return 1
1657 fi
1658
1659 count=0
1660 max=1
1661
1662 if [ $# -eq 3 ]; then
1663 max=$3
1664 fi
1665
1666 pid=$2
1667 ARR=""
1668 while [ $count -lt $max ]; do
1669 if [ "$A1PMS_VERSION" == "V2" ]; then
1670 query="/v2/policies/"$UUID$pid
1671 else
1672 query="/policy?id="$UUID$pid
1673 fi
1674 res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)"
1675 status=${res:${#res}-3}
1676 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1677
1678 if [ $status -ne 200 ]; then
1679 echo " Requested(batch) "$count"?("$max")"
1680 __log_test_fail_status_code 200 $status
1681 return 1
1682 fi
1683 cid=${res:0:${#res}-3}
1684 ARR=$ARR" "$cid
1685 let pid=$pid+1
1686 let count=$count+1
1687 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1688 done
1689
1690 echo ""
1691
1692 count=0
1693 for cid in $ARR; do
1694
1695 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1696 status=${res:${#res}-3}
1697 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1698
1699 if [ $status -ne $1 ]; then
1700 echo " Deleted(batch) "$count"?("$max")"
1701 __log_test_fail_status_code $1 $status
1702 return 1
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001703 fi
1704
raviteja.karumurif6dce272024-05-03 16:50:07 +01001705 let count=$count+1
1706 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1707 done
1708 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001709
raviteja.karumurif6dce272024-05-03 16:50:07 +01001710 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001711
raviteja.karumurif6dce272024-05-03 16:50:07 +01001712 __log_test_pass
1713 return 0
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001714}
1715
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001716# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001717# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1718# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001719a1pms_api_delete_policy_parallel() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001720 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001721
raviteja.karumurif6dce272024-05-03 16:50:07 +01001722 if [ $# -ne 5 ]; then
1723 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1724 return 1
1725 fi
1726 resp_code=$1
1727 shift
1728 num_rics=$1
1729 shift
1730 start_id=$1
1731 shift
1732 count=$1
1733 shift
1734 pids=$1
1735 shift
1736
1737 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1738 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1739 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported"
1740 echo " Info - will execute over a1pms REST"
1741 fi
1742
1743 if [ "$A1PMS_VERSION" == "V2" ]; then
1744 query="$A1PMS_API_PREFIX/v2/policies/"
1745 else
1746 query="/policy"
1747 fi
1748
1749 urlbase=${A1PMS_ADAPTER}${query}
1750
1751 httpproxy="NOPROXY"
1752 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1753 httpproxy=$KUBE_PROXY_PATH
1754 fi
1755
1756 for ((i = 1; i <= $pids; i++)); do
1757 uuid=$UUID
1758 if [ -z "$uuid" ]; then
1759 uuid="NOUUID"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001760 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01001761 echo "" >"./tmp/.pid${i}.del.res.txt"
1762 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy >"./tmp/.pid${i}.del.txt"
1763 echo $i
1764 done | xargs -n 1 -I{} -P $pids bash -c '{
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001765 arg=$(echo {})
1766 echo " Parallel process $arg started"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001767 tmp=$(< "./tmp/.pid${arg}.del.txt")
1768 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001769 }'
raviteja.karumurif6dce272024-05-03 16:50:07 +01001770 msg=""
1771 for ((i = 1; i <= $pids; i++)); do
1772 file="./tmp/.pid${i}.del.res.txt"
1773 tmp=$(<$file)
1774 if [ -z "$tmp" ]; then
1775 echo " Process $i : unknown result (result file empty"
1776 msg="failed"
1777 else
1778 res=${tmp:0:1}
1779 if [ $res == "0" ]; then
1780 echo " Process $i : OK - "${tmp:1}
1781 else
1782 echo " Process $i : failed - "${tmp:1}
1783 msg="failed"
1784 fi
1785 fi
1786 done
1787 if [ -z $msg ]; then
1788 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count * $num_rics))
1789 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1790 return 0
1791 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001792
raviteja.karumurif6dce272024-05-03 16:50:07 +01001793 __log_test_fail_general "One of more processes failed to execute"
1794 return 1
1795}
1796
1797# API Test function: V3 DELETE a1policymanagement/v1/policies/{policy_id}, to run in i parallel for a number of rics
1798# args: <responseCode> <numberOfRics> <PolicyIdsFilePath> <countPerRic> <numberOfThreads>
1799# (Function for test scripts)
1800a1pms_api_delete_policy_parallel_v3() {
1801 __log_test_start $@
1802
1803 if [ $# -ne 6 ]; then
1804 __print_err " <responseCode> <numberOfRics> <PolicyIdsFilePath> <StartID> <countPerRic> <numberOfThreads>" $@
1805 return 1
1806 fi
1807 resp_code=$1
1808 shift
1809 num_rics=$1
1810 shift
1811 policy_ids_file_path=$1
1812 shift
1813 start_id=$1
1814 shift
1815 count=$1
1816 shift
1817 pids=$1
1818 shift
1819
1820 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1821 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1822 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported"
1823 echo " Info - will execute over a1pms REST"
1824 fi
1825
1826 query="$A1PMS_API_PREFIX/v1/policies/"
1827 urlbase=${A1PMS_ADAPTER}${query}
1828
1829 urlbase=${A1PMS_ADAPTER}${query}
1830
1831 httpproxy="NOPROXY"
1832 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1833 httpproxy=$KUBE_PROXY_PATH
1834 fi
1835
1836 for ((i = 1; i <= $pids; i++)); do
1837 echo "" >"./tmp/.pid${i}.del.res.txt"
1838 echo $resp_code $urlbase $policy_ids_file_path $start_id $pids $i $httpproxy >"./tmp/.pid${i}.del.txt"
1839 echo $i
1840 done | xargs -n 1 -I{} -P $pids bash -c '{
1841 arg=$(echo {})
1842 echo " Parallel process $arg started"
1843 tmp=$(< "./tmp/.pid${arg}.del.txt")
1844 python3 ../common/delete_policies_process_v3.py $tmp > ./tmp/.pid${arg}.del.res.txt
1845 }'
1846 msg=""
1847 for ((i = 1; i <= $pids; i++)); do
1848 file="./tmp/.pid${i}.del.res.txt"
1849 tmp=$(<$file)
1850 if [ -z "$tmp" ]; then
1851 echo " Process $i : unknown result (result file empty"
1852 msg="failed"
1853 else
1854 res=${tmp:0:1}
1855 if [ $res == "0" ]; then
1856 echo " Process $i : OK - "${tmp:1}
1857 else
1858 echo " Process $i : failed - "${tmp:1}
1859 msg="failed"
1860 fi
1861 fi
1862 done
1863 if [ -z $msg ]; then
1864 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v1/policies/{policy_id}" $resp_code $(($count * $num_rics))
1865 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1866 return 0
1867 fi
1868
1869 __log_test_fail_general "One of more processes failed to execute"
1870 return 1
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001871}
1872
JohnKeeney2f3b2682024-03-22 16:56:46 +00001873# API Test function: GET /policy and V2 GET /v2/policies/{policy_id}, to run in i parallel for a number of rics
1874# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1875# (Function for test scripts)
1876a1pms_api_get_policy_parallel() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001877 __log_test_start $@
JohnKeeney2f3b2682024-03-22 16:56:46 +00001878
raviteja.karumurif6dce272024-05-03 16:50:07 +01001879 if [ $# -ne 5 ]; then
1880 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1881 return 1
1882 fi
1883 resp_code=$1
1884 shift
1885 num_rics=$1
1886 shift
1887 start_id=$1
1888 shift
1889 count=$1
1890 shift
1891 pids=$1
1892 shift
1893
1894 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1895 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1896 echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported"
1897 echo " Info - will execute over a1pms REST"
1898 fi
1899
1900 if [ "$A1PMS_VERSION" == "V2" ]; then
1901 query="$A1PMS_API_PREFIX/v2/policies/"
1902 else
1903 query="/policy"
1904 fi
1905
1906 urlbase=${A1PMS_ADAPTER}${query}
1907
1908 httpproxy="NOPROXY"
1909 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1910 httpproxy=$KUBE_PROXY_PATH
1911 fi
1912
1913 for ((i = 1; i <= $pids; i++)); do
1914 uuid=$UUID
1915 if [ -z "$uuid" ]; then
1916 uuid="NOUUID"
JohnKeeney2f3b2682024-03-22 16:56:46 +00001917 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01001918 echo "" >"./tmp/.pid${i}.get.res.txt"
1919 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy >"./tmp/.pid${i}.get.txt"
1920 echo $i
1921 done | xargs -n 1 -I{} -P $pids bash -c '{
JohnKeeney2f3b2682024-03-22 16:56:46 +00001922 arg=$(echo {})
1923 echo " Parallel process $arg started"
1924 tmp=$(< "./tmp/.pid${arg}.get.txt")
1925 python3 ../common/get_policies_process.py $tmp > ./tmp/.pid${arg}.get.res.txt
1926 }'
raviteja.karumurif6dce272024-05-03 16:50:07 +01001927 msg=""
1928 for ((i = 1; i <= $pids; i++)); do
1929 file="./tmp/.pid${i}.get.res.txt"
1930 tmp=$(<$file)
1931 if [ -z "$tmp" ]; then
1932 echo " Process $i : unknown result (result file empty"
1933 msg="failed"
1934 else
1935 res=${tmp:0:1}
1936 if [ $res == "0" ]; then
1937 echo " Process $i : OK - "${tmp:1}
1938 else
1939 echo " Process $i : failed - "${tmp:1}
1940 msg="failed"
1941 fi
1942 fi
1943 done
1944 if [ -z $msg ]; then
1945 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count * $num_rics))
1946 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1947 return 0
1948 fi
JohnKeeney2f3b2682024-03-22 16:56:46 +00001949
raviteja.karumurif6dce272024-05-03 16:50:07 +01001950 __log_test_fail_general "One of more processes failed to execute"
1951 return 1
1952}
1953
1954# API Test function: V3 GET a1policymanagement/v1/policies/{policy_id}, to run in i parallel for a number of rics
1955# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1956# (Function for test scripts)
1957a1pms_api_get_policy_parallel_v3() {
1958 __log_test_start $@
1959
1960 if [ $# -ne 6 ]; then
1961 __print_err " <responseCode> <numberOfRics> <PolicyIdsFilePath> <startID> <countPerRic> <numberOfThreads>" $@
1962 return 1
1963 fi
1964 resp_code=$1
1965 shift
1966 num_rics=$1
1967 shift
1968 policy_ids_file_path=$1
1969 shift
1970 start_id=$1
1971 shift
1972 count=$1
1973 shift
1974 pids=$1
1975 shift
1976
1977 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1978 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1979 echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported"
1980 echo " Info - will execute over a1pms REST"
1981 fi
1982
1983 query="$A1PMS_API_PREFIX/v1/policies/"
1984 urlbase=${A1PMS_ADAPTER}${query}
1985
1986 httpproxy="NOPROXY"
1987 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1988 httpproxy=$KUBE_PROXY_PATH
1989 fi
1990
1991 for ((i = 1; i <= $pids; i++)); do
1992 echo "" >"./tmp/.pid${i}.get.res.txt"
1993 echo $resp_code $urlbase $policy_ids_file_path $start_id $pids $i $httpproxy >"./tmp/.pid${i}.get.txt"
1994 echo $i
1995 done | xargs -n 1 -I{} -P $pids bash -c '{
1996 arg=$(echo {})
1997 echo " Parallel process $arg started"
1998 tmp=$(< "./tmp/.pid${arg}.get.txt")
1999 python3 ../common/get_policies_process_v3.py $tmp > ./tmp/.pid${arg}.get.res.txt
2000 }'
2001 msg=""
2002 for ((i = 1; i <= $pids; i++)); do
2003 file="./tmp/.pid${i}.get.res.txt"
2004 tmp=$(<$file)
2005 if [ -z "$tmp" ]; then
2006 echo " Process $i : unknown result (result file empty"
2007 msg="failed"
2008 else
2009 res=${tmp:0:1}
2010 if [ $res == "0" ]; then
2011 echo " Process $i : OK - "${tmp:1}
2012 else
2013 echo " Process $i : failed - "${tmp:1}
2014 msg="failed"
2015 fi
2016 fi
2017 done
2018 if [ -z $msg ]; then
2019 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v1/policies/{policyId}" $resp_code $(($count * $num_rics))
2020 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
2021 return 0
2022 fi
2023
2024 __log_test_fail_general "One of more processes failed to execute"
2025 return 1
JohnKeeney2f3b2682024-03-22 16:56:46 +00002026}
2027
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002028# API Test function: GET /policy_ids and V2 GET /v2/policies
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002029# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
2030# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002031a1pms_api_get_policy_ids() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002032 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002033
raviteja.karumurif6dce272024-05-03 16:50:07 +01002034 if [ $# -lt 4 ]; then
2035 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
2036 return 1
2037 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002038
raviteja.karumurif6dce272024-05-03 16:50:07 +01002039 queryparams=""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002040
raviteja.karumurif6dce272024-05-03 16:50:07 +01002041 if [ "$A1PMS_VERSION" == "V2" ]; then
2042 if [ $2 != "NORIC" ]; then
2043 queryparams="?ric_id="$2
2044 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002045
raviteja.karumurif6dce272024-05-03 16:50:07 +01002046 if [ $3 != "NOSERVICE" ]; then
2047 if [ -z $queryparams ]; then
2048 queryparams="?service_id="$3
2049 else
2050 queryparams=$queryparams"&service_id="$3
2051 fi
2052 fi
2053 if [ $4 != "NOTYPE" ]; then
2054 if [ -z $queryparams ]; then
2055 queryparams="?policytype_id="$4
2056 else
2057 queryparams=$queryparams"&policytype_id="$4
2058 fi
2059 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002060
raviteja.karumurif6dce272024-05-03 16:50:07 +01002061 query="/v2/policies"$queryparams
2062 else
2063 if [ $2 != "NORIC" ]; then
2064 queryparams="?ric="$2
2065 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002066
raviteja.karumurif6dce272024-05-03 16:50:07 +01002067 if [ $3 != "NOSERVICE" ]; then
2068 if [ -z $queryparams ]; then
2069 queryparams="?service="$3
2070 else
2071 queryparams=$queryparams"&service="$3
2072 fi
2073 fi
2074 if [ $4 != "NOTYPE" ]; then
2075 if [ -z $queryparams ]; then
2076 queryparams="?type="$4
2077 else
2078 queryparams=$queryparams"&type="$4
2079 fi
2080 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002081
raviteja.karumurif6dce272024-05-03 16:50:07 +01002082 query="/policy_ids"$queryparams
2083 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002084
raviteja.karumurif6dce272024-05-03 16:50:07 +01002085 res="$(__do_curl_to_api A1PMS GET $query)"
2086 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002087
raviteja.karumurif6dce272024-05-03 16:50:07 +01002088 if [ $status -ne $1 ]; then
2089 __log_test_fail_status_code $1 $status
2090 return 1
2091 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002092
raviteja.karumurif6dce272024-05-03 16:50:07 +01002093 if [ $# -gt 4 ]; then
2094 body=${res:0:${#res}-3}
2095 targetJson="["
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002096
raviteja.karumurif6dce272024-05-03 16:50:07 +01002097 for pid in ${@:5}; do
2098 if [ "$targetJson" != "[" ]; then
2099 targetJson=$targetJson","
2100 fi
2101 if [ $pid != "NOID" ]; then
2102 targetJson=$targetJson"\"$UUID$pid\""
2103 fi
2104 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002105
raviteja.karumurif6dce272024-05-03 16:50:07 +01002106 targetJson=$targetJson"]"
2107 if [ "$A1PMS_VERSION" == "V2" ]; then
2108 targetJson="{\"policy_ids\": $targetJson}"
2109 fi
2110 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2111 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002112
raviteja.karumurif6dce272024-05-03 16:50:07 +01002113 if [ $res -ne 0 ]; then
2114 __log_test_fail_body
2115 return 1
2116 fi
2117 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002118
raviteja.karumurif6dce272024-05-03 16:50:07 +01002119 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status
2120 __log_test_pass
2121 return 0
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002122}
2123
raviteja.karumuri64755e02024-05-29 18:20:42 +01002124# API Test function: V3 GET a1policymanagement/v1/policies
2125# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
2126# (Function for test scripts)
2127a1pms_api_get_all_policies_v3() {
2128 __log_test_start $@
2129
2130 if [ $# -lt 4 ]; then
2131 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
2132 return 1
2133 fi
2134
2135 queryparams=""
2136
2137 if [ $2 != "NORIC" ]; then
2138 queryparams="?nearRtRicId="$2
2139 fi
2140
2141 if [ $3 != "NOSERVICE" ]; then
2142 if [ -z $queryparams ]; then
2143 queryparams="?serviceId="$3
2144 else
2145 queryparams=$queryparams"&serviceId="$3
2146 fi
2147 fi
2148 if [ $4 != "NOTYPE" ]; then
2149 if [ -z $queryparams ]; then
2150 queryparams="?policyTypeId="$4
2151 else
2152 queryparams=$queryparams"&policyTypeId="$4
2153 fi
2154 fi
2155
2156 query="/v1/policies"$queryparams
2157
2158 res="$(__do_curl_to_api A1PMS GET $query)"
2159 status=${res:${#res}-3}
2160
2161 if [ $status -ne $1 ]; then
2162 __log_test_fail_status_code $1 $status
2163 return 1
2164 fi
2165
2166 if [ $# -gt 4 ]; then
2167 body=${res:0:${#res}-3}
2168 targetJson="["
2169
2170 for pid in ${@:5}; do
2171 if [ "$targetJson" != "[" ]; then
2172 targetJson=$targetJson","
2173 fi
2174 IFS=':' read -r policy_id ric_id <<<"$pid"
2175 if [ $policy_id != "NOID" ]; then
2176 targetJson=$targetJson"{ \"policyId\": \"${UUID}${policy_id}\", \"nearRtRicId\": \"$ric_id\" }"
2177 fi
2178 done
2179
2180 targetJson=$targetJson"]"
2181 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2182 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2183
2184 if [ $res -ne 0 ]; then
2185 __log_test_fail_body
2186 return 1
2187 fi
2188 fi
2189
2190 __collect_endpoint_stats "A1PMS" 04 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2191 __log_test_pass
2192 return 0
2193}
2194
2195# API Test function: V2 GET a1-policy/v2/policy-types/{policyTypeId} and V3 GET a1policymanagement/v1/policytypes/{policyTypeId}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002196# args(V2): <response-code> <policy-type-id> [<schema-file>]
2197# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002198a1pms_api_get_policy_type() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002199 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002200
raviteja.karumuri64755e02024-05-29 18:20:42 +01002201 if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
raviteja.karumurif6dce272024-05-03 16:50:07 +01002202 __log_test_fail_not_supported
2203 return 1
2204 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002205
raviteja.karumurif6dce272024-05-03 16:50:07 +01002206 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2207 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
2208 return 1
2209 fi
raviteja.karumuri64755e02024-05-29 18:20:42 +01002210 if [ "$A1PMS_VERSION" == "V2" ]; then
2211 query="/v2/policy-types/$2"
2212 fi
2213 if [ "$A1PMS_VERSION" == "V3" ]; then
2214 query="/v1/policytypes/$2"
2215 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002216
2217 res="$(__do_curl_to_api A1PMS GET $query)"
2218 status=${res:${#res}-3}
2219
2220 if [ $status -ne $1 ]; then
2221 __log_test_fail_status_code $1 $status
2222 return 1
2223 fi
2224
2225 if [ $# -eq 3 ]; then
2226
2227 body=${res:0:${#res}-3}
2228
2229 targetJson=$(<$3)
raviteja.karumuri64755e02024-05-29 18:20:42 +01002230 if [ "$A1PMS_VERSION" == "V2" ]; then
2231 targetJson="{\"policy_schema\":$targetJson}"
2232 elif [ "$A1PMS_VERSION" == "V3" ]; then
2233 targetJson="$targetJson"
2234 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002235 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2236 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2237
2238 if [ $res -ne 0 ]; then
2239 __log_test_fail_body
2240 return 1
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002241 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002242 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002243
raviteja.karumuri64755e02024-05-29 18:20:42 +01002244 __collect_endpoint_stats "A1PMS" 05 "GET" ${A1PMS_API_PREFIX}${query} ${status}
raviteja.karumurif6dce272024-05-03 16:50:07 +01002245 __log_test_pass
2246 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002247}
2248
2249# API Test function: GET /policy_schema
2250# args: <response-code> <policy-type-id> [<schema-file>]
2251# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002252a1pms_api_get_policy_schema() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002253 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002254
raviteja.karumurif6dce272024-05-03 16:50:07 +01002255 if [ "$A1PMS_VERSION" == "V2" ]; then
2256 __log_test_fail_not_supported
2257 return 1
2258 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002259
raviteja.karumurif6dce272024-05-03 16:50:07 +01002260 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2261 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
2262 return 1
2263 fi
2264 query="/policy_schema?id=$2"
2265 res="$(__do_curl_to_api A1PMS GET $query)"
2266 status=${res:${#res}-3}
2267
2268 if [ $status -ne $1 ]; then
2269 __log_test_fail_status_code $1 $status
2270 return 1
2271 fi
2272
2273 if [ $# -eq 3 ]; then
2274
2275 body=${res:0:${#res}-3}
2276
2277 targetJson=$(<$3)
2278
2279 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2280 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2281
2282 if [ $res -ne 0 ]; then
2283 __log_test_fail_body
2284 return 1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002285 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002286 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002287
raviteja.karumurif6dce272024-05-03 16:50:07 +01002288 __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status
2289 __log_test_pass
2290 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002291}
2292
2293# API Test function: GET /policy_schemas
2294# args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002295# args(V2): <response-code>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002296# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002297a1pms_api_get_policy_schemas() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002298 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002299
raviteja.karumurif6dce272024-05-03 16:50:07 +01002300 if [ "$A1PMS_VERSION" == "V2" ]; then
2301 if [ $# -ne 1 ]; then
2302 __print_err "<response-code>" $@
2303 return 1
2304 fi
2305 else
2306 if [ $# -lt 2 ]; then
2307 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
2308 return 1
2309 fi
2310 fi
2311 if [ "$A1PMS_VERSION" == "V2" ]; then
2312 query="/v2/policy-schemas"
2313 else
2314 query="/policy_schemas"
2315 if [ $2 != "NORIC" ]; then
2316 query=$query"?ric="$2
2317 fi
2318 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002319
raviteja.karumurif6dce272024-05-03 16:50:07 +01002320 res="$(__do_curl_to_api A1PMS GET $query)"
2321 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002322
raviteja.karumurif6dce272024-05-03 16:50:07 +01002323 if [ $status -ne $1 ]; then
2324 __log_test_fail_status_code $1 $status
2325 return 1
2326 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002327
raviteja.karumurif6dce272024-05-03 16:50:07 +01002328 if [ $# -gt 2 ]; then
2329 body=${res:0:${#res}-3}
2330 targetJson="["
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002331
raviteja.karumurif6dce272024-05-03 16:50:07 +01002332 for file in ${@:3}; do
2333 if [ "$targetJson" != "[" ]; then
2334 targetJson=$targetJson","
2335 fi
2336 if [ $file == "NOFILE" ]; then
2337 targetJson=$targetJson"{}"
2338 else
2339 targetJson=$targetJson$(<$file)
2340 fi
2341 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002342
raviteja.karumurif6dce272024-05-03 16:50:07 +01002343 targetJson=$targetJson"]"
2344 if [ "$A1PMS_VERSION" == "V2" ]; then
2345 targetJson="{\"policy_schemas\": $targetJson }"
2346 fi
2347 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2348 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002349
raviteja.karumurif6dce272024-05-03 16:50:07 +01002350 if [ $res -ne 0 ]; then
2351 __log_test_fail_body
2352 return 1
2353 fi
2354 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002355
raviteja.karumurif6dce272024-05-03 16:50:07 +01002356 __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status
2357 __log_test_pass
2358 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002359}
2360
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002361# API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002362# arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002363# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002364a1pms_api_get_policy_status() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002365 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002366
raviteja.karumurif6dce272024-05-03 16:50:07 +01002367 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2368 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
2369 return 1
2370 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002371
raviteja.karumurif6dce272024-05-03 16:50:07 +01002372 targetJson=""
2373 if [ $# -eq 2 ]; then
2374 :
2375 elif [ "$3" == "STD" ]; then
2376 targetJson="{\"enforceStatus\":\"$4\""
2377 if [ $# -eq 5 ]; then
2378 targetJson=$targetJson",\"reason\":\"$5\""
2379 fi
2380 targetJson=$targetJson"}"
2381 elif [ "$3" == "STD2" ]; then
2382 if [ $4 == "EMPTY" ]; then
2383 targetJson="{\"enforceStatus\":\"\""
2384 else
2385 targetJson="{\"enforceStatus\":\"$4\""
2386 fi
2387 if [ $# -eq 5 ]; then
2388 if [ $5 == "EMPTY" ]; then
2389 targetJson=$targetJson",\"enforceReason\":\"\""
2390 else
2391 targetJson=$targetJson",\"enforceReason\":\"$5\""
2392 fi
2393 fi
2394 targetJson=$targetJson"}"
2395 elif [ "$3" == "OSC" ]; then
2396 if [[ $TEST_ENV_PROFILE =~ ^ORAN-[A-H] ]] || [[ $TEST_ENV_PROFILE =~ ^ONAP-[A-L] ]]; then
raviteja.karumuri2c6c06e2024-05-27 10:58:44 +01002397 targetJson="{\"instance_status\":\"$4\""
2398 if [ $# -eq 5 ]; then
2399 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
2400 fi
2401 targetJson=$targetJson",\"created_at\":\"????\"}"
2402 else
2403 targetJson="{\"enforceStatus\":\"$4\""
2404 if [ $# -eq 5 ]; then
2405 targetJson=$targetJson",\"enforceReason\":\"$5\"}"
2406 fi
2407 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002408 else
2409 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
2410 return 1
2411 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002412
raviteja.karumurif6dce272024-05-03 16:50:07 +01002413 if [ "$A1PMS_VERSION" == "V2" ]; then
2414 query="/v2/policies/$UUID$2/status"
2415 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
2416 else
2417 query="/policy_status?id="$UUID$2
2418 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002419
raviteja.karumurif6dce272024-05-03 16:50:07 +01002420 res="$(__do_curl_to_api A1PMS GET $query)"
2421 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002422
raviteja.karumurif6dce272024-05-03 16:50:07 +01002423 if [ $status -ne $1 ]; then
2424 __log_test_fail_status_code $1 $status
2425 return 1
2426 fi
2427 if [ $# -gt 2 ]; then
2428 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2429 body=${res:0:${#res}-3}
2430 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002431
raviteja.karumurif6dce272024-05-03 16:50:07 +01002432 if [ $res -ne 0 ]; then
2433 __log_test_fail_body
2434 return 1
2435 fi
2436 fi
2437 __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
2438 __log_test_pass
2439 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002440}
2441
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002442# API Test function: GET /policy_types and V2 GET /v2/policy-types
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002443# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
2444# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002445a1pms_api_get_policy_types() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002446 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002447
raviteja.karumurif6dce272024-05-03 16:50:07 +01002448 if [ $# -lt 1 ]; then
2449 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
2450 return 1
2451 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002452
raviteja.karumurif6dce272024-05-03 16:50:07 +01002453 if [ "$A1PMS_VERSION" == "V2" ]; then
2454 if [ $# -eq 1 ]; then
2455 query="/v2/policy-types"
2456 elif [ $2 == "NORIC" ]; then
2457 query="/v2/policy-types"
2458 else
2459 query="/v2/policy-types?ric_id=$2"
2460 fi
2461 else
2462 if [ $# -eq 1 ]; then
2463 query="/policy_types"
2464 elif [ $2 == "NORIC" ]; then
2465 query="/policy_types"
2466 else
2467 query="/policy_types?ric=$2"
2468 fi
2469 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002470
raviteja.karumurif6dce272024-05-03 16:50:07 +01002471 res="$(__do_curl_to_api A1PMS GET $query)"
2472 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002473
raviteja.karumurif6dce272024-05-03 16:50:07 +01002474 if [ $status -ne $1 ]; then
2475 __log_test_fail_status_code $1 $status
2476 return 1
2477 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002478
raviteja.karumurif6dce272024-05-03 16:50:07 +01002479 if [ $# -gt 2 ]; then
2480 body=${res:0:${#res}-3}
2481 targetJson="["
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002482
raviteja.karumurif6dce272024-05-03 16:50:07 +01002483 for pid in ${@:3}; do
2484 if [ "$targetJson" != "[" ]; then
2485 targetJson=$targetJson","
2486 fi
2487 if [ $pid == "EMPTY" ]; then
2488 pid=""
2489 fi
2490 targetJson=$targetJson"\"$pid\""
2491 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002492
raviteja.karumurif6dce272024-05-03 16:50:07 +01002493 targetJson=$targetJson"]"
2494 if [ "$A1PMS_VERSION" == "V2" ]; then
2495 targetJson="{\"policytype_ids\": $targetJson }"
2496 fi
2497 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2498 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002499
raviteja.karumurif6dce272024-05-03 16:50:07 +01002500 if [ $res -ne 0 ]; then
2501 __log_test_fail_body
2502 return 1
2503 fi
2504 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002505
raviteja.karumurif6dce272024-05-03 16:50:07 +01002506 __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
2507 __log_test_pass
2508 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002509}
2510
raviteja.karumuri64755e02024-05-29 18:20:42 +01002511# API Test function: V3 GET a1policymanagement/v1/policytypes
2512# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
2513# (Function for test scripts)
2514a1pms_api_get_policy_types_v3() {
2515 __log_test_start $@
2516
2517 if [ $# -lt 1 ]; then
2518 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
2519 return 1
2520 fi
2521
2522 if [ $# -eq 1 ]; then
2523 query="/v1/policytypes"
2524 elif [ $2 == "NORIC" ]; then
2525 query="/v1/policytypes"
2526 else
2527 query="/v1/policytypes?nearRtRicId=$2"
2528 fi
2529 res="$(__do_curl_to_api A1PMS GET $query)"
2530 status=${res:${#res}-3}
2531
2532 if [ $status -ne $1 ]; then
2533 __log_test_fail_status_code $1 $status
2534 return 1
2535 fi
2536
2537 if [ $# -gt 2 ]; then
2538 body=${res:0:${#res}-3}
2539 targetJson="["
2540
2541 for pid in ${@:3}; do
2542 if [ "$targetJson" != "[" ]; then
2543 targetJson=$targetJson","
2544 fi
2545 IFS=':' read -r policy_type_id ric_id <<<"$pid"
2546 # if [ -n "$policy_type_id" ] && [ -n "$ric_id" ]; then
2547 if [ $policy_type_id == "EMPTY" ]; then
2548 policy_type_id=""
2549 fi
2550 targetJson=$targetJson"{ \"policyTypeId\": \"$policy_type_id\", \"nearRtRicId\": \"$ric_id\" }"
2551 # fi
2552 done
2553
2554 targetJson=$targetJson"]"
2555
2556 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2557 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2558
2559 if [ $res -ne 0 ]; then
2560 __log_test_fail_body
2561 return 1
2562 fi
2563 fi
2564
2565 __collect_endpoint_stats "A1PMS" 09 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2566 __log_test_pass
2567 return 0
2568}
2569
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002570#########################################################
2571#### Test case functions Health check
2572#########################################################
2573
raviteja.karumurif6dce272024-05-03 16:50:07 +01002574# API Test function: GET /status and V2 GET /status or (v1/status for a1pmsV3)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002575# args: <response-code>
2576# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002577a1pms_api_get_status() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002578 __log_test_start $@
2579 if [ $# -ne 1 ]; then
2580 __print_err "<response-code>" $@
2581 return 1
2582 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002583
raviteja.karumurif6dce272024-05-03 16:50:07 +01002584 if [ "$A1PMS_VERSION" == "V2" ]; then
2585 query="/v2/status"
2586 elif [ "$A1PMS_VERSION" == "V3" ]; then
2587 query="/v1/status"
2588 else
2589 query="/status"
2590 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002591
raviteja.karumurif6dce272024-05-03 16:50:07 +01002592 res="$(__do_curl_to_api A1PMS GET $query)"
2593 status=${res:${#res}-3}
2594
2595 if [ $status -ne $1 ]; then
2596 __log_test_fail_status_code $1 $status
2597 return 1
2598 fi
2599
raviteja.karumuri64755e02024-05-29 18:20:42 +01002600 __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX$query $status
raviteja.karumurif6dce272024-05-03 16:50:07 +01002601 __log_test_pass
2602 return 0
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002603}
2604
2605# API Test function: GET /status (root) without api prefix
2606# args: <response-code>
2607# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002608a1pms_api_get_status_root() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002609 __log_test_start $@
2610 if [ $# -ne 1 ]; then
2611 __print_err "<response-code>" $@
2612 return 1
2613 fi
2614 query="/status"
2615 TMP_PREFIX=$A1PMS_API_PREFIX
2616 A1PMS_API_PREFIX=""
2617 res="$(__do_curl_to_api A1PMS GET $query)"
2618 A1PMS_API_PREFIX=$TMP_PREFIX
2619 status=${res:${#res}-3}
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002620
raviteja.karumurif6dce272024-05-03 16:50:07 +01002621 if [ $status -ne $1 ]; then
2622 __log_test_fail_status_code $1 $status
2623 return 1
2624 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002625
raviteja.karumurif6dce272024-05-03 16:50:07 +01002626 __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
2627 __log_test_pass
2628 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002629}
2630
2631#########################################################
2632#### Test case functions RIC Repository
2633#########################################################
2634
raviteja.karumuri64755e02024-05-29 18:20:42 +01002635# API Test function: GET /ric, V2 GET /v2/rics/ric, and V3 GET a1policymanagement/v1/rics/ric
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002636# args: <reponse-code> <management-element-id> [<ric-id>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002637# (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
2638# (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
2639# (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2640
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002641# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002642a1pms_api_get_ric() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002643 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002644
raviteja.karumurif6dce272024-05-03 16:50:07 +01002645 if [ "$A1PMS_VERSION" == "V2" ]; then
2646 if [ $# -lt 3 ]; then
2647 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
2648 return 1
2649 fi
2650 search=""
2651 if [ $2 != "NOME" ]; then
2652 search="?managed_element_id="$2
2653 fi
2654 if [ $3 != "NORIC" ]; then
2655 if [ -z $search ]; then
2656 search="?ric_id="$3
2657 else
2658 search=$search"&ric_id="$3
2659 fi
2660 fi
2661 query="/v2/rics/ric"$search
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002662
raviteja.karumurif6dce272024-05-03 16:50:07 +01002663 res="$(__do_curl_to_api A1PMS GET $query)"
2664 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002665
raviteja.karumurif6dce272024-05-03 16:50:07 +01002666 if [ $status -ne $1 ]; then
2667 __log_test_fail_status_code $1 $status
2668 return 1
2669 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002670
raviteja.karumurif6dce272024-05-03 16:50:07 +01002671 if [ $# -gt 3 ]; then
2672 body=${res:0:${#res}-3}
2673 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4")
2674 if [ $res -ne 0 ]; then
2675 __log_test_fail_general "Could not create target ric info json"
2676 return 1
2677 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002678
raviteja.karumurif6dce272024-05-03 16:50:07 +01002679 targetJson=$(<./tmp/.tmp_rics.json)
2680 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
2681 echo " TARGET JSON: $targetJson" >>$HTTPLOG
2682 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2683 if [ $res -ne 0 ]; then
2684 __log_test_fail_body
2685 return 1
2686 fi
2687 fi
raviteja.karumuri64755e02024-05-29 18:20:42 +01002688 elif [ "$A1PMS_VERSION" == "V3" ]; then
2689 if [ $# -lt 3 ]; then
2690 __print_err "<reponseCode> <managementElementId>|NOME <ricId>|<NORIC> [stringOfRicInfo>]" $@
2691 return 1
2692 fi
2693 search=""
2694 if [ $2 != "NOME" ]; then
2695 search="?managedElementId="$2
2696 fi
2697 if [ $3 != "NORIC" ]; then
2698 if [ -z $search ]; then
2699 search="?ricId="$3
2700 else
2701 search=$search"&ricId="$3
2702 fi
2703 fi
2704 query="/v1/rics/ric"$search
2705
2706 res="$(__do_curl_to_api A1PMS GET $query)"
2707 status=${res:${#res}-3}
2708
2709 if [ $status -ne $1 ]; then
2710 __log_test_fail_status_code $1 $status
2711 return 1
2712 fi
2713
2714 if [ $# -gt 3 ]; then
2715 body=${res:0:${#res}-3}
2716 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "${A1PMS_VERSION}" "$4")
2717 if [ $res -ne 0 ]; then
2718 __log_test_fail_general "Could not create target ric info json"
2719 return 1
2720 fi
2721
2722 targetJson=$(<./tmp/.tmp_rics.json)
2723 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
2724 echo " TARGET JSON: $targetJson" >>$HTTPLOG
2725 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2726 if [ $res -ne 0 ]; then
2727 __log_test_fail_body
2728 return 1
2729 fi
2730 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002731 else
2732 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
raviteja.karumuri64755e02024-05-29 18:20:42 +01002733 __print_err "<reponseCode> <managedElementIds> [<ricId>]" $@
raviteja.karumurif6dce272024-05-03 16:50:07 +01002734 return 1
2735 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002736
raviteja.karumurif6dce272024-05-03 16:50:07 +01002737 query="/ric?managedElementId="$2
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002738
raviteja.karumurif6dce272024-05-03 16:50:07 +01002739 res="$(__do_curl_to_api A1PMS GET $query)"
2740 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002741
raviteja.karumurif6dce272024-05-03 16:50:07 +01002742 if [ $status -ne $1 ]; then
2743 __log_test_fail_status_code $1 $status
2744 return 1
2745 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002746
raviteja.karumurif6dce272024-05-03 16:50:07 +01002747 if [ $# -eq 3 ]; then
2748 body=${res:0:${#res}-3}
2749 if [ "$body" != "$3" ]; then
2750 __log_test_fail_body
2751 return 1
2752 fi
2753 fi
2754 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002755
raviteja.karumuri64755e02024-05-29 18:20:42 +01002756 __collect_endpoint_stats "A1PMS" 11 "GET" ${A1PMS_API_PREFIX}${query} ${status}
raviteja.karumurif6dce272024-05-03 16:50:07 +01002757 __log_test_pass
2758 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002759}
2760
raviteja.karumuri64755e02024-05-29 18:20:42 +01002761# API test function: GET /rics, V2 GET /v2/rics, and V3 GET /a1policymanagement/v1/rics
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002762# args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
2763# example of <space-separate-string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4 ricsim_g1_1:me2_........."
2764# format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2765# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002766a1pms_api_get_rics() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002767 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002768
raviteja.karumurif6dce272024-05-03 16:50:07 +01002769 if [ $# -lt 2 ]; then
2770 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
2771 return 1
2772 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002773
raviteja.karumurif6dce272024-05-03 16:50:07 +01002774 if [ "$A1PMS_VERSION" == "V2" ]; then
2775 query="/v2/rics"
2776 if [ $2 != "NOTYPE" ]; then
2777 query="/v2/rics?policytype_id="$2
2778 fi
raviteja.karumuri64755e02024-05-29 18:20:42 +01002779 elif [ "$A1PMS_VERSION" == "V3" ]; then
2780 query="/v1/rics"
2781 if [ $2 != "NOTYPE" ]; then
2782 query=${query}"?policyTypeId="$2
2783 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002784 else
2785 query="/rics"
2786 if [ $2 != "NOTYPE" ]; then
2787 query="/rics?policyType="$2
2788 fi
2789 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002790
raviteja.karumurif6dce272024-05-03 16:50:07 +01002791 res="$(__do_curl_to_api A1PMS GET $query)"
2792 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002793
raviteja.karumurif6dce272024-05-03 16:50:07 +01002794 if [ $status -ne $1 ]; then
2795 __log_test_fail_status_code $1 $status
2796 return 1
2797 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002798
raviteja.karumurif6dce272024-05-03 16:50:07 +01002799 if [ $# -gt 2 ]; then
2800 body=${res:0:${#res}-3}
raviteja.karumuri64755e02024-05-29 18:20:42 +01002801 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "${A1PMS_VERSION}" "$3")
raviteja.karumurif6dce272024-05-03 16:50:07 +01002802 if [ $res -ne 0 ]; then
2803 __log_test_fail_general "Could not create target ric info json"
2804 return 1
2805 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002806
raviteja.karumurif6dce272024-05-03 16:50:07 +01002807 targetJson=$(<./tmp/.tmp_rics.json)
raviteja.karumuri64755e02024-05-29 18:20:42 +01002808 if [ "$A1PMS_VERSION" == "V2" ] || [ "$A1PMS_VERSION" == "V3" ]; then
raviteja.karumurif6dce272024-05-03 16:50:07 +01002809 targetJson="{\"rics\": $targetJson }"
2810 fi
2811 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2812 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2813 if [ $res -ne 0 ]; then
2814 __log_test_fail_body
2815 return 1
2816 fi
2817 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002818
raviteja.karumuri64755e02024-05-29 18:20:42 +01002819 __collect_endpoint_stats "A1PMS" 12 "GET" ${A1PMS_API_PREFIX}${query} ${status}
raviteja.karumurif6dce272024-05-03 16:50:07 +01002820 __log_test_pass
2821 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002822}
2823
2824##################################################################
2825#### API Test case functions Service registry and supervision ####
2826##################################################################
2827
raviteja.karumuri85d61ba2024-06-12 13:46:45 +01002828# API test function: PUT /service, V2 PUT /service and V3 PUT a1policymanagement/v1/services
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002829# args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2830# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002831a1pms_api_put_service() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002832 __log_test_start $@
2833 if [ $# -ne 4 ]; then
2834 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2835 return 1
2836 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002837
raviteja.karumurif6dce272024-05-03 16:50:07 +01002838 if [ "$A1PMS_VERSION" == "V2" ]; then
2839 query="/v2/services"
2840 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2841 elif [ "$A1PMS_VERSION" == "V3" ]; then
2842 query="/v1/services"
2843 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceId\": \""$2"\"}"
2844 else
2845 query="/service"
2846 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2847 fi
2848 file="./tmp/.tmp.json"
2849 echo "$json" >$file
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002850
raviteja.karumurif6dce272024-05-03 16:50:07 +01002851 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2852 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002853
raviteja.karumurif6dce272024-05-03 16:50:07 +01002854 if [ $status -ne $1 ]; then
2855 __log_test_fail_status_code $1 $status
2856 return 1
2857 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002858
raviteja.karumuri64755e02024-05-29 18:20:42 +01002859 __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX$query $status
raviteja.karumurif6dce272024-05-03 16:50:07 +01002860 __log_test_pass
2861 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002862}
2863
raviteja.karumuri64755e02024-05-29 18:20:42 +01002864# API test function: GET /services, V2 GET /v2/services and V3 /a1policymanagement/v1/services
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002865#args: <response-code> [ (<query-service-name> <target-service-name> <keepalive-timeout> <callbackurl>) | (NOSERVICE <target-service-name> <keepalive-timeout> <callbackurl> [<target-service-name> <keepalive-timeout> <callbackurl>]* )]
2866# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002867a1pms_api_get_services() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002868 __log_test_start $@
2869 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2870 paramError=1
2871 if [ $# -eq 1 ]; then
2872 paramError=0
2873 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2874 paramError=0
2875 elif [ $# -eq 5 ]; then
2876 paramError=0
2877 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2878 argLen=$(($# - 2))
2879 if [ $(($argLen % 3)) -eq 0 ]; then
2880 paramError=0
2881 fi
2882 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002883
raviteja.karumurif6dce272024-05-03 16:50:07 +01002884 if [ $paramError -ne 0 ]; then
2885 __print_err "<response-code> [ (<query-service-name> <target-service-name> <keepalive-timeout> <callbackurl>) | (NOSERVICE <target-service-name> <keepalive-timeout> <callbackurl> [<target-service-name> <keepalive-timeout> <callbackurl>]* )]" $@
2886 return 1
2887 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002888
raviteja.karumurif6dce272024-05-03 16:50:07 +01002889 if [ "$A1PMS_VERSION" == "V2" ]; then
2890 query="/v2/services"
raviteja.karumurif6dce272024-05-03 16:50:07 +01002891 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2892 query="/v2/services?service_id="$2
2893 fi
raviteja.karumuri64755e02024-05-29 18:20:42 +01002894 elif [ "$A1PMS_VERSION" == "V3" ]; then
2895 query="/v1/services"
2896 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2897 query="/v1/services?serviceId="$2
2898 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002899 else
2900 query="/services"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002901
raviteja.karumurif6dce272024-05-03 16:50:07 +01002902 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2903 query="/services?name="$2
2904 fi
2905 fi
2906 res="$(__do_curl_to_api A1PMS GET $query)"
2907 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002908
raviteja.karumurif6dce272024-05-03 16:50:07 +01002909 if [ $status -ne $1 ]; then
2910 __log_test_fail_status_code $1 $status
2911 return 1
2912 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002913
raviteja.karumurif6dce272024-05-03 16:50:07 +01002914 if [ $# -gt 2 ]; then
2915 variableArgCount=$(($# - 2))
2916 body=${res:0:${#res}-3}
2917 targetJson="["
2918 shift
2919 shift
2920 cntr=0
2921 while [ $cntr -lt $variableArgCount ]; do
2922 servicename=$1
2923 shift
2924 timeout=$1
2925 shift
2926 callback=$1
2927 shift
2928 if [ $cntr -gt 0 ]; then
2929 targetJson=$targetJson","
2930 fi
2931 # timeSinceLastActivitySeconds value cannot be checked since value varies
2932 if [ "$A1PMS_VERSION" == "V2" ]; then
2933 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
raviteja.karumuri64755e02024-05-29 18:20:42 +01002934 elif [ "$A1PMS_VERSION" == "V3" ]; then
2935 targetJson=$targetJson"{\"serviceId\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
raviteja.karumurif6dce272024-05-03 16:50:07 +01002936 else
2937 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2938 fi
2939 let cntr=cntr+3
2940 done
2941 targetJson=$targetJson"]"
2942 if [ "$A1PMS_VERSION" == "V2" ]; then
2943 targetJson="{\"service_list\": $targetJson }"
raviteja.karumuri64755e02024-05-29 18:20:42 +01002944 URL_for_Collect_End_Point="/v2/services"
2945 elif [ "$A1PMS_VERSION" == "V3" ]; then
2946 targetJson="{\"serviceList\": $targetJson }"
2947 URL_for_Collect_End_Point="/v1/services"
raviteja.karumurif6dce272024-05-03 16:50:07 +01002948 fi
2949 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2950 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2951 if [ $res -ne 0 ]; then
2952 __log_test_fail_body
2953 return 1
2954 fi
2955 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002956
raviteja.karumuri64755e02024-05-29 18:20:42 +01002957 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX$URL_for_Collect_End_Point $status
raviteja.karumurif6dce272024-05-03 16:50:07 +01002958 __log_test_pass
2959 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002960}
2961
raviteja.karumuri64755e02024-05-29 18:20:42 +01002962# API test function: GET /services, V2 GET /v2/services and V3 /a1policymanagement/v1/services - (only checking service names)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002963# args: <response-code> [<service-name>]*"
2964# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002965a1pms_api_get_service_ids() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002966 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002967
raviteja.karumurif6dce272024-05-03 16:50:07 +01002968 if [ $# -lt 1 ]; then
2969 __print_err "<response-code> [<service-name>]*" $@
2970 return 1
2971 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002972
raviteja.karumurif6dce272024-05-03 16:50:07 +01002973 if [ "$A1PMS_VERSION" == "V2" ]; then
2974 query="/v2/services"
raviteja.karumuri64755e02024-05-29 18:20:42 +01002975 elif [ "$A1PMS_VERSION" == "V3" ]; then
2976 query="/v1/services"
raviteja.karumurif6dce272024-05-03 16:50:07 +01002977 else
2978 query="/services"
2979 fi
2980 res="$(__do_curl_to_api A1PMS GET $query)"
2981 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002982
raviteja.karumurif6dce272024-05-03 16:50:07 +01002983 if [ $status -ne $1 ]; then
2984 __log_test_fail_status_code $1 $status
2985 return 1
2986 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002987
raviteja.karumurif6dce272024-05-03 16:50:07 +01002988 body=${res:0:${#res}-3}
2989 targetJson="["
2990 for rapp in ${@:2}; do
2991 if [ "$targetJson" != "[" ]; then
2992 targetJson=$targetJson","
2993 fi
2994 if [ "$A1PMS_VERSION" == "V2" ]; then
2995 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
raviteja.karumuri64755e02024-05-29 18:20:42 +01002996 elif [ "$A1PMS_VERSION" == "V3" ]; then
2997 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceId\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
raviteja.karumurif6dce272024-05-03 16:50:07 +01002998 else
2999 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
3000 fi
3001 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003002
raviteja.karumurif6dce272024-05-03 16:50:07 +01003003 targetJson=$targetJson"]"
3004 if [ "$A1PMS_VERSION" == "V2" ]; then
3005 targetJson="{\"service_list\": $targetJson }"
raviteja.karumuri64755e02024-05-29 18:20:42 +01003006 URL_for_Collect_End_Point="/v2/services"
3007 elif [ "$A1PMS_VERSION" == "V3" ]; then
3008 targetJson="{\"serviceList\": $targetJson }"
3009 URL_for_Collect_End_Point="/v1/services"
raviteja.karumurif6dce272024-05-03 16:50:07 +01003010 fi
3011 echo "TARGET JSON: $targetJson" >>$HTTPLOG
3012 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003013
raviteja.karumurif6dce272024-05-03 16:50:07 +01003014 if [ $res -ne 0 ]; then
3015 __log_test_fail_body
3016 return 1
3017 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003018
raviteja.karumuri64755e02024-05-29 18:20:42 +01003019 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX$URL_for_Collect_End_Point $status
raviteja.karumurif6dce272024-05-03 16:50:07 +01003020 __log_test_pass
3021 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003022}
3023
raviteja.karumuri1097b4b2024-06-11 13:11:20 +01003024# API test function: DELETE /services, V2 DELETE /v2/services/{serviceId} and V3 DELETE a1policymanagement/v1/services/{serviceId}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003025# args: <response-code> <service-name>
3026# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01003027a1pms_api_delete_services() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01003028 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003029
raviteja.karumurif6dce272024-05-03 16:50:07 +01003030 if [ $# -ne 2 ]; then
3031 __print_err "<response-code> <service-name>" $@
3032 return 1
3033 fi
3034 if [ "$A1PMS_VERSION" == "V2" ]; then
raviteja.karumuri64755e02024-05-29 18:20:42 +01003035 url_part="/v2/services/"
3036 query=${url_part}${2}
3037 elif [ "$A1PMS_VERSION" == "V3" ]; then
3038 url_part="/v1/services/"
3039 query=${url_part}${2}
raviteja.karumurif6dce272024-05-03 16:50:07 +01003040 else
3041 query="/services?name="$2
3042 fi
3043 res="$(__do_curl_to_api A1PMS DELETE $query)"
3044 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003045
raviteja.karumurif6dce272024-05-03 16:50:07 +01003046 if [ $status -ne $1 ]; then
3047 __log_test_fail_status_code $1 $status
3048 return 1
3049 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003050
raviteja.karumuri64755e02024-05-29 18:20:42 +01003051 __collect_endpoint_stats "A1PMS" 15 "DELETE" ${A1PMS_API_PREFIX}${url_part}"{serviceId}" $status
raviteja.karumurif6dce272024-05-03 16:50:07 +01003052 __log_test_pass
3053 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003054}
3055
raviteja.karumuri1097b4b2024-06-11 13:11:20 +01003056# API test function: PUT /services/keepalive, V2 PUT /v2/services/{service_id}/keepalive and V3 DELETE a1policymanagement/v1/services/{serviceId}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003057# args: <response-code> <service-name>
3058# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01003059a1pms_api_put_services_keepalive() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01003060 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003061
raviteja.karumurif6dce272024-05-03 16:50:07 +01003062 if [ $# -ne 2 ]; then
3063 __print_err "<response-code> <service-name>" $@
3064 return 1
3065 fi
3066 if [ "$A1PMS_VERSION" == "V2" ]; then
3067 query="/v2/services/$2/keepalive"
raviteja.karumuri1097b4b2024-06-11 13:11:20 +01003068 elif [ "$A1PMS_VERSION" == "V3" ]; then
3069 query="/v1/services/$2/keepalive"
raviteja.karumurif6dce272024-05-03 16:50:07 +01003070 else
3071 query="/services/keepalive?name="$2
3072 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003073
raviteja.karumuri1097b4b2024-06-11 13:11:20 +01003074 if [ "$A1PMS_VERSION" == "V3" ]; then
3075 empty_json_body={}
3076 res="$(__do_curl_to_api A1PMS PUT ${query} ${empty_json_body})"
3077 else
3078 res="$(__do_curl_to_api A1PMS PUT ${query})"
3079 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01003080 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003081
raviteja.karumurif6dce272024-05-03 16:50:07 +01003082 if [ $status -ne $1 ]; then
raviteja.karumuri1097b4b2024-06-11 13:11:20 +01003083 __log_test_fail_status_code ${1} ${status}
raviteja.karumurif6dce272024-05-03 16:50:07 +01003084 return 1
3085 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003086
raviteja.karumuri1097b4b2024-06-11 13:11:20 +01003087 __collect_endpoint_stats "A1PMS" 16 "PUT" ${A1PMS_API_PREFIX}${query} ${status}
raviteja.karumurif6dce272024-05-03 16:50:07 +01003088 __log_test_pass
3089 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003090}
3091
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003092##################################################################
3093#### API Test case functions Configuration ####
3094##################################################################
3095
raviteja.karumuri85d61ba2024-06-12 13:46:45 +01003096# API Test function: PUT "/v2/configuration" or V3 PUT "a1policymanagement/v1/configuration"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003097# args: <response-code> <config-file>
3098# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01003099a1pms_api_put_configuration() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01003100 __log_test_start $@
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003101
raviteja.karumurif6dce272024-05-03 16:50:07 +01003102 if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
3103 __log_test_fail_not_supported
3104 return 1
3105 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003106
raviteja.karumurif6dce272024-05-03 16:50:07 +01003107 if [ $# -ne 2 ]; then
3108 __print_err "<response-code> <config-file>" $@
3109 return 1
3110 fi
3111 if [ ! -f $2 ]; then
3112 __log_test_fail_general "Config file "$2", does not exist"
3113 return 1
3114 fi
3115 inputJson=$(<$2)
3116 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
3117 # inputJson="{\"config\":"$inputJson"}"
3118 # fi
3119 file="./tmp/.config.json"
3120 echo $inputJson >$file
3121 if [ "$A1PMS_VERSION" == "V2" ]; then
3122 query="/v2/configuration"
3123 elif [ "$A1PMS_VERSION" == "V3" ]; then
3124 #V3 has baseurl changes 'a1-policy/v2' to 'a1policymanagement/v1'
3125 query="/v1/configuration"
3126 fi
3127 res="$(__do_curl_to_api A1PMS PUT $query $file)"
3128 status=${res:${#res}-3}
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003129
raviteja.karumurif6dce272024-05-03 16:50:07 +01003130 if [ $status -ne $1 ]; then
3131 __log_test_fail_status_code $1 $status
3132 return 1
3133 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003134
raviteja.karumuri64755e02024-05-29 18:20:42 +01003135 __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX$query $status
raviteja.karumurif6dce272024-05-03 16:50:07 +01003136 __log_test_pass
3137 return 0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003138}
3139
raviteja.karumuri85d61ba2024-06-12 13:46:45 +01003140# API Test function: GET /v2/configuration and V3 GET a1policymanagement/v1/configuration
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003141# args: <response-code> [<config-file>]
3142# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01003143a1pms_api_get_configuration() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01003144 __log_test_start $@
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003145
raviteja.karumuri64755e02024-05-29 18:20:42 +01003146 if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
raviteja.karumurif6dce272024-05-03 16:50:07 +01003147 __log_test_fail_not_supported
3148 return 1
3149 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003150
raviteja.karumurif6dce272024-05-03 16:50:07 +01003151 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
3152 __print_err "<response-code> [<config-file>]" $@
3153 return 1
3154 fi
3155 if [ ! -f $2 ]; then
3156 __log_test_fail_general "Config file "$2" for comparison, does not exist"
3157 return 1
3158 fi
3159
raviteja.karumuri64755e02024-05-29 18:20:42 +01003160 if [ "$A1PMS_VERSION" == "V3" ]; then
3161 #The V3 of a1-pms URL is a1policymanagement/v1 and the v2 is a1-policy/v2
3162 query="/v1/configuration"
3163 else
3164 query="/v2/configuration"
3165 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01003166 res="$(__do_curl_to_api A1PMS GET $query)"
3167 status=${res:${#res}-3}
3168
3169 if [ $status -ne $1 ]; then
3170 __log_test_fail_status_code $1 $status
3171 return 1
3172 fi
3173
3174 if [ $# -eq 2 ]; then
3175
3176 body=${res:0:${#res}-3}
3177
3178 targetJson=$(<$2)
3179 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
3180 # inputJson="{\"config\":"$inputJson"}"
3181 # fi
3182 echo "TARGET JSON: $targetJson" >>$HTTPLOG
3183 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
3184
3185 if [ $res -ne 0 ]; then
3186 __log_test_fail_body
3187 return 1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003188 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01003189 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003190
raviteja.karumuri64755e02024-05-29 18:20:42 +01003191 if [ "$A1PMS_VERSION" == "V3" ]; then
3192 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v1/configuration" $status
3193 else
3194 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
3195 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01003196 __log_test_pass
3197 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02003198}
3199
3200##########################################
3201#### Reset types and instances ####
3202##########################################
3203
3204# Admin reset to remove all policies and services
3205# All types and instances etc are removed - types and instances in a1 sims need to be removed separately
3206# NOTE - only works in kubernetes and the pod should not be running
3207# args: -
3208# (Function for test scripts)
3209
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01003210a1pms_kube_pvc_reset() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01003211 __log_test_start $@
BjornMagnussonXAa5491572021-05-04 09:21:24 +02003212
raviteja.karumurif6dce272024-05-03 16:50:07 +01003213 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
3214 if [ -z "$pvc_name" ]; then
3215 pvc_name=policymanagementservice-vardata-pvc
3216 fi
3217 echo " Trying to reset pvc: "$pvc_name
3218 __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR
BjornMagnussonXAa5491572021-05-04 09:21:24 +02003219
raviteja.karumurif6dce272024-05-03 16:50:07 +01003220 __log_test_pass
3221 return 0
BjornMagnussonXAcd938442022-05-11 10:01:24 +02003222}
3223
3224# args: <realm> <client-name> <client-secret>
3225a1pms_configure_sec() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01003226 export A1PMS_CREDS_GRANT_TYPE="client_credentials"
3227 export A1PMS_CREDS_CLIENT_SECRET=$3
3228 export A1PMS_CREDS_CLIENT_ID=$2
3229 export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
3230 export A1PMS_SIDECAR_MOUNT="/token-cache"
3231 export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
BjornMagnussonXAcd938442022-05-11 10:01:24 +02003232
raviteja.karumurif6dce272024-05-03 16:50:07 +01003233 export AUTHSIDECAR_APP_NAME
3234 export AUTHSIDECAR_DISPLAY_NAME
3235}