BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1 | #!/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 | |
| 24 | # Generic function to query the agent via the REST or DMAAP interface. |
| 25 | # Used by all other agent api test functions |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 26 | # If operation prefix is '_BATCH' the the send and get response is split in two sequences, |
| 27 | # one for sending the requests and one for receiving the response |
| 28 | # but only when using the DMAAP interface |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 29 | # REST or DMAAP is controlled of the base url of $ADAPTER |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 30 | # arg: (GET|PUT|POST|DELETE|GET_BATCH|PUT_BATCH|POST_BATCH|DELETE_BATCH <url> [<file>]) | (RESPONSE <correlation-id>) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 31 | # (Not for test scripts) |
| 32 | __do_curl_to_agent() { |
| 33 | echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 34 | paramError=0 |
| 35 | |
| 36 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 37 | paramError=1 |
| 38 | else |
| 39 | timeout="" |
| 40 | oper="" |
| 41 | file='' |
| 42 | httpcode=" -sw %{http_code}" |
| 43 | accept='' |
| 44 | content='' |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 45 | batch=0 |
| 46 | if [[ $1 == *"_BATCH" ]]; then |
| 47 | batch=1 |
| 48 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 49 | if [ $# -gt 2 ]; then |
| 50 | content=" -H Content-Type:application/json" |
| 51 | fi |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 52 | if [ $1 == "GET" ] || [ $1 == "GET_BATCH" ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 53 | oper="GET" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 54 | if [ $# -ne 2 ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 55 | paramError=1 |
| 56 | fi |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 57 | elif [ $1 == "PUT" ] || [ $1 == "PUT_BATCH" ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 58 | oper="PUT" |
| 59 | if [ $# -eq 3 ]; then |
| 60 | file=" --data-binary @$3" |
| 61 | fi |
| 62 | accept=" -H accept:application/json" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 63 | elif [ $1 == "POST" ] || [ $1 == "POST_BATCH" ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 64 | oper="POST" |
| 65 | accept=" -H accept:*/*" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 66 | if [ $# -ne 2 ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 67 | paramError=1 |
| 68 | fi |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 69 | elif [ $1 == "DELETE" ] || [ $1 == "DELETE_BATCH" ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 70 | oper="DELETE" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 71 | if [ $# -ne 2 ]; then |
| 72 | paramError=1 |
| 73 | fi |
| 74 | elif [ $1 == "RESPONSE" ]; then |
| 75 | oper="RESPONSE" |
| 76 | if [ $# -ne 2 ]; then |
| 77 | paramError=1 |
| 78 | fi |
| 79 | if ! [ $ADAPTER == $DMAAPBASE ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 80 | paramError=1 |
| 81 | fi |
| 82 | else |
| 83 | paramError=1 |
| 84 | fi |
| 85 | fi |
| 86 | |
| 87 | if [ $paramError -eq 1 ]; then |
| 88 | ((RES_CONF_FAIL++)) |
| 89 | echo "-Incorrect number of parameters to __do_curl_agent " $@ >> $HTTPLOG |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 90 | echo "-Expected: (GET|PUT|POST|DELETE|GET_BATCH|PUT_BATCH|POST_BATCH|DELETE_BATCH <url> [<file>]) | (RESPONSE <correlation-id>) [<file>]" >> $HTTPLOG |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 91 | echo "-Returning response 000" >> $HTTPLOG |
| 92 | echo "-000" |
| 93 | return 1 |
| 94 | fi |
| 95 | |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 96 | if [ $ADAPTER == $RESTBASE ] || [ $ADAPTER == $RESTBASE_SECURE ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 97 | url=" "${ADAPTER}${2} |
| 98 | oper=" -X "$oper |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 99 | curlString="curl -k "${oper}${timeout}${httpcode}${accept}${content}${url}${file} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 100 | echo " CMD: "$curlString >> $HTTPLOG |
| 101 | if [ $# -eq 3 ]; then |
| 102 | echo " FILE: $(<$3)" >> $HTTPLOG |
| 103 | fi |
| 104 | |
| 105 | # Do retry for configured response codes, otherwise only one attempt |
| 106 | maxretries=5 |
| 107 | while [ $maxretries -ge 0 ]; do |
| 108 | |
| 109 | let maxretries=maxretries-1 |
| 110 | res=$($curlString) |
| 111 | retcode=$? |
| 112 | if [ $retcode -ne 0 ]; then |
| 113 | echo " RETCODE: "$retcode >> $HTTPLOG |
| 114 | echo "000" |
| 115 | return 1 |
| 116 | fi |
| 117 | retry=0 |
| 118 | echo " RESP: "$res >> $HTTPLOG |
| 119 | status=${res:${#res}-3} |
| 120 | if [ ! -z "${AGENT_RETRY_CODES}" ]; then |
| 121 | for retrycode in $AGENT_RETRY_CODES; do |
| 122 | if [ $retrycode -eq $status ]; then |
| 123 | echo -e $RED" Retrying (according to set codes for retry), got status $status....."$ERED >> $HTTPLOG |
| 124 | sleep 1 |
| 125 | retry=1 |
| 126 | fi |
| 127 | done |
| 128 | fi |
| 129 | if [ $retry -eq 0 ]; then |
| 130 | maxretries=-1 |
| 131 | fi |
| 132 | done |
| 133 | echo $res |
| 134 | return 0 |
| 135 | else |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 136 | if [ $oper != "RESPONSE" ]; then |
| 137 | requestUrl=$2 |
| 138 | if [ $1 == "PUT" ] && [ $# -eq 3 ]; then |
| 139 | payload="$(cat $3 | tr -d '\n' | tr -d ' ' )" |
| 140 | echo "payload: "$payload >> $HTTPLOG |
| 141 | file=" --data-binary "$payload |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 142 | fi |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 143 | #urlencode the request url since it will be carried by send-request url |
| 144 | requestUrl=$(python3 -c "from __future__ import print_function; import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$2") |
| 145 | url=" "${ADAPTER}"/send-request?url="${requestUrl}"&operation="${oper} |
| 146 | curlString="curl -X POST${timeout}${httpcode}${content}${url}${file}" |
| 147 | echo " CMD: "$curlString >> $HTTPLOG |
| 148 | res=$($curlString) |
| 149 | retcode=$? |
| 150 | if [ $retcode -ne 0 ]; then |
| 151 | echo " RETCODE: "$retcode >> $HTTPLOG |
| 152 | echo "000" |
| 153 | return 1 |
| 154 | fi |
| 155 | echo " RESP: "$res >> $HTTPLOG |
| 156 | status=${res:${#res}-3} |
| 157 | if [ $status -ne 200 ]; then |
| 158 | echo "000" |
| 159 | return 1 |
| 160 | fi |
| 161 | cid=${res:0:${#res}-3} |
| 162 | if [[ $batch -eq 1 ]]; then |
| 163 | echo $cid"200" |
| 164 | return 0 |
| 165 | fi |
| 166 | fi |
| 167 | if [ $oper == "RESPONSE" ] || [ $batch -eq 0 ]; then |
| 168 | if [ $oper == "RESPONSE" ]; then |
| 169 | cid=$2 |
| 170 | fi |
| 171 | url=" "${ADAPTER}"/receive-response?correlationid="${cid} |
| 172 | curlString="curl -X GET"${timeout}${httpcode}${url} |
| 173 | echo " CMD: "$curlString >> $HTTPLOG |
| 174 | res=$($curlString) |
| 175 | retcode=$? |
| 176 | if [ $retcode -ne 0 ]; then |
| 177 | echo " RETCODE: "$retcode >> $HTTPLOG |
| 178 | echo "000" |
| 179 | return 1 |
| 180 | fi |
| 181 | echo " RESP: "$res >> $HTTPLOG |
| 182 | status=${res:${#res}-3} |
| 183 | TS=$SECONDS |
| 184 | # wait of the reply from the agent... |
| 185 | while [ $status -eq 204 ]; do |
| 186 | if [ $(($SECONDS - $TS)) -gt 90 ]; then |
| 187 | echo " RETCODE: (timeout after 90s)" >> $HTTPLOG |
| 188 | echo "000" |
| 189 | return 1 |
| 190 | fi |
| 191 | sleep 0.01 |
| 192 | echo " CMD: "$curlString >> $HTTPLOG |
| 193 | res=$($curlString) |
| 194 | if [ $retcode -ne 0 ]; then |
| 195 | echo " RETCODE: "$retcode >> $HTTPLOG |
| 196 | echo "000" |
| 197 | return 1 |
| 198 | fi |
| 199 | echo " RESP: "$res >> $HTTPLOG |
| 200 | status=${res:${#res}-3} |
| 201 | done |
| 202 | if [ $status -eq 200 ]; then |
| 203 | body=${res:0:${#res}-3} |
| 204 | echo $body |
| 205 | return 0 |
| 206 | fi |
| 207 | echo "Status not 200, returning response 000" >> $HTTPLOG |
| 208 | echo "0000" |
| 209 | return 1 |
| 210 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 211 | fi |
| 212 | } |
| 213 | |
| 214 | |
| 215 | ######################################################### |
| 216 | #### Test case functions A1 Policy management service |
| 217 | ######################################################### |
| 218 | |
| 219 | # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent. |
| 220 | # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL |
| 221 | # args: json:<url> <target-value> [<timeout-in-seconds] |
| 222 | # (Function for test scripts) |
| 223 | api_equal() { |
| 224 | echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 225 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 226 | if [[ $1 == "json:"* ]]; then |
| 227 | __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/" $1 "=" $2 $3 |
| 228 | return 0 |
| 229 | fi |
| 230 | fi |
| 231 | |
| 232 | ((RES_CONF_FAIL++)) |
| 233 | __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@ |
| 234 | return 1 |
| 235 | } |
| 236 | |
| 237 | # API Test function: GET /policies |
| 238 | # 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>]*] |
| 239 | # (Function for test scripts) |
| 240 | api_get_policies() { |
| 241 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 242 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 243 | ((RES_TEST++)) |
| 244 | paramError=0 |
| 245 | if [ $# -lt 4 ]; then |
| 246 | paramError=1 |
| 247 | elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then |
| 248 | paramError=1 |
| 249 | elif [ $# -gt 4 ] && [ $(($#%5)) -ne 4 ]; then |
| 250 | paramError=1 |
| 251 | fi |
| 252 | |
| 253 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 254 | __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>]*]" $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 255 | return 1 |
| 256 | fi |
| 257 | queryparams="" |
| 258 | if [ $2 != "NORIC" ]; then |
| 259 | queryparams="?ric="$2 |
| 260 | fi |
| 261 | if [ $3 != "NOSERVICE" ]; then |
| 262 | if [ -z $queryparams ]; then |
| 263 | queryparams="?service="$3 |
| 264 | else |
| 265 | queryparams=$queryparams"&service="$3 |
| 266 | fi |
| 267 | fi |
| 268 | if [ $4 != "NOTYPE" ]; then |
| 269 | if [ -z $queryparams ]; then |
| 270 | queryparams="?type="$4 |
| 271 | else |
| 272 | queryparams=$queryparams"&type="$4 |
| 273 | fi |
| 274 | fi |
| 275 | |
| 276 | query="/policies"$queryparams |
| 277 | res="$(__do_curl_to_agent GET $query)" |
| 278 | status=${res:${#res}-3} |
| 279 | |
| 280 | if [ $status -ne $1 ]; then |
| 281 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 282 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 283 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 284 | return 1 |
| 285 | fi |
| 286 | |
| 287 | if [ $# -gt 4 ]; then |
| 288 | if [ $# -eq 5 ] && [ $5 == "NOID" ]; then |
| 289 | targetJson="[" |
| 290 | else |
| 291 | body=${res:0:${#res}-3} |
| 292 | targetJson="[" |
| 293 | arr=(${@:5}) |
| 294 | |
| 295 | for ((i=0; i<$(($#-4)); i=i+5)); do |
| 296 | |
| 297 | if [ "$targetJson" != "[" ]; then |
| 298 | targetJson=$targetJson"," |
| 299 | fi |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 300 | targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 301 | if [ "${arr[$i+3]}" == "EMPTY" ]; then |
| 302 | targetJson=$targetJson"\"\"," |
| 303 | else |
| 304 | targetJson=$targetJson"\"${arr[$i+3]}\"," |
| 305 | fi |
| 306 | file=".p.json" |
| 307 | sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file |
| 308 | json=$(cat $file) |
| 309 | targetJson=$targetJson"\"json\":"$json"}" |
| 310 | done |
| 311 | fi |
| 312 | |
| 313 | targetJson=$targetJson"]" |
| 314 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 315 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 316 | |
| 317 | if [ $res -ne 0 ]; then |
| 318 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 319 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 320 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 321 | return 1 |
| 322 | fi |
| 323 | fi |
| 324 | |
| 325 | ((RES_PASS++)) |
| 326 | echo -e $GREEN" PASS"$EGREEN |
| 327 | return 0 |
| 328 | |
| 329 | } |
| 330 | |
| 331 | # API Test function: GET /policy |
| 332 | #args: <response-code> <policy-id> [<template-file>] |
| 333 | # (Function for test scripts) |
| 334 | api_get_policy() { |
| 335 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 336 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 337 | ((RES_TEST++)) |
| 338 | |
| 339 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 340 | __print_err "<response-code> <policy-id> [<template-file>] " $@ |
| 341 | return 1 |
| 342 | fi |
| 343 | |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 344 | query="/policy?id=$UUID$2" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 345 | res="$(__do_curl_to_agent GET $query)" |
| 346 | status=${res:${#res}-3} |
| 347 | |
| 348 | if [ $status -ne $1 ]; then |
| 349 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 350 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 351 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 352 | return 1 |
| 353 | fi |
| 354 | |
| 355 | if [ $# -eq 3 ]; then |
| 356 | #Create a policy json to compare with |
| 357 | body=${res:0:${#res}-3} |
| 358 | file=".p.json" |
| 359 | sed 's/XXX/'${2}'/g' $3 > $file |
| 360 | targetJson=$(< $file) |
| 361 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 362 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 363 | if [ $res -ne 0 ]; then |
| 364 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 365 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 366 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 367 | return 1 |
| 368 | fi |
| 369 | fi |
| 370 | |
| 371 | ((RES_PASS++)) |
| 372 | echo -e $GREEN" PASS"$EGREEN |
| 373 | return 0 |
| 374 | } |
| 375 | |
| 376 | # API Test function: PUT /policy |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 377 | # args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>] |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 378 | # (Function for test scripts) |
| 379 | api_put_policy() { |
| 380 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 381 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 382 | ((RES_TEST++)) |
| 383 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 384 | if [ $# -lt 7 ] || [ $# -gt 8 ]; then |
| 385 | __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]" $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 386 | return 1 |
| 387 | fi |
| 388 | |
| 389 | ric=$3 |
| 390 | count=0 |
| 391 | max=1 |
| 392 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 393 | if [ $# -eq 8 ]; then |
| 394 | max=$8 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 395 | fi |
| 396 | |
| 397 | pid=$5 |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 398 | file=$7 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 399 | |
| 400 | while [ $count -lt $max ]; do |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 401 | query="/policy?id=$UUID$pid&ric=$ric&service=$2" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 402 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 403 | if [ $4 != "NOTYPE" ]; then |
| 404 | query=$query"&type=$4" |
| 405 | fi |
| 406 | |
| 407 | if [ $6 != NOTRANSIENT ]; then |
| 408 | query=$query"&transient=$6" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 409 | fi |
| 410 | |
| 411 | file=".p.json" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 412 | sed 's/XXX/'${pid}'/g' $7 > $file |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 413 | res="$(__do_curl_to_agent PUT $query $file)" |
| 414 | status=${res:${#res}-3} |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 415 | echo -ne " Creating "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 416 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 417 | echo " Created "$count"?("$max")" |
| 418 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 419 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 420 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 421 | return 1 |
| 422 | fi |
| 423 | |
| 424 | let pid=$pid+1 |
| 425 | let count=$count+1 |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 426 | echo -ne " Created "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 427 | done |
| 428 | echo "" |
| 429 | |
| 430 | ((RES_PASS++)) |
| 431 | echo -e $GREEN" PASS"$EGREEN |
| 432 | return 0 |
| 433 | } |
| 434 | |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 435 | # API Test function: PUT /policy to run in batch |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 436 | # args: <response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>] |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 437 | # (Function for test scripts) |
| 438 | api_put_policy_batch() { |
| 439 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 440 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 441 | ((RES_TEST++)) |
| 442 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 443 | if [ $# -lt 7 ] || [ $# -gt 8 ]; then |
| 444 | __print_err "<response-code> <service-name> <ric-id> <policytype-id> <policy-id> <transient> <template-file> [<count>]" $@ |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 445 | return 1 |
| 446 | fi |
| 447 | |
| 448 | ric=$3 |
| 449 | count=0 |
| 450 | max=1 |
| 451 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 452 | if [ $# -eq 8 ]; then |
| 453 | max=$8 |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 454 | fi |
| 455 | |
| 456 | pid=$5 |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 457 | file=$7 |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 458 | ARR="" |
| 459 | while [ $count -lt $max ]; do |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 460 | query="/policy?id=$UUID$pid&ric=$ric&service=$2" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 461 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 462 | if [ $4 != "NOTYPE" ]; then |
| 463 | query=$query"&type=$4" |
| 464 | fi |
| 465 | |
| 466 | if [ $6 != NOTRANSIENT ]; then |
| 467 | query=$query"&transient=$6" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 468 | fi |
| 469 | |
| 470 | file=".p.json" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 471 | sed 's/XXX/'${pid}'/g' $7 > $file |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 472 | res="$(__do_curl_to_agent PUT_BATCH $query $file)" |
| 473 | status=${res:${#res}-3} |
| 474 | echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" |
| 475 | |
| 476 | if [ $status -ne 200 ]; then |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 477 | echo " Requested(batch) "$count"?("$max")" |
| 478 | echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED |
| 479 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 480 | __check_stop_at_error |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 481 | return 1 |
| 482 | fi |
| 483 | cid=${res:0:${#res}-3} |
| 484 | ARR=$ARR" "$cid |
| 485 | let pid=$pid+1 |
| 486 | let count=$count+1 |
| 487 | echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" |
| 488 | done |
| 489 | |
| 490 | echo "" |
| 491 | count=0 |
| 492 | for cid in $ARR; do |
| 493 | |
| 494 | res="$(__do_curl_to_agent RESPONSE $cid)" |
| 495 | status=${res:${#res}-3} |
| 496 | echo -ne " Created(batch) "$count"("$max")${SAMELINE}" |
| 497 | |
| 498 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 499 | echo " Created(batch) "$count"?("$max")" |
| 500 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 501 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 502 | __check_stop_at_error |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 503 | return 1 |
| 504 | fi |
| 505 | |
| 506 | let count=$count+1 |
| 507 | echo -ne " Created(batch) "$count"("$max")${SAMELINE}" |
| 508 | done |
| 509 | |
| 510 | echo "" |
| 511 | |
| 512 | ((RES_PASS++)) |
| 513 | echo -e $GREEN" PASS"$EGREEN |
| 514 | return 0 |
| 515 | } |
| 516 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 517 | # API Test function: PUT /policy to run in i parallel for a number of rics |
| 518 | # 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> |
| 519 | # (Function for test scripts) |
| 520 | api_put_policy_parallel() { |
| 521 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 522 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 523 | ((RES_TEST++)) |
| 524 | |
| 525 | if [ $# -ne 10 ]; then |
| 526 | __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>" $@ |
| 527 | return 1 |
| 528 | fi |
| 529 | resp_code=$1; shift; |
| 530 | serv=$1; shift |
| 531 | ric_base=$1; shift; |
| 532 | num_rics=$1; shift; |
| 533 | type=$1; shift; |
| 534 | start_id=$1; shift; |
| 535 | transient=$1; shift; |
| 536 | template=$1; shift; |
| 537 | count=$1; shift; |
| 538 | pids=$1; shift; |
| 539 | |
| 540 | if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then |
| 541 | echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported" |
| 542 | echo " Info - will execute over agent REST" |
| 543 | fi |
| 544 | |
| 545 | if [ $serv == "NOSERVICE" ]; then |
| 546 | serv="" |
| 547 | fi |
| 548 | query="/policy?service=$serv" |
| 549 | |
| 550 | if [ $type != "NOTYPE" ]; then |
| 551 | query=$query"&type=$type" |
| 552 | fi |
| 553 | |
| 554 | if [ $transient != NOTRANSIENT ]; then |
| 555 | query=$query"&transient=$transient" |
| 556 | fi |
| 557 | |
| 558 | urlbase=${ADAPTER}${query} |
| 559 | |
| 560 | for ((i=1; i<=$pids; i++)) |
| 561 | do |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 562 | uuid=$UUID |
| 563 | if [ -z "$uuid" ]; then |
| 564 | uuid="NOUUID" |
| 565 | fi |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 566 | echo "" > ".pid${i}.res.txt" |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 567 | echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > ".pid${i}.txt" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 568 | echo $i |
| 569 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
| 570 | arg=$(echo {}) |
| 571 | echo " Parallel process $arg started" |
| 572 | tmp=$(< ".pid${arg}.txt") |
| 573 | python3 ../common/create_policies_process.py $tmp > .pid${arg}.res.txt |
| 574 | }' |
| 575 | msg="" |
| 576 | for ((i=1; i<=$pids; i++)) |
| 577 | do |
| 578 | file=".pid${i}.res.txt" |
| 579 | tmp=$(< $file) |
| 580 | if [ -z "$tmp" ]; then |
| 581 | echo " Process $i : unknown result (result file empty" |
| 582 | msg="failed" |
| 583 | else |
| 584 | res=${tmp:0:1} |
| 585 | if [ $res == "0" ]; then |
| 586 | echo " Process $i : OK" |
| 587 | else |
| 588 | echo " Process $i : failed - "${tmp:1} |
| 589 | msg="failed" |
| 590 | fi |
| 591 | fi |
| 592 | done |
| 593 | if [ -z $msg ]; then |
| 594 | echo " $(($count*$num_rics)) policies created/updated" |
| 595 | ((RES_PASS++)) |
| 596 | echo -e $GREEN" PASS"$EGREEN |
| 597 | return 0 |
| 598 | fi |
| 599 | |
| 600 | echo -e $RED" FAIL. One of more processes failed to execute" $ERED |
| 601 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 602 | __check_stop_at_error |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 603 | return 1 |
| 604 | } |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 605 | |
| 606 | # API Test function: DELETE /policy |
| 607 | # args: <response-code> <policy-id> [count] |
| 608 | # (Function for test scripts) |
| 609 | api_delete_policy() { |
| 610 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 611 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 612 | ((RES_TEST++)) |
| 613 | |
| 614 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 615 | __print_err "<response-code> <policy-id> [count]" $@ |
| 616 | return 1 |
| 617 | fi |
| 618 | |
| 619 | count=0 |
| 620 | max=1 |
| 621 | |
| 622 | if [ $# -eq 3 ]; then |
| 623 | max=$3 |
| 624 | fi |
| 625 | |
| 626 | pid=$2 |
| 627 | |
| 628 | while [ $count -lt $max ]; do |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 629 | query="/policy?id="$UUID$pid |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 630 | res="$(__do_curl_to_agent DELETE $query)" |
| 631 | status=${res:${#res}-3} |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 632 | echo -ne " Deleting "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 633 | |
| 634 | if [ $status -ne $1 ]; then |
| 635 | echo " Deleted "$count"?("$max")" |
| 636 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 637 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 638 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 639 | return 1 |
| 640 | fi |
| 641 | let pid=$pid+1 |
| 642 | let count=$count+1 |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 643 | echo -ne " Deleted "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 644 | done |
| 645 | echo "" |
| 646 | |
| 647 | ((RES_PASS++)) |
| 648 | echo -e $GREEN" PASS"$EGREEN |
| 649 | return 0 |
| 650 | } |
| 651 | |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 652 | # API Test function: DELETE /policy to run in batch |
| 653 | # args: <response-code> <policy-id> [count] |
| 654 | # (Function for test scripts) |
| 655 | api_delete_policy_batch() { |
| 656 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 657 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 658 | ((RES_TEST++)) |
| 659 | |
| 660 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 661 | __print_err "<response-code> <policy-id> [count]" $@ |
| 662 | return 1 |
| 663 | fi |
| 664 | |
| 665 | count=0 |
| 666 | max=1 |
| 667 | |
| 668 | if [ $# -eq 3 ]; then |
| 669 | max=$3 |
| 670 | fi |
| 671 | |
| 672 | pid=$2 |
| 673 | ARR="" |
| 674 | while [ $count -lt $max ]; do |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 675 | query="/policy?id="$UUID$pid |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 676 | res="$(__do_curl_to_agent DELETE_BATCH $query)" |
| 677 | status=${res:${#res}-3} |
| 678 | echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" |
| 679 | |
| 680 | if [ $status -ne 200 ]; then |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 681 | echo " Requested(batch) "$count"?("$max")" |
| 682 | echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED |
| 683 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 684 | __check_stop_at_error |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 685 | return 1 |
| 686 | fi |
| 687 | cid=${res:0:${#res}-3} |
| 688 | ARR=$ARR" "$cid |
| 689 | let pid=$pid+1 |
| 690 | let count=$count+1 |
| 691 | echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" |
| 692 | done |
| 693 | |
| 694 | echo "" |
| 695 | |
| 696 | count=0 |
| 697 | for cid in $ARR; do |
| 698 | |
| 699 | res="$(__do_curl_to_agent RESPONSE $cid)" |
| 700 | status=${res:${#res}-3} |
| 701 | echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}" |
| 702 | |
| 703 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 704 | echo " Deleted(batch) "$count"?("$max")" |
| 705 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 706 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 707 | __check_stop_at_error |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 708 | return 1 |
| 709 | fi |
| 710 | |
| 711 | let count=$count+1 |
| 712 | echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}" |
| 713 | done |
| 714 | |
| 715 | ((RES_PASS++)) |
| 716 | echo -e $GREEN" PASS"$EGREEN |
| 717 | return 0 |
| 718 | } |
| 719 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 720 | # API Test function: DELETE /policy to run in i parallel for a number of rics |
| 721 | # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads> |
| 722 | # (Function for test scripts) |
| 723 | api_delete_policy_parallel() { |
| 724 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 725 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 726 | ((RES_TEST++)) |
| 727 | |
| 728 | if [ $# -ne 5 ]; then |
| 729 | __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@ |
| 730 | return 1 |
| 731 | fi |
| 732 | resp_code=$1; shift; |
| 733 | num_rics=$1; shift; |
| 734 | start_id=$1; shift; |
| 735 | count=$1; shift; |
| 736 | pids=$1; shift; |
| 737 | |
| 738 | if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then |
| 739 | echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported" |
| 740 | echo " Info - will execute over agent REST" |
| 741 | fi |
| 742 | |
| 743 | query="/policy" |
| 744 | |
| 745 | urlbase=${ADAPTER}${query} |
| 746 | |
| 747 | for ((i=1; i<=$pids; i++)) |
| 748 | do |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 749 | uuid=$UUID |
| 750 | if [ -z "$uuid" ]; then |
| 751 | uuid="NOUUID" |
| 752 | fi |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 753 | echo "" > ".pid${i}.del.res.txt" |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 754 | echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > ".pid${i}.del.txt" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 755 | echo $i |
| 756 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
| 757 | arg=$(echo {}) |
| 758 | echo " Parallel process $arg started" |
| 759 | tmp=$(< ".pid${arg}.del.txt") |
| 760 | python3 ../common/delete_policies_process.py $tmp > .pid${arg}.del.res.txt |
| 761 | }' |
| 762 | msg="" |
| 763 | for ((i=1; i<=$pids; i++)) |
| 764 | do |
| 765 | file=".pid${i}.del.res.txt" |
| 766 | tmp=$(< $file) |
| 767 | if [ -z "$tmp" ]; then |
| 768 | echo " Process $i : unknown result (result file empty" |
| 769 | msg="failed" |
| 770 | else |
| 771 | res=${tmp:0:1} |
| 772 | if [ $res == "0" ]; then |
| 773 | echo " Process $i : OK" |
| 774 | else |
| 775 | echo " Process $i : failed - "${tmp:1} |
| 776 | msg="failed" |
| 777 | fi |
| 778 | fi |
| 779 | done |
| 780 | if [ -z $msg ]; then |
| 781 | echo " $(($count*$num_rics)) deleted" |
| 782 | ((RES_PASS++)) |
| 783 | echo -e $GREEN" PASS"$EGREEN |
| 784 | return 0 |
| 785 | fi |
| 786 | |
| 787 | echo -e $RED" FAIL. One of more processes failed to execute" $ERED |
| 788 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 789 | __check_stop_at_error |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 790 | return 1 |
| 791 | } |
| 792 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 793 | # API Test function: GET /policy_ids |
| 794 | # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID) |
| 795 | # (Function for test scripts) |
| 796 | api_get_policy_ids() { |
| 797 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 798 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 799 | ((RES_TEST++)) |
| 800 | |
| 801 | if [ $# -lt 4 ]; then |
| 802 | __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@ |
| 803 | return 1 |
| 804 | fi |
| 805 | |
| 806 | queryparams="" |
| 807 | |
| 808 | if [ $2 != "NORIC" ]; then |
| 809 | queryparams="?ric="$2 |
| 810 | fi |
| 811 | |
| 812 | if [ $3 != "NOSERVICE" ]; then |
| 813 | if [ -z $queryparams ]; then |
| 814 | queryparams="?service="$3 |
| 815 | else |
| 816 | queryparams=$queryparams"&service="$3 |
| 817 | fi |
| 818 | fi |
| 819 | if [ $4 != "NOTYPE" ]; then |
| 820 | if [ -z $queryparams ]; then |
| 821 | queryparams="?type="$4 |
| 822 | else |
| 823 | queryparams=$queryparams"&type="$4 |
| 824 | fi |
| 825 | fi |
| 826 | |
| 827 | query="/policy_ids"$queryparams |
| 828 | res="$(__do_curl_to_agent GET $query)" |
| 829 | status=${res:${#res}-3} |
| 830 | |
| 831 | if [ $status -ne $1 ]; then |
| 832 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 833 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 834 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 835 | return 1 |
| 836 | fi |
| 837 | |
| 838 | if [ $# -gt 4 ]; then |
| 839 | body=${res:0:${#res}-3} |
| 840 | targetJson="[" |
| 841 | |
| 842 | for pid in ${@:5} ; do |
| 843 | if [ "$targetJson" != "[" ]; then |
| 844 | targetJson=$targetJson"," |
| 845 | fi |
| 846 | if [ $pid != "NOID" ]; then |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 847 | targetJson=$targetJson"\"$UUID$pid\"" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 848 | fi |
| 849 | done |
| 850 | |
| 851 | targetJson=$targetJson"]" |
| 852 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 853 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 854 | |
| 855 | if [ $res -ne 0 ]; then |
| 856 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 857 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 858 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 859 | return 1 |
| 860 | fi |
| 861 | fi |
| 862 | |
| 863 | ((RES_PASS++)) |
| 864 | echo -e $GREEN" PASS"$EGREEN |
| 865 | return 0 |
| 866 | } |
| 867 | |
| 868 | # API Test function: GET /policy_schema |
| 869 | # args: <response-code> <policy-type-id> [<schema-file>] |
| 870 | # (Function for test scripts) |
| 871 | api_get_policy_schema() { |
| 872 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 873 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 874 | ((RES_TEST++)) |
| 875 | |
| 876 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 877 | __print_err "<response-code> <policy-type-id> [<schema-file>]" $@ |
| 878 | return 1 |
| 879 | fi |
| 880 | |
| 881 | query="/policy_schema?id=$2" |
| 882 | res="$(__do_curl_to_agent GET $query)" |
| 883 | status=${res:${#res}-3} |
| 884 | |
| 885 | if [ $status -ne $1 ]; then |
| 886 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 887 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 888 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 889 | return 1 |
| 890 | fi |
| 891 | |
| 892 | if [ $# -eq 3 ]; then |
| 893 | |
| 894 | body=${res:0:${#res}-3} |
| 895 | |
| 896 | targetJson=$(< $3) |
| 897 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 898 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 899 | |
| 900 | if [ $res -ne 0 ]; then |
| 901 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 902 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 903 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 904 | return 1 |
| 905 | fi |
| 906 | fi |
| 907 | |
| 908 | ((RES_PASS++)) |
| 909 | echo -e $GREEN" PASS"$EGREEN |
| 910 | return 0 |
| 911 | } |
| 912 | |
| 913 | # API Test function: GET /policy_schemas |
| 914 | # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]* |
| 915 | # (Function for test scripts) |
| 916 | api_get_policy_schemas() { |
| 917 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 918 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 919 | ((RES_TEST++)) |
| 920 | |
| 921 | if [ $# -lt 2 ]; then |
| 922 | __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@ |
| 923 | return 1 |
| 924 | fi |
| 925 | |
| 926 | query="/policy_schemas" |
| 927 | if [ $2 != "NORIC" ]; then |
| 928 | query=$query"?ric="$2 |
| 929 | fi |
| 930 | |
| 931 | res="$(__do_curl_to_agent GET $query)" |
| 932 | status=${res:${#res}-3} |
| 933 | |
| 934 | if [ $status -ne $1 ]; then |
| 935 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 936 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 937 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 938 | return 1 |
| 939 | fi |
| 940 | |
| 941 | if [ $# -gt 2 ]; then |
| 942 | body=${res:0:${#res}-3} |
| 943 | targetJson="[" |
| 944 | |
| 945 | for file in ${@:3} ; do |
| 946 | if [ "$targetJson" != "[" ]; then |
| 947 | targetJson=$targetJson"," |
| 948 | fi |
| 949 | if [ $file == "NOFILE" ]; then |
| 950 | targetJson=$targetJson"{}" |
| 951 | else |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 952 | targetJson=$targetJson$(< $file) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 953 | fi |
| 954 | done |
| 955 | |
| 956 | targetJson=$targetJson"]" |
| 957 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 958 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 959 | |
| 960 | if [ $res -ne 0 ]; then |
| 961 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 962 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 963 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 964 | return 1 |
| 965 | fi |
| 966 | fi |
| 967 | |
| 968 | ((RES_PASS++)) |
| 969 | echo -e $GREEN" PASS"$EGREEN |
| 970 | return 0 |
| 971 | } |
| 972 | |
| 973 | # API Test function: GET /policy_status |
| 974 | # arg: <response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>) |
| 975 | # (Function for test scripts) |
| 976 | api_get_policy_status() { |
| 977 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 978 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 979 | ((RES_TEST++)) |
| 980 | if [ $# -lt 4 ] || [ $# -gt 5 ]; then |
| 981 | __print_err "<response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@ |
| 982 | return 1 |
| 983 | fi |
| 984 | |
| 985 | targetJson="" |
| 986 | |
| 987 | if [ $3 == "STD" ]; then |
| 988 | targetJson="{\"enforceStatus\":\"$4\"" |
| 989 | if [ $# -eq 5 ]; then |
| 990 | targetJson=$targetJson",\"reason\":\"$5\"" |
| 991 | fi |
| 992 | targetJson=$targetJson"}" |
| 993 | elif [ $3 == "OSC" ]; then |
| 994 | targetJson="{\"instance_status\":\"$4\"" |
| 995 | if [ $# -eq 5 ]; then |
| 996 | targetJson=$targetJson",\"has_been_deleted\":\"$5\"" |
| 997 | fi |
| 998 | targetJson=$targetJson",\"created_at\":\"????\"}" |
| 999 | else |
| 1000 | __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@ |
| 1001 | return 1 |
| 1002 | fi |
| 1003 | |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 1004 | query="/policy_status?id="$UUID$2 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1005 | |
| 1006 | res="$(__do_curl_to_agent GET $query)" |
| 1007 | status=${res:${#res}-3} |
| 1008 | |
| 1009 | if [ $status -ne $1 ]; then |
| 1010 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1011 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1012 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1013 | return 1 |
| 1014 | fi |
| 1015 | |
| 1016 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
| 1017 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1018 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1019 | |
| 1020 | if [ $res -ne 0 ]; then |
| 1021 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 1022 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1023 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1024 | return 1 |
| 1025 | fi |
| 1026 | |
| 1027 | ((RES_PASS++)) |
| 1028 | echo -e $GREEN" PASS"$EGREEN |
| 1029 | return 0 |
| 1030 | } |
| 1031 | |
| 1032 | # API Test function: GET /policy_types |
| 1033 | # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]] |
| 1034 | # (Function for test scripts) |
| 1035 | api_get_policy_types() { |
| 1036 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1037 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1038 | ((RES_TEST++)) |
| 1039 | |
| 1040 | if [ $# -lt 1 ]; then |
| 1041 | __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@ |
| 1042 | return 1 |
| 1043 | fi |
| 1044 | |
| 1045 | if [ $# -eq 1 ]; then |
| 1046 | query="/policy_types" |
| 1047 | elif [ $2 == "NORIC" ]; then |
| 1048 | query="/policy_types" |
| 1049 | else |
| 1050 | query="/policy_types?ric=$2" |
| 1051 | fi |
| 1052 | |
| 1053 | res="$(__do_curl_to_agent GET $query)" |
| 1054 | status=${res:${#res}-3} |
| 1055 | |
| 1056 | if [ $status -ne $1 ]; then |
| 1057 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1058 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1059 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1060 | return 1 |
| 1061 | fi |
| 1062 | |
| 1063 | if [ $# -gt 2 ]; then |
| 1064 | body=${res:0:${#res}-3} |
| 1065 | targetJson="[" |
| 1066 | |
| 1067 | for pid in ${@:3} ; do |
| 1068 | if [ "$targetJson" != "[" ]; then |
| 1069 | targetJson=$targetJson"," |
| 1070 | fi |
| 1071 | if [ $pid == "EMPTY" ]; then |
| 1072 | pid="" |
| 1073 | fi |
| 1074 | targetJson=$targetJson"\"$pid\"" |
| 1075 | done |
| 1076 | |
| 1077 | targetJson=$targetJson"]" |
| 1078 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1079 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1080 | |
| 1081 | if [ $res -ne 0 ]; then |
| 1082 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 1083 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1084 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1085 | return 1 |
| 1086 | fi |
| 1087 | fi |
| 1088 | |
| 1089 | ((RES_PASS++)) |
| 1090 | echo -e $GREEN" PASS"$EGREEN |
| 1091 | return 0 |
| 1092 | } |
| 1093 | |
| 1094 | ######################################################### |
| 1095 | #### Test case functions Health check |
| 1096 | ######################################################### |
| 1097 | |
| 1098 | # API Test function: GET /status |
| 1099 | # args: <response-code> |
| 1100 | # (Function for test scripts) |
| 1101 | api_get_status() { |
| 1102 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1103 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1104 | ((RES_TEST++)) |
| 1105 | if [ $# -ne 1 ]; then |
| 1106 | __print_err "<response-code>" $@ |
| 1107 | return 1 |
| 1108 | fi |
| 1109 | query="/status" |
| 1110 | res="$(__do_curl_to_agent GET $query)" |
| 1111 | status=${res:${#res}-3} |
| 1112 | |
| 1113 | if [ $status -ne $1 ]; then |
| 1114 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1115 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1116 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1117 | return 1 |
| 1118 | fi |
| 1119 | |
| 1120 | ((RES_PASS++)) |
| 1121 | echo -e $GREEN" PASS"$EGREEN |
| 1122 | return 0 |
| 1123 | } |
| 1124 | |
| 1125 | ######################################################### |
| 1126 | #### Test case functions RIC Repository |
| 1127 | ######################################################### |
| 1128 | |
| 1129 | # API Test function: GET /ric |
| 1130 | # args: <reponse-code> <management-element-id> [<ric-id>] |
| 1131 | # (Function for test scripts) |
| 1132 | api_get_ric() { |
| 1133 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1134 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1135 | ((RES_TEST++)) |
| 1136 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 1137 | __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@ |
| 1138 | return 1 |
| 1139 | fi |
| 1140 | |
| 1141 | query="/ric?managedElementId="$2 |
| 1142 | |
| 1143 | res="$(__do_curl_to_agent GET $query)" |
| 1144 | status=${res:${#res}-3} |
| 1145 | |
| 1146 | if [ $status -ne $1 ]; then |
| 1147 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1148 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1149 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1150 | return 1 |
| 1151 | fi |
| 1152 | |
| 1153 | if [ $# -eq 3 ]; then |
| 1154 | body=${res:0:${#res}-3} |
| 1155 | if [ "$body" != "$3" ]; then |
| 1156 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 1157 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1158 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1159 | return 1 |
| 1160 | fi |
| 1161 | fi |
| 1162 | |
| 1163 | ((RES_PASS++)) |
| 1164 | echo -e $GREEN" PASS"$EGREEN |
| 1165 | return 0 |
| 1166 | } |
| 1167 | |
| 1168 | # API test function: GET /rics |
| 1169 | # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>] |
| 1170 | # 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_........." |
| 1171 | # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids> |
| 1172 | # (Function for test scripts) |
| 1173 | api_get_rics() { |
| 1174 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1175 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1176 | ((RES_TEST++)) |
| 1177 | |
| 1178 | if [ $# -lt 2 ]; then |
| 1179 | __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@ |
| 1180 | return 1 |
| 1181 | fi |
| 1182 | |
| 1183 | query="/rics" |
| 1184 | if [ $2 != "NOTYPE" ]; then |
| 1185 | query="/rics?policyType="$2 |
| 1186 | fi |
| 1187 | |
| 1188 | res="$(__do_curl_to_agent GET $query)" |
| 1189 | status=${res:${#res}-3} |
| 1190 | |
| 1191 | if [ $status -ne $1 ]; then |
| 1192 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1193 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1194 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1195 | return 1 |
| 1196 | fi |
| 1197 | |
| 1198 | if [ $# -gt 2 ]; then |
| 1199 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1200 | res=$(python3 ../common/create_rics_json.py ".tmp_rics.json" "$3" ) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1201 | if [ $res -ne 0 ]; then |
| 1202 | echo -e $RED" FAIL, could not create target ric info json"$ERED |
| 1203 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1204 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1205 | return 1 |
| 1206 | fi |
| 1207 | |
| 1208 | targetJson=$(<.tmp_rics.json) |
| 1209 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1210 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1211 | if [ $res -ne 0 ]; then |
| 1212 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 1213 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1214 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1215 | return 1 |
| 1216 | fi |
| 1217 | fi |
| 1218 | |
| 1219 | ((RES_PASS++)) |
| 1220 | echo -e $GREEN" PASS"$EGREEN |
| 1221 | return 0 |
| 1222 | } |
| 1223 | |
| 1224 | ################################################################## |
| 1225 | #### API Test case functions Service registry and supervision #### |
| 1226 | ################################################################## |
| 1227 | |
| 1228 | # API test function: PUT /service |
| 1229 | # args: <response-code> <service-name> <keepalive-timeout> <callbackurl> |
| 1230 | # (Function for test scripts) |
| 1231 | api_put_service() { |
| 1232 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1233 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1234 | ((RES_TEST++)) |
| 1235 | if [ $# -ne 4 ]; then |
| 1236 | __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@ |
| 1237 | return 1 |
| 1238 | fi |
| 1239 | |
| 1240 | query="/service" |
| 1241 | json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}" |
| 1242 | file=".tmp.json" |
| 1243 | echo "$json" > $file |
| 1244 | |
| 1245 | res="$(__do_curl_to_agent PUT $query $file)" |
| 1246 | status=${res:${#res}-3} |
| 1247 | |
| 1248 | if [ $status -ne $1 ]; then |
| 1249 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1250 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1251 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1252 | return 1 |
| 1253 | fi |
| 1254 | |
| 1255 | ((RES_PASS++)) |
| 1256 | echo -e $GREEN" PASS"$EGREEN |
| 1257 | return 0 |
| 1258 | } |
| 1259 | |
| 1260 | # API test function: GET /services |
| 1261 | #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>]* )] |
| 1262 | # (Function for test scripts) |
| 1263 | api_get_services() { |
| 1264 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1265 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1266 | ((RES_TEST++)) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1267 | #Number of accepted parameters: 1, 2, 4, 7, 10, 13,... |
| 1268 | paramError=1 |
| 1269 | if [ $# -eq 1 ]; then |
| 1270 | paramError=0 |
| 1271 | elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then |
| 1272 | paramError=0 |
| 1273 | elif [ $# -eq 5 ]; then |
| 1274 | paramError=0 |
| 1275 | elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then |
| 1276 | argLen=$(($#-2)) |
| 1277 | if [ $(($argLen%3)) -eq 0 ]; then |
| 1278 | paramError=0 |
| 1279 | fi |
| 1280 | fi |
| 1281 | |
| 1282 | if [ $paramError -ne 0 ]; then |
| 1283 | __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>]* )]" $@ |
| 1284 | return 1 |
| 1285 | fi |
| 1286 | |
| 1287 | query="/services" |
| 1288 | |
| 1289 | if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then |
| 1290 | query="/services?name="$2 |
| 1291 | fi |
| 1292 | |
| 1293 | res="$(__do_curl_to_agent GET $query)" |
| 1294 | status=${res:${#res}-3} |
| 1295 | |
| 1296 | if [ $status -ne $1 ]; then |
| 1297 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1298 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1299 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1300 | return 1 |
| 1301 | fi |
| 1302 | |
| 1303 | if [ $# -gt 2 ]; then |
| 1304 | variableArgCount=$(($#-2)) |
| 1305 | body=${res:0:${#res}-3} |
| 1306 | targetJson="[" |
| 1307 | shift; shift; |
| 1308 | cntr=0 |
| 1309 | while [ $cntr -lt $variableArgCount ]; do |
| 1310 | servicename=$1; shift; |
| 1311 | timeout=$1; shift; |
| 1312 | callback=$1; shift; |
| 1313 | if [ $cntr -gt 0 ]; then |
| 1314 | targetJson=$targetJson"," |
| 1315 | fi |
| 1316 | # timeSinceLastActivitySeconds value cannot be checked since value varies |
| 1317 | targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}" |
| 1318 | let cntr=cntr+3 |
| 1319 | done |
| 1320 | targetJson=$targetJson"]" |
| 1321 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1322 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1323 | if [ $res -ne 0 ]; then |
| 1324 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 1325 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1326 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1327 | return 1 |
| 1328 | fi |
| 1329 | fi |
| 1330 | |
| 1331 | ((RES_PASS++)) |
| 1332 | echo -e $GREEN" PASS"$EGREEN |
| 1333 | return 0 |
| 1334 | } |
| 1335 | |
| 1336 | # API test function: GET /services (only checking service names) |
| 1337 | # args: <response-code> [<service-name>]*" |
| 1338 | # (Function for test scripts) |
| 1339 | api_get_service_ids() { |
| 1340 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1341 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1342 | ((RES_TEST++)) |
| 1343 | |
| 1344 | if [ $# -lt 1 ]; then |
| 1345 | __print_err "<response-code> [<service-name>]*" $@ |
| 1346 | return 1 |
| 1347 | fi |
| 1348 | |
| 1349 | query="/services" |
| 1350 | res="$(__do_curl_to_agent GET $query)" |
| 1351 | status=${res:${#res}-3} |
| 1352 | |
| 1353 | if [ $status -ne $1 ]; then |
| 1354 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1355 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1356 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1357 | return 1 |
| 1358 | fi |
| 1359 | |
| 1360 | body=${res:0:${#res}-3} |
| 1361 | targetJson="[" |
| 1362 | for rapp in ${@:2} ; do |
| 1363 | if [ "$targetJson" != "[" ]; then |
| 1364 | targetJson=$targetJson"," |
| 1365 | fi |
| 1366 | targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}" |
| 1367 | done |
| 1368 | |
| 1369 | targetJson=$targetJson"]" |
| 1370 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1371 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1372 | |
| 1373 | if [ $res -ne 0 ]; then |
| 1374 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 1375 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1376 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1377 | return 1 |
| 1378 | fi |
| 1379 | |
| 1380 | ((RES_PASS++)) |
| 1381 | echo -e $GREEN" PASS"$EGREEN |
| 1382 | return 0 |
| 1383 | } |
| 1384 | |
| 1385 | # API test function: DELETE /services |
| 1386 | # args: <response-code> <service-name> |
| 1387 | # (Function for test scripts) |
| 1388 | api_delete_services() { |
| 1389 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1390 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1391 | ((RES_TEST++)) |
| 1392 | |
| 1393 | if [ $# -ne 2 ]; then |
| 1394 | __print_err "<response-code> <service-name>" $@ |
| 1395 | return 1 |
| 1396 | fi |
| 1397 | |
| 1398 | query="/services?name="$2 |
| 1399 | res="$(__do_curl_to_agent DELETE $query)" |
| 1400 | status=${res:${#res}-3} |
| 1401 | |
| 1402 | if [ $status -ne $1 ]; then |
| 1403 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1404 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1405 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1406 | return 1 |
| 1407 | fi |
| 1408 | |
| 1409 | ((RES_PASS++)) |
| 1410 | echo -e $GREEN" PASS"$EGREEN |
| 1411 | return 0 |
| 1412 | } |
| 1413 | |
| 1414 | # API test function: PUT /services/keepalive |
| 1415 | # args: <response-code> <service-name> |
| 1416 | # (Function for test scripts) |
| 1417 | api_put_services_keepalive() { |
| 1418 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1419 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1420 | ((RES_TEST++)) |
| 1421 | |
| 1422 | if [ $# -ne 2 ]; then |
| 1423 | __print_err "<response-code> <service-name>" $@ |
| 1424 | return 1 |
| 1425 | fi |
| 1426 | |
| 1427 | query="/services/keepalive?name="$2 |
| 1428 | res="$(__do_curl_to_agent PUT $query)" |
| 1429 | status=${res:${#res}-3} |
| 1430 | |
| 1431 | if [ $status -ne $1 ]; then |
| 1432 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1433 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame] | 1434 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1435 | return 1 |
| 1436 | fi |
| 1437 | |
| 1438 | ((RES_PASS++)) |
| 1439 | echo -e $GREEN" PASS"$EGREEN |
| 1440 | return 0 |
| 1441 | } |
| 1442 | |