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 |
| 254 | __print_err "<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>]*]" $@ |
| 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 |
| 300 | targetJson=$targetJson"{\"id\":\"${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":" |
| 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 | |
| 344 | query="/policy?id=$2" |
| 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 |
| 401 | query="/policy?id=$pid&ric=$ric&service=$2" |
| 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 |
| 417 | let pid=$pid+1 |
| 418 | echo " Created "$count"?("$max")" |
| 419 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 420 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 421 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 422 | return 1 |
| 423 | fi |
| 424 | |
| 425 | let pid=$pid+1 |
| 426 | let count=$count+1 |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 427 | echo -ne " Created "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 428 | done |
| 429 | echo "" |
| 430 | |
| 431 | ((RES_PASS++)) |
| 432 | echo -e $GREEN" PASS"$EGREEN |
| 433 | return 0 |
| 434 | } |
| 435 | |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 436 | # API Test function: PUT /policy to run in batch |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 437 | # 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] | 438 | # (Function for test scripts) |
| 439 | api_put_policy_batch() { |
| 440 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 441 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 442 | ((RES_TEST++)) |
| 443 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 444 | if [ $# -lt 7 ] || [ $# -gt 8 ]; then |
| 445 | __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] | 446 | return 1 |
| 447 | fi |
| 448 | |
| 449 | ric=$3 |
| 450 | count=0 |
| 451 | max=1 |
| 452 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 453 | if [ $# -eq 8 ]; then |
| 454 | max=$8 |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 455 | fi |
| 456 | |
| 457 | pid=$5 |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 458 | file=$7 |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 459 | ARR="" |
| 460 | while [ $count -lt $max ]; do |
| 461 | query="/policy?id=$pid&ric=$ric&service=$2" |
| 462 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 463 | if [ $4 != "NOTYPE" ]; then |
| 464 | query=$query"&type=$4" |
| 465 | fi |
| 466 | |
| 467 | if [ $6 != NOTRANSIENT ]; then |
| 468 | query=$query"&transient=$6" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 469 | fi |
| 470 | |
| 471 | file=".p.json" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 472 | sed 's/XXX/'${pid}'/g' $7 > $file |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 473 | res="$(__do_curl_to_agent PUT_BATCH $query $file)" |
| 474 | status=${res:${#res}-3} |
| 475 | echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" |
| 476 | |
| 477 | if [ $status -ne 200 ]; then |
| 478 | let pid=$pid+1 |
| 479 | echo " Requested(batch) "$count"?("$max")" |
| 480 | echo -e $RED" FAIL. Exepected status 200 (in request), got "$status $ERED |
| 481 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 482 | __check_stop_at_error |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 483 | return 1 |
| 484 | fi |
| 485 | cid=${res:0:${#res}-3} |
| 486 | ARR=$ARR" "$cid |
| 487 | let pid=$pid+1 |
| 488 | let count=$count+1 |
| 489 | echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" |
| 490 | done |
| 491 | |
| 492 | echo "" |
| 493 | count=0 |
| 494 | for cid in $ARR; do |
| 495 | |
| 496 | res="$(__do_curl_to_agent RESPONSE $cid)" |
| 497 | status=${res:${#res}-3} |
| 498 | echo -ne " Created(batch) "$count"("$max")${SAMELINE}" |
| 499 | |
| 500 | if [ $status -ne $1 ]; then |
| 501 | let pid=$pid+1 |
| 502 | echo " Created(batch) "$count"?("$max")" |
| 503 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 504 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 505 | __check_stop_at_error |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 506 | return 1 |
| 507 | fi |
| 508 | |
| 509 | let count=$count+1 |
| 510 | echo -ne " Created(batch) "$count"("$max")${SAMELINE}" |
| 511 | done |
| 512 | |
| 513 | echo "" |
| 514 | |
| 515 | ((RES_PASS++)) |
| 516 | echo -e $GREEN" PASS"$EGREEN |
| 517 | return 0 |
| 518 | } |
| 519 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 520 | # API Test function: PUT /policy to run in i parallel for a number of rics |
| 521 | # 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> |
| 522 | # (Function for test scripts) |
| 523 | api_put_policy_parallel() { |
| 524 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 525 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 526 | ((RES_TEST++)) |
| 527 | |
| 528 | if [ $# -ne 10 ]; then |
| 529 | __print_err " <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <template-file> <count-per-ric> <number-of-threads>" $@ |
| 530 | return 1 |
| 531 | fi |
| 532 | resp_code=$1; shift; |
| 533 | serv=$1; shift |
| 534 | ric_base=$1; shift; |
| 535 | num_rics=$1; shift; |
| 536 | type=$1; shift; |
| 537 | start_id=$1; shift; |
| 538 | transient=$1; shift; |
| 539 | template=$1; shift; |
| 540 | count=$1; shift; |
| 541 | pids=$1; shift; |
| 542 | |
| 543 | if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then |
| 544 | echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported" |
| 545 | echo " Info - will execute over agent REST" |
| 546 | fi |
| 547 | |
| 548 | if [ $serv == "NOSERVICE" ]; then |
| 549 | serv="" |
| 550 | fi |
| 551 | query="/policy?service=$serv" |
| 552 | |
| 553 | if [ $type != "NOTYPE" ]; then |
| 554 | query=$query"&type=$type" |
| 555 | fi |
| 556 | |
| 557 | if [ $transient != NOTRANSIENT ]; then |
| 558 | query=$query"&transient=$transient" |
| 559 | fi |
| 560 | |
| 561 | urlbase=${ADAPTER}${query} |
| 562 | |
| 563 | for ((i=1; i<=$pids; i++)) |
| 564 | do |
| 565 | echo "" > ".pid${i}.res.txt" |
| 566 | echo $resp_code $urlbase $ric_base $num_rics $start_id $template $count $pids $i > ".pid${i}.txt" |
| 567 | echo $i |
| 568 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
| 569 | arg=$(echo {}) |
| 570 | echo " Parallel process $arg started" |
| 571 | tmp=$(< ".pid${arg}.txt") |
| 572 | python3 ../common/create_policies_process.py $tmp > .pid${arg}.res.txt |
| 573 | }' |
| 574 | msg="" |
| 575 | for ((i=1; i<=$pids; i++)) |
| 576 | do |
| 577 | file=".pid${i}.res.txt" |
| 578 | tmp=$(< $file) |
| 579 | if [ -z "$tmp" ]; then |
| 580 | echo " Process $i : unknown result (result file empty" |
| 581 | msg="failed" |
| 582 | else |
| 583 | res=${tmp:0:1} |
| 584 | if [ $res == "0" ]; then |
| 585 | echo " Process $i : OK" |
| 586 | else |
| 587 | echo " Process $i : failed - "${tmp:1} |
| 588 | msg="failed" |
| 589 | fi |
| 590 | fi |
| 591 | done |
| 592 | if [ -z $msg ]; then |
| 593 | echo " $(($count*$num_rics)) policies created/updated" |
| 594 | ((RES_PASS++)) |
| 595 | echo -e $GREEN" PASS"$EGREEN |
| 596 | return 0 |
| 597 | fi |
| 598 | |
| 599 | echo -e $RED" FAIL. One of more processes failed to execute" $ERED |
| 600 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 601 | __check_stop_at_error |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 602 | return 1 |
| 603 | } |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 604 | |
| 605 | # API Test function: DELETE /policy |
| 606 | # args: <response-code> <policy-id> [count] |
| 607 | # (Function for test scripts) |
| 608 | api_delete_policy() { |
| 609 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 610 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 611 | ((RES_TEST++)) |
| 612 | |
| 613 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 614 | __print_err "<response-code> <policy-id> [count]" $@ |
| 615 | return 1 |
| 616 | fi |
| 617 | |
| 618 | count=0 |
| 619 | max=1 |
| 620 | |
| 621 | if [ $# -eq 3 ]; then |
| 622 | max=$3 |
| 623 | fi |
| 624 | |
| 625 | pid=$2 |
| 626 | |
| 627 | while [ $count -lt $max ]; do |
| 628 | query="/policy?id="$pid |
| 629 | res="$(__do_curl_to_agent DELETE $query)" |
| 630 | status=${res:${#res}-3} |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 631 | echo -ne " Deleting "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 632 | |
| 633 | if [ $status -ne $1 ]; then |
| 634 | echo " Deleted "$count"?("$max")" |
| 635 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 636 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 637 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 638 | return 1 |
| 639 | fi |
| 640 | let pid=$pid+1 |
| 641 | let count=$count+1 |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 642 | echo -ne " Deleted "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 643 | done |
| 644 | echo "" |
| 645 | |
| 646 | ((RES_PASS++)) |
| 647 | echo -e $GREEN" PASS"$EGREEN |
| 648 | return 0 |
| 649 | } |
| 650 | |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 651 | # API Test function: DELETE /policy to run in batch |
| 652 | # args: <response-code> <policy-id> [count] |
| 653 | # (Function for test scripts) |
| 654 | api_delete_policy_batch() { |
| 655 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 656 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 657 | ((RES_TEST++)) |
| 658 | |
| 659 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 660 | __print_err "<response-code> <policy-id> [count]" $@ |
| 661 | return 1 |
| 662 | fi |
| 663 | |
| 664 | count=0 |
| 665 | max=1 |
| 666 | |
| 667 | if [ $# -eq 3 ]; then |
| 668 | max=$3 |
| 669 | fi |
| 670 | |
| 671 | pid=$2 |
| 672 | ARR="" |
| 673 | while [ $count -lt $max ]; do |
| 674 | query="/policy?id="$pid |
| 675 | res="$(__do_curl_to_agent DELETE_BATCH $query)" |
| 676 | status=${res:${#res}-3} |
| 677 | echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" |
| 678 | |
| 679 | if [ $status -ne 200 ]; then |
| 680 | let pid=$pid+1 |
| 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 |
| 704 | let pid=$pid+1 |
| 705 | echo " Deleted(batch) "$count"?("$max")" |
| 706 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 707 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 708 | __check_stop_at_error |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 709 | return 1 |
| 710 | fi |
| 711 | |
| 712 | let count=$count+1 |
| 713 | echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}" |
| 714 | done |
| 715 | |
| 716 | ((RES_PASS++)) |
| 717 | echo -e $GREEN" PASS"$EGREEN |
| 718 | return 0 |
| 719 | } |
| 720 | |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 721 | # API Test function: DELETE /policy to run in i parallel for a number of rics |
| 722 | # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads> |
| 723 | # (Function for test scripts) |
| 724 | api_delete_policy_parallel() { |
| 725 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 726 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 727 | ((RES_TEST++)) |
| 728 | |
| 729 | if [ $# -ne 5 ]; then |
| 730 | __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@ |
| 731 | return 1 |
| 732 | fi |
| 733 | resp_code=$1; shift; |
| 734 | num_rics=$1; shift; |
| 735 | start_id=$1; shift; |
| 736 | count=$1; shift; |
| 737 | pids=$1; shift; |
| 738 | |
| 739 | if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then |
| 740 | echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported" |
| 741 | echo " Info - will execute over agent REST" |
| 742 | fi |
| 743 | |
| 744 | query="/policy" |
| 745 | |
| 746 | urlbase=${ADAPTER}${query} |
| 747 | |
| 748 | for ((i=1; i<=$pids; i++)) |
| 749 | do |
| 750 | echo "" > ".pid${i}.del.res.txt" |
| 751 | echo $resp_code $urlbase $num_rics $start_id $count $pids $i > ".pid${i}.del.txt" |
| 752 | echo $i |
| 753 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
| 754 | arg=$(echo {}) |
| 755 | echo " Parallel process $arg started" |
| 756 | tmp=$(< ".pid${arg}.del.txt") |
| 757 | python3 ../common/delete_policies_process.py $tmp > .pid${arg}.del.res.txt |
| 758 | }' |
| 759 | msg="" |
| 760 | for ((i=1; i<=$pids; i++)) |
| 761 | do |
| 762 | file=".pid${i}.del.res.txt" |
| 763 | tmp=$(< $file) |
| 764 | if [ -z "$tmp" ]; then |
| 765 | echo " Process $i : unknown result (result file empty" |
| 766 | msg="failed" |
| 767 | else |
| 768 | res=${tmp:0:1} |
| 769 | if [ $res == "0" ]; then |
| 770 | echo " Process $i : OK" |
| 771 | else |
| 772 | echo " Process $i : failed - "${tmp:1} |
| 773 | msg="failed" |
| 774 | fi |
| 775 | fi |
| 776 | done |
| 777 | if [ -z $msg ]; then |
| 778 | echo " $(($count*$num_rics)) deleted" |
| 779 | ((RES_PASS++)) |
| 780 | echo -e $GREEN" PASS"$EGREEN |
| 781 | return 0 |
| 782 | fi |
| 783 | |
| 784 | echo -e $RED" FAIL. One of more processes failed to execute" $ERED |
| 785 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 786 | __check_stop_at_error |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 787 | return 1 |
| 788 | } |
| 789 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 790 | # API Test function: GET /policy_ids |
| 791 | # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID) |
| 792 | # (Function for test scripts) |
| 793 | api_get_policy_ids() { |
| 794 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 795 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 796 | ((RES_TEST++)) |
| 797 | |
| 798 | if [ $# -lt 4 ]; then |
| 799 | __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@ |
| 800 | return 1 |
| 801 | fi |
| 802 | |
| 803 | queryparams="" |
| 804 | |
| 805 | if [ $2 != "NORIC" ]; then |
| 806 | queryparams="?ric="$2 |
| 807 | fi |
| 808 | |
| 809 | if [ $3 != "NOSERVICE" ]; then |
| 810 | if [ -z $queryparams ]; then |
| 811 | queryparams="?service="$3 |
| 812 | else |
| 813 | queryparams=$queryparams"&service="$3 |
| 814 | fi |
| 815 | fi |
| 816 | if [ $4 != "NOTYPE" ]; then |
| 817 | if [ -z $queryparams ]; then |
| 818 | queryparams="?type="$4 |
| 819 | else |
| 820 | queryparams=$queryparams"&type="$4 |
| 821 | fi |
| 822 | fi |
| 823 | |
| 824 | query="/policy_ids"$queryparams |
| 825 | res="$(__do_curl_to_agent GET $query)" |
| 826 | status=${res:${#res}-3} |
| 827 | |
| 828 | if [ $status -ne $1 ]; then |
| 829 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 830 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 831 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 832 | return 1 |
| 833 | fi |
| 834 | |
| 835 | if [ $# -gt 4 ]; then |
| 836 | body=${res:0:${#res}-3} |
| 837 | targetJson="[" |
| 838 | |
| 839 | for pid in ${@:5} ; do |
| 840 | if [ "$targetJson" != "[" ]; then |
| 841 | targetJson=$targetJson"," |
| 842 | fi |
| 843 | if [ $pid != "NOID" ]; then |
| 844 | targetJson=$targetJson"\"$pid\"" |
| 845 | fi |
| 846 | done |
| 847 | |
| 848 | targetJson=$targetJson"]" |
| 849 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 850 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 851 | |
| 852 | if [ $res -ne 0 ]; then |
| 853 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 854 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 855 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 856 | return 1 |
| 857 | fi |
| 858 | fi |
| 859 | |
| 860 | ((RES_PASS++)) |
| 861 | echo -e $GREEN" PASS"$EGREEN |
| 862 | return 0 |
| 863 | } |
| 864 | |
| 865 | # API Test function: GET /policy_schema |
| 866 | # args: <response-code> <policy-type-id> [<schema-file>] |
| 867 | # (Function for test scripts) |
| 868 | api_get_policy_schema() { |
| 869 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 870 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 871 | ((RES_TEST++)) |
| 872 | |
| 873 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 874 | __print_err "<response-code> <policy-type-id> [<schema-file>]" $@ |
| 875 | return 1 |
| 876 | fi |
| 877 | |
| 878 | query="/policy_schema?id=$2" |
| 879 | res="$(__do_curl_to_agent GET $query)" |
| 880 | status=${res:${#res}-3} |
| 881 | |
| 882 | if [ $status -ne $1 ]; then |
| 883 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 884 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 885 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 886 | return 1 |
| 887 | fi |
| 888 | |
| 889 | if [ $# -eq 3 ]; then |
| 890 | |
| 891 | body=${res:0:${#res}-3} |
| 892 | |
| 893 | targetJson=$(< $3) |
| 894 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 895 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 896 | |
| 897 | if [ $res -ne 0 ]; then |
| 898 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 899 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 900 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 901 | return 1 |
| 902 | fi |
| 903 | fi |
| 904 | |
| 905 | ((RES_PASS++)) |
| 906 | echo -e $GREEN" PASS"$EGREEN |
| 907 | return 0 |
| 908 | } |
| 909 | |
| 910 | # API Test function: GET /policy_schemas |
| 911 | # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]* |
| 912 | # (Function for test scripts) |
| 913 | api_get_policy_schemas() { |
| 914 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 915 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 916 | ((RES_TEST++)) |
| 917 | |
| 918 | if [ $# -lt 2 ]; then |
| 919 | __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@ |
| 920 | return 1 |
| 921 | fi |
| 922 | |
| 923 | query="/policy_schemas" |
| 924 | if [ $2 != "NORIC" ]; then |
| 925 | query=$query"?ric="$2 |
| 926 | fi |
| 927 | |
| 928 | res="$(__do_curl_to_agent GET $query)" |
| 929 | status=${res:${#res}-3} |
| 930 | |
| 931 | if [ $status -ne $1 ]; then |
| 932 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 933 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 934 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 935 | return 1 |
| 936 | fi |
| 937 | |
| 938 | if [ $# -gt 2 ]; then |
| 939 | body=${res:0:${#res}-3} |
| 940 | targetJson="[" |
| 941 | |
| 942 | for file in ${@:3} ; do |
| 943 | if [ "$targetJson" != "[" ]; then |
| 944 | targetJson=$targetJson"," |
| 945 | fi |
| 946 | if [ $file == "NOFILE" ]; then |
| 947 | targetJson=$targetJson"{}" |
| 948 | else |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 949 | targetJson=$targetJson$(< $file) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 950 | fi |
| 951 | done |
| 952 | |
| 953 | targetJson=$targetJson"]" |
| 954 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 955 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 956 | |
| 957 | if [ $res -ne 0 ]; then |
| 958 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 959 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 960 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 961 | return 1 |
| 962 | fi |
| 963 | fi |
| 964 | |
| 965 | ((RES_PASS++)) |
| 966 | echo -e $GREEN" PASS"$EGREEN |
| 967 | return 0 |
| 968 | } |
| 969 | |
| 970 | # API Test function: GET /policy_status |
| 971 | # arg: <response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>) |
| 972 | # (Function for test scripts) |
| 973 | api_get_policy_status() { |
| 974 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 975 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 976 | ((RES_TEST++)) |
| 977 | if [ $# -lt 4 ] || [ $# -gt 5 ]; then |
| 978 | __print_err "<response-code> <policy-id> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@ |
| 979 | return 1 |
| 980 | fi |
| 981 | |
| 982 | targetJson="" |
| 983 | |
| 984 | if [ $3 == "STD" ]; then |
| 985 | targetJson="{\"enforceStatus\":\"$4\"" |
| 986 | if [ $# -eq 5 ]; then |
| 987 | targetJson=$targetJson",\"reason\":\"$5\"" |
| 988 | fi |
| 989 | targetJson=$targetJson"}" |
| 990 | elif [ $3 == "OSC" ]; then |
| 991 | targetJson="{\"instance_status\":\"$4\"" |
| 992 | if [ $# -eq 5 ]; then |
| 993 | targetJson=$targetJson",\"has_been_deleted\":\"$5\"" |
| 994 | fi |
| 995 | targetJson=$targetJson",\"created_at\":\"????\"}" |
| 996 | else |
| 997 | __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@ |
| 998 | return 1 |
| 999 | fi |
| 1000 | |
| 1001 | query="/policy_status?id="$2 |
| 1002 | |
| 1003 | res="$(__do_curl_to_agent GET $query)" |
| 1004 | status=${res:${#res}-3} |
| 1005 | |
| 1006 | if [ $status -ne $1 ]; then |
| 1007 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1008 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1009 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1010 | return 1 |
| 1011 | fi |
| 1012 | |
| 1013 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
| 1014 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1015 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1016 | |
| 1017 | if [ $res -ne 0 ]; then |
| 1018 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 1019 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1020 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1021 | return 1 |
| 1022 | fi |
| 1023 | |
| 1024 | ((RES_PASS++)) |
| 1025 | echo -e $GREEN" PASS"$EGREEN |
| 1026 | return 0 |
| 1027 | } |
| 1028 | |
| 1029 | # API Test function: GET /policy_types |
| 1030 | # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]] |
| 1031 | # (Function for test scripts) |
| 1032 | api_get_policy_types() { |
| 1033 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1034 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1035 | ((RES_TEST++)) |
| 1036 | |
| 1037 | if [ $# -lt 1 ]; then |
| 1038 | __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@ |
| 1039 | return 1 |
| 1040 | fi |
| 1041 | |
| 1042 | if [ $# -eq 1 ]; then |
| 1043 | query="/policy_types" |
| 1044 | elif [ $2 == "NORIC" ]; then |
| 1045 | query="/policy_types" |
| 1046 | else |
| 1047 | query="/policy_types?ric=$2" |
| 1048 | fi |
| 1049 | |
| 1050 | res="$(__do_curl_to_agent GET $query)" |
| 1051 | status=${res:${#res}-3} |
| 1052 | |
| 1053 | if [ $status -ne $1 ]; then |
| 1054 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1055 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1056 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1057 | return 1 |
| 1058 | fi |
| 1059 | |
| 1060 | if [ $# -gt 2 ]; then |
| 1061 | body=${res:0:${#res}-3} |
| 1062 | targetJson="[" |
| 1063 | |
| 1064 | for pid in ${@:3} ; do |
| 1065 | if [ "$targetJson" != "[" ]; then |
| 1066 | targetJson=$targetJson"," |
| 1067 | fi |
| 1068 | if [ $pid == "EMPTY" ]; then |
| 1069 | pid="" |
| 1070 | fi |
| 1071 | targetJson=$targetJson"\"$pid\"" |
| 1072 | done |
| 1073 | |
| 1074 | targetJson=$targetJson"]" |
| 1075 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1076 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1077 | |
| 1078 | if [ $res -ne 0 ]; then |
| 1079 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 1080 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1081 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1082 | return 1 |
| 1083 | fi |
| 1084 | fi |
| 1085 | |
| 1086 | ((RES_PASS++)) |
| 1087 | echo -e $GREEN" PASS"$EGREEN |
| 1088 | return 0 |
| 1089 | } |
| 1090 | |
| 1091 | ######################################################### |
| 1092 | #### Test case functions Health check |
| 1093 | ######################################################### |
| 1094 | |
| 1095 | # API Test function: GET /status |
| 1096 | # args: <response-code> |
| 1097 | # (Function for test scripts) |
| 1098 | api_get_status() { |
| 1099 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1100 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1101 | ((RES_TEST++)) |
| 1102 | if [ $# -ne 1 ]; then |
| 1103 | __print_err "<response-code>" $@ |
| 1104 | return 1 |
| 1105 | fi |
| 1106 | query="/status" |
| 1107 | res="$(__do_curl_to_agent GET $query)" |
| 1108 | status=${res:${#res}-3} |
| 1109 | |
| 1110 | if [ $status -ne $1 ]; then |
| 1111 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1112 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1113 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1114 | return 1 |
| 1115 | fi |
| 1116 | |
| 1117 | ((RES_PASS++)) |
| 1118 | echo -e $GREEN" PASS"$EGREEN |
| 1119 | return 0 |
| 1120 | } |
| 1121 | |
| 1122 | ######################################################### |
| 1123 | #### Test case functions RIC Repository |
| 1124 | ######################################################### |
| 1125 | |
| 1126 | # API Test function: GET /ric |
| 1127 | # args: <reponse-code> <management-element-id> [<ric-id>] |
| 1128 | # (Function for test scripts) |
| 1129 | api_get_ric() { |
| 1130 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1131 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1132 | ((RES_TEST++)) |
| 1133 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 1134 | __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@ |
| 1135 | return 1 |
| 1136 | fi |
| 1137 | |
| 1138 | query="/ric?managedElementId="$2 |
| 1139 | |
| 1140 | res="$(__do_curl_to_agent GET $query)" |
| 1141 | status=${res:${#res}-3} |
| 1142 | |
| 1143 | if [ $status -ne $1 ]; then |
| 1144 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1145 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1146 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1147 | return 1 |
| 1148 | fi |
| 1149 | |
| 1150 | if [ $# -eq 3 ]; then |
| 1151 | body=${res:0:${#res}-3} |
| 1152 | if [ "$body" != "$3" ]; then |
| 1153 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 1154 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1155 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1156 | return 1 |
| 1157 | fi |
| 1158 | fi |
| 1159 | |
| 1160 | ((RES_PASS++)) |
| 1161 | echo -e $GREEN" PASS"$EGREEN |
| 1162 | return 0 |
| 1163 | } |
| 1164 | |
| 1165 | # API test function: GET /rics |
| 1166 | # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>] |
| 1167 | # 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_........." |
| 1168 | # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids> |
| 1169 | # (Function for test scripts) |
| 1170 | api_get_rics() { |
| 1171 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1172 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1173 | ((RES_TEST++)) |
| 1174 | |
| 1175 | if [ $# -lt 2 ]; then |
| 1176 | __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@ |
| 1177 | return 1 |
| 1178 | fi |
| 1179 | |
| 1180 | query="/rics" |
| 1181 | if [ $2 != "NOTYPE" ]; then |
| 1182 | query="/rics?policyType="$2 |
| 1183 | fi |
| 1184 | |
| 1185 | res="$(__do_curl_to_agent GET $query)" |
| 1186 | status=${res:${#res}-3} |
| 1187 | |
| 1188 | if [ $status -ne $1 ]; then |
| 1189 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1190 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1191 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1192 | return 1 |
| 1193 | fi |
| 1194 | |
| 1195 | if [ $# -gt 2 ]; then |
| 1196 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1197 | res=$(python3 ../common/create_rics_json.py ".tmp_rics.json" "$3" ) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1198 | if [ $res -ne 0 ]; then |
| 1199 | echo -e $RED" FAIL, could not create target ric info json"$ERED |
| 1200 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1201 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1202 | return 1 |
| 1203 | fi |
| 1204 | |
| 1205 | targetJson=$(<.tmp_rics.json) |
| 1206 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1207 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1208 | if [ $res -ne 0 ]; then |
| 1209 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 1210 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1211 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1212 | return 1 |
| 1213 | fi |
| 1214 | fi |
| 1215 | |
| 1216 | ((RES_PASS++)) |
| 1217 | echo -e $GREEN" PASS"$EGREEN |
| 1218 | return 0 |
| 1219 | } |
| 1220 | |
| 1221 | ################################################################## |
| 1222 | #### API Test case functions Service registry and supervision #### |
| 1223 | ################################################################## |
| 1224 | |
| 1225 | # API test function: PUT /service |
| 1226 | # args: <response-code> <service-name> <keepalive-timeout> <callbackurl> |
| 1227 | # (Function for test scripts) |
| 1228 | api_put_service() { |
| 1229 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1230 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1231 | ((RES_TEST++)) |
| 1232 | if [ $# -ne 4 ]; then |
| 1233 | __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@ |
| 1234 | return 1 |
| 1235 | fi |
| 1236 | |
| 1237 | query="/service" |
| 1238 | json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}" |
| 1239 | file=".tmp.json" |
| 1240 | echo "$json" > $file |
| 1241 | |
| 1242 | res="$(__do_curl_to_agent PUT $query $file)" |
| 1243 | status=${res:${#res}-3} |
| 1244 | |
| 1245 | if [ $status -ne $1 ]; then |
| 1246 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1247 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1248 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1249 | return 1 |
| 1250 | fi |
| 1251 | |
| 1252 | ((RES_PASS++)) |
| 1253 | echo -e $GREEN" PASS"$EGREEN |
| 1254 | return 0 |
| 1255 | } |
| 1256 | |
| 1257 | # API test function: GET /services |
| 1258 | #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>]* )] |
| 1259 | # (Function for test scripts) |
| 1260 | api_get_services() { |
| 1261 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1262 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1263 | ((RES_TEST++)) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1264 | #Number of accepted parameters: 1, 2, 4, 7, 10, 13,... |
| 1265 | paramError=1 |
| 1266 | if [ $# -eq 1 ]; then |
| 1267 | paramError=0 |
| 1268 | elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then |
| 1269 | paramError=0 |
| 1270 | elif [ $# -eq 5 ]; then |
| 1271 | paramError=0 |
| 1272 | elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then |
| 1273 | argLen=$(($#-2)) |
| 1274 | if [ $(($argLen%3)) -eq 0 ]; then |
| 1275 | paramError=0 |
| 1276 | fi |
| 1277 | fi |
| 1278 | |
| 1279 | if [ $paramError -ne 0 ]; then |
| 1280 | __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>]* )]" $@ |
| 1281 | return 1 |
| 1282 | fi |
| 1283 | |
| 1284 | query="/services" |
| 1285 | |
| 1286 | if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then |
| 1287 | query="/services?name="$2 |
| 1288 | fi |
| 1289 | |
| 1290 | res="$(__do_curl_to_agent GET $query)" |
| 1291 | status=${res:${#res}-3} |
| 1292 | |
| 1293 | if [ $status -ne $1 ]; then |
| 1294 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1295 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1296 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1297 | return 1 |
| 1298 | fi |
| 1299 | |
| 1300 | if [ $# -gt 2 ]; then |
| 1301 | variableArgCount=$(($#-2)) |
| 1302 | body=${res:0:${#res}-3} |
| 1303 | targetJson="[" |
| 1304 | shift; shift; |
| 1305 | cntr=0 |
| 1306 | while [ $cntr -lt $variableArgCount ]; do |
| 1307 | servicename=$1; shift; |
| 1308 | timeout=$1; shift; |
| 1309 | callback=$1; shift; |
| 1310 | if [ $cntr -gt 0 ]; then |
| 1311 | targetJson=$targetJson"," |
| 1312 | fi |
| 1313 | # timeSinceLastActivitySeconds value cannot be checked since value varies |
| 1314 | targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}" |
| 1315 | let cntr=cntr+3 |
| 1316 | done |
| 1317 | targetJson=$targetJson"]" |
| 1318 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1319 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1320 | if [ $res -ne 0 ]; then |
| 1321 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 1322 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1323 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1324 | return 1 |
| 1325 | fi |
| 1326 | fi |
| 1327 | |
| 1328 | ((RES_PASS++)) |
| 1329 | echo -e $GREEN" PASS"$EGREEN |
| 1330 | return 0 |
| 1331 | } |
| 1332 | |
| 1333 | # API test function: GET /services (only checking service names) |
| 1334 | # args: <response-code> [<service-name>]*" |
| 1335 | # (Function for test scripts) |
| 1336 | api_get_service_ids() { |
| 1337 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1338 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1339 | ((RES_TEST++)) |
| 1340 | |
| 1341 | if [ $# -lt 1 ]; then |
| 1342 | __print_err "<response-code> [<service-name>]*" $@ |
| 1343 | return 1 |
| 1344 | fi |
| 1345 | |
| 1346 | query="/services" |
| 1347 | res="$(__do_curl_to_agent GET $query)" |
| 1348 | status=${res:${#res}-3} |
| 1349 | |
| 1350 | if [ $status -ne $1 ]; then |
| 1351 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1352 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1353 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1354 | return 1 |
| 1355 | fi |
| 1356 | |
| 1357 | body=${res:0:${#res}-3} |
| 1358 | targetJson="[" |
| 1359 | for rapp in ${@:2} ; do |
| 1360 | if [ "$targetJson" != "[" ]; then |
| 1361 | targetJson=$targetJson"," |
| 1362 | fi |
| 1363 | targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}" |
| 1364 | done |
| 1365 | |
| 1366 | targetJson=$targetJson"]" |
| 1367 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1368 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1369 | |
| 1370 | if [ $res -ne 0 ]; then |
| 1371 | echo -e $RED" FAIL, returned body not correct"$ERED |
| 1372 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1373 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1374 | return 1 |
| 1375 | fi |
| 1376 | |
| 1377 | ((RES_PASS++)) |
| 1378 | echo -e $GREEN" PASS"$EGREEN |
| 1379 | return 0 |
| 1380 | } |
| 1381 | |
| 1382 | # API test function: DELETE /services |
| 1383 | # args: <response-code> <service-name> |
| 1384 | # (Function for test scripts) |
| 1385 | api_delete_services() { |
| 1386 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1387 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1388 | ((RES_TEST++)) |
| 1389 | |
| 1390 | if [ $# -ne 2 ]; then |
| 1391 | __print_err "<response-code> <service-name>" $@ |
| 1392 | return 1 |
| 1393 | fi |
| 1394 | |
| 1395 | query="/services?name="$2 |
| 1396 | res="$(__do_curl_to_agent DELETE $query)" |
| 1397 | status=${res:${#res}-3} |
| 1398 | |
| 1399 | if [ $status -ne $1 ]; then |
| 1400 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1401 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1402 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1403 | return 1 |
| 1404 | fi |
| 1405 | |
| 1406 | ((RES_PASS++)) |
| 1407 | echo -e $GREEN" PASS"$EGREEN |
| 1408 | return 0 |
| 1409 | } |
| 1410 | |
| 1411 | # API test function: PUT /services/keepalive |
| 1412 | # args: <response-code> <service-name> |
| 1413 | # (Function for test scripts) |
| 1414 | api_put_services_keepalive() { |
| 1415 | echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD |
| 1416 | echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 1417 | ((RES_TEST++)) |
| 1418 | |
| 1419 | if [ $# -ne 2 ]; then |
| 1420 | __print_err "<response-code> <service-name>" $@ |
| 1421 | return 1 |
| 1422 | fi |
| 1423 | |
| 1424 | query="/services/keepalive?name="$2 |
| 1425 | res="$(__do_curl_to_agent PUT $query)" |
| 1426 | status=${res:${#res}-3} |
| 1427 | |
| 1428 | if [ $status -ne $1 ]; then |
| 1429 | echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED |
| 1430 | ((RES_FAIL++)) |
BjornMagnussonXA | 048aaa1 | 2020-06-04 07:48:37 +0200 | [diff] [blame^] | 1431 | __check_stop_at_error |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1432 | return 1 |
| 1433 | fi |
| 1434 | |
| 1435 | ((RES_PASS++)) |
| 1436 | echo -e $GREEN" PASS"$EGREEN |
| 1437 | return 0 |
| 1438 | } |
| 1439 | |