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