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