blob: ceef204eee17cb295a9fa4a19e1e781bb323d3e7 [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
raviteja.karumuri64755e02024-05-29 18:20:42 +0100868# API Test function: GET /policy, V2 GET /v2/policies/{policy_id} and V3 GET a1policymanagement/v1/policies/{policy_id}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100869# 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 ]
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100871# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100872a1pms_api_get_policy() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100873 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100874
raviteja.karumurif6dce272024-05-03 16:50:07 +0100875 if [ "$A1PMS_VERSION" == "V2" ]; then
876 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
877 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
878 return 1
879 fi
880 query="/v2/policies/$UUID$2"
raviteja.karumuri64755e02024-05-29 18:20:42 +0100881 elif [ "$A1PMS_VERSION" == "V3" ]; then
882 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
883 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
884 return 1
885 fi
886 query="/v1/policies/$UUID$2"
raviteja.karumurif6dce272024-05-03 16:50:07 +0100887 else
888 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
889 __print_err "<response-code> <policy-id> [<template-file>] " $@
890 return 1
891 fi
892 query="/policy?id=$UUID$2"
893 fi
894 res="$(__do_curl_to_api A1PMS GET $query)"
895 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100896
raviteja.karumurif6dce272024-05-03 16:50:07 +0100897 if [ $status -ne $1 ]; then
898 __log_test_fail_status_code $1 $status
899 return 1
900 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100901
raviteja.karumurif6dce272024-05-03 16:50:07 +0100902 if [ "$A1PMS_VERSION" == "V2" ]; then
903 if [ $# -eq 8 ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100904
raviteja.karumurif6dce272024-05-03 16:50:07 +0100905 #Create a policy json to compare with
906 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100907
raviteja.karumurif6dce272024-05-03 16:50:07 +0100908 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
909 if [ $7 != "NOTRANSIENT" ]; then
910 targetJson=$targetJson", \"transient\":$7"
911 fi
912 if [ $6 != "NOTYPE" ]; then
913 targetJson=$targetJson", \"policytype_id\":\"$6\""
914 else
915 targetJson=$targetJson", \"policytype_id\":\"\""
916 fi
917 if [ $8 != "NOURL" ]; then
918 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
919 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100920
raviteja.karumurif6dce272024-05-03 16:50:07 +0100921 data=$(sed 's/XXX/'${2}'/g' $3)
922 targetJson=$targetJson", \"policy_data\":$data"
923 targetJson="{$targetJson}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100924
raviteja.karumurif6dce272024-05-03 16:50:07 +0100925 echo "TARGET JSON: $targetJson" >>$HTTPLOG
926 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
927 if [ $res -ne 0 ]; then
928 __log_test_fail_body
929 return 1
930 fi
931 fi
raviteja.karumuri64755e02024-05-29 18:20:42 +0100932 elif [ "$A1PMS_VERSION" == "V3" ]; then
933 if [ $# -eq 8 ]; then
934 #Create a policy json to compare with
935 body=${res:0:${#res}-3}
936 data=$(sed 's/XXX/'${2}'/g' $3)
937 targetJson=$data
938
939 echo "TARGET JSON: $targetJson" >>$HTTPLOG
940 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
941 if [ $res -ne 0 ]; then
942 __log_test_fail_body
943 return 1
944 fi
945 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +0100946 else
947 if [ $# -eq 3 ]; then
948 #Create a policy json to compare with
949 body=${res:0:${#res}-3}
950 file="./tmp/.p.json"
951 sed 's/XXX/'${2}'/g' $3 >$file
952 targetJson=$(<$file)
953 echo "TARGET JSON: $targetJson" >>$HTTPLOG
954 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
955 if [ $res -ne 0 ]; then
956 __log_test_fail_body
957 fi
958 fi
959 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100960
raviteja.karumuri64755e02024-05-29 18:20:42 +0100961 __collect_endpoint_stats "A1PMS" 01 "GET" ${A1PMS_API_PREFIX}${query} ${status}
raviteja.karumurif6dce272024-05-03 16:50:07 +0100962 __log_test_pass
963 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100964}
965
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100966# API Test function: PUT /policy and V2 PUT /policies
967# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
968# 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 +0100969# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100970a1pms_api_put_policy() {
raviteja.karumurif6dce272024-05-03 16:50:07 +0100971 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100972
raviteja.karumuri64755e02024-05-29 18:20:42 +0100973 if [ "$A1PMS_VERSION" == "V2" ] || [ "$A1PMS_VERSION" == "V3" ]; then
raviteja.karumurif6dce272024-05-03 16:50:07 +0100974 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
975 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
976 return 1
977 fi
978 else
979 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
980 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
981 return 1
982 fi
983 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100984
raviteja.karumurif6dce272024-05-03 16:50:07 +0100985 count=0
986 max=1
987 serv=$2
988 ric=$3
989 pt=$4
990 pid=$5
991 trans=$6
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100992
raviteja.karumurif6dce272024-05-03 16:50:07 +0100993 if [ "$A1PMS_VERSION" == "V2" ]; then
994 noti=$7
995 temp=$8
996 if [ $# -eq 9 ]; then
997 max=$9
998 fi
999 else
1000 temp=$7
1001 if [ $# -eq 8 ]; then
1002 max=$8
1003 fi
1004 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001005
raviteja.karumurif6dce272024-05-03 16:50:07 +01001006 while [ $count -lt $max ]; do
1007 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001008
raviteja.karumurif6dce272024-05-03 16:50:07 +01001009 query="/v2/policies"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001010
raviteja.karumurif6dce272024-05-03 16:50:07 +01001011 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1012 if [ $trans != "NOTRANSIENT" ]; then
1013 inputJson=$inputJson", \"transient\":$trans"
1014 fi
1015 if [ $pt != "NOTYPE" ]; then
1016 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1017 else
1018 inputJson=$inputJson", \"policytype_id\":\"\""
1019 fi
1020 if [ $noti != "NOURL" ]; then
1021 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1022 fi
1023 file="./tmp/.p.json"
1024 data=$(sed 's/XXX/'${pid}'/g' $temp)
1025 inputJson=$inputJson", \"policy_data\":$data"
1026 inputJson="{$inputJson}"
1027 echo $inputJson >$file
1028 else
1029 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001030
raviteja.karumurif6dce272024-05-03 16:50:07 +01001031 if [ $pt != "NOTYPE" ]; then
1032 query=$query"&type=$pt"
1033 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001034
raviteja.karumurif6dce272024-05-03 16:50:07 +01001035 if [ $trans != NOTRANSIENT ]; then
1036 query=$query"&transient=$trans"
1037 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001038
raviteja.karumurif6dce272024-05-03 16:50:07 +01001039 file="./tmp/.p.json"
1040 sed 's/XXX/'${pid}'/g' $temp >$file
1041 fi
1042 res="$(__do_curl_to_api A1PMS PUT $query $file)"
1043 status=${res:${#res}-3}
1044 echo -ne " Executing "$count"("$max")${SAMELINE}"
1045 if [ $status -ne $1 ]; then
1046 echo " Executed "$count"?("$max")"
1047 __log_test_fail_status_code $1 $status
1048 return 1
1049 fi
1050 let pid=$pid+1
1051 let count=$count+1
1052 echo -ne " Executed "$count"("$max")${SAMELINE}"
1053 done
raviteja.karumuri64755e02024-05-29 18:20:42 +01001054 __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${query} ${status} ${max}
1055 echo ""
1056
1057 __log_test_pass
1058 return 0
1059}
1060
1061# API Test function: V3 PUT a1policymanagement/v1/policies
1062# args: <response-code> <policy-id> <template-file> [<count>]
1063# args(V2): <response-code> <policy-id> <template-file> [<count>]
1064# (Function for test scripts)
1065a1pms_api_put_policy_v3() {
1066 __log_test_start $@
1067
1068 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1069 __print_err "<response-code> <policy-id> <template-file> [<count>]" $@
1070 return 1
1071 fi
1072
1073 count=0
1074 max=1
1075 pid=$2
1076 temp=$3
1077
1078 if [ $# -eq 4 ]; then
1079 max=$4
1080 fi
1081
1082 while [ $count -lt $max ]; do
1083 query="/v1/policies/$UUID$pid"
1084 file="./tmp/.p_v3.json"
1085 let update_value=$pid+300
1086 data=$(sed 's/XXX/'${update_value}'/g' $temp)
1087 inputJson="$data"
1088 echo $inputJson >$file
1089 res="$(__do_curl_to_api A1PMS PUT $query $file)"
1090 status=${res:${#res}-3}
1091 echo -ne " Executing "$count"("$max")${SAMELINE}"
1092 if [ $status -ne $1 ]; then
1093 echo " Executed "$count"?("$max")"
1094 __log_test_fail_status_code $1 $status
1095 return 1
1096 fi
1097 let pid=$pid+1
1098 let count=$count+1
1099 echo -ne " Executed "$count"("$max")${SAMELINE}"
1100 done
1101 __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${query} ${status} ${max}
1102 echo ""
1103
1104 __log_test_pass
1105 return 0
1106}
1107
1108# API Test function: V£ POST a1policymanagement/v1/policies
1109# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
1110# args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]
1111# (Function for test scripts)
1112a1pms_api_post_policy_v3() {
1113 __log_test_start $@
1114
1115 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1116 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
1117 return 1
1118 fi
1119
1120 count=0
1121 max=1
1122 serv=$2
1123 ric=$3
1124 pt=$4
1125 pid=$5
1126 trans=$6
1127 noti=$7
1128 temp=$8
1129 if [ $# -eq 9 ]; then
1130 max=$9
1131 fi
1132
1133 while [ $count -lt $max ]; do
1134 query="/v1/policies"
1135
1136 inputJson="\"nearRtRicId\":\"$ric\""
1137 if [ $pt != "NOTYPE" ]; then
1138 inputJson=$inputJson", \"policyTypeId\":\"$pt\""
1139 else
1140 inputJson=$inputJson", \"policyTypeId\":\"\""
1141 fi
1142 if [ $serv != "NOSERVICE" ]; then
1143 inputJson=$inputJson", \"serviceId\":\"$serv\""
1144 fi
1145 if [ $noti != "NONOTIFYURL" ]; then
1146 inputJson=$inputJson", \"statusNotificationUri\":\"$noti\""
1147 fi
1148 if [ $trans != "NOTRANSIENT" ]; then
1149 inputJson=$inputJson", \"transient\":\"$trans\""
1150 fi
1151 file="./tmp/.p.json"
1152 data=$(sed 's/XXX/'${pid}'/g' $temp)
1153 inputJson=$inputJson", \"policyObject\":$data"
1154 inputJson=$inputJson", \"policyId\":\"$UUID$pid\""
1155 inputJson="{$inputJson}"
1156 echo $inputJson >$file
1157 res="$(__do_curl_to_api A1PMS POST $query $file)"
1158 status=${res:${#res}-3}
1159 echo -ne " Executing "$count"("$max")${SAMELINE}"
1160 if [ $status -ne $1 ]; then
1161 echo " Executed "$count"?("$max")"
1162 __log_test_fail_status_code $1 $status
1163 return 1
1164 fi
1165 let pid=$pid+1
1166 let count=$count+1
1167 echo -ne " Executed "$count"("$max")${SAMELINE}"
1168 done
1169 __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${A1PMS_VERSION} ${status} ${max}
raviteja.karumurif6dce272024-05-03 16:50:07 +01001170 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001171
raviteja.karumurif6dce272024-05-03 16:50:07 +01001172 __log_test_pass
1173 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001174}
1175
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001176# API Test function: PUT /policy and V2 PUT /policies, to run in batch
1177# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1178# 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 +02001179# (Function for test scripts)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001180
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001181a1pms_api_put_policy_batch() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001182 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001183
raviteja.karumurif6dce272024-05-03 16:50:07 +01001184 if [ "$A1PMS_VERSION" == "V2" ]; then
1185 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1186 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1187 return 1
1188 fi
1189 else
1190 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1191 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1192 return 1
1193 fi
1194 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001195
raviteja.karumurif6dce272024-05-03 16:50:07 +01001196 count=0
1197 max=1
1198 serv=$2
1199 ric=$3
1200 pt=$4
1201 pid=$5
1202 trans=$6
1203 if [ "$A1PMS_VERSION" == "V2" ]; then
1204 noti=$7
1205 temp=$8
1206 if [ $# -eq 9 ]; then
1207 max=$9
1208 fi
1209 else
1210 temp=$7
1211 if [ $# -eq 8 ]; then
1212 max=$8
1213 fi
1214 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001215
raviteja.karumurif6dce272024-05-03 16:50:07 +01001216 ARR=""
1217 while [ $count -lt $max ]; do
1218 if [ "$A1PMS_VERSION" == "V2" ]; then
1219 query="/v2/policies"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001220
raviteja.karumurif6dce272024-05-03 16:50:07 +01001221 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1222 if [ $trans != "NOTRANSIENT" ]; then
1223 inputJson=$inputJson", \"transient\":$trans"
1224 fi
1225 if [ $pt != "NOTYPE" ]; then
1226 inputJson=$inputJson", \"policytype_id\":\"$pt\""
1227 else
1228 inputJson=$inputJson", \"policytype_id\":\"\""
1229 fi
1230 if [ $noti != "NOURL" ]; then
1231 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1232 fi
1233 file="./tmp/.p.json"
1234 data=$(sed 's/XXX/'${pid}'/g' $temp)
1235 inputJson=$inputJson", \"policy_data\":$data"
1236 inputJson="{$inputJson}"
1237 echo $inputJson >$file
1238 else
1239 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001240
raviteja.karumurif6dce272024-05-03 16:50:07 +01001241 if [ $pt != "NOTYPE" ]; then
1242 query=$query"&type=$pt"
1243 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001244
raviteja.karumurif6dce272024-05-03 16:50:07 +01001245 if [ $trans != NOTRANSIENT ]; then
1246 query=$query"&transient=$trans"
1247 fi
1248 file="./tmp/.p.json"
1249 sed 's/XXX/'${pid}'/g' $temp >$file
1250 fi
1251 res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)"
1252 status=${res:${#res}-3}
1253 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001254
raviteja.karumurif6dce272024-05-03 16:50:07 +01001255 if [ $status -ne 200 ]; then
1256 echo " Requested(batch) "$count"?("$max")"
1257 __log_test_fail_status_code 200 $status
1258 return 1
1259 fi
1260 cid=${res:0:${#res}-3}
1261 ARR=$ARR" "$cid
1262 let pid=$pid+1
1263 let count=$count+1
1264 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1265 done
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001266
raviteja.karumurif6dce272024-05-03 16:50:07 +01001267 echo ""
1268 count=0
1269 for cid in $ARR; do
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001270
raviteja.karumurif6dce272024-05-03 16:50:07 +01001271 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1272 status=${res:${#res}-3}
1273 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001274
raviteja.karumurif6dce272024-05-03 16:50:07 +01001275 if [ $status -ne $1 ]; then
1276 echo " Accepted(batch) "$count"?("$max")"
1277 __log_test_fail_status_code $1 $status
1278 return 1
1279 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001280
raviteja.karumurif6dce272024-05-03 16:50:07 +01001281 let count=$count+1
1282 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
1283 done
1284 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001285
raviteja.karumurif6dce272024-05-03 16:50:07 +01001286 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001287
raviteja.karumurif6dce272024-05-03 16:50:07 +01001288 __log_test_pass
1289 return 0
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001290}
1291
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001292# 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 +02001293# 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 +01001294# 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 +02001295# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001296a1pms_api_put_policy_parallel() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001297 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001298
raviteja.karumurif6dce272024-05-03 16:50:07 +01001299 if [ "$A1PMS_VERSION" == "V2" ]; then
1300 if [ $# -ne 11 ]; then
1301 __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>" $@
1302 return 1
1303 fi
1304 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001305
raviteja.karumurif6dce272024-05-03 16:50:07 +01001306 resp_code=$1
1307 shift
1308 serv=$1
1309 shift
1310 ric_base=$1
1311 shift
1312 num_rics=$1
1313 shift
1314 type=$1
1315 shift
1316 start_id=$1
1317 shift
1318 transient=$1
1319 shift
1320 if [ "$A1PMS_VERSION" == "V2" ]; then
1321 noti=$1
1322 shift
1323 else
1324 noti=""
1325 fi
1326 template=$1
1327 shift
1328 count=$1
1329 shift
1330 pids=$1
1331 shift
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001332
raviteja.karumurif6dce272024-05-03 16:50:07 +01001333 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1334 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1335 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1336 echo " Info - will execute over a1pms REST"
1337 fi
1338 if [ "$A1PMS_VERSION" == "V2" ]; then
1339 if [ $serv == "NOSERVICE" ]; then
1340 serv=""
1341 fi
1342 query="$A1PMS_API_PREFIX/v2/policies"
1343 else
1344 if [ $serv == "NOSERVICE" ]; then
1345 serv=""
1346 fi
1347 query="/policy?service=$serv"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001348
raviteja.karumurif6dce272024-05-03 16:50:07 +01001349 if [ $type != "NOTYPE" ]; then
1350 query=$query"&type=$type"
1351 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001352
raviteja.karumurif6dce272024-05-03 16:50:07 +01001353 if [ $transient != NOTRANSIENT ]; then
1354 query=$query"&transient=$transient"
1355 fi
1356 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001357
raviteja.karumurif6dce272024-05-03 16:50:07 +01001358 urlbase=${A1PMS_ADAPTER}${query}
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001359
raviteja.karumurif6dce272024-05-03 16:50:07 +01001360 httpproxy="NOPROXY"
1361 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1362 httpproxy=$KUBE_PROXY_PATH
1363 fi
1364
1365 for ((i = 1; i <= $pids; i++)); do
1366 uuid=$UUID
1367 if [ -z "$uuid" ]; then
1368 uuid="NOUUID"
1369 fi
1370 echo "" >"./tmp/.pid${i}.res.txt"
1371 if [ "$A1PMS_VERSION" == "V2" ]; then
1372 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1373 else
1374 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1375 fi
1376 echo $i
1377 done | xargs -n 1 -I{} -P $pids bash -c '{
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001378 arg=$(echo {})
1379 echo " Parallel process $arg started"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001380 tmp=$(< "./tmp/.pid${arg}.txt")
1381 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001382 }'
raviteja.karumurif6dce272024-05-03 16:50:07 +01001383 msg=""
1384 for ((i = 1; i <= $pids; i++)); do
1385 file="./tmp/.pid${i}.res.txt"
1386 tmp=$(<$file)
1387 if [ -z "$tmp" ]; then
1388 echo " Process $i : unknown result (result file empty"
1389 msg="failed"
1390 else
1391 res=${tmp:0:1}
1392 if [ $res == "0" ]; then
1393 echo " Process $i : OK - "${tmp:1}
1394 else
1395 echo " Process $i : failed - "${tmp:1}
1396 msg="failed"
1397 fi
1398 fi
1399 done
1400 if [ -z $msg ]; then
1401 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count * $num_rics))
1402 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1403 return 0
1404 fi
1405 __log_test_fail_general "One of more processes failed to execute"
1406 return 1
1407}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001408
raviteja.karumurif6dce272024-05-03 16:50:07 +01001409# API Test function: V3 POST /policies, to run in i parallel for a number of rics
1410# 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>
1411# 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>
1412# (Function for test scripts)
1413a1pms_api_post_policy_parallel() {
1414 __log_test_start $@
1415
1416 if [ $# -ne 11 ]; then
1417 __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>" $@
1418 return 1
1419 fi
1420
1421 resp_code=$1
1422 shift
1423 serv=$1
1424 shift
1425 ric_base=$1
1426 shift
1427 num_rics=$1
1428 shift
1429 type=$1
1430 shift
1431 start_id=$1
1432 shift
1433 transient=$1
1434 shift
1435 noti=$1
1436 shift
1437 template=$1
1438 shift
1439 count=$1
1440 shift
1441 pids=$1
1442 shift
1443
1444 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1445 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1446 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1447 echo " Info - will execute over a1pms REST"
1448 fi
1449
1450 if [ $serv == "NOSERVICE" ]; then
1451 serv=""
1452 fi
1453 query="$A1PMS_API_PREFIX/v1/policies"
1454
1455 urlbase=${A1PMS_ADAPTER}${query}
1456
1457 httpproxy="NOPROXY"
1458 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1459 httpproxy=$KUBE_PROXY_PATH
1460 fi
1461
1462 for ((i = 1; i <= $pids; i++)); do
1463 uuid=$UUID
1464 if [ -z "$uuid" ]; then
1465 uuid="NOUUID"
1466 fi
1467 echo "" >"./tmp/.pid${i}.res.txt"
1468 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt"
1469 echo $i
1470 done | xargs -n 1 -I{} -P $pids bash -c '{
1471 arg=$(echo {})
1472 echo " Parallel process $arg started"
1473 tmp=$(< "./tmp/.pid${arg}.txt")
1474 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1475 }'
1476 msg=""
1477 for ((i = 1; i <= $pids; i++)); do
1478 file="./tmp/.pid${i}.res.txt"
1479 tmp=$(<$file)
1480 if [ -z "$tmp" ]; then
1481 echo " Process $i : unknown result (result file empty"
1482 msg="failed"
1483 else
1484 res=${tmp:0:1}
1485 if [ $res == "0" ]; then
1486 echo " Process $i : OK - "${tmp:1}
1487 else
1488 echo " Process $i : failed - "${tmp:1}
1489 msg="failed"
1490 fi
1491 fi
1492 done
1493 if [ -z $msg ]; then
1494 __collect_endpoint_stats "A1PMS" 02 "POST" $A1PMS_API_PREFIX"/v1/policies" $resp_code $(($count * $num_rics))
1495 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1496 return 0
1497 fi
1498 __log_test_fail_general "One of more processes failed to execute"
1499 return 1
1500}
1501
1502# API Test function: V3 PUT /policies, to run in i parallel for a number of rics
1503# 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>
1504# 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>
1505# (Function for test scripts)
1506a1pms_api_update_policy_parallel() {
1507 __log_test_start $@
1508
1509 if [ $# -ne 12 ]; then
1510 __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>" $@
1511 return 1
1512 fi
1513
1514 resp_code=$1
1515 shift
1516 serv=$1
1517 shift
1518 ric_base=$1
1519 shift
1520 num_rics=$1
1521 shift
1522 type=$1
1523 shift
1524 start_id=$1
1525 shift
1526 transient=$1
1527 shift
1528 noti=$1
1529 shift
1530 template=$1
1531 shift
1532 count=$1
1533 shift
1534 pids=$1
1535 shift
1536 policy_ids_file_path=$1
1537 shift
1538
1539 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1540 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1541 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1542 echo " Info - will execute over a1pms REST"
1543 fi
1544
1545 if [ $serv == "NOSERVICE" ]; then
1546 serv=""
1547 fi
1548 query="$A1PMS_API_PREFIX/v1/policies"
1549
1550 urlbase=${A1PMS_ADAPTER}${query}
1551
1552 httpproxy="NOPROXY"
1553 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1554 httpproxy=$KUBE_PROXY_PATH
1555 fi
1556
1557 for ((i = 1; i <= $pids; i++)); do
1558 uuid=$UUID
1559 if [ -z "$uuid" ]; then
1560 uuid="NOUUID"
1561 fi
1562 echo "" >"./tmp/.pid${i}.res.txt"
1563 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"
1564 echo $i
1565 done | xargs -n 1 -I{} -P $pids bash -c '{
1566 arg=$(echo {})
1567 echo " Parallel process $arg started"
1568 tmp=$(< "./tmp/.pid${arg}.txt")
1569 python3 ../common/update_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
1570 }'
1571 msg=""
1572 for ((i = 1; i <= $pids; i++)); do
1573 file="./tmp/.pid${i}.res.txt"
1574 tmp=$(<$file)
1575 if [ -z "$tmp" ]; then
1576 echo " Process $i : unknown result (result file empty"
1577 msg="failed"
1578 else
1579 res=${tmp:0:1}
1580 if [ $res == "0" ]; then
1581 echo " Process $i : OK - "${tmp:1}
1582 else
1583 echo " Process $i : failed - "${tmp:1}
1584 msg="failed"
1585 fi
1586 fi
1587 done
1588 if [ -z $msg ]; then
1589 __collect_endpoint_stats "A1PMS" 02 "POST" $A1PMS_API_PREFIX"/v1/policies" $resp_code $(($count * $num_rics))
1590 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1591 return 0
1592 fi
1593 __log_test_fail_general "One of more processes failed to execute"
1594 return 1
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001595}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001596
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001597# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001598# args: <response-code> <policy-id> [count]
1599# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001600a1pms_api_delete_policy() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001601 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001602
raviteja.karumurif6dce272024-05-03 16:50:07 +01001603 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1604 __print_err "<response-code> <policy-id> [count]" $@
1605 return 1
1606 fi
1607
1608 count=0
1609 max=1
1610
1611 if [ $# -eq 3 ]; then
1612 max=$3
1613 fi
1614
1615 pid=$2
1616
1617 while [ $count -lt $max ]; do
1618 if [ "$A1PMS_VERSION" == "V2" ]; then
1619 query="/v2/policies/"$UUID$pid
raviteja.karumuri64755e02024-05-29 18:20:42 +01001620 elif [ "$A1PMS_VERSION" == "V3" ]; then
1621 query="/v1/policies/"$UUID$pid
raviteja.karumurif6dce272024-05-03 16:50:07 +01001622 else
1623 query="/policy?id="$UUID$pid
1624 fi
1625 res="$(__do_curl_to_api A1PMS DELETE $query)"
1626 status=${res:${#res}-3}
raviteja.karumuri64755e02024-05-29 18:20:42 +01001627 echo -ne " Executing "${count}"("${max}")${SAMELINE}"
raviteja.karumurif6dce272024-05-03 16:50:07 +01001628
1629 if [ $status -ne $1 ]; then
raviteja.karumuri64755e02024-05-29 18:20:42 +01001630 echo " Executed "${count}"?("${max}")"
raviteja.karumurif6dce272024-05-03 16:50:07 +01001631 __log_test_fail_status_code $1 $status
1632 return 1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001633 fi
1634
raviteja.karumurif6dce272024-05-03 16:50:07 +01001635 let pid=$pid+1
1636 let count=$count+1
raviteja.karumuri64755e02024-05-29 18:20:42 +01001637 echo -ne " Executed "${count}"("${max}")${SAMELINE}"
raviteja.karumurif6dce272024-05-03 16:50:07 +01001638 done
raviteja.karumuri64755e02024-05-29 18:20:42 +01001639 __collect_endpoint_stats "A1PMS" 03 "DELETE" ${A1PMS_API_PREFIX}${query} ${status} ${max}
raviteja.karumurif6dce272024-05-03 16:50:07 +01001640 echo ""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001641
raviteja.karumurif6dce272024-05-03 16:50:07 +01001642 __log_test_pass
1643 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001644}
1645
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001646# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001647# args: <response-code> <policy-id> [count]
1648# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001649a1pms_api_delete_policy_batch() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001650 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001651
raviteja.karumurif6dce272024-05-03 16:50:07 +01001652 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1653 __print_err "<response-code> <policy-id> [count]" $@
1654 return 1
1655 fi
1656
1657 count=0
1658 max=1
1659
1660 if [ $# -eq 3 ]; then
1661 max=$3
1662 fi
1663
1664 pid=$2
1665 ARR=""
1666 while [ $count -lt $max ]; do
1667 if [ "$A1PMS_VERSION" == "V2" ]; then
1668 query="/v2/policies/"$UUID$pid
1669 else
1670 query="/policy?id="$UUID$pid
1671 fi
1672 res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)"
1673 status=${res:${#res}-3}
1674 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
1675
1676 if [ $status -ne 200 ]; then
1677 echo " Requested(batch) "$count"?("$max")"
1678 __log_test_fail_status_code 200 $status
1679 return 1
1680 fi
1681 cid=${res:0:${#res}-3}
1682 ARR=$ARR" "$cid
1683 let pid=$pid+1
1684 let count=$count+1
1685 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1686 done
1687
1688 echo ""
1689
1690 count=0
1691 for cid in $ARR; do
1692
1693 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
1694 status=${res:${#res}-3}
1695 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
1696
1697 if [ $status -ne $1 ]; then
1698 echo " Deleted(batch) "$count"?("$max")"
1699 __log_test_fail_status_code $1 $status
1700 return 1
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001701 fi
1702
raviteja.karumurif6dce272024-05-03 16:50:07 +01001703 let count=$count+1
1704 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1705 done
1706 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001707
raviteja.karumurif6dce272024-05-03 16:50:07 +01001708 echo ""
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001709
raviteja.karumurif6dce272024-05-03 16:50:07 +01001710 __log_test_pass
1711 return 0
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001712}
1713
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001714# 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 +02001715# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1716# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001717a1pms_api_delete_policy_parallel() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001718 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001719
raviteja.karumurif6dce272024-05-03 16:50:07 +01001720 if [ $# -ne 5 ]; then
1721 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1722 return 1
1723 fi
1724 resp_code=$1
1725 shift
1726 num_rics=$1
1727 shift
1728 start_id=$1
1729 shift
1730 count=$1
1731 shift
1732 pids=$1
1733 shift
1734
1735 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1736 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1737 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported"
1738 echo " Info - will execute over a1pms REST"
1739 fi
1740
1741 if [ "$A1PMS_VERSION" == "V2" ]; then
1742 query="$A1PMS_API_PREFIX/v2/policies/"
1743 else
1744 query="/policy"
1745 fi
1746
1747 urlbase=${A1PMS_ADAPTER}${query}
1748
1749 httpproxy="NOPROXY"
1750 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1751 httpproxy=$KUBE_PROXY_PATH
1752 fi
1753
1754 for ((i = 1; i <= $pids; i++)); do
1755 uuid=$UUID
1756 if [ -z "$uuid" ]; then
1757 uuid="NOUUID"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001758 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01001759 echo "" >"./tmp/.pid${i}.del.res.txt"
1760 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy >"./tmp/.pid${i}.del.txt"
1761 echo $i
1762 done | xargs -n 1 -I{} -P $pids bash -c '{
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001763 arg=$(echo {})
1764 echo " Parallel process $arg started"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001765 tmp=$(< "./tmp/.pid${arg}.del.txt")
1766 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001767 }'
raviteja.karumurif6dce272024-05-03 16:50:07 +01001768 msg=""
1769 for ((i = 1; i <= $pids; i++)); do
1770 file="./tmp/.pid${i}.del.res.txt"
1771 tmp=$(<$file)
1772 if [ -z "$tmp" ]; then
1773 echo " Process $i : unknown result (result file empty"
1774 msg="failed"
1775 else
1776 res=${tmp:0:1}
1777 if [ $res == "0" ]; then
1778 echo " Process $i : OK - "${tmp:1}
1779 else
1780 echo " Process $i : failed - "${tmp:1}
1781 msg="failed"
1782 fi
1783 fi
1784 done
1785 if [ -z $msg ]; then
1786 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count * $num_rics))
1787 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1788 return 0
1789 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001790
raviteja.karumurif6dce272024-05-03 16:50:07 +01001791 __log_test_fail_general "One of more processes failed to execute"
1792 return 1
1793}
1794
1795# API Test function: V3 DELETE a1policymanagement/v1/policies/{policy_id}, to run in i parallel for a number of rics
1796# args: <responseCode> <numberOfRics> <PolicyIdsFilePath> <countPerRic> <numberOfThreads>
1797# (Function for test scripts)
1798a1pms_api_delete_policy_parallel_v3() {
1799 __log_test_start $@
1800
1801 if [ $# -ne 6 ]; then
1802 __print_err " <responseCode> <numberOfRics> <PolicyIdsFilePath> <StartID> <countPerRic> <numberOfThreads>" $@
1803 return 1
1804 fi
1805 resp_code=$1
1806 shift
1807 num_rics=$1
1808 shift
1809 policy_ids_file_path=$1
1810 shift
1811 start_id=$1
1812 shift
1813 count=$1
1814 shift
1815 pids=$1
1816 shift
1817
1818 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1819 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1820 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported"
1821 echo " Info - will execute over a1pms REST"
1822 fi
1823
1824 query="$A1PMS_API_PREFIX/v1/policies/"
1825 urlbase=${A1PMS_ADAPTER}${query}
1826
1827 urlbase=${A1PMS_ADAPTER}${query}
1828
1829 httpproxy="NOPROXY"
1830 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1831 httpproxy=$KUBE_PROXY_PATH
1832 fi
1833
1834 for ((i = 1; i <= $pids; i++)); do
1835 echo "" >"./tmp/.pid${i}.del.res.txt"
1836 echo $resp_code $urlbase $policy_ids_file_path $start_id $pids $i $httpproxy >"./tmp/.pid${i}.del.txt"
1837 echo $i
1838 done | xargs -n 1 -I{} -P $pids bash -c '{
1839 arg=$(echo {})
1840 echo " Parallel process $arg started"
1841 tmp=$(< "./tmp/.pid${arg}.del.txt")
1842 python3 ../common/delete_policies_process_v3.py $tmp > ./tmp/.pid${arg}.del.res.txt
1843 }'
1844 msg=""
1845 for ((i = 1; i <= $pids; i++)); do
1846 file="./tmp/.pid${i}.del.res.txt"
1847 tmp=$(<$file)
1848 if [ -z "$tmp" ]; then
1849 echo " Process $i : unknown result (result file empty"
1850 msg="failed"
1851 else
1852 res=${tmp:0:1}
1853 if [ $res == "0" ]; then
1854 echo " Process $i : OK - "${tmp:1}
1855 else
1856 echo " Process $i : failed - "${tmp:1}
1857 msg="failed"
1858 fi
1859 fi
1860 done
1861 if [ -z $msg ]; then
1862 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v1/policies/{policy_id}" $resp_code $(($count * $num_rics))
1863 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1864 return 0
1865 fi
1866
1867 __log_test_fail_general "One of more processes failed to execute"
1868 return 1
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001869}
1870
JohnKeeney2f3b2682024-03-22 16:56:46 +00001871# API Test function: GET /policy and V2 GET /v2/policies/{policy_id}, to run in i parallel for a number of rics
1872# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1873# (Function for test scripts)
1874a1pms_api_get_policy_parallel() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01001875 __log_test_start $@
JohnKeeney2f3b2682024-03-22 16:56:46 +00001876
raviteja.karumurif6dce272024-05-03 16:50:07 +01001877 if [ $# -ne 5 ]; then
1878 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1879 return 1
1880 fi
1881 resp_code=$1
1882 shift
1883 num_rics=$1
1884 shift
1885 start_id=$1
1886 shift
1887 count=$1
1888 shift
1889 pids=$1
1890 shift
1891
1892 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1893 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1894 echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported"
1895 echo " Info - will execute over a1pms REST"
1896 fi
1897
1898 if [ "$A1PMS_VERSION" == "V2" ]; then
1899 query="$A1PMS_API_PREFIX/v2/policies/"
1900 else
1901 query="/policy"
1902 fi
1903
1904 urlbase=${A1PMS_ADAPTER}${query}
1905
1906 httpproxy="NOPROXY"
1907 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1908 httpproxy=$KUBE_PROXY_PATH
1909 fi
1910
1911 for ((i = 1; i <= $pids; i++)); do
1912 uuid=$UUID
1913 if [ -z "$uuid" ]; then
1914 uuid="NOUUID"
JohnKeeney2f3b2682024-03-22 16:56:46 +00001915 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01001916 echo "" >"./tmp/.pid${i}.get.res.txt"
1917 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy >"./tmp/.pid${i}.get.txt"
1918 echo $i
1919 done | xargs -n 1 -I{} -P $pids bash -c '{
JohnKeeney2f3b2682024-03-22 16:56:46 +00001920 arg=$(echo {})
1921 echo " Parallel process $arg started"
1922 tmp=$(< "./tmp/.pid${arg}.get.txt")
1923 python3 ../common/get_policies_process.py $tmp > ./tmp/.pid${arg}.get.res.txt
1924 }'
raviteja.karumurif6dce272024-05-03 16:50:07 +01001925 msg=""
1926 for ((i = 1; i <= $pids; i++)); do
1927 file="./tmp/.pid${i}.get.res.txt"
1928 tmp=$(<$file)
1929 if [ -z "$tmp" ]; then
1930 echo " Process $i : unknown result (result file empty"
1931 msg="failed"
1932 else
1933 res=${tmp:0:1}
1934 if [ $res == "0" ]; then
1935 echo " Process $i : OK - "${tmp:1}
1936 else
1937 echo " Process $i : failed - "${tmp:1}
1938 msg="failed"
1939 fi
1940 fi
1941 done
1942 if [ -z $msg ]; then
1943 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count * $num_rics))
1944 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
1945 return 0
1946 fi
JohnKeeney2f3b2682024-03-22 16:56:46 +00001947
raviteja.karumurif6dce272024-05-03 16:50:07 +01001948 __log_test_fail_general "One of more processes failed to execute"
1949 return 1
1950}
1951
1952# API Test function: V3 GET a1policymanagement/v1/policies/{policy_id}, to run in i parallel for a number of rics
1953# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1954# (Function for test scripts)
1955a1pms_api_get_policy_parallel_v3() {
1956 __log_test_start $@
1957
1958 if [ $# -ne 6 ]; then
1959 __print_err " <responseCode> <numberOfRics> <PolicyIdsFilePath> <startID> <countPerRic> <numberOfThreads>" $@
1960 return 1
1961 fi
1962 resp_code=$1
1963 shift
1964 num_rics=$1
1965 shift
1966 policy_ids_file_path=$1
1967 shift
1968 start_id=$1
1969 shift
1970 count=$1
1971 shift
1972 pids=$1
1973 shift
1974
1975 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1976 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1977 echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported"
1978 echo " Info - will execute over a1pms REST"
1979 fi
1980
1981 query="$A1PMS_API_PREFIX/v1/policies/"
1982 urlbase=${A1PMS_ADAPTER}${query}
1983
1984 httpproxy="NOPROXY"
1985 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1986 httpproxy=$KUBE_PROXY_PATH
1987 fi
1988
1989 for ((i = 1; i <= $pids; i++)); do
1990 echo "" >"./tmp/.pid${i}.get.res.txt"
1991 echo $resp_code $urlbase $policy_ids_file_path $start_id $pids $i $httpproxy >"./tmp/.pid${i}.get.txt"
1992 echo $i
1993 done | xargs -n 1 -I{} -P $pids bash -c '{
1994 arg=$(echo {})
1995 echo " Parallel process $arg started"
1996 tmp=$(< "./tmp/.pid${arg}.get.txt")
1997 python3 ../common/get_policies_process_v3.py $tmp > ./tmp/.pid${arg}.get.res.txt
1998 }'
1999 msg=""
2000 for ((i = 1; i <= $pids; i++)); do
2001 file="./tmp/.pid${i}.get.res.txt"
2002 tmp=$(<$file)
2003 if [ -z "$tmp" ]; then
2004 echo " Process $i : unknown result (result file empty"
2005 msg="failed"
2006 else
2007 res=${tmp:0:1}
2008 if [ $res == "0" ]; then
2009 echo " Process $i : OK - "${tmp:1}
2010 else
2011 echo " Process $i : failed - "${tmp:1}
2012 msg="failed"
2013 fi
2014 fi
2015 done
2016 if [ -z $msg ]; then
2017 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v1/policies/{policyId}" $resp_code $(($count * $num_rics))
2018 __log_test_pass " $(($count * $num_rics)) policy request(s) executed"
2019 return 0
2020 fi
2021
2022 __log_test_fail_general "One of more processes failed to execute"
2023 return 1
JohnKeeney2f3b2682024-03-22 16:56:46 +00002024}
2025
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002026# API Test function: GET /policy_ids and V2 GET /v2/policies
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002027# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
2028# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002029a1pms_api_get_policy_ids() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002030 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002031
raviteja.karumurif6dce272024-05-03 16:50:07 +01002032 if [ $# -lt 4 ]; then
2033 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
2034 return 1
2035 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002036
raviteja.karumurif6dce272024-05-03 16:50:07 +01002037 queryparams=""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002038
raviteja.karumurif6dce272024-05-03 16:50:07 +01002039 if [ "$A1PMS_VERSION" == "V2" ]; then
2040 if [ $2 != "NORIC" ]; then
2041 queryparams="?ric_id="$2
2042 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002043
raviteja.karumurif6dce272024-05-03 16:50:07 +01002044 if [ $3 != "NOSERVICE" ]; then
2045 if [ -z $queryparams ]; then
2046 queryparams="?service_id="$3
2047 else
2048 queryparams=$queryparams"&service_id="$3
2049 fi
2050 fi
2051 if [ $4 != "NOTYPE" ]; then
2052 if [ -z $queryparams ]; then
2053 queryparams="?policytype_id="$4
2054 else
2055 queryparams=$queryparams"&policytype_id="$4
2056 fi
2057 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002058
raviteja.karumurif6dce272024-05-03 16:50:07 +01002059 query="/v2/policies"$queryparams
2060 else
2061 if [ $2 != "NORIC" ]; then
2062 queryparams="?ric="$2
2063 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002064
raviteja.karumurif6dce272024-05-03 16:50:07 +01002065 if [ $3 != "NOSERVICE" ]; then
2066 if [ -z $queryparams ]; then
2067 queryparams="?service="$3
2068 else
2069 queryparams=$queryparams"&service="$3
2070 fi
2071 fi
2072 if [ $4 != "NOTYPE" ]; then
2073 if [ -z $queryparams ]; then
2074 queryparams="?type="$4
2075 else
2076 queryparams=$queryparams"&type="$4
2077 fi
2078 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002079
raviteja.karumurif6dce272024-05-03 16:50:07 +01002080 query="/policy_ids"$queryparams
2081 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002082
raviteja.karumurif6dce272024-05-03 16:50:07 +01002083 res="$(__do_curl_to_api A1PMS GET $query)"
2084 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002085
raviteja.karumurif6dce272024-05-03 16:50:07 +01002086 if [ $status -ne $1 ]; then
2087 __log_test_fail_status_code $1 $status
2088 return 1
2089 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002090
raviteja.karumurif6dce272024-05-03 16:50:07 +01002091 if [ $# -gt 4 ]; then
2092 body=${res:0:${#res}-3}
2093 targetJson="["
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002094
raviteja.karumurif6dce272024-05-03 16:50:07 +01002095 for pid in ${@:5}; do
2096 if [ "$targetJson" != "[" ]; then
2097 targetJson=$targetJson","
2098 fi
2099 if [ $pid != "NOID" ]; then
2100 targetJson=$targetJson"\"$UUID$pid\""
2101 fi
2102 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002103
raviteja.karumurif6dce272024-05-03 16:50:07 +01002104 targetJson=$targetJson"]"
2105 if [ "$A1PMS_VERSION" == "V2" ]; then
2106 targetJson="{\"policy_ids\": $targetJson}"
2107 fi
2108 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2109 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002110
raviteja.karumurif6dce272024-05-03 16:50:07 +01002111 if [ $res -ne 0 ]; then
2112 __log_test_fail_body
2113 return 1
2114 fi
2115 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002116
raviteja.karumurif6dce272024-05-03 16:50:07 +01002117 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status
2118 __log_test_pass
2119 return 0
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002120}
2121
raviteja.karumuri64755e02024-05-29 18:20:42 +01002122# API Test function: V3 GET a1policymanagement/v1/policies
2123# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
2124# (Function for test scripts)
2125a1pms_api_get_all_policies_v3() {
2126 __log_test_start $@
2127
2128 if [ $# -lt 4 ]; then
2129 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
2130 return 1
2131 fi
2132
2133 queryparams=""
2134
2135 if [ $2 != "NORIC" ]; then
2136 queryparams="?nearRtRicId="$2
2137 fi
2138
2139 if [ $3 != "NOSERVICE" ]; then
2140 if [ -z $queryparams ]; then
2141 queryparams="?serviceId="$3
2142 else
2143 queryparams=$queryparams"&serviceId="$3
2144 fi
2145 fi
2146 if [ $4 != "NOTYPE" ]; then
2147 if [ -z $queryparams ]; then
2148 queryparams="?policyTypeId="$4
2149 else
2150 queryparams=$queryparams"&policyTypeId="$4
2151 fi
2152 fi
2153
2154 query="/v1/policies"$queryparams
2155
2156 res="$(__do_curl_to_api A1PMS GET $query)"
2157 status=${res:${#res}-3}
2158
2159 if [ $status -ne $1 ]; then
2160 __log_test_fail_status_code $1 $status
2161 return 1
2162 fi
2163
2164 if [ $# -gt 4 ]; then
2165 body=${res:0:${#res}-3}
2166 targetJson="["
2167
2168 for pid in ${@:5}; do
2169 if [ "$targetJson" != "[" ]; then
2170 targetJson=$targetJson","
2171 fi
2172 IFS=':' read -r policy_id ric_id <<<"$pid"
2173 if [ $policy_id != "NOID" ]; then
2174 targetJson=$targetJson"{ \"policyId\": \"${UUID}${policy_id}\", \"nearRtRicId\": \"$ric_id\" }"
2175 fi
2176 done
2177
2178 targetJson=$targetJson"]"
2179 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2180 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2181
2182 if [ $res -ne 0 ]; then
2183 __log_test_fail_body
2184 return 1
2185 fi
2186 fi
2187
2188 __collect_endpoint_stats "A1PMS" 04 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2189 __log_test_pass
2190 return 0
2191}
2192
2193# API Test function: V2 GET a1-policy/v2/policy-types/{policyTypeId} and V3 GET a1policymanagement/v1/policytypes/{policyTypeId}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002194# args(V2): <response-code> <policy-type-id> [<schema-file>]
2195# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002196a1pms_api_get_policy_type() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002197 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002198
raviteja.karumuri64755e02024-05-29 18:20:42 +01002199 if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
raviteja.karumurif6dce272024-05-03 16:50:07 +01002200 __log_test_fail_not_supported
2201 return 1
2202 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002203
raviteja.karumurif6dce272024-05-03 16:50:07 +01002204 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2205 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
2206 return 1
2207 fi
raviteja.karumuri64755e02024-05-29 18:20:42 +01002208 if [ "$A1PMS_VERSION" == "V2" ]; then
2209 query="/v2/policy-types/$2"
2210 fi
2211 if [ "$A1PMS_VERSION" == "V3" ]; then
2212 query="/v1/policytypes/$2"
2213 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002214
2215 res="$(__do_curl_to_api A1PMS GET $query)"
2216 status=${res:${#res}-3}
2217
2218 if [ $status -ne $1 ]; then
2219 __log_test_fail_status_code $1 $status
2220 return 1
2221 fi
2222
2223 if [ $# -eq 3 ]; then
2224
2225 body=${res:0:${#res}-3}
2226
2227 targetJson=$(<$3)
raviteja.karumuri64755e02024-05-29 18:20:42 +01002228 if [ "$A1PMS_VERSION" == "V2" ]; then
2229 targetJson="{\"policy_schema\":$targetJson}"
2230 elif [ "$A1PMS_VERSION" == "V3" ]; then
2231 targetJson="$targetJson"
2232 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002233 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2234 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2235
2236 if [ $res -ne 0 ]; then
2237 __log_test_fail_body
2238 return 1
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002239 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002240 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002241
raviteja.karumuri64755e02024-05-29 18:20:42 +01002242 __collect_endpoint_stats "A1PMS" 05 "GET" ${A1PMS_API_PREFIX}${query} ${status}
raviteja.karumurif6dce272024-05-03 16:50:07 +01002243 __log_test_pass
2244 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002245}
2246
2247# API Test function: GET /policy_schema
2248# args: <response-code> <policy-type-id> [<schema-file>]
2249# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002250a1pms_api_get_policy_schema() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002251 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002252
raviteja.karumurif6dce272024-05-03 16:50:07 +01002253 if [ "$A1PMS_VERSION" == "V2" ]; then
2254 __log_test_fail_not_supported
2255 return 1
2256 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002257
raviteja.karumurif6dce272024-05-03 16:50:07 +01002258 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2259 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
2260 return 1
2261 fi
2262 query="/policy_schema?id=$2"
2263 res="$(__do_curl_to_api A1PMS GET $query)"
2264 status=${res:${#res}-3}
2265
2266 if [ $status -ne $1 ]; then
2267 __log_test_fail_status_code $1 $status
2268 return 1
2269 fi
2270
2271 if [ $# -eq 3 ]; then
2272
2273 body=${res:0:${#res}-3}
2274
2275 targetJson=$(<$3)
2276
2277 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2278 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2279
2280 if [ $res -ne 0 ]; then
2281 __log_test_fail_body
2282 return 1
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002283 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002284 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002285
raviteja.karumurif6dce272024-05-03 16:50:07 +01002286 __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status
2287 __log_test_pass
2288 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002289}
2290
2291# API Test function: GET /policy_schemas
2292# args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002293# args(V2): <response-code>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002294# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002295a1pms_api_get_policy_schemas() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002296 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002297
raviteja.karumurif6dce272024-05-03 16:50:07 +01002298 if [ "$A1PMS_VERSION" == "V2" ]; then
2299 if [ $# -ne 1 ]; then
2300 __print_err "<response-code>" $@
2301 return 1
2302 fi
2303 else
2304 if [ $# -lt 2 ]; then
2305 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
2306 return 1
2307 fi
2308 fi
2309 if [ "$A1PMS_VERSION" == "V2" ]; then
2310 query="/v2/policy-schemas"
2311 else
2312 query="/policy_schemas"
2313 if [ $2 != "NORIC" ]; then
2314 query=$query"?ric="$2
2315 fi
2316 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002317
raviteja.karumurif6dce272024-05-03 16:50:07 +01002318 res="$(__do_curl_to_api A1PMS GET $query)"
2319 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002320
raviteja.karumurif6dce272024-05-03 16:50:07 +01002321 if [ $status -ne $1 ]; then
2322 __log_test_fail_status_code $1 $status
2323 return 1
2324 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002325
raviteja.karumurif6dce272024-05-03 16:50:07 +01002326 if [ $# -gt 2 ]; then
2327 body=${res:0:${#res}-3}
2328 targetJson="["
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002329
raviteja.karumurif6dce272024-05-03 16:50:07 +01002330 for file in ${@:3}; do
2331 if [ "$targetJson" != "[" ]; then
2332 targetJson=$targetJson","
2333 fi
2334 if [ $file == "NOFILE" ]; then
2335 targetJson=$targetJson"{}"
2336 else
2337 targetJson=$targetJson$(<$file)
2338 fi
2339 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002340
raviteja.karumurif6dce272024-05-03 16:50:07 +01002341 targetJson=$targetJson"]"
2342 if [ "$A1PMS_VERSION" == "V2" ]; then
2343 targetJson="{\"policy_schemas\": $targetJson }"
2344 fi
2345 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2346 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002347
raviteja.karumurif6dce272024-05-03 16:50:07 +01002348 if [ $res -ne 0 ]; then
2349 __log_test_fail_body
2350 return 1
2351 fi
2352 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002353
raviteja.karumurif6dce272024-05-03 16:50:07 +01002354 __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status
2355 __log_test_pass
2356 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002357}
2358
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002359# API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002360# arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002361# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002362a1pms_api_get_policy_status() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002363 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002364
raviteja.karumurif6dce272024-05-03 16:50:07 +01002365 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2366 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
2367 return 1
2368 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002369
raviteja.karumurif6dce272024-05-03 16:50:07 +01002370 targetJson=""
2371 if [ $# -eq 2 ]; then
2372 :
2373 elif [ "$3" == "STD" ]; then
2374 targetJson="{\"enforceStatus\":\"$4\""
2375 if [ $# -eq 5 ]; then
2376 targetJson=$targetJson",\"reason\":\"$5\""
2377 fi
2378 targetJson=$targetJson"}"
2379 elif [ "$3" == "STD2" ]; then
2380 if [ $4 == "EMPTY" ]; then
2381 targetJson="{\"enforceStatus\":\"\""
2382 else
2383 targetJson="{\"enforceStatus\":\"$4\""
2384 fi
2385 if [ $# -eq 5 ]; then
2386 if [ $5 == "EMPTY" ]; then
2387 targetJson=$targetJson",\"enforceReason\":\"\""
2388 else
2389 targetJson=$targetJson",\"enforceReason\":\"$5\""
2390 fi
2391 fi
2392 targetJson=$targetJson"}"
2393 elif [ "$3" == "OSC" ]; then
2394 if [[ $TEST_ENV_PROFILE =~ ^ORAN-[A-H] ]] || [[ $TEST_ENV_PROFILE =~ ^ONAP-[A-L] ]]; then
raviteja.karumuri2c6c06e2024-05-27 10:58:44 +01002395 targetJson="{\"instance_status\":\"$4\""
2396 if [ $# -eq 5 ]; then
2397 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
2398 fi
2399 targetJson=$targetJson",\"created_at\":\"????\"}"
2400 else
2401 targetJson="{\"enforceStatus\":\"$4\""
2402 if [ $# -eq 5 ]; then
2403 targetJson=$targetJson",\"enforceReason\":\"$5\"}"
2404 fi
2405 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002406 else
2407 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
2408 return 1
2409 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002410
raviteja.karumurif6dce272024-05-03 16:50:07 +01002411 if [ "$A1PMS_VERSION" == "V2" ]; then
2412 query="/v2/policies/$UUID$2/status"
2413 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
2414 else
2415 query="/policy_status?id="$UUID$2
2416 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002417
raviteja.karumurif6dce272024-05-03 16:50:07 +01002418 res="$(__do_curl_to_api A1PMS GET $query)"
2419 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002420
raviteja.karumurif6dce272024-05-03 16:50:07 +01002421 if [ $status -ne $1 ]; then
2422 __log_test_fail_status_code $1 $status
2423 return 1
2424 fi
2425 if [ $# -gt 2 ]; then
2426 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2427 body=${res:0:${#res}-3}
2428 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002429
raviteja.karumurif6dce272024-05-03 16:50:07 +01002430 if [ $res -ne 0 ]; then
2431 __log_test_fail_body
2432 return 1
2433 fi
2434 fi
2435 __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
2436 __log_test_pass
2437 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002438}
2439
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002440# API Test function: GET /policy_types and V2 GET /v2/policy-types
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002441# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
2442# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002443a1pms_api_get_policy_types() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002444 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002445
raviteja.karumurif6dce272024-05-03 16:50:07 +01002446 if [ $# -lt 1 ]; then
2447 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
2448 return 1
2449 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002450
raviteja.karumurif6dce272024-05-03 16:50:07 +01002451 if [ "$A1PMS_VERSION" == "V2" ]; then
2452 if [ $# -eq 1 ]; then
2453 query="/v2/policy-types"
2454 elif [ $2 == "NORIC" ]; then
2455 query="/v2/policy-types"
2456 else
2457 query="/v2/policy-types?ric_id=$2"
2458 fi
2459 else
2460 if [ $# -eq 1 ]; then
2461 query="/policy_types"
2462 elif [ $2 == "NORIC" ]; then
2463 query="/policy_types"
2464 else
2465 query="/policy_types?ric=$2"
2466 fi
2467 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002468
raviteja.karumurif6dce272024-05-03 16:50:07 +01002469 res="$(__do_curl_to_api A1PMS GET $query)"
2470 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002471
raviteja.karumurif6dce272024-05-03 16:50:07 +01002472 if [ $status -ne $1 ]; then
2473 __log_test_fail_status_code $1 $status
2474 return 1
2475 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002476
raviteja.karumurif6dce272024-05-03 16:50:07 +01002477 if [ $# -gt 2 ]; then
2478 body=${res:0:${#res}-3}
2479 targetJson="["
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002480
raviteja.karumurif6dce272024-05-03 16:50:07 +01002481 for pid in ${@:3}; do
2482 if [ "$targetJson" != "[" ]; then
2483 targetJson=$targetJson","
2484 fi
2485 if [ $pid == "EMPTY" ]; then
2486 pid=""
2487 fi
2488 targetJson=$targetJson"\"$pid\""
2489 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002490
raviteja.karumurif6dce272024-05-03 16:50:07 +01002491 targetJson=$targetJson"]"
2492 if [ "$A1PMS_VERSION" == "V2" ]; then
2493 targetJson="{\"policytype_ids\": $targetJson }"
2494 fi
2495 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2496 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002497
raviteja.karumurif6dce272024-05-03 16:50:07 +01002498 if [ $res -ne 0 ]; then
2499 __log_test_fail_body
2500 return 1
2501 fi
2502 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002503
raviteja.karumurif6dce272024-05-03 16:50:07 +01002504 __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
2505 __log_test_pass
2506 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002507}
2508
raviteja.karumuri64755e02024-05-29 18:20:42 +01002509# API Test function: V3 GET a1policymanagement/v1/policytypes
2510# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
2511# (Function for test scripts)
2512a1pms_api_get_policy_types_v3() {
2513 __log_test_start $@
2514
2515 if [ $# -lt 1 ]; then
2516 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
2517 return 1
2518 fi
2519
2520 if [ $# -eq 1 ]; then
2521 query="/v1/policytypes"
2522 elif [ $2 == "NORIC" ]; then
2523 query="/v1/policytypes"
2524 else
2525 query="/v1/policytypes?nearRtRicId=$2"
2526 fi
2527 res="$(__do_curl_to_api A1PMS GET $query)"
2528 status=${res:${#res}-3}
2529
2530 if [ $status -ne $1 ]; then
2531 __log_test_fail_status_code $1 $status
2532 return 1
2533 fi
2534
2535 if [ $# -gt 2 ]; then
2536 body=${res:0:${#res}-3}
2537 targetJson="["
2538
2539 for pid in ${@:3}; do
2540 if [ "$targetJson" != "[" ]; then
2541 targetJson=$targetJson","
2542 fi
2543 IFS=':' read -r policy_type_id ric_id <<<"$pid"
2544 # if [ -n "$policy_type_id" ] && [ -n "$ric_id" ]; then
2545 if [ $policy_type_id == "EMPTY" ]; then
2546 policy_type_id=""
2547 fi
2548 targetJson=$targetJson"{ \"policyTypeId\": \"$policy_type_id\", \"nearRtRicId\": \"$ric_id\" }"
2549 # fi
2550 done
2551
2552 targetJson=$targetJson"]"
2553
2554 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2555 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2556
2557 if [ $res -ne 0 ]; then
2558 __log_test_fail_body
2559 return 1
2560 fi
2561 fi
2562
2563 __collect_endpoint_stats "A1PMS" 09 "GET" ${A1PMS_API_PREFIX}${query} ${status}
2564 __log_test_pass
2565 return 0
2566}
2567
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002568#########################################################
2569#### Test case functions Health check
2570#########################################################
2571
raviteja.karumurif6dce272024-05-03 16:50:07 +01002572# API Test function: GET /status and V2 GET /status or (v1/status for a1pmsV3)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002573# args: <response-code>
2574# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002575a1pms_api_get_status() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002576 __log_test_start $@
2577 if [ $# -ne 1 ]; then
2578 __print_err "<response-code>" $@
2579 return 1
2580 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002581
raviteja.karumurif6dce272024-05-03 16:50:07 +01002582 if [ "$A1PMS_VERSION" == "V2" ]; then
2583 query="/v2/status"
2584 elif [ "$A1PMS_VERSION" == "V3" ]; then
2585 query="/v1/status"
2586 else
2587 query="/status"
2588 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002589
raviteja.karumurif6dce272024-05-03 16:50:07 +01002590 res="$(__do_curl_to_api A1PMS GET $query)"
2591 status=${res:${#res}-3}
2592
2593 if [ $status -ne $1 ]; then
2594 __log_test_fail_status_code $1 $status
2595 return 1
2596 fi
2597
raviteja.karumuri64755e02024-05-29 18:20:42 +01002598 __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX$query $status
raviteja.karumurif6dce272024-05-03 16:50:07 +01002599 __log_test_pass
2600 return 0
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002601}
2602
2603# API Test function: GET /status (root) without api prefix
2604# args: <response-code>
2605# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002606a1pms_api_get_status_root() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002607 __log_test_start $@
2608 if [ $# -ne 1 ]; then
2609 __print_err "<response-code>" $@
2610 return 1
2611 fi
2612 query="/status"
2613 TMP_PREFIX=$A1PMS_API_PREFIX
2614 A1PMS_API_PREFIX=""
2615 res="$(__do_curl_to_api A1PMS GET $query)"
2616 A1PMS_API_PREFIX=$TMP_PREFIX
2617 status=${res:${#res}-3}
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002618
raviteja.karumurif6dce272024-05-03 16:50:07 +01002619 if [ $status -ne $1 ]; then
2620 __log_test_fail_status_code $1 $status
2621 return 1
2622 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002623
raviteja.karumurif6dce272024-05-03 16:50:07 +01002624 __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
2625 __log_test_pass
2626 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002627}
2628
2629#########################################################
2630#### Test case functions RIC Repository
2631#########################################################
2632
raviteja.karumuri64755e02024-05-29 18:20:42 +01002633# API Test function: GET /ric, V2 GET /v2/rics/ric, and V3 GET a1policymanagement/v1/rics/ric
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002634# args: <reponse-code> <management-element-id> [<ric-id>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002635# (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
2636# (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
2637# (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2638
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002639# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002640a1pms_api_get_ric() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002641 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002642
raviteja.karumurif6dce272024-05-03 16:50:07 +01002643 if [ "$A1PMS_VERSION" == "V2" ]; then
2644 if [ $# -lt 3 ]; then
2645 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
2646 return 1
2647 fi
2648 search=""
2649 if [ $2 != "NOME" ]; then
2650 search="?managed_element_id="$2
2651 fi
2652 if [ $3 != "NORIC" ]; then
2653 if [ -z $search ]; then
2654 search="?ric_id="$3
2655 else
2656 search=$search"&ric_id="$3
2657 fi
2658 fi
2659 query="/v2/rics/ric"$search
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002660
raviteja.karumurif6dce272024-05-03 16:50:07 +01002661 res="$(__do_curl_to_api A1PMS GET $query)"
2662 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002663
raviteja.karumurif6dce272024-05-03 16:50:07 +01002664 if [ $status -ne $1 ]; then
2665 __log_test_fail_status_code $1 $status
2666 return 1
2667 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002668
raviteja.karumurif6dce272024-05-03 16:50:07 +01002669 if [ $# -gt 3 ]; then
2670 body=${res:0:${#res}-3}
2671 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4")
2672 if [ $res -ne 0 ]; then
2673 __log_test_fail_general "Could not create target ric info json"
2674 return 1
2675 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002676
raviteja.karumurif6dce272024-05-03 16:50:07 +01002677 targetJson=$(<./tmp/.tmp_rics.json)
2678 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
2679 echo " TARGET JSON: $targetJson" >>$HTTPLOG
2680 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2681 if [ $res -ne 0 ]; then
2682 __log_test_fail_body
2683 return 1
2684 fi
2685 fi
raviteja.karumuri64755e02024-05-29 18:20:42 +01002686 elif [ "$A1PMS_VERSION" == "V3" ]; then
2687 if [ $# -lt 3 ]; then
2688 __print_err "<reponseCode> <managementElementId>|NOME <ricId>|<NORIC> [stringOfRicInfo>]" $@
2689 return 1
2690 fi
2691 search=""
2692 if [ $2 != "NOME" ]; then
2693 search="?managedElementId="$2
2694 fi
2695 if [ $3 != "NORIC" ]; then
2696 if [ -z $search ]; then
2697 search="?ricId="$3
2698 else
2699 search=$search"&ricId="$3
2700 fi
2701 fi
2702 query="/v1/rics/ric"$search
2703
2704 res="$(__do_curl_to_api A1PMS GET $query)"
2705 status=${res:${#res}-3}
2706
2707 if [ $status -ne $1 ]; then
2708 __log_test_fail_status_code $1 $status
2709 return 1
2710 fi
2711
2712 if [ $# -gt 3 ]; then
2713 body=${res:0:${#res}-3}
2714 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "${A1PMS_VERSION}" "$4")
2715 if [ $res -ne 0 ]; then
2716 __log_test_fail_general "Could not create target ric info json"
2717 return 1
2718 fi
2719
2720 targetJson=$(<./tmp/.tmp_rics.json)
2721 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
2722 echo " TARGET JSON: $targetJson" >>$HTTPLOG
2723 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2724 if [ $res -ne 0 ]; then
2725 __log_test_fail_body
2726 return 1
2727 fi
2728 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002729 else
2730 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
raviteja.karumuri64755e02024-05-29 18:20:42 +01002731 __print_err "<reponseCode> <managedElementIds> [<ricId>]" $@
raviteja.karumurif6dce272024-05-03 16:50:07 +01002732 return 1
2733 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002734
raviteja.karumurif6dce272024-05-03 16:50:07 +01002735 query="/ric?managedElementId="$2
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002736
raviteja.karumurif6dce272024-05-03 16:50:07 +01002737 res="$(__do_curl_to_api A1PMS GET $query)"
2738 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002739
raviteja.karumurif6dce272024-05-03 16:50:07 +01002740 if [ $status -ne $1 ]; then
2741 __log_test_fail_status_code $1 $status
2742 return 1
2743 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002744
raviteja.karumurif6dce272024-05-03 16:50:07 +01002745 if [ $# -eq 3 ]; then
2746 body=${res:0:${#res}-3}
2747 if [ "$body" != "$3" ]; then
2748 __log_test_fail_body
2749 return 1
2750 fi
2751 fi
2752 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002753
raviteja.karumuri64755e02024-05-29 18:20:42 +01002754 __collect_endpoint_stats "A1PMS" 11 "GET" ${A1PMS_API_PREFIX}${query} ${status}
raviteja.karumurif6dce272024-05-03 16:50:07 +01002755 __log_test_pass
2756 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002757}
2758
raviteja.karumuri64755e02024-05-29 18:20:42 +01002759# API test function: GET /rics, V2 GET /v2/rics, and V3 GET /a1policymanagement/v1/rics
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002760# args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
2761# 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_........."
2762# format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
2763# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002764a1pms_api_get_rics() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002765 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002766
raviteja.karumurif6dce272024-05-03 16:50:07 +01002767 if [ $# -lt 2 ]; then
2768 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
2769 return 1
2770 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002771
raviteja.karumurif6dce272024-05-03 16:50:07 +01002772 if [ "$A1PMS_VERSION" == "V2" ]; then
2773 query="/v2/rics"
2774 if [ $2 != "NOTYPE" ]; then
2775 query="/v2/rics?policytype_id="$2
2776 fi
raviteja.karumuri64755e02024-05-29 18:20:42 +01002777 elif [ "$A1PMS_VERSION" == "V3" ]; then
2778 query="/v1/rics"
2779 if [ $2 != "NOTYPE" ]; then
2780 query=${query}"?policyTypeId="$2
2781 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002782 else
2783 query="/rics"
2784 if [ $2 != "NOTYPE" ]; then
2785 query="/rics?policyType="$2
2786 fi
2787 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002788
raviteja.karumurif6dce272024-05-03 16:50:07 +01002789 res="$(__do_curl_to_api A1PMS GET $query)"
2790 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002791
raviteja.karumurif6dce272024-05-03 16:50:07 +01002792 if [ $status -ne $1 ]; then
2793 __log_test_fail_status_code $1 $status
2794 return 1
2795 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002796
raviteja.karumurif6dce272024-05-03 16:50:07 +01002797 if [ $# -gt 2 ]; then
2798 body=${res:0:${#res}-3}
raviteja.karumuri64755e02024-05-29 18:20:42 +01002799 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "${A1PMS_VERSION}" "$3")
raviteja.karumurif6dce272024-05-03 16:50:07 +01002800 if [ $res -ne 0 ]; then
2801 __log_test_fail_general "Could not create target ric info json"
2802 return 1
2803 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002804
raviteja.karumurif6dce272024-05-03 16:50:07 +01002805 targetJson=$(<./tmp/.tmp_rics.json)
raviteja.karumuri64755e02024-05-29 18:20:42 +01002806 if [ "$A1PMS_VERSION" == "V2" ] || [ "$A1PMS_VERSION" == "V3" ]; then
raviteja.karumurif6dce272024-05-03 16:50:07 +01002807 targetJson="{\"rics\": $targetJson }"
2808 fi
2809 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2810 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2811 if [ $res -ne 0 ]; then
2812 __log_test_fail_body
2813 return 1
2814 fi
2815 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002816
raviteja.karumuri64755e02024-05-29 18:20:42 +01002817 __collect_endpoint_stats "A1PMS" 12 "GET" ${A1PMS_API_PREFIX}${query} ${status}
raviteja.karumurif6dce272024-05-03 16:50:07 +01002818 __log_test_pass
2819 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002820}
2821
2822##################################################################
2823#### API Test case functions Service registry and supervision ####
2824##################################################################
2825
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002826# API test function: PUT /service and V2 PUT /service
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002827# args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2828# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002829a1pms_api_put_service() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002830 __log_test_start $@
2831 if [ $# -ne 4 ]; then
2832 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2833 return 1
2834 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002835
raviteja.karumurif6dce272024-05-03 16:50:07 +01002836 if [ "$A1PMS_VERSION" == "V2" ]; then
2837 query="/v2/services"
2838 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2839 elif [ "$A1PMS_VERSION" == "V3" ]; then
2840 query="/v1/services"
2841 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceId\": \""$2"\"}"
2842 else
2843 query="/service"
2844 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2845 fi
2846 file="./tmp/.tmp.json"
2847 echo "$json" >$file
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002848
raviteja.karumurif6dce272024-05-03 16:50:07 +01002849 res="$(__do_curl_to_api A1PMS PUT $query $file)"
2850 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002851
raviteja.karumurif6dce272024-05-03 16:50:07 +01002852 if [ $status -ne $1 ]; then
2853 __log_test_fail_status_code $1 $status
2854 return 1
2855 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002856
raviteja.karumuri64755e02024-05-29 18:20:42 +01002857 __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX$query $status
raviteja.karumurif6dce272024-05-03 16:50:07 +01002858 __log_test_pass
2859 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002860}
2861
raviteja.karumuri64755e02024-05-29 18:20:42 +01002862# API test function: GET /services, V2 GET /v2/services and V3 /a1policymanagement/v1/services
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002863#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>]* )]
2864# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002865a1pms_api_get_services() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002866 __log_test_start $@
2867 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2868 paramError=1
2869 if [ $# -eq 1 ]; then
2870 paramError=0
2871 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2872 paramError=0
2873 elif [ $# -eq 5 ]; then
2874 paramError=0
2875 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2876 argLen=$(($# - 2))
2877 if [ $(($argLen % 3)) -eq 0 ]; then
2878 paramError=0
2879 fi
2880 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002881
raviteja.karumurif6dce272024-05-03 16:50:07 +01002882 if [ $paramError -ne 0 ]; then
2883 __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>]* )]" $@
2884 return 1
2885 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002886
raviteja.karumurif6dce272024-05-03 16:50:07 +01002887 if [ "$A1PMS_VERSION" == "V2" ]; then
2888 query="/v2/services"
raviteja.karumurif6dce272024-05-03 16:50:07 +01002889 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2890 query="/v2/services?service_id="$2
2891 fi
raviteja.karumuri64755e02024-05-29 18:20:42 +01002892 elif [ "$A1PMS_VERSION" == "V3" ]; then
2893 query="/v1/services"
2894 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2895 query="/v1/services?serviceId="$2
2896 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01002897 else
2898 query="/services"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002899
raviteja.karumurif6dce272024-05-03 16:50:07 +01002900 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2901 query="/services?name="$2
2902 fi
2903 fi
2904 res="$(__do_curl_to_api A1PMS GET $query)"
2905 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002906
raviteja.karumurif6dce272024-05-03 16:50:07 +01002907 if [ $status -ne $1 ]; then
2908 __log_test_fail_status_code $1 $status
2909 return 1
2910 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002911
raviteja.karumurif6dce272024-05-03 16:50:07 +01002912 if [ $# -gt 2 ]; then
2913 variableArgCount=$(($# - 2))
2914 body=${res:0:${#res}-3}
2915 targetJson="["
2916 shift
2917 shift
2918 cntr=0
2919 while [ $cntr -lt $variableArgCount ]; do
2920 servicename=$1
2921 shift
2922 timeout=$1
2923 shift
2924 callback=$1
2925 shift
2926 if [ $cntr -gt 0 ]; then
2927 targetJson=$targetJson","
2928 fi
2929 # timeSinceLastActivitySeconds value cannot be checked since value varies
2930 if [ "$A1PMS_VERSION" == "V2" ]; then
2931 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
raviteja.karumuri64755e02024-05-29 18:20:42 +01002932 elif [ "$A1PMS_VERSION" == "V3" ]; then
2933 targetJson=$targetJson"{\"serviceId\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
raviteja.karumurif6dce272024-05-03 16:50:07 +01002934 else
2935 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2936 fi
2937 let cntr=cntr+3
2938 done
2939 targetJson=$targetJson"]"
2940 if [ "$A1PMS_VERSION" == "V2" ]; then
2941 targetJson="{\"service_list\": $targetJson }"
raviteja.karumuri64755e02024-05-29 18:20:42 +01002942 URL_for_Collect_End_Point="/v2/services"
2943 elif [ "$A1PMS_VERSION" == "V3" ]; then
2944 targetJson="{\"serviceList\": $targetJson }"
2945 URL_for_Collect_End_Point="/v1/services"
raviteja.karumurif6dce272024-05-03 16:50:07 +01002946 fi
2947 echo "TARGET JSON: $targetJson" >>$HTTPLOG
2948 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2949 if [ $res -ne 0 ]; then
2950 __log_test_fail_body
2951 return 1
2952 fi
2953 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002954
raviteja.karumuri64755e02024-05-29 18:20:42 +01002955 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX$URL_for_Collect_End_Point $status
raviteja.karumurif6dce272024-05-03 16:50:07 +01002956 __log_test_pass
2957 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002958}
2959
raviteja.karumuri64755e02024-05-29 18:20:42 +01002960# API test function: GET /services, V2 GET /v2/services and V3 /a1policymanagement/v1/services - (only checking service names)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002961# args: <response-code> [<service-name>]*"
2962# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002963a1pms_api_get_service_ids() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01002964 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002965
raviteja.karumurif6dce272024-05-03 16:50:07 +01002966 if [ $# -lt 1 ]; then
2967 __print_err "<response-code> [<service-name>]*" $@
2968 return 1
2969 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002970
raviteja.karumurif6dce272024-05-03 16:50:07 +01002971 if [ "$A1PMS_VERSION" == "V2" ]; then
2972 query="/v2/services"
raviteja.karumuri64755e02024-05-29 18:20:42 +01002973 elif [ "$A1PMS_VERSION" == "V3" ]; then
2974 query="/v1/services"
raviteja.karumurif6dce272024-05-03 16:50:07 +01002975 else
2976 query="/services"
2977 fi
2978 res="$(__do_curl_to_api A1PMS GET $query)"
2979 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002980
raviteja.karumurif6dce272024-05-03 16:50:07 +01002981 if [ $status -ne $1 ]; then
2982 __log_test_fail_status_code $1 $status
2983 return 1
2984 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002985
raviteja.karumurif6dce272024-05-03 16:50:07 +01002986 body=${res:0:${#res}-3}
2987 targetJson="["
2988 for rapp in ${@:2}; do
2989 if [ "$targetJson" != "[" ]; then
2990 targetJson=$targetJson","
2991 fi
2992 if [ "$A1PMS_VERSION" == "V2" ]; then
2993 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
raviteja.karumuri64755e02024-05-29 18:20:42 +01002994 elif [ "$A1PMS_VERSION" == "V3" ]; then
2995 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceId\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
raviteja.karumurif6dce272024-05-03 16:50:07 +01002996 else
2997 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2998 fi
2999 done
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003000
raviteja.karumurif6dce272024-05-03 16:50:07 +01003001 targetJson=$targetJson"]"
3002 if [ "$A1PMS_VERSION" == "V2" ]; then
3003 targetJson="{\"service_list\": $targetJson }"
raviteja.karumuri64755e02024-05-29 18:20:42 +01003004 URL_for_Collect_End_Point="/v2/services"
3005 elif [ "$A1PMS_VERSION" == "V3" ]; then
3006 targetJson="{\"serviceList\": $targetJson }"
3007 URL_for_Collect_End_Point="/v1/services"
raviteja.karumurif6dce272024-05-03 16:50:07 +01003008 fi
3009 echo "TARGET JSON: $targetJson" >>$HTTPLOG
3010 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003011
raviteja.karumurif6dce272024-05-03 16:50:07 +01003012 if [ $res -ne 0 ]; then
3013 __log_test_fail_body
3014 return 1
3015 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003016
raviteja.karumuri64755e02024-05-29 18:20:42 +01003017 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX$URL_for_Collect_End_Point $status
raviteja.karumurif6dce272024-05-03 16:50:07 +01003018 __log_test_pass
3019 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003020}
3021
BjornMagnussonXA4207b832020-11-03 09:52:49 +01003022# API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003023# args: <response-code> <service-name>
3024# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01003025a1pms_api_delete_services() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01003026 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003027
raviteja.karumurif6dce272024-05-03 16:50:07 +01003028 if [ $# -ne 2 ]; then
3029 __print_err "<response-code> <service-name>" $@
3030 return 1
3031 fi
3032 if [ "$A1PMS_VERSION" == "V2" ]; then
raviteja.karumuri64755e02024-05-29 18:20:42 +01003033 url_part="/v2/services/"
3034 query=${url_part}${2}
3035 elif [ "$A1PMS_VERSION" == "V3" ]; then
3036 url_part="/v1/services/"
3037 query=${url_part}${2}
raviteja.karumurif6dce272024-05-03 16:50:07 +01003038 else
3039 query="/services?name="$2
3040 fi
3041 res="$(__do_curl_to_api A1PMS DELETE $query)"
3042 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003043
raviteja.karumurif6dce272024-05-03 16:50:07 +01003044 if [ $status -ne $1 ]; then
3045 __log_test_fail_status_code $1 $status
3046 return 1
3047 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003048
raviteja.karumuri64755e02024-05-29 18:20:42 +01003049 __collect_endpoint_stats "A1PMS" 15 "DELETE" ${A1PMS_API_PREFIX}${url_part}"{serviceId}" $status
raviteja.karumurif6dce272024-05-03 16:50:07 +01003050 __log_test_pass
3051 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003052}
3053
BjornMagnussonXA4207b832020-11-03 09:52:49 +01003054# API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003055# args: <response-code> <service-name>
3056# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01003057a1pms_api_put_services_keepalive() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01003058 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003059
raviteja.karumurif6dce272024-05-03 16:50:07 +01003060 if [ $# -ne 2 ]; then
3061 __print_err "<response-code> <service-name>" $@
3062 return 1
3063 fi
3064 if [ "$A1PMS_VERSION" == "V2" ]; then
3065 query="/v2/services/$2/keepalive"
3066 else
3067 query="/services/keepalive?name="$2
3068 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003069
raviteja.karumurif6dce272024-05-03 16:50:07 +01003070 res="$(__do_curl_to_api A1PMS PUT $query)"
3071 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003072
raviteja.karumurif6dce272024-05-03 16:50:07 +01003073 if [ $status -ne $1 ]; then
3074 __log_test_fail_status_code $1 $status
3075 return 1
3076 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003077
raviteja.karumurif6dce272024-05-03 16:50:07 +01003078 __collect_endpoint_stats "A1PMS" 16 "PUT" $A1PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
3079 __log_test_pass
3080 return 0
BjornMagnussonXA80a92002020-03-19 14:31:06 +01003081}
3082
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003083##################################################################
3084#### API Test case functions Configuration ####
3085##################################################################
3086
raviteja.karumurif6dce272024-05-03 16:50:07 +01003087# API Test function: PUT "/v2/configuration" or "/v1/configuration"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003088# args: <response-code> <config-file>
3089# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01003090a1pms_api_put_configuration() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01003091 __log_test_start $@
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003092
raviteja.karumurif6dce272024-05-03 16:50:07 +01003093 if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
3094 __log_test_fail_not_supported
3095 return 1
3096 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003097
raviteja.karumurif6dce272024-05-03 16:50:07 +01003098 if [ $# -ne 2 ]; then
3099 __print_err "<response-code> <config-file>" $@
3100 return 1
3101 fi
3102 if [ ! -f $2 ]; then
3103 __log_test_fail_general "Config file "$2", does not exist"
3104 return 1
3105 fi
3106 inputJson=$(<$2)
3107 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
3108 # inputJson="{\"config\":"$inputJson"}"
3109 # fi
3110 file="./tmp/.config.json"
3111 echo $inputJson >$file
3112 if [ "$A1PMS_VERSION" == "V2" ]; then
3113 query="/v2/configuration"
3114 elif [ "$A1PMS_VERSION" == "V3" ]; then
3115 #V3 has baseurl changes 'a1-policy/v2' to 'a1policymanagement/v1'
3116 query="/v1/configuration"
3117 fi
3118 res="$(__do_curl_to_api A1PMS PUT $query $file)"
3119 status=${res:${#res}-3}
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003120
raviteja.karumurif6dce272024-05-03 16:50:07 +01003121 if [ $status -ne $1 ]; then
3122 __log_test_fail_status_code $1 $status
3123 return 1
3124 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003125
raviteja.karumuri64755e02024-05-29 18:20:42 +01003126 __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX$query $status
raviteja.karumurif6dce272024-05-03 16:50:07 +01003127 __log_test_pass
3128 return 0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003129}
3130
3131# API Test function: GET /v2/configuration
3132# args: <response-code> [<config-file>]
3133# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01003134a1pms_api_get_configuration() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01003135 __log_test_start $@
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003136
raviteja.karumuri64755e02024-05-29 18:20:42 +01003137 if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then
raviteja.karumurif6dce272024-05-03 16:50:07 +01003138 __log_test_fail_not_supported
3139 return 1
3140 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003141
raviteja.karumurif6dce272024-05-03 16:50:07 +01003142 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
3143 __print_err "<response-code> [<config-file>]" $@
3144 return 1
3145 fi
3146 if [ ! -f $2 ]; then
3147 __log_test_fail_general "Config file "$2" for comparison, does not exist"
3148 return 1
3149 fi
3150
raviteja.karumuri64755e02024-05-29 18:20:42 +01003151 if [ "$A1PMS_VERSION" == "V3" ]; then
3152 #The V3 of a1-pms URL is a1policymanagement/v1 and the v2 is a1-policy/v2
3153 query="/v1/configuration"
3154 else
3155 query="/v2/configuration"
3156 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01003157 res="$(__do_curl_to_api A1PMS GET $query)"
3158 status=${res:${#res}-3}
3159
3160 if [ $status -ne $1 ]; then
3161 __log_test_fail_status_code $1 $status
3162 return 1
3163 fi
3164
3165 if [ $# -eq 2 ]; then
3166
3167 body=${res:0:${#res}-3}
3168
3169 targetJson=$(<$2)
3170 # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
3171 # inputJson="{\"config\":"$inputJson"}"
3172 # fi
3173 echo "TARGET JSON: $targetJson" >>$HTTPLOG
3174 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
3175
3176 if [ $res -ne 0 ]; then
3177 __log_test_fail_body
3178 return 1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003179 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01003180 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01003181
raviteja.karumuri64755e02024-05-29 18:20:42 +01003182 if [ "$A1PMS_VERSION" == "V3" ]; then
3183 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v1/configuration" $status
3184 else
3185 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
3186 fi
raviteja.karumurif6dce272024-05-03 16:50:07 +01003187 __log_test_pass
3188 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02003189}
3190
3191##########################################
3192#### Reset types and instances ####
3193##########################################
3194
3195# Admin reset to remove all policies and services
3196# All types and instances etc are removed - types and instances in a1 sims need to be removed separately
3197# NOTE - only works in kubernetes and the pod should not be running
3198# args: -
3199# (Function for test scripts)
3200
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01003201a1pms_kube_pvc_reset() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01003202 __log_test_start $@
BjornMagnussonXAa5491572021-05-04 09:21:24 +02003203
raviteja.karumurif6dce272024-05-03 16:50:07 +01003204 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
3205 if [ -z "$pvc_name" ]; then
3206 pvc_name=policymanagementservice-vardata-pvc
3207 fi
3208 echo " Trying to reset pvc: "$pvc_name
3209 __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR
BjornMagnussonXAa5491572021-05-04 09:21:24 +02003210
raviteja.karumurif6dce272024-05-03 16:50:07 +01003211 __log_test_pass
3212 return 0
BjornMagnussonXAcd938442022-05-11 10:01:24 +02003213}
3214
3215# args: <realm> <client-name> <client-secret>
3216a1pms_configure_sec() {
raviteja.karumurif6dce272024-05-03 16:50:07 +01003217 export A1PMS_CREDS_GRANT_TYPE="client_credentials"
3218 export A1PMS_CREDS_CLIENT_SECRET=$3
3219 export A1PMS_CREDS_CLIENT_ID=$2
3220 export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token
3221 export A1PMS_SIDECAR_MOUNT="/token-cache"
3222 export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt"
BjornMagnussonXAcd938442022-05-11 10:01:24 +02003223
raviteja.karumurif6dce272024-05-03 16:50:07 +01003224 export AUTHSIDECAR_APP_NAME
3225 export AUTHSIDECAR_DISPLAY_NAME
3226}