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