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. |
JohnKeeney | 2f3b268 | 2024-03-22 16:56:46 +0000 | [diff] [blame] | 5 | # Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved. |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 6 | # ======================================================================== |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | # ============LICENSE_END================================================= |
| 19 | # |
| 20 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 21 | # This is a script that contains management and test functions for A1PMS |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 22 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 23 | ################ Test engine functions ################ |
| 24 | |
| 25 | # Create the image var used during the test |
| 26 | # arg: <image-tag-suffix> (selects staging, snapshot, release etc) |
| 27 | # <image-tag-suffix> is present only for images with staging, snapshot,release tags |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 28 | __A1PMS_imagesetup() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 29 | __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] | 30 | } |
| 31 | |
| 32 | # Pull image from remote repo or use locally built image |
| 33 | # arg: <pull-policy-override> <pull-policy-original> |
| 34 | # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images |
| 35 | # <pull-policy-original> Shall be used for images that does not allow overriding |
| 36 | # Both var may contain: 'remote', 'remote-remove' or 'local' |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 37 | __A1PMS_imagepull() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 38 | __check_and_pull_image $1 "$A1PMS_DISPLAY_NAME" $A1PMS_APP_NAME A1PMS_IMAGE |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | # Build image (only for simulator or interfaces stubs owned by the test environment) |
| 42 | # arg: <image-tag-suffix> (selects staging, snapshot, release etc) |
| 43 | # <image-tag-suffix> is present only for images with staging, snapshot,release tags |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 44 | __A1PMS_imagebuild() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 45 | echo -e $RED" Image for app A1PMS shall never be built"$ERED |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | # 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] | 49 | # 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] | 50 | # arg: <docker-images-format-string> <file-to-append> |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 51 | __A1PMS_image_data() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 52 | echo -e "$A1PMS_DISPLAY_NAME\t$(docker images --format $1 $A1PMS_IMAGE)" >>$2 |
| 53 | if [ ! -z "$A1PMS_IMAGE_SOURCE" ]; then |
| 54 | echo -e "-- source image --\t$(docker images --format $1 $A1PMS_IMAGE_SOURCE)" >>$2 |
| 55 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | # Scale kubernetes resources to zero |
| 59 | # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action. |
| 60 | # This function is called for apps fully managed by the test script |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 61 | __A1PMS_kube_scale_zero() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 62 | __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action. |
BjornMagnussonXA | d54225b | 2023-04-19 14:03:49 +0200 | [diff] [blame] | 66 | # This function is called for pre-started apps not managed by the test script. |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 67 | __A1PMS_kube_scale_zero_and_wait() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 68 | __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] | 69 | } |
| 70 | |
BjornMagnussonXA | d54225b | 2023-04-19 14:03:49 +0200 | [diff] [blame] | 71 | # Delete all kube resources for the app |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 72 | # This function is called for apps managed by the test script. |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 73 | __A1PMS_kube_delete_all() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 74 | __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | # Store docker logs |
| 78 | # This function is called for apps managed by the test script. |
BjornMagnussonXA | d54225b | 2023-04-19 14:03:49 +0200 | [diff] [blame] | 79 | # args: <log-dir> <file-prefix> |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 80 | __A1PMS_store_docker_logs() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 81 | if [ $RUNMODE == "KUBE" ]; then |
| 82 | kubectl $KUBECONF logs -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 >$1$2_a1pms.log 2>&1 |
| 83 | else |
| 84 | docker logs $A1PMS_APP_NAME >$1$2_a1pms.log 2>&1 |
| 85 | fi |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | # Initial setup of protocol, host and ports |
| 89 | # This function is called for apps managed by the test script. |
| 90 | # args: - |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 91 | __A1PMS_initial_setup() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 92 | use_a1pms_rest_http |
| 93 | export A1PMS_SIDECAR_JWT_FILE="" |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 94 | } |
| 95 | |
BjornMagnussonXA | d54225b | 2023-04-19 14:03:49 +0200 | [diff] [blame] | 96 | # Set app short-name, app name and namespace for logging runtime statistics of kubernetes pods or docker containers |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 97 | # For docker, the namespace shall be excluded |
BjornMagnussonXA | d54225b | 2023-04-19 14:03:49 +0200 | [diff] [blame] | 98 | # This function is called for apps managed by the test script as well as for pre-started apps. |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 99 | # args: - |
BjornMagnussonXA | d54225b | 2023-04-19 14:03:49 +0200 | [diff] [blame] | 100 | __A1PMS_statistics_setup() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 101 | if [ $RUNMODE == "KUBE" ]; then |
| 102 | echo "A1PMS $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE" |
| 103 | else |
| 104 | echo "A1PMS $A1PMS_APP_NAME" |
| 105 | fi |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 106 | } |
| 107 | |
BjornMagnussonXA | e60d04e | 2021-12-27 13:38:01 +0100 | [diff] [blame] | 108 | # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied |
| 109 | # args: - |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 110 | __A1PMS_test_requirements() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 111 | : |
BjornMagnussonXA | e60d04e | 2021-12-27 13:38:01 +0100 | [diff] [blame] | 112 | } |
| 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() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 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() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 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() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 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" |
| 141 | echo "" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 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() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 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" |
| 150 | echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW |
| 151 | A1PMS_ADAPTER_TYPE="MR-HTTPS" |
| 152 | echo "" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 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() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 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 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 161 | ## Access to Dmaap adapter |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 162 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 163 | A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME":"$2 # docker access, container->container and script->container via proxy |
| 164 | if [ $RUNMODE == "KUBE" ]; then |
| 165 | A1PMS_SERVICE_PATH=$1"://"$A1PMS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy |
| 166 | fi |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 167 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +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 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 172 | echo "" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 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 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +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 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 189 | export KUBE_NONRTRIC_NAMESPACE |
| 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 |
| 200 | export A1PMS_CONFIG_KEY |
| 201 | export DOCKER_SIM_NWNAME |
| 202 | export A1PMS_HOST_MNT_DIR |
| 203 | export A1PMS_CONFIG_FILE |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 204 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 205 | export A1PMS_DATA_PV_NAME=$A1PMS_APP_NAME"-pv" |
| 206 | export A1PMS_DATA_PVC_NAME=$A1PMS_APP_NAME"-pvc" |
| 207 | ##Create a unique path for the pv each time to prevent a previous volume to be reused |
| 208 | export A1PMS_PV_PATH="a1pmsdata-"$(date +%s) |
| 209 | export A1PMS_CONTAINER_MNT_DIR |
| 210 | export HOST_PATH_BASE_DIR |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 211 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 212 | if [ $1 == "PROXY" ]; then |
| 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 |
| 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 |
| 221 | export A1PMS_HTTP_PROXY_CONFIG_PORT=0 |
| 222 | export A1PMS_HTTP_PROXY_CONFIG_HOST_NAME="" |
| 223 | echo " Configured without http proxy" |
| 224 | fi |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 225 | } |
| 226 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 227 | # Start the ms |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 228 | # args: (docker) PROXY|NOPROXY <config-file> |
| 229 | # args: (kube) PROXY|NOPROXY <config-file> [ <data-file>] |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 230 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 231 | start_a1pms() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 232 | echo -e $BOLD"Starting $A1PMS_DISPLAY_NAME"$EBOLD |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 233 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 234 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 235 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 236 | # Check if app shall be fully managed by the test script |
| 237 | __check_included_image "A1PMS" |
| 238 | retcode_i=$? |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 239 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 240 | # Check if app shall only be used by the test script |
| 241 | __check_prestarted_image "A1PMS" |
| 242 | retcode_p=$? |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 243 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 244 | if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then |
| 245 | echo -e $RED"The $A1PMS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED |
| 246 | echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED |
| 247 | exit |
| 248 | fi |
| 249 | if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then |
| 250 | echo -e $RED"The $A1PMS_APP_NAME app is included both as managed and prestarted in this test script"$ERED |
| 251 | echo -e $RED"The $A1PMS_APP_NAME will not be started"$ERED |
| 252 | exit |
| 253 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 254 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 255 | if [ $retcode_p -eq 0 ]; then |
| 256 | echo -e " Using existing $A1PMS_APP_NAME deployment and service" |
| 257 | echo " Setting $A1PMS_APP_NAME replicas=1" |
| 258 | res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE) |
| 259 | __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 |
| 260 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 261 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 262 | if [ $retcode_i -eq 0 ]; then |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 263 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 264 | echo -e " Creating $A1PMS_APP_NAME app and expose service" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 265 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 266 | #Check if nonrtric namespace exists, if not create it |
| 267 | __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 268 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 269 | __export_a1pms_vars $1 |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 270 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 271 | # Create config map for config |
| 272 | configfile=$PWD/tmp/$A1PMS_CONFIG_FILE |
| 273 | cp $2 $configfile |
| 274 | output_yaml=$PWD/tmp/a1pms-cfc.yaml |
| 275 | __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] | 276 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 277 | # Create config map for data |
| 278 | data_json=$PWD/tmp/$A1PMS_DATA_FILE |
| 279 | if [ $# -lt 3 ]; then |
| 280 | #create empty dummy file |
| 281 | echo "{}" >$data_json |
| 282 | else |
| 283 | cp $3 $data_json |
| 284 | fi |
| 285 | output_yaml=$PWD/tmp/a1pms-cfd.yaml |
| 286 | __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] | 287 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 288 | ## Create pv |
| 289 | input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pv.yaml |
| 290 | output_yaml=$PWD/tmp/a1pms-pv.yaml |
| 291 | __kube_create_instance pv $A1PMS_APP_NAME $input_yaml $output_yaml |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 292 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 293 | ## Create pvc |
| 294 | input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"pvc.yaml |
| 295 | output_yaml=$PWD/tmp/a1pms-pvc.yaml |
| 296 | __kube_create_instance pvc $A1PMS_APP_NAME $input_yaml $output_yaml |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 297 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 298 | # Create service |
| 299 | input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"svc.yaml |
| 300 | output_yaml=$PWD/tmp/a1pmssvc.yaml |
| 301 | __kube_create_instance service $A1PMS_APP_NAME $input_yaml $output_yaml |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 302 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 303 | # Create app |
| 304 | input_yaml=$SIM_GROUP"/"$A1PMS_COMPOSE_DIR"/"app.yaml |
| 305 | output_yaml=$PWD/tmp/a1pmsapp.yaml |
| 306 | if [ -z "$A1PMS_SIDECAR_JWT_FILE" ]; then |
| 307 | cat $input_yaml | sed '/#A1PMS_JWT_START/,/#A1PMS_JWT_STOP/d' >$PWD/tmp/a1pmsapp_tmp.yaml |
| 308 | input_yaml=$PWD/tmp/a1pmsapp_tmp.yaml |
| 309 | fi |
| 310 | __kube_create_instance app $A1PMS_APP_NAME $input_yaml $output_yaml |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 311 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 312 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 313 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 314 | # 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 |
| 315 | if [ $retcode_i -eq 0 ]; then |
| 316 | __A1PMS_WORKER_NODE=$(kubectl $KUBECONF get pod -l "autotest=A1PMS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}') |
| 317 | if [ -z "$__A1PMS_WORKER_NODE" ]; then |
| 318 | echo -e $YELLOW" Cannot find worker node for pod for $A1PMS_APP_NAME, persistency may not work"$EYELLOW |
| 319 | fi |
| 320 | else |
| 321 | 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 |
| 322 | fi |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 323 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 324 | __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 325 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 326 | else |
| 327 | __check_included_image 'A1PMS' |
| 328 | if [ $? -eq 1 ]; then |
| 329 | echo -e $RED"The A1PMS app is not included in this test script"$ERED |
| 330 | echo -e $RED"The A1PMS will not be started"$ERED |
| 331 | exit |
| 332 | fi |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 333 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 334 | curdir=$PWD |
| 335 | cd $SIM_GROUP |
| 336 | cd a1pms |
| 337 | cd $A1PMS_HOST_MNT_DIR |
| 338 | #cd .. |
| 339 | if [ -d db ]; then |
| 340 | if [ "$(ls -A $DIR)" ]; then |
| 341 | echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD |
| 342 | rm -rf db/* &>/dev/null |
| 343 | if [ $? -ne 0 ]; then |
| 344 | echo -e $RED" Cannot remove database files in: $PWD"$ERED |
| 345 | exit 1 |
| 346 | fi |
| 347 | fi |
| 348 | else |
| 349 | echo " No files in mounted dir or dir does not exists" |
| 350 | mkdir db |
| 351 | fi |
| 352 | cd $curdir |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 353 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 354 | __export_a1pms_vars $1 |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 355 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 356 | dest_file=$SIM_GROUP/$A1PMS_COMPOSE_DIR/$A1PMS_HOST_MNT_DIR/application.yaml |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 357 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 358 | envsubst <$2 >$dest_file |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 359 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 360 | __start_container $A1PMS_COMPOSE_DIR "" NODOCKERARGS 1 $A1PMS_APP_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 361 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 362 | __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL |
| 363 | fi |
BjornMagnussonXA | 8fbb226 | 2022-01-24 15:20:15 +0100 | [diff] [blame] | 364 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 365 | __collect_endpoint_stats_image_info "A1PMS" $A1PMS_IMAGE |
| 366 | echo "" |
| 367 | return 0 |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 368 | } |
| 369 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 370 | # Stop the a1pms |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 371 | # args: - |
| 372 | # args: - |
| 373 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 374 | stop_a1pms() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 375 | echo -e $BOLD"Stopping $A1PMS_DISPLAY_NAME"$EBOLD |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 376 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 377 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 378 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 379 | __check_prestarted_image "A1PMS" |
| 380 | if [ $? -eq 0 ]; then |
| 381 | 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 |
| 382 | res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE) |
| 383 | __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0 |
| 384 | return 0 |
| 385 | fi |
| 386 | __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest A1PMS |
| 387 | echo " Deleting the replica set - a new will be started when the app is started" |
| 388 | tmp=$(kubectl $KUBECONF delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=PA") |
| 389 | if [ $? -ne 0 ]; then |
| 390 | echo -e $RED" Could not delete replica set "$RED |
| 391 | ((RES_CONF_FAIL++)) |
| 392 | return 1 |
| 393 | fi |
| 394 | else |
| 395 | docker stop $A1PMS_APP_NAME &>./tmp/.dockererr |
| 396 | if [ $? -ne 0 ]; then |
| 397 | __print_err "Could not stop $A1PMS_APP_NAME" $@ |
| 398 | cat ./tmp/.dockererr |
| 399 | ((RES_CONF_FAIL++)) |
| 400 | return 1 |
| 401 | fi |
| 402 | fi |
| 403 | echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD |
| 404 | echo "" |
| 405 | return 0 |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 406 | } |
| 407 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 408 | # Start a previously stopped a1pms |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 409 | # args: - |
| 410 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 411 | start_stopped_a1pms() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 412 | echo -e $BOLD"Starting (the previously stopped) $A1PMS_DISPLAY_NAME"$EBOLD |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 413 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 414 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 415 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 416 | __check_prestarted_image "A1PMS" |
| 417 | if [ $? -eq 0 ]; then |
| 418 | 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 |
| 419 | res_type=$(__kube_get_resource_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE) |
| 420 | __kube_scale $res_type $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 |
| 421 | __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL |
| 422 | return 0 |
| 423 | fi |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 424 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 425 | # Tie the A1PMS to the same worker node it was initially started on |
| 426 | # 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 |
| 427 | if [ -z "$__A1PMS_WORKER_NODE" ]; then |
| 428 | echo -e $RED" No initial worker node found for pod "$RED |
| 429 | ((RES_CONF_FAIL++)) |
| 430 | return 1 |
| 431 | else |
| 432 | 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 |
| 433 | echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD |
| 434 | tmp=$(kubectl $KUBECONF patch deployment $A1PMS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__A1PMS_WORKER_NODE'"}}}}}') |
| 435 | if [ $? -ne 0 ]; then |
| 436 | echo -e $YELLOW" Cannot set nodeSelector to deployment for $A1PMS_APP_NAME, persistency may not work"$EYELLOW |
| 437 | fi |
| 438 | __kube_scale deployment $A1PMS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 |
| 439 | fi |
| 440 | else |
| 441 | docker start $A1PMS_APP_NAME &>./tmp/.dockererr |
| 442 | if [ $? -ne 0 ]; then |
| 443 | __print_err "Could not start (the stopped) $A1PMS_APP_NAME" $@ |
| 444 | cat ./tmp/.dockererr |
| 445 | ((RES_CONF_FAIL++)) |
| 446 | return 1 |
| 447 | fi |
| 448 | fi |
| 449 | __check_service_start $A1PMS_APP_NAME $A1PMS_SERVICE_PATH$A1PMS_ALIVE_URL |
| 450 | if [ $? -ne 0 ]; then |
| 451 | return 1 |
| 452 | fi |
| 453 | echo "" |
| 454 | return 0 |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 455 | } |
| 456 | |
BjornMagnussonXA | d54225b | 2023-04-19 14:03:49 +0200 | [diff] [blame] | 457 | # Function to prepare the a1pms configuration according to the current simulator configuration |
BjornMagnussonXA | 7d7cb5f | 2023-04-11 10:32:56 +0200 | [diff] [blame] | 458 | # args: SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ] |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 459 | # (Function for test scripts) |
BjornMagnussonXA | f83c362 | 2023-02-28 10:05:51 +0100 | [diff] [blame] | 460 | prepare_a1pms_config() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 461 | echo -e $BOLD"Prepare A1PMS config"$EBOLD |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 462 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 463 | echo " Writing a1pms config for "$A1PMS_APP_NAME" to file: "$2 |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 464 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 465 | if [ $# != 2 ] && [ $# != 4 ]; then |
| 466 | ((RES_CONF_FAIL++)) |
| 467 | __print_err "need two or four args, SDNC|NOSDNC <output-file> [ <sim-group> <adapter-class> ]" $@ |
| 468 | exit 1 |
| 469 | fi |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 470 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 471 | if [ $1 == "SDNC" ]; then |
| 472 | echo -e " Config$BOLD including SDNC$EBOLD configuration" |
| 473 | elif [ $1 == "NOSDNC" ]; then |
| 474 | echo -e " Config$BOLD excluding SDNC$EBOLD configuration" |
| 475 | else |
| 476 | ((RES_CONF_FAIL++)) |
| 477 | __print_err "need three args, SDNC|NOSDNC <output-file> HEADER|NOHEADER" $@ |
| 478 | exit 1 |
| 479 | fi |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 480 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 481 | config_json="\n {" |
| 482 | if [ $1 == "SDNC" ]; then |
| 483 | config_json=$config_json"\n \"controller\": [" |
| 484 | config_json=$config_json"\n {" |
| 485 | config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\"," |
| 486 | config_json=$config_json"\n \"baseUrl\": \"$SDNC_SERVICE_PATH\"," |
| 487 | config_json=$config_json"\n \"userName\": \"$SDNC_USER\"," |
| 488 | config_json=$config_json"\n \"password\": \"$SDNC_PWD\"" |
| 489 | config_json=$config_json"\n }" |
| 490 | config_json=$config_json"\n ]," |
| 491 | fi |
| 492 | if [[ "$A1PMS_FEATURE_LEVEL" == *"NO-DMAAP"* ]]; then |
| 493 | : |
| 494 | else |
| 495 | config_json=$config_json"\n \"streams_publishes\": {" |
| 496 | config_json=$config_json"\n \"dmaap_publisher\": {" |
| 497 | config_json=$config_json"\n \"type\": \"message-router\"," |
| 498 | config_json=$config_json"\n \"dmaap_info\": {" |
| 499 | config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_WRITE_URL\"" |
| 500 | config_json=$config_json"\n }" |
| 501 | config_json=$config_json"\n }" |
| 502 | config_json=$config_json"\n }," |
| 503 | config_json=$config_json"\n \"streams_subscribes\": {" |
| 504 | config_json=$config_json"\n \"dmaap_subscriber\": {" |
| 505 | config_json=$config_json"\n \"type\": \"message-router\"," |
| 506 | config_json=$config_json"\n \"dmaap_info\": {" |
| 507 | config_json=$config_json"\n \"topic_url\": \"$MR_SERVICE_PATH$MR_READ_URL\"" |
| 508 | config_json=$config_json"\n }" |
| 509 | config_json=$config_json"\n }" |
| 510 | config_json=$config_json"\n }," |
| 511 | fi |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 512 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 513 | config_json=$config_json"\n \"ric\": [" |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 514 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 515 | if [ $RUNMODE == "KUBE" ]; then |
| 516 | result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICSIM")].metadata.name}') |
| 517 | rics="" |
| 518 | ric_cntr=0 |
| 519 | if [ $? -eq 0 ] && [ ! -z "$result" ]; then |
| 520 | for im in $result; do |
| 521 | if [[ $im != *"-0" ]]; then |
| 522 | ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}') |
| 523 | rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE |
| 524 | let ric_cntr=ric_cntr+1 |
| 525 | fi |
| 526 | done |
| 527 | fi |
| 528 | result=$(kubectl $KUBECONF get pods -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.items[?(@.metadata.labels.autotest=="RICMEDIATORSIM")].metadata.name}') |
| 529 | oranrics="" |
| 530 | if [ $? -eq 0 ] && [ ! -z "$result" ]; then |
| 531 | for im in $result; do |
| 532 | if [[ $im != *"-0" ]]; then |
| 533 | ric_subdomain=$(kubectl $KUBECONF get pod $im -n $KUBE_A1SIM_NAMESPACE -o jsonpath='{.spec.subdomain}') |
| 534 | rics=$rics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE |
| 535 | oranrics=$oranrics" "$im"."$ric_subdomain"."$KUBE_A1SIM_NAMESPACE |
| 536 | let ric_cntr=ric_cntr+1 |
| 537 | fi |
| 538 | done |
| 539 | fi |
| 540 | if [ $ric_cntr -eq 0 ]; then |
| 541 | echo $YELLOW"Warning: No rics found for the configuration"$EYELLOW |
| 542 | fi |
| 543 | else |
| 544 | rics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=a1sim" --filter "status=running" --format {{.Names}}) |
| 545 | oranrics=$(docker ps --filter "name=$RIC_SIM_PREFIX" --filter "network=$DOCKER_SIM_NWNAME" --filter "label=orana1sim" --filter "status=running" --format {{.Names}}) |
rohithrajneesh | 931e034 | 2023-11-06 18:02:22 +0000 | [diff] [blame] | 546 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 547 | rics="$rics $oranrics" |
rohithrajneesh | 931e034 | 2023-11-06 18:02:22 +0000 | [diff] [blame] | 548 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 549 | if [ $? -ne 0 ] || [ -z "$rics" ]; then |
| 550 | echo -e $RED" FAIL - the names of the running RIC Simulator or ORAN RIC cannot be retrieved." $ERED |
| 551 | ((RES_CONF_FAIL++)) |
| 552 | exit 1 |
| 553 | fi |
| 554 | fi |
| 555 | cntr=0 |
| 556 | for ric in $rics; do |
| 557 | if [ $cntr -gt 0 ]; then |
| 558 | config_json=$config_json"\n ," |
| 559 | fi |
| 560 | config_json=$config_json"\n {" |
| 561 | if [ $RUNMODE == "KUBE" ]; then |
| 562 | ric_id=${ric%.*.*} #extract pod id from full hosthame |
| 563 | ric_id=$(echo "$ric_id" | tr '-' '_') |
| 564 | else |
| 565 | ric_id=$(echo "$ric" | tr '-' '_') #ric var still needs underscore as it is different from the container name |
| 566 | fi |
| 567 | echo " Found a1 sim: "$ric |
| 568 | config_json=$config_json"\n \"name\": \"$ric_id\"," |
BjornMagnussonXA | 7d7cb5f | 2023-04-11 10:32:56 +0200 | [diff] [blame] | 569 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 570 | xricfound=0 |
| 571 | for xric in $oranrics; do |
| 572 | if [ $xric == $ric ]; then |
| 573 | xricfound=1 |
| 574 | fi |
| 575 | done |
| 576 | if [ $xricfound -eq 0 ]; then |
| 577 | config_json=$config_json"\n \"baseUrl\": \"$RIC_SIM_HTTPX://$ric:$RIC_SIM_PORT\"," |
| 578 | else |
| 579 | config_json=$config_json"\n \"baseUrl\": \"$RICMEDIATOR_SIM_HTTPX://$ric:$RICMEDIATOR_SIM_PORT\"," |
| 580 | fi |
| 581 | if [ ! -z "$3" ]; then |
| 582 | if [[ $ric == "$3"* ]]; then |
| 583 | config_json=$config_json"\n \"customAdapterClass\": \"$4\"," |
| 584 | fi |
| 585 | fi |
| 586 | if [ $1 == "SDNC" ]; then |
| 587 | config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\"," |
| 588 | fi |
| 589 | config_json=$config_json"\n \"managedElementIds\": [" |
| 590 | config_json=$config_json"\n \"me1_$ric_id\"," |
| 591 | config_json=$config_json"\n \"me2_$ric_id\"" |
| 592 | config_json=$config_json"\n ]" |
| 593 | config_json=$config_json"\n }" |
| 594 | let cntr=cntr+1 |
| 595 | done |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 596 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 597 | config_json=$config_json"\n ]" |
| 598 | config_json=$config_json"\n}" |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 599 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 600 | config_json="{\"config\":"$config_json"}" |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 601 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 602 | printf "$config_json" >$2 |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 603 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 604 | echo "" |
BjornMagnussonXA | 79e3700 | 2021-11-22 13:36:04 +0100 | [diff] [blame] | 605 | } |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 606 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 607 | # Load the the appl config for the a1pms into a config map |
| 608 | a1pms_load_config() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 609 | echo -e $BOLD"A1PMS - load config from "$EBOLD$1 |
| 610 | data_json=$PWD/tmp/$A1PMS_DATA_FILE |
| 611 | cp $1 $data_json |
| 612 | output_yaml=$PWD/tmp/a1pms-cfd.yaml |
| 613 | __kube_create_configmap $A1PMS_APP_NAME"-data" $KUBE_NONRTRIC_NAMESPACE autotest A1PMS $data_json $output_yaml |
| 614 | echo "" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 615 | } |
| 616 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 617 | # Turn on debug level tracing in the a1pms |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 618 | # args: - |
| 619 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 620 | set_a1pms_debug() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 621 | echo -e $BOLD"Setting a1pms debug logging"$EBOLD |
| 622 | curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}" |
| 623 | result=$(__do_curl "$curlString") |
| 624 | if [ $? -ne 0 ]; then |
| 625 | __print_err "could not set debug mode" $@ |
| 626 | ((RES_CONF_FAIL++)) |
| 627 | return 1 |
| 628 | fi |
| 629 | echo "" |
| 630 | return 0 |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 631 | } |
| 632 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 633 | # Turn on trace level tracing in the a1pms |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 634 | # args: - |
| 635 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 636 | set_a1pms_trace() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 637 | echo -e $BOLD"Setting a1pms trace logging"$EBOLD |
| 638 | curlString="$A1PMS_SERVICE_PATH$A1PMS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}" |
| 639 | result=$(__do_curl "$curlString") |
| 640 | if [ $? -ne 0 ]; then |
| 641 | __print_err "could not set trace mode" $@ |
| 642 | ((RES_CONF_FAIL++)) |
| 643 | return 1 |
| 644 | fi |
| 645 | echo "" |
| 646 | return 0 |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 647 | } |
| 648 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 649 | # 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] | 650 | # Speace separated list of http response codes |
| 651 | # args: [<response-code>]* |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 652 | use_a1pms_retries() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 653 | echo -e $BOLD"Do curl retries to the a1pms REST inteface for these response codes:$@"$EBOLD |
| 654 | AGENT_RETRY_CODES=$@ |
| 655 | echo "" |
| 656 | return |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 657 | } |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 658 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 659 | # Check the a1pms logs for WARNINGs and ERRORs |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 660 | # args: - |
| 661 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 662 | check_a1pms_logs() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 663 | __check_container_logs "A1PMS" $A1PMS_APP_NAME $A1PMS_LOGPATH WARN ERR |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 664 | } |
| 665 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 666 | ######################################################### |
| 667 | #### Test case functions A1 Policy management service |
| 668 | ######################################################### |
| 669 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 670 | # 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] | 671 | # This is done immediately by setting PASS or FAIL or wait up to and optional timeout before setting PASS or FAIL |
| 672 | # args: json:<url> <target-value> [<timeout-in-seconds] |
| 673 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 674 | a1pms_equal() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 675 | echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >>$HTTPLOG |
| 676 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 677 | if [[ $1 == "json:"* ]]; then |
| 678 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 679 | __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v2/" $1 "=" $2 $3 |
| 680 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 681 | echo "var test execution for V3" |
| 682 | __var_test "A1PMS" $A1PMS_SERVICE_PATH$A1PMS_API_PREFIX"/v1/" $1 "=" $2 $3 |
| 683 | else |
| 684 | __var_test "A1PMS" $A1PMS_SERVICE_PATH"/" $1 "=" $2 $3 |
| 685 | fi |
| 686 | return 0 |
| 687 | fi |
| 688 | fi |
| 689 | __print_err "needs two or three args: json:<json-array-param> <target-value> [ timeout ]" $@ |
| 690 | return 1 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 691 | } |
| 692 | |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 693 | # API Test function: GET /policies and V2 GET /v2/policy-instances |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 694 | # 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>]*] |
| 695 | # 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] | 696 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 697 | a1pms_api_get_policies() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 698 | __log_test_start $@ |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 699 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 700 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 701 | paramError=0 |
| 702 | variableParams=$(($# - 4)) |
| 703 | if [ $# -lt 4 ]; then |
| 704 | paramError=1 |
| 705 | elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then |
| 706 | paramError=1 |
| 707 | elif [ $# -gt 5 ] && [ $(($variableParams % 7)) -ne 0 ]; then |
| 708 | paramError=1 |
| 709 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 710 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 711 | if [ $paramError -ne 0 ]; then |
| 712 | __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>]*]" $@ |
| 713 | return 1 |
| 714 | fi |
| 715 | else |
| 716 | paramError=0 |
| 717 | variableParams=$(($# - 4)) |
| 718 | if [ $# -lt 4 ]; then |
| 719 | paramError=1 |
| 720 | elif [ $# -eq 5 ] && [ $5 != "NOID" ]; then |
| 721 | paramError=1 |
| 722 | elif [ $# -gt 5 ] && [ $(($variableParams % 5)) -ne 0 ]; then |
| 723 | paramError=1 |
| 724 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 725 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 726 | if [ $paramError -ne 0 ]; then |
| 727 | __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>]*]" $@ |
| 728 | return 1 |
| 729 | fi |
| 730 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 731 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 732 | queryparams="" |
| 733 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 734 | if [ $2 != "NORIC" ]; then |
| 735 | queryparams="?ric_id="$2 |
| 736 | fi |
| 737 | if [ $3 != "NOSERVICE" ]; then |
| 738 | if [ -z $queryparams ]; then |
| 739 | queryparams="?service_id="$3 |
| 740 | else |
| 741 | queryparams=$queryparams"&service_id="$3 |
| 742 | fi |
| 743 | fi |
| 744 | if [ $4 != "NOTYPE" ]; then |
| 745 | if [ -z $queryparams ]; then |
| 746 | queryparams="?policytype_id="$4 |
| 747 | else |
| 748 | queryparams=$queryparams"&policytype_id="$4 |
| 749 | fi |
| 750 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 751 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 752 | query="/v2/policy-instances"$queryparams |
| 753 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 754 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 755 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 756 | if [ $status -ne $1 ]; then |
| 757 | __log_test_fail_status_code $1 $status |
| 758 | return 1 |
| 759 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 760 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 761 | if [ $# -gt 4 ]; then |
| 762 | body=${res:0:${#res}-3} |
| 763 | if [ $# -eq 5 ] && [ $5 == "NOID" ]; then |
| 764 | targetJson="[" |
| 765 | else |
| 766 | targetJson="[" |
| 767 | arr=(${@:5}) |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 768 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 769 | for ((i = 0; i < $(($# - 4)); i = i + 7)); do |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 770 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 771 | if [ "$targetJson" != "[" ]; then |
| 772 | targetJson=$targetJson"," |
| 773 | fi |
| 774 | targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i + 1]}\",\"service_id\":\"${arr[$i + 2]}\",\"policytype_id\":" |
| 775 | if [ "${arr[$i + 3]}" == "EMPTY" ]; then |
| 776 | targetJson=$targetJson"\"\"," |
| 777 | else |
| 778 | targetJson=$targetJson"\"${arr[$i + 3]}\"," |
| 779 | fi |
| 780 | targetJson=$targetJson"\"transient\":${arr[$i + 4]},\"status_notification_uri\":\"${arr[$i + 5]}\"," |
| 781 | file="./tmp/.p.json" |
| 782 | sed 's/XXX/'${arr[$i]}'/g' ${arr[$i + 6]} >$file |
| 783 | json=$(cat $file) |
| 784 | targetJson=$targetJson"\"policy_data\":"$json"}" |
| 785 | done |
| 786 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 787 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 788 | targetJson=$targetJson"]" |
| 789 | targetJson="{\"policies\": $targetJson}" |
| 790 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 791 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 792 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 793 | if [ $res -ne 0 ]; then |
| 794 | __log_test_fail_body |
| 795 | return 1 |
| 796 | fi |
| 797 | fi |
| 798 | else |
| 799 | if [ $2 != "NORIC" ]; then |
| 800 | queryparams="?ric="$2 |
| 801 | fi |
| 802 | if [ $3 != "NOSERVICE" ]; then |
| 803 | if [ -z $queryparams ]; then |
| 804 | queryparams="?service="$3 |
| 805 | else |
| 806 | queryparams=$queryparams"&service="$3 |
| 807 | fi |
| 808 | fi |
| 809 | if [ $4 != "NOTYPE" ]; then |
| 810 | if [ -z $queryparams ]; then |
| 811 | queryparams="?type="$4 |
| 812 | else |
| 813 | queryparams=$queryparams"&type="$4 |
| 814 | fi |
| 815 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 816 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 817 | query="/policies"$queryparams |
| 818 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 819 | status=${res:${#res}-3} |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 820 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 821 | if [ $status -ne $1 ]; then |
| 822 | __log_test_fail_status_code $1 $status |
| 823 | return 1 |
| 824 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 825 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 826 | if [ $# -gt 4 ]; then |
| 827 | if [ $# -eq 5 ] && [ $5 == "NOID" ]; then |
| 828 | targetJson="[" |
| 829 | else |
| 830 | body=${res:0:${#res}-3} |
| 831 | targetJson="[" |
| 832 | arr=(${@:5}) |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 833 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 834 | for ((i = 0; i < $(($# - 4)); i = i + 5)); do |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 835 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 836 | if [ "$targetJson" != "[" ]; then |
| 837 | targetJson=$targetJson"," |
| 838 | fi |
| 839 | targetJson=$targetJson"{\"id\":\"$UUID${arr[$i]}\",\"lastModified\":\"????\",\"ric\":\"${arr[$i + 1]}\",\"service\":\"${arr[$i + 2]}\",\"type\":" |
| 840 | if [ "${arr[$i + 3]}" == "EMPTY" ]; then |
| 841 | targetJson=$targetJson"\"\"," |
| 842 | else |
| 843 | targetJson=$targetJson"\"${arr[$i + 3]}\"," |
| 844 | fi |
| 845 | file="./tmp/.p.json" |
| 846 | sed 's/XXX/'${arr[$i]}'/g' ${arr[$i + 4]} >$file |
| 847 | json=$(cat $file) |
| 848 | targetJson=$targetJson"\"json\":"$json"}" |
| 849 | done |
| 850 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 851 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 852 | targetJson=$targetJson"]" |
| 853 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 854 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 855 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 856 | if [ $res -ne 0 ]; then |
| 857 | __log_test_fail_body |
| 858 | return 1 |
| 859 | fi |
| 860 | fi |
| 861 | fi |
| 862 | __collect_endpoint_stats "A1PMS" 00 "GET" $A1PMS_API_PREFIX"/v2/policy-instances" $status |
| 863 | __log_test_pass |
| 864 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 865 | |
| 866 | } |
| 867 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 868 | # API Test function: GET /policy, V2 GET /v2/policies/{policy_id} and V3 GET a1policymanagement/v1/policies/{policy_id} |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 869 | # args: <response-code> <policy-id> [<template-file>] |
| 870 | # args(V2): <response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ] |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 871 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 872 | a1pms_api_get_policy() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 873 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 874 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 875 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 876 | if [ $# -ne 2 ] && [ $# -ne 8 ]; then |
| 877 | __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@ |
| 878 | return 1 |
| 879 | fi |
| 880 | query="/v2/policies/$UUID$2" |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 881 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 882 | if [ $# -ne 2 ] && [ $# -ne 8 ]; then |
| 883 | __print_err "<response-code> <policy-id> [ <template-file> <service-name> <ric-id> <policytype-id>|NOTYPE <transient> <notification-url>|NOURL ]" $@ |
| 884 | return 1 |
| 885 | fi |
| 886 | query="/v1/policies/$UUID$2" |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 887 | else |
| 888 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 889 | __print_err "<response-code> <policy-id> [<template-file>] " $@ |
| 890 | return 1 |
| 891 | fi |
| 892 | query="/policy?id=$UUID$2" |
| 893 | fi |
| 894 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 895 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 896 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 897 | if [ $status -ne $1 ]; then |
| 898 | __log_test_fail_status_code $1 $status |
| 899 | return 1 |
| 900 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 901 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 902 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 903 | if [ $# -eq 8 ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 904 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 905 | #Create a policy json to compare with |
| 906 | body=${res:0:${#res}-3} |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 907 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 908 | targetJson="\"ric_id\":\"$5\",\"policy_id\":\"$UUID$2\",\"service_id\":\"$4\"" |
| 909 | if [ $7 != "NOTRANSIENT" ]; then |
| 910 | targetJson=$targetJson", \"transient\":$7" |
| 911 | fi |
| 912 | if [ $6 != "NOTYPE" ]; then |
| 913 | targetJson=$targetJson", \"policytype_id\":\"$6\"" |
| 914 | else |
| 915 | targetJson=$targetJson", \"policytype_id\":\"\"" |
| 916 | fi |
| 917 | if [ $8 != "NOURL" ]; then |
| 918 | targetJson=$targetJson", \"status_notification_uri\":\"$8\"" |
| 919 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 920 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 921 | data=$(sed 's/XXX/'${2}'/g' $3) |
| 922 | targetJson=$targetJson", \"policy_data\":$data" |
| 923 | targetJson="{$targetJson}" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 924 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 925 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 926 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 927 | if [ $res -ne 0 ]; then |
| 928 | __log_test_fail_body |
| 929 | return 1 |
| 930 | fi |
| 931 | fi |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 932 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 933 | if [ $# -eq 8 ]; then |
| 934 | #Create a policy json to compare with |
| 935 | body=${res:0:${#res}-3} |
| 936 | data=$(sed 's/XXX/'${2}'/g' $3) |
| 937 | targetJson=$data |
| 938 | |
| 939 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 940 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 941 | if [ $res -ne 0 ]; then |
| 942 | __log_test_fail_body |
| 943 | return 1 |
| 944 | fi |
| 945 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 946 | else |
| 947 | if [ $# -eq 3 ]; then |
| 948 | #Create a policy json to compare with |
| 949 | body=${res:0:${#res}-3} |
| 950 | file="./tmp/.p.json" |
| 951 | sed 's/XXX/'${2}'/g' $3 >$file |
| 952 | targetJson=$(<$file) |
| 953 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 954 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 955 | if [ $res -ne 0 ]; then |
| 956 | __log_test_fail_body |
| 957 | fi |
| 958 | fi |
| 959 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 960 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 961 | __collect_endpoint_stats "A1PMS" 01 "GET" ${A1PMS_API_PREFIX}${query} ${status} |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 962 | __log_test_pass |
| 963 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 964 | } |
| 965 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 966 | # API Test function: PUT /policy and V2 PUT /policies |
| 967 | # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>] |
| 968 | # 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] | 969 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 970 | a1pms_api_put_policy() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 971 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 972 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 973 | if [ "$A1PMS_VERSION" == "V2" ] || [ "$A1PMS_VERSION" == "V3" ]; then |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 974 | if [ $# -lt 8 ] || [ $# -gt 9 ]; then |
| 975 | __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@ |
| 976 | return 1 |
| 977 | fi |
| 978 | else |
| 979 | if [ $# -lt 7 ] || [ $# -gt 8 ]; then |
| 980 | __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>]" $@ |
| 981 | return 1 |
| 982 | fi |
| 983 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 984 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 985 | count=0 |
| 986 | max=1 |
| 987 | serv=$2 |
| 988 | ric=$3 |
| 989 | pt=$4 |
| 990 | pid=$5 |
| 991 | trans=$6 |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 992 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 993 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 994 | noti=$7 |
| 995 | temp=$8 |
| 996 | if [ $# -eq 9 ]; then |
| 997 | max=$9 |
| 998 | fi |
| 999 | else |
| 1000 | temp=$7 |
| 1001 | if [ $# -eq 8 ]; then |
| 1002 | max=$8 |
| 1003 | fi |
| 1004 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1005 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1006 | while [ $count -lt $max ]; do |
| 1007 | if [ "$A1PMS_VERSION" == "V2" ]; then |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1008 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1009 | query="/v2/policies" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1010 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1011 | inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\"" |
| 1012 | if [ $trans != "NOTRANSIENT" ]; then |
| 1013 | inputJson=$inputJson", \"transient\":$trans" |
| 1014 | fi |
| 1015 | if [ $pt != "NOTYPE" ]; then |
| 1016 | inputJson=$inputJson", \"policytype_id\":\"$pt\"" |
| 1017 | else |
| 1018 | inputJson=$inputJson", \"policytype_id\":\"\"" |
| 1019 | fi |
| 1020 | if [ $noti != "NOURL" ]; then |
| 1021 | inputJson=$inputJson", \"status_notification_uri\":\"$noti\"" |
| 1022 | fi |
| 1023 | file="./tmp/.p.json" |
| 1024 | data=$(sed 's/XXX/'${pid}'/g' $temp) |
| 1025 | inputJson=$inputJson", \"policy_data\":$data" |
| 1026 | inputJson="{$inputJson}" |
| 1027 | echo $inputJson >$file |
| 1028 | else |
| 1029 | query="/policy?id=$UUID$pid&ric=$ric&service=$serv" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1030 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1031 | if [ $pt != "NOTYPE" ]; then |
| 1032 | query=$query"&type=$pt" |
| 1033 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1034 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1035 | if [ $trans != NOTRANSIENT ]; then |
| 1036 | query=$query"&transient=$trans" |
| 1037 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1038 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1039 | file="./tmp/.p.json" |
| 1040 | sed 's/XXX/'${pid}'/g' $temp >$file |
| 1041 | fi |
| 1042 | res="$(__do_curl_to_api A1PMS PUT $query $file)" |
| 1043 | status=${res:${#res}-3} |
| 1044 | echo -ne " Executing "$count"("$max")${SAMELINE}" |
| 1045 | if [ $status -ne $1 ]; then |
| 1046 | echo " Executed "$count"?("$max")" |
| 1047 | __log_test_fail_status_code $1 $status |
| 1048 | return 1 |
| 1049 | fi |
| 1050 | let pid=$pid+1 |
| 1051 | let count=$count+1 |
| 1052 | echo -ne " Executed "$count"("$max")${SAMELINE}" |
| 1053 | done |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 1054 | __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${query} ${status} ${max} |
| 1055 | echo "" |
| 1056 | |
| 1057 | __log_test_pass |
| 1058 | return 0 |
| 1059 | } |
| 1060 | |
| 1061 | # API Test function: V3 PUT a1policymanagement/v1/policies |
| 1062 | # args: <response-code> <policy-id> <template-file> [<count>] |
| 1063 | # args(V2): <response-code> <policy-id> <template-file> [<count>] |
| 1064 | # (Function for test scripts) |
| 1065 | a1pms_api_put_policy_v3() { |
| 1066 | __log_test_start $@ |
| 1067 | |
| 1068 | if [ $# -lt 3 ] || [ $# -gt 4 ]; then |
| 1069 | __print_err "<response-code> <policy-id> <template-file> [<count>]" $@ |
| 1070 | return 1 |
| 1071 | fi |
| 1072 | |
| 1073 | count=0 |
| 1074 | max=1 |
| 1075 | pid=$2 |
| 1076 | temp=$3 |
| 1077 | |
| 1078 | if [ $# -eq 4 ]; then |
| 1079 | max=$4 |
| 1080 | fi |
| 1081 | |
| 1082 | while [ $count -lt $max ]; do |
| 1083 | query="/v1/policies/$UUID$pid" |
| 1084 | file="./tmp/.p_v3.json" |
| 1085 | let update_value=$pid+300 |
| 1086 | data=$(sed 's/XXX/'${update_value}'/g' $temp) |
| 1087 | inputJson="$data" |
| 1088 | echo $inputJson >$file |
| 1089 | res="$(__do_curl_to_api A1PMS PUT $query $file)" |
| 1090 | status=${res:${#res}-3} |
| 1091 | echo -ne " Executing "$count"("$max")${SAMELINE}" |
| 1092 | if [ $status -ne $1 ]; then |
| 1093 | echo " Executed "$count"?("$max")" |
| 1094 | __log_test_fail_status_code $1 $status |
| 1095 | return 1 |
| 1096 | fi |
| 1097 | let pid=$pid+1 |
| 1098 | let count=$count+1 |
| 1099 | echo -ne " Executed "$count"("$max")${SAMELINE}" |
| 1100 | done |
| 1101 | __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${query} ${status} ${max} |
| 1102 | echo "" |
| 1103 | |
| 1104 | __log_test_pass |
| 1105 | return 0 |
| 1106 | } |
| 1107 | |
| 1108 | # API Test function: V£ POST a1policymanagement/v1/policies |
| 1109 | # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <template-file> [<count>] |
| 1110 | # args(V2): <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>] |
| 1111 | # (Function for test scripts) |
| 1112 | a1pms_api_post_policy_v3() { |
| 1113 | __log_test_start $@ |
| 1114 | |
| 1115 | if [ $# -lt 8 ] || [ $# -gt 9 ]; then |
| 1116 | __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient>|NOTRANSIENT <notification-url>|NOURL <template-file> [<count>]" $@ |
| 1117 | return 1 |
| 1118 | fi |
| 1119 | |
| 1120 | count=0 |
| 1121 | max=1 |
| 1122 | serv=$2 |
| 1123 | ric=$3 |
| 1124 | pt=$4 |
| 1125 | pid=$5 |
| 1126 | trans=$6 |
| 1127 | noti=$7 |
| 1128 | temp=$8 |
| 1129 | if [ $# -eq 9 ]; then |
| 1130 | max=$9 |
| 1131 | fi |
| 1132 | |
| 1133 | while [ $count -lt $max ]; do |
| 1134 | query="/v1/policies" |
| 1135 | |
| 1136 | inputJson="\"nearRtRicId\":\"$ric\"" |
| 1137 | if [ $pt != "NOTYPE" ]; then |
| 1138 | inputJson=$inputJson", \"policyTypeId\":\"$pt\"" |
| 1139 | else |
| 1140 | inputJson=$inputJson", \"policyTypeId\":\"\"" |
| 1141 | fi |
| 1142 | if [ $serv != "NOSERVICE" ]; then |
| 1143 | inputJson=$inputJson", \"serviceId\":\"$serv\"" |
| 1144 | fi |
| 1145 | if [ $noti != "NONOTIFYURL" ]; then |
| 1146 | inputJson=$inputJson", \"statusNotificationUri\":\"$noti\"" |
| 1147 | fi |
| 1148 | if [ $trans != "NOTRANSIENT" ]; then |
| 1149 | inputJson=$inputJson", \"transient\":\"$trans\"" |
| 1150 | fi |
| 1151 | file="./tmp/.p.json" |
| 1152 | data=$(sed 's/XXX/'${pid}'/g' $temp) |
| 1153 | inputJson=$inputJson", \"policyObject\":$data" |
| 1154 | inputJson=$inputJson", \"policyId\":\"$UUID$pid\"" |
| 1155 | inputJson="{$inputJson}" |
| 1156 | echo $inputJson >$file |
| 1157 | res="$(__do_curl_to_api A1PMS POST $query $file)" |
| 1158 | status=${res:${#res}-3} |
| 1159 | echo -ne " Executing "$count"("$max")${SAMELINE}" |
| 1160 | if [ $status -ne $1 ]; then |
| 1161 | echo " Executed "$count"?("$max")" |
| 1162 | __log_test_fail_status_code $1 $status |
| 1163 | return 1 |
| 1164 | fi |
| 1165 | let pid=$pid+1 |
| 1166 | let count=$count+1 |
| 1167 | echo -ne " Executed "$count"("$max")${SAMELINE}" |
| 1168 | done |
| 1169 | __collect_endpoint_stats "A1PMS" 02 "PUT" ${A1PMS_API_PREFIX}${A1PMS_VERSION} ${status} ${max} |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1170 | echo "" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1171 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1172 | __log_test_pass |
| 1173 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1174 | } |
| 1175 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1176 | # API Test function: PUT /policy and V2 PUT /policies, to run in batch |
| 1177 | # args: <response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>] |
| 1178 | # 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] | 1179 | # (Function for test scripts) |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1180 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 1181 | a1pms_api_put_policy_batch() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1182 | __log_test_start $@ |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1183 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1184 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 1185 | if [ $# -lt 8 ] || [ $# -gt 9 ]; then |
| 1186 | __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <notification-url>|NOURL <template-file> [<count>]" $@ |
| 1187 | return 1 |
| 1188 | fi |
| 1189 | else |
| 1190 | if [ $# -lt 7 ] || [ $# -gt 8 ]; then |
| 1191 | __print_err "<response-code> <service-name> <ric-id> <policytype-id>|NOTYPE <policy-id> <transient> <template-file> [<count>]" $@ |
| 1192 | return 1 |
| 1193 | fi |
| 1194 | fi |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1195 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1196 | count=0 |
| 1197 | max=1 |
| 1198 | serv=$2 |
| 1199 | ric=$3 |
| 1200 | pt=$4 |
| 1201 | pid=$5 |
| 1202 | trans=$6 |
| 1203 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 1204 | noti=$7 |
| 1205 | temp=$8 |
| 1206 | if [ $# -eq 9 ]; then |
| 1207 | max=$9 |
| 1208 | fi |
| 1209 | else |
| 1210 | temp=$7 |
| 1211 | if [ $# -eq 8 ]; then |
| 1212 | max=$8 |
| 1213 | fi |
| 1214 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1215 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1216 | ARR="" |
| 1217 | while [ $count -lt $max ]; do |
| 1218 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 1219 | query="/v2/policies" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1220 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1221 | inputJson="\"ric_id\":\"$ric\",\"policy_id\":\"$UUID$pid\",\"service_id\":\"$serv\"" |
| 1222 | if [ $trans != "NOTRANSIENT" ]; then |
| 1223 | inputJson=$inputJson", \"transient\":$trans" |
| 1224 | fi |
| 1225 | if [ $pt != "NOTYPE" ]; then |
| 1226 | inputJson=$inputJson", \"policytype_id\":\"$pt\"" |
| 1227 | else |
| 1228 | inputJson=$inputJson", \"policytype_id\":\"\"" |
| 1229 | fi |
| 1230 | if [ $noti != "NOURL" ]; then |
| 1231 | inputJson=$inputJson", \"status_notification_uri\":\"$noti\"" |
| 1232 | fi |
| 1233 | file="./tmp/.p.json" |
| 1234 | data=$(sed 's/XXX/'${pid}'/g' $temp) |
| 1235 | inputJson=$inputJson", \"policy_data\":$data" |
| 1236 | inputJson="{$inputJson}" |
| 1237 | echo $inputJson >$file |
| 1238 | else |
| 1239 | query="/policy?id=$UUID$pid&ric=$ric&service=$serv" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1240 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1241 | if [ $pt != "NOTYPE" ]; then |
| 1242 | query=$query"&type=$pt" |
| 1243 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1244 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1245 | if [ $trans != NOTRANSIENT ]; then |
| 1246 | query=$query"&transient=$trans" |
| 1247 | fi |
| 1248 | file="./tmp/.p.json" |
| 1249 | sed 's/XXX/'${pid}'/g' $temp >$file |
| 1250 | fi |
| 1251 | res="$(__do_curl_to_api A1PMS PUT_BATCH $query $file)" |
| 1252 | status=${res:${#res}-3} |
| 1253 | echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1254 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1255 | if [ $status -ne 200 ]; then |
| 1256 | echo " Requested(batch) "$count"?("$max")" |
| 1257 | __log_test_fail_status_code 200 $status |
| 1258 | return 1 |
| 1259 | fi |
| 1260 | cid=${res:0:${#res}-3} |
| 1261 | ARR=$ARR" "$cid |
| 1262 | let pid=$pid+1 |
| 1263 | let count=$count+1 |
| 1264 | echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" |
| 1265 | done |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1266 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1267 | echo "" |
| 1268 | count=0 |
| 1269 | for cid in $ARR; do |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1270 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1271 | res="$(__do_curl_to_api A1PMS RESPONSE $cid)" |
| 1272 | status=${res:${#res}-3} |
| 1273 | echo -ne " Accepting(batch) "$count"("$max")${SAMELINE}" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1274 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1275 | if [ $status -ne $1 ]; then |
| 1276 | echo " Accepted(batch) "$count"?("$max")" |
| 1277 | __log_test_fail_status_code $1 $status |
| 1278 | return 1 |
| 1279 | fi |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1280 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1281 | let count=$count+1 |
| 1282 | echo -ne " Accepted(batch) "$count"("$max")${SAMELINE}" |
| 1283 | done |
| 1284 | __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $1 $max |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1285 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1286 | echo "" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1287 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1288 | __log_test_pass |
| 1289 | return 0 |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1290 | } |
| 1291 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1292 | # 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] | 1293 | # 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] | 1294 | # 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] | 1295 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 1296 | a1pms_api_put_policy_parallel() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1297 | __log_test_start $@ |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1298 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1299 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 1300 | if [ $# -ne 11 ]; then |
| 1301 | __print_err "These all arguments needed <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>" $@ |
| 1302 | return 1 |
| 1303 | fi |
| 1304 | fi |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1305 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1306 | resp_code=$1 |
| 1307 | shift |
| 1308 | serv=$1 |
| 1309 | shift |
| 1310 | ric_base=$1 |
| 1311 | shift |
| 1312 | num_rics=$1 |
| 1313 | shift |
| 1314 | type=$1 |
| 1315 | shift |
| 1316 | start_id=$1 |
| 1317 | shift |
| 1318 | transient=$1 |
| 1319 | shift |
| 1320 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 1321 | noti=$1 |
| 1322 | shift |
| 1323 | else |
| 1324 | noti="" |
| 1325 | fi |
| 1326 | template=$1 |
| 1327 | shift |
| 1328 | count=$1 |
| 1329 | shift |
| 1330 | pids=$1 |
| 1331 | shift |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1332 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1333 | #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then |
| 1334 | if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then |
| 1335 | echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported" |
| 1336 | echo " Info - will execute over a1pms REST" |
| 1337 | fi |
| 1338 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 1339 | if [ $serv == "NOSERVICE" ]; then |
| 1340 | serv="" |
| 1341 | fi |
| 1342 | query="$A1PMS_API_PREFIX/v2/policies" |
| 1343 | else |
| 1344 | if [ $serv == "NOSERVICE" ]; then |
| 1345 | serv="" |
| 1346 | fi |
| 1347 | query="/policy?service=$serv" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1348 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1349 | if [ $type != "NOTYPE" ]; then |
| 1350 | query=$query"&type=$type" |
| 1351 | fi |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1352 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1353 | if [ $transient != NOTRANSIENT ]; then |
| 1354 | query=$query"&transient=$transient" |
| 1355 | fi |
| 1356 | fi |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1357 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1358 | urlbase=${A1PMS_ADAPTER}${query} |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 1359 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1360 | httpproxy="NOPROXY" |
| 1361 | if [ ! -z "$KUBE_PROXY_PATH" ]; then |
| 1362 | httpproxy=$KUBE_PROXY_PATH |
| 1363 | fi |
| 1364 | |
| 1365 | for ((i = 1; i <= $pids; i++)); do |
| 1366 | uuid=$UUID |
| 1367 | if [ -z "$uuid" ]; then |
| 1368 | uuid="NOUUID" |
| 1369 | fi |
| 1370 | echo "" >"./tmp/.pid${i}.res.txt" |
| 1371 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 1372 | echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt" |
| 1373 | else |
| 1374 | echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt" |
| 1375 | fi |
| 1376 | echo $i |
| 1377 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1378 | arg=$(echo {}) |
| 1379 | echo " Parallel process $arg started" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1380 | tmp=$(< "./tmp/.pid${arg}.txt") |
| 1381 | python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1382 | }' |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1383 | msg="" |
| 1384 | for ((i = 1; i <= $pids; i++)); do |
| 1385 | file="./tmp/.pid${i}.res.txt" |
| 1386 | tmp=$(<$file) |
| 1387 | if [ -z "$tmp" ]; then |
| 1388 | echo " Process $i : unknown result (result file empty" |
| 1389 | msg="failed" |
| 1390 | else |
| 1391 | res=${tmp:0:1} |
| 1392 | if [ $res == "0" ]; then |
| 1393 | echo " Process $i : OK - "${tmp:1} |
| 1394 | else |
| 1395 | echo " Process $i : failed - "${tmp:1} |
| 1396 | msg="failed" |
| 1397 | fi |
| 1398 | fi |
| 1399 | done |
| 1400 | if [ -z $msg ]; then |
| 1401 | __collect_endpoint_stats "A1PMS" 02 "PUT" $A1PMS_API_PREFIX"/v2/policies" $resp_code $(($count * $num_rics)) |
| 1402 | __log_test_pass " $(($count * $num_rics)) policy request(s) executed" |
| 1403 | return 0 |
| 1404 | fi |
| 1405 | __log_test_fail_general "One of more processes failed to execute" |
| 1406 | return 1 |
| 1407 | } |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1408 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1409 | # API Test function: V3 POST /policies, to run in i parallel for a number of rics |
| 1410 | # 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> |
| 1411 | # args(V3): <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> |
| 1412 | # (Function for test scripts) |
| 1413 | a1pms_api_post_policy_parallel() { |
| 1414 | __log_test_start $@ |
| 1415 | |
| 1416 | if [ $# -ne 11 ]; then |
| 1417 | __print_err "These all arguments needed <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>" $@ |
| 1418 | return 1 |
| 1419 | fi |
| 1420 | |
| 1421 | resp_code=$1 |
| 1422 | shift |
| 1423 | serv=$1 |
| 1424 | shift |
| 1425 | ric_base=$1 |
| 1426 | shift |
| 1427 | num_rics=$1 |
| 1428 | shift |
| 1429 | type=$1 |
| 1430 | shift |
| 1431 | start_id=$1 |
| 1432 | shift |
| 1433 | transient=$1 |
| 1434 | shift |
| 1435 | noti=$1 |
| 1436 | shift |
| 1437 | template=$1 |
| 1438 | shift |
| 1439 | count=$1 |
| 1440 | shift |
| 1441 | pids=$1 |
| 1442 | shift |
| 1443 | |
| 1444 | #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then |
| 1445 | if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then |
| 1446 | echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported" |
| 1447 | echo " Info - will execute over a1pms REST" |
| 1448 | fi |
| 1449 | |
| 1450 | if [ $serv == "NOSERVICE" ]; then |
| 1451 | serv="" |
| 1452 | fi |
| 1453 | query="$A1PMS_API_PREFIX/v1/policies" |
| 1454 | |
| 1455 | urlbase=${A1PMS_ADAPTER}${query} |
| 1456 | |
| 1457 | httpproxy="NOPROXY" |
| 1458 | if [ ! -z "$KUBE_PROXY_PATH" ]; then |
| 1459 | httpproxy=$KUBE_PROXY_PATH |
| 1460 | fi |
| 1461 | |
| 1462 | for ((i = 1; i <= $pids; i++)); do |
| 1463 | uuid=$UUID |
| 1464 | if [ -z "$uuid" ]; then |
| 1465 | uuid="NOUUID" |
| 1466 | fi |
| 1467 | echo "" >"./tmp/.pid${i}.res.txt" |
| 1468 | echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy >"./tmp/.pid${i}.txt" |
| 1469 | echo $i |
| 1470 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
| 1471 | arg=$(echo {}) |
| 1472 | echo " Parallel process $arg started" |
| 1473 | tmp=$(< "./tmp/.pid${arg}.txt") |
| 1474 | python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt |
| 1475 | }' |
| 1476 | msg="" |
| 1477 | for ((i = 1; i <= $pids; i++)); do |
| 1478 | file="./tmp/.pid${i}.res.txt" |
| 1479 | tmp=$(<$file) |
| 1480 | if [ -z "$tmp" ]; then |
| 1481 | echo " Process $i : unknown result (result file empty" |
| 1482 | msg="failed" |
| 1483 | else |
| 1484 | res=${tmp:0:1} |
| 1485 | if [ $res == "0" ]; then |
| 1486 | echo " Process $i : OK - "${tmp:1} |
| 1487 | else |
| 1488 | echo " Process $i : failed - "${tmp:1} |
| 1489 | msg="failed" |
| 1490 | fi |
| 1491 | fi |
| 1492 | done |
| 1493 | if [ -z $msg ]; then |
| 1494 | __collect_endpoint_stats "A1PMS" 02 "POST" $A1PMS_API_PREFIX"/v1/policies" $resp_code $(($count * $num_rics)) |
| 1495 | __log_test_pass " $(($count * $num_rics)) policy request(s) executed" |
| 1496 | return 0 |
| 1497 | fi |
| 1498 | __log_test_fail_general "One of more processes failed to execute" |
| 1499 | return 1 |
| 1500 | } |
| 1501 | |
| 1502 | # API Test function: V3 PUT /policies, to run in i parallel for a number of rics |
| 1503 | # 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> <policy-ids-file-path> |
| 1504 | # args(V3): <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> <policy-ids-file-path> |
| 1505 | # (Function for test scripts) |
| 1506 | a1pms_api_update_policy_parallel() { |
| 1507 | __log_test_start $@ |
| 1508 | |
| 1509 | if [ $# -ne 12 ]; then |
| 1510 | __print_err "These all arguments needed <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> <policy-ids-file-path>" $@ |
| 1511 | return 1 |
| 1512 | fi |
| 1513 | |
| 1514 | resp_code=$1 |
| 1515 | shift |
| 1516 | serv=$1 |
| 1517 | shift |
| 1518 | ric_base=$1 |
| 1519 | shift |
| 1520 | num_rics=$1 |
| 1521 | shift |
| 1522 | type=$1 |
| 1523 | shift |
| 1524 | start_id=$1 |
| 1525 | shift |
| 1526 | transient=$1 |
| 1527 | shift |
| 1528 | noti=$1 |
| 1529 | shift |
| 1530 | template=$1 |
| 1531 | shift |
| 1532 | count=$1 |
| 1533 | shift |
| 1534 | pids=$1 |
| 1535 | shift |
| 1536 | policy_ids_file_path=$1 |
| 1537 | shift |
| 1538 | |
| 1539 | #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then |
| 1540 | if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then |
| 1541 | echo " Info - a1pms_api_put_policy_parallel uses only the a1pms REST interface - create over dmaap in parallel is not supported" |
| 1542 | echo " Info - will execute over a1pms REST" |
| 1543 | fi |
| 1544 | |
| 1545 | if [ $serv == "NOSERVICE" ]; then |
| 1546 | serv="" |
| 1547 | fi |
| 1548 | query="$A1PMS_API_PREFIX/v1/policies" |
| 1549 | |
| 1550 | urlbase=${A1PMS_ADAPTER}${query} |
| 1551 | |
| 1552 | httpproxy="NOPROXY" |
| 1553 | if [ ! -z "$KUBE_PROXY_PATH" ]; then |
| 1554 | httpproxy=$KUBE_PROXY_PATH |
| 1555 | fi |
| 1556 | |
| 1557 | for ((i = 1; i <= $pids; i++)); do |
| 1558 | uuid=$UUID |
| 1559 | if [ -z "$uuid" ]; then |
| 1560 | uuid="NOUUID" |
| 1561 | fi |
| 1562 | echo "" >"./tmp/.pid${i}.res.txt" |
| 1563 | echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $serv $type $transient $noti $template $count $pids $i $httpproxy $policy_ids_file_path >"./tmp/.pid${i}.txt" |
| 1564 | echo $i |
| 1565 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
| 1566 | arg=$(echo {}) |
| 1567 | echo " Parallel process $arg started" |
| 1568 | tmp=$(< "./tmp/.pid${arg}.txt") |
| 1569 | python3 ../common/update_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt |
| 1570 | }' |
| 1571 | msg="" |
| 1572 | for ((i = 1; i <= $pids; i++)); do |
| 1573 | file="./tmp/.pid${i}.res.txt" |
| 1574 | tmp=$(<$file) |
| 1575 | if [ -z "$tmp" ]; then |
| 1576 | echo " Process $i : unknown result (result file empty" |
| 1577 | msg="failed" |
| 1578 | else |
| 1579 | res=${tmp:0:1} |
| 1580 | if [ $res == "0" ]; then |
| 1581 | echo " Process $i : OK - "${tmp:1} |
| 1582 | else |
| 1583 | echo " Process $i : failed - "${tmp:1} |
| 1584 | msg="failed" |
| 1585 | fi |
| 1586 | fi |
| 1587 | done |
| 1588 | if [ -z $msg ]; then |
| 1589 | __collect_endpoint_stats "A1PMS" 02 "POST" $A1PMS_API_PREFIX"/v1/policies" $resp_code $(($count * $num_rics)) |
| 1590 | __log_test_pass " $(($count * $num_rics)) policy request(s) executed" |
| 1591 | return 0 |
| 1592 | fi |
| 1593 | __log_test_fail_general "One of more processes failed to execute" |
| 1594 | return 1 |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1595 | } |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1596 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1597 | # API Test function: DELETE /policy and V2 DELETE /v2/policies/{policy_id} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1598 | # args: <response-code> <policy-id> [count] |
| 1599 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 1600 | a1pms_api_delete_policy() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1601 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1602 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1603 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 1604 | __print_err "<response-code> <policy-id> [count]" $@ |
| 1605 | return 1 |
| 1606 | fi |
| 1607 | |
| 1608 | count=0 |
| 1609 | max=1 |
| 1610 | |
| 1611 | if [ $# -eq 3 ]; then |
| 1612 | max=$3 |
| 1613 | fi |
| 1614 | |
| 1615 | pid=$2 |
| 1616 | |
| 1617 | while [ $count -lt $max ]; do |
| 1618 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 1619 | query="/v2/policies/"$UUID$pid |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 1620 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 1621 | query="/v1/policies/"$UUID$pid |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1622 | else |
| 1623 | query="/policy?id="$UUID$pid |
| 1624 | fi |
| 1625 | res="$(__do_curl_to_api A1PMS DELETE $query)" |
| 1626 | status=${res:${#res}-3} |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 1627 | echo -ne " Executing "${count}"("${max}")${SAMELINE}" |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1628 | |
| 1629 | if [ $status -ne $1 ]; then |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 1630 | echo " Executed "${count}"?("${max}")" |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1631 | __log_test_fail_status_code $1 $status |
| 1632 | return 1 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1633 | fi |
| 1634 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1635 | let pid=$pid+1 |
| 1636 | let count=$count+1 |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 1637 | echo -ne " Executed "${count}"("${max}")${SAMELINE}" |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1638 | done |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 1639 | __collect_endpoint_stats "A1PMS" 03 "DELETE" ${A1PMS_API_PREFIX}${query} ${status} ${max} |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1640 | echo "" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1641 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1642 | __log_test_pass |
| 1643 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1644 | } |
| 1645 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1646 | # 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] | 1647 | # args: <response-code> <policy-id> [count] |
| 1648 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 1649 | a1pms_api_delete_policy_batch() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1650 | __log_test_start $@ |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1651 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1652 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 1653 | __print_err "<response-code> <policy-id> [count]" $@ |
| 1654 | return 1 |
| 1655 | fi |
| 1656 | |
| 1657 | count=0 |
| 1658 | max=1 |
| 1659 | |
| 1660 | if [ $# -eq 3 ]; then |
| 1661 | max=$3 |
| 1662 | fi |
| 1663 | |
| 1664 | pid=$2 |
| 1665 | ARR="" |
| 1666 | while [ $count -lt $max ]; do |
| 1667 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 1668 | query="/v2/policies/"$UUID$pid |
| 1669 | else |
| 1670 | query="/policy?id="$UUID$pid |
| 1671 | fi |
| 1672 | res="$(__do_curl_to_api A1PMS DELETE_BATCH $query)" |
| 1673 | status=${res:${#res}-3} |
| 1674 | echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}" |
| 1675 | |
| 1676 | if [ $status -ne 200 ]; then |
| 1677 | echo " Requested(batch) "$count"?("$max")" |
| 1678 | __log_test_fail_status_code 200 $status |
| 1679 | return 1 |
| 1680 | fi |
| 1681 | cid=${res:0:${#res}-3} |
| 1682 | ARR=$ARR" "$cid |
| 1683 | let pid=$pid+1 |
| 1684 | let count=$count+1 |
| 1685 | echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" |
| 1686 | done |
| 1687 | |
| 1688 | echo "" |
| 1689 | |
| 1690 | count=0 |
| 1691 | for cid in $ARR; do |
| 1692 | |
| 1693 | res="$(__do_curl_to_api A1PMS RESPONSE $cid)" |
| 1694 | status=${res:${#res}-3} |
| 1695 | echo -ne " Deleting(batch) "$count"("$max")${SAMELINE}" |
| 1696 | |
| 1697 | if [ $status -ne $1 ]; then |
| 1698 | echo " Deleted(batch) "$count"?("$max")" |
| 1699 | __log_test_fail_status_code $1 $status |
| 1700 | return 1 |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1701 | fi |
| 1702 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1703 | let count=$count+1 |
| 1704 | echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}" |
| 1705 | done |
| 1706 | __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] | 1707 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1708 | echo "" |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1709 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1710 | __log_test_pass |
| 1711 | return 0 |
BjornMagnussonXA | 70e878f | 2020-05-11 14:11:30 +0200 | [diff] [blame] | 1712 | } |
| 1713 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1714 | # 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] | 1715 | # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads> |
| 1716 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 1717 | a1pms_api_delete_policy_parallel() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1718 | __log_test_start $@ |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1719 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1720 | if [ $# -ne 5 ]; then |
| 1721 | __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@ |
| 1722 | return 1 |
| 1723 | fi |
| 1724 | resp_code=$1 |
| 1725 | shift |
| 1726 | num_rics=$1 |
| 1727 | shift |
| 1728 | start_id=$1 |
| 1729 | shift |
| 1730 | count=$1 |
| 1731 | shift |
| 1732 | pids=$1 |
| 1733 | shift |
| 1734 | |
| 1735 | #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then |
| 1736 | if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then |
| 1737 | echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported" |
| 1738 | echo " Info - will execute over a1pms REST" |
| 1739 | fi |
| 1740 | |
| 1741 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 1742 | query="$A1PMS_API_PREFIX/v2/policies/" |
| 1743 | else |
| 1744 | query="/policy" |
| 1745 | fi |
| 1746 | |
| 1747 | urlbase=${A1PMS_ADAPTER}${query} |
| 1748 | |
| 1749 | httpproxy="NOPROXY" |
| 1750 | if [ ! -z "$KUBE_PROXY_PATH" ]; then |
| 1751 | httpproxy=$KUBE_PROXY_PATH |
| 1752 | fi |
| 1753 | |
| 1754 | for ((i = 1; i <= $pids; i++)); do |
| 1755 | uuid=$UUID |
| 1756 | if [ -z "$uuid" ]; then |
| 1757 | uuid="NOUUID" |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1758 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1759 | echo "" >"./tmp/.pid${i}.del.res.txt" |
| 1760 | echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy >"./tmp/.pid${i}.del.txt" |
| 1761 | echo $i |
| 1762 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1763 | arg=$(echo {}) |
| 1764 | echo " Parallel process $arg started" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 1765 | tmp=$(< "./tmp/.pid${arg}.del.txt") |
| 1766 | python3 ../common/delete_policies_process.py $tmp > ./tmp/.pid${arg}.del.res.txt |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1767 | }' |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1768 | msg="" |
| 1769 | for ((i = 1; i <= $pids; i++)); do |
| 1770 | file="./tmp/.pid${i}.del.res.txt" |
| 1771 | tmp=$(<$file) |
| 1772 | if [ -z "$tmp" ]; then |
| 1773 | echo " Process $i : unknown result (result file empty" |
| 1774 | msg="failed" |
| 1775 | else |
| 1776 | res=${tmp:0:1} |
| 1777 | if [ $res == "0" ]; then |
| 1778 | echo " Process $i : OK - "${tmp:1} |
| 1779 | else |
| 1780 | echo " Process $i : failed - "${tmp:1} |
| 1781 | msg="failed" |
| 1782 | fi |
| 1783 | fi |
| 1784 | done |
| 1785 | if [ -z $msg ]; then |
| 1786 | __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count * $num_rics)) |
| 1787 | __log_test_pass " $(($count * $num_rics)) policy request(s) executed" |
| 1788 | return 0 |
| 1789 | fi |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1790 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1791 | __log_test_fail_general "One of more processes failed to execute" |
| 1792 | return 1 |
| 1793 | } |
| 1794 | |
| 1795 | # API Test function: V3 DELETE a1policymanagement/v1/policies/{policy_id}, to run in i parallel for a number of rics |
| 1796 | # args: <responseCode> <numberOfRics> <PolicyIdsFilePath> <countPerRic> <numberOfThreads> |
| 1797 | # (Function for test scripts) |
| 1798 | a1pms_api_delete_policy_parallel_v3() { |
| 1799 | __log_test_start $@ |
| 1800 | |
| 1801 | if [ $# -ne 6 ]; then |
| 1802 | __print_err " <responseCode> <numberOfRics> <PolicyIdsFilePath> <StartID> <countPerRic> <numberOfThreads>" $@ |
| 1803 | return 1 |
| 1804 | fi |
| 1805 | resp_code=$1 |
| 1806 | shift |
| 1807 | num_rics=$1 |
| 1808 | shift |
| 1809 | policy_ids_file_path=$1 |
| 1810 | shift |
| 1811 | start_id=$1 |
| 1812 | shift |
| 1813 | count=$1 |
| 1814 | shift |
| 1815 | pids=$1 |
| 1816 | shift |
| 1817 | |
| 1818 | #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then |
| 1819 | if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then |
| 1820 | echo " Info - a1pms_api_delete_policy_parallel uses only the a1pms REST interface - delete over dmaap in parallel is not supported" |
| 1821 | echo " Info - will execute over a1pms REST" |
| 1822 | fi |
| 1823 | |
| 1824 | query="$A1PMS_API_PREFIX/v1/policies/" |
| 1825 | urlbase=${A1PMS_ADAPTER}${query} |
| 1826 | |
| 1827 | urlbase=${A1PMS_ADAPTER}${query} |
| 1828 | |
| 1829 | httpproxy="NOPROXY" |
| 1830 | if [ ! -z "$KUBE_PROXY_PATH" ]; then |
| 1831 | httpproxy=$KUBE_PROXY_PATH |
| 1832 | fi |
| 1833 | |
| 1834 | for ((i = 1; i <= $pids; i++)); do |
| 1835 | echo "" >"./tmp/.pid${i}.del.res.txt" |
| 1836 | echo $resp_code $urlbase $policy_ids_file_path $start_id $pids $i $httpproxy >"./tmp/.pid${i}.del.txt" |
| 1837 | echo $i |
| 1838 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
| 1839 | arg=$(echo {}) |
| 1840 | echo " Parallel process $arg started" |
| 1841 | tmp=$(< "./tmp/.pid${arg}.del.txt") |
| 1842 | python3 ../common/delete_policies_process_v3.py $tmp > ./tmp/.pid${arg}.del.res.txt |
| 1843 | }' |
| 1844 | msg="" |
| 1845 | for ((i = 1; i <= $pids; i++)); do |
| 1846 | file="./tmp/.pid${i}.del.res.txt" |
| 1847 | tmp=$(<$file) |
| 1848 | if [ -z "$tmp" ]; then |
| 1849 | echo " Process $i : unknown result (result file empty" |
| 1850 | msg="failed" |
| 1851 | else |
| 1852 | res=${tmp:0:1} |
| 1853 | if [ $res == "0" ]; then |
| 1854 | echo " Process $i : OK - "${tmp:1} |
| 1855 | else |
| 1856 | echo " Process $i : failed - "${tmp:1} |
| 1857 | msg="failed" |
| 1858 | fi |
| 1859 | fi |
| 1860 | done |
| 1861 | if [ -z $msg ]; then |
| 1862 | __collect_endpoint_stats "A1PMS" 03 "DELETE" $A1PMS_API_PREFIX"/v1/policies/{policy_id}" $resp_code $(($count * $num_rics)) |
| 1863 | __log_test_pass " $(($count * $num_rics)) policy request(s) executed" |
| 1864 | return 0 |
| 1865 | fi |
| 1866 | |
| 1867 | __log_test_fail_general "One of more processes failed to execute" |
| 1868 | return 1 |
BjornMagnussonXA | bbd2e9d | 2020-05-27 21:24:06 +0200 | [diff] [blame] | 1869 | } |
| 1870 | |
JohnKeeney | 2f3b268 | 2024-03-22 16:56:46 +0000 | [diff] [blame] | 1871 | # API Test function: GET /policy and V2 GET /v2/policies/{policy_id}, to run in i parallel for a number of rics |
| 1872 | # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads> |
| 1873 | # (Function for test scripts) |
| 1874 | a1pms_api_get_policy_parallel() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1875 | __log_test_start $@ |
JohnKeeney | 2f3b268 | 2024-03-22 16:56:46 +0000 | [diff] [blame] | 1876 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1877 | if [ $# -ne 5 ]; then |
| 1878 | __print_err " <response-code> <ric-id-base> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads>" $@ |
| 1879 | return 1 |
| 1880 | fi |
| 1881 | resp_code=$1 |
| 1882 | shift |
| 1883 | num_rics=$1 |
| 1884 | shift |
| 1885 | start_id=$1 |
| 1886 | shift |
| 1887 | count=$1 |
| 1888 | shift |
| 1889 | pids=$1 |
| 1890 | shift |
| 1891 | |
| 1892 | #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then |
| 1893 | if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then |
| 1894 | echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported" |
| 1895 | echo " Info - will execute over a1pms REST" |
| 1896 | fi |
| 1897 | |
| 1898 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 1899 | query="$A1PMS_API_PREFIX/v2/policies/" |
| 1900 | else |
| 1901 | query="/policy" |
| 1902 | fi |
| 1903 | |
| 1904 | urlbase=${A1PMS_ADAPTER}${query} |
| 1905 | |
| 1906 | httpproxy="NOPROXY" |
| 1907 | if [ ! -z "$KUBE_PROXY_PATH" ]; then |
| 1908 | httpproxy=$KUBE_PROXY_PATH |
| 1909 | fi |
| 1910 | |
| 1911 | for ((i = 1; i <= $pids; i++)); do |
| 1912 | uuid=$UUID |
| 1913 | if [ -z "$uuid" ]; then |
| 1914 | uuid="NOUUID" |
JohnKeeney | 2f3b268 | 2024-03-22 16:56:46 +0000 | [diff] [blame] | 1915 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1916 | echo "" >"./tmp/.pid${i}.get.res.txt" |
| 1917 | echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i $httpproxy >"./tmp/.pid${i}.get.txt" |
| 1918 | echo $i |
| 1919 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
JohnKeeney | 2f3b268 | 2024-03-22 16:56:46 +0000 | [diff] [blame] | 1920 | arg=$(echo {}) |
| 1921 | echo " Parallel process $arg started" |
| 1922 | tmp=$(< "./tmp/.pid${arg}.get.txt") |
| 1923 | python3 ../common/get_policies_process.py $tmp > ./tmp/.pid${arg}.get.res.txt |
| 1924 | }' |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1925 | msg="" |
| 1926 | for ((i = 1; i <= $pids; i++)); do |
| 1927 | file="./tmp/.pid${i}.get.res.txt" |
| 1928 | tmp=$(<$file) |
| 1929 | if [ -z "$tmp" ]; then |
| 1930 | echo " Process $i : unknown result (result file empty" |
| 1931 | msg="failed" |
| 1932 | else |
| 1933 | res=${tmp:0:1} |
| 1934 | if [ $res == "0" ]; then |
| 1935 | echo " Process $i : OK - "${tmp:1} |
| 1936 | else |
| 1937 | echo " Process $i : failed - "${tmp:1} |
| 1938 | msg="failed" |
| 1939 | fi |
| 1940 | fi |
| 1941 | done |
| 1942 | if [ -z $msg ]; then |
| 1943 | __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}" $resp_code $(($count * $num_rics)) |
| 1944 | __log_test_pass " $(($count * $num_rics)) policy request(s) executed" |
| 1945 | return 0 |
| 1946 | fi |
JohnKeeney | 2f3b268 | 2024-03-22 16:56:46 +0000 | [diff] [blame] | 1947 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 1948 | __log_test_fail_general "One of more processes failed to execute" |
| 1949 | return 1 |
| 1950 | } |
| 1951 | |
| 1952 | # API Test function: V3 GET a1policymanagement/v1/policies/{policy_id}, to run in i parallel for a number of rics |
| 1953 | # args: <response-code> <number-of-rics> <policy-start-id> <count-per-ric> <number-of-threads> |
| 1954 | # (Function for test scripts) |
| 1955 | a1pms_api_get_policy_parallel_v3() { |
| 1956 | __log_test_start $@ |
| 1957 | |
| 1958 | if [ $# -ne 6 ]; then |
| 1959 | __print_err " <responseCode> <numberOfRics> <PolicyIdsFilePath> <startID> <countPerRic> <numberOfThreads>" $@ |
| 1960 | return 1 |
| 1961 | fi |
| 1962 | resp_code=$1 |
| 1963 | shift |
| 1964 | num_rics=$1 |
| 1965 | shift |
| 1966 | policy_ids_file_path=$1 |
| 1967 | shift |
| 1968 | start_id=$1 |
| 1969 | shift |
| 1970 | count=$1 |
| 1971 | shift |
| 1972 | pids=$1 |
| 1973 | shift |
| 1974 | |
| 1975 | #if [ $A1PMS_ADAPTER != $RESTBASE ] && [ $A1PMS_ADAPTER != $RESTBASE_SECURE ]; then |
| 1976 | if [ $A1PMS_ADAPTER_TYPE != "REST" ]; then |
| 1977 | echo " Info - a1pms_api_get_policy_parallel uses only the a1pms REST interface - GET over dmaap in parallel is not supported" |
| 1978 | echo " Info - will execute over a1pms REST" |
| 1979 | fi |
| 1980 | |
| 1981 | query="$A1PMS_API_PREFIX/v1/policies/" |
| 1982 | urlbase=${A1PMS_ADAPTER}${query} |
| 1983 | |
| 1984 | httpproxy="NOPROXY" |
| 1985 | if [ ! -z "$KUBE_PROXY_PATH" ]; then |
| 1986 | httpproxy=$KUBE_PROXY_PATH |
| 1987 | fi |
| 1988 | |
| 1989 | for ((i = 1; i <= $pids; i++)); do |
| 1990 | echo "" >"./tmp/.pid${i}.get.res.txt" |
| 1991 | echo $resp_code $urlbase $policy_ids_file_path $start_id $pids $i $httpproxy >"./tmp/.pid${i}.get.txt" |
| 1992 | echo $i |
| 1993 | done | xargs -n 1 -I{} -P $pids bash -c '{ |
| 1994 | arg=$(echo {}) |
| 1995 | echo " Parallel process $arg started" |
| 1996 | tmp=$(< "./tmp/.pid${arg}.get.txt") |
| 1997 | python3 ../common/get_policies_process_v3.py $tmp > ./tmp/.pid${arg}.get.res.txt |
| 1998 | }' |
| 1999 | msg="" |
| 2000 | for ((i = 1; i <= $pids; i++)); do |
| 2001 | file="./tmp/.pid${i}.get.res.txt" |
| 2002 | tmp=$(<$file) |
| 2003 | if [ -z "$tmp" ]; then |
| 2004 | echo " Process $i : unknown result (result file empty" |
| 2005 | msg="failed" |
| 2006 | else |
| 2007 | res=${tmp:0:1} |
| 2008 | if [ $res == "0" ]; then |
| 2009 | echo " Process $i : OK - "${tmp:1} |
| 2010 | else |
| 2011 | echo " Process $i : failed - "${tmp:1} |
| 2012 | msg="failed" |
| 2013 | fi |
| 2014 | fi |
| 2015 | done |
| 2016 | if [ -z $msg ]; then |
| 2017 | __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v1/policies/{policyId}" $resp_code $(($count * $num_rics)) |
| 2018 | __log_test_pass " $(($count * $num_rics)) policy request(s) executed" |
| 2019 | return 0 |
| 2020 | fi |
| 2021 | |
| 2022 | __log_test_fail_general "One of more processes failed to execute" |
| 2023 | return 1 |
JohnKeeney | 2f3b268 | 2024-03-22 16:56:46 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2026 | # API Test function: GET /policy_ids and V2 GET /v2/policies |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2027 | # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID) |
| 2028 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2029 | a1pms_api_get_policy_ids() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2030 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2031 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2032 | if [ $# -lt 4 ]; then |
| 2033 | __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@ |
| 2034 | return 1 |
| 2035 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2036 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2037 | queryparams="" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2038 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2039 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2040 | if [ $2 != "NORIC" ]; then |
| 2041 | queryparams="?ric_id="$2 |
| 2042 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2043 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2044 | if [ $3 != "NOSERVICE" ]; then |
| 2045 | if [ -z $queryparams ]; then |
| 2046 | queryparams="?service_id="$3 |
| 2047 | else |
| 2048 | queryparams=$queryparams"&service_id="$3 |
| 2049 | fi |
| 2050 | fi |
| 2051 | if [ $4 != "NOTYPE" ]; then |
| 2052 | if [ -z $queryparams ]; then |
| 2053 | queryparams="?policytype_id="$4 |
| 2054 | else |
| 2055 | queryparams=$queryparams"&policytype_id="$4 |
| 2056 | fi |
| 2057 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2058 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2059 | query="/v2/policies"$queryparams |
| 2060 | else |
| 2061 | if [ $2 != "NORIC" ]; then |
| 2062 | queryparams="?ric="$2 |
| 2063 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2064 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2065 | if [ $3 != "NOSERVICE" ]; then |
| 2066 | if [ -z $queryparams ]; then |
| 2067 | queryparams="?service="$3 |
| 2068 | else |
| 2069 | queryparams=$queryparams"&service="$3 |
| 2070 | fi |
| 2071 | fi |
| 2072 | if [ $4 != "NOTYPE" ]; then |
| 2073 | if [ -z $queryparams ]; then |
| 2074 | queryparams="?type="$4 |
| 2075 | else |
| 2076 | queryparams=$queryparams"&type="$4 |
| 2077 | fi |
| 2078 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2079 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2080 | query="/policy_ids"$queryparams |
| 2081 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2082 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2083 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2084 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2085 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2086 | if [ $status -ne $1 ]; then |
| 2087 | __log_test_fail_status_code $1 $status |
| 2088 | return 1 |
| 2089 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2090 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2091 | if [ $# -gt 4 ]; then |
| 2092 | body=${res:0:${#res}-3} |
| 2093 | targetJson="[" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2094 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2095 | for pid in ${@:5}; do |
| 2096 | if [ "$targetJson" != "[" ]; then |
| 2097 | targetJson=$targetJson"," |
| 2098 | fi |
| 2099 | if [ $pid != "NOID" ]; then |
| 2100 | targetJson=$targetJson"\"$UUID$pid\"" |
| 2101 | fi |
| 2102 | done |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2103 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2104 | targetJson=$targetJson"]" |
| 2105 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2106 | targetJson="{\"policy_ids\": $targetJson}" |
| 2107 | fi |
| 2108 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 2109 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2110 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2111 | if [ $res -ne 0 ]; then |
| 2112 | __log_test_fail_body |
| 2113 | return 1 |
| 2114 | fi |
| 2115 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2116 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2117 | __collect_endpoint_stats "A1PMS" 04 "GET" $A1PMS_API_PREFIX"/v2/policies" $status |
| 2118 | __log_test_pass |
| 2119 | return 0 |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2120 | } |
| 2121 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2122 | # API Test function: V3 GET a1policymanagement/v1/policies |
| 2123 | # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID) |
| 2124 | # (Function for test scripts) |
| 2125 | a1pms_api_get_all_policies_v3() { |
| 2126 | __log_test_start $@ |
| 2127 | |
| 2128 | if [ $# -lt 4 ]; then |
| 2129 | __print_err "<response-code> <ric-id>|NORIC <service-id>|NOSERVICE <type-id>|NOTYPE ([<policy-instance-id]*|NOID)" $@ |
| 2130 | return 1 |
| 2131 | fi |
| 2132 | |
| 2133 | queryparams="" |
| 2134 | |
| 2135 | if [ $2 != "NORIC" ]; then |
| 2136 | queryparams="?nearRtRicId="$2 |
| 2137 | fi |
| 2138 | |
| 2139 | if [ $3 != "NOSERVICE" ]; then |
| 2140 | if [ -z $queryparams ]; then |
| 2141 | queryparams="?serviceId="$3 |
| 2142 | else |
| 2143 | queryparams=$queryparams"&serviceId="$3 |
| 2144 | fi |
| 2145 | fi |
| 2146 | if [ $4 != "NOTYPE" ]; then |
| 2147 | if [ -z $queryparams ]; then |
| 2148 | queryparams="?policyTypeId="$4 |
| 2149 | else |
| 2150 | queryparams=$queryparams"&policyTypeId="$4 |
| 2151 | fi |
| 2152 | fi |
| 2153 | |
| 2154 | query="/v1/policies"$queryparams |
| 2155 | |
| 2156 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2157 | status=${res:${#res}-3} |
| 2158 | |
| 2159 | if [ $status -ne $1 ]; then |
| 2160 | __log_test_fail_status_code $1 $status |
| 2161 | return 1 |
| 2162 | fi |
| 2163 | |
| 2164 | if [ $# -gt 4 ]; then |
| 2165 | body=${res:0:${#res}-3} |
| 2166 | targetJson="[" |
| 2167 | |
| 2168 | for pid in ${@:5}; do |
| 2169 | if [ "$targetJson" != "[" ]; then |
| 2170 | targetJson=$targetJson"," |
| 2171 | fi |
| 2172 | IFS=':' read -r policy_id ric_id <<<"$pid" |
| 2173 | if [ $policy_id != "NOID" ]; then |
| 2174 | targetJson=$targetJson"{ \"policyId\": \"${UUID}${policy_id}\", \"nearRtRicId\": \"$ric_id\" }" |
| 2175 | fi |
| 2176 | done |
| 2177 | |
| 2178 | targetJson=$targetJson"]" |
| 2179 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 2180 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2181 | |
| 2182 | if [ $res -ne 0 ]; then |
| 2183 | __log_test_fail_body |
| 2184 | return 1 |
| 2185 | fi |
| 2186 | fi |
| 2187 | |
| 2188 | __collect_endpoint_stats "A1PMS" 04 "GET" ${A1PMS_API_PREFIX}${query} ${status} |
| 2189 | __log_test_pass |
| 2190 | return 0 |
| 2191 | } |
| 2192 | |
| 2193 | # API Test function: V2 GET a1-policy/v2/policy-types/{policyTypeId} and V3 GET a1policymanagement/v1/policytypes/{policyTypeId} |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2194 | # args(V2): <response-code> <policy-type-id> [<schema-file>] |
| 2195 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2196 | a1pms_api_get_policy_type() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2197 | __log_test_start $@ |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2198 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2199 | if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2200 | __log_test_fail_not_supported |
| 2201 | return 1 |
| 2202 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2203 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2204 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 2205 | __print_err "<response-code> <policy-type-id> [<schema-file>]" $@ |
| 2206 | return 1 |
| 2207 | fi |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2208 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2209 | query="/v2/policy-types/$2" |
| 2210 | fi |
| 2211 | if [ "$A1PMS_VERSION" == "V3" ]; then |
| 2212 | query="/v1/policytypes/$2" |
| 2213 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2214 | |
| 2215 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2216 | status=${res:${#res}-3} |
| 2217 | |
| 2218 | if [ $status -ne $1 ]; then |
| 2219 | __log_test_fail_status_code $1 $status |
| 2220 | return 1 |
| 2221 | fi |
| 2222 | |
| 2223 | if [ $# -eq 3 ]; then |
| 2224 | |
| 2225 | body=${res:0:${#res}-3} |
| 2226 | |
| 2227 | targetJson=$(<$3) |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2228 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2229 | targetJson="{\"policy_schema\":$targetJson}" |
| 2230 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 2231 | targetJson="$targetJson" |
| 2232 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2233 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 2234 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2235 | |
| 2236 | if [ $res -ne 0 ]; then |
| 2237 | __log_test_fail_body |
| 2238 | return 1 |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2239 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2240 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2241 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2242 | __collect_endpoint_stats "A1PMS" 05 "GET" ${A1PMS_API_PREFIX}${query} ${status} |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2243 | __log_test_pass |
| 2244 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | # API Test function: GET /policy_schema |
| 2248 | # args: <response-code> <policy-type-id> [<schema-file>] |
| 2249 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2250 | a1pms_api_get_policy_schema() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2251 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2252 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2253 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2254 | __log_test_fail_not_supported |
| 2255 | return 1 |
| 2256 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2257 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2258 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 2259 | __print_err "<response-code> <policy-type-id> [<schema-file>]" $@ |
| 2260 | return 1 |
| 2261 | fi |
| 2262 | query="/policy_schema?id=$2" |
| 2263 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2264 | status=${res:${#res}-3} |
| 2265 | |
| 2266 | if [ $status -ne $1 ]; then |
| 2267 | __log_test_fail_status_code $1 $status |
| 2268 | return 1 |
| 2269 | fi |
| 2270 | |
| 2271 | if [ $# -eq 3 ]; then |
| 2272 | |
| 2273 | body=${res:0:${#res}-3} |
| 2274 | |
| 2275 | targetJson=$(<$3) |
| 2276 | |
| 2277 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 2278 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2279 | |
| 2280 | if [ $res -ne 0 ]; then |
| 2281 | __log_test_fail_body |
| 2282 | return 1 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2283 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2284 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2285 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2286 | __collect_endpoint_stats "A1PMS" 06 "GET" $A1PMS_API_PREFIX"/v2/policy_schema" $status |
| 2287 | __log_test_pass |
| 2288 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | # API Test function: GET /policy_schemas |
| 2292 | # args: <response-code> <ric-id>|NORIC [<schema-file>|NOFILE]* |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2293 | # args(V2): <response-code> |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2294 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2295 | a1pms_api_get_policy_schemas() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2296 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2297 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2298 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2299 | if [ $# -ne 1 ]; then |
| 2300 | __print_err "<response-code>" $@ |
| 2301 | return 1 |
| 2302 | fi |
| 2303 | else |
| 2304 | if [ $# -lt 2 ]; then |
| 2305 | __print_err "<response-code> <ric-id>|NORIC [<schema-file>|NOFILE]*" $@ |
| 2306 | return 1 |
| 2307 | fi |
| 2308 | fi |
| 2309 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2310 | query="/v2/policy-schemas" |
| 2311 | else |
| 2312 | query="/policy_schemas" |
| 2313 | if [ $2 != "NORIC" ]; then |
| 2314 | query=$query"?ric="$2 |
| 2315 | fi |
| 2316 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2317 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2318 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2319 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2320 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2321 | if [ $status -ne $1 ]; then |
| 2322 | __log_test_fail_status_code $1 $status |
| 2323 | return 1 |
| 2324 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2325 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2326 | if [ $# -gt 2 ]; then |
| 2327 | body=${res:0:${#res}-3} |
| 2328 | targetJson="[" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2329 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2330 | for file in ${@:3}; do |
| 2331 | if [ "$targetJson" != "[" ]; then |
| 2332 | targetJson=$targetJson"," |
| 2333 | fi |
| 2334 | if [ $file == "NOFILE" ]; then |
| 2335 | targetJson=$targetJson"{}" |
| 2336 | else |
| 2337 | targetJson=$targetJson$(<$file) |
| 2338 | fi |
| 2339 | done |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2340 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2341 | targetJson=$targetJson"]" |
| 2342 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2343 | targetJson="{\"policy_schemas\": $targetJson }" |
| 2344 | fi |
| 2345 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 2346 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2347 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2348 | if [ $res -ne 0 ]; then |
| 2349 | __log_test_fail_body |
| 2350 | return 1 |
| 2351 | fi |
| 2352 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2353 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2354 | __collect_endpoint_stats "A1PMS" 07 "GET" $A1PMS_API_PREFIX"/v2/policy-schemas" $status |
| 2355 | __log_test_pass |
| 2356 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2357 | } |
| 2358 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2359 | # API Test function: GET /policy_status and V2 GET /policies/{policy_id}/status |
BjornMagnussonXA | 8fbb226 | 2022-01-24 15:20:15 +0100 | [diff] [blame] | 2360 | # 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] | 2361 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2362 | a1pms_api_get_policy_status() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2363 | __log_test_start $@ |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2364 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2365 | if [ $# -lt 2 ] || [ $# -gt 5 ]; then |
| 2366 | __print_err "<response-code> <policy-id> [(STD <enforce-status>|EMPTY [<reason>|EMPTY])|(OSC <instance-status> <has-been-deleted>)]" $@ |
| 2367 | return 1 |
| 2368 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2369 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2370 | targetJson="" |
| 2371 | if [ $# -eq 2 ]; then |
| 2372 | : |
| 2373 | elif [ "$3" == "STD" ]; then |
| 2374 | targetJson="{\"enforceStatus\":\"$4\"" |
| 2375 | if [ $# -eq 5 ]; then |
| 2376 | targetJson=$targetJson",\"reason\":\"$5\"" |
| 2377 | fi |
| 2378 | targetJson=$targetJson"}" |
| 2379 | elif [ "$3" == "STD2" ]; then |
| 2380 | if [ $4 == "EMPTY" ]; then |
| 2381 | targetJson="{\"enforceStatus\":\"\"" |
| 2382 | else |
| 2383 | targetJson="{\"enforceStatus\":\"$4\"" |
| 2384 | fi |
| 2385 | if [ $# -eq 5 ]; then |
| 2386 | if [ $5 == "EMPTY" ]; then |
| 2387 | targetJson=$targetJson",\"enforceReason\":\"\"" |
| 2388 | else |
| 2389 | targetJson=$targetJson",\"enforceReason\":\"$5\"" |
| 2390 | fi |
| 2391 | fi |
| 2392 | targetJson=$targetJson"}" |
| 2393 | elif [ "$3" == "OSC" ]; then |
| 2394 | if [[ $TEST_ENV_PROFILE =~ ^ORAN-[A-H] ]] || [[ $TEST_ENV_PROFILE =~ ^ONAP-[A-L] ]]; then |
raviteja.karumuri | 2c6c06e | 2024-05-27 10:58:44 +0100 | [diff] [blame] | 2395 | targetJson="{\"instance_status\":\"$4\"" |
| 2396 | if [ $# -eq 5 ]; then |
| 2397 | targetJson=$targetJson",\"has_been_deleted\":\"$5\"" |
| 2398 | fi |
| 2399 | targetJson=$targetJson",\"created_at\":\"????\"}" |
| 2400 | else |
| 2401 | targetJson="{\"enforceStatus\":\"$4\"" |
| 2402 | if [ $# -eq 5 ]; then |
| 2403 | targetJson=$targetJson",\"enforceReason\":\"$5\"}" |
| 2404 | fi |
| 2405 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2406 | else |
| 2407 | __print_err "<response-code> (STD <enforce-status> [<reason>])|(OSC <instance-status> <has-been-deleted>)" $@ |
| 2408 | return 1 |
| 2409 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2410 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2411 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2412 | query="/v2/policies/$UUID$2/status" |
| 2413 | targetJson="{\"last_modified\":\"????\",\"status\":$targetJson}" |
| 2414 | else |
| 2415 | query="/policy_status?id="$UUID$2 |
| 2416 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2417 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2418 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2419 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2420 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2421 | if [ $status -ne $1 ]; then |
| 2422 | __log_test_fail_status_code $1 $status |
| 2423 | return 1 |
| 2424 | fi |
| 2425 | if [ $# -gt 2 ]; then |
| 2426 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 2427 | body=${res:0:${#res}-3} |
| 2428 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2429 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2430 | if [ $res -ne 0 ]; then |
| 2431 | __log_test_fail_body |
| 2432 | return 1 |
| 2433 | fi |
| 2434 | fi |
| 2435 | __collect_endpoint_stats "A1PMS" 08 "GET" $A1PMS_API_PREFIX"/v2/policies/{policy_id}/status" $status |
| 2436 | __log_test_pass |
| 2437 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2438 | } |
| 2439 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2440 | # API Test function: GET /policy_types and V2 GET /v2/policy-types |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2441 | # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]] |
| 2442 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2443 | a1pms_api_get_policy_types() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2444 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2445 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2446 | if [ $# -lt 1 ]; then |
| 2447 | __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@ |
| 2448 | return 1 |
| 2449 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2450 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2451 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2452 | if [ $# -eq 1 ]; then |
| 2453 | query="/v2/policy-types" |
| 2454 | elif [ $2 == "NORIC" ]; then |
| 2455 | query="/v2/policy-types" |
| 2456 | else |
| 2457 | query="/v2/policy-types?ric_id=$2" |
| 2458 | fi |
| 2459 | else |
| 2460 | if [ $# -eq 1 ]; then |
| 2461 | query="/policy_types" |
| 2462 | elif [ $2 == "NORIC" ]; then |
| 2463 | query="/policy_types" |
| 2464 | else |
| 2465 | query="/policy_types?ric=$2" |
| 2466 | fi |
| 2467 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2468 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2469 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2470 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2471 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2472 | if [ $status -ne $1 ]; then |
| 2473 | __log_test_fail_status_code $1 $status |
| 2474 | return 1 |
| 2475 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2476 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2477 | if [ $# -gt 2 ]; then |
| 2478 | body=${res:0:${#res}-3} |
| 2479 | targetJson="[" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2480 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2481 | for pid in ${@:3}; do |
| 2482 | if [ "$targetJson" != "[" ]; then |
| 2483 | targetJson=$targetJson"," |
| 2484 | fi |
| 2485 | if [ $pid == "EMPTY" ]; then |
| 2486 | pid="" |
| 2487 | fi |
| 2488 | targetJson=$targetJson"\"$pid\"" |
| 2489 | done |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2490 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2491 | targetJson=$targetJson"]" |
| 2492 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2493 | targetJson="{\"policytype_ids\": $targetJson }" |
| 2494 | fi |
| 2495 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 2496 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2497 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2498 | if [ $res -ne 0 ]; then |
| 2499 | __log_test_fail_body |
| 2500 | return 1 |
| 2501 | fi |
| 2502 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2503 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2504 | __collect_endpoint_stats "A1PMS" 09 "GET" $A1PMS_API_PREFIX"/v2/policy-types" $status |
| 2505 | __log_test_pass |
| 2506 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2507 | } |
| 2508 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2509 | # API Test function: V3 GET a1policymanagement/v1/policytypes |
| 2510 | # args: <response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]] |
| 2511 | # (Function for test scripts) |
| 2512 | a1pms_api_get_policy_types_v3() { |
| 2513 | __log_test_start $@ |
| 2514 | |
| 2515 | if [ $# -lt 1 ]; then |
| 2516 | __print_err "<response-code> [<ric-id>|NORIC [<policy-type-id>|EMPTY [<policy-type-id>]*]]" $@ |
| 2517 | return 1 |
| 2518 | fi |
| 2519 | |
| 2520 | if [ $# -eq 1 ]; then |
| 2521 | query="/v1/policytypes" |
| 2522 | elif [ $2 == "NORIC" ]; then |
| 2523 | query="/v1/policytypes" |
| 2524 | else |
| 2525 | query="/v1/policytypes?nearRtRicId=$2" |
| 2526 | fi |
| 2527 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2528 | status=${res:${#res}-3} |
| 2529 | |
| 2530 | if [ $status -ne $1 ]; then |
| 2531 | __log_test_fail_status_code $1 $status |
| 2532 | return 1 |
| 2533 | fi |
| 2534 | |
| 2535 | if [ $# -gt 2 ]; then |
| 2536 | body=${res:0:${#res}-3} |
| 2537 | targetJson="[" |
| 2538 | |
| 2539 | for pid in ${@:3}; do |
| 2540 | if [ "$targetJson" != "[" ]; then |
| 2541 | targetJson=$targetJson"," |
| 2542 | fi |
| 2543 | IFS=':' read -r policy_type_id ric_id <<<"$pid" |
| 2544 | # if [ -n "$policy_type_id" ] && [ -n "$ric_id" ]; then |
| 2545 | if [ $policy_type_id == "EMPTY" ]; then |
| 2546 | policy_type_id="" |
| 2547 | fi |
| 2548 | targetJson=$targetJson"{ \"policyTypeId\": \"$policy_type_id\", \"nearRtRicId\": \"$ric_id\" }" |
| 2549 | # fi |
| 2550 | done |
| 2551 | |
| 2552 | targetJson=$targetJson"]" |
| 2553 | |
| 2554 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 2555 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2556 | |
| 2557 | if [ $res -ne 0 ]; then |
| 2558 | __log_test_fail_body |
| 2559 | return 1 |
| 2560 | fi |
| 2561 | fi |
| 2562 | |
| 2563 | __collect_endpoint_stats "A1PMS" 09 "GET" ${A1PMS_API_PREFIX}${query} ${status} |
| 2564 | __log_test_pass |
| 2565 | return 0 |
| 2566 | } |
| 2567 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2568 | ######################################################### |
| 2569 | #### Test case functions Health check |
| 2570 | ######################################################### |
| 2571 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2572 | # API Test function: GET /status and V2 GET /status or (v1/status for a1pmsV3) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2573 | # args: <response-code> |
| 2574 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2575 | a1pms_api_get_status() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2576 | __log_test_start $@ |
| 2577 | if [ $# -ne 1 ]; then |
| 2578 | __print_err "<response-code>" $@ |
| 2579 | return 1 |
| 2580 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2581 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2582 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2583 | query="/v2/status" |
| 2584 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 2585 | query="/v1/status" |
| 2586 | else |
| 2587 | query="/status" |
| 2588 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2589 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2590 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2591 | status=${res:${#res}-3} |
| 2592 | |
| 2593 | if [ $status -ne $1 ]; then |
| 2594 | __log_test_fail_status_code $1 $status |
| 2595 | return 1 |
| 2596 | fi |
| 2597 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2598 | __collect_endpoint_stats "A1PMS" 10 "GET" $A1PMS_API_PREFIX$query $status |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2599 | __log_test_pass |
| 2600 | return 0 |
BjornMagnussonXA | 8fbb226 | 2022-01-24 15:20:15 +0100 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | # API Test function: GET /status (root) without api prefix |
| 2604 | # args: <response-code> |
| 2605 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2606 | a1pms_api_get_status_root() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2607 | __log_test_start $@ |
| 2608 | if [ $# -ne 1 ]; then |
| 2609 | __print_err "<response-code>" $@ |
| 2610 | return 1 |
| 2611 | fi |
| 2612 | query="/status" |
| 2613 | TMP_PREFIX=$A1PMS_API_PREFIX |
| 2614 | A1PMS_API_PREFIX="" |
| 2615 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2616 | A1PMS_API_PREFIX=$TMP_PREFIX |
| 2617 | status=${res:${#res}-3} |
BjornMagnussonXA | 8fbb226 | 2022-01-24 15:20:15 +0100 | [diff] [blame] | 2618 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2619 | if [ $status -ne $1 ]; then |
| 2620 | __log_test_fail_status_code $1 $status |
| 2621 | return 1 |
| 2622 | fi |
BjornMagnussonXA | 8fbb226 | 2022-01-24 15:20:15 +0100 | [diff] [blame] | 2623 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2624 | __collect_endpoint_stats "A1PMS" 19 "GET" "/status" $status |
| 2625 | __log_test_pass |
| 2626 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | ######################################################### |
| 2630 | #### Test case functions RIC Repository |
| 2631 | ######################################################### |
| 2632 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2633 | # API Test function: GET /ric, V2 GET /v2/rics/ric, and V3 GET a1policymanagement/v1/rics/ric |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2634 | # args: <reponse-code> <management-element-id> [<ric-id>] |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2635 | # (V2) args: <reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [<string-of-ricinfo>] |
| 2636 | # (V2) example of <string-of-ricinfo> = "ricsim_g1_1:me1_ricsim_g1_1,me2_ricsim_g1_1:1,2,4" |
| 2637 | # (V2) format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids> |
| 2638 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2639 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2640 | a1pms_api_get_ric() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2641 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2642 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2643 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2644 | if [ $# -lt 3 ]; then |
| 2645 | __print_err "<reponse-code> <management-element-id>|NOME <ric-id>|<NORIC> [string-of-ricinfo>]" $@ |
| 2646 | return 1 |
| 2647 | fi |
| 2648 | search="" |
| 2649 | if [ $2 != "NOME" ]; then |
| 2650 | search="?managed_element_id="$2 |
| 2651 | fi |
| 2652 | if [ $3 != "NORIC" ]; then |
| 2653 | if [ -z $search ]; then |
| 2654 | search="?ric_id="$3 |
| 2655 | else |
| 2656 | search=$search"&ric_id="$3 |
| 2657 | fi |
| 2658 | fi |
| 2659 | query="/v2/rics/ric"$search |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2660 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2661 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2662 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2663 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2664 | if [ $status -ne $1 ]; then |
| 2665 | __log_test_fail_status_code $1 $status |
| 2666 | return 1 |
| 2667 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2668 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2669 | if [ $# -gt 3 ]; then |
| 2670 | body=${res:0:${#res}-3} |
| 2671 | res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "V2" "$4") |
| 2672 | if [ $res -ne 0 ]; then |
| 2673 | __log_test_fail_general "Could not create target ric info json" |
| 2674 | return 1 |
| 2675 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2676 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2677 | targetJson=$(<./tmp/.tmp_rics.json) |
| 2678 | targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets |
| 2679 | echo " TARGET JSON: $targetJson" >>$HTTPLOG |
| 2680 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2681 | if [ $res -ne 0 ]; then |
| 2682 | __log_test_fail_body |
| 2683 | return 1 |
| 2684 | fi |
| 2685 | fi |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2686 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 2687 | if [ $# -lt 3 ]; then |
| 2688 | __print_err "<reponseCode> <managementElementId>|NOME <ricId>|<NORIC> [stringOfRicInfo>]" $@ |
| 2689 | return 1 |
| 2690 | fi |
| 2691 | search="" |
| 2692 | if [ $2 != "NOME" ]; then |
| 2693 | search="?managedElementId="$2 |
| 2694 | fi |
| 2695 | if [ $3 != "NORIC" ]; then |
| 2696 | if [ -z $search ]; then |
| 2697 | search="?ricId="$3 |
| 2698 | else |
| 2699 | search=$search"&ricId="$3 |
| 2700 | fi |
| 2701 | fi |
| 2702 | query="/v1/rics/ric"$search |
| 2703 | |
| 2704 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2705 | status=${res:${#res}-3} |
| 2706 | |
| 2707 | if [ $status -ne $1 ]; then |
| 2708 | __log_test_fail_status_code $1 $status |
| 2709 | return 1 |
| 2710 | fi |
| 2711 | |
| 2712 | if [ $# -gt 3 ]; then |
| 2713 | body=${res:0:${#res}-3} |
| 2714 | res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "${A1PMS_VERSION}" "$4") |
| 2715 | if [ $res -ne 0 ]; then |
| 2716 | __log_test_fail_general "Could not create target ric info json" |
| 2717 | return 1 |
| 2718 | fi |
| 2719 | |
| 2720 | targetJson=$(<./tmp/.tmp_rics.json) |
| 2721 | targetJson=${targetJson:1:${#targetJson}-2} #remove array brackets |
| 2722 | echo " TARGET JSON: $targetJson" >>$HTTPLOG |
| 2723 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2724 | if [ $res -ne 0 ]; then |
| 2725 | __log_test_fail_body |
| 2726 | return 1 |
| 2727 | fi |
| 2728 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2729 | else |
| 2730 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2731 | __print_err "<reponseCode> <managedElementIds> [<ricId>]" $@ |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2732 | return 1 |
| 2733 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2734 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2735 | query="/ric?managedElementId="$2 |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2736 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2737 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2738 | status=${res:${#res}-3} |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2739 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2740 | if [ $status -ne $1 ]; then |
| 2741 | __log_test_fail_status_code $1 $status |
| 2742 | return 1 |
| 2743 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2744 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2745 | if [ $# -eq 3 ]; then |
| 2746 | body=${res:0:${#res}-3} |
| 2747 | if [ "$body" != "$3" ]; then |
| 2748 | __log_test_fail_body |
| 2749 | return 1 |
| 2750 | fi |
| 2751 | fi |
| 2752 | fi |
BjornMagnussonXA | 8fbb226 | 2022-01-24 15:20:15 +0100 | [diff] [blame] | 2753 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2754 | __collect_endpoint_stats "A1PMS" 11 "GET" ${A1PMS_API_PREFIX}${query} ${status} |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2755 | __log_test_pass |
| 2756 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2757 | } |
| 2758 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2759 | # API test function: GET /rics, V2 GET /v2/rics, and V3 GET /a1policymanagement/v1/rics |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2760 | # args: <reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>] |
| 2761 | # 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_........." |
| 2762 | # format of ric-info: <ric-id>:<list-of-mes>:<list-of-policy-type-ids> |
| 2763 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2764 | a1pms_api_get_rics() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2765 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2766 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2767 | if [ $# -lt 2 ]; then |
| 2768 | __print_err "<reponse-code> <policy-type-id>|NOTYPE [<space-separate-string-of-ricinfo>]" $@ |
| 2769 | return 1 |
| 2770 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2771 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2772 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2773 | query="/v2/rics" |
| 2774 | if [ $2 != "NOTYPE" ]; then |
| 2775 | query="/v2/rics?policytype_id="$2 |
| 2776 | fi |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2777 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 2778 | query="/v1/rics" |
| 2779 | if [ $2 != "NOTYPE" ]; then |
| 2780 | query=${query}"?policyTypeId="$2 |
| 2781 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2782 | else |
| 2783 | query="/rics" |
| 2784 | if [ $2 != "NOTYPE" ]; then |
| 2785 | query="/rics?policyType="$2 |
| 2786 | fi |
| 2787 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2788 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2789 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2790 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2791 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2792 | if [ $status -ne $1 ]; then |
| 2793 | __log_test_fail_status_code $1 $status |
| 2794 | return 1 |
| 2795 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2796 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2797 | if [ $# -gt 2 ]; then |
| 2798 | body=${res:0:${#res}-3} |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2799 | res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "${A1PMS_VERSION}" "$3") |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2800 | if [ $res -ne 0 ]; then |
| 2801 | __log_test_fail_general "Could not create target ric info json" |
| 2802 | return 1 |
| 2803 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2804 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2805 | targetJson=$(<./tmp/.tmp_rics.json) |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2806 | if [ "$A1PMS_VERSION" == "V2" ] || [ "$A1PMS_VERSION" == "V3" ]; then |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2807 | targetJson="{\"rics\": $targetJson }" |
| 2808 | fi |
| 2809 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 2810 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2811 | if [ $res -ne 0 ]; then |
| 2812 | __log_test_fail_body |
| 2813 | return 1 |
| 2814 | fi |
| 2815 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2816 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2817 | __collect_endpoint_stats "A1PMS" 12 "GET" ${A1PMS_API_PREFIX}${query} ${status} |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2818 | __log_test_pass |
| 2819 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | ################################################################## |
| 2823 | #### API Test case functions Service registry and supervision #### |
| 2824 | ################################################################## |
| 2825 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2826 | # API test function: PUT /service and V2 PUT /service |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2827 | # args: <response-code> <service-name> <keepalive-timeout> <callbackurl> |
| 2828 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2829 | a1pms_api_put_service() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2830 | __log_test_start $@ |
| 2831 | if [ $# -ne 4 ]; then |
| 2832 | __print_err "<response-code> <service-name> <keepalive-timeout> <callbackurl>" $@ |
| 2833 | return 1 |
| 2834 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2835 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2836 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2837 | query="/v2/services" |
| 2838 | json="{\"callback_url\": \""$4"\",\"keep_alive_interval_seconds\": \""$3"\",\"service_id\": \""$2"\"}" |
| 2839 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 2840 | query="/v1/services" |
| 2841 | json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceId\": \""$2"\"}" |
| 2842 | else |
| 2843 | query="/service" |
| 2844 | json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}" |
| 2845 | fi |
| 2846 | file="./tmp/.tmp.json" |
| 2847 | echo "$json" >$file |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2848 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2849 | res="$(__do_curl_to_api A1PMS PUT $query $file)" |
| 2850 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2851 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2852 | if [ $status -ne $1 ]; then |
| 2853 | __log_test_fail_status_code $1 $status |
| 2854 | return 1 |
| 2855 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2856 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2857 | __collect_endpoint_stats "A1PMS" 13 "PUT" $A1PMS_API_PREFIX$query $status |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2858 | __log_test_pass |
| 2859 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2860 | } |
| 2861 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2862 | # API test function: GET /services, V2 GET /v2/services and V3 /a1policymanagement/v1/services |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2863 | #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>]* )] |
| 2864 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2865 | a1pms_api_get_services() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2866 | __log_test_start $@ |
| 2867 | #Number of accepted parameters: 1, 2, 4, 7, 10, 13,... |
| 2868 | paramError=1 |
| 2869 | if [ $# -eq 1 ]; then |
| 2870 | paramError=0 |
| 2871 | elif [ $# -eq 2 ] && [ $2 != "NOSERVICE" ]; then |
| 2872 | paramError=0 |
| 2873 | elif [ $# -eq 5 ]; then |
| 2874 | paramError=0 |
| 2875 | elif [ $# -gt 5 ] && [ $2 == "NOSERVICE" ]; then |
| 2876 | argLen=$(($# - 2)) |
| 2877 | if [ $(($argLen % 3)) -eq 0 ]; then |
| 2878 | paramError=0 |
| 2879 | fi |
| 2880 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2881 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2882 | if [ $paramError -ne 0 ]; then |
| 2883 | __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>]* )]" $@ |
| 2884 | return 1 |
| 2885 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2886 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2887 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2888 | query="/v2/services" |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2889 | if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then |
| 2890 | query="/v2/services?service_id="$2 |
| 2891 | fi |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2892 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 2893 | query="/v1/services" |
| 2894 | if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then |
| 2895 | query="/v1/services?serviceId="$2 |
| 2896 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2897 | else |
| 2898 | query="/services" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 2899 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2900 | if [ $# -gt 1 ] && [ $2 != "NOSERVICE" ]; then |
| 2901 | query="/services?name="$2 |
| 2902 | fi |
| 2903 | fi |
| 2904 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2905 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2906 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2907 | if [ $status -ne $1 ]; then |
| 2908 | __log_test_fail_status_code $1 $status |
| 2909 | return 1 |
| 2910 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2911 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2912 | if [ $# -gt 2 ]; then |
| 2913 | variableArgCount=$(($# - 2)) |
| 2914 | body=${res:0:${#res}-3} |
| 2915 | targetJson="[" |
| 2916 | shift |
| 2917 | shift |
| 2918 | cntr=0 |
| 2919 | while [ $cntr -lt $variableArgCount ]; do |
| 2920 | servicename=$1 |
| 2921 | shift |
| 2922 | timeout=$1 |
| 2923 | shift |
| 2924 | callback=$1 |
| 2925 | shift |
| 2926 | if [ $cntr -gt 0 ]; then |
| 2927 | targetJson=$targetJson"," |
| 2928 | fi |
| 2929 | # timeSinceLastActivitySeconds value cannot be checked since value varies |
| 2930 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2931 | targetJson=$targetJson"{\"service_id\": \""$servicename"\",\"keep_alive_interval_seconds\": "$timeout",\"time_since_last_activity_seconds\":\"????\",\"callback_url\": \""$callback"\"}" |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2932 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 2933 | targetJson=$targetJson"{\"serviceId\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}" |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2934 | else |
| 2935 | targetJson=$targetJson"{\"serviceName\": \""$servicename"\",\"keepAliveIntervalSeconds\": "$timeout",\"timeSinceLastActivitySeconds\":\"????\",\"callbackUrl\": \""$callback"\"}" |
| 2936 | fi |
| 2937 | let cntr=cntr+3 |
| 2938 | done |
| 2939 | targetJson=$targetJson"]" |
| 2940 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2941 | targetJson="{\"service_list\": $targetJson }" |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2942 | URL_for_Collect_End_Point="/v2/services" |
| 2943 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 2944 | targetJson="{\"serviceList\": $targetJson }" |
| 2945 | URL_for_Collect_End_Point="/v1/services" |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2946 | fi |
| 2947 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 2948 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 2949 | if [ $res -ne 0 ]; then |
| 2950 | __log_test_fail_body |
| 2951 | return 1 |
| 2952 | fi |
| 2953 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2954 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2955 | __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX$URL_for_Collect_End_Point $status |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2956 | __log_test_pass |
| 2957 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2958 | } |
| 2959 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2960 | # API test function: GET /services, V2 GET /v2/services and V3 /a1policymanagement/v1/services - (only checking service names) |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2961 | # args: <response-code> [<service-name>]*" |
| 2962 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 2963 | a1pms_api_get_service_ids() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2964 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2965 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2966 | if [ $# -lt 1 ]; then |
| 2967 | __print_err "<response-code> [<service-name>]*" $@ |
| 2968 | return 1 |
| 2969 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2970 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2971 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2972 | query="/v2/services" |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2973 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 2974 | query="/v1/services" |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2975 | else |
| 2976 | query="/services" |
| 2977 | fi |
| 2978 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 2979 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2980 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2981 | if [ $status -ne $1 ]; then |
| 2982 | __log_test_fail_status_code $1 $status |
| 2983 | return 1 |
| 2984 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 2985 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2986 | body=${res:0:${#res}-3} |
| 2987 | targetJson="[" |
| 2988 | for rapp in ${@:2}; do |
| 2989 | if [ "$targetJson" != "[" ]; then |
| 2990 | targetJson=$targetJson"," |
| 2991 | fi |
| 2992 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 2993 | targetJson=$targetJson"{\"callback_url\":\"????\",\"keep_alive_interval_seconds\":\"????\",\"service_id\":\""$rapp"\",\"time_since_last_activity_seconds\":\"????\"}" |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 2994 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 2995 | targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceId\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}" |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 2996 | else |
| 2997 | targetJson=$targetJson"{\"callbackUrl\":\"????\",\"keepAliveIntervalSeconds\":\"????\",\"serviceName\":\""$rapp"\",\"timeSinceLastActivitySeconds\":\"????\"}" |
| 2998 | fi |
| 2999 | done |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3000 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3001 | targetJson=$targetJson"]" |
| 3002 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 3003 | targetJson="{\"service_list\": $targetJson }" |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 3004 | URL_for_Collect_End_Point="/v2/services" |
| 3005 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 3006 | targetJson="{\"serviceList\": $targetJson }" |
| 3007 | URL_for_Collect_End_Point="/v1/services" |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3008 | fi |
| 3009 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 3010 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3011 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3012 | if [ $res -ne 0 ]; then |
| 3013 | __log_test_fail_body |
| 3014 | return 1 |
| 3015 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3016 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 3017 | __collect_endpoint_stats "A1PMS" 14 "GET" $A1PMS_API_PREFIX$URL_for_Collect_End_Point $status |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3018 | __log_test_pass |
| 3019 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3020 | } |
| 3021 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 3022 | # API test function: DELETE /services and V2 DELETE /v2/services/{serviceId} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3023 | # args: <response-code> <service-name> |
| 3024 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 3025 | a1pms_api_delete_services() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3026 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3027 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3028 | if [ $# -ne 2 ]; then |
| 3029 | __print_err "<response-code> <service-name>" $@ |
| 3030 | return 1 |
| 3031 | fi |
| 3032 | if [ "$A1PMS_VERSION" == "V2" ]; then |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 3033 | url_part="/v2/services/" |
| 3034 | query=${url_part}${2} |
| 3035 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 3036 | url_part="/v1/services/" |
| 3037 | query=${url_part}${2} |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3038 | else |
| 3039 | query="/services?name="$2 |
| 3040 | fi |
| 3041 | res="$(__do_curl_to_api A1PMS DELETE $query)" |
| 3042 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3043 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3044 | if [ $status -ne $1 ]; then |
| 3045 | __log_test_fail_status_code $1 $status |
| 3046 | return 1 |
| 3047 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3048 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 3049 | __collect_endpoint_stats "A1PMS" 15 "DELETE" ${A1PMS_API_PREFIX}${url_part}"{serviceId}" $status |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3050 | __log_test_pass |
| 3051 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3052 | } |
| 3053 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 3054 | # 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] | 3055 | # args: <response-code> <service-name> |
| 3056 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 3057 | a1pms_api_put_services_keepalive() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3058 | __log_test_start $@ |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3059 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3060 | if [ $# -ne 2 ]; then |
| 3061 | __print_err "<response-code> <service-name>" $@ |
| 3062 | return 1 |
| 3063 | fi |
| 3064 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 3065 | query="/v2/services/$2/keepalive" |
| 3066 | else |
| 3067 | query="/services/keepalive?name="$2 |
| 3068 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3069 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3070 | res="$(__do_curl_to_api A1PMS PUT $query)" |
| 3071 | status=${res:${#res}-3} |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3072 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3073 | if [ $status -ne $1 ]; then |
| 3074 | __log_test_fail_status_code $1 $status |
| 3075 | return 1 |
| 3076 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3077 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3078 | __collect_endpoint_stats "A1PMS" 16 "PUT" $A1PMS_API_PREFIX"/v2/services/{service_id}/keepalive" $status |
| 3079 | __log_test_pass |
| 3080 | return 0 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 3081 | } |
| 3082 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 3083 | ################################################################## |
| 3084 | #### API Test case functions Configuration #### |
| 3085 | ################################################################## |
| 3086 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3087 | # API Test function: PUT "/v2/configuration" or "/v1/configuration" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 3088 | # args: <response-code> <config-file> |
| 3089 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 3090 | a1pms_api_put_configuration() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3091 | __log_test_start $@ |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 3092 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3093 | if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then |
| 3094 | __log_test_fail_not_supported |
| 3095 | return 1 |
| 3096 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 3097 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3098 | if [ $# -ne 2 ]; then |
| 3099 | __print_err "<response-code> <config-file>" $@ |
| 3100 | return 1 |
| 3101 | fi |
| 3102 | if [ ! -f $2 ]; then |
| 3103 | __log_test_fail_general "Config file "$2", does not exist" |
| 3104 | return 1 |
| 3105 | fi |
| 3106 | inputJson=$(<$2) |
| 3107 | # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header |
| 3108 | # inputJson="{\"config\":"$inputJson"}" |
| 3109 | # fi |
| 3110 | file="./tmp/.config.json" |
| 3111 | echo $inputJson >$file |
| 3112 | if [ "$A1PMS_VERSION" == "V2" ]; then |
| 3113 | query="/v2/configuration" |
| 3114 | elif [ "$A1PMS_VERSION" == "V3" ]; then |
| 3115 | #V3 has baseurl changes 'a1-policy/v2' to 'a1policymanagement/v1' |
| 3116 | query="/v1/configuration" |
| 3117 | fi |
| 3118 | res="$(__do_curl_to_api A1PMS PUT $query $file)" |
| 3119 | status=${res:${#res}-3} |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 3120 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3121 | if [ $status -ne $1 ]; then |
| 3122 | __log_test_fail_status_code $1 $status |
| 3123 | return 1 |
| 3124 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 3125 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 3126 | __collect_endpoint_stats "A1PMS" 17 "PUT" $A1PMS_API_PREFIX$query $status |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3127 | __log_test_pass |
| 3128 | return 0 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | # API Test function: GET /v2/configuration |
| 3132 | # args: <response-code> [<config-file>] |
| 3133 | # (Function for test scripts) |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 3134 | a1pms_api_get_configuration() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3135 | __log_test_start $@ |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 3136 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 3137 | if [ "$A1PMS_VERSION" != "V2" ] && [ "$A1PMS_VERSION" != "V3" ]; then |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3138 | __log_test_fail_not_supported |
| 3139 | return 1 |
| 3140 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 3141 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3142 | if [ $# -lt 1 ] || [ $# -gt 2 ]; then |
| 3143 | __print_err "<response-code> [<config-file>]" $@ |
| 3144 | return 1 |
| 3145 | fi |
| 3146 | if [ ! -f $2 ]; then |
| 3147 | __log_test_fail_general "Config file "$2" for comparison, does not exist" |
| 3148 | return 1 |
| 3149 | fi |
| 3150 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 3151 | if [ "$A1PMS_VERSION" == "V3" ]; then |
| 3152 | #The V3 of a1-pms URL is a1policymanagement/v1 and the v2 is a1-policy/v2 |
| 3153 | query="/v1/configuration" |
| 3154 | else |
| 3155 | query="/v2/configuration" |
| 3156 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3157 | res="$(__do_curl_to_api A1PMS GET $query)" |
| 3158 | status=${res:${#res}-3} |
| 3159 | |
| 3160 | if [ $status -ne $1 ]; then |
| 3161 | __log_test_fail_status_code $1 $status |
| 3162 | return 1 |
| 3163 | fi |
| 3164 | |
| 3165 | if [ $# -eq 2 ]; then |
| 3166 | |
| 3167 | body=${res:0:${#res}-3} |
| 3168 | |
| 3169 | targetJson=$(<$2) |
| 3170 | # if [ $RUNMODE == "DOCKER" ]; then #In kube the file already has a header |
| 3171 | # inputJson="{\"config\":"$inputJson"}" |
| 3172 | # fi |
| 3173 | echo "TARGET JSON: $targetJson" >>$HTTPLOG |
| 3174 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 3175 | |
| 3176 | if [ $res -ne 0 ]; then |
| 3177 | __log_test_fail_body |
| 3178 | return 1 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 3179 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3180 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 3181 | |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame^] | 3182 | if [ "$A1PMS_VERSION" == "V3" ]; then |
| 3183 | __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v1/configuration" $status |
| 3184 | else |
| 3185 | __collect_endpoint_stats "A1PMS" 18 "GET" $A1PMS_API_PREFIX"/v2/configuration" $status |
| 3186 | fi |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3187 | __log_test_pass |
| 3188 | return 0 |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | ########################################## |
| 3192 | #### Reset types and instances #### |
| 3193 | ########################################## |
| 3194 | |
| 3195 | # Admin reset to remove all policies and services |
| 3196 | # All types and instances etc are removed - types and instances in a1 sims need to be removed separately |
| 3197 | # NOTE - only works in kubernetes and the pod should not be running |
| 3198 | # args: - |
| 3199 | # (Function for test scripts) |
| 3200 | |
BjornMagnussonXA | d2aeca8 | 2022-03-07 11:04:55 +0100 | [diff] [blame] | 3201 | a1pms_kube_pvc_reset() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3202 | __log_test_start $@ |
BjornMagnussonXA | a549157 | 2021-05-04 09:21:24 +0200 | [diff] [blame] | 3203 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3204 | pvc_name=$(kubectl $KUBECONF get pvc -n $KUBE_NONRTRIC_NAMESPACE --no-headers -o custom-columns=":metadata.name" | grep policy) |
| 3205 | if [ -z "$pvc_name" ]; then |
| 3206 | pvc_name=policymanagementservice-vardata-pvc |
| 3207 | fi |
| 3208 | echo " Trying to reset pvc: "$pvc_name |
| 3209 | __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] | 3210 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3211 | __log_test_pass |
| 3212 | return 0 |
BjornMagnussonXA | cd93844 | 2022-05-11 10:01:24 +0200 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | # args: <realm> <client-name> <client-secret> |
| 3216 | a1pms_configure_sec() { |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3217 | export A1PMS_CREDS_GRANT_TYPE="client_credentials" |
| 3218 | export A1PMS_CREDS_CLIENT_SECRET=$3 |
| 3219 | export A1PMS_CREDS_CLIENT_ID=$2 |
| 3220 | export A1PMS_AUTH_SERVICE_URL=$KEYCLOAK_SERVICE_PATH$KEYCLOAK_TOKEN_URL_PREFIX/$1/protocol/openid-connect/token |
| 3221 | export A1PMS_SIDECAR_MOUNT="/token-cache" |
| 3222 | export A1PMS_SIDECAR_JWT_FILE=$A1PMS_SIDECAR_MOUNT"/jwt.txt" |
BjornMagnussonXA | cd93844 | 2022-05-11 10:01:24 +0200 | [diff] [blame] | 3223 | |
raviteja.karumuri | f6dce27 | 2024-05-03 16:50:07 +0100 | [diff] [blame] | 3224 | export AUTHSIDECAR_APP_NAME |
| 3225 | export AUTHSIDECAR_DISPLAY_NAME |
| 3226 | } |