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