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