blob: 2f1f543a2b48ef3fd5744ff22c097cfcb9cc593b [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
BjornMagnussonXA80a92002020-03-19 14:31:06 +010022
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010023## Access to Policy agent
24# Host name may be changed if app started by kube
25# Direct access from script
26PA_HTTPX="http"
27PA_HOST_NAME=$LOCALHOST_NAME
28PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
29
30# PA_ADAPTER used for switch between REST and DMAAP
31PA_ADAPTER_TYPE="REST"
32PA_ADAPTER=$PA_PATH
33
34# Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
35AGENT_RETRY_CODES=""
36
37###########################
38### Policy Agents functions
39###########################
40
41# All calls to the agent will be directed to the agent REST interface from now on
42# args: -
43# (Function for test scripts)
44use_agent_rest_http() {
45 echo -e $BOLD"Agent protocol setting"$EBOLD
46 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
47 PA_HTTPX="http"
48 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
49
50 PA_ADAPTER_TYPE="REST"
51 PA_ADAPTER=$PA_PATH
52 echo ""
53}
54
55# All calls to the agent will be directed to the agent REST interface from now on
56# args: -
57# (Function for test scripts)
58use_agent_rest_https() {
59 echo -e $BOLD"Agent protocol setting"$EBOLD
60 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
61 PA_HTTPX="https"
62 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
63
64 PA_ADAPTER_TYPE="REST"
65 PA_ADAPTER=$PA_PATH
66 echo ""
67}
68
69# All calls to the agent will be directed to the agent dmaap interface over http from now on
70# args: -
71# (Function for test scripts)
72use_agent_dmaap_http() {
73 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
74 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
75 PA_ADAPTER_TYPE="MR-HTTP"
76 echo ""
77}
78
79# All calls to the agent will be directed to the agent dmaap interface over https from now on
80# args: -
81# (Function for test scripts)
82use_agent_dmaap_https() {
83 echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
84 echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
85 echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
86 PA_ADAPTER_TYPE="MR-HTTPS"
87 echo ""
88}
89
90# Start the policy agent
BjornMagnussonXAc963b732021-01-20 14:24:13 +010091# args: (docker) PROXY|NOPROXY <config-file>
92# args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010093# (Function for test scripts)
94start_policy_agent() {
95 echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
96
97 if [ $RUNMODE == "KUBE" ]; then
98
99 # Check if app shall be fully managed by the test script
100 __check_included_image "PA"
101 retcode_i=$?
102
103 # Check if app shall only be used by the testscipt
104 __check_prestarted_image "PA"
105 retcode_p=$?
106
107 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
108 echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
109 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
110 exit
111 fi
112 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
113 echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
114 echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
115 exit
116 fi
117
118 if [ $retcode_p -eq 0 ]; then
119 echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
120 echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
121 __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
122 fi
123
124 if [ $retcode_i -eq 0 ]; then
125
126 echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
127
128 #Check if nonrtric namespace exists, if not create it
129 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
130
131 #Export all vars needed for service and deployment
132 export POLICY_AGENT_APP_NAME
133 export KUBE_NONRTRIC_NAMESPACE
134 export POLICY_AGENT_IMAGE
135 export POLICY_AGENT_INTERNAL_PORT
136 export POLICY_AGENT_INTERNAL_SECURE_PORT
137 export POLICY_AGENT_EXTERNAL_PORT
138 export POLICY_AGENT_EXTERNAL_SECURE_PORT
139 export POLICY_AGENT_CONFIG_MOUNT_PATH
140 export POLICY_AGENT_DATA_MOUNT_PATH
141 export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
142 export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
143 export POLICY_AGENT_PKG_NAME
144 if [ $1 == "PROXY" ]; then
145 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
146 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100147 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
148 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
149 else
150 echo " Configured with http proxy"
151 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100152 else
153 AGENT_HTTP_PROXY_CONFIG_PORT=0
154 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100155 echo " Configured without http proxy"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100156 fi
157 export AGENT_HTTP_PROXY_CONFIG_PORT
158 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
159
160
161 # Create config map for config
162 configfile=$PWD/tmp/$POLICY_AGENT_CONFIG_FILE
163 cp $2 $configfile
164 output_yaml=$PWD/tmp/pa_cfc.yaml
165 __kube_create_configmap $POLICY_AGENT_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $configfile $output_yaml
166
167 # Create config map for data
168 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
169 if [ $# -lt 3 ]; then
170 #create empty dummy file
171 echo "{}" > $data_json
172 else
173 cp $3 $data_json
174 fi
175 output_yaml=$PWD/tmp/pa_cfd.yaml
176 __kube_create_configmap $POLICY_AGENT_DATA_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
177
178 # Create service
179 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"svc.yaml
180 output_yaml=$PWD/tmp/pa_svc.yaml
181 __kube_create_instance service $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
182
183 # Create app
184 input_yaml=$SIM_GROUP"/"$POLICY_AGENT_COMPOSE_DIR"/"app.yaml
185 output_yaml=$PWD/tmp/pa_app.yaml
186 __kube_create_instance app $POLICY_AGENT_APP_NAME $input_yaml $output_yaml
187
188 fi
189
190 echo " Retrieving host and ports for service..."
191 PA_HOST_NAME=$(__kube_get_service_host $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
192 POLICY_AGENT_EXTERNAL_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
193 POLICY_AGENT_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
194
195 echo " Host IP, http port, https port: $PA_HOST_NAME $POLICY_AGENT_EXTERNAL_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT"
196
197 if [ $PA_HTTPX == "http" ]; then
198 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
199 else
200 PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
201 fi
202 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
203
204 if [ $PA_ADAPTER_TYPE == "REST" ]; then
205 PA_ADAPTER=$PA_PATH
206 fi
207 else
208 __check_included_image 'PA'
209 if [ $? -eq 1 ]; then
210 echo -e $RED"The Policy Agent app is not included in this test script"$ERED
211 echo -e $RED"The Policy Agent will not be started"$ERED
212 exit
213 fi
214
215 #Export all vars needed for docker-compose
216 export POLICY_AGENT_APP_NAME
217 export POLICY_AGENT_APP_NAME_ALIAS
218 export POLICY_AGENT_INTERNAL_PORT
219 export POLICY_AGENT_EXTERNAL_PORT
220 export POLICY_AGENT_INTERNAL_SECURE_PORT
221 export POLICY_AGENT_EXTERNAL_SECURE_PORT
222 export CONSUL_HOST
223 export CONSUL_INTERNAL_PORT
224 export CONFIG_BINDING_SERVICE
225 export POLICY_AGENT_CONFIG_KEY
226 export DOCKER_SIM_NWNAME
227 export POLICY_AGENT_HOST_MNT_DIR
228 export POLICY_AGENT_CONFIG_MOUNT_PATH
229 export POLICY_AGENT_CONFIG_FILE
230 export POLICY_AGENT_PKG_NAME
231
232 if [ $1 == "PROXY" ]; then
233 AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
234 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100235 if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
236 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
237 else
238 echo " Configured with http proxy"
239 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100240 else
241 AGENT_HTTP_PROXY_CONFIG_PORT=0
242 AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100243 echo " Configured without http proxy"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100244 fi
245 export AGENT_HTTP_PROXY_CONFIG_PORT
246 export AGENT_HTTP_PROXY_CONFIG_HOST_NAME
247
248 dest_file=$SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_HOST_MNT_DIR/application.yaml
249
250 envsubst < $2 > $dest_file
251
252 __start_container $POLICY_AGENT_COMPOSE_DIR NODOCKERARGS 1 $POLICY_AGENT_APP_NAME
253
254 __check_service_start $POLICY_AGENT_APP_NAME $PA_PATH$POLICY_AGENT_ALIVE_URL
255 fi
256 echo ""
257 return 0
258}
259
BjornMagnussonXA366e36a2021-01-27 11:48:56 +0100260# Load the the appl config for the agent into a config map
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100261agent_load_config() {
262 echo -e $BOLD"Agent - load config from "$EBOLD$1
263 data_json=$PWD/tmp/$POLICY_AGENT_DATA_FILE
264 cp $1 $data_json
265 output_yaml=$PWD/tmp/pa_cfd.yaml
266 __kube_create_configmap $POLICY_AGENT_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest PA $data_json $output_yaml
267}
268
269
270# Turn on debug level tracing in the agent
271# args: -
272# (Function for test scripts)
273set_agent_debug() {
274 echo -e $BOLD"Setting agent debug logging"$EBOLD
275 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
276 result=$(__do_curl "$curlString")
277 if [ $? -ne 0 ]; then
278 __print_err "could not set debug mode" $@
279 ((RES_CONF_FAIL++))
280 return 1
281 fi
282 echo ""
283 return 0
284}
285
286# Turn on trace level tracing in the agent
287# args: -
288# (Function for test scripts)
289set_agent_trace() {
290 echo -e $BOLD"Setting agent trace logging"$EBOLD
291 curlString="$PA_PATH$POLICY_AGENT_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
292 result=$(__do_curl "$curlString")
293 if [ $? -ne 0 ]; then
294 __print_err "could not set trace mode" $@
295 ((RES_CONF_FAIL++))
296 return 1
297 fi
298 echo ""
299 return 0
300}
301
302# Perform curl retries when making direct call to the agent for the specified http response codes
303# Speace separated list of http response codes
304# args: [<response-code>]*
305use_agent_retries() {
306 echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
307 AGENT_RETRY_CODES=$@
308 echo ""
309 return
310}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100311
312#########################################################
313#### Test case functions A1 Policy management service
314#########################################################
315
316# This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
317# This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
318# args: json:<url> <target-value> [<timeout-in-seconds]
319# (Function for test scripts)
320api_equal() {
321 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
322 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
323 if [[ $1 == "json:"* ]]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100324 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100325 __var_test "Policy Agent" $PA_PATH$PMS_API_PREFIX"/v2/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100326 else
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100327 __var_test "Policy Agent" $PA_PATH"/" $1 "=" $2 $3
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100328 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100329 return 0
330 fi
331 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100332 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
333 return 1
334}
335
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100336# API Test function: GET /policies and V2 GET /v2/policy-instances
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100337# 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>]*]
338# 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 +0100339# (Function for test scripts)
340api_get_policies() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100341 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100342
343 if [ "$PMS_VERSION" == "V2" ]; then
344 paramError=0
345 variableParams=$(($#-4))
346 if [ $# -lt 4 ]; then
347 paramError=1
348 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
349 paramError=1
350 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
351 paramError=1
352 fi
353
354 if [ $paramError -ne 0 ]; then
355 __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>]*]" $@
356 return 1
357 fi
358 else
359 paramError=0
360 variableParams=$(($#-4))
361 if [ $# -lt 4 ]; then
362 paramError=1
363 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
364 paramError=1
365 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
366 paramError=1
367 fi
368
369 if [ $paramError -ne 0 ]; then
370 __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>]*]" $@
371 return 1
372 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100373 fi
374
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100375 queryparams=""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100376 if [ "$PMS_VERSION" == "V2" ]; then
377 if [ $2 != "NORIC" ]; then
378 queryparams="?ric_id="$2
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100379 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100380 if [ $3 != "NOSERVICE" ]; then
381 if [ -z $queryparams ]; then
382 queryparams="?service_id="$3
383 else
384 queryparams=$queryparams"&service_id="$3
385 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100386 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100387 if [ $4 != "NOTYPE" ]; then
388 if [ -z $queryparams ]; then
389 queryparams="?policytype_id="$4
390 else
391 queryparams=$queryparams"&policytype_id="$4
392 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100393 fi
394
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100395 query="/v2/policy-instances"$queryparams
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100396 res="$(__do_curl_to_api PA GET $query)"
397 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100398
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100399 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100400 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100401 return 1
402 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100403
404 if [ $# -gt 4 ]; then
405 body=${res:0:${#res}-3}
406 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
407 targetJson="["
408 else
409 targetJson="["
410 arr=(${@:5})
411
412 for ((i=0; i<$(($#-4)); i=i+7)); do
413
414 if [ "$targetJson" != "[" ]; then
415 targetJson=$targetJson","
416 fi
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100417 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 +0100418 if [ "${arr[$i+3]}" == "EMPTY" ]; then
419 targetJson=$targetJson"\"\","
420 else
421 targetJson=$targetJson"\"${arr[$i+3]}\","
422 fi
423 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
424 file="./tmp/.p.json"
425 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
426 json=$(cat $file)
427 targetJson=$targetJson"\"policy_data\":"$json"}"
428 done
429 fi
430
431 targetJson=$targetJson"]"
432 targetJson="{\"policies\": $targetJson}"
433 echo "TARGET JSON: $targetJson" >> $HTTPLOG
434 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
435
436 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100437 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100438 return 1
439 fi
440 fi
441 else
442 if [ $2 != "NORIC" ]; then
443 queryparams="?ric="$2
444 fi
445 if [ $3 != "NOSERVICE" ]; then
446 if [ -z $queryparams ]; then
447 queryparams="?service="$3
448 else
449 queryparams=$queryparams"&service="$3
450 fi
451 fi
452 if [ $4 != "NOTYPE" ]; then
453 if [ -z $queryparams ]; then
454 queryparams="?type="$4
455 else
456 queryparams=$queryparams"&type="$4
457 fi
458 fi
459
460 query="/policies"$queryparams
461 res="$(__do_curl_to_api PA GET $query)"
462 status=${res:${#res}-3}
463
464 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100465 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100466 return 1
467 fi
468
469 if [ $# -gt 4 ]; then
470 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
471 targetJson="["
472 else
473 body=${res:0:${#res}-3}
474 targetJson="["
475 arr=(${@:5})
476
477 for ((i=0; i<$(($#-4)); i=i+5)); do
478
479 if [ "$targetJson" != "[" ]; then
480 targetJson=$targetJson","
481 fi
482 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
483 if [ "${arr[$i+3]}" == "EMPTY" ]; then
484 targetJson=$targetJson"\"\","
485 else
486 targetJson=$targetJson"\"${arr[$i+3]}\","
487 fi
488 file="./tmp/.p.json"
489 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
490 json=$(cat $file)
491 targetJson=$targetJson"\"json\":"$json"}"
492 done
493 fi
494
495 targetJson=$targetJson"]"
496 echo "TARGET JSON: $targetJson" >> $HTTPLOG
497 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
498
499 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100500 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100501 return 1
502 fi
503 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100504 fi
505
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100506 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100507 return 0
508
509}
510
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100511
512# API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
513# args: <response-code> <policy-id> [<template-file>]
514# args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
515
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100516# (Function for test scripts)
517api_get_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100518 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100519
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100520
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100521 if [ "$PMS_VERSION" == "V2" ]; then
522 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
523 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
524 return 1
525 fi
526 query="/v2/policies/$UUID$2"
527 else
528 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
529 __print_err "<response-code> <policy-id> [<template-file>] " $@
530 return 1
531 fi
532 query="/policy?id=$UUID$2"
533 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200534 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100535 status=${res:${#res}-3}
536
537 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100538 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100539 return 1
540 fi
541
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100542 if [ "$PMS_VERSION" == "V2" ]; then
543 if [ $# -eq 8 ]; then
544
545 #Create a policy json to compare with
546 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100547
548 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
549 if [ $7 != "NOTRANSIENT" ]; then
550 targetJson=$targetJson", \"transient\":$7"
551 fi
552 if [ $6 != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100553 targetJson=$targetJson", \"policytype_id\":\"$6\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100554 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100555 targetJson=$targetJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100556 fi
557 if [ $8 != "NOURL" ]; then
558 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
559 fi
560
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100561 data=$(sed 's/XXX/'${2}'/g' $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100562 targetJson=$targetJson", \"policy_data\":$data"
563 targetJson="{$targetJson}"
564
565 echo "TARGET JSON: $targetJson" >> $HTTPLOG
566 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
567 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100568 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100569 return 1
570 fi
571 fi
572 else
573 if [ $# -eq 3 ]; then
574 #Create a policy json to compare with
575 body=${res:0:${#res}-3}
576 file="./tmp/.p.json"
577 sed 's/XXX/'${2}'/g' $3 > $file
578 targetJson=$(< $file)
579 echo "TARGET JSON: $targetJson" >> $HTTPLOG
580 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
581 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100582 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100583 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100584 fi
585 fi
586
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100587 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100588 return 0
589}
590
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100591# API Test function: PUT /policy and V2 PUT /policies
592# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
593# 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 +0100594# (Function for test scripts)
595api_put_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100596 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100597
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100598 if [ "$PMS_VERSION" == "V2" ]; then
599 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
600 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
601 return 1
602 fi
603 else
604 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
605 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
606 return 1
607 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100608 fi
609
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100610 count=0
611 max=1
612 serv=$2
613 ric=$3
614 pt=$4
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100615 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100616 trans=$6
617
618 if [ "$PMS_VERSION" == "V2" ]; then
619 noti=$7
620 temp=$8
621 if [ $# -eq 9 ]; then
622 max=$9
623 fi
624 else
625 temp=$7
626 if [ $# -eq 8 ]; then
627 max=$8
628 fi
629 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100630
631 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100632 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100633
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100634 query="/v2/policies"
635
636 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
637 if [ $trans != "NOTRANSIENT" ]; then
638 inputJson=$inputJson", \"transient\":$trans"
639 fi
640 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100641 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100642 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100643 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100644 fi
645 if [ $noti != "NOURL" ]; then
646 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
647 fi
648 file="./tmp/.p.json"
649 data=$(sed 's/XXX/'${pid}'/g' $temp)
650 inputJson=$inputJson", \"policy_data\":$data"
651 inputJson="{$inputJson}"
652 echo $inputJson > $file
653 else
654 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
655
656 if [ $pt != "NOTYPE" ]; then
657 query=$query"&type=$pt"
658 fi
659
660 if [ $trans != NOTRANSIENT ]; then
661 query=$query"&transient=$trans"
662 fi
663
664 file="./tmp/.p.json"
665 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200666 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200667 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100668 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200669 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100670 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200671 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100672 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100673 return 1
674 fi
675
676 let pid=$pid+1
677 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200678 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100679 done
680 echo ""
681
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100682 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100683 return 0
684}
685
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100686# API Test function: PUT /policy and V2 PUT /policies, to run in batch
687# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
688# 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 +0200689# (Function for test scripts)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100690
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200691api_put_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100692 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200693
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100694 if [ "$PMS_VERSION" == "V2" ]; then
695 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
696 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
697 return 1
698 fi
699 else
700 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
701 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
702 return 1
703 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200704 fi
705
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100706 count=0
707 max=1
708 serv=$2
709 ric=$3
710 pt=$4
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200711 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100712 trans=$6
713 if [ "$PMS_VERSION" == "V2" ]; then
714 noti=$7
715 temp=$8
716 if [ $# -eq 9 ]; then
717 max=$9
718 fi
719 else
720 temp=$7
721 if [ $# -eq 8 ]; then
722 max=$8
723 fi
724 fi
725
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200726 ARR=""
727 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100728 if [ "$PMS_VERSION" == "V2" ]; then
729 query="/v2/policies"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200730
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100731 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
732 if [ $trans != "NOTRANSIENT" ]; then
733 inputJson=$inputJson", \"transient\":$trans"
734 fi
735 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100736 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100737 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100738 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100739 fi
740 if [ $noti != "NOURL" ]; then
741 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
742 fi
743 file="./tmp/.p.json"
744 data=$(sed 's/XXX/'${pid}'/g' $temp)
745 inputJson=$inputJson", \"policy_data\":$data"
746 inputJson="{$inputJson}"
747 echo $inputJson > $file
748 else
749 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
750
751 if [ $pt != "NOTYPE" ]; then
752 query=$query"&type=$pt"
753 fi
754
755 if [ $trans != NOTRANSIENT ]; then
756 query=$query"&transient=$trans"
757 fi
758 file="./tmp/.p.json"
759 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200760 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200761 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200762 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200763 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200764
765 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200766 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100767 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200768 return 1
769 fi
770 cid=${res:0:${#res}-3}
771 ARR=$ARR" "$cid
772 let pid=$pid+1
773 let count=$count+1
774 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
775 done
776
777 echo ""
778 count=0
779 for cid in $ARR; do
780
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200781 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200782 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100783 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200784
785 if [ $status -ne $1 ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100786 echo " Accepted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100787 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200788 return 1
789 fi
790
791 let count=$count+1
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100792 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200793 done
794
795 echo ""
796
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100797 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200798 return 0
799}
800
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100801# 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 +0200802# 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 +0100803# 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 +0200804# (Function for test scripts)
805api_put_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100806 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200807
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100808 if [ "$PMS_VERSION" == "V2" ]; then
809 if [ $# -ne 11 ]; then
810 __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>" $@
811 return 1
812 fi
813 else
814 if [ $# -ne 10 ]; then
815 __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>" $@
816 return 1
817 fi
818 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200819 resp_code=$1; shift;
820 serv=$1; shift
821 ric_base=$1; shift;
822 num_rics=$1; shift;
823 type=$1; shift;
824 start_id=$1; shift;
825 transient=$1; shift;
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100826 if [ "$PMS_VERSION" == "V2" ]; then
827 noti=$1; shift;
828 else
829 noti=""
830 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200831 template=$1; shift;
832 count=$1; shift;
833 pids=$1; shift;
834
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100835 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100836 if [ $PA_ADAPTER_TYPE != "REST" ]; then
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200837 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
838 echo " Info - will execute over agent REST"
839 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100840 if [ "$PMS_VERSION" == "V2" ]; then
841 if [ $serv == "NOSERVICE" ]; then
842 serv=""
843 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100844 query="$PMS_API_PREFIX/v2/policies"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100845 else
846 if [ $serv == "NOSERVICE" ]; then
847 serv=""
848 fi
849 query="/policy?service=$serv"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200850
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100851 if [ $type != "NOTYPE" ]; then
852 query=$query"&type=$type"
853 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200854
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100855 if [ $transient != NOTRANSIENT ]; then
856 query=$query"&transient=$transient"
857 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200858 fi
859
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100860 urlbase=${PA_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200861
862 for ((i=1; i<=$pids; i++))
863 do
BjornMagnussonXAad047782020-06-08 15:54:11 +0200864 uuid=$UUID
865 if [ -z "$uuid" ]; then
866 uuid="NOUUID"
867 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200868 echo "" > "./tmp/.pid${i}.res.txt"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100869 if [ "$PMS_VERSION" == "V2" ]; then
870 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i > "./tmp/.pid${i}.txt"
871 else
872 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt"
873 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200874 echo $i
875 done | xargs -n 1 -I{} -P $pids bash -c '{
876 arg=$(echo {})
877 echo " Parallel process $arg started"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200878 tmp=$(< "./tmp/.pid${arg}.txt")
879 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200880 }'
881 msg=""
882 for ((i=1; i<=$pids; i++))
883 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200884 file="./tmp/.pid${i}.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200885 tmp=$(< $file)
886 if [ -z "$tmp" ]; then
887 echo " Process $i : unknown result (result file empty"
888 msg="failed"
889 else
890 res=${tmp:0:1}
891 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100892 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200893 else
894 echo " Process $i : failed - "${tmp:1}
895 msg="failed"
896 fi
897 fi
898 done
899 if [ -z $msg ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100900 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200901 return 0
902 fi
903
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100904 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200905 return 1
906}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100907
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100908# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100909# args: <response-code> <policy-id> [count]
910# (Function for test scripts)
911api_delete_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100912 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100913
914 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
915 __print_err "<response-code> <policy-id> [count]" $@
916 return 1
917 fi
918
919 count=0
920 max=1
921
922 if [ $# -eq 3 ]; then
923 max=$3
924 fi
925
926 pid=$2
927
928 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100929 if [ "$PMS_VERSION" == "V2" ]; then
930 query="/v2/policies/"$UUID$pid
931 else
932 query="/policy?id="$UUID$pid
933 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200934 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100935 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200936 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100937
938 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200939 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100940 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100941 return 1
942 fi
943 let pid=$pid+1
944 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200945 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100946 done
947 echo ""
948
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100949 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100950 return 0
951}
952
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100953# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200954# args: <response-code> <policy-id> [count]
955# (Function for test scripts)
956api_delete_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100957 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200958
959 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
960 __print_err "<response-code> <policy-id> [count]" $@
961 return 1
962 fi
963
964 count=0
965 max=1
966
967 if [ $# -eq 3 ]; then
968 max=$3
969 fi
970
971 pid=$2
972 ARR=""
973 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100974 if [ "$PMS_VERSION" == "V2" ]; then
975 query="/v2/policies/"$UUID$pid
976 else
977 query="/policy?id="$UUID$pid
978 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200979 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200980 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200981 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200982
983 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200984 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100985 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200986 return 1
987 fi
988 cid=${res:0:${#res}-3}
989 ARR=$ARR" "$cid
990 let pid=$pid+1
991 let count=$count+1
992 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
993 done
994
995 echo ""
996
997 count=0
998 for cid in $ARR; do
999
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001000 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001001 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001002 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001003
1004 if [ $status -ne $1 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001005 echo " Deleted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001006 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001007 return 1
1008 fi
1009
1010 let count=$count+1
1011 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
1012 done
1013
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001014 echo ""
1015
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001016 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +02001017 return 0
1018}
1019
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001020# 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 +02001021# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
1022# (Function for test scripts)
1023api_delete_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001024 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001025
1026 if [ $# -ne 5 ]; then
1027 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
1028 return 1
1029 fi
1030 resp_code=$1; shift;
1031 num_rics=$1; shift;
1032 start_id=$1; shift;
1033 count=$1; shift;
1034 pids=$1; shift;
1035
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001036 #if [ $PA_ADAPTER != $RESTBASE ] && [ $PA_ADAPTER != $RESTBASE_SECURE ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001037 if [ $PA_ADAPTER_TYPE != "REST" ]; then
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001038 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
1039 echo " Info - will execute over agent REST"
1040 fi
1041
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001042 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001043 query="$PMS_API_PREFIX/v2/policies/"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001044 else
1045 query="/policy"
1046 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001047
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001048 urlbase=${PA_ADAPTER}${query}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001049
1050 for ((i=1; i<=$pids; i++))
1051 do
BjornMagnussonXAad047782020-06-08 15:54:11 +02001052 uuid=$UUID
1053 if [ -z "$uuid" ]; then
1054 uuid="NOUUID"
1055 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001056 echo "" > "./tmp/.pid${i}.del.res.txt"
1057 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > "./tmp/.pid${i}.del.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001058 echo $i
1059 done | xargs -n 1 -I{} -P $pids bash -c '{
1060 arg=$(echo {})
1061 echo " Parallel process $arg started"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001062 tmp=$(< "./tmp/.pid${arg}.del.txt")
1063 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001064 }'
1065 msg=""
1066 for ((i=1; i<=$pids; i++))
1067 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001068 file="./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001069 tmp=$(< $file)
1070 if [ -z "$tmp" ]; then
1071 echo " Process $i : unknown result (result file empty"
1072 msg="failed"
1073 else
1074 res=${tmp:0:1}
1075 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001076 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001077 else
1078 echo " Process $i : failed - "${tmp:1}
1079 msg="failed"
1080 fi
1081 fi
1082 done
1083 if [ -z $msg ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001084 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001085 return 0
1086 fi
1087
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001088 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +02001089 return 1
1090}
1091
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001092# API Test function: GET /policy_ids and V2 GET /v2/policies
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001093# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
1094# (Function for test scripts)
1095api_get_policy_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001096 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001097
1098 if [ $# -lt 4 ]; then
1099 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
1100 return 1
1101 fi
1102
1103 queryparams=""
1104
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001105 if [ "$PMS_VERSION" == "V2" ]; then
1106 if [ $2 != "NORIC" ]; then
1107 queryparams="?ric_id="$2
1108 fi
1109
1110 if [ $3 != "NOSERVICE" ]; then
1111 if [ -z $queryparams ]; then
1112 queryparams="?service_id="$3
1113 else
1114 queryparams=$queryparams"&service_id="$3
1115 fi
1116 fi
1117 if [ $4 != "NOTYPE" ]; then
1118 if [ -z $queryparams ]; then
1119 queryparams="?policytype_id="$4
1120 else
1121 queryparams=$queryparams"&policytype_id="$4
1122 fi
1123 fi
1124
1125 query="/v2/policies"$queryparams
1126 else
1127 if [ $2 != "NORIC" ]; then
1128 queryparams="?ric="$2
1129 fi
1130
1131 if [ $3 != "NOSERVICE" ]; then
1132 if [ -z $queryparams ]; then
1133 queryparams="?service="$3
1134 else
1135 queryparams=$queryparams"&service="$3
1136 fi
1137 fi
1138 if [ $4 != "NOTYPE" ]; then
1139 if [ -z $queryparams ]; then
1140 queryparams="?type="$4
1141 else
1142 queryparams=$queryparams"&type="$4
1143 fi
1144 fi
1145
1146 query="/policy_ids"$queryparams
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001147 fi
1148
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001149 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001150 status=${res:${#res}-3}
1151
1152 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001153 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001154 return 1
1155 fi
1156
1157 if [ $# -gt 4 ]; then
1158 body=${res:0:${#res}-3}
1159 targetJson="["
1160
1161 for pid in ${@:5} ; do
1162 if [ "$targetJson" != "[" ]; then
1163 targetJson=$targetJson","
1164 fi
1165 if [ $pid != "NOID" ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +02001166 targetJson=$targetJson"\"$UUID$pid\""
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001167 fi
1168 done
1169
1170 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001171 if [ "$PMS_VERSION" == "V2" ]; then
1172 targetJson="{\"policy_ids\": $targetJson}"
1173 fi
1174 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1175 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1176
1177 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001178 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001179 return 1
1180 fi
1181 fi
1182
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001183 __log_test_pass
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001184 return 0
1185}
1186
1187# API Test function: V2 GET /v2/policy-types/{policyTypeId}
1188# args(V2): <response-code> <policy-type-id> [<schema-file>]
1189# (Function for test scripts)
1190api_get_policy_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001191 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001192
1193 if [ "$PMS_VERSION" != "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001194 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001195 return 1
1196 fi
1197
1198 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1199 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1200 return 1
1201 fi
1202 query="/v2/policy-types/$2"
1203
1204 res="$(__do_curl_to_api PA GET $query)"
1205 status=${res:${#res}-3}
1206
1207 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001208 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001209 return 1
1210 fi
1211
1212 if [ $# -eq 3 ]; then
1213
1214 body=${res:0:${#res}-3}
1215
1216 targetJson=$(< $3)
1217 targetJson="{\"policy_schema\":$targetJson}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001218 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001219 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001220
1221 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001222 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001223 return 1
1224 fi
1225 fi
1226
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001227 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001228 return 0
1229}
1230
1231# API Test function: GET /policy_schema
1232# args: <response-code> <policy-type-id> [<schema-file>]
1233# (Function for test scripts)
1234api_get_policy_schema() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001235 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001236
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001237 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001238 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001239 return 1
1240 fi
1241
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001242 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1243 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
1244 return 1
1245 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001246 query="/policy_schema?id=$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001247 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001248 status=${res:${#res}-3}
1249
1250 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001251 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001252 return 1
1253 fi
1254
1255 if [ $# -eq 3 ]; then
1256
1257 body=${res:0:${#res}-3}
1258
1259 targetJson=$(< $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001260
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001261 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001262 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001263
1264 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001265 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001266 return 1
1267 fi
1268 fi
1269
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001270 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001271 return 0
1272}
1273
1274# API Test function: GET /policy_schemas
1275# args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001276# args(V2): <response-code>
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001277# (Function for test scripts)
1278api_get_policy_schemas() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001279 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001280
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001281 if [ "$PMS_VERSION" == "V2" ]; then
1282 if [ $# -ne 1 ]; then
1283 __print_err "<response-code>" $@
1284 return 1
1285 fi
1286 else
1287 if [ $# -lt 2 ]; then
1288 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1289 return 1
1290 fi
1291 fi
1292 if [ "$PMS_VERSION" == "V2" ]; then
1293 query="/v2/policy-schemas"
1294 else
1295 query="/policy_schemas"
1296 if [ $2 != "NORIC" ]; then
1297 query=$query"?ric="$2
1298 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001299 fi
1300
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001301 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001302 status=${res:${#res}-3}
1303
1304 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001305 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001306 return 1
1307 fi
1308
1309 if [ $# -gt 2 ]; then
1310 body=${res:0:${#res}-3}
1311 targetJson="["
1312
1313 for file in ${@:3} ; do
1314 if [ "$targetJson" != "[" ]; then
1315 targetJson=$targetJson","
1316 fi
1317 if [ $file == "NOFILE" ]; then
1318 targetJson=$targetJson"{}"
1319 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001320 targetJson=$targetJson$(< $file)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001321 fi
1322 done
1323
1324 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001325 if [ "$PMS_VERSION" == "V2" ]; then
1326 targetJson="{\"policy_schemas\": $targetJson }"
1327 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001328 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001329 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001330
1331 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001332 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001333 return 1
1334 fi
1335 fi
1336
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001337 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001338 return 0
1339}
1340
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001341# API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001342# arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001343# (Function for test scripts)
1344api_get_policy_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001345 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001346
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001347 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001348 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001349 return 1
1350 fi
1351
1352 targetJson=""
1353
1354 if [ $3 == "STD" ]; then
1355 targetJson="{\"enforceStatus\":\"$4\""
1356 if [ $# -eq 5 ]; then
1357 targetJson=$targetJson",\"reason\":\"$5\""
1358 fi
1359 targetJson=$targetJson"}"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001360 elif [ $3 == "STD2" ]; then
1361 if [ $4 == "EMPTY" ]; then
1362 targetJson="{\"enforceStatus\":\"\""
1363 else
1364 targetJson="{\"enforceStatus\":\"$4\""
1365 fi
1366 if [ $# -eq 5 ]; then
1367 if [ $5 == "EMPTY" ]; then
1368 targetJson=$targetJson",\"enforceReason\":\"\""
1369 else
1370 targetJson=$targetJson",\"enforceReason\":\"$5\""
1371 fi
1372 fi
1373 targetJson=$targetJson"}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001374 elif [ $3 == "OSC" ]; then
1375 targetJson="{\"instance_status\":\"$4\""
1376 if [ $# -eq 5 ]; then
1377 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1378 fi
1379 targetJson=$targetJson",\"created_at\":\"????\"}"
1380 else
1381 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1382 return 1
1383 fi
1384
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001385 if [ "$PMS_VERSION" == "V2" ]; then
1386 query="/v2/policies/$UUID$2/status"
1387 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1388 else
1389 query="/policy_status?id="$UUID$2
1390 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001391
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001392 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001393 status=${res:${#res}-3}
1394
1395 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001396 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001397 return 1
1398 fi
1399
1400 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1401 body=${res:0:${#res}-3}
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001402 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001403
1404 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001405 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001406 return 1
1407 fi
1408
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001409 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001410 return 0
1411}
1412
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001413# API Test function: GET /policy_types and V2 GET /v2/policy-types
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001414# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1415# (Function for test scripts)
1416api_get_policy_types() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001417 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001418
1419 if [ $# -lt 1 ]; then
1420 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1421 return 1
1422 fi
1423
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001424 if [ "$PMS_VERSION" == "V2" ]; then
1425 if [ $# -eq 1 ]; then
1426 query="/v2/policy-types"
1427 elif [ $2 == "NORIC" ]; then
1428 query="/v2/policy-types"
1429 else
1430 query="/v2/policy-types?ric_id=$2"
1431 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001432 else
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001433 if [ $# -eq 1 ]; then
1434 query="/policy_types"
1435 elif [ $2 == "NORIC" ]; then
1436 query="/policy_types"
1437 else
1438 query="/policy_types?ric=$2"
1439 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001440 fi
1441
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001442 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001443 status=${res:${#res}-3}
1444
1445 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001446 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001447 return 1
1448 fi
1449
1450 if [ $# -gt 2 ]; then
1451 body=${res:0:${#res}-3}
1452 targetJson="["
1453
1454 for pid in ${@:3} ; do
1455 if [ "$targetJson" != "[" ]; then
1456 targetJson=$targetJson","
1457 fi
1458 if [ $pid == "EMPTY" ]; then
1459 pid=""
1460 fi
1461 targetJson=$targetJson"\"$pid\""
1462 done
1463
1464 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001465 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001466 targetJson="{\"policytype_ids\": $targetJson }"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001467 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001468 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001469 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001470
1471 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001472 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001473 return 1
1474 fi
1475 fi
1476
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001477 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001478 return 0
1479}
1480
1481#########################################################
1482#### Test case functions Health check
1483#########################################################
1484
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001485# API Test function: GET /status and V2 GET /status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001486# args: <response-code>
1487# (Function for test scripts)
1488api_get_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001489 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001490 if [ $# -ne 1 ]; then
1491 __print_err "<response-code>" $@
1492 return 1
1493 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001494 if [ "$PMS_VERSION" == "V2" ]; then
1495 query="/v2/status"
1496 else
1497 query="/status"
1498 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001499 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001500 status=${res:${#res}-3}
1501
1502 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001503 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001504 return 1
1505 fi
1506
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001507 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001508 return 0
1509}
1510
1511#########################################################
1512#### Test case functions RIC Repository
1513#########################################################
1514
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001515# API Test function: GET /ric and V2 GET /v2/rics/ric
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001516# args: <reponse-code> <management-element-id> [<ric-id>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001517# (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1518# (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1519# (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1520
1521
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001522# (Function for test scripts)
1523api_get_ric() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001524 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001525
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001526 if [ "$PMS_VERSION" == "V2" ]; then
1527 if [ $# -lt 3 ]; then
1528 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1529 return 1
1530 fi
1531 search=""
1532 if [ $2 != "NOME" ]; then
1533 search="?managed_element_id="$2
1534 fi
1535 if [ $3 != "NORIC" ]; then
1536 if [ -z $search ]; then
1537 search="?ric_id="$3
1538 else
1539 search=$search"&ric_id="$3
1540 fi
1541 fi
1542 query="/v2/rics/ric"$search
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001543
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001544 res="$(__do_curl_to_api PA GET $query)"
1545 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001546
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001547 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001548 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001549 return 1
1550 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001551
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001552 if [ $# -gt 3 ]; then
1553 body=${res:0:${#res}-3}
1554 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1555 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001556 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001557 return 1
1558 fi
1559
1560 targetJson=$(<./tmp/.tmp_rics.json)
1561 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1562 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1563 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1564 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001565 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001566 return 1
1567 fi
1568 fi
1569 else
1570 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1571 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1572 return 1
1573 fi
1574
1575 query="/ric?managedElementId="$2
1576
1577 res="$(__do_curl_to_api PA GET $query)"
1578 status=${res:${#res}-3}
1579
1580 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001581 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001582 return 1
1583 fi
1584
1585 if [ $# -eq 3 ]; then
1586 body=${res:0:${#res}-3}
1587 if [ "$body" != "$3" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001588 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001589 return 1
1590 fi
1591 fi
1592 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001593 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001594 return 0
1595}
1596
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001597# API test function: GET /rics and V2 GET /v2/rics
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001598# args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1599# 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_........."
1600# format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1601# (Function for test scripts)
1602api_get_rics() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001603 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001604
1605 if [ $# -lt 2 ]; then
1606 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1607 return 1
1608 fi
1609
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001610 if [ "$PMS_VERSION" == "V2" ]; then
1611 query="/v2/rics"
1612 if [ $2 != "NOTYPE" ]; then
1613 query="/v2/rics?policytype_id="$2
1614 fi
1615 else
1616 query="/rics"
1617 if [ $2 != "NOTYPE" ]; then
1618 query="/rics?policyType="$2
1619 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001620 fi
1621
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001622 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001623 status=${res:${#res}-3}
1624
1625 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001626 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001627 return 1
1628 fi
1629
1630 if [ $# -gt 2 ]; then
1631 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001632 if [ "$PMS_VERSION" == "V2" ]; then
1633 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1634 else
1635 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1636 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001637 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001638 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001639 return 1
1640 fi
1641
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001642 targetJson=$(<./tmp/.tmp_rics.json)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001643 if [ "$PMS_VERSION" == "V2" ]; then
1644 targetJson="{\"rics\": $targetJson }"
1645 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001646 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001647 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001648 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001649 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001650 return 1
1651 fi
1652 fi
1653
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001654 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001655 return 0
1656}
1657
1658##################################################################
1659#### API Test case functions Service registry and supervision ####
1660##################################################################
1661
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001662# API test function: PUT /service and V2 PUT /service
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001663# args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1664# (Function for test scripts)
1665api_put_service() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001666 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001667 if [ $# -ne 4 ]; then
1668 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1669 return 1
1670 fi
1671
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001672 if [ "$PMS_VERSION" == "V2" ]; then
1673 query="/v2/services"
1674 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1675 else
1676 query="/service"
1677 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1678 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001679 file="./tmp/.tmp.json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001680 echo "$json" > $file
1681
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001682 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001683 status=${res:${#res}-3}
1684
1685 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001686 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001687 return 1
1688 fi
1689
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001690 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001691 return 0
1692}
1693
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001694# API test function: GET /services and V2 GET /v2/services
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001695#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>]* )]
1696# (Function for test scripts)
1697api_get_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001698 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001699 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1700 paramError=1
1701 if [ $# -eq 1 ]; then
1702 paramError=0
1703 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1704 paramError=0
1705 elif [ $# -eq 5 ]; then
1706 paramError=0
1707 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1708 argLen=$(($#-2))
1709 if [ $(($argLen%3)) -eq 0 ]; then
1710 paramError=0
1711 fi
1712 fi
1713
1714 if [ $paramError -ne 0 ]; then
1715 __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>]* )]" $@
1716 return 1
1717 fi
1718
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001719 if [ "$PMS_VERSION" == "V2" ]; then
1720 query="/v2/services"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001721
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001722 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1723 query="/v2/services?service_id="$2
1724 fi
1725 else
1726 query="/services"
1727
1728 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1729 query="/services?name="$2
1730 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001731 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001732 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001733 status=${res:${#res}-3}
1734
1735 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001736 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001737 return 1
1738 fi
1739
1740 if [ $# -gt 2 ]; then
1741 variableArgCount=$(($#-2))
1742 body=${res:0:${#res}-3}
1743 targetJson="["
1744 shift; shift;
1745 cntr=0
1746 while [ $cntr -lt $variableArgCount ]; do
1747 servicename=$1; shift;
1748 timeout=$1; shift;
1749 callback=$1; shift;
1750 if [ $cntr -gt 0 ]; then
1751 targetJson=$targetJson","
1752 fi
1753 # timeSinceLastActivitySeconds value cannot be checked since value varies
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001754 if [ "$PMS_VERSION" == "V2" ]; then
1755 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1756 else
1757 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1758 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001759 let cntr=cntr+3
1760 done
1761 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001762 if [ "$PMS_VERSION" == "V2" ]; then
1763 targetJson="{\"service_list\": $targetJson }"
1764 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001765 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001766 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001767 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001768 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001769 return 1
1770 fi
1771 fi
1772
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001773 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001774 return 0
1775}
1776
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001777# API test function: GET /services V2 GET /v2/services - (only checking service names)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001778# args: <response-code> [<service-name>]*"
1779# (Function for test scripts)
1780api_get_service_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001781 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001782
1783 if [ $# -lt 1 ]; then
1784 __print_err "<response-code> [<service-name>]*" $@
1785 return 1
1786 fi
1787
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001788 if [ "$PMS_VERSION" == "V2" ]; then
1789 query="/v2/services"
1790 else
1791 query="/services"
1792 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001793 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001794 status=${res:${#res}-3}
1795
1796 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001797 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001798 return 1
1799 fi
1800
1801 body=${res:0:${#res}-3}
1802 targetJson="["
1803 for rapp in ${@:2} ; do
1804 if [ "$targetJson" != "[" ]; then
1805 targetJson=$targetJson","
1806 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001807 if [ "$PMS_VERSION" == "V2" ]; then
1808 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
1809 else
1810 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1811 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001812 done
1813
1814 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001815 if [ "$PMS_VERSION" == "V2" ]; then
1816 targetJson="{\"service_list\": $targetJson }"
1817 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001818 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001819 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001820
1821 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001822 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001823 return 1
1824 fi
1825
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001826 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001827 return 0
1828}
1829
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001830# API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001831# args: <response-code> <service-name>
1832# (Function for test scripts)
1833api_delete_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001834 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001835
1836 if [ $# -ne 2 ]; then
1837 __print_err "<response-code> <service-name>" $@
1838 return 1
1839 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001840 if [ "$PMS_VERSION" == "V2" ]; then
1841 query="/v2/services/"$2
1842 else
1843 query="/services?name="$2
1844 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001845 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001846 status=${res:${#res}-3}
1847
1848 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001849 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001850 return 1
1851 fi
1852
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001853 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001854 return 0
1855}
1856
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001857# API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001858# args: <response-code> <service-name>
1859# (Function for test scripts)
1860api_put_services_keepalive() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001861 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001862
1863 if [ $# -ne 2 ]; then
1864 __print_err "<response-code> <service-name>" $@
1865 return 1
1866 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001867 if [ "$PMS_VERSION" == "V2" ]; then
1868 query="/v2/services/$2/keepalive"
1869 else
1870 query="/services/keepalive?name="$2
1871 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001872
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001873 res="$(__do_curl_to_api PA PUT $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001874 status=${res:${#res}-3}
1875
1876 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001877 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001878 return 1
1879 fi
1880
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001881 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001882 return 0
1883}
1884
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001885##################################################################
1886#### API Test case functions Configuration ####
1887##################################################################
1888
1889# API Test function: PUT /v2/configuration
1890# args: <response-code> <config-file>
1891# (Function for test scripts)
1892api_put_configuration() {
1893 __log_test_start $@
1894
1895 if [ "$PMS_VERSION" != "V2" ]; then
1896 __log_test_fail_not_supported
1897 return 1
1898 fi
1899
1900 if [ $# -ne 2 ]; then
1901 __print_err "<response-code> <config-file>" $@
1902 return 1
1903 fi
1904 if [ ! -f $2 ]; then
1905 _log_test_fail_general "Config file "$2", does not exist"
1906 return 1
1907 fi
1908 inputJson=$(< $2)
1909 inputJson="{\"config\":"$inputJson"}"
1910 file="./tmp/.config.json"
1911 echo $inputJson > $file
1912 query="/v2/configuration"
1913 res="$(__do_curl_to_api PA PUT $query $file)"
1914 status=${res:${#res}-3}
1915
1916 if [ $status -ne $1 ]; then
1917 __log_test_fail_status_code $1 $status
1918 return 1
1919 fi
1920
1921 __log_test_pass
1922 return 0
1923}
1924
1925# API Test function: GET /v2/configuration
1926# args: <response-code> [<config-file>]
1927# (Function for test scripts)
1928api_get_configuration() {
1929 __log_test_start $@
1930
1931 if [ "$PMS_VERSION" != "V2" ]; then
1932 __log_test_fail_not_supported
1933 return 1
1934 fi
1935
1936 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
1937 __print_err "<response-code> [<config-file>]" $@
1938 return 1
1939 fi
1940 if [ ! -f $2 ]; then
1941 _log_test_fail_general "Config file "$2" for comparison, does not exist"
1942 return 1
1943 fi
1944
1945 query="/v2/configuration"
1946 res="$(__do_curl_to_api PA GET $query)"
1947 status=${res:${#res}-3}
1948
1949 if [ $status -ne $1 ]; then
1950 __log_test_fail_status_code $1 $status
1951 return 1
1952 fi
1953
1954 if [ $# -eq 2 ]; then
1955
1956 body=${res:0:${#res}-3}
1957
1958 targetJson=$(< $2)
1959 targetJson="{\"config\":"$targetJson"}"
1960 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1961 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1962
1963 if [ $res -ne 0 ]; then
1964 __log_test_fail_body
1965 return 1
1966 fi
1967 fi
1968
1969 __log_test_pass
1970 return 0
1971}