BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # ============LICENSE_START=============================================== |
| 4 | # Copyright (C) 2020 Nordix Foundation. All rights reserved. |
| 5 | # ======================================================================== |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # ============LICENSE_END================================================= |
| 18 | # |
| 19 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 20 | # This is a script that contains container/service management functions and test functions for Producer stub |
| 21 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 22 | |
| 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 |
| 28 | __PRODSTUB_imagesetup() { |
| 29 | __check_and_create_image_var PRODSTUB "PROD_STUB_IMAGE" "PROD_STUB_IMAGE_BASE" "PROD_STUB_IMAGE_TAG" LOCAL "$PROD_STUB_DISPLAY_NAME" |
| 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' |
| 37 | __PRODSTUB_imagepull() { |
BjornMagnussonXA | a69cd90 | 2021-04-22 23:46:10 +0200 | [diff] [blame] | 38 | echo -e $RED"Image for app PRODSTUB shall never be pulled from remote repo"$ERED |
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 |
| 44 | __PRODSTUB_imagebuild() { |
| 45 | cd ../prodstub |
| 46 | echo " Building PRODSTUB - $PROD_STUB_DISPLAY_NAME - image: $PROD_STUB_IMAGE" |
| 47 | docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $PROD_STUB_IMAGE . &> .dockererr |
| 48 | if [ $? -eq 0 ]; then |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 49 | echo -e $GREEN" Build Ok"$EGREEN |
| 50 | __retag_and_push_image PROD_STUB_IMAGE |
| 51 | if [ $? -ne 0 ]; then |
| 52 | exit 1 |
| 53 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 54 | else |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 55 | echo -e $RED" Build Failed"$ERED |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 56 | ((RES_CONF_FAIL++)) |
| 57 | cat .dockererr |
| 58 | echo -e $RED"Exiting...."$ERED |
| 59 | exit 1 |
| 60 | fi |
| 61 | } |
| 62 | |
| 63 | # 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] | 64 | # 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] | 65 | # arg: <docker-images-format-string> <file-to-append> |
| 66 | __PRODSTUB_image_data() { |
| 67 | echo -e "$PROD_STUB_DISPLAY_NAME\t$(docker images --format $1 $PROD_STUB_IMAGE)" >> $2 |
BjornMagnussonXA | 483ee33 | 2021-04-08 01:35:24 +0200 | [diff] [blame] | 68 | if [ ! -z "$PROD_STUB_IMAGE_SOURCE" ]; then |
| 69 | echo -e "-- source image --\t$(docker images --format $1 $PROD_STUB_IMAGE_SOURCE)" >> $2 |
| 70 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | # Scale kubernetes resources to zero |
| 74 | # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action. |
| 75 | # This function is called for apps fully managed by the test script |
| 76 | __PRODSTUB_kube_scale_zero() { |
| 77 | __kube_scale_all_resources $KUBE_SIM_NAMESPACE autotest PRODSTUB |
| 78 | } |
| 79 | |
| 80 | # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action. |
| 81 | # This function is called for prestarted apps not managed by the test script. |
| 82 | __PRODSTUB_kube_scale_zero_and_wait() { |
| 83 | echo -e $RED" PRODSTUB app is not scaled in this state"$ERED |
| 84 | } |
| 85 | |
| 86 | # Delete all kube resouces for the app |
| 87 | # This function is called for apps managed by the test script. |
| 88 | __PRODSTUB_kube_delete_all() { |
| 89 | __kube_delete_all_resources $KUBE_SIM_NAMESPACE autotest PRODSTUB |
| 90 | } |
| 91 | |
| 92 | # Store docker logs |
| 93 | # This function is called for apps managed by the test script. |
| 94 | # args: <log-dir> <file-prexix> |
| 95 | __PRODSTUB_store_docker_logs() { |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 96 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | cb6113e | 2022-02-17 15:01:28 +0100 | [diff] [blame] | 97 | kubectl $KUBECONF logs -l "autotest=PRODSTUB" -n $KUBE_SIM_NAMESPACE --tail=-1 > $1$2_prodstub.log 2>&1 |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 98 | else |
| 99 | docker logs $PROD_STUB_APP_NAME > $1$2_prodstub.log 2>&1 |
| 100 | fi |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 101 | } |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 102 | |
| 103 | # Initial setup of protocol, host and ports |
| 104 | # This function is called for apps managed by the test script. |
| 105 | # args: - |
| 106 | __PRODSTUB_initial_setup() { |
| 107 | use_prod_stub_http |
| 108 | } |
| 109 | |
BjornMagnussonXA | 6fc58fd | 2021-11-18 08:19:45 +0100 | [diff] [blame] | 110 | # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers |
| 111 | # For docker, the namespace shall be excluded |
| 112 | # This function is called for apps managed by the test script as well as for prestarted apps. |
| 113 | # args: - |
| 114 | __PRODSTUB_statisics_setup() { |
| 115 | if [ $RUNMODE == "KUBE" ]; then |
| 116 | echo "PRODSTUB $PROD_STUB_APP_NAME $KUBE_SIM_NAMESPACE" |
| 117 | else |
| 118 | echo "PRODSTUB $PROD_STUB_APP_NAME" |
| 119 | fi |
| 120 | } |
| 121 | |
BjornMagnussonXA | e60d04e | 2021-12-27 13:38:01 +0100 | [diff] [blame] | 122 | # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied |
| 123 | # args: - |
| 124 | __PRODSTUB_test_requirements() { |
| 125 | : |
| 126 | } |
| 127 | |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 128 | ####################################################### |
| 129 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 130 | # Set http as the protocol to use for all communication to the Prod stub sim |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 131 | # args: - |
| 132 | # (Function for test scripts) |
| 133 | use_prod_stub_http() { |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 134 | __prod_stub_set_protocoll "http" $PROD_STUB_INTERNAL_PORT $PROD_STUB_EXTERNAL_PORT |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 135 | } |
| 136 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 137 | # Set https as the protocol to use for all communication to the Prod stub sim |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 138 | # args: - |
| 139 | # (Function for test scripts) |
| 140 | use_prod_stub_https() { |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 141 | __prod_stub_set_protocoll "https" $PROD_STUB_INTERNAL_SECURE_PORT $PROD_STUB_EXTERNAL_SECURE_PORT |
| 142 | } |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 143 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 144 | # Setup paths to svc/container for internal and external access |
| 145 | # args: <protocol> <internal-port> <external-port> |
| 146 | __prod_stub_set_protocoll() { |
| 147 | echo -e $BOLD"$PROD_STUB_DISPLAY_NAME protocol setting"$EBOLD |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 148 | echo -e " Using $BOLD $1 $EBOLD towards $PROD_STUB_DISPLAY_NAME" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 149 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 150 | ## Access to Prod stub sim |
| 151 | |
| 152 | PROD_STUB_SERVICE_PATH=$1"://"$PROD_STUB_APP_NAME":"$2 # docker access, container->container and script->container via proxy |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 153 | if [ $RUNMODE == "KUBE" ]; then |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 154 | PROD_STUB_SERVICE_PATH=$1"://"$PROD_STUB_APP_NAME.$KUBE_SIM_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 155 | fi |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 156 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 157 | echo "" |
| 158 | } |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 159 | |
| 160 | ### Admin API functions producer stub |
| 161 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 162 | ########################### |
| 163 | ### Producer stub functions |
| 164 | ########################### |
| 165 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 166 | # Export env vars for config files, docker compose and kube resources |
| 167 | # args: |
| 168 | __prodstub_export_vars() { |
| 169 | export PROD_STUB_APP_NAME |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 170 | export PROD_STUB_DISPLAY_NAME |
| 171 | |
| 172 | export DOCKER_SIM_NWNAME |
| 173 | export KUBE_SIM_NAMESPACE |
| 174 | |
| 175 | export PROD_STUB_IMAGE |
| 176 | export PROD_STUB_INTERNAL_PORT |
| 177 | export PROD_STUB_INTERNAL_SECURE_PORT |
| 178 | export PROD_STUB_EXTERNAL_PORT |
| 179 | export PROD_STUB_EXTERNAL_SECURE_PORT |
| 180 | } |
| 181 | |
| 182 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 183 | # Start the Producer stub in the simulator group |
| 184 | # args: - |
| 185 | # (Function for test scripts) |
| 186 | start_prod_stub() { |
| 187 | |
| 188 | echo -e $BOLD"Starting $PROD_STUB_DISPLAY_NAME"$EBOLD |
| 189 | |
| 190 | if [ $RUNMODE == "KUBE" ]; then |
| 191 | |
| 192 | # Check if app shall be fully managed by the test script |
| 193 | __check_included_image "PRODSTUB" |
| 194 | retcode_i=$? |
| 195 | |
| 196 | # Check if app shall only be used by the testscipt |
| 197 | __check_prestarted_image "PRODSTUB" |
| 198 | retcode_p=$? |
| 199 | |
| 200 | if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then |
BjornMagnussonXA | e60d04e | 2021-12-27 13:38:01 +0100 | [diff] [blame] | 201 | echo -e $RED"The $PROD_STUB_APP_NAME app is not included as managed nor prestarted in this test script"$ERED |
| 202 | echo -e $RED"The $PROD_STUB_APP_NAME will not be started"$ERED |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 203 | exit |
| 204 | fi |
| 205 | if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then |
BjornMagnussonXA | e60d04e | 2021-12-27 13:38:01 +0100 | [diff] [blame] | 206 | echo -e $RED"The $PROD_STUB_APP_NAME app is included both as managed and prestarted in this test script"$ERED |
| 207 | echo -e $RED"The $PROD_STUB_APP_NAME will not be started"$ERED |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 208 | exit |
| 209 | fi |
| 210 | |
| 211 | if [ $retcode_p -eq 0 ]; then |
| 212 | echo -e " Using existing $PROD_STUB_APP_NAME deployment and service" |
| 213 | echo " Setting RC replicas=1" |
| 214 | __kube_scale deployment $PROD_STUB_APP_NAME $KUBE_SIM_NAMESPACE 1 |
| 215 | fi |
| 216 | |
| 217 | if [ $retcode_i -eq 0 ]; then |
| 218 | echo -e " Creating $PROD_STUB_APP_NAME deployment and service" |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 219 | |
| 220 | __kube_create_namespace $KUBE_SIM_NAMESPACE |
| 221 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 222 | __prodstub_export_vars |
| 223 | |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 224 | # Create service |
| 225 | input_yaml=$SIM_GROUP"/"$PROD_STUB_COMPOSE_DIR"/"svc.yaml |
| 226 | output_yaml=$PWD/tmp/prodstub_svc.yaml |
| 227 | __kube_create_instance service $PROD_STUB_APP_NAME $input_yaml $output_yaml |
| 228 | |
| 229 | # Create app |
| 230 | input_yaml=$SIM_GROUP"/"$PROD_STUB_COMPOSE_DIR"/"app.yaml |
| 231 | output_yaml=$PWD/tmp/prodstub_app.yaml |
| 232 | __kube_create_instance app $PROD_STUB_APP_NAME $input_yaml $output_yaml |
| 233 | fi |
| 234 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 235 | __check_service_start $PROD_STUB_APP_NAME $PROD_STUB_SERVICE_PATH$PROD_STUB_ALIVE_URL |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 236 | |
| 237 | echo -ne " Service $PROD_STUB_APP_NAME - reset "$SAMELINE |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 238 | result=$(__do_curl $PROD_STUB_SERVICE_PATH/reset) |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 239 | if [ $? -ne 0 ]; then |
| 240 | echo -e " Service $PROD_STUB_APP_NAME - reset $RED Failed $ERED - will continue" |
| 241 | else |
| 242 | echo -e " Service $PROD_STUB_APP_NAME - reset $GREEN OK $EGREEN" |
| 243 | fi |
| 244 | else |
| 245 | |
| 246 | # Check if docker app shall be fully managed by the test script |
| 247 | __check_included_image 'PRODSTUB' |
| 248 | if [ $? -eq 1 ]; then |
| 249 | echo -e $RED"The Producer stub app is not included as managed in this test script"$ERED |
| 250 | echo -e $RED"The Producer stub will not be started"$ERED |
| 251 | exit |
| 252 | fi |
| 253 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 254 | __prodstub_export_vars |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 255 | |
| 256 | __start_container $PROD_STUB_COMPOSE_DIR "" NODOCKERARGS 1 $PROD_STUB_APP_NAME |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 257 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 258 | __check_service_start $PROD_STUB_APP_NAME $PROD_STUB_SERVICE_PATH$PROD_STUB_ALIVE_URL |
BjornMagnussonXA | e0b665e | 2021-01-08 22:19:18 +0100 | [diff] [blame] | 259 | fi |
| 260 | echo "" |
| 261 | return 0 |
| 262 | } |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 263 | |
| 264 | # Excute a curl cmd towards the prodstub simulator and check the response code. |
| 265 | # args: TEST|CONF <expected-response-code> <curl-cmd-string> [<json-file-to-compare-output>] |
| 266 | __execute_curl_to_prodstub() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 267 | TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") |
| 268 | echo "(${BASH_LINENO[0]}) - ${TIMESTAMP}: ${FUNCNAME[0]}" $@ >> $HTTPLOG |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 269 | proxyflag="" |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 270 | if [ ! -z "$KUBE_PROXY_PATH" ]; then |
| 271 | if [ $KUBE_PROXY_HTTPX == "http" ]; then |
| 272 | proxyflag=" --proxy $KUBE_PROXY_PATH" |
| 273 | else |
| 274 | proxyflag=" --proxy-insecure --proxy $KUBE_PROXY_PATH" |
BjornMagnussonXA | be9a07f | 2021-02-25 10:51:46 +0100 | [diff] [blame] | 275 | fi |
| 276 | fi |
BjornMagnussonXA | 145762b | 2022-03-22 10:35:10 +0100 | [diff] [blame] | 277 | if [ ! -z "$KUBE_PROXY_CURL_JWT" ]; then |
| 278 | jwt="-H "\""Authorization: Bearer $KUBE_PROXY_CURL_JWT"\" |
| 279 | echo " CMD: $3 $proxyflag $jwt" >> $HTTPLOG |
| 280 | res=$($3 $proxyflag -H "Authorization: Bearer $KUBE_PROXY_CURL_JWT") |
| 281 | else |
| 282 | echo " CMD: $3 $proxyflag" >> $HTTPLOG |
| 283 | res="$($3 $proxyflag)" |
| 284 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 285 | echo " RESP: $res" >> $HTTPLOG |
| 286 | retcode=$? |
| 287 | if [ $retcode -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 288 | __log_conf_fail_general " Fatal error when executing curl, response: "$retcode |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 289 | return 1 |
| 290 | fi |
| 291 | status=${res:${#res}-3} |
| 292 | if [ $status -eq $2 ]; then |
| 293 | if [ $# -eq 4 ]; then |
| 294 | body=${res:0:${#res}-3} |
| 295 | jobfile=$(cat $4) |
| 296 | echo " TARGET JSON: $jobfile" >> $HTTPLOG |
| 297 | res=$(python3 ../common/compare_json.py "$jobfile" "$body") |
| 298 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 299 | if [ $1 == "TEST" ]; then |
| 300 | __log_test_fail_body |
| 301 | else |
| 302 | __log_conf_fail_body |
| 303 | fi |
| 304 | return 1 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 305 | fi |
| 306 | fi |
| 307 | if [ $1 == "TEST" ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 308 | __log_test_pass |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 309 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 310 | __log_conf_ok |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 311 | fi |
| 312 | return 0 |
| 313 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 314 | if [ $1 == "TEST" ]; then |
| 315 | __log_test_fail_status_code $2 $status |
| 316 | else |
| 317 | __log_conf_fail_status_code $2 $status |
| 318 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 319 | return 1 |
| 320 | } |
| 321 | |
| 322 | # Prodstub API: Set (or reset) response code for producer supervision |
| 323 | # <response-code> <producer-id> [<forced_response_code>] |
| 324 | # (Function for test scripts) |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 325 | prodstub_arm_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 326 | __log_conf_start $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 327 | if [ $# -ne 2 ] && [ $# -ne 3 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 328 | __print_err "<response-code> <producer-id> [<forced_response_code>]" $@ |
| 329 | return 1 |
| 330 | fi |
| 331 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 332 | curlString="curl -X PUT -skw %{http_code} $PROD_STUB_SERVICE_PATH/arm/supervision/"$2 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 333 | if [ $# -eq 3 ]; then |
| 334 | curlString=$curlString"?response="$3 |
| 335 | fi |
| 336 | |
| 337 | __execute_curl_to_prodstub CONF $1 "$curlString" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 338 | return $? |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | # Prodstub API: Set (or reset) response code job create |
| 342 | # <response-code> <producer-id> <job-id> [<forced_response_code>] |
| 343 | # (Function for test scripts) |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 344 | prodstub_arm_job_create() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 345 | __log_conf_start $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 346 | if [ $# -ne 3 ] && [ $# -ne 4 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 347 | __print_err "<response-code> <producer-id> <job-id> [<forced_response_code>]" $@ |
| 348 | return 1 |
| 349 | fi |
| 350 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 351 | curlString="curl -X PUT -skw %{http_code} $PROD_STUB_SERVICE_PATH/arm/create/$2/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 352 | if [ $# -eq 4 ]; then |
| 353 | curlString=$curlString"?response="$4 |
| 354 | fi |
| 355 | |
| 356 | __execute_curl_to_prodstub CONF $1 "$curlString" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 357 | return $? |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | # Prodstub API: Set (or reset) response code job delete |
| 361 | # <response-code> <producer-id> <job-id> [<forced_response_code>] |
| 362 | # (Function for test scripts) |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 363 | prodstub_arm_job_delete() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 364 | __log_conf_start $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 365 | if [ $# -ne 3 ] && [ $# -ne 4 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 366 | __print_err "<response-code> <producer-id> <job-id> [<forced_response_code>]" $@ |
| 367 | return 1 |
| 368 | fi |
| 369 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 370 | curlString="curl -X PUT -skw %{http_code} $PROD_STUB_SERVICE_PATH/arm/delete/$2/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 371 | if [ $# -eq 4 ]; then |
| 372 | curlString=$curlString"?response="$4 |
| 373 | fi |
| 374 | |
| 375 | __execute_curl_to_prodstub CONF $1 "$curlString" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 376 | return $? |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | # Prodstub API: Arm a type of a producer |
| 380 | # <response-code> <producer-id> <type-id> |
| 381 | # (Function for test scripts) |
| 382 | prodstub_arm_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 383 | __log_conf_start $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 384 | if [ $# -ne 3 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 385 | __print_err "<response-code> <producer-id> <type-id>" $@ |
| 386 | return 1 |
| 387 | fi |
| 388 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 389 | curlString="curl -X PUT -skw %{http_code} $PROD_STUB_SERVICE_PATH/arm/type/$2/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 390 | |
| 391 | __execute_curl_to_prodstub CONF $1 "$curlString" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 392 | return $? |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | # Prodstub API: Disarm a type in a producer |
| 396 | # <response-code> <producer-id> <type-id> |
| 397 | # (Function for test scripts) |
| 398 | prodstub_disarm_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 399 | __log_conf_start $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 400 | if [ $# -ne 3 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 401 | __print_err "<response-code> <producer-id> <type-id>" $@ |
| 402 | return 1 |
| 403 | fi |
| 404 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 405 | curlString="curl -X DELETE -skw %{http_code} $PROD_STUB_SERVICE_PATH/arm/type/$2/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 406 | |
| 407 | __execute_curl_to_prodstub CONF $1 "$curlString" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 408 | return $? |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | # Prodstub API: Get job data for a job and compare with a target job json |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 412 | # <response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file> |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 413 | # (Function for test scripts) |
| 414 | prodstub_check_jobdata() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 415 | __log_test_start $@ |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 416 | if [ $# -ne 7 ]; then |
| 417 | __print_err "<response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file>" $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 418 | return 1 |
| 419 | fi |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 420 | if [ -f $7 ]; then |
| 421 | jobfile=$(cat $7) |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 422 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 423 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 424 | __log_test_fail_general "Template file "$7" for jobdata, does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 425 | return 1 |
| 426 | fi |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame] | 427 | targetJson="{\"ei_job_identity\":\"$3\",\"ei_type_identity\":\"$4\",\"target_uri\":\"$5\",\"owner\":\"$6\", \"ei_job_data\":$jobfile}" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 428 | file="./tmp/.p.json" |
| 429 | echo "$targetJson" > $file |
| 430 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 431 | curlString="curl -X GET -skw %{http_code} $PROD_STUB_SERVICE_PATH/jobdata/$2/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 432 | |
| 433 | __execute_curl_to_prodstub TEST $1 "$curlString" $file |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 434 | return $? |
| 435 | } |
| 436 | |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 437 | # Prodstub API: Get job data for a job and compare with a target job json |
| 438 | # <response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file> |
| 439 | # (Function for test scripts) |
| 440 | prodstub_check_jobdata_2() { |
| 441 | __log_test_start $@ |
| 442 | if [ $# -ne 7 ]; then |
| 443 | __print_err "<response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file>" $@ |
| 444 | return 1 |
| 445 | fi |
| 446 | if [ -f $7 ]; then |
| 447 | jobfile=$(cat $7) |
| 448 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 449 | else |
BjornMagnussonXA | 9d8fafb | 2021-05-10 11:11:49 +0200 | [diff] [blame] | 450 | __log_test_fail_general "Template file "$7" for jobdata, does not exist" |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 451 | return 1 |
| 452 | fi |
BjornMagnussonXA | 007b645 | 2021-11-29 08:03:38 +0100 | [diff] [blame] | 453 | if [[ "$ICS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then |
BjornMagnussonXA | 6f9c2b2 | 2021-06-11 16:31:40 +0200 | [diff] [blame] | 454 | targetJson="{\"info_job_identity\":\"$3\",\"info_type_identity\":\"$4\",\"target_uri\":\"$5\",\"owner\":\"$6\", \"info_job_data\":$jobfile,\"last_updated\":\"????\"}" |
| 455 | else |
| 456 | targetJson="{\"ei_job_identity\":\"$3\",\"ei_type_identity\":\"$4\",\"target_uri\":\"$5\",\"owner\":\"$6\", \"ei_job_data\":$jobfile,\"last_updated\":\"????\"}" |
| 457 | fi |
| 458 | file="./tmp/.p.json" |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 459 | echo "$targetJson" > $file |
| 460 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 461 | curlString="curl -X GET -skw %{http_code} $PROD_STUB_SERVICE_PATH/jobdata/$2/$3" |
BjornMagnussonXA | c963b73 | 2021-01-20 14:24:13 +0100 | [diff] [blame] | 462 | |
| 463 | __execute_curl_to_prodstub TEST $1 "$curlString" $file |
| 464 | return $? |
| 465 | } |
| 466 | |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 467 | # Prodstub API: Get job data for a job and compare with a target job json (info-jobs) |
| 468 | # <response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file> |
| 469 | # (Function for test scripts) |
| 470 | prodstub_check_jobdata_3() { |
| 471 | __log_test_start $@ |
| 472 | if [ $# -ne 7 ]; then |
| 473 | __print_err "<response-code> <producer-id> <job-id> <type-id> <target-url> <job-owner> <template-job-file>" $@ |
| 474 | return 1 |
| 475 | fi |
| 476 | if [ -f $7 ]; then |
| 477 | jobfile=$(cat $7) |
| 478 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 479 | else |
| 480 | __log_test_fail_general "Template file "$7" for jobdata, does not exist" |
| 481 | return 1 |
| 482 | fi |
| 483 | targetJson="{\"info_job_identity\":\"$3\",\"info_type_identity\":\"$4\",\"target_uri\":\"$5\",\"owner\":\"$6\", \"info_job_data\":$jobfile,\"last_updated\":\"????\"}" |
| 484 | file="./tmp/.p.json" |
| 485 | echo "$targetJson" > $file |
| 486 | |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 487 | curlString="curl -X GET -skw %{http_code} $PROD_STUB_SERVICE_PATH/jobdata/$2/$3" |
BjornMagnussonXA | ce4b14c | 2021-05-11 15:40:03 +0200 | [diff] [blame] | 488 | |
| 489 | __execute_curl_to_prodstub TEST $1 "$curlString" $file |
| 490 | return $? |
| 491 | } |
| 492 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 493 | # Prodstub API: Delete the job data |
| 494 | # <response-code> <producer-id> <job-id> |
| 495 | # (Function for test scripts) |
| 496 | prodstub_delete_jobdata() { |
| 497 | __log_conf_start |
| 498 | if [ $# -ne 3 ]; then |
| 499 | __print_err "<response-code> <producer-id> <job-id> " $@ |
| 500 | return 1 |
| 501 | fi |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 502 | curlString="curl -X DELETE -skw %{http_code} $PROD_STUB_SERVICE_PATH/jobdata/$2/$3" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 503 | |
| 504 | __execute_curl_to_prodstub CONF $1 "$curlString" |
| 505 | return $? |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | # Tests if a variable value in the prod stub is equal to a target value and and optional timeout. |
| 509 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 510 | # equal to the target or not. |
| 511 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 512 | # before setting pass or fail depending on if the variable value becomes equal to the target |
| 513 | # value or not. |
| 514 | # (Function for test scripts) |
| 515 | prodstub_equal() { |
| 516 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
BjornMagnussonXA | 663566c | 2021-11-08 10:25:07 +0100 | [diff] [blame] | 517 | __var_test "PRODSTUB" "$PROD_STUB_SERVICE_PATH/counter/" $1 "=" $2 $3 |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 518 | else |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 519 | __print_err "Wrong args to prodstub_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@ |
| 520 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 521 | } |