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