blob: 5367060593939b8284dfeeec64f4c54468318662 [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/bin/bash
2
3# ============LICENSE_START===============================================
4# Copyright (C) 2020 Nordix Foundation. All rights reserved.
5# ========================================================================
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
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010020# This is a script that contains management and test functions for Policy Agent
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
27__PA_imagesetup() {
28 __check_and_create_image_var PA "POLICY_AGENT_IMAGE" "POLICY_AGENT_IMAGE_BASE" "POLICY_AGENT_IMAGE_TAG" $1 "$POLICY_AGENT_DISPLAY_NAME"
29}
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'
36__PA_imagepull() {
BjornMagnussonXA483ee332021-04-08 01:35:24 +020037 __check_and_pull_image $1 "$POLICY_AGENT_DISPLAY_NAME" $POLICY_AGENT_APP_NAME POLICY_AGENT_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
43__PA_imagebuild() {
44 echo -e $RED" Image for app PA shall never be built"$ERED
45}
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>
50__PA_image_data() {
51 echo -e "$POLICY_AGENT_DISPLAY_NAME\t$(docker images --format $1 $POLICY_AGENT_IMAGE)" >> $2
BjornMagnussonXA483ee332021-04-08 01:35:24 +020052 if [ ! -z "$POLICY_AGENT_IMAGE_SOURCE" ]; then
53 echo -e "-- source image --\t$(docker images --format $1 $POLICY_AGENT_IMAGE_SOURCE)" >> $2
54 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
60__PA_kube_scale_zero() {
61 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
62}
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.
66__PA_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.
72__PA_kube_delete_all() {
73 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
74}
75
76# Store docker logs
77# This function is called for apps managed by the test script.
78# args: <log-dir> <file-prexix>
79__PA_store_docker_logs() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +010080 if [ $RUNMODE == "KUBE" ]; then
81 kubectl logs -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_policy-agent.log 2>&1
82 else
83 docker logs $POLICY_AGENT_APP_NAME > $1$2_policy-agent.log 2>&1
84 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: -
90__PA_initial_setup() {
91 use_agent_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: -
98__PA_statisics_setup() {
99 if [ $RUNMODE == "KUBE" ]; then
100 echo "PA $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE"
101 else
102 echo "PA $POLICY_AGENT_APP_NAME"
103 fi
104}
105
106
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100107#######################################################
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100108
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100109###########################
110### Policy Agents functions
111###########################
112
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100113# Set http as the protocol to use for all communication to the Policy Agent
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100114# args: -
115# (Function for test scripts)
116use_agent_rest_http() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100117 __agent_set_protocoll "http" $POLICY_AGENT_INTERNAL_PORT $POLICY_AGENT_EXTERNAL_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100118}
119
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100120# Set https as the protocol to use for all communication to the Policy Agent
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100121# args: -
122# (Function for test scripts)
123use_agent_rest_https() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100124 __agent_set_protocoll "https" $POLICY_AGENT_INTERNAL_SECURE_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100125}
126
127# All calls to the agent will be directed to the agent dmaap interface over http from now on
128# args: -
129# (Function for test scripts)
130use_agent_dmaap_http() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100131 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100132 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
133 PA_ADAPTER_TYPE="MR-HTTP"
134 echo ""
135}
136
137# All calls to the agent will be directed to the agent dmaap interface over https from now on
138# args: -
139# (Function for test scripts)
140use_agent_dmaap_https() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100141 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100142 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
143 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
144 PA_ADAPTER_TYPE="MR-HTTPS"
145 echo ""
146}
147
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100148# Setup paths to svc/container for internal and external access
149# args: <protocol> <internal-port> <external-port>
150__agent_set_protocoll() {
151 echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME protocol setting"$EBOLD
152 echo -e " Using $BOLD http $EBOLD towards $POLICY_AGENT_DISPLAY_NAME"
153
154 ## Access to Dmaap adapter
155
156 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME":"$2 # docker access, container->container and script->container via proxy
157 if [ $RUNMODE == "KUBE" ]; then
158 PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
159 fi
160
161 # PA_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
162 PA_ADAPTER_TYPE="REST"
163 PA_ADAPTER=$PA_SERVICE_PATH
164
165 echo ""
166}
167
168# Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
169AGENT_RETRY_CODES=""
170
171#Save first worker node the pod is started on
172__PA_WORKER_NODE=""
173
174# Export env vars for config files, docker compose and kube resources
175# args: PROXY|NOPROXY
176__export_agent_vars() {
177
178 export POLICY_AGENT_APP_NAME
179 export POLICY_AGENT_APP_NAME_ALIAS
180 export POLICY_AGENT_DISPLAY_NAME
181
182 export KUBE_NONRTRIC_NAMESPACE
183 export POLICY_AGENT_IMAGE
184 export POLICY_AGENT_INTERNAL_PORT
185 export POLICY_AGENT_INTERNAL_SECURE_PORT
186 export POLICY_AGENT_EXTERNAL_PORT
187 export POLICY_AGENT_EXTERNAL_SECURE_PORT
188 export POLICY_AGENT_CONFIG_MOUNT_PATH
189 export POLICY_AGENT_DATA_MOUNT_PATH
190 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
191 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
192 export POLICY_AGENT_PKG_NAME
193 export CONSUL_HOST
194 export CONSUL_INTERNAL_PORT
195 export CONFIG_BINDING_SERVICE
196 export POLICY_AGENT_CONFIG_KEY
197 export DOCKER_SIM_NWNAME
198 export POLICY_AGENT_HOST_MNT_DIR
199 export POLICY_AGENT_CONFIG_FILE
200
201 export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
202 export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
203 ##Create a unique path for the pv each time to prevent a previous volume to be reused
204 export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
205 export POLICY_AGENT_CONTAINER_MNT_DIR
206
207 if [ $1 == "PROXY" ]; then
208 export AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
209 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
210 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
211 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
212 else
213 echo " Configured with http proxy"
214 fi
215 else
216 export AGENT_HTTP_PROXY_CONFIG_PORT=0
217 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
218 echo " Configured without http proxy"
219 fi
220}
221
222
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100223# Start the policy agent
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100224# args: (docker) PROXY|NOPROXY <config-file>
225# args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100226# (Function for test scripts)
227start_policy_agent() {
228 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
229
230 if [ $RUNMODE == "KUBE" ]; then
231
232 # Check if app shall be fully managed by the test script
233 __check_included_image "PA"
234 retcode_i=$?
235
236 # Check if app shall only be used by the testscipt
237 __check_prestarted_image "PA"
238 retcode_p=$?
239
240 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
241 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
242 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
243 exit
244 fi
245 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
246 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
247 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
248 exit
249 fi
250
251 if [ $retcode_p -eq 0 ]; then
252 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
253 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200254 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
255 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100256 fi
257
258 if [ $retcode_i -eq 0 ]; then
259
260 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
261
262 #Check if nonrtric namespace exists, if not create it
263 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
264
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100265 __export_agent_vars $1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100266
267 # Create config map for config
268 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
269 cp $2 $configfile
270 output_yaml=$PWD/tmp/pa_cfc.yaml
271 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
272
273 # Create config map for data
274 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
275 if [ $# -lt 3 ]; then
276 #create empty dummy file
277 echo "{}" > $data_json
278 else
279 cp $3 $data_json
280 fi
281 output_yaml=$PWD/tmp/pa_cfd.yaml
282 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
283
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200284 ## Create pv
285 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pv.yaml
286 output_yaml=$PWD/tmp/pa_pv.yaml
287 __kube_create_instance pv $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
288
289 ## Create pvc
290 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"pvc.yaml
291 output_yaml=$PWD/tmp/pa_pvc.yaml
292 __kube_create_instance pvc $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
293
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100294 # Create service
295 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
296 output_yaml=$PWD/tmp/pa_svc.yaml
297 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
298
299 # Create app
300 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
301 output_yaml=$PWD/tmp/pa_app.yaml
302 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
303
304 fi
305
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200306 # 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 +0200307 if [ $retcode_i -eq 0 ]; then
308 __PA_WORKER_NODE=$(kubectl get pod -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
309 if [ -z "$__PA_WORKER_NODE" ]; then
310 echo -e $YELLOW" Cannot find worker node for pod for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
311 fi
312 else
313 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200314 fi
315
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100316 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100317
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100318 else
319 __check_included_image 'PA'
320 if [ $? -eq 1 ]; then
321 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
322 echo -e $RED"The Policy Agent will not be started"$ERED
323 exit
324 fi
325
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200326 curdir=$PWD
327 cd $SIM_GROUP
328 cd policy_agent
329 cd $POLICY_AGENT_HOST_MNT_DIR
330 #cd ..
331 if [ -d db ]; then
332 if [ "$(ls -A $DIR)" ]; then
333 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
334 rm -rf db/* &> /dev/null
335 if [ $? -ne 0 ]; then
336 echo -e $RED" Cannot remove database files in: $PWD"$ERED
337 exit 1
338 fi
339 fi
340 else
341 echo " No files in mounted dir or dir does not exists"
342 fi
343 cd $curdir
344
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100345 __export_agent_vars $1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100346
347 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
348
349 envsubst < $2 > $dest_file
350
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100351 __start_container $POLICY_AGENT_COMPOSE_DIR "" NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100352
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100353 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100354 fi
355 echo ""
356 return 0
357}
358
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200359# Stop the policy agent
360# args: -
361# args: -
362# (Function for test scripts)
363stop_policy_agent() {
364 echo -e $BOLD"Stopping $POLICY_AGENT_DISPLAY_NAME"$EBOLD
365
366 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200367
368 __check_prestarted_image "PA"
369 if [ $? -eq 0 ]; then
370 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200371 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
372 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200373 return 0
374 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200375 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
376 echo " Deleting the replica set - a new will be started when the app is started"
377 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA")
378 if [ $? -ne 0 ]; then
379 echo -e $RED" Could not delete replica set "$RED
380 ((RES_CONF_FAIL++))
381 return 1
382 fi
383 else
384 docker stop $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
385 if [ $? -ne 0 ]; then
386 __print_err "Could not stop $POLICY_AGENT_APP_NAME" $@
387 cat ./tmp/.dockererr
388 ((RES_CONF_FAIL++))
389 return 1
390 fi
391 fi
392 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
393 echo ""
394 return 0
395}
396
397# Start a previously stopped policy agent
398# args: -
399# (Function for test scripts)
400start_stopped_policy_agent() {
401 echo -e $BOLD"Starting (the previously stopped) $POLICY_AGENT_DISPLAY_NAME"$EBOLD
402
403 if [ $RUNMODE == "KUBE" ]; then
404
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200405 __check_prestarted_image "PA"
406 if [ $? -eq 0 ]; then
407 echo -e $YELLOW" Persistency may not work for app $POLICY_AGENT_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200408 res_type=$(__kube_get_resource_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
409 __kube_scale $res_type $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100410 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200411 return 0
412 fi
413
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200414 # Tie the PMS to the same worker node it was initially started on
415 # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume
416 if [ -z "$__PA_WORKER_NODE" ]; then
417 echo -e $RED" No initial worker node found for pod "$RED
418 ((RES_CONF_FAIL++))
419 return 1
420 else
421 echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__PA_WORKER_NODE to deployment for $POLICY_AGENT_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD
422 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
423 tmp=$(kubectl patch deployment $POLICY_AGENT_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__PA_WORKER_NODE'"}}}}}')
424 if [ $? -ne 0 ]; then
425 echo -e $YELLOW" Cannot set nodeSelector to deployment for $POLICY_AGENT_APP_NAME, persistency may not work"$EYELLOW
426 fi
427 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
428 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200429 else
430 docker start $POLICY_AGENT_APP_NAME &> ./tmp/.dockererr
431 if [ $? -ne 0 ]; then
432 __print_err "Could not start (the stopped) $POLICY_AGENT_APP_NAME" $@
433 cat ./tmp/.dockererr
434 ((RES_CONF_FAIL++))
435 return 1
436 fi
437 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100438 __check_service_start $POLICY_AGENT_APP_NAME $PA_SERVICE_PATH$POLICY_AGENT_ALIVE_URL
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200439 if [ $? -ne 0 ]; then
440 return 1
441 fi
442 echo ""
443 return 0
444}
445
446
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100447# Function to perpare the consul configuration according to the current simulator configuration
448# args: SDNC|NOSDNC <output-file>
449# (Function for test scripts)
450prepare_consul_config() {
451 echo -e $BOLD"Prepare Consul config"$EBOLD
452
453 echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
454
455 if [ $# != 2 ]; then
456 ((RES_CONF_FAIL++))
457 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
458 exit 1
459 fi
460
461 if [ $1 == "SDNC" ]; then
462 echo -e " Config$BOLD including SDNC$EBOLD configuration"
463 elif [ $1 == "NOSDNC" ]; then
464 echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
465 else
466 ((RES_CONF_FAIL++))
467 __print_err "need two args, SDNC|NOSDNC <output-file>" $@
468 exit 1
469 fi
470
471 config_json="\n {"
472 if [ $1 == "SDNC" ]; then
473 config_json=$config_json"\n \"controller\": ["
474 config_json=$config_json"\n {"
475 config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
476 config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\","
477 config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
478 config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
479 config_json=$config_json"\n }"
480 config_json=$config_json"\n ],"
481 fi
482
483 config_json=$config_json"\n \"streams_publishes\": {"
484 config_json=$config_json"\n \"dmaap_publisher\": {"
485 config_json=$config_json"\n \"type\": \"message-router\","
486 config_json=$config_json"\n \"dmaap_info\": {"
487 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\""
488 config_json=$config_json"\n }"
489 config_json=$config_json"\n }"
490 config_json=$config_json"\n },"
491 config_json=$config_json"\n \"streams_subscribes\": {"
492 config_json=$config_json"\n \"dmaap_subscriber\": {"
493 config_json=$config_json"\n \"type\": \"message-router\","
494 config_json=$config_json"\n \"dmaap_info\": {"
495 config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\""
496 config_json=$config_json"\n }"
497 config_json=$config_json"\n }"
498 config_json=$config_json"\n },"
499
500 config_json=$config_json"\n \"ric\": ["
501
502 if [ $RUNMODE == "KUBE" ]; then
503 result=$(kubectl get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}')
504 rics=""
505 ric_cntr=0
506 if [ $? -eq 0 ] && [ ! -z "$result" ]; then
507 for im in $result; do
508 if [[ $im != *"-0" ]]; then
509 ric_subdomain=$(kubectl get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}')
510 rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE
511 let ric_cntr=ric_cntr+1
512 fi
513 done
514 fi
515 if [ $ric_cntr -eq 0 ]; then
516 echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW
517 fi
518 else
519 rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
520 if [ $? -ne 0 ] || [ -z "$rics" ]; then
521 echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
522 ((RES_CONF_FAIL++))
523 return 1
524 fi
525 fi
526 cntr=0
527 for ric in $rics; do
528 if [ $cntr -gt 0 ]; then
529 config_json=$config_json"\n ,"
530 fi
531 config_json=$config_json"\n {"
532 if [ $RUNMODE == "KUBE" ]; then
533 ric_id=${ric%.*.*} #extract pod id from full hosthame
534 ric_id=$(echo "$ric_id" | tr '-' '_')
535 else
536 ric_id=$ric
537 fi
538 echo " Found a1 sim: "$ric_id
539 config_json=$config_json"\n \"name\": \"$ric_id\","
540 config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\","
541 if [ $1 == "SDNC" ]; then
542 config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
543 fi
544 config_json=$config_json"\n \"managedElementIds\": ["
545 config_json=$config_json"\n \"me1_$ric_id\","
546 config_json=$config_json"\n \"me2_$ric_id\""
547 config_json=$config_json"\n ]"
548 config_json=$config_json"\n }"
549 let cntr=cntr+1
550 done
551
552 config_json=$config_json"\n ]"
553 config_json=$config_json"\n}"
554
555 if [ $RUNMODE == "KUBE" ]; then
556 config_json="{\"config\":"$config_json"}"
557 fi
558
559 printf "$config_json">$2
560
561 echo ""
562}
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200563
BjornMagnussonXA366e36a2021-01-27 11:48:56 +0100564# Load the the appl config for the agent into a config map
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100565agent_load_config() {
566 echo -e $BOLD"Agent - load config from "$EBOLD$1
567 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
568 cp $1 $data_json
569 output_yaml=$PWD/tmp/pa_cfd.yaml
570 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100571 echo ""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100572}
573
574
575# Turn on debug level tracing in the agent
576# args: -
577# (Function for test scripts)
578set_agent_debug() {
579 echo -e $BOLD"Setting agent debug logging"$EBOLD
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100580 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100581 result=$(__do_curl "$curlString")
582 if [ $? -ne 0 ]; then
583 __print_err "could not set debug mode" $@
584 ((RES_CONF_FAIL++))
585 return 1
586 fi
587 echo ""
588 return 0
589}
590
591# Turn on trace level tracing in the agent
592# args: -
593# (Function for test scripts)
594set_agent_trace() {
595 echo -e $BOLD"Setting agent trace logging"$EBOLD
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100596 curlString="$PA_SERVICE_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100597 result=$(__do_curl "$curlString")
598 if [ $? -ne 0 ]; then
599 __print_err "could not set trace mode" $@
600 ((RES_CONF_FAIL++))
601 return 1
602 fi
603 echo ""
604 return 0
605}
606
607# Perform curl retries when making direct call to the agent for the specified http response codes
608# Speace separated list of http response codes
609# args: [<response-code>]*
610use_agent_retries() {
611 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
612 AGENT_RETRY_CODES=$@
613 echo ""
614 return
615}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100616
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100617# Check the agent logs for WARNINGs and ERRORs
618# args: -
619# (Function for test scripts)
620check_policy_agent_logs() {
621 __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH WARN ERR
622}
623
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100624#########################################################
625#### Test case functions A1 Policy management service
626#########################################################
627
628# This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
629# This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
630# args: json:<url> <target-value> [<timeout-in-seconds]
631# (Function for test scripts)
632api_equal() {
633 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
634 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
635 if [[ $1 == "json:"* ]]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100636 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100637 __var_test "Policy Agent" $PA_SERVICE_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100638 else
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100639 __var_test "Policy Agent" $PA_SERVICE_PATH"/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100640 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100641 return 0
642 fi
643 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100644 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
645 return 1
646}
647
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100648# API Test function: GET /policies and V2 GET /v2/policy-instances
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100649# 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>]*]
650# 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 +0100651# (Function for test scripts)
652api_get_policies() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100653 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100654
655 if [ "$PMS_VERSION" == "V2" ]; then
656 paramError=0
657 variableParams=$(($#-4))
658 if [ $# -lt 4 ]; then
659 paramError=1
660 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
661 paramError=1
662 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
663 paramError=1
664 fi
665
666 if [ $paramError -ne 0 ]; then
667 __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>]*]" $@
668 return 1
669 fi
670 else
671 paramError=0
672 variableParams=$(($#-4))
673 if [ $# -lt 4 ]; then
674 paramError=1
675 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
676 paramError=1
677 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
678 paramError=1
679 fi
680
681 if [ $paramError -ne 0 ]; then
682 __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>]*]" $@
683 return 1
684 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100685 fi
686
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100687 queryparams=""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100688 if [ "$PMS_VERSION" == "V2" ]; then
689 if [ $2 != "NORIC" ]; then
690 queryparams="?ric_id="$2
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100691 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100692 if [ $3 != "NOSERVICE" ]; then
693 if [ -z $queryparams ]; then
694 queryparams="?service_id="$3
695 else
696 queryparams=$queryparams"&service_id="$3
697 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100698 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100699 if [ $4 != "NOTYPE" ]; then
700 if [ -z $queryparams ]; then
701 queryparams="?policytype_id="$4
702 else
703 queryparams=$queryparams"&policytype_id="$4
704 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100705 fi
706
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100707 query="/v2/policy-instances"$queryparams
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100708 res="$(__do_curl_to_api PA GET $query)"
709 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100710
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100711 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100712 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100713 return 1
714 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100715
716 if [ $# -gt 4 ]; then
717 body=${res:0:${#res}-3}
718 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
719 targetJson="["
720 else
721 targetJson="["
722 arr=(${@:5})
723
724 for ((i=0; i<$(($#-4)); i=i+7)); do
725
726 if [ "$targetJson" != "[" ]; then
727 targetJson=$targetJson","
728 fi
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100729 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 +0100730 if [ "${arr[$i+3]}" == "EMPTY" ]; then
731 targetJson=$targetJson"\"\","
732 else
733 targetJson=$targetJson"\"${arr[$i+3]}\","
734 fi
735 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
736 file="./tmp/.p.json"
737 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
738 json=$(cat $file)
739 targetJson=$targetJson"\"policy_data\":"$json"}"
740 done
741 fi
742
743 targetJson=$targetJson"]"
744 targetJson="{\"policies\": $targetJson}"
745 echo "TARGET JSON: $targetJson" >> $HTTPLOG
746 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
747
748 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100749 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100750 return 1
751 fi
752 fi
753 else
754 if [ $2 != "NORIC" ]; then
755 queryparams="?ric="$2
756 fi
757 if [ $3 != "NOSERVICE" ]; then
758 if [ -z $queryparams ]; then
759 queryparams="?service="$3
760 else
761 queryparams=$queryparams"&service="$3
762 fi
763 fi
764 if [ $4 != "NOTYPE" ]; then
765 if [ -z $queryparams ]; then
766 queryparams="?type="$4
767 else
768 queryparams=$queryparams"&type="$4
769 fi
770 fi
771
772 query="/policies"$queryparams
773 res="$(__do_curl_to_api PA GET $query)"
774 status=${res:${#res}-3}
775
776 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100777 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100778 return 1
779 fi
780
781 if [ $# -gt 4 ]; then
782 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
783 targetJson="["
784 else
785 body=${res:0:${#res}-3}
786 targetJson="["
787 arr=(${@:5})
788
789 for ((i=0; i<$(($#-4)); i=i+5)); do
790
791 if [ "$targetJson" != "[" ]; then
792 targetJson=$targetJson","
793 fi
794 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
795 if [ "${arr[$i+3]}" == "EMPTY" ]; then
796 targetJson=$targetJson"\"\","
797 else
798 targetJson=$targetJson"\"${arr[$i+3]}\","
799 fi
800 file="./tmp/.p.json"
801 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
802 json=$(cat $file)
803 targetJson=$targetJson"\"json\":"$json"}"
804 done
805 fi
806
807 targetJson=$targetJson"]"
808 echo "TARGET JSON: $targetJson" >> $HTTPLOG
809 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
810
811 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100812 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100813 return 1
814 fi
815 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100816 fi
817
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100818 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100819 return 0
820
821}
822
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100823
824# API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
825# args: <response-code> <policy-id> [<template-file>]
826# args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
827
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100828# (Function for test scripts)
829api_get_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100830 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100831
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100832
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100833 if [ "$PMS_VERSION" == "V2" ]; then
834 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
835 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
836 return 1
837 fi
838 query="/v2/policies/$UUID$2"
839 else
840 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
841 __print_err "<response-code> <policy-id> [<template-file>] " $@
842 return 1
843 fi
844 query="/policy?id=$UUID$2"
845 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200846 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100847 status=${res:${#res}-3}
848
849 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100850 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100851 return 1
852 fi
853
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100854 if [ "$PMS_VERSION" == "V2" ]; then
855 if [ $# -eq 8 ]; then
856
857 #Create a policy json to compare with
858 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100859
860 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
861 if [ $7 != "NOTRANSIENT" ]; then
862 targetJson=$targetJson", \"transient\":$7"
863 fi
864 if [ $6 != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100865 targetJson=$targetJson", \"policytype_id\":\"$6\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100866 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100867 targetJson=$targetJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100868 fi
869 if [ $8 != "NOURL" ]; then
870 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
871 fi
872
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100873 data=$(sed 's/XXX/'${2}'/g' $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100874 targetJson=$targetJson", \"policy_data\":$data"
875 targetJson="{$targetJson}"
876
877 echo "TARGET JSON: $targetJson" >> $HTTPLOG
878 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
879 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100880 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100881 return 1
882 fi
883 fi
884 else
885 if [ $# -eq 3 ]; then
886 #Create a policy json to compare with
887 body=${res:0:${#res}-3}
888 file="./tmp/.p.json"
889 sed 's/XXX/'${2}'/g' $3 > $file
890 targetJson=$(< $file)
891 echo "TARGET JSON: $targetJson" >> $HTTPLOG
892 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
893 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100894 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100895 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100896 fi
897 fi
898
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100899 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100900 return 0
901}
902
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100903# API Test function: PUT /policy and V2 PUT /policies
904# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
905# 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 +0100906# (Function for test scripts)
907api_put_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100908 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100909
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100910 if [ "$PMS_VERSION" == "V2" ]; then
911 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
912 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
913 return 1
914 fi
915 else
916 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
917 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
918 return 1
919 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100920 fi
921
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100922 count=0
923 max=1
924 serv=$2
925 ric=$3
926 pt=$4
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100927 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100928 trans=$6
929
930 if [ "$PMS_VERSION" == "V2" ]; then
931 noti=$7
932 temp=$8
933 if [ $# -eq 9 ]; then
934 max=$9
935 fi
936 else
937 temp=$7
938 if [ $# -eq 8 ]; then
939 max=$8
940 fi
941 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100942
943 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100944 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100945
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100946 query="/v2/policies"
947
948 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
949 if [ $trans != "NOTRANSIENT" ]; then
950 inputJson=$inputJson", \"transient\":$trans"
951 fi
952 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100953 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100954 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100955 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100956 fi
957 if [ $noti != "NOURL" ]; then
958 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
959 fi
960 file="./tmp/.p.json"
961 data=$(sed 's/XXX/'${pid}'/g' $temp)
962 inputJson=$inputJson", \"policy_data\":$data"
963 inputJson="{$inputJson}"
964 echo $inputJson > $file
965 else
966 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
967
968 if [ $pt != "NOTYPE" ]; then
969 query=$query"&type=$pt"
970 fi
971
972 if [ $trans != NOTRANSIENT ]; then
973 query=$query"&transient=$trans"
974 fi
975
976 file="./tmp/.p.json"
977 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200978 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200979 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100980 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200981 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100982 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200983 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100984 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100985 return 1
986 fi
987
988 let pid=$pid+1
989 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200990 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100991 done
992 echo ""
993
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100994 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100995 return 0
996}
997
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100998# API Test function: PUT /policy and V2 PUT /policies, to run in batch
999# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
1000# 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 +02001001# (Function for test scripts)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001002
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001003api_put_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001004 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001005
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001006 if [ "$PMS_VERSION" == "V2" ]; then
1007 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
1008 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
1009 return 1
1010 fi
1011 else
1012 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1013 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
1014 return 1
1015 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001016 fi
1017
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001018 count=0
1019 max=1
1020 serv=$2
1021 ric=$3
1022 pt=$4
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001023 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001024 trans=$6
1025 if [ "$PMS_VERSION" == "V2" ]; then
1026 noti=$7
1027 temp=$8
1028 if [ $# -eq 9 ]; then
1029 max=$9
1030 fi
1031 else
1032 temp=$7
1033 if [ $# -eq 8 ]; then
1034 max=$8
1035 fi
1036 fi
1037
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001038 ARR=""
1039 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001040 if [ "$PMS_VERSION" == "V2" ]; then
1041 query="/v2/policies"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001042
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001043 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
1044 if [ $trans != "NOTRANSIENT" ]; then
1045 inputJson=$inputJson", \"transient\":$trans"
1046 fi
1047 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001048 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001049 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001050 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001051 fi
1052 if [ $noti != "NOURL" ]; then
1053 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
1054 fi
1055 file="./tmp/.p.json"
1056 data=$(sed 's/XXX/'${pid}'/g' $temp)
1057 inputJson=$inputJson", \"policy_data\":$data"
1058 inputJson="{$inputJson}"
1059 echo $inputJson > $file
1060 else
1061 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
1062
1063 if [ $pt != "NOTYPE" ]; then
1064 query=$query"&type=$pt"
1065 fi
1066
1067 if [ $trans != NOTRANSIENT ]; then
1068 query=$query"&transient=$trans"
1069 fi
1070 file="./tmp/.p.json"
1071 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001072 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001073 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001074 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001075 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001076
1077 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001078 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001079 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001080 return 1
1081 fi
1082 cid=${res:0:${#res}-3}
1083 ARR=$ARR" "$cid
1084 let pid=$pid+1
1085 let count=$count+1
1086 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1087 done
1088
1089 echo ""
1090 count=0
1091 for cid in $ARR; do
1092
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001093 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001094 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001095 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001096
1097 if [ $status -ne $1 ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001098 echo " Accepted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001099 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001100 return 1
1101 fi
1102
1103 let count=$count+1
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001104 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001105 done
1106
1107 echo ""
1108
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001109 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001110 return 0
1111}
1112
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001113# 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 +02001114# 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 +01001115# 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 +02001116# (Function for test scripts)
1117api_put_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001118 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001119
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001120 if [ "$PMS_VERSION" == "V2" ]; then
1121 if [ $# -ne 11 ]; then
1122 __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>" $@
1123 return 1
1124 fi
1125 else
1126 if [ $# -ne 10 ]; then
1127 __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>" $@
1128 return 1
1129 fi
1130 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001131 resp_code=$1; shift;
1132 serv=$1; shift
1133 ric_base=$1; shift;
1134 num_rics=$1; shift;
1135 type=$1; shift;
1136 start_id=$1; shift;
1137 transient=$1; shift;
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001138 if [ "$PMS_VERSION" == "V2" ]; then
1139 noti=$1; shift;
1140 else
1141 noti=""
1142 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001143 template=$1; shift;
1144 count=$1; shift;
1145 pids=$1; shift;
1146
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001147 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001148 if [ $PA_ADAPTER_TYPE != "REST" ]; then
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001149 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1150 echo " Info - will execute over agent REST"
1151 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001152 if [ "$PMS_VERSION" == "V2" ]; then
1153 if [ $serv == "NOSERVICE" ]; then
1154 serv=""
1155 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001156 query="$PMS_API_PREFIX/v2/policies"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001157 else
1158 if [ $serv == "NOSERVICE" ]; then
1159 serv=""
1160 fi
1161 query="/policy?service=$serv"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001162
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001163 if [ $type != "NOTYPE" ]; then
1164 query=$query"&type=$type"
1165 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001166
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001167 if [ $transient != NOTRANSIENT ]; then
1168 query=$query"&transient=$transient"
1169 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001170 fi
1171
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001172 urlbase=${PA_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001173
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001174 httpproxy="NOPROXY"
BjornMagnussonXA663566c2021-11-08 10:25:07 +01001175 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1176 httpproxy=$KUBE_PROXY_PATH
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001177 fi
1178
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001179 for ((i=1; i<=$pids; i++))
1180 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001181 uuid=$UUID
1182 if [ -z "$uuid" ]; then
1183 uuid="NOUUID"
1184 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001185 echo "" > "./tmp/.pid${i}.res.txt"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001186 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001187 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 +01001188 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001189 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 +01001190 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001191 echo $i
1192 done | xargs -n 1 -I{} -P $pids bash -c '{
1193 arg=$(echo {})
1194 echo " Parallel process $arg started"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001195 tmp=$(< "./tmp/.pid${arg}.txt")
1196 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001197 }'
1198 msg=""
1199 for ((i=1; i<=$pids; i++))
1200 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001201 file="./tmp/.pid${i}.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001202 tmp=$(< $file)
1203 if [ -z "$tmp" ]; then
1204 echo " Process $i : unknown result (result file empty"
1205 msg="failed"
1206 else
1207 res=${tmp:0:1}
1208 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001209 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001210 else
1211 echo " Process $i : failed - "${tmp:1}
1212 msg="failed"
1213 fi
1214 fi
1215 done
1216 if [ -z $msg ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001217 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001218 return 0
1219 fi
1220
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001221 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001222 return 1
1223}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001224
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001225# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001226# args: <response-code> <policy-id> [count]
1227# (Function for test scripts)
1228api_delete_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001229 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001230
1231 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1232 __print_err "<response-code> <policy-id> [count]" $@
1233 return 1
1234 fi
1235
1236 count=0
1237 max=1
1238
1239 if [ $# -eq 3 ]; then
1240 max=$3
1241 fi
1242
1243 pid=$2
1244
1245 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001246 if [ "$PMS_VERSION" == "V2" ]; then
1247 query="/v2/policies/"$UUID$pid
1248 else
1249 query="/policy?id="$UUID$pid
1250 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001251 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001252 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001253 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001254
1255 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001256 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001257 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001258 return 1
1259 fi
1260 let pid=$pid+1
1261 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001262 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001263 done
1264 echo ""
1265
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001266 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001267 return 0
1268}
1269
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001270# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001271# args: <response-code> <policy-id> [count]
1272# (Function for test scripts)
1273api_delete_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001274 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001275
1276 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1277 __print_err "<response-code> <policy-id> [count]" $@
1278 return 1
1279 fi
1280
1281 count=0
1282 max=1
1283
1284 if [ $# -eq 3 ]; then
1285 max=$3
1286 fi
1287
1288 pid=$2
1289 ARR=""
1290 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001291 if [ "$PMS_VERSION" == "V2" ]; then
1292 query="/v2/policies/"$UUID$pid
1293 else
1294 query="/policy?id="$UUID$pid
1295 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001296 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001297 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001298 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001299
1300 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001301 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001302 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001303 return 1
1304 fi
1305 cid=${res:0:${#res}-3}
1306 ARR=$ARR" "$cid
1307 let pid=$pid+1
1308 let count=$count+1
1309 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
1310 done
1311
1312 echo ""
1313
1314 count=0
1315 for cid in $ARR; do
1316
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001317 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001318 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001319 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001320
1321 if [ $status -ne $1 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001322 echo " Deleted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001323 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001324 return 1
1325 fi
1326
1327 let count=$count+1
1328 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1329 done
1330
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001331 echo ""
1332
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001333 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001334 return 0
1335}
1336
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001337# 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 +02001338# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1339# (Function for test scripts)
1340api_delete_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001341 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001342
1343 if [ $# -ne 5 ]; then
1344 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1345 return 1
1346 fi
1347 resp_code=$1; shift;
1348 num_rics=$1; shift;
1349 start_id=$1; shift;
1350 count=$1; shift;
1351 pids=$1; shift;
1352
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001353 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001354 if [ $PA_ADAPTER_TYPE != "REST" ]; then
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001355 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1356 echo " Info - will execute over agent REST"
1357 fi
1358
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001359 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001360 query="$PMS_API_PREFIX/v2/policies/"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001361 else
1362 query="/policy"
1363 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001364
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001365 urlbase=${PA_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001366
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001367 httpproxy="NOPROXY"
BjornMagnussonXA663566c2021-11-08 10:25:07 +01001368 if [ ! -z "$KUBE_PROXY_PATH" ]; then
1369 httpproxy=$KUBE_PROXY_PATH
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001370 fi
1371
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001372 for ((i=1; i<=$pids; i++))
1373 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001374 uuid=$UUID
1375 if [ -z "$uuid" ]; then
1376 uuid="NOUUID"
1377 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001378 echo "" > "./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +01001379 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy> "./tmp/.pid${i}.del.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001380 echo $i
1381 done | xargs -n 1 -I{} -P $pids bash -c '{
1382 arg=$(echo {})
1383 echo " Parallel process $arg started"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001384 tmp=$(< "./tmp/.pid${arg}.del.txt")
1385 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001386 }'
1387 msg=""
1388 for ((i=1; i<=$pids; i++))
1389 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001390 file="./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001391 tmp=$(< $file)
1392 if [ -z "$tmp" ]; then
1393 echo " Process $i : unknown result (result file empty"
1394 msg="failed"
1395 else
1396 res=${tmp:0:1}
1397 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001398 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001399 else
1400 echo " Process $i : failed - "${tmp:1}
1401 msg="failed"
1402 fi
1403 fi
1404 done
1405 if [ -z $msg ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001406 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001407 return 0
1408 fi
1409
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001410 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001411 return 1
1412}
1413
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001414# API Test function: GET /policy_ids and V2 GET /v2/policies
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001415# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1416# (Function for test scripts)
1417api_get_policy_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001418 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001419
1420 if [ $# -lt 4 ]; then
1421 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1422 return 1
1423 fi
1424
1425 queryparams=""
1426
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001427 if [ "$PMS_VERSION" == "V2" ]; then
1428 if [ $2 != "NORIC" ]; then
1429 queryparams="?ric_id="$2
1430 fi
1431
1432 if [ $3 != "NOSERVICE" ]; then
1433 if [ -z $queryparams ]; then
1434 queryparams="?service_id="$3
1435 else
1436 queryparams=$queryparams"&service_id="$3
1437 fi
1438 fi
1439 if [ $4 != "NOTYPE" ]; then
1440 if [ -z $queryparams ]; then
1441 queryparams="?policytype_id="$4
1442 else
1443 queryparams=$queryparams"&policytype_id="$4
1444 fi
1445 fi
1446
1447 query="/v2/policies"$queryparams
1448 else
1449 if [ $2 != "NORIC" ]; then
1450 queryparams="?ric="$2
1451 fi
1452
1453 if [ $3 != "NOSERVICE" ]; then
1454 if [ -z $queryparams ]; then
1455 queryparams="?service="$3
1456 else
1457 queryparams=$queryparams"&service="$3
1458 fi
1459 fi
1460 if [ $4 != "NOTYPE" ]; then
1461 if [ -z $queryparams ]; then
1462 queryparams="?type="$4
1463 else
1464 queryparams=$queryparams"&type="$4
1465 fi
1466 fi
1467
1468 query="/policy_ids"$queryparams
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001469 fi
1470
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001471 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001472 status=${res:${#res}-3}
1473
1474 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001475 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001476 return 1
1477 fi
1478
1479 if [ $# -gt 4 ]; then
1480 body=${res:0:${#res}-3}
1481 targetJson="["
1482
1483 for pid in ${@:5} ; do
1484 if [ "$targetJson" != "[" ]; then
1485 targetJson=$targetJson","
1486 fi
1487 if [ $pid != "NOID" ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +02001488 targetJson=$targetJson"\"$UUID$pid\""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001489 fi
1490 done
1491
1492 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001493 if [ "$PMS_VERSION" == "V2" ]; then
1494 targetJson="{\"policy_ids\": $targetJson}"
1495 fi
1496 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1497 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1498
1499 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001500 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001501 return 1
1502 fi
1503 fi
1504
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001505 __log_test_pass
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001506 return 0
1507}
1508
1509# API Test function: V2 GET /v2/policy-types/{policyTypeId}
1510# args(V2): <response-code> <policy-type-id> [<schema-file>]
1511# (Function for test scripts)
1512api_get_policy_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001513 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001514
1515 if [ "$PMS_VERSION" != "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001516 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001517 return 1
1518 fi
1519
1520 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1521 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1522 return 1
1523 fi
1524 query="/v2/policy-types/$2"
1525
1526 res="$(__do_curl_to_api PA GET $query)"
1527 status=${res:${#res}-3}
1528
1529 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001530 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001531 return 1
1532 fi
1533
1534 if [ $# -eq 3 ]; then
1535
1536 body=${res:0:${#res}-3}
1537
1538 targetJson=$(< $3)
1539 targetJson="{\"policy_schema\":$targetJson}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001540 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001541 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001542
1543 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001544 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001545 return 1
1546 fi
1547 fi
1548
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001549 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001550 return 0
1551}
1552
1553# API Test function: GET /policy_schema
1554# args: <response-code> <policy-type-id> [<schema-file>]
1555# (Function for test scripts)
1556api_get_policy_schema() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001557 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001558
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001559 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001560 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001561 return 1
1562 fi
1563
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001564 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1565 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1566 return 1
1567 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001568 query="/policy_schema?id=$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001569 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001570 status=${res:${#res}-3}
1571
1572 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001573 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001574 return 1
1575 fi
1576
1577 if [ $# -eq 3 ]; then
1578
1579 body=${res:0:${#res}-3}
1580
1581 targetJson=$(< $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001582
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001583 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001584 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001585
1586 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001587 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001588 return 1
1589 fi
1590 fi
1591
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001592 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001593 return 0
1594}
1595
1596# API Test function: GET /policy_schemas
1597# args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001598# args(V2): <response-code>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001599# (Function for test scripts)
1600api_get_policy_schemas() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001601 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001602
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001603 if [ "$PMS_VERSION" == "V2" ]; then
1604 if [ $# -ne 1 ]; then
1605 __print_err "<response-code>" $@
1606 return 1
1607 fi
1608 else
1609 if [ $# -lt 2 ]; then
1610 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1611 return 1
1612 fi
1613 fi
1614 if [ "$PMS_VERSION" == "V2" ]; then
1615 query="/v2/policy-schemas"
1616 else
1617 query="/policy_schemas"
1618 if [ $2 != "NORIC" ]; then
1619 query=$query"?ric="$2
1620 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001621 fi
1622
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001623 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001624 status=${res:${#res}-3}
1625
1626 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001627 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001628 return 1
1629 fi
1630
1631 if [ $# -gt 2 ]; then
1632 body=${res:0:${#res}-3}
1633 targetJson="["
1634
1635 for file in ${@:3} ; do
1636 if [ "$targetJson" != "[" ]; then
1637 targetJson=$targetJson","
1638 fi
1639 if [ $file == "NOFILE" ]; then
1640 targetJson=$targetJson"{}"
1641 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001642 targetJson=$targetJson$(< $file)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001643 fi
1644 done
1645
1646 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001647 if [ "$PMS_VERSION" == "V2" ]; then
1648 targetJson="{\"policy_schemas\": $targetJson }"
1649 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001650 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001651 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001652
1653 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001654 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001655 return 1
1656 fi
1657 fi
1658
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001659 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001660 return 0
1661}
1662
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001663# API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001664# arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001665# (Function for test scripts)
1666api_get_policy_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001667 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001668
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001669 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001670 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001671 return 1
1672 fi
1673
1674 targetJson=""
1675
1676 if [ $3 == "STD" ]; then
1677 targetJson="{\"enforceStatus\":\"$4\""
1678 if [ $# -eq 5 ]; then
1679 targetJson=$targetJson",\"reason\":\"$5\""
1680 fi
1681 targetJson=$targetJson"}"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001682 elif [ $3 == "STD2" ]; then
1683 if [ $4 == "EMPTY" ]; then
1684 targetJson="{\"enforceStatus\":\"\""
1685 else
1686 targetJson="{\"enforceStatus\":\"$4\""
1687 fi
1688 if [ $# -eq 5 ]; then
1689 if [ $5 == "EMPTY" ]; then
1690 targetJson=$targetJson",\"enforceReason\":\"\""
1691 else
1692 targetJson=$targetJson",\"enforceReason\":\"$5\""
1693 fi
1694 fi
1695 targetJson=$targetJson"}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001696 elif [ $3 == "OSC" ]; then
1697 targetJson="{\"instance_status\":\"$4\""
1698 if [ $# -eq 5 ]; then
1699 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1700 fi
1701 targetJson=$targetJson",\"created_at\":\"????\"}"
1702 else
1703 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1704 return 1
1705 fi
1706
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001707 if [ "$PMS_VERSION" == "V2" ]; then
1708 query="/v2/policies/$UUID$2/status"
1709 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1710 else
1711 query="/policy_status?id="$UUID$2
1712 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001713
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001714 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001715 status=${res:${#res}-3}
1716
1717 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001718 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001719 return 1
1720 fi
1721
1722 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1723 body=${res:0:${#res}-3}
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001724 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001725
1726 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001727 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001728 return 1
1729 fi
1730
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001731 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001732 return 0
1733}
1734
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001735# API Test function: GET /policy_types and V2 GET /v2/policy-types
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001736# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1737# (Function for test scripts)
1738api_get_policy_types() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001739 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001740
1741 if [ $# -lt 1 ]; then
1742 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1743 return 1
1744 fi
1745
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001746 if [ "$PMS_VERSION" == "V2" ]; then
1747 if [ $# -eq 1 ]; then
1748 query="/v2/policy-types"
1749 elif [ $2 == "NORIC" ]; then
1750 query="/v2/policy-types"
1751 else
1752 query="/v2/policy-types?ric_id=$2"
1753 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001754 else
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001755 if [ $# -eq 1 ]; then
1756 query="/policy_types"
1757 elif [ $2 == "NORIC" ]; then
1758 query="/policy_types"
1759 else
1760 query="/policy_types?ric=$2"
1761 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001762 fi
1763
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001764 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001765 status=${res:${#res}-3}
1766
1767 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001768 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001769 return 1
1770 fi
1771
1772 if [ $# -gt 2 ]; then
1773 body=${res:0:${#res}-3}
1774 targetJson="["
1775
1776 for pid in ${@:3} ; do
1777 if [ "$targetJson" != "[" ]; then
1778 targetJson=$targetJson","
1779 fi
1780 if [ $pid == "EMPTY" ]; then
1781 pid=""
1782 fi
1783 targetJson=$targetJson"\"$pid\""
1784 done
1785
1786 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001787 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001788 targetJson="{\"policytype_ids\": $targetJson }"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001789 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001790 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001791 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001792
1793 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001794 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001795 return 1
1796 fi
1797 fi
1798
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001799 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001800 return 0
1801}
1802
1803#########################################################
1804#### Test case functions Health check
1805#########################################################
1806
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001807# API Test function: GET /status and V2 GET /status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001808# args: <response-code>
1809# (Function for test scripts)
1810api_get_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001811 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001812 if [ $# -ne 1 ]; then
1813 __print_err "<response-code>" $@
1814 return 1
1815 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001816 if [ "$PMS_VERSION" == "V2" ]; then
1817 query="/v2/status"
1818 else
1819 query="/status"
1820 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001821 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001822 status=${res:${#res}-3}
1823
1824 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001825 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001826 return 1
1827 fi
1828
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001829 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001830 return 0
1831}
1832
1833#########################################################
1834#### Test case functions RIC Repository
1835#########################################################
1836
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001837# API Test function: GET /ric and V2 GET /v2/rics/ric
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001838# args: <reponse-code> <management-element-id> [<ric-id>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001839# (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1840# (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1841# (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1842
1843
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001844# (Function for test scripts)
1845api_get_ric() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001846 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001847
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001848 if [ "$PMS_VERSION" == "V2" ]; then
1849 if [ $# -lt 3 ]; then
1850 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1851 return 1
1852 fi
1853 search=""
1854 if [ $2 != "NOME" ]; then
1855 search="?managed_element_id="$2
1856 fi
1857 if [ $3 != "NORIC" ]; then
1858 if [ -z $search ]; then
1859 search="?ric_id="$3
1860 else
1861 search=$search"&ric_id="$3
1862 fi
1863 fi
1864 query="/v2/rics/ric"$search
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001865
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001866 res="$(__do_curl_to_api PA GET $query)"
1867 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001868
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001869 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001870 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001871 return 1
1872 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001873
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001874 if [ $# -gt 3 ]; then
1875 body=${res:0:${#res}-3}
1876 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1877 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001878 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001879 return 1
1880 fi
1881
1882 targetJson=$(<./tmp/.tmp_rics.json)
1883 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1884 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1885 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1886 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001887 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001888 return 1
1889 fi
1890 fi
1891 else
1892 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1893 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1894 return 1
1895 fi
1896
1897 query="/ric?managedElementId="$2
1898
1899 res="$(__do_curl_to_api PA GET $query)"
1900 status=${res:${#res}-3}
1901
1902 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001903 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001904 return 1
1905 fi
1906
1907 if [ $# -eq 3 ]; then
1908 body=${res:0:${#res}-3}
1909 if [ "$body" != "$3" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001910 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001911 return 1
1912 fi
1913 fi
1914 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001915 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001916 return 0
1917}
1918
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001919# API test function: GET /rics and V2 GET /v2/rics
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001920# args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1921# 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_........."
1922# format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1923# (Function for test scripts)
1924api_get_rics() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001925 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001926
1927 if [ $# -lt 2 ]; then
1928 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1929 return 1
1930 fi
1931
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001932 if [ "$PMS_VERSION" == "V2" ]; then
1933 query="/v2/rics"
1934 if [ $2 != "NOTYPE" ]; then
1935 query="/v2/rics?policytype_id="$2
1936 fi
1937 else
1938 query="/rics"
1939 if [ $2 != "NOTYPE" ]; then
1940 query="/rics?policyType="$2
1941 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001942 fi
1943
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001944 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001945 status=${res:${#res}-3}
1946
1947 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001948 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001949 return 1
1950 fi
1951
1952 if [ $# -gt 2 ]; then
1953 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001954 if [ "$PMS_VERSION" == "V2" ]; then
1955 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1956 else
1957 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1958 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001959 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001960 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001961 return 1
1962 fi
1963
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001964 targetJson=$(<./tmp/.tmp_rics.json)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001965 if [ "$PMS_VERSION" == "V2" ]; then
1966 targetJson="{\"rics\": $targetJson }"
1967 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001968 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001969 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001970 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001971 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001972 return 1
1973 fi
1974 fi
1975
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001976 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001977 return 0
1978}
1979
1980##################################################################
1981#### API Test case functions Service registry and supervision ####
1982##################################################################
1983
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001984# API test function: PUT /service and V2 PUT /service
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001985# args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1986# (Function for test scripts)
1987api_put_service() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001988 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001989 if [ $# -ne 4 ]; then
1990 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1991 return 1
1992 fi
1993
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001994 if [ "$PMS_VERSION" == "V2" ]; then
1995 query="/v2/services"
1996 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1997 else
1998 query="/service"
1999 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
2000 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02002001 file="./tmp/.tmp.json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002002 echo "$json" > $file
2003
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002004 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002005 status=${res:${#res}-3}
2006
2007 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002008 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002009 return 1
2010 fi
2011
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002012 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002013 return 0
2014}
2015
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002016# API test function: GET /services and V2 GET /v2/services
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002017#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>]* )]
2018# (Function for test scripts)
2019api_get_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002020 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002021 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
2022 paramError=1
2023 if [ $# -eq 1 ]; then
2024 paramError=0
2025 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
2026 paramError=0
2027 elif [ $# -eq 5 ]; then
2028 paramError=0
2029 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
2030 argLen=$(($#-2))
2031 if [ $(($argLen%3)) -eq 0 ]; then
2032 paramError=0
2033 fi
2034 fi
2035
2036 if [ $paramError -ne 0 ]; then
2037 __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>]* )]" $@
2038 return 1
2039 fi
2040
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002041 if [ "$PMS_VERSION" == "V2" ]; then
2042 query="/v2/services"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002043
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002044 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2045 query="/v2/services?service_id="$2
2046 fi
2047 else
2048 query="/services"
2049
2050 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
2051 query="/services?name="$2
2052 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002053 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002054 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002055 status=${res:${#res}-3}
2056
2057 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002058 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002059 return 1
2060 fi
2061
2062 if [ $# -gt 2 ]; then
2063 variableArgCount=$(($#-2))
2064 body=${res:0:${#res}-3}
2065 targetJson="["
2066 shift; shift;
2067 cntr=0
2068 while [ $cntr -lt $variableArgCount ]; do
2069 servicename=$1; shift;
2070 timeout=$1; shift;
2071 callback=$1; shift;
2072 if [ $cntr -gt 0 ]; then
2073 targetJson=$targetJson","
2074 fi
2075 # timeSinceLastActivitySeconds value cannot be checked since value varies
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002076 if [ "$PMS_VERSION" == "V2" ]; then
2077 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
2078 else
2079 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
2080 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002081 let cntr=cntr+3
2082 done
2083 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002084 if [ "$PMS_VERSION" == "V2" ]; then
2085 targetJson="{\"service_list\": $targetJson }"
2086 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002087 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002088 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002089 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002090 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002091 return 1
2092 fi
2093 fi
2094
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002095 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002096 return 0
2097}
2098
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002099# API test function: GET /services V2 GET /v2/services - (only checking service names)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002100# args: <response-code> [<service-name>]*"
2101# (Function for test scripts)
2102api_get_service_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002103 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002104
2105 if [ $# -lt 1 ]; then
2106 __print_err "<response-code> [<service-name>]*" $@
2107 return 1
2108 fi
2109
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002110 if [ "$PMS_VERSION" == "V2" ]; then
2111 query="/v2/services"
2112 else
2113 query="/services"
2114 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002115 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002116 status=${res:${#res}-3}
2117
2118 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002119 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002120 return 1
2121 fi
2122
2123 body=${res:0:${#res}-3}
2124 targetJson="["
2125 for rapp in ${@:2} ; do
2126 if [ "$targetJson" != "[" ]; then
2127 targetJson=$targetJson","
2128 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002129 if [ "$PMS_VERSION" == "V2" ]; then
2130 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
2131 else
2132 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
2133 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002134 done
2135
2136 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002137 if [ "$PMS_VERSION" == "V2" ]; then
2138 targetJson="{\"service_list\": $targetJson }"
2139 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002140 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02002141 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002142
2143 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002144 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002145 return 1
2146 fi
2147
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002148 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002149 return 0
2150}
2151
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002152# API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002153# args: <response-code> <service-name>
2154# (Function for test scripts)
2155api_delete_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002156 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002157
2158 if [ $# -ne 2 ]; then
2159 __print_err "<response-code> <service-name>" $@
2160 return 1
2161 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002162 if [ "$PMS_VERSION" == "V2" ]; then
2163 query="/v2/services/"$2
2164 else
2165 query="/services?name="$2
2166 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002167 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002168 status=${res:${#res}-3}
2169
2170 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002171 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002172 return 1
2173 fi
2174
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002175 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002176 return 0
2177}
2178
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002179# API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002180# args: <response-code> <service-name>
2181# (Function for test scripts)
2182api_put_services_keepalive() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002183 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002184
2185 if [ $# -ne 2 ]; then
2186 __print_err "<response-code> <service-name>" $@
2187 return 1
2188 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01002189 if [ "$PMS_VERSION" == "V2" ]; then
2190 query="/v2/services/$2/keepalive"
2191 else
2192 query="/services/keepalive?name="$2
2193 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002194
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002195 res="$(__do_curl_to_api PA PUT $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002196 status=${res:${#res}-3}
2197
2198 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002199 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002200 return 1
2201 fi
2202
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002203 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01002204 return 0
2205}
2206
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002207##################################################################
2208#### API Test case functions Configuration ####
2209##################################################################
2210
2211# API Test function: PUT /v2/configuration
2212# args: <response-code> <config-file>
2213# (Function for test scripts)
2214api_put_configuration() {
2215 __log_test_start $@
2216
2217 if [ "$PMS_VERSION" != "V2" ]; then
2218 __log_test_fail_not_supported
2219 return 1
2220 fi
2221
2222 if [ $# -ne 2 ]; then
2223 __print_err "<response-code> <config-file>" $@
2224 return 1
2225 fi
2226 if [ ! -f $2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002227 __log_test_fail_general "Config file "$2", does not exist"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002228 return 1
2229 fi
2230 inputJson=$(< $2)
2231 inputJson="{\"config\":"$inputJson"}"
2232 file="./tmp/.config.json"
2233 echo $inputJson > $file
2234 query="/v2/configuration"
2235 res="$(__do_curl_to_api PA PUT $query $file)"
2236 status=${res:${#res}-3}
2237
2238 if [ $status -ne $1 ]; then
2239 __log_test_fail_status_code $1 $status
2240 return 1
2241 fi
2242
2243 __log_test_pass
2244 return 0
2245}
2246
2247# API Test function: GET /v2/configuration
2248# args: <response-code> [<config-file>]
2249# (Function for test scripts)
2250api_get_configuration() {
2251 __log_test_start $@
2252
2253 if [ "$PMS_VERSION" != "V2" ]; then
2254 __log_test_fail_not_supported
2255 return 1
2256 fi
2257
2258 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
2259 __print_err "<response-code> [<config-file>]" $@
2260 return 1
2261 fi
2262 if [ ! -f $2 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002263 __log_test_fail_general "Config file "$2" for comparison, does not exist"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002264 return 1
2265 fi
2266
2267 query="/v2/configuration"
2268 res="$(__do_curl_to_api PA GET $query)"
2269 status=${res:${#res}-3}
2270
2271 if [ $status -ne $1 ]; then
2272 __log_test_fail_status_code $1 $status
2273 return 1
2274 fi
2275
2276 if [ $# -eq 2 ]; then
2277
2278 body=${res:0:${#res}-3}
2279
2280 targetJson=$(< $2)
2281 targetJson="{\"config\":"$targetJson"}"
2282 echo "TARGET JSON: $targetJson" >> $HTTPLOG
2283 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2284
2285 if [ $res -ne 0 ]; then
2286 __log_test_fail_body
2287 return 1
2288 fi
2289 fi
2290
2291 __log_test_pass
2292 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002293}
2294
2295##########################################
2296#### Reset types and instances ####
2297##########################################
2298
2299# Admin reset to remove all policies and services
2300# All types and instances etc are removed - types and instances in a1 sims need to be removed separately
2301# NOTE - only works in kubernetes and the pod should not be running
2302# args: -
2303# (Function for test scripts)
2304
2305pms_kube_pvc_reset() {
2306 __log_test_start $@
2307
BjornMagnussonXA663566c2021-11-08 10:25:07 +01002308 pvc_name=$(kubectl get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy)
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002309 if [ -z "$pvc_name" ]; then
2310 pvc_name=policymanagementservice-vardata-pvc
2311 fi
2312 echo " Trying to reset pvc: "$pvc_name
BjornMagnussonXA663566c2021-11-08 10:25:07 +01002313 __kube_clean_pvc $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $POLICY_AGENT_CONTAINER_MNT_DIR
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002314
2315 __log_test_pass
2316 return 0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01002317}