blob: fbd9fc49efc125a0e7af89759cf6aea89cbc4693 [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
20# This is a script that contains specific test functions for Policy Agent API
21
22### API functiond towards the Policy Agent
23
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020024. ../common/api_curl.sh
BjornMagnussonXA80a92002020-03-19 14:31:06 +010025
26#########################################################
27#### Test case functions A1 Policy management service
28#########################################################
29
30# This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent.
31# This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL
32# args: json:<url> <target-value> [<timeout-in-seconds]
33# (Function for test scripts)
34api_equal() {
35 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
36 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
37 if [[ $1 == "json:"* ]]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +010038 if [ "$PMS_VERSION" == "V2" ]; then
39 __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/v2/" $1 "=" $2 $3
40 else
41 __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/" $1 "=" $2 $3
42 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +010043 return 0
44 fi
45 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +010046 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
47 return 1
48}
49
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010050# API Test function: GET /policies and V2 GET /v2/policy-instances
BjornMagnussonXA4207b832020-11-03 09:52:49 +010051# 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>]*]
52# 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 +010053# (Function for test scripts)
54api_get_policies() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +010055 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +010056
57 if [ "$PMS_VERSION" == "V2" ]; then
58 paramError=0
59 variableParams=$(($#-4))
60 if [ $# -lt 4 ]; then
61 paramError=1
62 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
63 paramError=1
64 elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then
65 paramError=1
66 fi
67
68 if [ $paramError -ne 0 ]; then
69 __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>]*]" $@
70 return 1
71 fi
72 else
73 paramError=0
74 variableParams=$(($#-4))
75 if [ $# -lt 4 ]; then
76 paramError=1
77 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
78 paramError=1
79 elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then
80 paramError=1
81 fi
82
83 if [ $paramError -ne 0 ]; then
84 __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>]*]" $@
85 return 1
86 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +010087 fi
88
BjornMagnussonXA80a92002020-03-19 14:31:06 +010089 queryparams=""
BjornMagnussonXA4207b832020-11-03 09:52:49 +010090 if [ "$PMS_VERSION" == "V2" ]; then
91 if [ $2 != "NORIC" ]; then
92 queryparams="?ric_id="$2
BjornMagnussonXA80a92002020-03-19 14:31:06 +010093 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +010094 if [ $3 != "NOSERVICE" ]; then
95 if [ -z $queryparams ]; then
96 queryparams="?service_id="$3
97 else
98 queryparams=$queryparams"&service_id="$3
99 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100100 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100101 if [ $4 != "NOTYPE" ]; then
102 if [ -z $queryparams ]; then
103 queryparams="?policytype_id="$4
104 else
105 queryparams=$queryparams"&policytype_id="$4
106 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100107 fi
108
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100109 query="/v2/policy-instances"$queryparams
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100110 res="$(__do_curl_to_api PA GET $query)"
111 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100112
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100113 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100114 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100115 return 1
116 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100117
118 if [ $# -gt 4 ]; then
119 body=${res:0:${#res}-3}
120 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
121 targetJson="["
122 else
123 targetJson="["
124 arr=(${@:5})
125
126 for ((i=0; i<$(($#-4)); i=i+7)); do
127
128 if [ "$targetJson" != "[" ]; then
129 targetJson=$targetJson","
130 fi
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100131 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 +0100132 if [ "${arr[$i+3]}" == "EMPTY" ]; then
133 targetJson=$targetJson"\"\","
134 else
135 targetJson=$targetJson"\"${arr[$i+3]}\","
136 fi
137 targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\","
138 file="./tmp/.p.json"
139 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file
140 json=$(cat $file)
141 targetJson=$targetJson"\"policy_data\":"$json"}"
142 done
143 fi
144
145 targetJson=$targetJson"]"
146 targetJson="{\"policies\": $targetJson}"
147 echo "TARGET JSON: $targetJson" >> $HTTPLOG
148 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
149
150 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100151 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100152 return 1
153 fi
154 fi
155 else
156 if [ $2 != "NORIC" ]; then
157 queryparams="?ric="$2
158 fi
159 if [ $3 != "NOSERVICE" ]; then
160 if [ -z $queryparams ]; then
161 queryparams="?service="$3
162 else
163 queryparams=$queryparams"&service="$3
164 fi
165 fi
166 if [ $4 != "NOTYPE" ]; then
167 if [ -z $queryparams ]; then
168 queryparams="?type="$4
169 else
170 queryparams=$queryparams"&type="$4
171 fi
172 fi
173
174 query="/policies"$queryparams
175 res="$(__do_curl_to_api PA GET $query)"
176 status=${res:${#res}-3}
177
178 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100179 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100180 return 1
181 fi
182
183 if [ $# -gt 4 ]; then
184 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
185 targetJson="["
186 else
187 body=${res:0:${#res}-3}
188 targetJson="["
189 arr=(${@:5})
190
191 for ((i=0; i<$(($#-4)); i=i+5)); do
192
193 if [ "$targetJson" != "[" ]; then
194 targetJson=$targetJson","
195 fi
196 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
197 if [ "${arr[$i+3]}" == "EMPTY" ]; then
198 targetJson=$targetJson"\"\","
199 else
200 targetJson=$targetJson"\"${arr[$i+3]}\","
201 fi
202 file="./tmp/.p.json"
203 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
204 json=$(cat $file)
205 targetJson=$targetJson"\"json\":"$json"}"
206 done
207 fi
208
209 targetJson=$targetJson"]"
210 echo "TARGET JSON: $targetJson" >> $HTTPLOG
211 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
212
213 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100214 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100215 return 1
216 fi
217 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100218 fi
219
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100220 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100221 return 0
222
223}
224
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100225
226# API Test function: GET /policy and V2 GET /v2/policies/{policy_id}
227# args: <response-code> <policy-id> [<template-file>]
228# args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]
229
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100230# (Function for test scripts)
231api_get_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100232 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100233
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100234
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100235 if [ "$PMS_VERSION" == "V2" ]; then
236 if [ $# -ne 2 ] && [ $# -ne 8 ]; then
237 __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@
238 return 1
239 fi
240 query="/v2/policies/$UUID$2"
241 else
242 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
243 __print_err "<response-code> <policy-id> [<template-file>] " $@
244 return 1
245 fi
246 query="/policy?id=$UUID$2"
247 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200248 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100249 status=${res:${#res}-3}
250
251 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100252 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100253 return 1
254 fi
255
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100256 if [ "$PMS_VERSION" == "V2" ]; then
257 if [ $# -eq 8 ]; then
258
259 #Create a policy json to compare with
260 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100261
262 targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\""
263 if [ $7 != "NOTRANSIENT" ]; then
264 targetJson=$targetJson", \"transient\":$7"
265 fi
266 if [ $6 != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100267 targetJson=$targetJson", \"policytype_id\":\"$6\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100268 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100269 targetJson=$targetJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100270 fi
271 if [ $8 != "NOURL" ]; then
272 targetJson=$targetJson", \"status_notification_uri\":\"$8\""
273 fi
274
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100275 data=$(sed 's/XXX/'${2}'/g' $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100276 targetJson=$targetJson", \"policy_data\":$data"
277 targetJson="{$targetJson}"
278
279 echo "TARGET JSON: $targetJson" >> $HTTPLOG
280 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
281 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100282 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100283 return 1
284 fi
285 fi
286 else
287 if [ $# -eq 3 ]; then
288 #Create a policy json to compare with
289 body=${res:0:${#res}-3}
290 file="./tmp/.p.json"
291 sed 's/XXX/'${2}'/g' $3 > $file
292 targetJson=$(< $file)
293 echo "TARGET JSON: $targetJson" >> $HTTPLOG
294 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
295 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100296 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100297 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100298 fi
299 fi
300
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100301 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100302 return 0
303}
304
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100305# API Test function: PUT /policy and V2 PUT /policies
306# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]
307# 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 +0100308# (Function for test scripts)
309api_put_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100310 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100311
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100312 if [ "$PMS_VERSION" == "V2" ]; then
313 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
314 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@
315 return 1
316 fi
317 else
318 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
319 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
320 return 1
321 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100322 fi
323
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100324 count=0
325 max=1
326 serv=$2
327 ric=$3
328 pt=$4
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100329 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100330 trans=$6
331
332 if [ "$PMS_VERSION" == "V2" ]; then
333 noti=$7
334 temp=$8
335 if [ $# -eq 9 ]; then
336 max=$9
337 fi
338 else
339 temp=$7
340 if [ $# -eq 8 ]; then
341 max=$8
342 fi
343 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100344
345 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100346 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100347
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100348 query="/v2/policies"
349
350 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
351 if [ $trans != "NOTRANSIENT" ]; then
352 inputJson=$inputJson", \"transient\":$trans"
353 fi
354 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100355 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100356 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100357 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100358 fi
359 if [ $noti != "NOURL" ]; then
360 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
361 fi
362 file="./tmp/.p.json"
363 data=$(sed 's/XXX/'${pid}'/g' $temp)
364 inputJson=$inputJson", \"policy_data\":$data"
365 inputJson="{$inputJson}"
366 echo $inputJson > $file
367 else
368 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
369
370 if [ $pt != "NOTYPE" ]; then
371 query=$query"&type=$pt"
372 fi
373
374 if [ $trans != NOTRANSIENT ]; then
375 query=$query"&transient=$trans"
376 fi
377
378 file="./tmp/.p.json"
379 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200380 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200381 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100382 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200383 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100384 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200385 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100386 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100387 return 1
388 fi
389
390 let pid=$pid+1
391 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200392 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100393 done
394 echo ""
395
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100396 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100397 return 0
398}
399
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100400# API Test function: PUT /policy and V2 PUT /policies, to run in batch
401# args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]
402# 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 +0200403# (Function for test scripts)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100404
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200405api_put_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100406 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200407
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100408 if [ "$PMS_VERSION" == "V2" ]; then
409 if [ $# -lt 8 ] || [ $# -gt 9 ]; then
410 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@
411 return 1
412 fi
413 else
414 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
415 __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@
416 return 1
417 fi
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200418 fi
419
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100420 count=0
421 max=1
422 serv=$2
423 ric=$3
424 pt=$4
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200425 pid=$5
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100426 trans=$6
427 if [ "$PMS_VERSION" == "V2" ]; then
428 noti=$7
429 temp=$8
430 if [ $# -eq 9 ]; then
431 max=$9
432 fi
433 else
434 temp=$7
435 if [ $# -eq 8 ]; then
436 max=$8
437 fi
438 fi
439
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200440 ARR=""
441 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100442 if [ "$PMS_VERSION" == "V2" ]; then
443 query="/v2/policies"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200444
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100445 inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\""
446 if [ $trans != "NOTRANSIENT" ]; then
447 inputJson=$inputJson", \"transient\":$trans"
448 fi
449 if [ $pt != "NOTYPE" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100450 inputJson=$inputJson", \"policytype_id\":\"$pt\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100451 else
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100452 inputJson=$inputJson", \"policytype_id\":\"\""
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100453 fi
454 if [ $noti != "NOURL" ]; then
455 inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
456 fi
457 file="./tmp/.p.json"
458 data=$(sed 's/XXX/'${pid}'/g' $temp)
459 inputJson=$inputJson", \"policy_data\":$data"
460 inputJson="{$inputJson}"
461 echo $inputJson > $file
462 else
463 query="/policy?id=$UUID$pid&ric=$ric&service=$serv"
464
465 if [ $pt != "NOTYPE" ]; then
466 query=$query"&type=$pt"
467 fi
468
469 if [ $trans != NOTRANSIENT ]; then
470 query=$query"&transient=$trans"
471 fi
472 file="./tmp/.p.json"
473 sed 's/XXX/'${pid}'/g' $temp > $file
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200474 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200475 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200476 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200477 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200478
479 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200480 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100481 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200482 return 1
483 fi
484 cid=${res:0:${#res}-3}
485 ARR=$ARR" "$cid
486 let pid=$pid+1
487 let count=$count+1
488 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
489 done
490
491 echo ""
492 count=0
493 for cid in $ARR; do
494
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200495 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200496 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100497 echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200498
499 if [ $status -ne $1 ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100500 echo " Accepted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100501 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200502 return 1
503 fi
504
505 let count=$count+1
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100506 echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200507 done
508
509 echo ""
510
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100511 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200512 return 0
513}
514
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100515# 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 +0200516# 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 +0100517# 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 +0200518# (Function for test scripts)
519api_put_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100520 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200521
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100522 if [ "$PMS_VERSION" == "V2" ]; then
523 if [ $# -ne 11 ]; then
524 __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>" $@
525 return 1
526 fi
527 else
528 if [ $# -ne 10 ]; then
529 __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>" $@
530 return 1
531 fi
532 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200533 resp_code=$1; shift;
534 serv=$1; shift
535 ric_base=$1; shift;
536 num_rics=$1; shift;
537 type=$1; shift;
538 start_id=$1; shift;
539 transient=$1; shift;
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100540 if [ "$PMS_VERSION" == "V2" ]; then
541 noti=$1; shift;
542 else
543 noti=""
544 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200545 template=$1; shift;
546 count=$1; shift;
547 pids=$1; shift;
548
549 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
550 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
551 echo " Info - will execute over agent REST"
552 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100553 if [ "$PMS_VERSION" == "V2" ]; then
554 if [ $serv == "NOSERVICE" ]; then
555 serv=""
556 fi
557 query="/v2/policies"
558 else
559 if [ $serv == "NOSERVICE" ]; then
560 serv=""
561 fi
562 query="/policy?service=$serv"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200563
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100564 if [ $type != "NOTYPE" ]; then
565 query=$query"&type=$type"
566 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200567
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100568 if [ $transient != NOTRANSIENT ]; then
569 query=$query"&transient=$transient"
570 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200571 fi
572
573 urlbase=${ADAPTER}${query}
574
575 for ((i=1; i<=$pids; i++))
576 do
BjornMagnussonXAad047782020-06-08 15:54:11 +0200577 uuid=$UUID
578 if [ -z "$uuid" ]; then
579 uuid="NOUUID"
580 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200581 echo "" > "./tmp/.pid${i}.res.txt"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100582 if [ "$PMS_VERSION" == "V2" ]; then
583 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i > "./tmp/.pid${i}.txt"
584 else
585 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt"
586 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200587 echo $i
588 done | xargs -n 1 -I{} -P $pids bash -c '{
589 arg=$(echo {})
590 echo " Parallel process $arg started"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200591 tmp=$(< "./tmp/.pid${arg}.txt")
592 python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200593 }'
594 msg=""
595 for ((i=1; i<=$pids; i++))
596 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200597 file="./tmp/.pid${i}.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200598 tmp=$(< $file)
599 if [ -z "$tmp" ]; then
600 echo " Process $i : unknown result (result file empty"
601 msg="failed"
602 else
603 res=${tmp:0:1}
604 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100605 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200606 else
607 echo " Process $i : failed - "${tmp:1}
608 msg="failed"
609 fi
610 fi
611 done
612 if [ -z $msg ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100613 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200614 return 0
615 fi
616
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100617 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200618 return 1
619}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100620
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100621# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100622# args: <response-code> <policy-id> [count]
623# (Function for test scripts)
624api_delete_policy() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100625 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100626
627 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
628 __print_err "<response-code> <policy-id> [count]" $@
629 return 1
630 fi
631
632 count=0
633 max=1
634
635 if [ $# -eq 3 ]; then
636 max=$3
637 fi
638
639 pid=$2
640
641 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100642 if [ "$PMS_VERSION" == "V2" ]; then
643 query="/v2/policies/"$UUID$pid
644 else
645 query="/policy?id="$UUID$pid
646 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200647 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100648 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200649 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100650
651 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200652 echo " Executed "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100653 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100654 return 1
655 fi
656 let pid=$pid+1
657 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200658 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100659 done
660 echo ""
661
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100662 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100663 return 0
664}
665
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100666# API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200667# args: <response-code> <policy-id> [count]
668# (Function for test scripts)
669api_delete_policy_batch() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100670 __log_test_start $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200671
672 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
673 __print_err "<response-code> <policy-id> [count]" $@
674 return 1
675 fi
676
677 count=0
678 max=1
679
680 if [ $# -eq 3 ]; then
681 max=$3
682 fi
683
684 pid=$2
685 ARR=""
686 while [ $count -lt $max ]; do
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100687 if [ "$PMS_VERSION" == "V2" ]; then
688 query="/v2/policies/"$UUID$pid
689 else
690 query="/policy?id="$UUID$pid
691 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200692 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200693 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200694 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200695
696 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200697 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100698 __log_test_fail_status_code 200 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200699 return 1
700 fi
701 cid=${res:0:${#res}-3}
702 ARR=$ARR" "$cid
703 let pid=$pid+1
704 let count=$count+1
705 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
706 done
707
708 echo ""
709
710 count=0
711 for cid in $ARR; do
712
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200713 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200714 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100715 echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200716
717 if [ $status -ne $1 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200718 echo " Deleted(batch) "$count"?("$max")"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100719 __log_test_fail_status_code $1 $status
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200720 return 1
721 fi
722
723 let count=$count+1
724 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
725 done
726
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100727 echo ""
728
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100729 __log_test_pass
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200730 return 0
731}
732
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100733# 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 +0200734# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
735# (Function for test scripts)
736api_delete_policy_parallel() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100737 __log_test_start $@
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200738
739 if [ $# -ne 5 ]; then
740 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
741 return 1
742 fi
743 resp_code=$1; shift;
744 num_rics=$1; shift;
745 start_id=$1; shift;
746 count=$1; shift;
747 pids=$1; shift;
748
749 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
750 echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
751 echo " Info - will execute over agent REST"
752 fi
753
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100754 if [ "$PMS_VERSION" == "V2" ]; then
755 query="/v2/policies/"
756 else
757 query="/policy"
758 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200759
760 urlbase=${ADAPTER}${query}
761
762 for ((i=1; i<=$pids; i++))
763 do
BjornMagnussonXAad047782020-06-08 15:54:11 +0200764 uuid=$UUID
765 if [ -z "$uuid" ]; then
766 uuid="NOUUID"
767 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200768 echo "" > "./tmp/.pid${i}.del.res.txt"
769 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > "./tmp/.pid${i}.del.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200770 echo $i
771 done | xargs -n 1 -I{} -P $pids bash -c '{
772 arg=$(echo {})
773 echo " Parallel process $arg started"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100774 tmp=$(< "./tmp/.pid${arg}.del.txt")
775 python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200776 }'
777 msg=""
778 for ((i=1; i<=$pids; i++))
779 do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200780 file="./tmp/.pid${i}.del.res.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200781 tmp=$(< $file)
782 if [ -z "$tmp" ]; then
783 echo " Process $i : unknown result (result file empty"
784 msg="failed"
785 else
786 res=${tmp:0:1}
787 if [ $res == "0" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100788 echo " Process $i : OK - "${tmp:1}
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200789 else
790 echo " Process $i : failed - "${tmp:1}
791 msg="failed"
792 fi
793 fi
794 done
795 if [ -z $msg ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100796 __log_test_pass " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200797 return 0
798 fi
799
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100800 __log_test_fail_general "One of more processes failed to execute"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200801 return 1
802}
803
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100804# API Test function: GET /policy_ids and V2 GET /v2/policies
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100805# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
806# (Function for test scripts)
807api_get_policy_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100808 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100809
810 if [ $# -lt 4 ]; then
811 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
812 return 1
813 fi
814
815 queryparams=""
816
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100817 if [ "$PMS_VERSION" == "V2" ]; then
818 if [ $2 != "NORIC" ]; then
819 queryparams="?ric_id="$2
820 fi
821
822 if [ $3 != "NOSERVICE" ]; then
823 if [ -z $queryparams ]; then
824 queryparams="?service_id="$3
825 else
826 queryparams=$queryparams"&service_id="$3
827 fi
828 fi
829 if [ $4 != "NOTYPE" ]; then
830 if [ -z $queryparams ]; then
831 queryparams="?policytype_id="$4
832 else
833 queryparams=$queryparams"&policytype_id="$4
834 fi
835 fi
836
837 query="/v2/policies"$queryparams
838 else
839 if [ $2 != "NORIC" ]; then
840 queryparams="?ric="$2
841 fi
842
843 if [ $3 != "NOSERVICE" ]; then
844 if [ -z $queryparams ]; then
845 queryparams="?service="$3
846 else
847 queryparams=$queryparams"&service="$3
848 fi
849 fi
850 if [ $4 != "NOTYPE" ]; then
851 if [ -z $queryparams ]; then
852 queryparams="?type="$4
853 else
854 queryparams=$queryparams"&type="$4
855 fi
856 fi
857
858 query="/policy_ids"$queryparams
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100859 fi
860
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200861 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100862 status=${res:${#res}-3}
863
864 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100865 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100866 return 1
867 fi
868
869 if [ $# -gt 4 ]; then
870 body=${res:0:${#res}-3}
871 targetJson="["
872
873 for pid in ${@:5} ; do
874 if [ "$targetJson" != "[" ]; then
875 targetJson=$targetJson","
876 fi
877 if [ $pid != "NOID" ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +0200878 targetJson=$targetJson"\"$UUID$pid\""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100879 fi
880 done
881
882 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100883 if [ "$PMS_VERSION" == "V2" ]; then
884 targetJson="{\"policy_ids\": $targetJson}"
885 fi
886 echo "TARGET JSON: $targetJson" >> $HTTPLOG
887 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
888
889 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100890 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100891 return 1
892 fi
893 fi
894
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100895 __log_test_pass
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100896 return 0
897}
898
899# API Test function: V2 GET /v2/policy-types/{policyTypeId}
900# args(V2): <response-code> <policy-type-id> [<schema-file>]
901# (Function for test scripts)
902api_get_policy_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100903 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100904
905 if [ "$PMS_VERSION" != "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100906 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100907 return 1
908 fi
909
910 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
911 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
912 return 1
913 fi
914 query="/v2/policy-types/$2"
915
916 res="$(__do_curl_to_api PA GET $query)"
917 status=${res:${#res}-3}
918
919 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100920 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100921 return 1
922 fi
923
924 if [ $# -eq 3 ]; then
925
926 body=${res:0:${#res}-3}
927
928 targetJson=$(< $3)
929 targetJson="{\"policy_schema\":$targetJson}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100930 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200931 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100932
933 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100934 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100935 return 1
936 fi
937 fi
938
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100939 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100940 return 0
941}
942
943# API Test function: GET /policy_schema
944# args: <response-code> <policy-type-id> [<schema-file>]
945# (Function for test scripts)
946api_get_policy_schema() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100947 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100948
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100949 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100950 __log_test_fail_not_supported
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100951 return 1
952 fi
953
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100954 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
955 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
956 return 1
957 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100958 query="/policy_schema?id=$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200959 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100960 status=${res:${#res}-3}
961
962 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100963 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100964 return 1
965 fi
966
967 if [ $# -eq 3 ]; then
968
969 body=${res:0:${#res}-3}
970
971 targetJson=$(< $3)
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100972
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100973 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200974 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100975
976 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100977 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100978 return 1
979 fi
980 fi
981
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100982 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100983 return 0
984}
985
986# API Test function: GET /policy_schemas
987# args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100988# args(V2): <response-code>
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100989# (Function for test scripts)
990api_get_policy_schemas() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100991 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100992
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100993 if [ "$PMS_VERSION" == "V2" ]; then
994 if [ $# -ne 1 ]; then
995 __print_err "<response-code>" $@
996 return 1
997 fi
998 else
999 if [ $# -lt 2 ]; then
1000 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
1001 return 1
1002 fi
1003 fi
1004 if [ "$PMS_VERSION" == "V2" ]; then
1005 query="/v2/policy-schemas"
1006 else
1007 query="/policy_schemas"
1008 if [ $2 != "NORIC" ]; then
1009 query=$query"?ric="$2
1010 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001011 fi
1012
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001013 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001014 status=${res:${#res}-3}
1015
1016 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001017 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001018 return 1
1019 fi
1020
1021 if [ $# -gt 2 ]; then
1022 body=${res:0:${#res}-3}
1023 targetJson="["
1024
1025 for file in ${@:3} ; do
1026 if [ "$targetJson" != "[" ]; then
1027 targetJson=$targetJson","
1028 fi
1029 if [ $file == "NOFILE" ]; then
1030 targetJson=$targetJson"{}"
1031 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001032 targetJson=$targetJson$(< $file)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001033 fi
1034 done
1035
1036 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001037 if [ "$PMS_VERSION" == "V2" ]; then
1038 targetJson="{\"policy_schemas\": $targetJson }"
1039 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001040 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001041 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001042
1043 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001044 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001045 return 1
1046 fi
1047 fi
1048
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001049 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001050 return 0
1051}
1052
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001053# API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001054# arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001055# (Function for test scripts)
1056api_get_policy_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001057 __log_test_start $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001058
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001059 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001060 __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001061 return 1
1062 fi
1063
1064 targetJson=""
1065
1066 if [ $3 == "STD" ]; then
1067 targetJson="{\"enforceStatus\":\"$4\""
1068 if [ $# -eq 5 ]; then
1069 targetJson=$targetJson",\"reason\":\"$5\""
1070 fi
1071 targetJson=$targetJson"}"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001072 elif [ $3 == "STD2" ]; then
1073 if [ $4 == "EMPTY" ]; then
1074 targetJson="{\"enforceStatus\":\"\""
1075 else
1076 targetJson="{\"enforceStatus\":\"$4\""
1077 fi
1078 if [ $# -eq 5 ]; then
1079 if [ $5 == "EMPTY" ]; then
1080 targetJson=$targetJson",\"enforceReason\":\"\""
1081 else
1082 targetJson=$targetJson",\"enforceReason\":\"$5\""
1083 fi
1084 fi
1085 targetJson=$targetJson"}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001086 elif [ $3 == "OSC" ]; then
1087 targetJson="{\"instance_status\":\"$4\""
1088 if [ $# -eq 5 ]; then
1089 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
1090 fi
1091 targetJson=$targetJson",\"created_at\":\"????\"}"
1092 else
1093 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
1094 return 1
1095 fi
1096
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001097 if [ "$PMS_VERSION" == "V2" ]; then
1098 query="/v2/policies/$UUID$2/status"
1099 targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}"
1100 else
1101 query="/policy_status?id="$UUID$2
1102 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001103
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001104 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001105 status=${res:${#res}-3}
1106
1107 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001108 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001109 return 1
1110 fi
1111
1112 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1113 body=${res:0:${#res}-3}
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001114 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001115
1116 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001117 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001118 return 1
1119 fi
1120
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001121 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001122 return 0
1123}
1124
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001125# API Test function: GET /policy_types and V2 GET /v2/policy-types
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001126# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
1127# (Function for test scripts)
1128api_get_policy_types() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001129 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001130
1131 if [ $# -lt 1 ]; then
1132 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
1133 return 1
1134 fi
1135
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001136 if [ "$PMS_VERSION" == "V2" ]; then
1137 if [ $# -eq 1 ]; then
1138 query="/v2/policy-types"
1139 elif [ $2 == "NORIC" ]; then
1140 query="/v2/policy-types"
1141 else
1142 query="/v2/policy-types?ric_id=$2"
1143 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001144 else
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001145 if [ $# -eq 1 ]; then
1146 query="/policy_types"
1147 elif [ $2 == "NORIC" ]; then
1148 query="/policy_types"
1149 else
1150 query="/policy_types?ric=$2"
1151 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001152 fi
1153
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001154 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001155 status=${res:${#res}-3}
1156
1157 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001158 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001159 return 1
1160 fi
1161
1162 if [ $# -gt 2 ]; then
1163 body=${res:0:${#res}-3}
1164 targetJson="["
1165
1166 for pid in ${@:3} ; do
1167 if [ "$targetJson" != "[" ]; then
1168 targetJson=$targetJson","
1169 fi
1170 if [ $pid == "EMPTY" ]; then
1171 pid=""
1172 fi
1173 targetJson=$targetJson"\"$pid\""
1174 done
1175
1176 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001177 if [ "$PMS_VERSION" == "V2" ]; then
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +01001178 targetJson="{\"policytype_ids\": $targetJson }"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001179 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001180 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001181 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001182
1183 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001184 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001185 return 1
1186 fi
1187 fi
1188
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001189 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001190 return 0
1191}
1192
1193#########################################################
1194#### Test case functions Health check
1195#########################################################
1196
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001197# API Test function: GET /status and V2 GET /status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001198# args: <response-code>
1199# (Function for test scripts)
1200api_get_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001201 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001202 if [ $# -ne 1 ]; then
1203 __print_err "<response-code>" $@
1204 return 1
1205 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001206 if [ "$PMS_VERSION" == "V2" ]; then
1207 query="/v2/status"
1208 else
1209 query="/status"
1210 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001211 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001212 status=${res:${#res}-3}
1213
1214 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001215 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001216 return 1
1217 fi
1218
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001219 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001220 return 0
1221}
1222
1223#########################################################
1224#### Test case functions RIC Repository
1225#########################################################
1226
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001227# API Test function: GET /ric and V2 GET /v2/rics/ric
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001228# args: <reponse-code> <management-element-id> [<ric-id>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001229# (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>]
1230# (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4"
1231# (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1232
1233
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001234# (Function for test scripts)
1235api_get_ric() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001236 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001237
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001238 if [ "$PMS_VERSION" == "V2" ]; then
1239 if [ $# -lt 3 ]; then
1240 __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@
1241 return 1
1242 fi
1243 search=""
1244 if [ $2 != "NOME" ]; then
1245 search="?managed_element_id="$2
1246 fi
1247 if [ $3 != "NORIC" ]; then
1248 if [ -z $search ]; then
1249 search="?ric_id="$3
1250 else
1251 search=$search"&ric_id="$3
1252 fi
1253 fi
1254 query="/v2/rics/ric"$search
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001255
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001256 res="$(__do_curl_to_api PA GET $query)"
1257 status=${res:${#res}-3}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001258
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001259 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001260 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001261 return 1
1262 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001263
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001264 if [ $# -gt 3 ]; then
1265 body=${res:0:${#res}-3}
1266 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" )
1267 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001268 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001269 return 1
1270 fi
1271
1272 targetJson=$(<./tmp/.tmp_rics.json)
1273 targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets
1274 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1275 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1276 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001277 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001278 return 1
1279 fi
1280 fi
1281 else
1282 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
1283 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
1284 return 1
1285 fi
1286
1287 query="/ric?managedElementId="$2
1288
1289 res="$(__do_curl_to_api PA GET $query)"
1290 status=${res:${#res}-3}
1291
1292 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001293 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001294 return 1
1295 fi
1296
1297 if [ $# -eq 3 ]; then
1298 body=${res:0:${#res}-3}
1299 if [ "$body" != "$3" ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001300 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001301 return 1
1302 fi
1303 fi
1304 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001305 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001306 return 0
1307}
1308
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001309# API test function: GET /rics and V2 GET /v2/rics
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001310# args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
1311# 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_........."
1312# format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
1313# (Function for test scripts)
1314api_get_rics() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001315 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001316
1317 if [ $# -lt 2 ]; then
1318 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
1319 return 1
1320 fi
1321
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001322 if [ "$PMS_VERSION" == "V2" ]; then
1323 query="/v2/rics"
1324 if [ $2 != "NOTYPE" ]; then
1325 query="/v2/rics?policytype_id="$2
1326 fi
1327 else
1328 query="/rics"
1329 if [ $2 != "NOTYPE" ]; then
1330 query="/rics?policyType="$2
1331 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001332 fi
1333
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001334 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001335 status=${res:${#res}-3}
1336
1337 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001338 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001339 return 1
1340 fi
1341
1342 if [ $# -gt 2 ]; then
1343 body=${res:0:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001344 if [ "$PMS_VERSION" == "V2" ]; then
1345 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" )
1346 else
1347 res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" )
1348 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001349 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001350 __log_test_fail_general "Could not create target ric info json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001351 return 1
1352 fi
1353
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001354 targetJson=$(<./tmp/.tmp_rics.json)
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001355 if [ "$PMS_VERSION" == "V2" ]; then
1356 targetJson="{\"rics\": $targetJson }"
1357 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001358 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001359 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001360 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001361 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001362 return 1
1363 fi
1364 fi
1365
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001366 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001367 return 0
1368}
1369
1370##################################################################
1371#### API Test case functions Service registry and supervision ####
1372##################################################################
1373
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001374# API test function: PUT /service and V2 PUT /service
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001375# args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1376# (Function for test scripts)
1377api_put_service() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001378 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001379 if [ $# -ne 4 ]; then
1380 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1381 return 1
1382 fi
1383
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001384 if [ "$PMS_VERSION" == "V2" ]; then
1385 query="/v2/services"
1386 json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}"
1387 else
1388 query="/service"
1389 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1390 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001391 file="./tmp/.tmp.json"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001392 echo "$json" > $file
1393
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001394 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001395 status=${res:${#res}-3}
1396
1397 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001398 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001399 return 1
1400 fi
1401
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001402 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001403 return 0
1404}
1405
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001406# API test function: GET /services and V2 GET /v2/services
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001407#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>]* )]
1408# (Function for test scripts)
1409api_get_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001410 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001411 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1412 paramError=1
1413 if [ $# -eq 1 ]; then
1414 paramError=0
1415 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1416 paramError=0
1417 elif [ $# -eq 5 ]; then
1418 paramError=0
1419 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1420 argLen=$(($#-2))
1421 if [ $(($argLen%3)) -eq 0 ]; then
1422 paramError=0
1423 fi
1424 fi
1425
1426 if [ $paramError -ne 0 ]; then
1427 __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>]* )]" $@
1428 return 1
1429 fi
1430
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001431 if [ "$PMS_VERSION" == "V2" ]; then
1432 query="/v2/services"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001433
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001434 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1435 query="/v2/services?service_id="$2
1436 fi
1437 else
1438 query="/services"
1439
1440 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1441 query="/services?name="$2
1442 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001443 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001444 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001445 status=${res:${#res}-3}
1446
1447 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001448 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001449 return 1
1450 fi
1451
1452 if [ $# -gt 2 ]; then
1453 variableArgCount=$(($#-2))
1454 body=${res:0:${#res}-3}
1455 targetJson="["
1456 shift; shift;
1457 cntr=0
1458 while [ $cntr -lt $variableArgCount ]; do
1459 servicename=$1; shift;
1460 timeout=$1; shift;
1461 callback=$1; shift;
1462 if [ $cntr -gt 0 ]; then
1463 targetJson=$targetJson","
1464 fi
1465 # timeSinceLastActivitySeconds value cannot be checked since value varies
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001466 if [ "$PMS_VERSION" == "V2" ]; then
1467 targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}"
1468 else
1469 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1470 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001471 let cntr=cntr+3
1472 done
1473 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001474 if [ "$PMS_VERSION" == "V2" ]; then
1475 targetJson="{\"service_list\": $targetJson }"
1476 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001477 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001478 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001479 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001480 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001481 return 1
1482 fi
1483 fi
1484
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001485 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001486 return 0
1487}
1488
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001489# API test function: GET /services V2 GET /v2/services - (only checking service names)
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001490# args: <response-code> [<service-name>]*"
1491# (Function for test scripts)
1492api_get_service_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001493 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001494
1495 if [ $# -lt 1 ]; then
1496 __print_err "<response-code> [<service-name>]*" $@
1497 return 1
1498 fi
1499
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001500 if [ "$PMS_VERSION" == "V2" ]; then
1501 query="/v2/services"
1502 else
1503 query="/services"
1504 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001505 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001506 status=${res:${#res}-3}
1507
1508 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001509 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001510 return 1
1511 fi
1512
1513 body=${res:0:${#res}-3}
1514 targetJson="["
1515 for rapp in ${@:2} ; do
1516 if [ "$targetJson" != "[" ]; then
1517 targetJson=$targetJson","
1518 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001519 if [ "$PMS_VERSION" == "V2" ]; then
1520 targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}"
1521 else
1522 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1523 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001524 done
1525
1526 targetJson=$targetJson"]"
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001527 if [ "$PMS_VERSION" == "V2" ]; then
1528 targetJson="{\"service_list\": $targetJson }"
1529 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001530 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001531 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001532
1533 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001534 __log_test_fail_body
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001535 return 1
1536 fi
1537
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001538 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001539 return 0
1540}
1541
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001542# API test function: DELETE /services and V2 DELETE /v2/services/{serviceId}
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001543# args: <response-code> <service-name>
1544# (Function for test scripts)
1545api_delete_services() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001546 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001547
1548 if [ $# -ne 2 ]; then
1549 __print_err "<response-code> <service-name>" $@
1550 return 1
1551 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001552 if [ "$PMS_VERSION" == "V2" ]; then
1553 query="/v2/services/"$2
1554 else
1555 query="/services?name="$2
1556 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001557 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001558 status=${res:${#res}-3}
1559
1560 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001561 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001562 return 1
1563 fi
1564
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001565 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001566 return 0
1567}
1568
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001569# API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001570# args: <response-code> <service-name>
1571# (Function for test scripts)
1572api_put_services_keepalive() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001573 __log_test_start $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001574
1575 if [ $# -ne 2 ]; then
1576 __print_err "<response-code> <service-name>" $@
1577 return 1
1578 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +01001579 if [ "$PMS_VERSION" == "V2" ]; then
1580 query="/v2/services/$2/keepalive"
1581 else
1582 query="/services/keepalive?name="$2
1583 fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001584
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001585 res="$(__do_curl_to_api PA PUT $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001586 status=${res:${#res}-3}
1587
1588 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001589 __log_test_fail_status_code $1 $status
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001590 return 1
1591 fi
1592
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001593 __log_test_pass
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001594 return 0
1595}
1596
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001597##################################################################
1598#### API Test case functions Configuration ####
1599##################################################################
1600
1601# API Test function: PUT /v2/configuration
1602# args: <response-code> <config-file>
1603# (Function for test scripts)
1604api_put_configuration() {
1605 __log_test_start $@
1606
1607 if [ "$PMS_VERSION" != "V2" ]; then
1608 __log_test_fail_not_supported
1609 return 1
1610 fi
1611
1612 if [ $# -ne 2 ]; then
1613 __print_err "<response-code> <config-file>" $@
1614 return 1
1615 fi
1616 if [ ! -f $2 ]; then
1617 _log_test_fail_general "Config file "$2", does not exist"
1618 return 1
1619 fi
1620 inputJson=$(< $2)
1621 inputJson="{\"config\":"$inputJson"}"
1622 file="./tmp/.config.json"
1623 echo $inputJson > $file
1624 query="/v2/configuration"
1625 res="$(__do_curl_to_api PA PUT $query $file)"
1626 status=${res:${#res}-3}
1627
1628 if [ $status -ne $1 ]; then
1629 __log_test_fail_status_code $1 $status
1630 return 1
1631 fi
1632
1633 __log_test_pass
1634 return 0
1635}
1636
1637# API Test function: GET /v2/configuration
1638# args: <response-code> [<config-file>]
1639# (Function for test scripts)
1640api_get_configuration() {
1641 __log_test_start $@
1642
1643 if [ "$PMS_VERSION" != "V2" ]; then
1644 __log_test_fail_not_supported
1645 return 1
1646 fi
1647
1648 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
1649 __print_err "<response-code> [<config-file>]" $@
1650 return 1
1651 fi
1652 if [ ! -f $2 ]; then
1653 _log_test_fail_general "Config file "$2" for comparison, does not exist"
1654 return 1
1655 fi
1656
1657 query="/v2/configuration"
1658 res="$(__do_curl_to_api PA GET $query)"
1659 status=${res:${#res}-3}
1660
1661 if [ $status -ne $1 ]; then
1662 __log_test_fail_status_code $1 $status
1663 return 1
1664 fi
1665
1666 if [ $# -eq 2 ]; then
1667
1668 body=${res:0:${#res}-3}
1669
1670 targetJson=$(< $2)
1671 targetJson="{\"config\":"$targetJson"}"
1672 echo "TARGET JSON: $targetJson" >> $HTTPLOG
1673 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1674
1675 if [ $res -ne 0 ]; then
1676 __log_test_fail_body
1677 return 1
1678 fi
1679 fi
1680
1681 __log_test_pass
1682 return 0
1683}