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 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 24 | . ../common/api_curl.sh |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 25 | |
| 26 | ######################################################### |
| 27 | #### Test case functions A1 Policy management service |
| 28 | ######################################################### |
| 29 | |
| 30 | # This function compare the size, towards a target value, of a json array returned from <url> of the Policy Agent. |
| 31 | # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL |
| 32 | # args: json:<url> <target-value> [<timeout-in-seconds] |
| 33 | # (Function for test scripts) |
| 34 | api_equal() { |
| 35 | echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG |
| 36 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 37 | if [[ $1 == "json:"* ]]; then |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 38 | if [ "$PMS_VERSION" == "V2" ]; then |
| 39 | __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/v2/" $1 "=" $2 $3 |
| 40 | else |
| 41 | __var_test "Policy Agent" $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT"/" $1 "=" $2 $3 |
| 42 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 43 | return 0 |
| 44 | fi |
| 45 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 46 | __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@ |
| 47 | return 1 |
| 48 | } |
| 49 | |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 50 | # API Test function: GET /policies and V2 GET /v2/policy-instances |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 51 | # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*] |
| 52 | # args(V2): <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <transient> <notification-url> <template-file>]*] |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 53 | # (Function for test scripts) |
| 54 | api_get_policies() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 55 | __log_test_start $@ |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 56 | |
| 57 | if [ "$PMS_VERSION" == "V2" ]; then |
| 58 | paramError=0 |
| 59 | variableParams=$(($#-4)) |
| 60 | if [ $# -lt 4 ]; then |
| 61 | paramError=1 |
| 62 | elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then |
| 63 | paramError=1 |
| 64 | elif [ $# -gt 5 ] && [ $(($variableParams%7)) -ne 0 ]; then |
| 65 | paramError=1 |
| 66 | fi |
| 67 | |
| 68 | if [ $paramError -ne 0 ]; then |
| 69 | __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <transient> <notification-url> <template-file>]*]" $@ |
| 70 | return 1 |
| 71 | fi |
| 72 | else |
| 73 | paramError=0 |
| 74 | variableParams=$(($#-4)) |
| 75 | if [ $# -lt 4 ]; then |
| 76 | paramError=1 |
| 77 | elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then |
| 78 | paramError=1 |
| 79 | elif [ $# -gt 5 ] && [ $(($variableParams%5)) -ne 0 ]; then |
| 80 | paramError=1 |
| 81 | fi |
| 82 | |
| 83 | if [ $paramError -ne 0 ]; then |
| 84 | __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*]" $@ |
| 85 | return 1 |
| 86 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 87 | fi |
| 88 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 89 | queryparams="" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 90 | if [ "$PMS_VERSION" == "V2" ]; then |
| 91 | if [ $2 != "NORIC" ]; then |
| 92 | queryparams="?ric_id="$2 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 93 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 94 | if [ $3 != "NOSERVICE" ]; then |
| 95 | if [ -z $queryparams ]; then |
| 96 | queryparams="?service_id="$3 |
| 97 | else |
| 98 | queryparams=$queryparams"&service_id="$3 |
| 99 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 100 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 101 | if [ $4 != "NOTYPE" ]; then |
| 102 | if [ -z $queryparams ]; then |
| 103 | queryparams="?policytype_id="$4 |
| 104 | else |
| 105 | queryparams=$queryparams"&policytype_id="$4 |
| 106 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 107 | fi |
| 108 | |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 109 | query="/v2/policy-instances"$queryparams |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 110 | res="$(__do_curl_to_api PA GET $query)" |
| 111 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 112 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 113 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 114 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 115 | return 1 |
| 116 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 117 | |
| 118 | if [ $# -gt 4 ]; then |
| 119 | body=${res:0:${#res}-3} |
| 120 | if [ $# -eq 5 ] && [ $5 == "NOID" ]; then |
| 121 | targetJson="[" |
| 122 | else |
| 123 | targetJson="[" |
| 124 | arr=(${@:5}) |
| 125 | |
| 126 | for ((i=0; i<$(($#-4)); i=i+7)); do |
| 127 | |
| 128 | if [ "$targetJson" != "[" ]; then |
| 129 | targetJson=$targetJson"," |
| 130 | fi |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 131 | targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 132 | if [ "${arr[$i+3]}" == "EMPTY" ]; then |
| 133 | targetJson=$targetJson"\"\"," |
| 134 | else |
| 135 | targetJson=$targetJson"\"${arr[$i+3]}\"," |
| 136 | fi |
| 137 | targetJson=$targetJson"\"transient\":${arr[$i+4]},\"status_notification_uri\":\"${arr[$i+5]}\"," |
| 138 | file="./tmp/.p.json" |
| 139 | sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+6]} > $file |
| 140 | json=$(cat $file) |
| 141 | targetJson=$targetJson"\"policy_data\":"$json"}" |
| 142 | done |
| 143 | fi |
| 144 | |
| 145 | targetJson=$targetJson"]" |
| 146 | targetJson="{\"policies\": $targetJson}" |
| 147 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
| 148 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 149 | |
| 150 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 151 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 152 | return 1 |
| 153 | fi |
| 154 | fi |
| 155 | else |
| 156 | if [ $2 != "NORIC" ]; then |
| 157 | queryparams="?ric="$2 |
| 158 | fi |
| 159 | if [ $3 != "NOSERVICE" ]; then |
| 160 | if [ -z $queryparams ]; then |
| 161 | queryparams="?service="$3 |
| 162 | else |
| 163 | queryparams=$queryparams"&service="$3 |
| 164 | fi |
| 165 | fi |
| 166 | if [ $4 != "NOTYPE" ]; then |
| 167 | if [ -z $queryparams ]; then |
| 168 | queryparams="?type="$4 |
| 169 | else |
| 170 | queryparams=$queryparams"&type="$4 |
| 171 | fi |
| 172 | fi |
| 173 | |
| 174 | query="/policies"$queryparams |
| 175 | res="$(__do_curl_to_api PA GET $query)" |
| 176 | status=${res:${#res}-3} |
| 177 | |
| 178 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 179 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 180 | return 1 |
| 181 | fi |
| 182 | |
| 183 | if [ $# -gt 4 ]; then |
| 184 | if [ $# -eq 5 ] && [ $5 == "NOID" ]; then |
| 185 | targetJson="[" |
| 186 | else |
| 187 | body=${res:0:${#res}-3} |
| 188 | targetJson="[" |
| 189 | arr=(${@:5}) |
| 190 | |
| 191 | for ((i=0; i<$(($#-4)); i=i+5)); do |
| 192 | |
| 193 | if [ "$targetJson" != "[" ]; then |
| 194 | targetJson=$targetJson"," |
| 195 | fi |
| 196 | targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i+1]}\",\"service\":\"${arr[$i+2]}\",\"type\":" |
| 197 | if [ "${arr[$i+3]}" == "EMPTY" ]; then |
| 198 | targetJson=$targetJson"\"\"," |
| 199 | else |
| 200 | targetJson=$targetJson"\"${arr[$i+3]}\"," |
| 201 | fi |
| 202 | file="./tmp/.p.json" |
| 203 | sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file |
| 204 | json=$(cat $file) |
| 205 | targetJson=$targetJson"\"json\":"$json"}" |
| 206 | done |
| 207 | fi |
| 208 | |
| 209 | targetJson=$targetJson"]" |
| 210 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
| 211 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 212 | |
| 213 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 214 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 215 | return 1 |
| 216 | fi |
| 217 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 218 | fi |
| 219 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 220 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 221 | return 0 |
| 222 | |
| 223 | } |
| 224 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 225 | |
| 226 | # API Test function: GET /policy and V2 GET /v2/policies/{policy_id} |
| 227 | # args: <response-code> <policy-id> [<template-file>] |
| 228 | # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ] |
| 229 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 230 | # (Function for test scripts) |
| 231 | api_get_policy() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 232 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 233 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 234 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 235 | if [ "$PMS_VERSION" == "V2" ]; then |
| 236 | if [ $# -ne 2 ] && [ $# -ne 8 ]; then |
| 237 | __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@ |
| 238 | return 1 |
| 239 | fi |
| 240 | query="/v2/policies/$UUID$2" |
| 241 | else |
| 242 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 243 | __print_err "<response-code> <policy-id> [<template-file>] " $@ |
| 244 | return 1 |
| 245 | fi |
| 246 | query="/policy?id=$UUID$2" |
| 247 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 248 | res="$(__do_curl_to_api PA GET $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 249 | status=${res:${#res}-3} |
| 250 | |
| 251 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 252 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 253 | return 1 |
| 254 | fi |
| 255 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 256 | if [ "$PMS_VERSION" == "V2" ]; then |
| 257 | if [ $# -eq 8 ]; then |
| 258 | |
| 259 | #Create a policy json to compare with |
| 260 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 261 | |
| 262 | targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\"" |
| 263 | if [ $7 != "NOTRANSIENT" ]; then |
| 264 | targetJson=$targetJson", \"transient\":$7" |
| 265 | fi |
| 266 | if [ $6 != "NOTYPE" ]; then |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 267 | targetJson=$targetJson", \"policytype_id\":\"$6\"" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 268 | else |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 269 | targetJson=$targetJson", \"policytype_id\":\"\"" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 270 | fi |
| 271 | if [ $8 != "NOURL" ]; then |
| 272 | targetJson=$targetJson", \"status_notification_uri\":\"$8\"" |
| 273 | fi |
| 274 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 275 | data=$(sed 's/XXX/'${2}'/g' $3) |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 276 | targetJson=$targetJson", \"policy_data\":$data" |
| 277 | targetJson="{$targetJson}" |
| 278 | |
| 279 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
| 280 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 281 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 282 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 283 | return 1 |
| 284 | fi |
| 285 | fi |
| 286 | else |
| 287 | if [ $# -eq 3 ]; then |
| 288 | #Create a policy json to compare with |
| 289 | body=${res:0:${#res}-3} |
| 290 | file="./tmp/.p.json" |
| 291 | sed 's/XXX/'${2}'/g' $3 > $file |
| 292 | targetJson=$(< $file) |
| 293 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
| 294 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 295 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 296 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 297 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 298 | fi |
| 299 | fi |
| 300 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 301 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 302 | return 0 |
| 303 | } |
| 304 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 305 | # API Test function: PUT /policy and V2 PUT /policies |
| 306 | # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>] |
| 307 | # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>] |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 308 | # (Function for test scripts) |
| 309 | api_put_policy() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 310 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 311 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 312 | if [ "$PMS_VERSION" == "V2" ]; then |
| 313 | if [ $# -lt 8 ] || [ $# -gt 9 ]; then |
| 314 | __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@ |
| 315 | return 1 |
| 316 | fi |
| 317 | else |
| 318 | if [ $# -lt 7 ] || [ $# -gt 8 ]; then |
| 319 | __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@ |
| 320 | return 1 |
| 321 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 322 | fi |
| 323 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 324 | count=0 |
| 325 | max=1 |
| 326 | serv=$2 |
| 327 | ric=$3 |
| 328 | pt=$4 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 329 | pid=$5 |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 330 | trans=$6 |
| 331 | |
| 332 | if [ "$PMS_VERSION" == "V2" ]; then |
| 333 | noti=$7 |
| 334 | temp=$8 |
| 335 | if [ $# -eq 9 ]; then |
| 336 | max=$9 |
| 337 | fi |
| 338 | else |
| 339 | temp=$7 |
| 340 | if [ $# -eq 8 ]; then |
| 341 | max=$8 |
| 342 | fi |
| 343 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 344 | |
| 345 | while [ $count -lt $max ]; do |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 346 | if [ "$PMS_VERSION" == "V2" ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 347 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 348 | query="/v2/policies" |
| 349 | |
| 350 | inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\"" |
| 351 | if [ $trans != "NOTRANSIENT" ]; then |
| 352 | inputJson=$inputJson", \"transient\":$trans" |
| 353 | fi |
| 354 | if [ $pt != "NOTYPE" ]; then |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 355 | inputJson=$inputJson", \"policytype_id\":\"$pt\"" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 356 | else |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 357 | inputJson=$inputJson", \"policytype_id\":\"\"" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 358 | fi |
| 359 | if [ $noti != "NOURL" ]; then |
| 360 | inputJson=$inputJson", \"status_notification_uri\":\"$noti\"" |
| 361 | fi |
| 362 | file="./tmp/.p.json" |
| 363 | data=$(sed 's/XXX/'${pid}'/g' $temp) |
| 364 | inputJson=$inputJson", \"policy_data\":$data" |
| 365 | inputJson="{$inputJson}" |
| 366 | echo $inputJson > $file |
| 367 | else |
| 368 | query="/policy?id=$UUID$pid&ric=$ric&service=$serv" |
| 369 | |
| 370 | if [ $pt != "NOTYPE" ]; then |
| 371 | query=$query"&type=$pt" |
| 372 | fi |
| 373 | |
| 374 | if [ $trans != NOTRANSIENT ]; then |
| 375 | query=$query"&transient=$trans" |
| 376 | fi |
| 377 | |
| 378 | file="./tmp/.p.json" |
| 379 | sed 's/XXX/'${pid}'/g' $temp > $file |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 380 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 381 | res="$(__do_curl_to_api PA PUT $query $file)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 382 | status=${res:${#res}-3} |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 383 | echo -ne " Executing "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 384 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 385 | echo " Executed "$count"?("$max")" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 386 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 387 | return 1 |
| 388 | fi |
| 389 | |
| 390 | let pid=$pid+1 |
| 391 | let count=$count+1 |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 392 | echo -ne " Executed "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 393 | done |
| 394 | echo "" |
| 395 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 396 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 397 | return 0 |
| 398 | } |
| 399 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 400 | # API Test function: PUT /policy and V2 PUT /policies, to run in batch |
| 401 | # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>] |
| 402 | # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>] |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 403 | # (Function for test scripts) |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 404 | |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 405 | api_put_policy_batch() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 406 | __log_test_start $@ |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 407 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 408 | if [ "$PMS_VERSION" == "V2" ]; then |
| 409 | if [ $# -lt 8 ] || [ $# -gt 9 ]; then |
| 410 | __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@ |
| 411 | return 1 |
| 412 | fi |
| 413 | else |
| 414 | if [ $# -lt 7 ] || [ $# -gt 8 ]; then |
| 415 | __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@ |
| 416 | return 1 |
| 417 | fi |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 418 | fi |
| 419 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 420 | count=0 |
| 421 | max=1 |
| 422 | serv=$2 |
| 423 | ric=$3 |
| 424 | pt=$4 |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 425 | pid=$5 |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 426 | trans=$6 |
| 427 | if [ "$PMS_VERSION" == "V2" ]; then |
| 428 | noti=$7 |
| 429 | temp=$8 |
| 430 | if [ $# -eq 9 ]; then |
| 431 | max=$9 |
| 432 | fi |
| 433 | else |
| 434 | temp=$7 |
| 435 | if [ $# -eq 8 ]; then |
| 436 | max=$8 |
| 437 | fi |
| 438 | fi |
| 439 | |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 440 | ARR="" |
| 441 | while [ $count -lt $max ]; do |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 442 | if [ "$PMS_VERSION" == "V2" ]; then |
| 443 | query="/v2/policies" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 444 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 445 | inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\"" |
| 446 | if [ $trans != "NOTRANSIENT" ]; then |
| 447 | inputJson=$inputJson", \"transient\":$trans" |
| 448 | fi |
| 449 | if [ $pt != "NOTYPE" ]; then |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 450 | inputJson=$inputJson", \"policytype_id\":\"$pt\"" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 451 | else |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 452 | inputJson=$inputJson", \"policytype_id\":\"\"" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 453 | fi |
| 454 | if [ $noti != "NOURL" ]; then |
| 455 | inputJson=$inputJson", \"status_notification_uri\":\"$noti\"" |
| 456 | fi |
| 457 | file="./tmp/.p.json" |
| 458 | data=$(sed 's/XXX/'${pid}'/g' $temp) |
| 459 | inputJson=$inputJson", \"policy_data\":$data" |
| 460 | inputJson="{$inputJson}" |
| 461 | echo $inputJson > $file |
| 462 | else |
| 463 | query="/policy?id=$UUID$pid&ric=$ric&service=$serv" |
| 464 | |
| 465 | if [ $pt != "NOTYPE" ]; then |
| 466 | query=$query"&type=$pt" |
| 467 | fi |
| 468 | |
| 469 | if [ $trans != NOTRANSIENT ]; then |
| 470 | query=$query"&transient=$trans" |
| 471 | fi |
| 472 | file="./tmp/.p.json" |
| 473 | sed 's/XXX/'${pid}'/g' $temp > $file |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 474 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 475 | res="$(__do_curl_to_api PA PUT_BATCH $query $file)" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 476 | status=${res:${#res}-3} |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 477 | echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 478 | |
| 479 | if [ $status -ne 200 ]; then |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 480 | echo " Requested(batch) "$count"?("$max")" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 481 | __log_test_fail_status_code 200 $status |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 482 | return 1 |
| 483 | fi |
| 484 | cid=${res:0:${#res}-3} |
| 485 | ARR=$ARR" "$cid |
| 486 | let pid=$pid+1 |
| 487 | let count=$count+1 |
| 488 | echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" |
| 489 | done |
| 490 | |
| 491 | echo "" |
| 492 | count=0 |
| 493 | for cid in $ARR; do |
| 494 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 495 | res="$(__do_curl_to_api PA RESPONSE $cid)" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 496 | status=${res:${#res}-3} |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 497 | echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 498 | |
| 499 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 500 | echo " Accepted(batch) "$count"?("$max")" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 501 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 502 | return 1 |
| 503 | fi |
| 504 | |
| 505 | let count=$count+1 |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 506 | echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 507 | done |
| 508 | |
| 509 | echo "" |
| 510 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 511 | __log_test_pass |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 512 | return 0 |
| 513 | } |
| 514 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 515 | # API Test function: PUT /policy and V2 PUT /policies, to run in i parallel for a number of rics |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 516 | # 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> |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 517 | # args(V2): <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads> |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 518 | # (Function for test scripts) |
| 519 | api_put_policy_parallel() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 520 | __log_test_start $@ |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 521 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 522 | if [ "$PMS_VERSION" == "V2" ]; then |
| 523 | if [ $# -ne 11 ]; then |
| 524 | __print_err "<response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <notification-url>|NOURL <template-file> <count-per-ric> <number-of-threads>" $@ |
| 525 | return 1 |
| 526 | fi |
| 527 | else |
| 528 | if [ $# -ne 10 ]; then |
| 529 | __print_err " <response-code> <service-name> <ric-id-base> <number-of-rics> <policytype-id> <policy-start-id> <transient> <template-file> <count-per-ric> <number-of-threads>" $@ |
| 530 | return 1 |
| 531 | fi |
| 532 | fi |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 533 | resp_code=$1; shift; |
| 534 | serv=$1; shift |
| 535 | ric_base=$1; shift; |
| 536 | num_rics=$1; shift; |
| 537 | type=$1; shift; |
| 538 | start_id=$1; shift; |
| 539 | transient=$1; shift; |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 540 | if [ "$PMS_VERSION" == "V2" ]; then |
| 541 | noti=$1; shift; |
| 542 | else |
| 543 | noti="" |
| 544 | fi |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 545 | template=$1; shift; |
| 546 | count=$1; shift; |
| 547 | pids=$1; shift; |
| 548 | |
| 549 | if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then |
| 550 | echo " Info - api_put_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported" |
| 551 | echo " Info - will execute over agent REST" |
| 552 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 553 | if [ "$PMS_VERSION" == "V2" ]; then |
| 554 | if [ $serv == "NOSERVICE" ]; then |
| 555 | serv="" |
| 556 | fi |
| 557 | query="/v2/policies" |
| 558 | else |
| 559 | if [ $serv == "NOSERVICE" ]; then |
| 560 | serv="" |
| 561 | fi |
| 562 | query="/policy?service=$serv" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 563 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 564 | if [ $type != "NOTYPE" ]; then |
| 565 | query=$query"&type=$type" |
| 566 | fi |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 567 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 568 | if [ $transient != NOTRANSIENT ]; then |
| 569 | query=$query"&transient=$transient" |
| 570 | fi |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 571 | fi |
| 572 | |
| 573 | urlbase=${ADAPTER}${query} |
| 574 | |
| 575 | for ((i=1; i<=$pids; i++)) |
| 576 | do |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 577 | uuid=$UUID |
| 578 | if [ -z "$uuid" ]; then |
| 579 | uuid="NOUUID" |
| 580 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 581 | echo "" > "./tmp/.pid${i}.res.txt" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 582 | if [ "$PMS_VERSION" == "V2" ]; then |
| 583 | echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i > "./tmp/.pid${i}.txt" |
| 584 | else |
| 585 | echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt" |
| 586 | fi |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 587 | echo $i |
| 588 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
| 589 | arg=$(echo {}) |
| 590 | echo " Parallel process $arg started" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 591 | tmp=$(< "./tmp/.pid${arg}.txt") |
| 592 | python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 593 | }' |
| 594 | msg="" |
| 595 | for ((i=1; i<=$pids; i++)) |
| 596 | do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 597 | file="./tmp/.pid${i}.res.txt" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 598 | tmp=$(< $file) |
| 599 | if [ -z "$tmp" ]; then |
| 600 | echo " Process $i : unknown result (result file empty" |
| 601 | msg="failed" |
| 602 | else |
| 603 | res=${tmp:0:1} |
| 604 | if [ $res == "0" ]; then |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 605 | echo " Process $i : OK - "${tmp:1} |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 606 | else |
| 607 | echo " Process $i : failed - "${tmp:1} |
| 608 | msg="failed" |
| 609 | fi |
| 610 | fi |
| 611 | done |
| 612 | if [ -z $msg ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 613 | __log_test_pass " $(($count*$num_rics)) policy request(s) executed" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 614 | return 0 |
| 615 | fi |
| 616 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 617 | __log_test_fail_general "One of more processes failed to execute" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 618 | return 1 |
| 619 | } |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 620 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 621 | # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 622 | # args: <response-code> <policy-id> [count] |
| 623 | # (Function for test scripts) |
| 624 | api_delete_policy() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 625 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 626 | |
| 627 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 628 | __print_err "<response-code> <policy-id> [count]" $@ |
| 629 | return 1 |
| 630 | fi |
| 631 | |
| 632 | count=0 |
| 633 | max=1 |
| 634 | |
| 635 | if [ $# -eq 3 ]; then |
| 636 | max=$3 |
| 637 | fi |
| 638 | |
| 639 | pid=$2 |
| 640 | |
| 641 | while [ $count -lt $max ]; do |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 642 | if [ "$PMS_VERSION" == "V2" ]; then |
| 643 | query="/v2/policies/"$UUID$pid |
| 644 | else |
| 645 | query="/policy?id="$UUID$pid |
| 646 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 647 | res="$(__do_curl_to_api PA DELETE $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 648 | status=${res:${#res}-3} |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 649 | echo -ne " Executing "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 650 | |
| 651 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 652 | echo " Executed "$count"?("$max")" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 653 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 654 | return 1 |
| 655 | fi |
| 656 | let pid=$pid+1 |
| 657 | let count=$count+1 |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 658 | echo -ne " Executed "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 659 | done |
| 660 | echo "" |
| 661 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 662 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 663 | return 0 |
| 664 | } |
| 665 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 666 | # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in batch |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 667 | # args: <response-code> <policy-id> [count] |
| 668 | # (Function for test scripts) |
| 669 | api_delete_policy_batch() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 670 | __log_test_start $@ |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 671 | |
| 672 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 673 | __print_err "<response-code> <policy-id> [count]" $@ |
| 674 | return 1 |
| 675 | fi |
| 676 | |
| 677 | count=0 |
| 678 | max=1 |
| 679 | |
| 680 | if [ $# -eq 3 ]; then |
| 681 | max=$3 |
| 682 | fi |
| 683 | |
| 684 | pid=$2 |
| 685 | ARR="" |
| 686 | while [ $count -lt $max ]; do |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 687 | if [ "$PMS_VERSION" == "V2" ]; then |
| 688 | query="/v2/policies/"$UUID$pid |
| 689 | else |
| 690 | query="/policy?id="$UUID$pid |
| 691 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 692 | res="$(__do_curl_to_api PA DELETE_BATCH $query)" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 693 | status=${res:${#res}-3} |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 694 | echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 695 | |
| 696 | if [ $status -ne 200 ]; then |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 697 | echo " Requested(batch) "$count"?("$max")" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 698 | __log_test_fail_status_code 200 $status |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 699 | return 1 |
| 700 | fi |
| 701 | cid=${res:0:${#res}-3} |
| 702 | ARR=$ARR" "$cid |
| 703 | let pid=$pid+1 |
| 704 | let count=$count+1 |
| 705 | echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" |
| 706 | done |
| 707 | |
| 708 | echo "" |
| 709 | |
| 710 | count=0 |
| 711 | for cid in $ARR; do |
| 712 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 713 | res="$(__do_curl_to_api PA RESPONSE $cid)" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 714 | status=${res:${#res}-3} |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 715 | echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 716 | |
| 717 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 718 | echo " Deleted(batch) "$count"?("$max")" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 719 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 720 | return 1 |
| 721 | fi |
| 722 | |
| 723 | let count=$count+1 |
| 724 | echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}" |
| 725 | done |
| 726 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 727 | echo "" |
| 728 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 729 | __log_test_pass |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 730 | return 0 |
| 731 | } |
| 732 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 733 | # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id}, to run in i parallel for a number of rics |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 734 | # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads> |
| 735 | # (Function for test scripts) |
| 736 | api_delete_policy_parallel() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 737 | __log_test_start $@ |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 738 | |
| 739 | if [ $# -ne 5 ]; then |
| 740 | __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@ |
| 741 | return 1 |
| 742 | fi |
| 743 | resp_code=$1; shift; |
| 744 | num_rics=$1; shift; |
| 745 | start_id=$1; shift; |
| 746 | count=$1; shift; |
| 747 | pids=$1; shift; |
| 748 | |
| 749 | if [ $ADAPTER != $RESTBASE ] && [ $ADAPTER != $RESTBASE_SECURE ]; then |
| 750 | echo " Info - api_delete_policy_parallel uses only the agent REST interface - create over dmaap in parallel is not supported" |
| 751 | echo " Info - will execute over agent REST" |
| 752 | fi |
| 753 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 754 | if [ "$PMS_VERSION" == "V2" ]; then |
| 755 | query="/v2/policies/" |
| 756 | else |
| 757 | query="/policy" |
| 758 | fi |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 759 | |
| 760 | urlbase=${ADAPTER}${query} |
| 761 | |
| 762 | for ((i=1; i<=$pids; i++)) |
| 763 | do |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 764 | uuid=$UUID |
| 765 | if [ -z "$uuid" ]; then |
| 766 | uuid="NOUUID" |
| 767 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 768 | echo "" > "./tmp/.pid${i}.del.res.txt" |
| 769 | echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > "./tmp/.pid${i}.del.txt" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 770 | echo $i |
| 771 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
| 772 | arg=$(echo {}) |
| 773 | echo " Parallel process $arg started" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 774 | tmp=$(< "./tmp/.pid${arg}.del.txt") |
| 775 | python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 776 | }' |
| 777 | msg="" |
| 778 | for ((i=1; i<=$pids; i++)) |
| 779 | do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 780 | file="./tmp/.pid${i}.del.res.txt" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 781 | tmp=$(< $file) |
| 782 | if [ -z "$tmp" ]; then |
| 783 | echo " Process $i : unknown result (result file empty" |
| 784 | msg="failed" |
| 785 | else |
| 786 | res=${tmp:0:1} |
| 787 | if [ $res == "0" ]; then |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 788 | echo " Process $i : OK - "${tmp:1} |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 789 | else |
| 790 | echo " Process $i : failed - "${tmp:1} |
| 791 | msg="failed" |
| 792 | fi |
| 793 | fi |
| 794 | done |
| 795 | if [ -z $msg ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 796 | __log_test_pass " $(($count*$num_rics)) policy request(s) executed" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 797 | return 0 |
| 798 | fi |
| 799 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 800 | __log_test_fail_general "One of more processes failed to execute" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 801 | return 1 |
| 802 | } |
| 803 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 804 | # API Test function: GET /policy_ids and V2 GET /v2/policies |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 805 | # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID) |
| 806 | # (Function for test scripts) |
| 807 | api_get_policy_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 808 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 809 | |
| 810 | if [ $# -lt 4 ]; then |
| 811 | __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@ |
| 812 | return 1 |
| 813 | fi |
| 814 | |
| 815 | queryparams="" |
| 816 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 817 | if [ "$PMS_VERSION" == "V2" ]; then |
| 818 | if [ $2 != "NORIC" ]; then |
| 819 | queryparams="?ric_id="$2 |
| 820 | fi |
| 821 | |
| 822 | if [ $3 != "NOSERVICE" ]; then |
| 823 | if [ -z $queryparams ]; then |
| 824 | queryparams="?service_id="$3 |
| 825 | else |
| 826 | queryparams=$queryparams"&service_id="$3 |
| 827 | fi |
| 828 | fi |
| 829 | if [ $4 != "NOTYPE" ]; then |
| 830 | if [ -z $queryparams ]; then |
| 831 | queryparams="?policytype_id="$4 |
| 832 | else |
| 833 | queryparams=$queryparams"&policytype_id="$4 |
| 834 | fi |
| 835 | fi |
| 836 | |
| 837 | query="/v2/policies"$queryparams |
| 838 | else |
| 839 | if [ $2 != "NORIC" ]; then |
| 840 | queryparams="?ric="$2 |
| 841 | fi |
| 842 | |
| 843 | if [ $3 != "NOSERVICE" ]; then |
| 844 | if [ -z $queryparams ]; then |
| 845 | queryparams="?service="$3 |
| 846 | else |
| 847 | queryparams=$queryparams"&service="$3 |
| 848 | fi |
| 849 | fi |
| 850 | if [ $4 != "NOTYPE" ]; then |
| 851 | if [ -z $queryparams ]; then |
| 852 | queryparams="?type="$4 |
| 853 | else |
| 854 | queryparams=$queryparams"&type="$4 |
| 855 | fi |
| 856 | fi |
| 857 | |
| 858 | query="/policy_ids"$queryparams |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 859 | fi |
| 860 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 861 | res="$(__do_curl_to_api PA GET $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 862 | status=${res:${#res}-3} |
| 863 | |
| 864 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 865 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 866 | return 1 |
| 867 | fi |
| 868 | |
| 869 | if [ $# -gt 4 ]; then |
| 870 | body=${res:0:${#res}-3} |
| 871 | targetJson="[" |
| 872 | |
| 873 | for pid in ${@:5} ; do |
| 874 | if [ "$targetJson" != "[" ]; then |
| 875 | targetJson=$targetJson"," |
| 876 | fi |
| 877 | if [ $pid != "NOID" ]; then |
BjornMagnussonXA | ad04778 | 2020-06-08 15:54:11 +0200 | [diff] [blame] | 878 | targetJson=$targetJson"\"$UUID$pid\"" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 879 | fi |
| 880 | done |
| 881 | |
| 882 | targetJson=$targetJson"]" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 883 | if [ "$PMS_VERSION" == "V2" ]; then |
| 884 | targetJson="{\"policy_ids\": $targetJson}" |
| 885 | fi |
| 886 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
| 887 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 888 | |
| 889 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 890 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 891 | return 1 |
| 892 | fi |
| 893 | fi |
| 894 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 895 | __log_test_pass |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 896 | return 0 |
| 897 | } |
| 898 | |
| 899 | # API Test function: V2 GET /v2/policy-types/{policyTypeId} |
| 900 | # args(V2): <response-code> <policy-type-id> [<schema-file>] |
| 901 | # (Function for test scripts) |
| 902 | api_get_policy_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 903 | __log_test_start $@ |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 904 | |
| 905 | if [ "$PMS_VERSION" != "V2" ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 906 | __log_test_fail_not_supported |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 907 | return 1 |
| 908 | fi |
| 909 | |
| 910 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 911 | __print_err "<response-code> <policy-type-id> [<schema-file>]" $@ |
| 912 | return 1 |
| 913 | fi |
| 914 | query="/v2/policy-types/$2" |
| 915 | |
| 916 | res="$(__do_curl_to_api PA GET $query)" |
| 917 | status=${res:${#res}-3} |
| 918 | |
| 919 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 920 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 921 | return 1 |
| 922 | fi |
| 923 | |
| 924 | if [ $# -eq 3 ]; then |
| 925 | |
| 926 | body=${res:0:${#res}-3} |
| 927 | |
| 928 | targetJson=$(< $3) |
| 929 | targetJson="{\"policy_schema\":$targetJson}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 930 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 931 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 932 | |
| 933 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 934 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 935 | return 1 |
| 936 | fi |
| 937 | fi |
| 938 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 939 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 940 | return 0 |
| 941 | } |
| 942 | |
| 943 | # API Test function: GET /policy_schema |
| 944 | # args: <response-code> <policy-type-id> [<schema-file>] |
| 945 | # (Function for test scripts) |
| 946 | api_get_policy_schema() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 947 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 948 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 949 | if [ "$PMS_VERSION" == "V2" ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 950 | __log_test_fail_not_supported |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 951 | return 1 |
| 952 | fi |
| 953 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 954 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 955 | __print_err "<response-code> <policy-type-id> [<schema-file>]" $@ |
| 956 | return 1 |
| 957 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 958 | query="/policy_schema?id=$2" |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 959 | res="$(__do_curl_to_api PA GET $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 960 | status=${res:${#res}-3} |
| 961 | |
| 962 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 963 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 964 | return 1 |
| 965 | fi |
| 966 | |
| 967 | if [ $# -eq 3 ]; then |
| 968 | |
| 969 | body=${res:0:${#res}-3} |
| 970 | |
| 971 | targetJson=$(< $3) |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 972 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 973 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 974 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 975 | |
| 976 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 977 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 978 | return 1 |
| 979 | fi |
| 980 | fi |
| 981 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 982 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 983 | return 0 |
| 984 | } |
| 985 | |
| 986 | # API Test function: GET /policy_schemas |
| 987 | # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]* |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 988 | # args(V2): <response-code> |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 989 | # (Function for test scripts) |
| 990 | api_get_policy_schemas() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 991 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 992 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 993 | if [ "$PMS_VERSION" == "V2" ]; then |
| 994 | if [ $# -ne 1 ]; then |
| 995 | __print_err "<response-code>" $@ |
| 996 | return 1 |
| 997 | fi |
| 998 | else |
| 999 | if [ $# -lt 2 ]; then |
| 1000 | __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@ |
| 1001 | return 1 |
| 1002 | fi |
| 1003 | fi |
| 1004 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1005 | query="/v2/policy-schemas" |
| 1006 | else |
| 1007 | query="/policy_schemas" |
| 1008 | if [ $2 != "NORIC" ]; then |
| 1009 | query=$query"?ric="$2 |
| 1010 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1011 | fi |
| 1012 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1013 | res="$(__do_curl_to_api PA GET $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1014 | status=${res:${#res}-3} |
| 1015 | |
| 1016 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1017 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1018 | return 1 |
| 1019 | fi |
| 1020 | |
| 1021 | if [ $# -gt 2 ]; then |
| 1022 | body=${res:0:${#res}-3} |
| 1023 | targetJson="[" |
| 1024 | |
| 1025 | for file in ${@:3} ; do |
| 1026 | if [ "$targetJson" != "[" ]; then |
| 1027 | targetJson=$targetJson"," |
| 1028 | fi |
| 1029 | if [ $file == "NOFILE" ]; then |
| 1030 | targetJson=$targetJson"{}" |
| 1031 | else |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1032 | targetJson=$targetJson$(< $file) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1033 | fi |
| 1034 | done |
| 1035 | |
| 1036 | targetJson=$targetJson"]" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1037 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1038 | targetJson="{\"policy_schemas\": $targetJson }" |
| 1039 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1040 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1041 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1042 | |
| 1043 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1044 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1045 | return 1 |
| 1046 | fi |
| 1047 | fi |
| 1048 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1049 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1050 | return 0 |
| 1051 | } |
| 1052 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1053 | # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1054 | # arg: <response-code> <policy-id> (STD|STD2 <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1055 | # (Function for test scripts) |
| 1056 | api_get_policy_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1057 | __log_test_start $@ |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1058 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1059 | if [ $# -lt 4 ] || [ $# -gt 5 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1060 | __print_err "<response-code> <policy-id> (STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)" $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1061 | return 1 |
| 1062 | fi |
| 1063 | |
| 1064 | targetJson="" |
| 1065 | |
| 1066 | if [ $3 == "STD" ]; then |
| 1067 | targetJson="{\"enforceStatus\":\"$4\"" |
| 1068 | if [ $# -eq 5 ]; then |
| 1069 | targetJson=$targetJson",\"reason\":\"$5\"" |
| 1070 | fi |
| 1071 | targetJson=$targetJson"}" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1072 | elif [ $3 == "STD2" ]; then |
| 1073 | if [ $4 == "EMPTY" ]; then |
| 1074 | targetJson="{\"enforceStatus\":\"\"" |
| 1075 | else |
| 1076 | targetJson="{\"enforceStatus\":\"$4\"" |
| 1077 | fi |
| 1078 | if [ $# -eq 5 ]; then |
| 1079 | if [ $5 == "EMPTY" ]; then |
| 1080 | targetJson=$targetJson",\"enforceReason\":\"\"" |
| 1081 | else |
| 1082 | targetJson=$targetJson",\"enforceReason\":\"$5\"" |
| 1083 | fi |
| 1084 | fi |
| 1085 | targetJson=$targetJson"}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1086 | elif [ $3 == "OSC" ]; then |
| 1087 | targetJson="{\"instance_status\":\"$4\"" |
| 1088 | if [ $# -eq 5 ]; then |
| 1089 | targetJson=$targetJson",\"has_been_deleted\":\"$5\"" |
| 1090 | fi |
| 1091 | targetJson=$targetJson",\"created_at\":\"????\"}" |
| 1092 | else |
| 1093 | __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@ |
| 1094 | return 1 |
| 1095 | fi |
| 1096 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1097 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1098 | query="/v2/policies/$UUID$2/status" |
| 1099 | targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}" |
| 1100 | else |
| 1101 | query="/policy_status?id="$UUID$2 |
| 1102 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1103 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1104 | res="$(__do_curl_to_api PA GET $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1105 | status=${res:${#res}-3} |
| 1106 | |
| 1107 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1108 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1109 | return 1 |
| 1110 | fi |
| 1111 | |
| 1112 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
| 1113 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1114 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1115 | |
| 1116 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1117 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1118 | return 1 |
| 1119 | fi |
| 1120 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1121 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1122 | return 0 |
| 1123 | } |
| 1124 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1125 | # API Test function: GET /policy_types and V2 GET /v2/policy-types |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1126 | # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]] |
| 1127 | # (Function for test scripts) |
| 1128 | api_get_policy_types() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1129 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1130 | |
| 1131 | if [ $# -lt 1 ]; then |
| 1132 | __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@ |
| 1133 | return 1 |
| 1134 | fi |
| 1135 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1136 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1137 | if [ $# -eq 1 ]; then |
| 1138 | query="/v2/policy-types" |
| 1139 | elif [ $2 == "NORIC" ]; then |
| 1140 | query="/v2/policy-types" |
| 1141 | else |
| 1142 | query="/v2/policy-types?ric_id=$2" |
| 1143 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1144 | else |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1145 | if [ $# -eq 1 ]; then |
| 1146 | query="/policy_types" |
| 1147 | elif [ $2 == "NORIC" ]; then |
| 1148 | query="/policy_types" |
| 1149 | else |
| 1150 | query="/policy_types?ric=$2" |
| 1151 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1152 | fi |
| 1153 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1154 | res="$(__do_curl_to_api PA GET $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1155 | status=${res:${#res}-3} |
| 1156 | |
| 1157 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1158 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1159 | return 1 |
| 1160 | fi |
| 1161 | |
| 1162 | if [ $# -gt 2 ]; then |
| 1163 | body=${res:0:${#res}-3} |
| 1164 | targetJson="[" |
| 1165 | |
| 1166 | for pid in ${@:3} ; do |
| 1167 | if [ "$targetJson" != "[" ]; then |
| 1168 | targetJson=$targetJson"," |
| 1169 | fi |
| 1170 | if [ $pid == "EMPTY" ]; then |
| 1171 | pid="" |
| 1172 | fi |
| 1173 | targetJson=$targetJson"\"$pid\"" |
| 1174 | done |
| 1175 | |
| 1176 | targetJson=$targetJson"]" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1177 | if [ "$PMS_VERSION" == "V2" ]; then |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 1178 | targetJson="{\"policytype_ids\": $targetJson }" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1179 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1180 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1181 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1182 | |
| 1183 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1184 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1185 | return 1 |
| 1186 | fi |
| 1187 | fi |
| 1188 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1189 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1190 | return 0 |
| 1191 | } |
| 1192 | |
| 1193 | ######################################################### |
| 1194 | #### Test case functions Health check |
| 1195 | ######################################################### |
| 1196 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1197 | # API Test function: GET /status and V2 GET /status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1198 | # args: <response-code> |
| 1199 | # (Function for test scripts) |
| 1200 | api_get_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1201 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1202 | if [ $# -ne 1 ]; then |
| 1203 | __print_err "<response-code>" $@ |
| 1204 | return 1 |
| 1205 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1206 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1207 | query="/v2/status" |
| 1208 | else |
| 1209 | query="/status" |
| 1210 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1211 | res="$(__do_curl_to_api PA GET $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1212 | status=${res:${#res}-3} |
| 1213 | |
| 1214 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1215 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1216 | return 1 |
| 1217 | fi |
| 1218 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1219 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1220 | return 0 |
| 1221 | } |
| 1222 | |
| 1223 | ######################################################### |
| 1224 | #### Test case functions RIC Repository |
| 1225 | ######################################################### |
| 1226 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1227 | # API Test function: GET /ric and V2 GET /v2/rics/ric |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1228 | # args: <reponse-code> <management-element-id> [<ric-id>] |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1229 | # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>] |
| 1230 | # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4" |
| 1231 | # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids> |
| 1232 | |
| 1233 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1234 | # (Function for test scripts) |
| 1235 | api_get_ric() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1236 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1237 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1238 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1239 | if [ $# -lt 3 ]; then |
| 1240 | __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@ |
| 1241 | return 1 |
| 1242 | fi |
| 1243 | search="" |
| 1244 | if [ $2 != "NOME" ]; then |
| 1245 | search="?managed_element_id="$2 |
| 1246 | fi |
| 1247 | if [ $3 != "NORIC" ]; then |
| 1248 | if [ -z $search ]; then |
| 1249 | search="?ric_id="$3 |
| 1250 | else |
| 1251 | search=$search"&ric_id="$3 |
| 1252 | fi |
| 1253 | fi |
| 1254 | query="/v2/rics/ric"$search |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1255 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1256 | res="$(__do_curl_to_api PA GET $query)" |
| 1257 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1258 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1259 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1260 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1261 | return 1 |
| 1262 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1263 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1264 | if [ $# -gt 3 ]; then |
| 1265 | body=${res:0:${#res}-3} |
| 1266 | res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4" ) |
| 1267 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1268 | __log_test_fail_general "Could not create target ric info json" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1269 | return 1 |
| 1270 | fi |
| 1271 | |
| 1272 | targetJson=$(<./tmp/.tmp_rics.json) |
| 1273 | targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets |
| 1274 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 1275 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1276 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1277 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1278 | return 1 |
| 1279 | fi |
| 1280 | fi |
| 1281 | else |
| 1282 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 1283 | __print_err "<reponse-code> <management-element-id> [<ric-id>]" $@ |
| 1284 | return 1 |
| 1285 | fi |
| 1286 | |
| 1287 | query="/ric?managedElementId="$2 |
| 1288 | |
| 1289 | res="$(__do_curl_to_api PA GET $query)" |
| 1290 | status=${res:${#res}-3} |
| 1291 | |
| 1292 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1293 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1294 | return 1 |
| 1295 | fi |
| 1296 | |
| 1297 | if [ $# -eq 3 ]; then |
| 1298 | body=${res:0:${#res}-3} |
| 1299 | if [ "$body" != "$3" ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1300 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1301 | return 1 |
| 1302 | fi |
| 1303 | fi |
| 1304 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1305 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1306 | return 0 |
| 1307 | } |
| 1308 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1309 | # API test function: GET /rics and V2 GET /v2/rics |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1310 | # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>] |
| 1311 | # example of <space-separate-string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4 ricsim_g1_1:me2_........." |
| 1312 | # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids> |
| 1313 | # (Function for test scripts) |
| 1314 | api_get_rics() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1315 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1316 | |
| 1317 | if [ $# -lt 2 ]; then |
| 1318 | __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@ |
| 1319 | return 1 |
| 1320 | fi |
| 1321 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1322 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1323 | query="/v2/rics" |
| 1324 | if [ $2 != "NOTYPE" ]; then |
| 1325 | query="/v2/rics?policytype_id="$2 |
| 1326 | fi |
| 1327 | else |
| 1328 | query="/rics" |
| 1329 | if [ $2 != "NOTYPE" ]; then |
| 1330 | query="/rics?policyType="$2 |
| 1331 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1332 | fi |
| 1333 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1334 | res="$(__do_curl_to_api PA GET $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1335 | status=${res:${#res}-3} |
| 1336 | |
| 1337 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1338 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1339 | return 1 |
| 1340 | fi |
| 1341 | |
| 1342 | if [ $# -gt 2 ]; then |
| 1343 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1344 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1345 | res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$3" ) |
| 1346 | else |
| 1347 | res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V1" "$3" ) |
| 1348 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1349 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1350 | __log_test_fail_general "Could not create target ric info json" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1351 | return 1 |
| 1352 | fi |
| 1353 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1354 | targetJson=$(<./tmp/.tmp_rics.json) |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1355 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1356 | targetJson="{\"rics\": $targetJson }" |
| 1357 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1358 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1359 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1360 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1361 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1362 | return 1 |
| 1363 | fi |
| 1364 | fi |
| 1365 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1366 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1367 | return 0 |
| 1368 | } |
| 1369 | |
| 1370 | ################################################################## |
| 1371 | #### API Test case functions Service registry and supervision #### |
| 1372 | ################################################################## |
| 1373 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1374 | # API test function: PUT /service and V2 PUT /service |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1375 | # args: <response-code> <service-name> <keepalive-timeout> <callbackurl> |
| 1376 | # (Function for test scripts) |
| 1377 | api_put_service() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1378 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1379 | if [ $# -ne 4 ]; then |
| 1380 | __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@ |
| 1381 | return 1 |
| 1382 | fi |
| 1383 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1384 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1385 | query="/v2/services" |
| 1386 | json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}" |
| 1387 | else |
| 1388 | query="/service" |
| 1389 | json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}" |
| 1390 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1391 | file="./tmp/.tmp.json" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1392 | echo "$json" > $file |
| 1393 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1394 | res="$(__do_curl_to_api PA PUT $query $file)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1395 | status=${res:${#res}-3} |
| 1396 | |
| 1397 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1398 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1399 | return 1 |
| 1400 | fi |
| 1401 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1402 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1403 | return 0 |
| 1404 | } |
| 1405 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1406 | # API test function: GET /services and V2 GET /v2/services |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1407 | #args: <response-code> [ (<query-service-name> <target-service-name> <keepalive-timeout> <callbackurl>) | (NOSERVICE <target-service-name> <keepalive-timeout> <callbackurl> [<target-service-name> <keepalive-timeout> <callbackurl>]* )] |
| 1408 | # (Function for test scripts) |
| 1409 | api_get_services() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1410 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1411 | #Number of accepted parameters: 1, 2, 4, 7, 10, 13,... |
| 1412 | paramError=1 |
| 1413 | if [ $# -eq 1 ]; then |
| 1414 | paramError=0 |
| 1415 | elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then |
| 1416 | paramError=0 |
| 1417 | elif [ $# -eq 5 ]; then |
| 1418 | paramError=0 |
| 1419 | elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then |
| 1420 | argLen=$(($#-2)) |
| 1421 | if [ $(($argLen%3)) -eq 0 ]; then |
| 1422 | paramError=0 |
| 1423 | fi |
| 1424 | fi |
| 1425 | |
| 1426 | if [ $paramError -ne 0 ]; then |
| 1427 | __print_err "<response-code> [ (<query-service-name> <target-service-name> <keepalive-timeout> <callbackurl>) | (NOSERVICE <target-service-name> <keepalive-timeout> <callbackurl> [<target-service-name> <keepalive-timeout> <callbackurl>]* )]" $@ |
| 1428 | return 1 |
| 1429 | fi |
| 1430 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1431 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1432 | query="/v2/services" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1433 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1434 | if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then |
| 1435 | query="/v2/services?service_id="$2 |
| 1436 | fi |
| 1437 | else |
| 1438 | query="/services" |
| 1439 | |
| 1440 | if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then |
| 1441 | query="/services?name="$2 |
| 1442 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1443 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1444 | res="$(__do_curl_to_api PA GET $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1445 | status=${res:${#res}-3} |
| 1446 | |
| 1447 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1448 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1449 | return 1 |
| 1450 | fi |
| 1451 | |
| 1452 | if [ $# -gt 2 ]; then |
| 1453 | variableArgCount=$(($#-2)) |
| 1454 | body=${res:0:${#res}-3} |
| 1455 | targetJson="[" |
| 1456 | shift; shift; |
| 1457 | cntr=0 |
| 1458 | while [ $cntr -lt $variableArgCount ]; do |
| 1459 | servicename=$1; shift; |
| 1460 | timeout=$1; shift; |
| 1461 | callback=$1; shift; |
| 1462 | if [ $cntr -gt 0 ]; then |
| 1463 | targetJson=$targetJson"," |
| 1464 | fi |
| 1465 | # timeSinceLastActivitySeconds value cannot be checked since value varies |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1466 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1467 | targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}" |
| 1468 | else |
| 1469 | targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}" |
| 1470 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1471 | let cntr=cntr+3 |
| 1472 | done |
| 1473 | targetJson=$targetJson"]" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1474 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1475 | targetJson="{\"service_list\": $targetJson }" |
| 1476 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1477 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1478 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1479 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1480 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1481 | return 1 |
| 1482 | fi |
| 1483 | fi |
| 1484 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1485 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1486 | return 0 |
| 1487 | } |
| 1488 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1489 | # API test function: GET /services V2 GET /v2/services - (only checking service names) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1490 | # args: <response-code> [<service-name>]*" |
| 1491 | # (Function for test scripts) |
| 1492 | api_get_service_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1493 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1494 | |
| 1495 | if [ $# -lt 1 ]; then |
| 1496 | __print_err "<response-code> [<service-name>]*" $@ |
| 1497 | return 1 |
| 1498 | fi |
| 1499 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1500 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1501 | query="/v2/services" |
| 1502 | else |
| 1503 | query="/services" |
| 1504 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1505 | res="$(__do_curl_to_api PA GET $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1506 | status=${res:${#res}-3} |
| 1507 | |
| 1508 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1509 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1510 | return 1 |
| 1511 | fi |
| 1512 | |
| 1513 | body=${res:0:${#res}-3} |
| 1514 | targetJson="[" |
| 1515 | for rapp in ${@:2} ; do |
| 1516 | if [ "$targetJson" != "[" ]; then |
| 1517 | targetJson=$targetJson"," |
| 1518 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1519 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1520 | targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}" |
| 1521 | else |
| 1522 | targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}" |
| 1523 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1524 | done |
| 1525 | |
| 1526 | targetJson=$targetJson"]" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1527 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1528 | targetJson="{\"service_list\": $targetJson }" |
| 1529 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1530 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | 72667f1 | 2020-04-24 09:20:18 +0200 | [diff] [blame] | 1531 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1532 | |
| 1533 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1534 | __log_test_fail_body |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1535 | return 1 |
| 1536 | fi |
| 1537 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1538 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1539 | return 0 |
| 1540 | } |
| 1541 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1542 | # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1543 | # args: <response-code> <service-name> |
| 1544 | # (Function for test scripts) |
| 1545 | api_delete_services() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1546 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1547 | |
| 1548 | if [ $# -ne 2 ]; then |
| 1549 | __print_err "<response-code> <service-name>" $@ |
| 1550 | return 1 |
| 1551 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1552 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1553 | query="/v2/services/"$2 |
| 1554 | else |
| 1555 | query="/services?name="$2 |
| 1556 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1557 | res="$(__do_curl_to_api PA DELETE $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1558 | status=${res:${#res}-3} |
| 1559 | |
| 1560 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1561 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1562 | return 1 |
| 1563 | fi |
| 1564 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1565 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1566 | return 0 |
| 1567 | } |
| 1568 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1569 | # API test function: PUT /services/keepalive and V2 PUT /v2/services/{service_id}/keepalive |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1570 | # args: <response-code> <service-name> |
| 1571 | # (Function for test scripts) |
| 1572 | api_put_services_keepalive() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1573 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1574 | |
| 1575 | if [ $# -ne 2 ]; then |
| 1576 | __print_err "<response-code> <service-name>" $@ |
| 1577 | return 1 |
| 1578 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1579 | if [ "$PMS_VERSION" == "V2" ]; then |
| 1580 | query="/v2/services/$2/keepalive" |
| 1581 | else |
| 1582 | query="/services/keepalive?name="$2 |
| 1583 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1584 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 1585 | res="$(__do_curl_to_api PA PUT $query)" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1586 | status=${res:${#res}-3} |
| 1587 | |
| 1588 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1589 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1590 | return 1 |
| 1591 | fi |
| 1592 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1593 | __log_test_pass |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1594 | return 0 |
| 1595 | } |
| 1596 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame^] | 1597 | ################################################################## |
| 1598 | #### API Test case functions Configuration #### |
| 1599 | ################################################################## |
| 1600 | |
| 1601 | # API Test function: PUT /v2/configuration |
| 1602 | # args: <response-code> <config-file> |
| 1603 | # (Function for test scripts) |
| 1604 | api_put_configuration() { |
| 1605 | __log_test_start $@ |
| 1606 | |
| 1607 | if [ "$PMS_VERSION" != "V2" ]; then |
| 1608 | __log_test_fail_not_supported |
| 1609 | return 1 |
| 1610 | fi |
| 1611 | |
| 1612 | if [ $# -ne 2 ]; then |
| 1613 | __print_err "<response-code> <config-file>" $@ |
| 1614 | return 1 |
| 1615 | fi |
| 1616 | if [ ! -f $2 ]; then |
| 1617 | _log_test_fail_general "Config file "$2", does not exist" |
| 1618 | return 1 |
| 1619 | fi |
| 1620 | inputJson=$(< $2) |
| 1621 | inputJson="{\"config\":"$inputJson"}" |
| 1622 | file="./tmp/.config.json" |
| 1623 | echo $inputJson > $file |
| 1624 | query="/v2/configuration" |
| 1625 | res="$(__do_curl_to_api PA PUT $query $file)" |
| 1626 | status=${res:${#res}-3} |
| 1627 | |
| 1628 | if [ $status -ne $1 ]; then |
| 1629 | __log_test_fail_status_code $1 $status |
| 1630 | return 1 |
| 1631 | fi |
| 1632 | |
| 1633 | __log_test_pass |
| 1634 | return 0 |
| 1635 | } |
| 1636 | |
| 1637 | # API Test function: GET /v2/configuration |
| 1638 | # args: <response-code> [<config-file>] |
| 1639 | # (Function for test scripts) |
| 1640 | api_get_configuration() { |
| 1641 | __log_test_start $@ |
| 1642 | |
| 1643 | if [ "$PMS_VERSION" != "V2" ]; then |
| 1644 | __log_test_fail_not_supported |
| 1645 | return 1 |
| 1646 | fi |
| 1647 | |
| 1648 | if [ $# -lt 1 ] || [ $# -gt 2 ]; then |
| 1649 | __print_err "<response-code> [<config-file>]" $@ |
| 1650 | return 1 |
| 1651 | fi |
| 1652 | if [ ! -f $2 ]; then |
| 1653 | _log_test_fail_general "Config file "$2" for comparison, does not exist" |
| 1654 | return 1 |
| 1655 | fi |
| 1656 | |
| 1657 | query="/v2/configuration" |
| 1658 | res="$(__do_curl_to_api PA GET $query)" |
| 1659 | status=${res:${#res}-3} |
| 1660 | |
| 1661 | if [ $status -ne $1 ]; then |
| 1662 | __log_test_fail_status_code $1 $status |
| 1663 | return 1 |
| 1664 | fi |
| 1665 | |
| 1666 | if [ $# -eq 2 ]; then |
| 1667 | |
| 1668 | body=${res:0:${#res}-3} |
| 1669 | |
| 1670 | targetJson=$(< $2) |
| 1671 | targetJson="{\"config\":"$targetJson"}" |
| 1672 | echo "TARGET JSON: $targetJson" >> $HTTPLOG |
| 1673 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 1674 | |
| 1675 | if [ $res -ne 0 ]; then |
| 1676 | __log_test_fail_body |
| 1677 | return 1 |
| 1678 | fi |
| 1679 | fi |
| 1680 | |
| 1681 | __log_test_pass |
| 1682 | return 0 |
| 1683 | } |