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