blob: 939762674ce69a3ade97f9fe0f7ce02681b19d3f [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"
350 mkdir db
351 fi
352 cd $curdir
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200353
raviteja.karumurif6dce272024-05-03 16:50:07 +0100354 __export_a1pms_vars $1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100355
raviteja.karumurif6dce272024-05-03 16:50:07 +0100356 dest_file=$SIM_GROUP/$A1PMS_COMPOSE_DIR/$A1PMS_HOST_MNT_DIR/application.yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100357
raviteja.karumurif6dce272024-05-03 16:50:07 +0100358 envsubst <$2 >$dest_file
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100359
raviteja.karumurif6dce272024-05-03 16:50:07 +0100360 __start_container $A1PMS_COMPOSE_DIR "" NODOCKERARGS 1 $A1PMS_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100361
raviteja.karumurif6dce272024-05-03 16:50:07 +0100362 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
363 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +0100364
raviteja.karumurif6dce272024-05-03 16:50:07 +0100365 __collect_endpoint_stats_image_info "A1PMS" $A1PMS_IMAGE
366 echo ""
367 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100368}
369
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100370# Stop the a1pms
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200371# args: -
372# args: -
373# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100374stop_a1pms() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100375 echo -e $BOLD"Stopping $A1PMS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200376
raviteja.karumurif6dce272024-05-03 16:50:07 +0100377 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200378
raviteja.karumurif6dce272024-05-03 16:50:07 +0100379 __check_prestarted_image "A1PMS"
380 if [ $? -eq 0 ]; then
381 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
382 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
383 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
384 return 0
385 fi
386 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
387 echo " Deleting the replica set - a new will be started when the app is started"
388 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
389 if [ $? -ne 0 ]; then
390 echo -e $RED" Could not delete replica set "$RED
391 ((RES_CONF_FAIL++))
392 return 1
393 fi
394 else
395 docker stop $A1PMS_APP_NAME &>./tmp/.dockererr
396 if [ $? -ne 0 ]; then
397 __print_err "Could not stop $A1PMS_APP_NAME" $@
398 cat ./tmp/.dockererr
399 ((RES_CONF_FAIL++))
400 return 1
401 fi
402 fi
403 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
404 echo ""
405 return 0
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200406}
407
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100408# Start a previously stopped a1pms
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200409# args: -
410# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100411start_stopped_a1pms() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100412 echo -e $BOLD"Starting (the previously stopped) $A1PMS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200413
raviteja.karumurif6dce272024-05-03 16:50:07 +0100414 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200415
raviteja.karumurif6dce272024-05-03 16:50:07 +0100416 __check_prestarted_image "A1PMS"
417 if [ $? -eq 0 ]; then
418 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
419 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
420 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
421 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
422 return 0
423 fi
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200424
raviteja.karumurif6dce272024-05-03 16:50:07 +0100425 # Tie the A1PMS to the same worker node it was initially started on
426 # 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
427 if [ -z "$__A1PMS_WORKER_NODE" ]; then
428 echo -e $RED" No initial worker node found for pod "$RED
429 ((RES_CONF_FAIL++))
430 return 1
431 else
432 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
433 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
434 tmp=$(kubectl $KUBECONF patch deployment $A1PMS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__A1PMS_WORKER_NODE'"}}}}}')
435 if [ $? -ne 0 ]; then
436 echo -e $YELLOW" Cannot set nodeSelector to deployment for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
437 fi
438 __kube_scale deployment $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
439 fi
440 else
441 docker start $A1PMS_APP_NAME &>./tmp/.dockererr
442 if [ $? -ne 0 ]; then
443 __print_err "Could not start (the stopped) $A1PMS_APP_NAME" $@
444 cat ./tmp/.dockererr
445 ((RES_CONF_FAIL++))
446 return 1
447 fi
448 fi
449 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
450 if [ $? -ne 0 ]; then
451 return 1
452 fi
453 echo ""
454 return 0
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200455}
456
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200457# Function to prepare the a1pms configuration according to the current simulator configuration
BjornMagnussonXA7d7cb5f2023-04-11 10:32:56 +0200458# args: SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100459# (Function for test scripts)
BjornMagnussonXAf83c3622023-02-28 10:05:51 +0100460prepare_a1pms_config() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100461 echo -e $BOLD"Prepare A1PMS config"$EBOLD
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100462
raviteja.karumurif6dce272024-05-03 16:50:07 +0100463 echo " Writing a1pms config for "$A1PMS_APP_NAME" to file: "$2
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100464
raviteja.karumurif6dce272024-05-03 16:50:07 +0100465 if [ $# != 2 ] && [ $# != 4 ]; then
466 ((RES_CONF_FAIL++))
467 __print_err "need two or four args, SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]" $@
468 exit 1
469 fi
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100470
raviteja.karumurif6dce272024-05-03 16:50:07 +0100471 if [ $1 == "SDNC" ]; then
472 echo -e " Config$BOLD including SDNC$EBOLD configuration"
473 elif [ $1 == "NOSDNC" ]; then
474 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
475 else
476 ((RES_CONF_FAIL++))
477 __print_err "need three args, SDNC|NOSDNC <output-file> HEADER|NOHEADER" $@
478 exit 1
479 fi
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100480
raviteja.karumurif6dce272024-05-03 16:50:07 +0100481 config_json="\n {"
482 if [ $1 == "SDNC" ]; then
483 config_json=$config_json"\n \"controller\": ["
484 config_json=$config_json"\n {"
485 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
486 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
487 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
488 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
489 config_json=$config_json"\n }"
490 config_json=$config_json"\n ],"
491 fi
492 if [[ "$A1PMS_FEATURE_LEVEL" == *"NO-DMAAP"* ]]; then
493 :
494 else
495 config_json=$config_json"\n \"streams_publishes\": {"
496 config_json=$config_json"\n \"dmaap_publisher\": {"
497 config_json=$config_json"\n \"type\": \"message-router\","
498 config_json=$config_json"\n \"dmaap_info\": {"
499 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
500 config_json=$config_json"\n }"
501 config_json=$config_json"\n }"
502 config_json=$config_json"\n },"
503 config_json=$config_json"\n \"streams_subscribes\": {"
504 config_json=$config_json"\n \"dmaap_subscriber\": {"
505 config_json=$config_json"\n \"type\": \"message-router\","
506 config_json=$config_json"\n \"dmaap_info\": {"
507 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
508 config_json=$config_json"\n }"
509 config_json=$config_json"\n }"
510 config_json=$config_json"\n },"
511 fi
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100512
raviteja.karumurif6dce272024-05-03 16:50:07 +0100513 config_json=$config_json"\n \"ric\": ["
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100514
raviteja.karumurif6dce272024-05-03 16:50:07 +0100515 if [ $RUNMODE == "KUBE" ]; then
516 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
517 rics=""
518 ric_cntr=0
519 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
520 for im in $result; do
521 if [[ $im != *"-0" ]]; then
522 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
523 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
524 let ric_cntr=ric_cntr+1
525 fi
526 done
527 fi
528 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICMEDIATORSIM")].metadata.name}')
529 oranrics=""
530 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
531 for im in $result; do
532 if [[ $im != *"-0" ]]; then
533 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
534 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
535 oranrics=$oranrics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
536 let ric_cntr=ric_cntr+1
537 fi
538 done
539 fi
540 if [ $ric_cntr -eq 0 ]; then
541 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
542 fi
543 else
544 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=a1sim" --filter "status=running" --format {{.Names}})
545 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 +0000546
raviteja.karumurif6dce272024-05-03 16:50:07 +0100547 rics="$rics $oranrics"
rohithrajneesh931e0342023-11-06 18:02:22 +0000548
raviteja.karumurif6dce272024-05-03 16:50:07 +0100549 if [ $? -ne 0 ] || [ -z "$rics" ]; then
550 echo -e $RED" FAIL - the names of the running RIC Simulator or ORAN RIC cannot be retrieved." $ERED
551 ((RES_CONF_FAIL++))
552 exit 1
553 fi
554 fi
555 cntr=0
556 for ric in $rics; do
557 if [ $cntr -gt 0 ]; then
558 config_json=$config_json"\n ,"
559 fi
560 config_json=$config_json"\n {"
561 if [ $RUNMODE == "KUBE" ]; then
562 ric_id=${ric%.*.*} #extract pod id from full hosthame
563 ric_id=$(echo "$ric_id" | tr '-' '_')
564 else
565 ric_id=$(echo "$ric" | tr '-' '_') #ric var still needs underscore as it is different from the container name
566 fi
567 echo " Found a1 sim: "$ric
568 config_json=$config_json"\n \"name\": \"$ric_id\","
BjornMagnussonXA7d7cb5f2023-04-11 10:32:56 +0200569
raviteja.karumurif6dce272024-05-03 16:50:07 +0100570 xricfound=0
571 for xric in $oranrics; do
572 if [ $xric == $ric ]; then
573 xricfound=1
574 fi
575 done
576 if [ $xricfound -eq 0 ]; then
577 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
578 else
579 config_json=$config_json"\n \"baseUrl\": \"$RICMEDIATOR_SIM_HTTPX://$ric:$RICMEDIATOR_SIM_PORT\","
580 fi
581 if [ ! -z "$3" ]; then
582 if [[ $ric == "$3"* ]]; then
583 config_json=$config_json"\n \"customAdapterClass\": \"$4\","
584 fi
585 fi
586 if [ $1 == "SDNC" ]; then
587 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
588 fi
589 config_json=$config_json"\n \"managedElementIds\": ["
590 config_json=$config_json"\n \"me1_$ric_id\","
591 config_json=$config_json"\n \"me2_$ric_id\""
592 config_json=$config_json"\n ]"
593 config_json=$config_json"\n }"
594 let cntr=cntr+1
595 done
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100596
raviteja.karumurif6dce272024-05-03 16:50:07 +0100597 config_json=$config_json"\n ]"
598 config_json=$config_json"\n}"
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100599
raviteja.karumurif6dce272024-05-03 16:50:07 +0100600 config_json="{\"config\":"$config_json"}"
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100601
raviteja.karumurif6dce272024-05-03 16:50:07 +0100602 printf "$config_json" >$2
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100603
raviteja.karumurif6dce272024-05-03 16:50:07 +0100604 echo ""
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100605}
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200606
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100607# Load the the appl config for the a1pms into a config map
608a1pms_load_config() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100609 echo -e $BOLD"A1PMS - load config from "$EBOLD$1
610 data_json=$PWD/tmp/$A1PMS_DATA_FILE
611 cp $1 $data_json
612 output_yaml=$PWD/tmp/a1pms-cfd.yaml
613 __kube_create_configmap $A1PMS_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
614 echo ""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100615}
616
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100617# Turn on debug level tracing in the a1pms
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100618# args: -
619# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100620set_a1pms_debug() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100621 echo -e $BOLD"Setting a1pms debug logging"$EBOLD
622 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
623 result=$(__do_curl "$curlString")
624 if [ $? -ne 0 ]; then
625 __print_err "could not set debug mode" $@
626 ((RES_CONF_FAIL++))
627 return 1
628 fi
629 echo ""
630 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100631}
632
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100633# Turn on trace level tracing in the a1pms
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100634# args: -
635# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100636set_a1pms_trace() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100637 echo -e $BOLD"Setting a1pms trace logging"$EBOLD
638 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
639 result=$(__do_curl "$curlString")
640 if [ $? -ne 0 ]; then
641 __print_err "could not set trace mode" $@
642 ((RES_CONF_FAIL++))
643 return 1
644 fi
645 echo ""
646 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100647}
648
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100649# Perform curl retries when making direct call to the a1pms for the specified http response codes
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100650# Speace separated list of http response codes
651# args: [<response-code>]*
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100652use_a1pms_retries() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100653 echo -e $BOLD"Do curl retries to the a1pms REST inteface for these response codes:$@"$EBOLD
654 AGENT_RETRY_CODES=$@
655 echo ""
656 return
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100657}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100658
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100659# Check the a1pms logs for WARNINGs and ERRORs
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100660# args: -
661# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100662check_a1pms_logs() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100663 __check_container_logs "A1PMS" $A1PMS_APP_NAME $A1PMS_LOGPATH WARN ERR
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100664}
665
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100666#########################################################
667#### Test case functions A1 Policy management service
668#########################################################
669
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100670# 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 +0100671# This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
672# args: json:<url> <target-value> [<timeout-in-seconds]
673# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100674a1pms_equal() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100675 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >>$HTTPLOG
676 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
677 if [[ $1 == "json:"* ]]; then
678 if [ "$A1PMS_VERSION" == "V2" ]; then
679 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v2/" $1 "=" $2 $3
680 elif [ "$A1PMS_VERSION" == "V3" ]; then
681 echo "var test execution for V3"
682 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v1/" $1 "=" $2 $3
683 else
684 __var_test "A1PMS" $A1PMS_SERVICE_PATH"/" $1 "=" $2 $3
685 fi
686 return 0
687 fi
688 fi
689 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
690 return 1
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100691}
692
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100693# API Test function: GET /policies and V2 GET /v2/policy-instances
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100694# 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>]*]
695# 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 +0100696# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100697a1pms_api_get_policies() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100698 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100699
raviteja.karumurif6dce272024-05-03 16:50:07 +0100700 if [ "$A1PMS_VERSION" == "V2" ]; then
701 paramError=0
702 variableParams=$(($# - 4))
703 if [ $# -lt 4 ]; then
704 paramError=1
705 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
706 paramError=1
707 elif [ $# -gt 5 ] && [ $(($variableParams % 7)) -ne 0 ]; then
708 paramError=1
709 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100710
raviteja.karumurif6dce272024-05-03 16:50:07 +0100711 if [ $paramError -ne 0 ]; then
712 __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>]*]" $@
713 return 1
714 fi
715 else
716 paramError=0
717 variableParams=$(($# - 4))
718 if [ $# -lt 4 ]; then
719 paramError=1
720 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
721 paramError=1
722 elif [ $# -gt 5 ] && [ $(($variableParams % 5)) -ne 0 ]; then
723 paramError=1
724 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100725
raviteja.karumurif6dce272024-05-03 16:50:07 +0100726 if [ $paramError -ne 0 ]; then
727 __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>]*]" $@
728 return 1
729 fi
730 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100731
raviteja.karumurif6dce272024-05-03 16:50:07 +0100732 queryparams=""
733 if [ "$A1PMS_VERSION" == "V2" ]; then
734 if [ $2 != "NORIC" ]; then
735 queryparams="?ric_id="$2
736 fi
737 if [ $3 != "NOSERVICE" ]; then
738 if [ -z $queryparams ]; then
739 queryparams="?service_id="$3
740 else
741 queryparams=$queryparams"&service_id="$3
742 fi
743 fi
744 if [ $4 != "NOTYPE" ]; then
745 if [ -z $queryparams ]; then
746 queryparams="?policytype_id="$4
747 else
748 queryparams=$queryparams"&policytype_id="$4
749 fi
750 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100751
raviteja.karumurif6dce272024-05-03 16:50:07 +0100752 query="/v2/policy-instances"$queryparams
753 res="$(__do_curl_to_api A1PMS GET $query)"
754 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100755
raviteja.karumurif6dce272024-05-03 16:50:07 +0100756 if [ $status -ne $1 ]; then
757 __log_test_fail_status_code $1 $status
758 return 1
759 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100760
raviteja.karumurif6dce272024-05-03 16:50:07 +0100761 if [ $# -gt 4 ]; then
762 body=${res:0:${#res}-3}
763 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
764 targetJson="["
765 else
766 targetJson="["
767 arr=(${@:5})
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100768
raviteja.karumurif6dce272024-05-03 16:50:07 +0100769 for ((i = 0; i < $(($# - 4)); i = i + 7)); do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100770
raviteja.karumurif6dce272024-05-03 16:50:07 +0100771 if [ "$targetJson" != "[" ]; then
772 targetJson=$targetJson","
773 fi
774 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i + 1]}\",\"service_id\":\"${arr[$i + 2]}\",\"policytype_id\":"
775 if [ "${arr[$i + 3]}" == "EMPTY" ]; then
776 targetJson=$targetJson"\"\","
777 else
778 targetJson=$targetJson"\"${arr[$i + 3]}\","
779 fi
780 targetJson=$targetJson"\"transient\":${arr[$i + 4]},\"status_notification_uri\":\"${arr[$i + 5]}\","
781 file="./tmp/.p.json"
782 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i + 6]} >$file
783 json=$(cat $file)
784 targetJson=$targetJson"\"policy_data\":"$json"}"
785 done
786 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100787
raviteja.karumurif6dce272024-05-03 16:50:07 +0100788 targetJson=$targetJson"]"
789 targetJson="{\"policies\": $targetJson}"
790 echo "TARGET JSON: $targetJson" >>$HTTPLOG
791 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100792
raviteja.karumurif6dce272024-05-03 16:50:07 +0100793 if [ $res -ne 0 ]; then
794 __log_test_fail_body
795 return 1
796 fi
797 fi
798 else
799 if [ $2 != "NORIC" ]; then
800 queryparams="?ric="$2
801 fi
802 if [ $3 != "NOSERVICE" ]; then
803 if [ -z $queryparams ]; then
804 queryparams="?service="$3
805 else
806 queryparams=$queryparams"&service="$3
807 fi
808 fi
809 if [ $4 != "NOTYPE" ]; then
810 if [ -z $queryparams ]; then
811 queryparams="?type="$4
812 else
813 queryparams=$queryparams"&type="$4
814 fi
815 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100816
raviteja.karumurif6dce272024-05-03 16:50:07 +0100817 query="/policies"$queryparams
818 res="$(__do_curl_to_api A1PMS GET $query)"
819 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100820
raviteja.karumurif6dce272024-05-03 16:50:07 +0100821 if [ $status -ne $1 ]; then
822 __log_test_fail_status_code $1 $status
823 return 1
824 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100825
raviteja.karumurif6dce272024-05-03 16:50:07 +0100826 if [ $# -gt 4 ]; then
827 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
828 targetJson="["
829 else
830 body=${res:0:${#res}-3}
831 targetJson="["
832 arr=(${@:5})
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100833
raviteja.karumurif6dce272024-05-03 16:50:07 +0100834 for ((i = 0; i < $(($# - 4)); i = i + 5)); do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100835
raviteja.karumurif6dce272024-05-03 16:50:07 +0100836 if [ "$targetJson" != "[" ]; then
837 targetJson=$targetJson","
838 fi
839 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i + 1]}\",\"service\":\"${arr[$i + 2]}\",\"type\":"
840 if [ "${arr[$i + 3]}" == "EMPTY" ]; then
841 targetJson=$targetJson"\"\","
842 else
843 targetJson=$targetJson"\"${arr[$i + 3]}\","
844 fi
845 file="./tmp/.p.json"
846 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i + 4]} >$file
847 json=$(cat $file)
848 targetJson=$targetJson"\"json\":"$json"}"
849 done
850 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100851
raviteja.karumurif6dce272024-05-03 16:50:07 +0100852 targetJson=$targetJson"]"
853 echo "TARGET JSON: $targetJson" >>$HTTPLOG
854 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100855
raviteja.karumurif6dce272024-05-03 16:50:07 +0100856 if [ $res -ne 0 ]; then
857 __log_test_fail_body
858 return 1
859 fi
860 fi
861 fi
862 __collect_endpoint_stats "A1PMS" 00 "GET" $A1PMS_API_PREFIX"/v2/policy-instances" $status
863 __log_test_pass
864 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100865
866}
867
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100868# API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
869# args: <response-code> <policy-id> [<template-file>]
870# args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
871
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100872# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100873a1pms_api_get_policy() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100874 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100875
raviteja.karumurif6dce272024-05-03 16:50:07 +0100876 if [ "$A1PMS_VERSION" == "V2" ]; then
877 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
878 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
879 return 1
880 fi
881 query="/v2/policies/$UUID$2"
882 else
883 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
884 __print_err "<response-code> <policy-id> [<template-file>] " $@
885 return 1
886 fi
887 query="/policy?id=$UUID$2"
888 fi
889 res="$(__do_curl_to_api A1PMS GET $query)"
890 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100891
raviteja.karumurif6dce272024-05-03 16:50:07 +0100892 if [ $status -ne $1 ]; then
893 __log_test_fail_status_code $1 $status
894 return 1
895 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100896
raviteja.karumurif6dce272024-05-03 16:50:07 +0100897 if [ "$A1PMS_VERSION" == "V2" ]; then
898 if [ $# -eq 8 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100899
raviteja.karumurif6dce272024-05-03 16:50:07 +0100900 #Create a policy json to compare with
901 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100902
raviteja.karumurif6dce272024-05-03 16:50:07 +0100903 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
904 if [ $7 != "NOTRANSIENT" ]; then
905 targetJson=$targetJson", \"transient\":$7"
906 fi
907 if [ $6 != "NOTYPE" ]; then
908 targetJson=$targetJson", \"policytype_id\":\"$6\""
909 else
910 targetJson=$targetJson", \"policytype_id\":\"\""
911 fi
912 if [ $8 != "NOURL" ]; then
913 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
914 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100915
raviteja.karumurif6dce272024-05-03 16:50:07 +0100916 data=$(sed 's/XXX/'${2}'/g' $3)
917 targetJson=$targetJson", \"policy_data\":$data"
918 targetJson="{$targetJson}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100919
raviteja.karumurif6dce272024-05-03 16:50:07 +0100920 echo "TARGET JSON: $targetJson" >>$HTTPLOG
921 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
922 if [ $res -ne 0 ]; then
923 __log_test_fail_body
924 return 1
925 fi
926 fi
927 else
928 if [ $# -eq 3 ]; then
929 #Create a policy json to compare with
930 body=${res:0:${#res}-3}
931 file="./tmp/.p.json"
932 sed 's/XXX/'${2}'/g' $3 >$file
933 targetJson=$(<$file)
934 echo "TARGET JSON: $targetJson" >>$HTTPLOG
935 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
936 if [ $res -ne 0 ]; then
937 __log_test_fail_body
938 fi
939 fi
940 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100941
raviteja.karumurif6dce272024-05-03 16:50:07 +0100942 __collect_endpoint_stats "A1PMS" 01 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status
943 __log_test_pass
944 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100945}
946
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100947# API Test function: PUT /policy and V2 PUT /policies
948# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
949# 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 +0100950# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100951a1pms_api_put_policy() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100952 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100953
raviteja.karumurif6dce272024-05-03 16:50:07 +0100954 if [ "$A1PMS_VERSION" == "V2" ]; then
955 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
956 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
957 return 1
958 fi
959 else
960 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
961 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
962 return 1
963 fi
964 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100965
raviteja.karumurif6dce272024-05-03 16:50:07 +0100966 count=0
967 max=1
968 serv=$2
969 ric=$3
970 pt=$4
971 pid=$5
972 trans=$6
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100973
raviteja.karumurif6dce272024-05-03 16:50:07 +0100974 if [ "$A1PMS_VERSION" == "V2" ]; then
975 noti=$7
976 temp=$8
977 if [ $# -eq 9 ]; then
978 max=$9
979 fi
980 else
981 temp=$7
982 if [ $# -eq 8 ]; then
983 max=$8
984 fi
985 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100986
raviteja.karumurif6dce272024-05-03 16:50:07 +0100987 while [ $count -lt $max ]; do
988 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100989
raviteja.karumurif6dce272024-05-03 16:50:07 +0100990 query="/v2/policies"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100991
raviteja.karumurif6dce272024-05-03 16:50:07 +0100992 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
993 if [ $trans != "NOTRANSIENT" ]; then
994 inputJson=$inputJson", \"transient\":$trans"
995 fi
996 if [ $pt != "NOTYPE" ]; then
997 inputJson=$inputJson", \"policytype_id\":\"$pt\""
998 else
999 inputJson=$inputJson", \"policytype_id\":\"\""
1000 fi
1001 if [ $noti != "NOURL" ]; then
1002 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1003 fi
1004 file="./tmp/.p.json"
1005 data=$(sed 's/XXX/'${pid}'/g' $temp)
1006 inputJson=$inputJson", \"policy_data\":$data"
1007 inputJson="{$inputJson}"
1008 echo $inputJson >$file
1009 else
1010 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001011
raviteja.karumurif6dce272024-05-03 16:50:07 +01001012 if [ $pt != "NOTYPE" ]; then
1013 query=$query"&type=$pt"
1014 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001015
raviteja.karumurif6dce272024-05-03 16:50:07 +01001016 if [ $trans != NOTRANSIENT ]; then
1017 query=$query"&transient=$trans"
1018 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001019
raviteja.karumurif6dce272024-05-03 16:50:07 +01001020 file="./tmp/.p.json"
1021 sed 's/XXX/'${pid}'/g' $temp >$file
1022 fi
1023 res="$(__do_curl_to_api A1PMS PUT $query $file)"
1024 status=${res:${#res}-3}
1025 echo -ne " Executing "$count"("$max")${SAMELINE}"
1026 if [ $status -ne $1 ]; then
1027 echo " Executed "$count"?("$max")"
1028 __log_test_fail_status_code $1 $status
1029 return 1
1030 fi
1031 let pid=$pid+1
1032 let count=$count+1
1033 echo -ne " Executed "$count"("$max")${SAMELINE}"
1034 done
1035 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $status $max
1036 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001037
raviteja.karumurif6dce272024-05-03 16:50:07 +01001038 __log_test_pass
1039 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001040}
1041
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001042# API Test function: PUT /policy and V2 PUT /policies, to run in batch
1043# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1044# 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 +02001045# (Function for test scripts)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001046
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001047a1pms_api_put_policy_batch() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001048 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001049
raviteja.karumurif6dce272024-05-03 16:50:07 +01001050 if [ "$A1PMS_VERSION" == "V2" ]; then
1051 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1052 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1053 return 1
1054 fi
1055 else
1056 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1057 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1058 return 1
1059 fi
1060 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001061
raviteja.karumurif6dce272024-05-03 16:50:07 +01001062 count=0
1063 max=1
1064 serv=$2
1065 ric=$3
1066 pt=$4
1067 pid=$5
1068 trans=$6
1069 if [ "$A1PMS_VERSION" == "V2" ]; then
1070 noti=$7
1071 temp=$8
1072 if [ $# -eq 9 ]; then
1073 max=$9
1074 fi
1075 else
1076 temp=$7
1077 if [ $# -eq 8 ]; then
1078 max=$8
1079 fi
1080 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001081
raviteja.karumurif6dce272024-05-03 16:50:07 +01001082 ARR=""
1083 while [ $count -lt $max ]; do
1084 if [ "$A1PMS_VERSION" == "V2" ]; then
1085 query="/v2/policies"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001086
raviteja.karumurif6dce272024-05-03 16:50:07 +01001087 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1088 if [ $trans != "NOTRANSIENT" ]; then
1089 inputJson=$inputJson", \"transient\":$trans"
1090 fi
1091 if [ $pt != "NOTYPE" ]; then
1092 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1093 else
1094 inputJson=$inputJson", \"policytype_id\":\"\""
1095 fi
1096 if [ $noti != "NOURL" ]; then
1097 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1098 fi
1099 file="./tmp/.p.json"
1100 data=$(sed 's/XXX/'${pid}'/g' $temp)
1101 inputJson=$inputJson", \"policy_data\":$data"
1102 inputJson="{$inputJson}"
1103 echo $inputJson >$file
1104 else
1105 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001106
raviteja.karumurif6dce272024-05-03 16:50:07 +01001107 if [ $pt != "NOTYPE" ]; then
1108 query=$query"&type=$pt"
1109 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001110
raviteja.karumurif6dce272024-05-03 16:50:07 +01001111 if [ $trans != NOTRANSIENT ]; then
1112 query=$query"&transient=$trans"
1113 fi
1114 file="./tmp/.p.json"
1115 sed 's/XXX/'${pid}'/g' $temp >$file
1116 fi
1117 res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)"
1118 status=${res:${#res}-3}
1119 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001120
raviteja.karumurif6dce272024-05-03 16:50:07 +01001121 if [ $status -ne 200 ]; then
1122 echo " Requested(batch) "$count"?("$max")"
1123 __log_test_fail_status_code 200 $status
1124 return 1
1125 fi
1126 cid=${res:0:${#res}-3}
1127 ARR=$ARR" "$cid
1128 let pid=$pid+1
1129 let count=$count+1
1130 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1131 done
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001132
raviteja.karumurif6dce272024-05-03 16:50:07 +01001133 echo ""
1134 count=0
1135 for cid in $ARR; do
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001136
raviteja.karumurif6dce272024-05-03 16:50:07 +01001137 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1138 status=${res:${#res}-3}
1139 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001140
raviteja.karumurif6dce272024-05-03 16:50:07 +01001141 if [ $status -ne $1 ]; then
1142 echo " Accepted(batch) "$count"?("$max")"
1143 __log_test_fail_status_code $1 $status
1144 return 1
1145 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001146
raviteja.karumurif6dce272024-05-03 16:50:07 +01001147 let count=$count+1
1148 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1149 done
1150 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001151
raviteja.karumurif6dce272024-05-03 16:50:07 +01001152 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001153
raviteja.karumurif6dce272024-05-03 16:50:07 +01001154 __log_test_pass
1155 return 0
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001156}
1157
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001158# 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 +02001159# 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 +01001160# 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 +02001161# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001162a1pms_api_put_policy_parallel() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001163 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001164
raviteja.karumurif6dce272024-05-03 16:50:07 +01001165 if [ "$A1PMS_VERSION" == "V2" ]; then
1166 if [ $# -ne 11 ]; then
1167 __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>" $@
1168 return 1
1169 fi
1170 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001171
raviteja.karumurif6dce272024-05-03 16:50:07 +01001172 resp_code=$1
1173 shift
1174 serv=$1
1175 shift
1176 ric_base=$1
1177 shift
1178 num_rics=$1
1179 shift
1180 type=$1
1181 shift
1182 start_id=$1
1183 shift
1184 transient=$1
1185 shift
1186 if [ "$A1PMS_VERSION" == "V2" ]; then
1187 noti=$1
1188 shift
1189 else
1190 noti=""
1191 fi
1192 template=$1
1193 shift
1194 count=$1
1195 shift
1196 pids=$1
1197 shift
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001198
raviteja.karumurif6dce272024-05-03 16:50:07 +01001199 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1200 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1201 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1202 echo " Info - will execute over a1pms REST"
1203 fi
1204 if [ "$A1PMS_VERSION" == "V2" ]; then
1205 if [ $serv == "NOSERVICE" ]; then
1206 serv=""
1207 fi
1208 query="$A1PMS_API_PREFIX/v2/policies"
1209 else
1210 if [ $serv == "NOSERVICE" ]; then
1211 serv=""
1212 fi
1213 query="/policy?service=$serv"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001214
raviteja.karumurif6dce272024-05-03 16:50:07 +01001215 if [ $type != "NOTYPE" ]; then
1216 query=$query"&type=$type"
1217 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001218
raviteja.karumurif6dce272024-05-03 16:50:07 +01001219 if [ $transient != NOTRANSIENT ]; then
1220 query=$query"&transient=$transient"
1221 fi
1222 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001223
raviteja.karumurif6dce272024-05-03 16:50:07 +01001224 urlbase=${A1PMS_ADAPTER}${query}
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001225
raviteja.karumurif6dce272024-05-03 16:50:07 +01001226 httpproxy="NOPROXY"
1227 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1228 httpproxy=$KUBE_PROXY_PATH
1229 fi
1230
1231 for ((i = 1; i <= $pids; i++)); do
1232 uuid=$UUID
1233 if [ -z "$uuid" ]; then
1234 uuid="NOUUID"
1235 fi
1236 echo "" >"./tmp/.pid${i}.res.txt"
1237 if [ "$A1PMS_VERSION" == "V2" ]; then
1238 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1239 else
1240 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1241 fi
1242 echo $i
1243 done | xargs -n 1 -I{} -P $pids bash -c '{
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001244 arg=$(echo {})
1245 echo " Parallel process $arg started"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001246 tmp=$(< "./tmp/.pid${arg}.txt")
1247 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001248 }'
raviteja.karumurif6dce272024-05-03 16:50:07 +01001249 msg=""
1250 for ((i = 1; i <= $pids; i++)); do
1251 file="./tmp/.pid${i}.res.txt"
1252 tmp=$(<$file)
1253 if [ -z "$tmp" ]; then
1254 echo " Process $i : unknown result (result file empty"
1255 msg="failed"
1256 else
1257 res=${tmp:0:1}
1258 if [ $res == "0" ]; then
1259 echo " Process $i : OK - "${tmp:1}
1260 else
1261 echo " Process $i : failed - "${tmp:1}
1262 msg="failed"
1263 fi
1264 fi
1265 done
1266 if [ -z $msg ]; then
1267 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count * $num_rics))
1268 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1269 return 0
1270 fi
1271 __log_test_fail_general "One of more processes failed to execute"
1272 return 1
1273}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001274
raviteja.karumurif6dce272024-05-03 16:50:07 +01001275# API Test function: V3 POST /policies, to run in i parallel for a number of rics
1276# 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>
1277# 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>
1278# (Function for test scripts)
1279a1pms_api_post_policy_parallel() {
1280 __log_test_start $@
1281
1282 if [ $# -ne 11 ]; then
1283 __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>" $@
1284 return 1
1285 fi
1286
1287 resp_code=$1
1288 shift
1289 serv=$1
1290 shift
1291 ric_base=$1
1292 shift
1293 num_rics=$1
1294 shift
1295 type=$1
1296 shift
1297 start_id=$1
1298 shift
1299 transient=$1
1300 shift
1301 noti=$1
1302 shift
1303 template=$1
1304 shift
1305 count=$1
1306 shift
1307 pids=$1
1308 shift
1309
1310 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1311 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1312 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1313 echo " Info - will execute over a1pms REST"
1314 fi
1315
1316 if [ $serv == "NOSERVICE" ]; then
1317 serv=""
1318 fi
1319 query="$A1PMS_API_PREFIX/v1/policies"
1320
1321 urlbase=${A1PMS_ADAPTER}${query}
1322
1323 httpproxy="NOPROXY"
1324 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1325 httpproxy=$KUBE_PROXY_PATH
1326 fi
1327
1328 for ((i = 1; i <= $pids; i++)); do
1329 uuid=$UUID
1330 if [ -z "$uuid" ]; then
1331 uuid="NOUUID"
1332 fi
1333 echo "" >"./tmp/.pid${i}.res.txt"
1334 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1335 echo $i
1336 done | xargs -n 1 -I{} -P $pids bash -c '{
1337 arg=$(echo {})
1338 echo " Parallel process $arg started"
1339 tmp=$(< "./tmp/.pid${arg}.txt")
1340 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1341 }'
1342 msg=""
1343 for ((i = 1; i <= $pids; i++)); do
1344 file="./tmp/.pid${i}.res.txt"
1345 tmp=$(<$file)
1346 if [ -z "$tmp" ]; then
1347 echo " Process $i : unknown result (result file empty"
1348 msg="failed"
1349 else
1350 res=${tmp:0:1}
1351 if [ $res == "0" ]; then
1352 echo " Process $i : OK - "${tmp:1}
1353 else
1354 echo " Process $i : failed - "${tmp:1}
1355 msg="failed"
1356 fi
1357 fi
1358 done
1359 if [ -z $msg ]; then
1360 __collect_endpoint_stats "A1PMS" 02 "POST" $A1PMS_API_PREFIX"/v1/policies" $resp_code $(($count * $num_rics))
1361 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1362 return 0
1363 fi
1364 __log_test_fail_general "One of more processes failed to execute"
1365 return 1
1366}
1367
1368# API Test function: V3 PUT /policies, to run in i parallel for a number of rics
1369# 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>
1370# 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>
1371# (Function for test scripts)
1372a1pms_api_update_policy_parallel() {
1373 __log_test_start $@
1374
1375 if [ $# -ne 12 ]; then
1376 __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>" $@
1377 return 1
1378 fi
1379
1380 resp_code=$1
1381 shift
1382 serv=$1
1383 shift
1384 ric_base=$1
1385 shift
1386 num_rics=$1
1387 shift
1388 type=$1
1389 shift
1390 start_id=$1
1391 shift
1392 transient=$1
1393 shift
1394 noti=$1
1395 shift
1396 template=$1
1397 shift
1398 count=$1
1399 shift
1400 pids=$1
1401 shift
1402 policy_ids_file_path=$1
1403 shift
1404
1405 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1406 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1407 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1408 echo " Info - will execute over a1pms REST"
1409 fi
1410
1411 if [ $serv == "NOSERVICE" ]; then
1412 serv=""
1413 fi
1414 query="$A1PMS_API_PREFIX/v1/policies"
1415
1416 urlbase=${A1PMS_ADAPTER}${query}
1417
1418 httpproxy="NOPROXY"
1419 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1420 httpproxy=$KUBE_PROXY_PATH
1421 fi
1422
1423 for ((i = 1; i <= $pids; i++)); do
1424 uuid=$UUID
1425 if [ -z "$uuid" ]; then
1426 uuid="NOUUID"
1427 fi
1428 echo "" >"./tmp/.pid${i}.res.txt"
1429 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"
1430 echo $i
1431 done | xargs -n 1 -I{} -P $pids bash -c '{
1432 arg=$(echo {})
1433 echo " Parallel process $arg started"
1434 tmp=$(< "./tmp/.pid${arg}.txt")
1435 python3 ../common/update_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1436 }'
1437 msg=""
1438 for ((i = 1; i <= $pids; i++)); do
1439 file="./tmp/.pid${i}.res.txt"
1440 tmp=$(<$file)
1441 if [ -z "$tmp" ]; then
1442 echo " Process $i : unknown result (result file empty"
1443 msg="failed"
1444 else
1445 res=${tmp:0:1}
1446 if [ $res == "0" ]; then
1447 echo " Process $i : OK - "${tmp:1}
1448 else
1449 echo " Process $i : failed - "${tmp:1}
1450 msg="failed"
1451 fi
1452 fi
1453 done
1454 if [ -z $msg ]; then
1455 __collect_endpoint_stats "A1PMS" 02 "POST" $A1PMS_API_PREFIX"/v1/policies" $resp_code $(($count * $num_rics))
1456 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1457 return 0
1458 fi
1459 __log_test_fail_general "One of more processes failed to execute"
1460 return 1
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001461}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001462
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001463# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001464# args: <response-code> <policy-id> [count]
1465# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001466a1pms_api_delete_policy() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001467 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001468
raviteja.karumurif6dce272024-05-03 16:50:07 +01001469 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1470 __print_err "<response-code> <policy-id> [count]" $@
1471 return 1
1472 fi
1473
1474 count=0
1475 max=1
1476
1477 if [ $# -eq 3 ]; then
1478 max=$3
1479 fi
1480
1481 pid=$2
1482
1483 while [ $count -lt $max ]; do
1484 if [ "$A1PMS_VERSION" == "V2" ]; then
1485 query="/v2/policies/"$UUID$pid
1486 else
1487 query="/policy?id="$UUID$pid
1488 fi
1489 res="$(__do_curl_to_api A1PMS DELETE $query)"
1490 status=${res:${#res}-3}
1491 echo -ne " Executing "$count"("$max")${SAMELINE}"
1492
1493 if [ $status -ne $1 ]; then
1494 echo " Executed "$count"?("$max")"
1495 __log_test_fail_status_code $1 $status
1496 return 1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001497 fi
1498
raviteja.karumurif6dce272024-05-03 16:50:07 +01001499 let pid=$pid+1
1500 let count=$count+1
1501 echo -ne " Executed "$count"("$max")${SAMELINE}"
1502 done
1503 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status $max
1504 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001505
raviteja.karumurif6dce272024-05-03 16:50:07 +01001506 __log_test_pass
1507 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001508}
1509
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001510# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001511# args: <response-code> <policy-id> [count]
1512# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001513a1pms_api_delete_policy_batch() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001514 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001515
raviteja.karumurif6dce272024-05-03 16:50:07 +01001516 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1517 __print_err "<response-code> <policy-id> [count]" $@
1518 return 1
1519 fi
1520
1521 count=0
1522 max=1
1523
1524 if [ $# -eq 3 ]; then
1525 max=$3
1526 fi
1527
1528 pid=$2
1529 ARR=""
1530 while [ $count -lt $max ]; do
1531 if [ "$A1PMS_VERSION" == "V2" ]; then
1532 query="/v2/policies/"$UUID$pid
1533 else
1534 query="/policy?id="$UUID$pid
1535 fi
1536 res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)"
1537 status=${res:${#res}-3}
1538 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1539
1540 if [ $status -ne 200 ]; then
1541 echo " Requested(batch) "$count"?("$max")"
1542 __log_test_fail_status_code 200 $status
1543 return 1
1544 fi
1545 cid=${res:0:${#res}-3}
1546 ARR=$ARR" "$cid
1547 let pid=$pid+1
1548 let count=$count+1
1549 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1550 done
1551
1552 echo ""
1553
1554 count=0
1555 for cid in $ARR; do
1556
1557 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1558 status=${res:${#res}-3}
1559 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1560
1561 if [ $status -ne $1 ]; then
1562 echo " Deleted(batch) "$count"?("$max")"
1563 __log_test_fail_status_code $1 $status
1564 return 1
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001565 fi
1566
raviteja.karumurif6dce272024-05-03 16:50:07 +01001567 let count=$count+1
1568 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1569 done
1570 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001571
raviteja.karumurif6dce272024-05-03 16:50:07 +01001572 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001573
raviteja.karumurif6dce272024-05-03 16:50:07 +01001574 __log_test_pass
1575 return 0
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001576}
1577
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001578# 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 +02001579# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1580# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001581a1pms_api_delete_policy_parallel() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001582 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001583
raviteja.karumurif6dce272024-05-03 16:50:07 +01001584 if [ $# -ne 5 ]; then
1585 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1586 return 1
1587 fi
1588 resp_code=$1
1589 shift
1590 num_rics=$1
1591 shift
1592 start_id=$1
1593 shift
1594 count=$1
1595 shift
1596 pids=$1
1597 shift
1598
1599 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1600 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1601 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported"
1602 echo " Info - will execute over a1pms REST"
1603 fi
1604
1605 if [ "$A1PMS_VERSION" == "V2" ]; then
1606 query="$A1PMS_API_PREFIX/v2/policies/"
1607 else
1608 query="/policy"
1609 fi
1610
1611 urlbase=${A1PMS_ADAPTER}${query}
1612
1613 httpproxy="NOPROXY"
1614 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1615 httpproxy=$KUBE_PROXY_PATH
1616 fi
1617
1618 for ((i = 1; i <= $pids; i++)); do
1619 uuid=$UUID
1620 if [ -z "$uuid" ]; then
1621 uuid="NOUUID"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001622 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01001623 echo "" >"./tmp/.pid${i}.del.res.txt"
1624 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy >"./tmp/.pid${i}.del.txt"
1625 echo $i
1626 done | xargs -n 1 -I{} -P $pids bash -c '{
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001627 arg=$(echo {})
1628 echo " Parallel process $arg started"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001629 tmp=$(< "./tmp/.pid${arg}.del.txt")
1630 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001631 }'
raviteja.karumurif6dce272024-05-03 16:50:07 +01001632 msg=""
1633 for ((i = 1; i <= $pids; i++)); do
1634 file="./tmp/.pid${i}.del.res.txt"
1635 tmp=$(<$file)
1636 if [ -z "$tmp" ]; then
1637 echo " Process $i : unknown result (result file empty"
1638 msg="failed"
1639 else
1640 res=${tmp:0:1}
1641 if [ $res == "0" ]; then
1642 echo " Process $i : OK - "${tmp:1}
1643 else
1644 echo " Process $i : failed - "${tmp:1}
1645 msg="failed"
1646 fi
1647 fi
1648 done
1649 if [ -z $msg ]; then
1650 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count * $num_rics))
1651 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1652 return 0
1653 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001654
raviteja.karumurif6dce272024-05-03 16:50:07 +01001655 __log_test_fail_general "One of more processes failed to execute"
1656 return 1
1657}
1658
1659# API Test function: V3 DELETE a1policymanagement/v1/policies/{policy_id}, to run in i parallel for a number of rics
1660# args: <responseCode> <numberOfRics> <PolicyIdsFilePath> <countPerRic> <numberOfThreads>
1661# (Function for test scripts)
1662a1pms_api_delete_policy_parallel_v3() {
1663 __log_test_start $@
1664
1665 if [ $# -ne 6 ]; then
1666 __print_err " <responseCode> <numberOfRics> <PolicyIdsFilePath> <StartID> <countPerRic> <numberOfThreads>" $@
1667 return 1
1668 fi
1669 resp_code=$1
1670 shift
1671 num_rics=$1
1672 shift
1673 policy_ids_file_path=$1
1674 shift
1675 start_id=$1
1676 shift
1677 count=$1
1678 shift
1679 pids=$1
1680 shift
1681
1682 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1683 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1684 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported"
1685 echo " Info - will execute over a1pms REST"
1686 fi
1687
1688 query="$A1PMS_API_PREFIX/v1/policies/"
1689 urlbase=${A1PMS_ADAPTER}${query}
1690
1691 urlbase=${A1PMS_ADAPTER}${query}
1692
1693 httpproxy="NOPROXY"
1694 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1695 httpproxy=$KUBE_PROXY_PATH
1696 fi
1697
1698 for ((i = 1; i <= $pids; i++)); do
1699 echo "" >"./tmp/.pid${i}.del.res.txt"
1700 echo $resp_code $urlbase $policy_ids_file_path $start_id $pids $i $httpproxy >"./tmp/.pid${i}.del.txt"
1701 echo $i
1702 done | xargs -n 1 -I{} -P $pids bash -c '{
1703 arg=$(echo {})
1704 echo " Parallel process $arg started"
1705 tmp=$(< "./tmp/.pid${arg}.del.txt")
1706 python3 ../common/delete_policies_process_v3.py $tmp > ./tmp/.pid${arg}.del.res.txt
1707 }'
1708 msg=""
1709 for ((i = 1; i <= $pids; i++)); do
1710 file="./tmp/.pid${i}.del.res.txt"
1711 tmp=$(<$file)
1712 if [ -z "$tmp" ]; then
1713 echo " Process $i : unknown result (result file empty"
1714 msg="failed"
1715 else
1716 res=${tmp:0:1}
1717 if [ $res == "0" ]; then
1718 echo " Process $i : OK - "${tmp:1}
1719 else
1720 echo " Process $i : failed - "${tmp:1}
1721 msg="failed"
1722 fi
1723 fi
1724 done
1725 if [ -z $msg ]; then
1726 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v1/policies/{policy_id}" $resp_code $(($count * $num_rics))
1727 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1728 return 0
1729 fi
1730
1731 __log_test_fail_general "One of more processes failed to execute"
1732 return 1
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001733}
1734
JohnKeeney2f3b2682024-03-22 16:56:46 +00001735# API Test function: GET /policy and V2 GET /v2/policies/{policy_id}, to run in i parallel for a number of rics
1736# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1737# (Function for test scripts)
1738a1pms_api_get_policy_parallel() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001739 __log_test_start $@
JohnKeeney2f3b2682024-03-22 16:56:46 +00001740
raviteja.karumurif6dce272024-05-03 16:50:07 +01001741 if [ $# -ne 5 ]; then
1742 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1743 return 1
1744 fi
1745 resp_code=$1
1746 shift
1747 num_rics=$1
1748 shift
1749 start_id=$1
1750 shift
1751 count=$1
1752 shift
1753 pids=$1
1754 shift
1755
1756 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1757 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1758 echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported"
1759 echo " Info - will execute over a1pms REST"
1760 fi
1761
1762 if [ "$A1PMS_VERSION" == "V2" ]; then
1763 query="$A1PMS_API_PREFIX/v2/policies/"
1764 else
1765 query="/policy"
1766 fi
1767
1768 urlbase=${A1PMS_ADAPTER}${query}
1769
1770 httpproxy="NOPROXY"
1771 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1772 httpproxy=$KUBE_PROXY_PATH
1773 fi
1774
1775 for ((i = 1; i <= $pids; i++)); do
1776 uuid=$UUID
1777 if [ -z "$uuid" ]; then
1778 uuid="NOUUID"
JohnKeeney2f3b2682024-03-22 16:56:46 +00001779 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01001780 echo "" >"./tmp/.pid${i}.get.res.txt"
1781 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy >"./tmp/.pid${i}.get.txt"
1782 echo $i
1783 done | xargs -n 1 -I{} -P $pids bash -c '{
JohnKeeney2f3b2682024-03-22 16:56:46 +00001784 arg=$(echo {})
1785 echo " Parallel process $arg started"
1786 tmp=$(< "./tmp/.pid${arg}.get.txt")
1787 python3 ../common/get_policies_process.py $tmp > ./tmp/.pid${arg}.get.res.txt
1788 }'
raviteja.karumurif6dce272024-05-03 16:50:07 +01001789 msg=""
1790 for ((i = 1; i <= $pids; i++)); do
1791 file="./tmp/.pid${i}.get.res.txt"
1792 tmp=$(<$file)
1793 if [ -z "$tmp" ]; then
1794 echo " Process $i : unknown result (result file empty"
1795 msg="failed"
1796 else
1797 res=${tmp:0:1}
1798 if [ $res == "0" ]; then
1799 echo " Process $i : OK - "${tmp:1}
1800 else
1801 echo " Process $i : failed - "${tmp:1}
1802 msg="failed"
1803 fi
1804 fi
1805 done
1806 if [ -z $msg ]; then
1807 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count * $num_rics))
1808 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1809 return 0
1810 fi
JohnKeeney2f3b2682024-03-22 16:56:46 +00001811
raviteja.karumurif6dce272024-05-03 16:50:07 +01001812 __log_test_fail_general "One of more processes failed to execute"
1813 return 1
1814}
1815
1816# API Test function: V3 GET a1policymanagement/v1/policies/{policy_id}, to run in i parallel for a number of rics
1817# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1818# (Function for test scripts)
1819a1pms_api_get_policy_parallel_v3() {
1820 __log_test_start $@
1821
1822 if [ $# -ne 6 ]; then
1823 __print_err " <responseCode> <numberOfRics> <PolicyIdsFilePath> <startID> <countPerRic> <numberOfThreads>" $@
1824 return 1
1825 fi
1826 resp_code=$1
1827 shift
1828 num_rics=$1
1829 shift
1830 policy_ids_file_path=$1
1831 shift
1832 start_id=$1
1833 shift
1834 count=$1
1835 shift
1836 pids=$1
1837 shift
1838
1839 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1840 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1841 echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported"
1842 echo " Info - will execute over a1pms REST"
1843 fi
1844
1845 query="$A1PMS_API_PREFIX/v1/policies/"
1846 urlbase=${A1PMS_ADAPTER}${query}
1847
1848 httpproxy="NOPROXY"
1849 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1850 httpproxy=$KUBE_PROXY_PATH
1851 fi
1852
1853 for ((i = 1; i <= $pids; i++)); do
1854 echo "" >"./tmp/.pid${i}.get.res.txt"
1855 echo $resp_code $urlbase $policy_ids_file_path $start_id $pids $i $httpproxy >"./tmp/.pid${i}.get.txt"
1856 echo $i
1857 done | xargs -n 1 -I{} -P $pids bash -c '{
1858 arg=$(echo {})
1859 echo " Parallel process $arg started"
1860 tmp=$(< "./tmp/.pid${arg}.get.txt")
1861 python3 ../common/get_policies_process_v3.py $tmp > ./tmp/.pid${arg}.get.res.txt
1862 }'
1863 msg=""
1864 for ((i = 1; i <= $pids; i++)); do
1865 file="./tmp/.pid${i}.get.res.txt"
1866 tmp=$(<$file)
1867 if [ -z "$tmp" ]; then
1868 echo " Process $i : unknown result (result file empty"
1869 msg="failed"
1870 else
1871 res=${tmp:0:1}
1872 if [ $res == "0" ]; then
1873 echo " Process $i : OK - "${tmp:1}
1874 else
1875 echo " Process $i : failed - "${tmp:1}
1876 msg="failed"
1877 fi
1878 fi
1879 done
1880 if [ -z $msg ]; then
1881 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v1/policies/{policyId}" $resp_code $(($count * $num_rics))
1882 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1883 return 0
1884 fi
1885
1886 __log_test_fail_general "One of more processes failed to execute"
1887 return 1
JohnKeeney2f3b2682024-03-22 16:56:46 +00001888}
1889
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001890# API Test function: GET /policy_ids and V2 GET /v2/policies
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001891# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1892# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001893a1pms_api_get_policy_ids() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001894 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001895
raviteja.karumurif6dce272024-05-03 16:50:07 +01001896 if [ $# -lt 4 ]; then
1897 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1898 return 1
1899 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001900
raviteja.karumurif6dce272024-05-03 16:50:07 +01001901 queryparams=""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001902
raviteja.karumurif6dce272024-05-03 16:50:07 +01001903 if [ "$A1PMS_VERSION" == "V2" ]; then
1904 if [ $2 != "NORIC" ]; then
1905 queryparams="?ric_id="$2
1906 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001907
raviteja.karumurif6dce272024-05-03 16:50:07 +01001908 if [ $3 != "NOSERVICE" ]; then
1909 if [ -z $queryparams ]; then
1910 queryparams="?service_id="$3
1911 else
1912 queryparams=$queryparams"&service_id="$3
1913 fi
1914 fi
1915 if [ $4 != "NOTYPE" ]; then
1916 if [ -z $queryparams ]; then
1917 queryparams="?policytype_id="$4
1918 else
1919 queryparams=$queryparams"&policytype_id="$4
1920 fi
1921 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001922
raviteja.karumurif6dce272024-05-03 16:50:07 +01001923 query="/v2/policies"$queryparams
1924 else
1925 if [ $2 != "NORIC" ]; then
1926 queryparams="?ric="$2
1927 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001928
raviteja.karumurif6dce272024-05-03 16:50:07 +01001929 if [ $3 != "NOSERVICE" ]; then
1930 if [ -z $queryparams ]; then
1931 queryparams="?service="$3
1932 else
1933 queryparams=$queryparams"&service="$3
1934 fi
1935 fi
1936 if [ $4 != "NOTYPE" ]; then
1937 if [ -z $queryparams ]; then
1938 queryparams="?type="$4
1939 else
1940 queryparams=$queryparams"&type="$4
1941 fi
1942 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001943
raviteja.karumurif6dce272024-05-03 16:50:07 +01001944 query="/policy_ids"$queryparams
1945 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001946
raviteja.karumurif6dce272024-05-03 16:50:07 +01001947 res="$(__do_curl_to_api A1PMS GET $query)"
1948 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001949
raviteja.karumurif6dce272024-05-03 16:50:07 +01001950 if [ $status -ne $1 ]; then
1951 __log_test_fail_status_code $1 $status
1952 return 1
1953 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001954
raviteja.karumurif6dce272024-05-03 16:50:07 +01001955 if [ $# -gt 4 ]; then
1956 body=${res:0:${#res}-3}
1957 targetJson="["
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001958
raviteja.karumurif6dce272024-05-03 16:50:07 +01001959 for pid in ${@:5}; do
1960 if [ "$targetJson" != "[" ]; then
1961 targetJson=$targetJson","
1962 fi
1963 if [ $pid != "NOID" ]; then
1964 targetJson=$targetJson"\"$UUID$pid\""
1965 fi
1966 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001967
raviteja.karumurif6dce272024-05-03 16:50:07 +01001968 targetJson=$targetJson"]"
1969 if [ "$A1PMS_VERSION" == "V2" ]; then
1970 targetJson="{\"policy_ids\": $targetJson}"
1971 fi
1972 echo "TARGET JSON: $targetJson" >>$HTTPLOG
1973 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001974
raviteja.karumurif6dce272024-05-03 16:50:07 +01001975 if [ $res -ne 0 ]; then
1976 __log_test_fail_body
1977 return 1
1978 fi
1979 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001980
raviteja.karumurif6dce272024-05-03 16:50:07 +01001981 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status
1982 __log_test_pass
1983 return 0
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001984}
1985
1986# API Test function: V2 GET /v2/policy-types/{policyTypeId}
1987# args(V2): <response-code> <policy-type-id> [<schema-file>]
1988# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001989a1pms_api_get_policy_type() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001990 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001991
raviteja.karumurif6dce272024-05-03 16:50:07 +01001992 if [ "$A1PMS_VERSION" != "V2" ]; then
1993 __log_test_fail_not_supported
1994 return 1
1995 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001996
raviteja.karumurif6dce272024-05-03 16:50:07 +01001997 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1998 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1999 return 1
2000 fi
2001 query="/v2/policy-types/$2"
2002
2003 res="$(__do_curl_to_api A1PMS GET $query)"
2004 status=${res:${#res}-3}
2005
2006 if [ $status -ne $1 ]; then
2007 __log_test_fail_status_code $1 $status
2008 return 1
2009 fi
2010
2011 if [ $# -eq 3 ]; then
2012
2013 body=${res:0:${#res}-3}
2014
2015 targetJson=$(<$3)
2016 targetJson="{\"policy_schema\":$targetJson}"
2017 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2018 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2019
2020 if [ $res -ne 0 ]; then
2021 __log_test_fail_body
2022 return 1
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002023 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002024 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002025
raviteja.karumurif6dce272024-05-03 16:50:07 +01002026 __collect_endpoint_stats "A1PMS" 05 "GET" $A1PMS_API_PREFIX"/v2/policy-types/{policyTypeId}" $status
2027 __log_test_pass
2028 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002029}
2030
2031# API Test function: GET /policy_schema
2032# args: <response-code> <policy-type-id> [<schema-file>]
2033# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002034a1pms_api_get_policy_schema() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002035 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002036
raviteja.karumurif6dce272024-05-03 16:50:07 +01002037 if [ "$A1PMS_VERSION" == "V2" ]; then
2038 __log_test_fail_not_supported
2039 return 1
2040 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002041
raviteja.karumurif6dce272024-05-03 16:50:07 +01002042 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2043 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
2044 return 1
2045 fi
2046 query="/policy_schema?id=$2"
2047 res="$(__do_curl_to_api A1PMS GET $query)"
2048 status=${res:${#res}-3}
2049
2050 if [ $status -ne $1 ]; then
2051 __log_test_fail_status_code $1 $status
2052 return 1
2053 fi
2054
2055 if [ $# -eq 3 ]; then
2056
2057 body=${res:0:${#res}-3}
2058
2059 targetJson=$(<$3)
2060
2061 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2062 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2063
2064 if [ $res -ne 0 ]; then
2065 __log_test_fail_body
2066 return 1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002067 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002068 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002069
raviteja.karumurif6dce272024-05-03 16:50:07 +01002070 __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status
2071 __log_test_pass
2072 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002073}
2074
2075# API Test function: GET /policy_schemas
2076# args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002077# args(V2): <response-code>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002078# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002079a1pms_api_get_policy_schemas() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002080 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002081
raviteja.karumurif6dce272024-05-03 16:50:07 +01002082 if [ "$A1PMS_VERSION" == "V2" ]; then
2083 if [ $# -ne 1 ]; then
2084 __print_err "<response-code>" $@
2085 return 1
2086 fi
2087 else
2088 if [ $# -lt 2 ]; then
2089 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
2090 return 1
2091 fi
2092 fi
2093 if [ "$A1PMS_VERSION" == "V2" ]; then
2094 query="/v2/policy-schemas"
2095 else
2096 query="/policy_schemas"
2097 if [ $2 != "NORIC" ]; then
2098 query=$query"?ric="$2
2099 fi
2100 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002101
raviteja.karumurif6dce272024-05-03 16:50:07 +01002102 res="$(__do_curl_to_api A1PMS GET $query)"
2103 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002104
raviteja.karumurif6dce272024-05-03 16:50:07 +01002105 if [ $status -ne $1 ]; then
2106 __log_test_fail_status_code $1 $status
2107 return 1
2108 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002109
raviteja.karumurif6dce272024-05-03 16:50:07 +01002110 if [ $# -gt 2 ]; then
2111 body=${res:0:${#res}-3}
2112 targetJson="["
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002113
raviteja.karumurif6dce272024-05-03 16:50:07 +01002114 for file in ${@:3}; do
2115 if [ "$targetJson" != "[" ]; then
2116 targetJson=$targetJson","
2117 fi
2118 if [ $file == "NOFILE" ]; then
2119 targetJson=$targetJson"{}"
2120 else
2121 targetJson=$targetJson$(<$file)
2122 fi
2123 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002124
raviteja.karumurif6dce272024-05-03 16:50:07 +01002125 targetJson=$targetJson"]"
2126 if [ "$A1PMS_VERSION" == "V2" ]; then
2127 targetJson="{\"policy_schemas\": $targetJson }"
2128 fi
2129 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2130 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002131
raviteja.karumurif6dce272024-05-03 16:50:07 +01002132 if [ $res -ne 0 ]; then
2133 __log_test_fail_body
2134 return 1
2135 fi
2136 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002137
raviteja.karumurif6dce272024-05-03 16:50:07 +01002138 __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status
2139 __log_test_pass
2140 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002141}
2142
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002143# API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002144# arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002145# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002146a1pms_api_get_policy_status() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002147 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002148
raviteja.karumurif6dce272024-05-03 16:50:07 +01002149 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2150 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
2151 return 1
2152 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002153
raviteja.karumurif6dce272024-05-03 16:50:07 +01002154 targetJson=""
2155 if [ $# -eq 2 ]; then
2156 :
2157 elif [ "$3" == "STD" ]; then
2158 targetJson="{\"enforceStatus\":\"$4\""
2159 if [ $# -eq 5 ]; then
2160 targetJson=$targetJson",\"reason\":\"$5\""
2161 fi
2162 targetJson=$targetJson"}"
2163 elif [ "$3" == "STD2" ]; then
2164 if [ $4 == "EMPTY" ]; then
2165 targetJson="{\"enforceStatus\":\"\""
2166 else
2167 targetJson="{\"enforceStatus\":\"$4\""
2168 fi
2169 if [ $# -eq 5 ]; then
2170 if [ $5 == "EMPTY" ]; then
2171 targetJson=$targetJson",\"enforceReason\":\"\""
2172 else
2173 targetJson=$targetJson",\"enforceReason\":\"$5\""
2174 fi
2175 fi
2176 targetJson=$targetJson"}"
2177 elif [ "$3" == "OSC" ]; then
2178 if [[ $TEST_ENV_PROFILE =~ ^ORAN-[A-H] ]] || [[ $TEST_ENV_PROFILE =~ ^ONAP-[A-L] ]]; then
raviteja.karumuri2c6c06e2024-05-27 10:58:44 +01002179 targetJson="{\"instance_status\":\"$4\""
2180 if [ $# -eq 5 ]; then
2181 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
2182 fi
2183 targetJson=$targetJson",\"created_at\":\"????\"}"
2184 else
2185 targetJson="{\"enforceStatus\":\"$4\""
2186 if [ $# -eq 5 ]; then
2187 targetJson=$targetJson",\"enforceReason\":\"$5\"}"
2188 fi
2189 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002190 else
2191 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
2192 return 1
2193 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002194
raviteja.karumurif6dce272024-05-03 16:50:07 +01002195 if [ "$A1PMS_VERSION" == "V2" ]; then
2196 query="/v2/policies/$UUID$2/status"
2197 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
2198 else
2199 query="/policy_status?id="$UUID$2
2200 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002201
raviteja.karumurif6dce272024-05-03 16:50:07 +01002202 res="$(__do_curl_to_api A1PMS GET $query)"
2203 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002204
raviteja.karumurif6dce272024-05-03 16:50:07 +01002205 if [ $status -ne $1 ]; then
2206 __log_test_fail_status_code $1 $status
2207 return 1
2208 fi
2209 if [ $# -gt 2 ]; then
2210 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2211 body=${res:0:${#res}-3}
2212 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002213
raviteja.karumurif6dce272024-05-03 16:50:07 +01002214 if [ $res -ne 0 ]; then
2215 __log_test_fail_body
2216 return 1
2217 fi
2218 fi
2219 __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
2220 __log_test_pass
2221 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002222}
2223
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002224# API Test function: GET /policy_types and V2 GET /v2/policy-types
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002225# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
2226# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002227a1pms_api_get_policy_types() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002228 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002229
raviteja.karumurif6dce272024-05-03 16:50:07 +01002230 if [ $# -lt 1 ]; then
2231 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
2232 return 1
2233 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002234
raviteja.karumurif6dce272024-05-03 16:50:07 +01002235 if [ "$A1PMS_VERSION" == "V2" ]; then
2236 if [ $# -eq 1 ]; then
2237 query="/v2/policy-types"
2238 elif [ $2 == "NORIC" ]; then
2239 query="/v2/policy-types"
2240 else
2241 query="/v2/policy-types?ric_id=$2"
2242 fi
2243 else
2244 if [ $# -eq 1 ]; then
2245 query="/policy_types"
2246 elif [ $2 == "NORIC" ]; then
2247 query="/policy_types"
2248 else
2249 query="/policy_types?ric=$2"
2250 fi
2251 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002252
raviteja.karumurif6dce272024-05-03 16:50:07 +01002253 res="$(__do_curl_to_api A1PMS GET $query)"
2254 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002255
raviteja.karumurif6dce272024-05-03 16:50:07 +01002256 if [ $status -ne $1 ]; then
2257 __log_test_fail_status_code $1 $status
2258 return 1
2259 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002260
raviteja.karumurif6dce272024-05-03 16:50:07 +01002261 if [ $# -gt 2 ]; then
2262 body=${res:0:${#res}-3}
2263 targetJson="["
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002264
raviteja.karumurif6dce272024-05-03 16:50:07 +01002265 for pid in ${@:3}; do
2266 if [ "$targetJson" != "[" ]; then
2267 targetJson=$targetJson","
2268 fi
2269 if [ $pid == "EMPTY" ]; then
2270 pid=""
2271 fi
2272 targetJson=$targetJson"\"$pid\""
2273 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002274
raviteja.karumurif6dce272024-05-03 16:50:07 +01002275 targetJson=$targetJson"]"
2276 if [ "$A1PMS_VERSION" == "V2" ]; then
2277 targetJson="{\"policytype_ids\": $targetJson }"
2278 fi
2279 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2280 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002281
raviteja.karumurif6dce272024-05-03 16:50:07 +01002282 if [ $res -ne 0 ]; then
2283 __log_test_fail_body
2284 return 1
2285 fi
2286 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002287
raviteja.karumurif6dce272024-05-03 16:50:07 +01002288 __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
2289 __log_test_pass
2290 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002291}
2292
2293#########################################################
2294#### Test case functions Health check
2295#########################################################
2296
raviteja.karumurif6dce272024-05-03 16:50:07 +01002297# API Test function: GET /status and V2 GET /status or (v1/status for a1pmsV3)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002298# args: <response-code>
2299# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002300a1pms_api_get_status() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002301 __log_test_start $@
2302 if [ $# -ne 1 ]; then
2303 __print_err "<response-code>" $@
2304 return 1
2305 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002306
raviteja.karumurif6dce272024-05-03 16:50:07 +01002307 if [ "$A1PMS_VERSION" == "V2" ]; then
2308 query="/v2/status"
2309 elif [ "$A1PMS_VERSION" == "V3" ]; then
2310 query="/v1/status"
2311 else
2312 query="/status"
2313 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002314
raviteja.karumurif6dce272024-05-03 16:50:07 +01002315 res="$(__do_curl_to_api A1PMS GET $query)"
2316 status=${res:${#res}-3}
2317
2318 if [ $status -ne $1 ]; then
2319 __log_test_fail_status_code $1 $status
2320 return 1
2321 fi
2322
2323 __collect_endpoint_stats "A1PMS" 10 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2324 __log_test_pass
2325 return 0
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002326}
2327
2328# API Test function: GET /status (root) without api prefix
2329# args: <response-code>
2330# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002331a1pms_api_get_status_root() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002332 __log_test_start $@
2333 if [ $# -ne 1 ]; then
2334 __print_err "<response-code>" $@
2335 return 1
2336 fi
2337 query="/status"
2338 TMP_PREFIX=$A1PMS_API_PREFIX
2339 A1PMS_API_PREFIX=""
2340 res="$(__do_curl_to_api A1PMS GET $query)"
2341 A1PMS_API_PREFIX=$TMP_PREFIX
2342 status=${res:${#res}-3}
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002343
raviteja.karumurif6dce272024-05-03 16:50:07 +01002344 if [ $status -ne $1 ]; then
2345 __log_test_fail_status_code $1 $status
2346 return 1
2347 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002348
raviteja.karumurif6dce272024-05-03 16:50:07 +01002349 __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
2350 __log_test_pass
2351 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002352}
2353
2354#########################################################
2355#### Test case functions RIC Repository
2356#########################################################
2357
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002358# API Test function: GET /ric and V2 GET /v2/rics/ric
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002359# args: <reponse-code> <management-element-id> [<ric-id>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002360# (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
2361# (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
2362# (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2363
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002364# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002365a1pms_api_get_ric() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002366 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002367
raviteja.karumurif6dce272024-05-03 16:50:07 +01002368 if [ "$A1PMS_VERSION" == "V2" ]; then
2369 if [ $# -lt 3 ]; then
2370 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
2371 return 1
2372 fi
2373 search=""
2374 if [ $2 != "NOME" ]; then
2375 search="?managed_element_id="$2
2376 fi
2377 if [ $3 != "NORIC" ]; then
2378 if [ -z $search ]; then
2379 search="?ric_id="$3
2380 else
2381 search=$search"&ric_id="$3
2382 fi
2383 fi
2384 query="/v2/rics/ric"$search
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002385
raviteja.karumurif6dce272024-05-03 16:50:07 +01002386 res="$(__do_curl_to_api A1PMS GET $query)"
2387 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002388
raviteja.karumurif6dce272024-05-03 16:50:07 +01002389 if [ $status -ne $1 ]; then
2390 __log_test_fail_status_code $1 $status
2391 return 1
2392 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002393
raviteja.karumurif6dce272024-05-03 16:50:07 +01002394 if [ $# -gt 3 ]; then
2395 body=${res:0:${#res}-3}
2396 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4")
2397 if [ $res -ne 0 ]; then
2398 __log_test_fail_general "Could not create target ric info json"
2399 return 1
2400 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002401
raviteja.karumurif6dce272024-05-03 16:50:07 +01002402 targetJson=$(<./tmp/.tmp_rics.json)
2403 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
2404 echo " TARGET JSON: $targetJson" >>$HTTPLOG
2405 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2406 if [ $res -ne 0 ]; then
2407 __log_test_fail_body
2408 return 1
2409 fi
2410 fi
2411 else
2412 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2413 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
2414 return 1
2415 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002416
raviteja.karumurif6dce272024-05-03 16:50:07 +01002417 query="/ric?managedElementId="$2
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002418
raviteja.karumurif6dce272024-05-03 16:50:07 +01002419 res="$(__do_curl_to_api A1PMS GET $query)"
2420 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002421
raviteja.karumurif6dce272024-05-03 16:50:07 +01002422 if [ $status -ne $1 ]; then
2423 __log_test_fail_status_code $1 $status
2424 return 1
2425 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002426
raviteja.karumurif6dce272024-05-03 16:50:07 +01002427 if [ $# -eq 3 ]; then
2428 body=${res:0:${#res}-3}
2429 if [ "$body" != "$3" ]; then
2430 __log_test_fail_body
2431 return 1
2432 fi
2433 fi
2434 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002435
raviteja.karumurif6dce272024-05-03 16:50:07 +01002436 __collect_endpoint_stats "A1PMS" 11 "GET" $A1PMS_API_PREFIX"/v2/rics/ric" $status
2437 __log_test_pass
2438 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002439}
2440
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002441# API test function: GET /rics and V2 GET /v2/rics
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002442# args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
2443# 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_........."
2444# format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2445# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002446a1pms_api_get_rics() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002447 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002448
raviteja.karumurif6dce272024-05-03 16:50:07 +01002449 if [ $# -lt 2 ]; then
2450 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
2451 return 1
2452 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002453
raviteja.karumurif6dce272024-05-03 16:50:07 +01002454 if [ "$A1PMS_VERSION" == "V2" ]; then
2455 query="/v2/rics"
2456 if [ $2 != "NOTYPE" ]; then
2457 query="/v2/rics?policytype_id="$2
2458 fi
2459 else
2460 query="/rics"
2461 if [ $2 != "NOTYPE" ]; then
2462 query="/rics?policyType="$2
2463 fi
2464 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002465
raviteja.karumurif6dce272024-05-03 16:50:07 +01002466 res="$(__do_curl_to_api A1PMS GET $query)"
2467 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002468
raviteja.karumurif6dce272024-05-03 16:50:07 +01002469 if [ $status -ne $1 ]; then
2470 __log_test_fail_status_code $1 $status
2471 return 1
2472 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002473
raviteja.karumurif6dce272024-05-03 16:50:07 +01002474 if [ $# -gt 2 ]; then
2475 body=${res:0:${#res}-3}
2476 if [ "$A1PMS_VERSION" == "V2" ]; then
2477 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3")
2478 else
2479 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3")
2480 fi
2481 if [ $res -ne 0 ]; then
2482 __log_test_fail_general "Could not create target ric info json"
2483 return 1
2484 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002485
raviteja.karumurif6dce272024-05-03 16:50:07 +01002486 targetJson=$(<./tmp/.tmp_rics.json)
2487 if [ "$A1PMS_VERSION" == "V2" ]; then
2488 targetJson="{\"rics\": $targetJson }"
2489 fi
2490 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2491 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2492 if [ $res -ne 0 ]; then
2493 __log_test_fail_body
2494 return 1
2495 fi
2496 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002497
raviteja.karumurif6dce272024-05-03 16:50:07 +01002498 __collect_endpoint_stats "A1PMS" 12 "GET" $A1PMS_API_PREFIX"/v2/rics" $status
2499 __log_test_pass
2500 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002501}
2502
2503##################################################################
2504#### API Test case functions Service registry and supervision ####
2505##################################################################
2506
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002507# API test function: PUT /service and V2 PUT /service
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002508# args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2509# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002510a1pms_api_put_service() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002511 __log_test_start $@
2512 if [ $# -ne 4 ]; then
2513 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2514 return 1
2515 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002516
raviteja.karumurif6dce272024-05-03 16:50:07 +01002517 if [ "$A1PMS_VERSION" == "V2" ]; then
2518 query="/v2/services"
2519 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2520 elif [ "$A1PMS_VERSION" == "V3" ]; then
2521 query="/v1/services"
2522 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceId\": \""$2"\"}"
2523 else
2524 query="/service"
2525 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2526 fi
2527 file="./tmp/.tmp.json"
2528 echo "$json" >$file
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002529
raviteja.karumurif6dce272024-05-03 16:50:07 +01002530 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2531 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002532
raviteja.karumurif6dce272024-05-03 16:50:07 +01002533 if [ $status -ne $1 ]; then
2534 __log_test_fail_status_code $1 $status
2535 return 1
2536 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002537
raviteja.karumurif6dce272024-05-03 16:50:07 +01002538 __collect_endpoint_stats "A1PMS" 13 "PUT" ${A1PMS_API_PREFIX}${query} ${status}
2539 __log_test_pass
2540 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002541}
2542
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002543# API test function: GET /services and V2 GET /v2/services
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002544#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>]* )]
2545# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002546a1pms_api_get_services() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002547 __log_test_start $@
2548 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2549 paramError=1
2550 if [ $# -eq 1 ]; then
2551 paramError=0
2552 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2553 paramError=0
2554 elif [ $# -eq 5 ]; then
2555 paramError=0
2556 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2557 argLen=$(($# - 2))
2558 if [ $(($argLen % 3)) -eq 0 ]; then
2559 paramError=0
2560 fi
2561 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002562
raviteja.karumurif6dce272024-05-03 16:50:07 +01002563 if [ $paramError -ne 0 ]; then
2564 __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>]* )]" $@
2565 return 1
2566 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002567
raviteja.karumurif6dce272024-05-03 16:50:07 +01002568 if [ "$A1PMS_VERSION" == "V2" ]; then
2569 query="/v2/services"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002570
raviteja.karumurif6dce272024-05-03 16:50:07 +01002571 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2572 query="/v2/services?service_id="$2
2573 fi
2574 else
2575 query="/services"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002576
raviteja.karumurif6dce272024-05-03 16:50:07 +01002577 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2578 query="/services?name="$2
2579 fi
2580 fi
2581 res="$(__do_curl_to_api A1PMS GET $query)"
2582 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002583
raviteja.karumurif6dce272024-05-03 16:50:07 +01002584 if [ $status -ne $1 ]; then
2585 __log_test_fail_status_code $1 $status
2586 return 1
2587 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002588
raviteja.karumurif6dce272024-05-03 16:50:07 +01002589 if [ $# -gt 2 ]; then
2590 variableArgCount=$(($# - 2))
2591 body=${res:0:${#res}-3}
2592 targetJson="["
2593 shift
2594 shift
2595 cntr=0
2596 while [ $cntr -lt $variableArgCount ]; do
2597 servicename=$1
2598 shift
2599 timeout=$1
2600 shift
2601 callback=$1
2602 shift
2603 if [ $cntr -gt 0 ]; then
2604 targetJson=$targetJson","
2605 fi
2606 # timeSinceLastActivitySeconds value cannot be checked since value varies
2607 if [ "$A1PMS_VERSION" == "V2" ]; then
2608 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2609 else
2610 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2611 fi
2612 let cntr=cntr+3
2613 done
2614 targetJson=$targetJson"]"
2615 if [ "$A1PMS_VERSION" == "V2" ]; then
2616 targetJson="{\"service_list\": $targetJson }"
2617 fi
2618 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2619 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2620 if [ $res -ne 0 ]; then
2621 __log_test_fail_body
2622 return 1
2623 fi
2624 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002625
raviteja.karumurif6dce272024-05-03 16:50:07 +01002626 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2627 __log_test_pass
2628 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002629}
2630
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002631# API test function: GET /services V2 GET /v2/services - (only checking service names)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002632# args: <response-code> [<service-name>]*"
2633# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002634a1pms_api_get_service_ids() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002635 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002636
raviteja.karumurif6dce272024-05-03 16:50:07 +01002637 if [ $# -lt 1 ]; then
2638 __print_err "<response-code> [<service-name>]*" $@
2639 return 1
2640 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002641
raviteja.karumurif6dce272024-05-03 16:50:07 +01002642 if [ "$A1PMS_VERSION" == "V2" ]; then
2643 query="/v2/services"
2644 else
2645 query="/services"
2646 fi
2647 res="$(__do_curl_to_api A1PMS GET $query)"
2648 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002649
raviteja.karumurif6dce272024-05-03 16:50:07 +01002650 if [ $status -ne $1 ]; then
2651 __log_test_fail_status_code $1 $status
2652 return 1
2653 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002654
raviteja.karumurif6dce272024-05-03 16:50:07 +01002655 body=${res:0:${#res}-3}
2656 targetJson="["
2657 for rapp in ${@:2}; do
2658 if [ "$targetJson" != "[" ]; then
2659 targetJson=$targetJson","
2660 fi
2661 if [ "$A1PMS_VERSION" == "V2" ]; then
2662 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2663 else
2664 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2665 fi
2666 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002667
raviteja.karumurif6dce272024-05-03 16:50:07 +01002668 targetJson=$targetJson"]"
2669 if [ "$A1PMS_VERSION" == "V2" ]; then
2670 targetJson="{\"service_list\": $targetJson }"
2671 fi
2672 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2673 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002674
raviteja.karumurif6dce272024-05-03 16:50:07 +01002675 if [ $res -ne 0 ]; then
2676 __log_test_fail_body
2677 return 1
2678 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002679
raviteja.karumurif6dce272024-05-03 16:50:07 +01002680 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
2681 __log_test_pass
2682 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002683}
2684
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002685# API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002686# args: <response-code> <service-name>
2687# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002688a1pms_api_delete_services() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002689 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002690
raviteja.karumurif6dce272024-05-03 16:50:07 +01002691 if [ $# -ne 2 ]; then
2692 __print_err "<response-code> <service-name>" $@
2693 return 1
2694 fi
2695 if [ "$A1PMS_VERSION" == "V2" ]; then
2696 query="/v2/services/"$2
2697 else
2698 query="/services?name="$2
2699 fi
2700 res="$(__do_curl_to_api A1PMS DELETE $query)"
2701 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002702
raviteja.karumurif6dce272024-05-03 16:50:07 +01002703 if [ $status -ne $1 ]; then
2704 __log_test_fail_status_code $1 $status
2705 return 1
2706 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002707
raviteja.karumurif6dce272024-05-03 16:50:07 +01002708 __collect_endpoint_stats "A1PMS" 15 "DELETE" $A1PMS_API_PREFIX"/v2/services/{serviceId}" $status
2709 __log_test_pass
2710 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002711}
2712
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002713# API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002714# args: <response-code> <service-name>
2715# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002716a1pms_api_put_services_keepalive() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002717 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002718
raviteja.karumurif6dce272024-05-03 16:50:07 +01002719 if [ $# -ne 2 ]; then
2720 __print_err "<response-code> <service-name>" $@
2721 return 1
2722 fi
2723 if [ "$A1PMS_VERSION" == "V2" ]; then
2724 query="/v2/services/$2/keepalive"
2725 else
2726 query="/services/keepalive?name="$2
2727 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002728
raviteja.karumurif6dce272024-05-03 16:50:07 +01002729 res="$(__do_curl_to_api A1PMS PUT $query)"
2730 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002731
raviteja.karumurif6dce272024-05-03 16:50:07 +01002732 if [ $status -ne $1 ]; then
2733 __log_test_fail_status_code $1 $status
2734 return 1
2735 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002736
raviteja.karumurif6dce272024-05-03 16:50:07 +01002737 __collect_endpoint_stats "A1PMS" 16 "PUT" $A1PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
2738 __log_test_pass
2739 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002740}
2741
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002742##################################################################
2743#### API Test case functions Configuration ####
2744##################################################################
2745
raviteja.karumurif6dce272024-05-03 16:50:07 +01002746# API Test function: PUT "/v2/configuration" or "/v1/configuration"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002747# args: <response-code> <config-file>
2748# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002749a1pms_api_put_configuration() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002750 __log_test_start $@
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002751
raviteja.karumurif6dce272024-05-03 16:50:07 +01002752 if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
2753 __log_test_fail_not_supported
2754 return 1
2755 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002756
raviteja.karumurif6dce272024-05-03 16:50:07 +01002757 if [ $# -ne 2 ]; then
2758 __print_err "<response-code> <config-file>" $@
2759 return 1
2760 fi
2761 if [ ! -f $2 ]; then
2762 __log_test_fail_general "Config file "$2", does not exist"
2763 return 1
2764 fi
2765 inputJson=$(<$2)
2766 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2767 # inputJson="{\"config\":"$inputJson"}"
2768 # fi
2769 file="./tmp/.config.json"
2770 echo $inputJson >$file
2771 if [ "$A1PMS_VERSION" == "V2" ]; then
2772 query="/v2/configuration"
2773 elif [ "$A1PMS_VERSION" == "V3" ]; then
2774 #V3 has baseurl changes 'a1-policy/v2' to 'a1policymanagement/v1'
2775 query="/v1/configuration"
2776 fi
2777 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2778 status=${res:${#res}-3}
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002779
raviteja.karumurif6dce272024-05-03 16:50:07 +01002780 if [ $status -ne $1 ]; then
2781 __log_test_fail_status_code $1 $status
2782 return 1
2783 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002784
raviteja.karumurif6dce272024-05-03 16:50:07 +01002785 __collect_endpoint_stats "A1PMS" 17 "PUT" ${A1PMS_API_PREFIX}${query} ${status}
2786 __log_test_pass
2787 return 0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002788}
2789
2790# API Test function: GET /v2/configuration
2791# args: <response-code> [<config-file>]
2792# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002793a1pms_api_get_configuration() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002794 __log_test_start $@
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002795
raviteja.karumurif6dce272024-05-03 16:50:07 +01002796 if [ "$A1PMS_VERSION" != "V2" ]; then
2797 __log_test_fail_not_supported
2798 return 1
2799 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002800
raviteja.karumurif6dce272024-05-03 16:50:07 +01002801 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2802 __print_err "<response-code> [<config-file>]" $@
2803 return 1
2804 fi
2805 if [ ! -f $2 ]; then
2806 __log_test_fail_general "Config file "$2" for comparison, does not exist"
2807 return 1
2808 fi
2809
2810 query="/v2/configuration"
2811 res="$(__do_curl_to_api A1PMS GET $query)"
2812 status=${res:${#res}-3}
2813
2814 if [ $status -ne $1 ]; then
2815 __log_test_fail_status_code $1 $status
2816 return 1
2817 fi
2818
2819 if [ $# -eq 2 ]; then
2820
2821 body=${res:0:${#res}-3}
2822
2823 targetJson=$(<$2)
2824 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2825 # inputJson="{\"config\":"$inputJson"}"
2826 # fi
2827 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2828 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2829
2830 if [ $res -ne 0 ]; then
2831 __log_test_fail_body
2832 return 1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002833 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002834 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002835
raviteja.karumurif6dce272024-05-03 16:50:07 +01002836 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
2837 __log_test_pass
2838 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002839}
2840
2841##########################################
2842#### Reset types and instances ####
2843##########################################
2844
2845# Admin reset to remove all policies and services
2846# All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2847# NOTE - only works in kubernetes and the pod should not be running
2848# args: -
2849# (Function for test scripts)
2850
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002851a1pms_kube_pvc_reset() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002852 __log_test_start $@
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002853
raviteja.karumurif6dce272024-05-03 16:50:07 +01002854 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
2855 if [ -z "$pvc_name" ]; then
2856 pvc_name=policymanagementservice-vardata-pvc
2857 fi
2858 echo " Trying to reset pvc: "$pvc_name
2859 __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002860
raviteja.karumurif6dce272024-05-03 16:50:07 +01002861 __log_test_pass
2862 return 0
BjornMagnussonXAcd938442022-05-11 10:01:24 +02002863}
2864
2865# args: <realm> <client-name> <client-secret>
2866a1pms_configure_sec() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002867 export A1PMS_CREDS_GRANT_TYPE="client_credentials"
2868 export A1PMS_CREDS_CLIENT_SECRET=$3
2869 export A1PMS_CREDS_CLIENT_ID=$2
2870 export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
2871 export A1PMS_SIDECAR_MOUNT="/token-cache"
2872 export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
BjornMagnussonXAcd938442022-05-11 10:01:24 +02002873
raviteja.karumurif6dce272024-05-03 16:50:07 +01002874 export AUTHSIDECAR_APP_NAME
2875 export AUTHSIDECAR_DISPLAY_NAME
2876}