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