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