blob: 8ec8fdbca01e696779e9571a3c23b74a6b24f30d [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
38 __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/" $1 "=" $2 $3
39 return 0
40 fi
41 fi
42
43 ((RES_CONF_FAIL++))
44 __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@
45 return 1
46}
47
48# API Test function: GET /policies
49# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-ype-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*]
50# (Function for test scripts)
51api_get_policies() {
52 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
53 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
54 ((RES_TEST++))
55 paramError=0
56 if [ $# -lt 4 ]; then
57 paramError=1
58 elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then
59 paramError=1
60 elif [ $# -gt 4 ] && [ $(($#%5)) -ne 4 ]; then
61 paramError=1
62 fi
63
64 if [ $paramError -ne 0 ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +020065 __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>]*]" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +010066 return 1
67 fi
68 queryparams=""
69 if [ $2 != "NORIC" ]; then
70 queryparams="?ric="$2
71 fi
72 if [ $3 != "NOSERVICE" ]; then
73 if [ -z $queryparams ]; then
74 queryparams="?service="$3
75 else
76 queryparams=$queryparams"&service="$3
77 fi
78 fi
79 if [ $4 != "NOTYPE" ]; then
80 if [ -z $queryparams ]; then
81 queryparams="?type="$4
82 else
83 queryparams=$queryparams"&type="$4
84 fi
85 fi
86
87 query="/policies"$queryparams
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020088 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +010089 status=${res:${#res}-3}
90
91 if [ $status -ne $1 ]; then
92 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
93 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +020094 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +010095 return 1
96 fi
97
98 if [ $# -gt 4 ]; then
99 if [ $# -eq 5 ] && [ $5 == "NOID" ]; then
100 targetJson="["
101 else
102 body=${res:0:${#res}-3}
103 targetJson="["
104 arr=(${@:5})
105
106 for ((i=0; i<$(($#-4)); i=i+5)); do
107
108 if [ "$targetJson" != "[" ]; then
109 targetJson=$targetJson","
110 fi
BjornMagnussonXAad047782020-06-08 15:54:11 +0200111 targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100112 if [ "${arr[$i+3]}" == "EMPTY" ]; then
113 targetJson=$targetJson"\"\","
114 else
115 targetJson=$targetJson"\"${arr[$i+3]}\","
116 fi
117 file=".p.json"
118 sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file
119 json=$(cat $file)
120 targetJson=$targetJson"\"json\":"$json"}"
121 done
122 fi
123
124 targetJson=$targetJson"]"
125 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200126 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100127
128 if [ $res -ne 0 ]; then
129 echo -e $RED" FAIL, returned body not correct"$ERED
130 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200131 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100132 return 1
133 fi
134 fi
135
136 ((RES_PASS++))
137 echo -e $GREEN" PASS"$EGREEN
138 return 0
139
140}
141
142# API Test function: GET /policy
143#args: <response-code> <policy-id> [<template-file>]
144# (Function for test scripts)
145api_get_policy() {
146 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
147 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
148 ((RES_TEST++))
149
150 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
151 __print_err "<response-code> <policy-id> [<template-file>] " $@
152 return 1
153 fi
154
BjornMagnussonXAad047782020-06-08 15:54:11 +0200155 query="/policy?id=$UUID$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200156 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100157 status=${res:${#res}-3}
158
159 if [ $status -ne $1 ]; then
160 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
161 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200162 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100163 return 1
164 fi
165
166 if [ $# -eq 3 ]; then
167 #Create a policy json to compare with
168 body=${res:0:${#res}-3}
169 file=".p.json"
170 sed 's/XXX/'${2}'/g' $3 > $file
171 targetJson=$(< $file)
172 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200173 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100174 if [ $res -ne 0 ]; then
175 echo -e $RED" FAIL, returned body not correct"$ERED
176 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200177 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100178 return 1
179 fi
180 fi
181
182 ((RES_PASS++))
183 echo -e $GREEN" PASS"$EGREEN
184 return 0
185}
186
187# API Test function: PUT /policy
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200188# args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100189# (Function for test scripts)
190api_put_policy() {
191 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
192 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
193 ((RES_TEST++))
194
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200195 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
BjornMagnussonXA0f9d5172020-06-17 15:43:39 +0200196 __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100197 return 1
198 fi
199
200 ric=$3
201 count=0
202 max=1
203
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200204 if [ $# -eq 8 ]; then
205 max=$8
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100206 fi
207
208 pid=$5
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200209 file=$7
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100210
211 while [ $count -lt $max ]; do
BjornMagnussonXAad047782020-06-08 15:54:11 +0200212 query="/policy?id=$UUID$pid&ric=$ric&service=$2"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100213
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200214 if [ $4 != "NOTYPE" ]; then
215 query=$query"&type=$4"
216 fi
217
218 if [ $6 != NOTRANSIENT ]; then
219 query=$query"&transient=$6"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100220 fi
221
222 file=".p.json"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200223 sed 's/XXX/'${pid}'/g' $7 > $file
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200224 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100225 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200226 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100227 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200228 echo " Executed "$count"?("$max")"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100229 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
230 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200231 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100232 return 1
233 fi
234
235 let pid=$pid+1
236 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200237 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100238 done
239 echo ""
240
241 ((RES_PASS++))
242 echo -e $GREEN" PASS"$EGREEN
243 return 0
244}
245
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200246# API Test function: PUT /policy to run in batch
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200247# args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200248# (Function for test scripts)
249api_put_policy_batch() {
250 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
251 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
252 ((RES_TEST++))
253
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200254 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
255 __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]" $@
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200256 return 1
257 fi
258
259 ric=$3
260 count=0
261 max=1
262
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200263 if [ $# -eq 8 ]; then
264 max=$8
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200265 fi
266
267 pid=$5
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200268 file=$7
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200269 ARR=""
270 while [ $count -lt $max ]; do
BjornMagnussonXAad047782020-06-08 15:54:11 +0200271 query="/policy?id=$UUID$pid&ric=$ric&service=$2"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200272
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200273 if [ $4 != "NOTYPE" ]; then
274 query=$query"&type=$4"
275 fi
276
277 if [ $6 != NOTRANSIENT ]; then
278 query=$query"&transient=$6"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200279 fi
280
281 file=".p.json"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200282 sed 's/XXX/'${pid}'/g' $7 > $file
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200283 res="$(__do_curl_to_api PA PUT_BATCH $query $file)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200284 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200285 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200286
287 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200288 echo " Requested(batch) "$count"?("$max")"
289 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
290 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200291 __check_stop_at_error
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200292 return 1
293 fi
294 cid=${res:0:${#res}-3}
295 ARR=$ARR" "$cid
296 let pid=$pid+1
297 let count=$count+1
298 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
299 done
300
301 echo ""
302 count=0
303 for cid in $ARR; do
304
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200305 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200306 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200307 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200308
309 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200310 echo " Requested(batch) "$count"?("$max")"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200311 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
312 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200313 __check_stop_at_error
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200314 return 1
315 fi
316
317 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200318 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200319 done
320
321 echo ""
322
323 ((RES_PASS++))
324 echo -e $GREEN" PASS"$EGREEN
325 return 0
326}
327
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200328# API Test function: PUT /policy to run in i parallel for a number of rics
329# 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>
330# (Function for test scripts)
331api_put_policy_parallel() {
332 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
333 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
334 ((RES_TEST++))
335
336 if [ $# -ne 10 ]; then
337 __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>" $@
338 return 1
339 fi
340 resp_code=$1; shift;
341 serv=$1; shift
342 ric_base=$1; shift;
343 num_rics=$1; shift;
344 type=$1; shift;
345 start_id=$1; shift;
346 transient=$1; shift;
347 template=$1; shift;
348 count=$1; shift;
349 pids=$1; shift;
350
351 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
352 echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported"
353 echo " Info - will execute over agent REST"
354 fi
355
356 if [ $serv == "NOSERVICE" ]; then
357 serv=""
358 fi
359 query="/policy?service=$serv"
360
361 if [ $type != "NOTYPE" ]; then
362 query=$query"&type=$type"
363 fi
364
365 if [ $transient != NOTRANSIENT ]; then
366 query=$query"&transient=$transient"
367 fi
368
369 urlbase=${ADAPTER}${query}
370
371 for ((i=1; i<=$pids; i++))
372 do
BjornMagnussonXAad047782020-06-08 15:54:11 +0200373 uuid=$UUID
374 if [ -z "$uuid" ]; then
375 uuid="NOUUID"
376 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200377 echo "" > ".pid${i}.res.txt"
BjornMagnussonXAad047782020-06-08 15:54:11 +0200378 echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > ".pid${i}.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200379 echo $i
380 done | xargs -n 1 -I{} -P $pids bash -c '{
381 arg=$(echo {})
382 echo " Parallel process $arg started"
383 tmp=$(< ".pid${arg}.txt")
384 python3 ../common/create_policies_process.py $tmp > .pid${arg}.res.txt
385 }'
386 msg=""
387 for ((i=1; i<=$pids; i++))
388 do
389 file=".pid${i}.res.txt"
390 tmp=$(< $file)
391 if [ -z "$tmp" ]; then
392 echo " Process $i : unknown result (result file empty"
393 msg="failed"
394 else
395 res=${tmp:0:1}
396 if [ $res == "0" ]; then
397 echo " Process $i : OK"
398 else
399 echo " Process $i : failed - "${tmp:1}
400 msg="failed"
401 fi
402 fi
403 done
404 if [ -z $msg ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200405 echo " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200406 ((RES_PASS++))
407 echo -e $GREEN" PASS"$EGREEN
408 return 0
409 fi
410
411 echo -e $RED" FAIL. One of more processes failed to execute" $ERED
412 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200413 __check_stop_at_error
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200414 return 1
415}
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100416
417# API Test function: DELETE /policy
418# args: <response-code> <policy-id> [count]
419# (Function for test scripts)
420api_delete_policy() {
421 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
422 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
423 ((RES_TEST++))
424
425 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
426 __print_err "<response-code> <policy-id> [count]" $@
427 return 1
428 fi
429
430 count=0
431 max=1
432
433 if [ $# -eq 3 ]; then
434 max=$3
435 fi
436
437 pid=$2
438
439 while [ $count -lt $max ]; do
BjornMagnussonXAad047782020-06-08 15:54:11 +0200440 query="/policy?id="$UUID$pid
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200441 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100442 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200443 echo -ne " Executing "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100444
445 if [ $status -ne $1 ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200446 echo " Executed "$count"?("$max")"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100447 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
448 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200449 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100450 return 1
451 fi
452 let pid=$pid+1
453 let count=$count+1
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200454 echo -ne " Executed "$count"("$max")${SAMELINE}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100455 done
456 echo ""
457
458 ((RES_PASS++))
459 echo -e $GREEN" PASS"$EGREEN
460 return 0
461}
462
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200463# API Test function: DELETE /policy to run in batch
464# args: <response-code> <policy-id> [count]
465# (Function for test scripts)
466api_delete_policy_batch() {
467 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
468 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
469 ((RES_TEST++))
470
471 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
472 __print_err "<response-code> <policy-id> [count]" $@
473 return 1
474 fi
475
476 count=0
477 max=1
478
479 if [ $# -eq 3 ]; then
480 max=$3
481 fi
482
483 pid=$2
484 ARR=""
485 while [ $count -lt $max ]; do
BjornMagnussonXAad047782020-06-08 15:54:11 +0200486 query="/policy?id="$UUID$pid
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200487 res="$(__do_curl_to_api PA DELETE_BATCH $query)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200488 status=${res:${#res}-3}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200489 echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200490
491 if [ $status -ne 200 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200492 echo " Requested(batch) "$count"?("$max")"
493 echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED
494 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200495 __check_stop_at_error
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200496 return 1
497 fi
498 cid=${res:0:${#res}-3}
499 ARR=$ARR" "$cid
500 let pid=$pid+1
501 let count=$count+1
502 echo -ne " Requested(batch) "$count"("$max")${SAMELINE}"
503 done
504
505 echo ""
506
507 count=0
508 for cid in $ARR; do
509
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200510 res="$(__do_curl_to_api PA RESPONSE $cid)"
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200511 status=${res:${#res}-3}
512 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
513
514 if [ $status -ne $1 ]; then
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200515 echo " Deleted(batch) "$count"?("$max")"
516 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
517 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200518 __check_stop_at_error
BjornMagnussonXA70e878f2020-05-11 14:11:30 +0200519 return 1
520 fi
521
522 let count=$count+1
523 echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}"
524 done
525
526 ((RES_PASS++))
527 echo -e $GREEN" PASS"$EGREEN
528 return 0
529}
530
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200531# API Test function: DELETE /policy to run in i parallel for a number of rics
532# args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>
533# (Function for test scripts)
534api_delete_policy_parallel() {
535 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
536 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
537 ((RES_TEST++))
538
539 if [ $# -ne 5 ]; then
540 __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@
541 return 1
542 fi
543 resp_code=$1; shift;
544 num_rics=$1; shift;
545 start_id=$1; shift;
546 count=$1; shift;
547 pids=$1; shift;
548
549 if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then
550 echo " Info - api_delete_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
553
554 query="/policy"
555
556 urlbase=${ADAPTER}${query}
557
558 for ((i=1; i<=$pids; i++))
559 do
BjornMagnussonXAad047782020-06-08 15:54:11 +0200560 uuid=$UUID
561 if [ -z "$uuid" ]; then
562 uuid="NOUUID"
563 fi
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200564 echo "" > ".pid${i}.del.res.txt"
BjornMagnussonXAad047782020-06-08 15:54:11 +0200565 echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > ".pid${i}.del.txt"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200566 echo $i
567 done | xargs -n 1 -I{} -P $pids bash -c '{
568 arg=$(echo {})
569 echo " Parallel process $arg started"
570 tmp=$(< ".pid${arg}.del.txt")
571 python3 ../common/delete_policies_process.py $tmp > .pid${arg}.del.res.txt
572 }'
573 msg=""
574 for ((i=1; i<=$pids; i++))
575 do
576 file=".pid${i}.del.res.txt"
577 tmp=$(< $file)
578 if [ -z "$tmp" ]; then
579 echo " Process $i : unknown result (result file empty"
580 msg="failed"
581 else
582 res=${tmp:0:1}
583 if [ $res == "0" ]; then
584 echo " Process $i : OK"
585 else
586 echo " Process $i : failed - "${tmp:1}
587 msg="failed"
588 fi
589 fi
590 done
591 if [ -z $msg ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200592 echo " $(($count*$num_rics)) policy request(s) executed"
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200593 ((RES_PASS++))
594 echo -e $GREEN" PASS"$EGREEN
595 return 0
596 fi
597
598 echo -e $RED" FAIL. One of more processes failed to execute" $ERED
599 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200600 __check_stop_at_error
BjornMagnussonXAbbd2e9d2020-05-27 21:24:06 +0200601 return 1
602}
603
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100604# API Test function: GET /policy_ids
605# args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)
606# (Function for test scripts)
607api_get_policy_ids() {
608 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
609 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
610 ((RES_TEST++))
611
612 if [ $# -lt 4 ]; then
613 __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@
614 return 1
615 fi
616
617 queryparams=""
618
619 if [ $2 != "NORIC" ]; then
620 queryparams="?ric="$2
621 fi
622
623 if [ $3 != "NOSERVICE" ]; then
624 if [ -z $queryparams ]; then
625 queryparams="?service="$3
626 else
627 queryparams=$queryparams"&service="$3
628 fi
629 fi
630 if [ $4 != "NOTYPE" ]; then
631 if [ -z $queryparams ]; then
632 queryparams="?type="$4
633 else
634 queryparams=$queryparams"&type="$4
635 fi
636 fi
637
638 query="/policy_ids"$queryparams
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200639 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100640 status=${res:${#res}-3}
641
642 if [ $status -ne $1 ]; then
643 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
644 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200645 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100646 return 1
647 fi
648
649 if [ $# -gt 4 ]; then
650 body=${res:0:${#res}-3}
651 targetJson="["
652
653 for pid in ${@:5} ; do
654 if [ "$targetJson" != "[" ]; then
655 targetJson=$targetJson","
656 fi
657 if [ $pid != "NOID" ]; then
BjornMagnussonXAad047782020-06-08 15:54:11 +0200658 targetJson=$targetJson"\"$UUID$pid\""
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100659 fi
660 done
661
662 targetJson=$targetJson"]"
663 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200664 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100665
666 if [ $res -ne 0 ]; then
667 echo -e $RED" FAIL, returned body not correct"$ERED
668 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200669 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100670 return 1
671 fi
672 fi
673
674 ((RES_PASS++))
675 echo -e $GREEN" PASS"$EGREEN
676 return 0
677}
678
679# API Test function: GET /policy_schema
680# args: <response-code> <policy-type-id> [<schema-file>]
681# (Function for test scripts)
682api_get_policy_schema() {
683 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
684 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
685 ((RES_TEST++))
686
687 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
688 __print_err "<response-code> <policy-type-id> [<schema-file>]" $@
689 return 1
690 fi
691
692 query="/policy_schema?id=$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200693 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100694 status=${res:${#res}-3}
695
696 if [ $status -ne $1 ]; then
697 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
698 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200699 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100700 return 1
701 fi
702
703 if [ $# -eq 3 ]; then
704
705 body=${res:0:${#res}-3}
706
707 targetJson=$(< $3)
708 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200709 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100710
711 if [ $res -ne 0 ]; then
712 echo -e $RED" FAIL, returned body not correct"$ERED
713 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200714 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100715 return 1
716 fi
717 fi
718
719 ((RES_PASS++))
720 echo -e $GREEN" PASS"$EGREEN
721 return 0
722}
723
724# API Test function: GET /policy_schemas
725# args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*
726# (Function for test scripts)
727api_get_policy_schemas() {
728 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
729 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
730 ((RES_TEST++))
731
732 if [ $# -lt 2 ]; then
733 __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@
734 return 1
735 fi
736
737 query="/policy_schemas"
738 if [ $2 != "NORIC" ]; then
739 query=$query"?ric="$2
740 fi
741
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200742 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100743 status=${res:${#res}-3}
744
745 if [ $status -ne $1 ]; then
746 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
747 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200748 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100749 return 1
750 fi
751
752 if [ $# -gt 2 ]; then
753 body=${res:0:${#res}-3}
754 targetJson="["
755
756 for file in ${@:3} ; do
757 if [ "$targetJson" != "[" ]; then
758 targetJson=$targetJson","
759 fi
760 if [ $file == "NOFILE" ]; then
761 targetJson=$targetJson"{}"
762 else
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200763 targetJson=$targetJson$(< $file)
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100764 fi
765 done
766
767 targetJson=$targetJson"]"
768 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200769 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100770
771 if [ $res -ne 0 ]; then
772 echo -e $RED" FAIL, returned body not correct"$ERED
773 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200774 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100775 return 1
776 fi
777 fi
778
779 ((RES_PASS++))
780 echo -e $GREEN" PASS"$EGREEN
781 return 0
782}
783
784# API Test function: GET /policy_status
785# arg: <response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)
786# (Function for test scripts)
787api_get_policy_status() {
788 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
789 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
790 ((RES_TEST++))
791 if [ $# -lt 4 ] || [ $# -gt 5 ]; then
792 __print_err "<response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
793 return 1
794 fi
795
796 targetJson=""
797
798 if [ $3 == "STD" ]; then
799 targetJson="{\"enforceStatus\":\"$4\""
800 if [ $# -eq 5 ]; then
801 targetJson=$targetJson",\"reason\":\"$5\""
802 fi
803 targetJson=$targetJson"}"
804 elif [ $3 == "OSC" ]; then
805 targetJson="{\"instance_status\":\"$4\""
806 if [ $# -eq 5 ]; then
807 targetJson=$targetJson",\"has_been_deleted\":\"$5\""
808 fi
809 targetJson=$targetJson",\"created_at\":\"????\"}"
810 else
811 __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@
812 return 1
813 fi
814
BjornMagnussonXAad047782020-06-08 15:54:11 +0200815 query="/policy_status?id="$UUID$2
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100816
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200817 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100818 status=${res:${#res}-3}
819
820 if [ $status -ne $1 ]; then
821 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
822 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200823 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100824 return 1
825 fi
826
827 echo "TARGET JSON: $targetJson" >> $HTTPLOG
828 body=${res:0:${#res}-3}
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200829 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100830
831 if [ $res -ne 0 ]; then
832 echo -e $RED" FAIL, returned body not correct"$ERED
833 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200834 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100835 return 1
836 fi
837
838 ((RES_PASS++))
839 echo -e $GREEN" PASS"$EGREEN
840 return 0
841}
842
843# API Test function: GET /policy_types
844# args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]
845# (Function for test scripts)
846api_get_policy_types() {
847 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
848 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
849 ((RES_TEST++))
850
851 if [ $# -lt 1 ]; then
852 __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@
853 return 1
854 fi
855
856 if [ $# -eq 1 ]; then
857 query="/policy_types"
858 elif [ $2 == "NORIC" ]; then
859 query="/policy_types"
860 else
861 query="/policy_types?ric=$2"
862 fi
863
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200864 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100865 status=${res:${#res}-3}
866
867 if [ $status -ne $1 ]; then
868 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
869 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200870 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100871 return 1
872 fi
873
874 if [ $# -gt 2 ]; then
875 body=${res:0:${#res}-3}
876 targetJson="["
877
878 for pid in ${@:3} ; do
879 if [ "$targetJson" != "[" ]; then
880 targetJson=$targetJson","
881 fi
882 if [ $pid == "EMPTY" ]; then
883 pid=""
884 fi
885 targetJson=$targetJson"\"$pid\""
886 done
887
888 targetJson=$targetJson"]"
889 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200890 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100891
892 if [ $res -ne 0 ]; then
893 echo -e $RED" FAIL, returned body not correct"$ERED
894 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200895 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100896 return 1
897 fi
898 fi
899
900 ((RES_PASS++))
901 echo -e $GREEN" PASS"$EGREEN
902 return 0
903}
904
905#########################################################
906#### Test case functions Health check
907#########################################################
908
909# API Test function: GET /status
910# args: <response-code>
911# (Function for test scripts)
912api_get_status() {
913 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
914 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
915 ((RES_TEST++))
916 if [ $# -ne 1 ]; then
917 __print_err "<response-code>" $@
918 return 1
919 fi
920 query="/status"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200921 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100922 status=${res:${#res}-3}
923
924 if [ $status -ne $1 ]; then
925 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
926 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200927 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100928 return 1
929 fi
930
931 ((RES_PASS++))
932 echo -e $GREEN" PASS"$EGREEN
933 return 0
934}
935
936#########################################################
937#### Test case functions RIC Repository
938#########################################################
939
940# API Test function: GET /ric
941# args: <reponse-code> <management-element-id> [<ric-id>]
942# (Function for test scripts)
943api_get_ric() {
944 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
945 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
946 ((RES_TEST++))
947 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
948 __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@
949 return 1
950 fi
951
952 query="/ric?managedElementId="$2
953
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200954 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100955 status=${res:${#res}-3}
956
957 if [ $status -ne $1 ]; then
958 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
959 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200960 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100961 return 1
962 fi
963
964 if [ $# -eq 3 ]; then
965 body=${res:0:${#res}-3}
966 if [ "$body" != "$3" ]; then
967 echo -e $RED" FAIL, returned body not correct"$ERED
968 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +0200969 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100970 return 1
971 fi
972 fi
973
974 ((RES_PASS++))
975 echo -e $GREEN" PASS"$EGREEN
976 return 0
977}
978
979# API test function: GET /rics
980# args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]
981# 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_........."
982# format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids>
983# (Function for test scripts)
984api_get_rics() {
985 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
986 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
987 ((RES_TEST++))
988
989 if [ $# -lt 2 ]; then
990 __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@
991 return 1
992 fi
993
994 query="/rics"
995 if [ $2 != "NOTYPE" ]; then
996 query="/rics?policyType="$2
997 fi
998
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200999 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001000 status=${res:${#res}-3}
1001
1002 if [ $status -ne $1 ]; then
1003 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1004 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001005 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001006 return 1
1007 fi
1008
1009 if [ $# -gt 2 ]; then
1010 body=${res:0:${#res}-3}
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001011 res=$(python3 ../common/create_rics_json.py ".tmp_rics.json" "$3" )
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001012 if [ $res -ne 0 ]; then
1013 echo -e $RED" FAIL, could not create target ric info json"$ERED
1014 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001015 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001016 return 1
1017 fi
1018
1019 targetJson=$(<.tmp_rics.json)
1020 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001021 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001022 if [ $res -ne 0 ]; then
1023 echo -e $RED" FAIL, returned body not correct"$ERED
1024 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001025 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001026 return 1
1027 fi
1028 fi
1029
1030 ((RES_PASS++))
1031 echo -e $GREEN" PASS"$EGREEN
1032 return 0
1033}
1034
1035##################################################################
1036#### API Test case functions Service registry and supervision ####
1037##################################################################
1038
1039# API test function: PUT /service
1040# args: <response-code> <service-name> <keepalive-timeout> <callbackurl>
1041# (Function for test scripts)
1042api_put_service() {
1043 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1044 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1045 ((RES_TEST++))
1046 if [ $# -ne 4 ]; then
1047 __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@
1048 return 1
1049 fi
1050
1051 query="/service"
1052 json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}"
1053 file=".tmp.json"
1054 echo "$json" > $file
1055
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001056 res="$(__do_curl_to_api PA PUT $query $file)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001057 status=${res:${#res}-3}
1058
1059 if [ $status -ne $1 ]; then
1060 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1061 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001062 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001063 return 1
1064 fi
1065
1066 ((RES_PASS++))
1067 echo -e $GREEN" PASS"$EGREEN
1068 return 0
1069}
1070
1071# API test function: GET /services
1072#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>]* )]
1073# (Function for test scripts)
1074api_get_services() {
1075 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1076 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1077 ((RES_TEST++))
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001078 #Number of accepted parameters: 1, 2, 4, 7, 10, 13,...
1079 paramError=1
1080 if [ $# -eq 1 ]; then
1081 paramError=0
1082 elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then
1083 paramError=0
1084 elif [ $# -eq 5 ]; then
1085 paramError=0
1086 elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then
1087 argLen=$(($#-2))
1088 if [ $(($argLen%3)) -eq 0 ]; then
1089 paramError=0
1090 fi
1091 fi
1092
1093 if [ $paramError -ne 0 ]; then
1094 __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>]* )]" $@
1095 return 1
1096 fi
1097
1098 query="/services"
1099
1100 if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then
1101 query="/services?name="$2
1102 fi
1103
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
1108 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1109 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001110 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001111 return 1
1112 fi
1113
1114 if [ $# -gt 2 ]; then
1115 variableArgCount=$(($#-2))
1116 body=${res:0:${#res}-3}
1117 targetJson="["
1118 shift; shift;
1119 cntr=0
1120 while [ $cntr -lt $variableArgCount ]; do
1121 servicename=$1; shift;
1122 timeout=$1; shift;
1123 callback=$1; shift;
1124 if [ $cntr -gt 0 ]; then
1125 targetJson=$targetJson","
1126 fi
1127 # timeSinceLastActivitySeconds value cannot be checked since value varies
1128 targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}"
1129 let cntr=cntr+3
1130 done
1131 targetJson=$targetJson"]"
1132 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001133 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001134 if [ $res -ne 0 ]; then
1135 echo -e $RED" FAIL, returned body not correct"$ERED
1136 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001137 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001138 return 1
1139 fi
1140 fi
1141
1142 ((RES_PASS++))
1143 echo -e $GREEN" PASS"$EGREEN
1144 return 0
1145}
1146
1147# API test function: GET /services (only checking service names)
1148# args: <response-code> [<service-name>]*"
1149# (Function for test scripts)
1150api_get_service_ids() {
1151 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1152 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1153 ((RES_TEST++))
1154
1155 if [ $# -lt 1 ]; then
1156 __print_err "<response-code> [<service-name>]*" $@
1157 return 1
1158 fi
1159
1160 query="/services"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001161 res="$(__do_curl_to_api PA GET $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001162 status=${res:${#res}-3}
1163
1164 if [ $status -ne $1 ]; then
1165 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1166 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001167 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001168 return 1
1169 fi
1170
1171 body=${res:0:${#res}-3}
1172 targetJson="["
1173 for rapp in ${@:2} ; do
1174 if [ "$targetJson" != "[" ]; then
1175 targetJson=$targetJson","
1176 fi
1177 targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}"
1178 done
1179
1180 targetJson=$targetJson"]"
1181 echo "TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXA72667f12020-04-24 09:20:18 +02001182 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001183
1184 if [ $res -ne 0 ]; then
1185 echo -e $RED" FAIL, returned body not correct"$ERED
1186 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001187 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001188 return 1
1189 fi
1190
1191 ((RES_PASS++))
1192 echo -e $GREEN" PASS"$EGREEN
1193 return 0
1194}
1195
1196# API test function: DELETE /services
1197# args: <response-code> <service-name>
1198# (Function for test scripts)
1199api_delete_services() {
1200 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1201 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1202 ((RES_TEST++))
1203
1204 if [ $# -ne 2 ]; then
1205 __print_err "<response-code> <service-name>" $@
1206 return 1
1207 fi
1208
1209 query="/services?name="$2
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001210 res="$(__do_curl_to_api PA DELETE $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001211 status=${res:${#res}-3}
1212
1213 if [ $status -ne $1 ]; then
1214 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1215 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001216 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001217 return 1
1218 fi
1219
1220 ((RES_PASS++))
1221 echo -e $GREEN" PASS"$EGREEN
1222 return 0
1223}
1224
1225# API test function: PUT /services/keepalive
1226# args: <response-code> <service-name>
1227# (Function for test scripts)
1228api_put_services_keepalive() {
1229 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
1230 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
1231 ((RES_TEST++))
1232
1233 if [ $# -ne 2 ]; then
1234 __print_err "<response-code> <service-name>" $@
1235 return 1
1236 fi
1237
1238 query="/services/keepalive?name="$2
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001239 res="$(__do_curl_to_api PA PUT $query)"
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001240 status=${res:${#res}-3}
1241
1242 if [ $status -ne $1 ]; then
1243 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
1244 ((RES_FAIL++))
BjornMagnussonXA048aaa12020-06-04 07:48:37 +02001245 __check_stop_at_error
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001246 return 1
1247 fi
1248
1249 ((RES_PASS++))
1250 echo -e $GREEN" PASS"$EGREEN
1251 return 0
1252}
1253