blob: f5397171c5a6264bc0c9638f17987a28b052169d [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/bin/bash
2
3# ============LICENSE_START===============================================
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01004# Copyright (C) 2021 Nordix Foundation. All rights reserved.
BjornMagnussonXA80a92002020-03-19 14:31:06 +01005# ========================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ============LICENSE_END=================================================
18#
19
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010020# This is a script that contains management and test functions for A1PMS
BjornMagnussonXA80a92002020-03-19 14:31:06 +010021
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010022################ Test engine functions ################
23
24# Create the image var used during the test
25# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
26# <image-tag-suffix> is present only for images with staging, snapshot,release tags
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010027__A1PMS_imagesetup() {
28 __check_and_create_image_var A1PMS "A1PMS_IMAGE" "A1PMS_IMAGE_BASE" "A1PMS_IMAGE_TAG" $1 "$A1PMS_DISPLAY_NAME"
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010029}
30
31# Pull image from remote repo or use locally built image
32# arg: <pull-policy-override> <pull-policy-original>
33# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
34# <pull-policy-original> Shall be used for images that does not allow overriding
35# Both var may contain: 'remote', 'remote-remove' or 'local'
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010036__A1PMS_imagepull() {
37 __check_and_pull_image $1 "$A1PMS_DISPLAY_NAME" $A1PMS_APP_NAME A1PMS_IMAGE
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010038}
39
40# Build image (only for simulator or interfaces stubs owned by the test environment)
41# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
42# <image-tag-suffix> is present only for images with staging, snapshot,release tags
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010043__A1PMS_imagebuild() {
44 echo -e $RED" Image for app A1PMS shall never be built"$ERED
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010045}
46
47# Generate a string for each included image using the app display name and a docker images format string
BjornMagnussonXA483ee332021-04-08 01:35:24 +020048# If a custom image repo is used then also the source image from the local repo is listed
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010049# arg: <docker-images-format-string> <file-to-append>
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010050__A1PMS_image_data() {
51 echo -e "$A1PMS_DISPLAY_NAME\t$(docker images --format $1 $A1PMS_IMAGE)" >> $2
52 if [ ! -z "$A1PMS_IMAGE_SOURCE" ]; then
53 echo -e "-- source image --\t$(docker images --format $1 $A1PMS_IMAGE_SOURCE)" >> $2
BjornMagnussonXA483ee332021-04-08 01:35:24 +020054 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010055}
56
57# Scale kubernetes resources to zero
58# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
59# This function is called for apps fully managed by the test script
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010060__A1PMS_kube_scale_zero() {
61 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010062}
63
64# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
65# This function is called for prestarted apps not managed by the test script.
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010066__A1PMS_kube_scale_zero_and_wait() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +010067 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-policymanagementservice
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010068}
69
70# Delete all kube resouces for the app
71# This function is called for apps managed by the test script.
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010072__A1PMS_kube_delete_all() {
73 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010074}
75
76# Store docker logs
77# This function is called for apps managed by the test script.
78# args: <log-dir> <file-prexix>
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010079__A1PMS_store_docker_logs() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +010080 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010081 kubectl $KUBECONF logs -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_a1pms.log 2>&1
BjornMagnussonXA663566c2021-11-08 10:25:07 +010082 else
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010083 docker logs $A1PMS_APP_NAME > $1$2_a1pms.log 2>&1
BjornMagnussonXA663566c2021-11-08 10:25:07 +010084 fi
85}
86
87# Initial setup of protocol, host and ports
88# This function is called for apps managed by the test script.
89# args: -
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010090__A1PMS_initial_setup() {
91 use_a1pms_rest_http
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010092}
93
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +010094# Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
95# For docker, the namespace shall be excluded
96# This function is called for apps managed by the test script as well as for prestarted apps.
97# args: -
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +010098__A1PMS_statisics_setup() {
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +010099 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100100 echo "A1PMS $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100101 else
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100102 echo "A1PMS $A1PMS_APP_NAME"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100103 fi
104}
105
BjornMagnussonXAe60d04e2021-12-27 13:38:01 +0100106# Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
107# args: -
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100108__A1PMS_test_requirements() {
BjornMagnussonXAe60d04e2021-12-27 13:38:01 +0100109 :
110}
111
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100112
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100113#######################################################
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100114
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100115###########################
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100116### A1PMSs functions
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100117###########################
118
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100119# Set http as the protocol to use for all communication to the A1PMS
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100120# args: -
121# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100122use_a1pms_rest_http() {
123 __a1pms_set_protocoll "http" $A1PMS_INTERNAL_PORT $A1PMS_EXTERNAL_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100124}
125
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100126# Set https as the protocol to use for all communication to the A1PMS
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100127# args: -
128# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100129use_a1pms_rest_https() {
130 __a1pms_set_protocoll "https" $A1PMS_INTERNAL_SECURE_PORT $A1PMS_EXTERNAL_SECURE_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100131}
132
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100133# All calls to the a1pms will be directed to the a1pms dmaap interface over http from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100134# args: -
135# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100136use_a1pms_dmaap_http() {
137 echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
138 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
139 A1PMS_ADAPTER_TYPE="MR-HTTP"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100140 echo ""
141}
142
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100143# All calls to the a1pms will be directed to the a1pms dmaap interface over https from now on
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100144# args: -
145# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100146use_a1pms_dmaap_https() {
147 echo -e $BOLD"$A1PMS_DISPLAY_NAME dmaap protocol setting"$EBOLD
148 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the a1pms"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100149 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100150 A1PMS_ADAPTER_TYPE="MR-HTTPS"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100151 echo ""
152}
153
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100154# Setup paths to svc/container for internal and external access
155# args: <protocol> <internal-port> <external-port>
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100156__a1pms_set_protocoll() {
157 echo -e $BOLD"$A1PMS_DISPLAY_NAME protocol setting"$EBOLD
158 echo -e " Using $BOLD $1 $EBOLD towards $A1PMS_DISPLAY_NAME"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100159
160 ## Access to Dmaap adapter
161
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100162 A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME":"$2 # docker access, container->container and script->container via proxy
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100163 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100164 A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100165 fi
166
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100167 # A1PMS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
168 A1PMS_ADAPTER_TYPE="REST"
169 A1PMS_ADAPTER=$A1PMS_SERVICE_PATH
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100170
171 echo ""
172}
173
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100174# Make curl retries towards the a1pms for http response codes set in this env var, space separated list of codes
175A1PMS_RETRY_CODES=""
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100176
177#Save first worker node the pod is started on
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100178__A1PMS_WORKER_NODE=""
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100179
180# Export env vars for config files, docker compose and kube resources
181# args: PROXY|NOPROXY
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100182__export_a1pms_vars() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100183
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100184 export A1PMS_APP_NAME
185 export A1PMS_APP_NAME_ALIAS
186 export A1PMS_DISPLAY_NAME
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100187
188 export KUBE_NONRTRIC_NAMESPACE
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100189 export A1PMS_IMAGE
190 export A1PMS_INTERNAL_PORT
191 export A1PMS_INTERNAL_SECURE_PORT
192 export A1PMS_EXTERNAL_PORT
193 export A1PMS_EXTERNAL_SECURE_PORT
194 export A1PMS_CONFIG_MOUNT_PATH
195 export A1PMS_DATA_MOUNT_PATH
196 export A1PMS_CONFIG_CONFIGMAP_NAME=$A1PMS_APP_NAME"-config"
197 export A1PMS_DATA_CONFIGMAP_NAME=$A1PMS_APP_NAME"-data"
198 export A1PMS_PKG_NAME
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100199 export CONSUL_HOST
200 export CONSUL_INTERNAL_PORT
201 export CONFIG_BINDING_SERVICE
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100202 export A1PMS_CONFIG_KEY
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100203 export DOCKER_SIM_NWNAME
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100204 export A1PMS_HOST_MNT_DIR
205 export A1PMS_CONFIG_FILE
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100206
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100207 export A1PMS_DATA_PV_NAME=$A1PMS_APP_NAME"-pv"
208 export A1PMS_DATA_PVC_NAME=$A1PMS_APP_NAME"-pvc"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100209 ##Create a unique path for the pv each time to prevent a previous volume to be reused
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100210 export A1PMS_PV_PATH="a1pmsdata-"$(date +%s)
211 export A1PMS_CONTAINER_MNT_DIR
BjornMagnussonXAc8f92e92022-02-28 15:16:37 +0100212 export HOST_PATH_BASE_DIR
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100213
214 if [ $1 == "PROXY" ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100215 export A1PMS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
216 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
217 if [ $A1PMS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$A1PMS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100218 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
219 else
220 echo " Configured with http proxy"
221 fi
222 else
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100223 export A1PMS_HTTP_PROXY_CONFIG_PORT=0
224 export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME=""
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100225 echo " Configured without http proxy"
226 fi
227}
228
229
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100230# Start the ms
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100231# args: (docker) PROXY|NOPROXY <config-file>
232# args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100233# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100234start_a1pms() {
235 echo -e $BOLD"Starting $A1PMS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100236
237 if [ $RUNMODE == "KUBE" ]; then
238
239 # Check if app shall be fully managed by the test script
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100240 __check_included_image "A1PMS"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100241 retcode_i=$?
242
243 # Check if app shall only be used by the testscipt
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100244 __check_prestarted_image "A1PMS"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100245 retcode_p=$?
246
247 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100248 echo -e $RED"The $A1PMS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
249 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100250 exit
251 fi
252 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100253 echo -e $RED"The $A1PMS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
254 echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100255 exit
256 fi
257
258 if [ $retcode_p -eq 0 ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100259 echo -e " Using existing $A1PMS_APP_NAME deployment and service"
260 echo " Setting $A1PMS_APP_NAME replicas=1"
261 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
262 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100263 fi
264
265 if [ $retcode_i -eq 0 ]; then
266
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100267 echo -e " Creating $A1PMS_APP_NAME app and expose service"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100268
269 #Check if nonrtric namespace exists, if not create it
270 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
271
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100272 __export_a1pms_vars $1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100273
274 # Create config map for config
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100275 configfile=$PWD/tmp/$A1PMS_CONFIG_FILE
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100276 cp $2 $configfile
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100277 output_yaml=$PWD/tmp/a1pms-cfc.yaml
278 __kube_create_configmap $A1PMS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $configfile $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100279
280 # Create config map for data
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100281 data_json=$PWD/tmp/$A1PMS_DATA_FILE
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100282 if [ $# -lt 3 ]; then
283 #create empty dummy file
284 echo "{}" > $data_json
285 else
286 cp $3 $data_json
287 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100288 output_yaml=$PWD/tmp/a1pms-cfd.yaml
289 __kube_create_configmap $A1PMS_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100290
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200291 ## Create pv
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100292 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pv.yaml
293 output_yaml=$PWD/tmp/a1pms-pv.yaml
294 __kube_create_instance pv $A1PMS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200295
296 ## Create pvc
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100297 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pvc.yaml
298 output_yaml=$PWD/tmp/a1pms-pvc.yaml
299 __kube_create_instance pvc $A1PMS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200300
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100301 # Create service
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100302 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"svc.yaml
303 output_yaml=$PWD/tmp/a1pmssvc.yaml
304 __kube_create_instance service $A1PMS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100305
306 # Create app
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100307 input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"app.yaml
308 output_yaml=$PWD/tmp/a1pmsapp.yaml
309 __kube_create_instance app $A1PMS_APP_NAME $input_yaml $output_yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100310
311 fi
312
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200313 # 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
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200314 if [ $retcode_i -eq 0 ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100315 __A1PMS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
316 if [ -z "$__A1PMS_WORKER_NODE" ]; then
317 echo -e $YELLOW" Cannot find worker node for pod for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200318 fi
319 else
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100320 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
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200321 fi
322
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100323 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100324
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100325 else
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100326 __check_included_image 'A1PMS'
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100327 if [ $? -eq 1 ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100328 echo -e $RED"The A1PMS app is not included in this test script"$ERED
329 echo -e $RED"The A1PMS will not be started"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100330 exit
331 fi
332
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200333 curdir=$PWD
334 cd $SIM_GROUP
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100335 cd a1pms
336 cd $A1PMS_HOST_MNT_DIR
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200337 #cd ..
338 if [ -d db ]; then
339 if [ "$(ls -A $DIR)" ]; then
340 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
341 rm -rf db/* &> /dev/null
342 if [ $? -ne 0 ]; then
343 echo -e $RED" Cannot remove database files in: $PWD"$ERED
344 exit 1
345 fi
346 fi
347 else
348 echo " No files in mounted dir or dir does not exists"
349 fi
350 cd $curdir
351
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100352 __export_a1pms_vars $1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100353
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100354 dest_file=$SIM_GROUP/$A1PMS_COMPOSE_DIR/$A1PMS_HOST_MNT_DIR/application.yaml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100355
356 envsubst < $2 > $dest_file
357
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100358 __start_container $A1PMS_COMPOSE_DIR "" NODOCKERARGS 1 $A1PMS_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100359
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100360 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100361 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +0100362
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100363 __collect_endpoint_stats_image_info "A1PMS" $A1PMS_IMAGE
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100364 echo ""
365 return 0
366}
367
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100368# Stop the a1pms
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200369# args: -
370# args: -
371# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100372stop_a1pms() {
373 echo -e $BOLD"Stopping $A1PMS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200374
375 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200376
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100377 __check_prestarted_image "A1PMS"
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200378 if [ $? -eq 0 ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100379 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
380 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
381 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200382 return 0
383 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100384 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200385 echo " Deleting the replica set - a new will be started when the app is started"
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +0100386 tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200387 if [ $? -ne 0 ]; then
388 echo -e $RED" Could not delete replica set "$RED
389 ((RES_CONF_FAIL++))
390 return 1
391 fi
392 else
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100393 docker stop $A1PMS_APP_NAME &> ./tmp/.dockererr
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200394 if [ $? -ne 0 ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100395 __print_err "Could not stop $A1PMS_APP_NAME" $@
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200396 cat ./tmp/.dockererr
397 ((RES_CONF_FAIL++))
398 return 1
399 fi
400 fi
401 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
402 echo ""
403 return 0
404}
405
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100406# Start a previously stopped a1pms
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200407# args: -
408# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100409start_stopped_a1pms() {
410 echo -e $BOLD"Starting (the previously stopped) $A1PMS_DISPLAY_NAME"$EBOLD
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200411
412 if [ $RUNMODE == "KUBE" ]; then
413
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100414 __check_prestarted_image "A1PMS"
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200415 if [ $? -eq 0 ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100416 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
417 res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
418 __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
419 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200420 return 0
421 fi
422
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100423 # Tie the A1PMS to the same worker node it was initially started on
424 # 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
425 if [ -z "$__A1PMS_WORKER_NODE" ]; then
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200426 echo -e $RED" No initial worker node found for pod "$RED
427 ((RES_CONF_FAIL++))
428 return 1
429 else
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100430 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
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200431 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100432 tmp=$(kubectl $KUBECONF patch deployment $A1PMS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__A1PMS_WORKER_NODE'"}}}}}')
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200433 if [ $? -ne 0 ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100434 echo -e $YELLOW" Cannot set nodeSelector to deployment for $A1PMS_APP_NAME, persistency may not work"$EYELLOW
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200435 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100436 __kube_scale deployment $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200437 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200438 else
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100439 docker start $A1PMS_APP_NAME &> ./tmp/.dockererr
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200440 if [ $? -ne 0 ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100441 __print_err "Could not start (the stopped) $A1PMS_APP_NAME" $@
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200442 cat ./tmp/.dockererr
443 ((RES_CONF_FAIL++))
444 return 1
445 fi
446 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100447 __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200448 if [ $? -ne 0 ]; then
449 return 1
450 fi
451 echo ""
452 return 0
453}
454
455
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100456# Function to perpare the consul configuration according to the current simulator configuration
457# args: SDNC|NOSDNC <output-file>
458# (Function for test scripts)
459prepare_consul_config() {
460 echo -e $BOLD"Prepare Consul config"$EBOLD
461
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100462 echo " Writing consul config for "$A1PMS_APP_NAME" to file: "$2
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100463
464 if [ $# != 2 ]; then
465 ((RES_CONF_FAIL++))
466 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
467 exit 1
468 fi
469
470 if [ $1 == "SDNC" ]; then
471 echo -e " Config$BOLD including SDNC$EBOLD configuration"
472 elif [ $1 == "NOSDNC" ]; then
473 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
474 else
475 ((RES_CONF_FAIL++))
476 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
477 exit 1
478 fi
479
480 config_json="\n {"
481 if [ $1 == "SDNC" ]; then
482 config_json=$config_json"\n \"controller\": ["
483 config_json=$config_json"\n {"
484 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
485 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
486 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
487 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
488 config_json=$config_json"\n }"
489 config_json=$config_json"\n ],"
490 fi
491
492 config_json=$config_json"\n \"streams_publishes\": {"
493 config_json=$config_json"\n \"dmaap_publisher\": {"
494 config_json=$config_json"\n \"type\": \"message-router\","
495 config_json=$config_json"\n \"dmaap_info\": {"
496 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
497 config_json=$config_json"\n }"
498 config_json=$config_json"\n }"
499 config_json=$config_json"\n },"
500 config_json=$config_json"\n \"streams_subscribes\": {"
501 config_json=$config_json"\n \"dmaap_subscriber\": {"
502 config_json=$config_json"\n \"type\": \"message-router\","
503 config_json=$config_json"\n \"dmaap_info\": {"
504 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
505 config_json=$config_json"\n }"
506 config_json=$config_json"\n }"
507 config_json=$config_json"\n },"
508
509 config_json=$config_json"\n \"ric\": ["
510
511 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +0100512 result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100513 rics=""
514 ric_cntr=0
515 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
516 for im in $result; do
517 if [[ $im != *"-0" ]]; then
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +0100518 ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100519 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
520 let ric_cntr=ric_cntr+1
521 fi
522 done
523 fi
524 if [ $ric_cntr -eq 0 ]; then
525 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
526 fi
527 else
528 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
529 if [ $? -ne 0 ] || [ -z "$rics" ]; then
530 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
531 ((RES_CONF_FAIL++))
532 return 1
533 fi
534 fi
535 cntr=0
536 for ric in $rics; do
537 if [ $cntr -gt 0 ]; then
538 config_json=$config_json"\n ,"
539 fi
540 config_json=$config_json"\n {"
541 if [ $RUNMODE == "KUBE" ]; then
542 ric_id=${ric%.*.*} #extract pod id from full hosthame
543 ric_id=$(echo "$ric_id" | tr '-' '_')
544 else
BjornMagnussonXA51f04f02021-11-23 09:22:35 +0100545 if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
546 ric_id=$ric
547 else
548 ric_id=$(echo "$ric" | tr '-' '_') #ric id still needs underscore as it is different from the container name
549 fi
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100550 fi
551 echo " Found a1 sim: "$ric_id
552 config_json=$config_json"\n \"name\": \"$ric_id\","
553 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
554 if [ $1 == "SDNC" ]; then
555 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
556 fi
557 config_json=$config_json"\n \"managedElementIds\": ["
558 config_json=$config_json"\n \"me1_$ric_id\","
559 config_json=$config_json"\n \"me2_$ric_id\""
560 config_json=$config_json"\n ]"
561 config_json=$config_json"\n }"
562 let cntr=cntr+1
563 done
564
565 config_json=$config_json"\n ]"
566 config_json=$config_json"\n}"
567
568 if [ $RUNMODE == "KUBE" ]; then
569 config_json="{\"config\":"$config_json"}"
570 fi
571
572 printf "$config_json">$2
573
574 echo ""
575}
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200576
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100577# Load the the appl config for the a1pms into a config map
578a1pms_load_config() {
579 echo -e $BOLD"A1PMS - load config from "$EBOLD$1
580 data_json=$PWD/tmp/$A1PMS_DATA_FILE
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100581 cp $1 $data_json
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100582 output_yaml=$PWD/tmp/a1pms-cfd.yaml
583 __kube_create_configmap $A1PMS_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100584 echo ""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100585}
586
587
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100588# Turn on debug level tracing in the a1pms
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100589# args: -
590# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100591set_a1pms_debug() {
592 echo -e $BOLD"Setting a1pms debug logging"$EBOLD
593 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100594 result=$(__do_curl "$curlString")
595 if [ $? -ne 0 ]; then
596 __print_err "could not set debug mode" $@
597 ((RES_CONF_FAIL++))
598 return 1
599 fi
600 echo ""
601 return 0
602}
603
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100604# Turn on trace level tracing in the a1pms
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100605# args: -
606# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100607set_a1pms_trace() {
608 echo -e $BOLD"Setting a1pms trace logging"$EBOLD
609 curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100610 result=$(__do_curl "$curlString")
611 if [ $? -ne 0 ]; then
612 __print_err "could not set trace mode" $@
613 ((RES_CONF_FAIL++))
614 return 1
615 fi
616 echo ""
617 return 0
618}
619
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100620# Perform curl retries when making direct call to the a1pms for the specified http response codes
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100621# Speace separated list of http response codes
622# args: [<response-code>]*
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100623use_a1pms_retries() {
624 echo -e $BOLD"Do curl retries to the a1pms REST inteface for these response codes:$@"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100625 AGENT_RETRY_CODES=$@
626 echo ""
627 return
628}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100629
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100630# Check the a1pms logs for WARNINGs and ERRORs
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100631# args: -
632# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100633check_a1pms_logs() {
634 __check_container_logs "A1PMS" $A1PMS_APP_NAME $A1PMS_LOGPATH WARN ERR
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100635}
636
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100637#########################################################
638#### Test case functions A1 Policy management service
639#########################################################
640
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100641# 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 +0100642# This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
643# args: json:<url> <target-value> [<timeout-in-seconds]
644# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100645a1pms_equal() {
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100646 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
647 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
648 if [[ $1 == "json:"* ]]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100649 if [ "$A1PMS_VERSION" == "V2" ]; then
650 __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v2/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100651 else
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100652 __var_test "A1PMS" $A1PMS_SERVICE_PATH"/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100653 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100654 return 0
655 fi
656 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100657 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
658 return 1
659}
660
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100661# API Test function: GET /policies and V2 GET /v2/policy-instances
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100662# 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>]*]
663# 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 +0100664# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100665a1pms_api_get_policies() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100666 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100667
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100668 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100669 paramError=0
670 variableParams=$(($#-4))
671 if [ $# -lt 4 ]; then
672 paramError=1
673 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
674 paramError=1
675 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
676 paramError=1
677 fi
678
679 if [ $paramError -ne 0 ]; then
680 __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>]*]" $@
681 return 1
682 fi
683 else
684 paramError=0
685 variableParams=$(($#-4))
686 if [ $# -lt 4 ]; then
687 paramError=1
688 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
689 paramError=1
690 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
691 paramError=1
692 fi
693
694 if [ $paramError -ne 0 ]; then
695 __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>]*]" $@
696 return 1
697 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100698 fi
699
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100700 queryparams=""
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100701 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100702 if [ $2 != "NORIC" ]; then
703 queryparams="?ric_id="$2
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100704 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100705 if [ $3 != "NOSERVICE" ]; then
706 if [ -z $queryparams ]; then
707 queryparams="?service_id="$3
708 else
709 queryparams=$queryparams"&service_id="$3
710 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100711 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100712 if [ $4 != "NOTYPE" ]; then
713 if [ -z $queryparams ]; then
714 queryparams="?policytype_id="$4
715 else
716 queryparams=$queryparams"&policytype_id="$4
717 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100718 fi
719
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100720 query="/v2/policy-instances"$queryparams
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100721 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100722 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100723
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100724 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100725 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100726 return 1
727 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100728
729 if [ $# -gt 4 ]; then
730 body=${res:0:${#res}-3}
731 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
732 targetJson="["
733 else
734 targetJson="["
735 arr=(${@:5})
736
737 for ((i=0; i<$(($#-4)); i=i+7)); do
738
739 if [ "$targetJson" != "[" ]; then
740 targetJson=$targetJson","
741 fi
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100742 targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100743 if [ "${arr[$i+3]}" == "EMPTY" ]; then
744 targetJson=$targetJson"\"\","
745 else
746 targetJson=$targetJson"\"${arr[$i+3]}\","
747 fi
748 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
749 file="./tmp/.p.json"
750 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
751 json=$(cat $file)
752 targetJson=$targetJson"\"policy_data\":"$json"}"
753 done
754 fi
755
756 targetJson=$targetJson"]"
757 targetJson="{\"policies\": $targetJson}"
758 echo "TARGET JSON: $targetJson" >> $HTTPLOG
759 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
760
761 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100762 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100763 return 1
764 fi
765 fi
766 else
767 if [ $2 != "NORIC" ]; then
768 queryparams="?ric="$2
769 fi
770 if [ $3 != "NOSERVICE" ]; then
771 if [ -z $queryparams ]; then
772 queryparams="?service="$3
773 else
774 queryparams=$queryparams"&service="$3
775 fi
776 fi
777 if [ $4 != "NOTYPE" ]; then
778 if [ -z $queryparams ]; then
779 queryparams="?type="$4
780 else
781 queryparams=$queryparams"&type="$4
782 fi
783 fi
784
785 query="/policies"$queryparams
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100786 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100787 status=${res:${#res}-3}
788
789 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100790 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100791 return 1
792 fi
793
794 if [ $# -gt 4 ]; then
795 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
796 targetJson="["
797 else
798 body=${res:0:${#res}-3}
799 targetJson="["
800 arr=(${@:5})
801
802 for ((i=0; i<$(($#-4)); i=i+5)); do
803
804 if [ "$targetJson" != "[" ]; then
805 targetJson=$targetJson","
806 fi
807 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
808 if [ "${arr[$i+3]}" == "EMPTY" ]; then
809 targetJson=$targetJson"\"\","
810 else
811 targetJson=$targetJson"\"${arr[$i+3]}\","
812 fi
813 file="./tmp/.p.json"
814 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
815 json=$(cat $file)
816 targetJson=$targetJson"\"json\":"$json"}"
817 done
818 fi
819
820 targetJson=$targetJson"]"
821 echo "TARGET JSON: $targetJson" >> $HTTPLOG
822 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
823
824 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100825 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100826 return 1
827 fi
828 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100829 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100830 __collect_endpoint_stats "A1PMS" 00 "GET" $A1PMS_API_PREFIX"/v2/policy-instances" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100831 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100832 return 0
833
834}
835
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100836
837# API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
838# args: <response-code> <policy-id> [<template-file>]
839# args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
840
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100841# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100842a1pms_api_get_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100843 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100844
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100845
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100846 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100847 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
848 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
849 return 1
850 fi
851 query="/v2/policies/$UUID$2"
852 else
853 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
854 __print_err "<response-code> <policy-id> [<template-file>] " $@
855 return 1
856 fi
857 query="/policy?id=$UUID$2"
858 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100859 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100860 status=${res:${#res}-3}
861
862 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100863 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100864 return 1
865 fi
866
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100867 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100868 if [ $# -eq 8 ]; then
869
870 #Create a policy json to compare with
871 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100872
873 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
874 if [ $7 != "NOTRANSIENT" ]; then
875 targetJson=$targetJson", \"transient\":$7"
876 fi
877 if [ $6 != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100878 targetJson=$targetJson", \"policytype_id\":\"$6\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100879 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100880 targetJson=$targetJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100881 fi
882 if [ $8 != "NOURL" ]; then
883 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
884 fi
885
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100886 data=$(sed 's/XXX/'${2}'/g' $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100887 targetJson=$targetJson", \"policy_data\":$data"
888 targetJson="{$targetJson}"
889
890 echo "TARGET JSON: $targetJson" >> $HTTPLOG
891 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
892 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100893 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100894 return 1
895 fi
896 fi
897 else
898 if [ $# -eq 3 ]; then
899 #Create a policy json to compare with
900 body=${res:0:${#res}-3}
901 file="./tmp/.p.json"
902 sed 's/XXX/'${2}'/g' $3 > $file
903 targetJson=$(< $file)
904 echo "TARGET JSON: $targetJson" >> $HTTPLOG
905 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
906 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100907 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100908 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100909 fi
910 fi
911
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100912 __collect_endpoint_stats "A1PMS" 01 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100913 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100914 return 0
915}
916
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100917# API Test function: PUT /policy and V2 PUT /policies
918# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
919# 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 +0100920# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100921a1pms_api_put_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100922 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100923
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100924 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100925 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
926 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
927 return 1
928 fi
929 else
930 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
931 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
932 return 1
933 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100934 fi
935
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100936 count=0
937 max=1
938 serv=$2
939 ric=$3
940 pt=$4
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100941 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100942 trans=$6
943
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100944 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100945 noti=$7
946 temp=$8
947 if [ $# -eq 9 ]; then
948 max=$9
949 fi
950 else
951 temp=$7
952 if [ $# -eq 8 ]; then
953 max=$8
954 fi
955 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100956
957 while [ $count -lt $max ]; do
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100958 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100959
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100960 query="/v2/policies"
961
962 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
963 if [ $trans != "NOTRANSIENT" ]; then
964 inputJson=$inputJson", \"transient\":$trans"
965 fi
966 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100967 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100968 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100969 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100970 fi
971 if [ $noti != "NOURL" ]; then
972 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
973 fi
974 file="./tmp/.p.json"
975 data=$(sed 's/XXX/'${pid}'/g' $temp)
976 inputJson=$inputJson", \"policy_data\":$data"
977 inputJson="{$inputJson}"
978 echo $inputJson > $file
979 else
980 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
981
982 if [ $pt != "NOTYPE" ]; then
983 query=$query"&type=$pt"
984 fi
985
986 if [ $trans != NOTRANSIENT ]; then
987 query=$query"&transient=$trans"
988 fi
989
990 file="./tmp/.p.json"
991 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200992 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +0100993 res="$(__do_curl_to_api A1PMS PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100994 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200995 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100996 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200997 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100998 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100999 return 1
1000 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001001 let pid=$pid+1
1002 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001003 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001004 done
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001005 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $status $max
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001006 echo ""
1007
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001008 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001009 return 0
1010}
1011
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001012# API Test function: PUT /policy and V2 PUT /policies, to run in batch
1013# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1014# 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 +02001015# (Function for test scripts)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001016
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001017a1pms_api_put_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001018 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001019
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001020 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001021 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1022 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1023 return 1
1024 fi
1025 else
1026 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1027 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1028 return 1
1029 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001030 fi
1031
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001032 count=0
1033 max=1
1034 serv=$2
1035 ric=$3
1036 pt=$4
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001037 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001038 trans=$6
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001039 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001040 noti=$7
1041 temp=$8
1042 if [ $# -eq 9 ]; then
1043 max=$9
1044 fi
1045 else
1046 temp=$7
1047 if [ $# -eq 8 ]; then
1048 max=$8
1049 fi
1050 fi
1051
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001052 ARR=""
1053 while [ $count -lt $max ]; do
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001054 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001055 query="/v2/policies"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001056
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001057 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1058 if [ $trans != "NOTRANSIENT" ]; then
1059 inputJson=$inputJson", \"transient\":$trans"
1060 fi
1061 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001062 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001063 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001064 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001065 fi
1066 if [ $noti != "NOURL" ]; then
1067 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1068 fi
1069 file="./tmp/.p.json"
1070 data=$(sed 's/XXX/'${pid}'/g' $temp)
1071 inputJson=$inputJson", \"policy_data\":$data"
1072 inputJson="{$inputJson}"
1073 echo $inputJson > $file
1074 else
1075 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1076
1077 if [ $pt != "NOTYPE" ]; then
1078 query=$query"&type=$pt"
1079 fi
1080
1081 if [ $trans != NOTRANSIENT ]; then
1082 query=$query"&transient=$trans"
1083 fi
1084 file="./tmp/.p.json"
1085 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001086 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001087 res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001088 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001089 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001090
1091 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001092 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001093 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001094 return 1
1095 fi
1096 cid=${res:0:${#res}-3}
1097 ARR=$ARR" "$cid
1098 let pid=$pid+1
1099 let count=$count+1
1100 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1101 done
1102
1103 echo ""
1104 count=0
1105 for cid in $ARR; do
1106
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001107 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001108 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001109 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001110
1111 if [ $status -ne $1 ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001112 echo " Accepted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001113 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001114 return 1
1115 fi
1116
1117 let count=$count+1
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001118 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001119 done
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001120 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001121
1122 echo ""
1123
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001124 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001125 return 0
1126}
1127
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001128# 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 +02001129# 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 +01001130# 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 +02001131# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001132a1pms_api_put_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001133 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001134
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001135 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001136 if [ $# -ne 11 ]; then
1137 __print_err "<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>" $@
1138 return 1
1139 fi
1140 else
1141 if [ $# -ne 10 ]; then
1142 __print_err " <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <template-file> <count-per-ric> <number-of-threads>" $@
1143 return 1
1144 fi
1145 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001146 resp_code=$1; shift;
1147 serv=$1; shift
1148 ric_base=$1; shift;
1149 num_rics=$1; shift;
1150 type=$1; shift;
1151 start_id=$1; shift;
1152 transient=$1; shift;
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001153 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001154 noti=$1; shift;
1155 else
1156 noti=""
1157 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001158 template=$1; shift;
1159 count=$1; shift;
1160 pids=$1; shift;
1161
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001162 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1163 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1164 echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1165 echo " Info - will execute over a1pms REST"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001166 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001167 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001168 if [ $serv == "NOSERVICE" ]; then
1169 serv=""
1170 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001171 query="$A1PMS_API_PREFIX/v2/policies"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001172 else
1173 if [ $serv == "NOSERVICE" ]; then
1174 serv=""
1175 fi
1176 query="/policy?service=$serv"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001177
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001178 if [ $type != "NOTYPE" ]; then
1179 query=$query"&type=$type"
1180 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001181
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001182 if [ $transient != NOTRANSIENT ]; then
1183 query=$query"&transient=$transient"
1184 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001185 fi
1186
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001187 urlbase=${A1PMS_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001188
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001189 httpproxy="NOPROXY"
BjornMagnussonXA663566c2021-11-08 10:25:07 +01001190 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1191 httpproxy=$KUBE_PROXY_PATH
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001192 fi
1193
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001194 for ((i=1; i<=$pids; i++))
1195 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001196 uuid=$UUID
1197 if [ -z "$uuid" ]; then
1198 uuid="NOUUID"
1199 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001200 echo "" > "./tmp/.pid${i}.res.txt"
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001201 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001202 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001203 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001204 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy > "./tmp/.pid${i}.txt"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001205 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001206 echo $i
1207 done | xargs -n 1 -I{} -P $pids bash -c '{
1208 arg=$(echo {})
1209 echo " Parallel process $arg started"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001210 tmp=$(< "./tmp/.pid${arg}.txt")
1211 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001212 }'
1213 msg=""
1214 for ((i=1; i<=$pids; i++))
1215 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001216 file="./tmp/.pid${i}.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001217 tmp=$(< $file)
1218 if [ -z "$tmp" ]; then
1219 echo " Process $i : unknown result (result file empty"
1220 msg="failed"
1221 else
1222 res=${tmp:0:1}
1223 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001224 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001225 else
1226 echo " Process $i : failed - "${tmp:1}
1227 msg="failed"
1228 fi
1229 fi
1230 done
1231 if [ -z $msg ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001232 __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count*$num_rics))
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001233 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001234 return 0
1235 fi
1236
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001237 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001238 return 1
1239}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001240
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001241# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001242# args: <response-code> <policy-id> [count]
1243# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001244a1pms_api_delete_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001245 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001246
1247 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1248 __print_err "<response-code> <policy-id> [count]" $@
1249 return 1
1250 fi
1251
1252 count=0
1253 max=1
1254
1255 if [ $# -eq 3 ]; then
1256 max=$3
1257 fi
1258
1259 pid=$2
1260
1261 while [ $count -lt $max ]; do
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001262 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001263 query="/v2/policies/"$UUID$pid
1264 else
1265 query="/policy?id="$UUID$pid
1266 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001267 res="$(__do_curl_to_api A1PMS DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001268 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001269 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001270
1271 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001272 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001273 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001274 return 1
1275 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001276
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001277 let pid=$pid+1
1278 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001279 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001280 done
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001281 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $status $max
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001282 echo ""
1283
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001284 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001285 return 0
1286}
1287
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001288# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001289# args: <response-code> <policy-id> [count]
1290# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001291a1pms_api_delete_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001292 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001293
1294 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1295 __print_err "<response-code> <policy-id> [count]" $@
1296 return 1
1297 fi
1298
1299 count=0
1300 max=1
1301
1302 if [ $# -eq 3 ]; then
1303 max=$3
1304 fi
1305
1306 pid=$2
1307 ARR=""
1308 while [ $count -lt $max ]; do
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001309 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001310 query="/v2/policies/"$UUID$pid
1311 else
1312 query="/policy?id="$UUID$pid
1313 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001314 res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001315 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001316 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001317
1318 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001319 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001320 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001321 return 1
1322 fi
1323 cid=${res:0:${#res}-3}
1324 ARR=$ARR" "$cid
1325 let pid=$pid+1
1326 let count=$count+1
1327 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1328 done
1329
1330 echo ""
1331
1332 count=0
1333 for cid in $ARR; do
1334
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001335 res="$(__do_curl_to_api A1PMS RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001336 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001337 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001338
1339 if [ $status -ne $1 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001340 echo " Deleted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001341 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001342 return 1
1343 fi
1344
1345 let count=$count+1
1346 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1347 done
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001348 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $1 $max
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001349
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001350 echo ""
1351
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001352 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001353 return 0
1354}
1355
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001356# 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 +02001357# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1358# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001359a1pms_api_delete_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001360 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001361
1362 if [ $# -ne 5 ]; then
1363 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1364 return 1
1365 fi
1366 resp_code=$1; shift;
1367 num_rics=$1; shift;
1368 start_id=$1; shift;
1369 count=$1; shift;
1370 pids=$1; shift;
1371
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001372 #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then
1373 if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then
1374 echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported"
1375 echo " Info - will execute over a1pms REST"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001376 fi
1377
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001378 if [ "$A1PMS_VERSION" == "V2" ]; then
1379 query="$A1PMS_API_PREFIX/v2/policies/"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001380 else
1381 query="/policy"
1382 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001383
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001384 urlbase=${A1PMS_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001385
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001386 httpproxy="NOPROXY"
BjornMagnussonXA663566c2021-11-08 10:25:07 +01001387 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1388 httpproxy=$KUBE_PROXY_PATH
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001389 fi
1390
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001391 for ((i=1; i<=$pids; i++))
1392 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001393 uuid=$UUID
1394 if [ -z "$uuid" ]; then
1395 uuid="NOUUID"
1396 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001397 echo "" > "./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001398 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001399 echo $i
1400 done | xargs -n 1 -I{} -P $pids bash -c '{
1401 arg=$(echo {})
1402 echo " Parallel process $arg started"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001403 tmp=$(< "./tmp/.pid${arg}.del.txt")
1404 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001405 }'
1406 msg=""
1407 for ((i=1; i<=$pids; i++))
1408 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001409 file="./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001410 tmp=$(< $file)
1411 if [ -z "$tmp" ]; then
1412 echo " Process $i : unknown result (result file empty"
1413 msg="failed"
1414 else
1415 res=${tmp:0:1}
1416 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001417 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001418 else
1419 echo " Process $i : failed - "${tmp:1}
1420 msg="failed"
1421 fi
1422 fi
1423 done
1424 if [ -z $msg ]; then
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001425 __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count*$num_rics))
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001426 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001427 return 0
1428 fi
1429
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001430 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001431 return 1
1432}
1433
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001434# API Test function: GET /policy_ids and V2 GET /v2/policies
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001435# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1436# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001437a1pms_api_get_policy_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001438 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001439
1440 if [ $# -lt 4 ]; then
1441 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1442 return 1
1443 fi
1444
1445 queryparams=""
1446
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001447 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001448 if [ $2 != "NORIC" ]; then
1449 queryparams="?ric_id="$2
1450 fi
1451
1452 if [ $3 != "NOSERVICE" ]; then
1453 if [ -z $queryparams ]; then
1454 queryparams="?service_id="$3
1455 else
1456 queryparams=$queryparams"&service_id="$3
1457 fi
1458 fi
1459 if [ $4 != "NOTYPE" ]; then
1460 if [ -z $queryparams ]; then
1461 queryparams="?policytype_id="$4
1462 else
1463 queryparams=$queryparams"&policytype_id="$4
1464 fi
1465 fi
1466
1467 query="/v2/policies"$queryparams
1468 else
1469 if [ $2 != "NORIC" ]; then
1470 queryparams="?ric="$2
1471 fi
1472
1473 if [ $3 != "NOSERVICE" ]; then
1474 if [ -z $queryparams ]; then
1475 queryparams="?service="$3
1476 else
1477 queryparams=$queryparams"&service="$3
1478 fi
1479 fi
1480 if [ $4 != "NOTYPE" ]; then
1481 if [ -z $queryparams ]; then
1482 queryparams="?type="$4
1483 else
1484 queryparams=$queryparams"&type="$4
1485 fi
1486 fi
1487
1488 query="/policy_ids"$queryparams
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001489 fi
1490
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001491 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001492 status=${res:${#res}-3}
1493
1494 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001495 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001496 return 1
1497 fi
1498
1499 if [ $# -gt 4 ]; then
1500 body=${res:0:${#res}-3}
1501 targetJson="["
1502
1503 for pid in ${@:5} ; do
1504 if [ "$targetJson" != "[" ]; then
1505 targetJson=$targetJson","
1506 fi
1507 if [ $pid != "NOID" ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +02001508 targetJson=$targetJson"\"$UUID$pid\""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001509 fi
1510 done
1511
1512 targetJson=$targetJson"]"
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001513 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001514 targetJson="{\"policy_ids\": $targetJson}"
1515 fi
1516 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1517 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1518
1519 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001520 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001521 return 1
1522 fi
1523 fi
1524
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001525 __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001526 __log_test_pass
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001527 return 0
1528}
1529
1530# API Test function: V2 GET /v2/policy-types/{policyTypeId}
1531# args(V2): <response-code> <policy-type-id> [<schema-file>]
1532# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001533a1pms_api_get_policy_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001534 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001535
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001536 if [ "$A1PMS_VERSION" != "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001537 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001538 return 1
1539 fi
1540
1541 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1542 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1543 return 1
1544 fi
1545 query="/v2/policy-types/$2"
1546
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001547 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001548 status=${res:${#res}-3}
1549
1550 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001551 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001552 return 1
1553 fi
1554
1555 if [ $# -eq 3 ]; then
1556
1557 body=${res:0:${#res}-3}
1558
1559 targetJson=$(< $3)
1560 targetJson="{\"policy_schema\":$targetJson}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001561 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001562 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001563
1564 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001565 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001566 return 1
1567 fi
1568 fi
1569
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001570 __collect_endpoint_stats "A1PMS" 05 "GET" $A1PMS_API_PREFIX"/v2/policy-types/{policyTypeId}" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001571 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001572 return 0
1573}
1574
1575# API Test function: GET /policy_schema
1576# args: <response-code> <policy-type-id> [<schema-file>]
1577# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001578a1pms_api_get_policy_schema() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001579 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001580
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001581 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001582 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001583 return 1
1584 fi
1585
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001586 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1587 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1588 return 1
1589 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001590 query="/policy_schema?id=$2"
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001591 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001592 status=${res:${#res}-3}
1593
1594 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001595 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001596 return 1
1597 fi
1598
1599 if [ $# -eq 3 ]; then
1600
1601 body=${res:0:${#res}-3}
1602
1603 targetJson=$(< $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001604
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001605 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001606 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001607
1608 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001609 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001610 return 1
1611 fi
1612 fi
1613
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001614 __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001615 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001616 return 0
1617}
1618
1619# API Test function: GET /policy_schemas
1620# args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001621# args(V2): <response-code>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001622# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001623a1pms_api_get_policy_schemas() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001624 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001625
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001626 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001627 if [ $# -ne 1 ]; then
1628 __print_err "<response-code>" $@
1629 return 1
1630 fi
1631 else
1632 if [ $# -lt 2 ]; then
1633 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1634 return 1
1635 fi
1636 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001637 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001638 query="/v2/policy-schemas"
1639 else
1640 query="/policy_schemas"
1641 if [ $2 != "NORIC" ]; then
1642 query=$query"?ric="$2
1643 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001644 fi
1645
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001646 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001647 status=${res:${#res}-3}
1648
1649 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001650 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001651 return 1
1652 fi
1653
1654 if [ $# -gt 2 ]; then
1655 body=${res:0:${#res}-3}
1656 targetJson="["
1657
1658 for file in ${@:3} ; do
1659 if [ "$targetJson" != "[" ]; then
1660 targetJson=$targetJson","
1661 fi
1662 if [ $file == "NOFILE" ]; then
1663 targetJson=$targetJson"{}"
1664 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001665 targetJson=$targetJson$(< $file)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001666 fi
1667 done
1668
1669 targetJson=$targetJson"]"
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001670 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001671 targetJson="{\"policy_schemas\": $targetJson }"
1672 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001673 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001674 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001675
1676 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001677 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001678 return 1
1679 fi
1680 fi
1681
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001682 __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001683 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001684 return 0
1685}
1686
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001687# API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001688# arg: <response-code> <policy-id> [ (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) ]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001689# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001690a1pms_api_get_policy_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001691 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001692
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001693 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
1694 __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001695 return 1
1696 fi
1697
1698 targetJson=""
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001699 if [ $# -eq 2 ]; then
1700 :
1701 elif [ "$3" == "STD" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001702 targetJson="{\"enforceStatus\":\"$4\""
1703 if [ $# -eq 5 ]; then
1704 targetJson=$targetJson",\"reason\":\"$5\""
1705 fi
1706 targetJson=$targetJson"}"
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001707 elif [ "$3" == "STD2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001708 if [ $4 == "EMPTY" ]; then
1709 targetJson="{\"enforceStatus\":\"\""
1710 else
1711 targetJson="{\"enforceStatus\":\"$4\""
1712 fi
1713 if [ $# -eq 5 ]; then
1714 if [ $5 == "EMPTY" ]; then
1715 targetJson=$targetJson",\"enforceReason\":\"\""
1716 else
1717 targetJson=$targetJson",\"enforceReason\":\"$5\""
1718 fi
1719 fi
1720 targetJson=$targetJson"}"
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001721 elif [ "$3" == "OSC" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001722 targetJson="{\"instance_status\":\"$4\""
1723 if [ $# -eq 5 ]; then
1724 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1725 fi
1726 targetJson=$targetJson",\"created_at\":\"????\"}"
1727 else
1728 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1729 return 1
1730 fi
1731
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001732 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001733 query="/v2/policies/$UUID$2/status"
1734 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1735 else
1736 query="/policy_status?id="$UUID$2
1737 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001738
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001739 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001740 status=${res:${#res}-3}
1741
1742 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001743 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001744 return 1
1745 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001746 if [ $# -gt 2 ]; then
1747 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1748 body=${res:0:${#res}-3}
1749 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001750
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001751 if [ $res -ne 0 ]; then
1752 __log_test_fail_body
1753 return 1
1754 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001755 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001756 __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001757 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001758 return 0
1759}
1760
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001761# API Test function: GET /policy_types and V2 GET /v2/policy-types
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001762# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1763# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001764a1pms_api_get_policy_types() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001765 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001766
1767 if [ $# -lt 1 ]; then
1768 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1769 return 1
1770 fi
1771
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001772 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001773 if [ $# -eq 1 ]; then
1774 query="/v2/policy-types"
1775 elif [ $2 == "NORIC" ]; then
1776 query="/v2/policy-types"
1777 else
1778 query="/v2/policy-types?ric_id=$2"
1779 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001780 else
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001781 if [ $# -eq 1 ]; then
1782 query="/policy_types"
1783 elif [ $2 == "NORIC" ]; then
1784 query="/policy_types"
1785 else
1786 query="/policy_types?ric=$2"
1787 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001788 fi
1789
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001790 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001791 status=${res:${#res}-3}
1792
1793 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001794 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001795 return 1
1796 fi
1797
1798 if [ $# -gt 2 ]; then
1799 body=${res:0:${#res}-3}
1800 targetJson="["
1801
1802 for pid in ${@:3} ; do
1803 if [ "$targetJson" != "[" ]; then
1804 targetJson=$targetJson","
1805 fi
1806 if [ $pid == "EMPTY" ]; then
1807 pid=""
1808 fi
1809 targetJson=$targetJson"\"$pid\""
1810 done
1811
1812 targetJson=$targetJson"]"
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001813 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001814 targetJson="{\"policytype_ids\": $targetJson }"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001815 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001816 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001817 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001818
1819 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001820 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001821 return 1
1822 fi
1823 fi
1824
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001825 __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001826 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001827 return 0
1828}
1829
1830#########################################################
1831#### Test case functions Health check
1832#########################################################
1833
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001834# API Test function: GET /status and V2 GET /status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001835# args: <response-code>
1836# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001837a1pms_api_get_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001838 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001839 if [ $# -ne 1 ]; then
1840 __print_err "<response-code>" $@
1841 return 1
1842 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001843 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001844 query="/v2/status"
1845 else
1846 query="/status"
1847 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001848 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001849 status=${res:${#res}-3}
1850
1851 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001852 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001853 return 1
1854 fi
1855
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001856 __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX"/v2/status" $status
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001857 __log_test_pass
1858 return 0
1859}
1860
1861# API Test function: GET /status (root) without api prefix
1862# args: <response-code>
1863# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001864a1pms_api_get_status_root() {
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001865 __log_test_start $@
1866 if [ $# -ne 1 ]; then
1867 __print_err "<response-code>" $@
1868 return 1
1869 fi
1870 query="/status"
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001871 TMP_PREFIX=$A1PMS_API_PREFIX
1872 A1PMS_API_PREFIX=""
1873 res="$(__do_curl_to_api A1PMS GET $query)"
1874 A1PMS_API_PREFIX=$TMP_PREFIX
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001875 status=${res:${#res}-3}
1876
1877 if [ $status -ne $1 ]; then
1878 __log_test_fail_status_code $1 $status
1879 return 1
1880 fi
1881
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001882 __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001883 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001884 return 0
1885}
1886
1887#########################################################
1888#### Test case functions RIC Repository
1889#########################################################
1890
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001891# API Test function: GET /ric and V2 GET /v2/rics/ric
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001892# args: <reponse-code> <management-element-id> [<ric-id>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001893# (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1894# (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1895# (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1896
1897
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001898# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001899a1pms_api_get_ric() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001900 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001901
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001902 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001903 if [ $# -lt 3 ]; then
1904 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1905 return 1
1906 fi
1907 search=""
1908 if [ $2 != "NOME" ]; then
1909 search="?managed_element_id="$2
1910 fi
1911 if [ $3 != "NORIC" ]; then
1912 if [ -z $search ]; then
1913 search="?ric_id="$3
1914 else
1915 search=$search"&ric_id="$3
1916 fi
1917 fi
1918 query="/v2/rics/ric"$search
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001919
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001920 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001921 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001922
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001923 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001924 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001925 return 1
1926 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001927
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001928 if [ $# -gt 3 ]; then
1929 body=${res:0:${#res}-3}
1930 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1931 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001932 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001933 return 1
1934 fi
1935
1936 targetJson=$(<./tmp/.tmp_rics.json)
1937 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1938 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1939 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1940 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001941 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001942 return 1
1943 fi
1944 fi
1945 else
1946 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1947 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1948 return 1
1949 fi
1950
1951 query="/ric?managedElementId="$2
1952
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001953 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001954 status=${res:${#res}-3}
1955
1956 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001957 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001958 return 1
1959 fi
1960
1961 if [ $# -eq 3 ]; then
1962 body=${res:0:${#res}-3}
1963 if [ "$body" != "$3" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001964 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001965 return 1
1966 fi
1967 fi
1968 fi
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001969
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001970 __collect_endpoint_stats "A1PMS" 11 "GET" $A1PMS_API_PREFIX"/v2/rics/ric" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001971 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001972 return 0
1973}
1974
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001975# API test function: GET /rics and V2 GET /v2/rics
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001976# args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1977# 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_........."
1978# format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1979# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001980a1pms_api_get_rics() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001981 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001982
1983 if [ $# -lt 2 ]; then
1984 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1985 return 1
1986 fi
1987
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01001988 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001989 query="/v2/rics"
1990 if [ $2 != "NOTYPE" ]; then
1991 query="/v2/rics?policytype_id="$2
1992 fi
1993 else
1994 query="/rics"
1995 if [ $2 != "NOTYPE" ]; then
1996 query="/rics?policyType="$2
1997 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001998 fi
1999
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002000 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002001 status=${res:${#res}-3}
2002
2003 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002004 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002005 return 1
2006 fi
2007
2008 if [ $# -gt 2 ]; then
2009 body=${res:0:${#res}-3}
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002010 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002011 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
2012 else
2013 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
2014 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002015 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002016 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002017 return 1
2018 fi
2019
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002020 targetJson=$(<./tmp/.tmp_rics.json)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002021 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002022 targetJson="{\"rics\": $targetJson }"
2023 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002024 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002025 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002026 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002027 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002028 return 1
2029 fi
2030 fi
2031
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002032 __collect_endpoint_stats "A1PMS" 12 "GET" $A1PMS_API_PREFIX"/v2/rics" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002033 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002034 return 0
2035}
2036
2037##################################################################
2038#### API Test case functions Service registry and supervision ####
2039##################################################################
2040
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002041# API test function: PUT /service and V2 PUT /service
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002042# args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
2043# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002044a1pms_api_put_service() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002045 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002046 if [ $# -ne 4 ]; then
2047 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
2048 return 1
2049 fi
2050
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002051 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002052 query="/v2/services"
2053 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
2054 else
2055 query="/service"
2056 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2057 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002058 file="./tmp/.tmp.json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002059 echo "$json" > $file
2060
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002061 res="$(__do_curl_to_api A1PMS PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002062 status=${res:${#res}-3}
2063
2064 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002065 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002066 return 1
2067 fi
2068
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002069 __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX"/v2/service" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002070 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002071 return 0
2072}
2073
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002074# API test function: GET /services and V2 GET /v2/services
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002075#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>]* )]
2076# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002077a1pms_api_get_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002078 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002079 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2080 paramError=1
2081 if [ $# -eq 1 ]; then
2082 paramError=0
2083 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2084 paramError=0
2085 elif [ $# -eq 5 ]; then
2086 paramError=0
2087 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2088 argLen=$(($#-2))
2089 if [ $(($argLen%3)) -eq 0 ]; then
2090 paramError=0
2091 fi
2092 fi
2093
2094 if [ $paramError -ne 0 ]; then
2095 __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>]* )]" $@
2096 return 1
2097 fi
2098
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002099 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002100 query="/v2/services"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002101
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002102 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2103 query="/v2/services?service_id="$2
2104 fi
2105 else
2106 query="/services"
2107
2108 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2109 query="/services?name="$2
2110 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002111 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002112 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002113 status=${res:${#res}-3}
2114
2115 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002116 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002117 return 1
2118 fi
2119
2120 if [ $# -gt 2 ]; then
2121 variableArgCount=$(($#-2))
2122 body=${res:0:${#res}-3}
2123 targetJson="["
2124 shift; shift;
2125 cntr=0
2126 while [ $cntr -lt $variableArgCount ]; do
2127 servicename=$1; shift;
2128 timeout=$1; shift;
2129 callback=$1; shift;
2130 if [ $cntr -gt 0 ]; then
2131 targetJson=$targetJson","
2132 fi
2133 # timeSinceLastActivitySeconds value cannot be checked since value varies
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002134 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002135 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2136 else
2137 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2138 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002139 let cntr=cntr+3
2140 done
2141 targetJson=$targetJson"]"
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002142 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002143 targetJson="{\"service_list\": $targetJson }"
2144 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002145 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002146 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002147 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002148 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002149 return 1
2150 fi
2151 fi
2152
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002153 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002154 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002155 return 0
2156}
2157
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002158# API test function: GET /services V2 GET /v2/services - (only checking service names)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002159# args: <response-code> [<service-name>]*"
2160# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002161a1pms_api_get_service_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002162 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002163
2164 if [ $# -lt 1 ]; then
2165 __print_err "<response-code> [<service-name>]*" $@
2166 return 1
2167 fi
2168
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002169 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002170 query="/v2/services"
2171 else
2172 query="/services"
2173 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002174 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002175 status=${res:${#res}-3}
2176
2177 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002178 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002179 return 1
2180 fi
2181
2182 body=${res:0:${#res}-3}
2183 targetJson="["
2184 for rapp in ${@:2} ; do
2185 if [ "$targetJson" != "[" ]; then
2186 targetJson=$targetJson","
2187 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002188 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002189 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2190 else
2191 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2192 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002193 done
2194
2195 targetJson=$targetJson"]"
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002196 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002197 targetJson="{\"service_list\": $targetJson }"
2198 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002199 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002200 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002201
2202 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002203 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002204 return 1
2205 fi
2206
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002207 __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX"/v2/services" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002208 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002209 return 0
2210}
2211
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002212# API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002213# args: <response-code> <service-name>
2214# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002215a1pms_api_delete_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002216 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002217
2218 if [ $# -ne 2 ]; then
2219 __print_err "<response-code> <service-name>" $@
2220 return 1
2221 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002222 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002223 query="/v2/services/"$2
2224 else
2225 query="/services?name="$2
2226 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002227 res="$(__do_curl_to_api A1PMS DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002228 status=${res:${#res}-3}
2229
2230 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002231 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002232 return 1
2233 fi
2234
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002235 __collect_endpoint_stats "A1PMS" 15 "DELETE" $A1PMS_API_PREFIX"/v2/services/{serviceId}" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002236 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002237 return 0
2238}
2239
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002240# API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002241# args: <response-code> <service-name>
2242# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002243a1pms_api_put_services_keepalive() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002244 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002245
2246 if [ $# -ne 2 ]; then
2247 __print_err "<response-code> <service-name>" $@
2248 return 1
2249 fi
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002250 if [ "$A1PMS_VERSION" == "V2" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002251 query="/v2/services/$2/keepalive"
2252 else
2253 query="/services/keepalive?name="$2
2254 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002255
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002256 res="$(__do_curl_to_api A1PMS PUT $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002257 status=${res:${#res}-3}
2258
2259 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002260 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002261 return 1
2262 fi
2263
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002264 __collect_endpoint_stats "A1PMS" 16 "PUT" $A1PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002265 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002266 return 0
2267}
2268
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002269##################################################################
2270#### API Test case functions Configuration ####
2271##################################################################
2272
2273# API Test function: PUT /v2/configuration
2274# args: <response-code> <config-file>
2275# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002276a1pms_api_put_configuration() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002277 __log_test_start $@
2278
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002279 if [ "$A1PMS_VERSION" != "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002280 __log_test_fail_not_supported
2281 return 1
2282 fi
2283
2284 if [ $# -ne 2 ]; then
2285 __print_err "<response-code> <config-file>" $@
2286 return 1
2287 fi
2288 if [ ! -f $2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002289 __log_test_fail_general "Config file "$2", does not exist"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002290 return 1
2291 fi
2292 inputJson=$(< $2)
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01002293 if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header
2294 inputJson="{\"config\":"$inputJson"}"
2295 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002296 file="./tmp/.config.json"
2297 echo $inputJson > $file
2298 query="/v2/configuration"
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002299 res="$(__do_curl_to_api A1PMS PUT $query $file)"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002300 status=${res:${#res}-3}
2301
2302 if [ $status -ne $1 ]; then
2303 __log_test_fail_status_code $1 $status
2304 return 1
2305 fi
2306
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002307 __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX"/v2/configuration" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002308 __log_test_pass
2309 return 0
2310}
2311
2312# API Test function: GET /v2/configuration
2313# args: <response-code> [<config-file>]
2314# (Function for test scripts)
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002315a1pms_api_get_configuration() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002316 __log_test_start $@
2317
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002318 if [ "$A1PMS_VERSION" != "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002319 __log_test_fail_not_supported
2320 return 1
2321 fi
2322
2323 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2324 __print_err "<response-code> [<config-file>]" $@
2325 return 1
2326 fi
2327 if [ ! -f $2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002328 __log_test_fail_general "Config file "$2" for comparison, does not exist"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002329 return 1
2330 fi
2331
2332 query="/v2/configuration"
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002333 res="$(__do_curl_to_api A1PMS GET $query)"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002334 status=${res:${#res}-3}
2335
2336 if [ $status -ne $1 ]; then
2337 __log_test_fail_status_code $1 $status
2338 return 1
2339 fi
2340
2341 if [ $# -eq 2 ]; then
2342
2343 body=${res:0:${#res}-3}
2344
2345 targetJson=$(< $2)
2346 targetJson="{\"config\":"$targetJson"}"
2347 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2348 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2349
2350 if [ $res -ne 0 ]; then
2351 __log_test_fail_body
2352 return 1
2353 fi
2354 fi
2355
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002356 __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002357 __log_test_pass
2358 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002359}
2360
2361##########################################
2362#### Reset types and instances ####
2363##########################################
2364
2365# Admin reset to remove all policies and services
2366# All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2367# NOTE - only works in kubernetes and the pod should not be running
2368# args: -
2369# (Function for test scripts)
2370
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002371a1pms_kube_pvc_reset() {
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002372 __log_test_start $@
2373
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +01002374 pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002375 if [ -z "$pvc_name" ]; then
2376 pvc_name=policymanagementservice-vardata-pvc
2377 fi
2378 echo " Trying to reset pvc: "$pvc_name
BjornMagnussonXAd2aeca82022-03-07 11:04:55 +01002379 __kube_clean_pvc $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $A1PMS_CONTAINER_MNT_DIR
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002380
2381 __log_test_pass
2382 return 0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002383}