BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +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 | |
| 20 | # This is a script that contains specific test functions for ECS NB/SB API |
| 21 | |
| 22 | . ../common/api_curl.sh |
| 23 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 24 | # Tests if a variable value in the ECS is equal to a target value and and optional timeout. |
| 25 | # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is |
| 26 | # equal to the target or not. |
| 27 | # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds |
| 28 | # before setting pass or fail depending on if the variable value becomes equal to the target |
| 29 | # value or not. |
| 30 | # (Function for test scripts) |
| 31 | ecs_equal() { |
| 32 | if [ $# -eq 2 ] || [ $# -eq 3 ]; then |
| 33 | __var_test ECS "$LOCALHOST$ECS_EXTERNAL_PORT/" $1 "=" $2 $3 |
| 34 | else |
| 35 | __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@ |
| 36 | fi |
| 37 | } |
| 38 | |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 39 | |
| 40 | ########################################## |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 41 | ######### A1-E Enrichment API ########## |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 42 | ########################################## |
| 43 | #Function prefix: ecs_api_a1 |
| 44 | |
| 45 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 46 | # args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ] |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 47 | # args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 48 | # (Function for test scripts) |
| 49 | ecs_api_a1_get_job_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 50 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 51 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 52 | if [ -z "$FLAT_A1_EI" ]; then |
| 53 | # Valid number of parameters 4,5,6 etc |
| 54 | if [ $# -lt 3 ]; then |
| 55 | __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@ |
| 56 | return 1 |
| 57 | fi |
| 58 | else |
| 59 | echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
| 60 | # Valid number of parameters 4,5,6 etc |
| 61 | if [ $# -lt 3 ]; then |
| 62 | __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@ |
| 63 | return 1 |
| 64 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 65 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 66 | search="" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 67 | if [ $3 != "NOWNER" ]; then |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 68 | search="?owner="$3 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 69 | fi |
| 70 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 71 | if [ -z "$FLAT_A1_EI" ]; then |
| 72 | query="/A1-EI/v1/eitypes/$2/eijobs$search" |
| 73 | else |
| 74 | if [ $2 != "NOTYPE" ]; then |
| 75 | if [ -z "$search" ]; then |
| 76 | search="?eiTypeId="$2 |
| 77 | else |
| 78 | search=$search"&eiTypeId="$2 |
| 79 | fi |
| 80 | fi |
| 81 | query="/A1-EI/v1/eijobs$search" |
| 82 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 83 | res="$(__do_curl_to_api ECS GET $query)" |
| 84 | status=${res:${#res}-3} |
| 85 | |
| 86 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 87 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 88 | return 1 |
| 89 | fi |
| 90 | |
| 91 | if [ $# -gt 3 ]; then |
| 92 | body=${res:0:${#res}-3} |
| 93 | targetJson="[" |
| 94 | |
| 95 | for pid in ${@:4} ; do |
| 96 | if [ "$targetJson" != "[" ]; then |
| 97 | targetJson=$targetJson"," |
| 98 | fi |
| 99 | if [ $pid != "EMPTY" ]; then |
| 100 | targetJson=$targetJson"\"$pid\"" |
| 101 | fi |
| 102 | done |
| 103 | |
| 104 | targetJson=$targetJson"]" |
| 105 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 106 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 107 | |
| 108 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 109 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 110 | return 1 |
| 111 | fi |
| 112 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 113 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 114 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 115 | return 0 |
| 116 | } |
| 117 | |
| 118 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 119 | # args: <response-code> <type-id> [<schema-file>] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 120 | # (Function for test scripts) |
| 121 | ecs_api_a1_get_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 122 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 123 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 124 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
| 125 | __print_err "<response-code> <type-id> [<schema-file>]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 126 | return 1 |
| 127 | fi |
| 128 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 129 | query="/A1-EI/v1/eitypes/$2" |
| 130 | res="$(__do_curl_to_api ECS GET $query)" |
| 131 | status=${res:${#res}-3} |
| 132 | |
| 133 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 134 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 135 | return 1 |
| 136 | fi |
| 137 | |
| 138 | if [ $# -eq 3 ]; then |
| 139 | body=${res:0:${#res}-3} |
| 140 | if [ -f $3 ]; then |
| 141 | schema=$(cat $3) |
| 142 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 143 | __log_test_fail_general "Schema file "$3", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 144 | return 1 |
| 145 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 146 | if [ -z "$FLAT_A1_EI" ]; then |
| 147 | targetJson="{\"eiJobParametersSchema\":$schema}" |
| 148 | else |
| 149 | targetJson=$schema |
| 150 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 151 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 152 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 153 | |
| 154 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 155 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 156 | return 1 |
| 157 | fi |
| 158 | fi |
| 159 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 160 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 161 | return 0 |
| 162 | } |
| 163 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 164 | # API Test function: GET /A1-EI/v1/eitypes |
| 165 | # args: <response-code> [ (EMPTY | [<type-id>]+) ] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 166 | # (Function for test scripts) |
| 167 | ecs_api_a1_get_type_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 168 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 169 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 170 | if [ $# -lt 1 ]; then |
| 171 | __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 172 | return 1 |
| 173 | fi |
| 174 | |
| 175 | query="/A1-EI/v1/eitypes" |
| 176 | res="$(__do_curl_to_api ECS GET $query)" |
| 177 | status=${res:${#res}-3} |
| 178 | |
| 179 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 180 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 181 | return 1 |
| 182 | fi |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 183 | if [ $# -gt 1 ]; then |
| 184 | body=${res:0:${#res}-3} |
| 185 | targetJson="[" |
| 186 | if [ $2 != "EMPTY" ]; then |
| 187 | for pid in ${@:2} ; do |
| 188 | if [ "$targetJson" != "[" ]; then |
| 189 | targetJson=$targetJson"," |
| 190 | fi |
| 191 | targetJson=$targetJson"\"$pid\"" |
| 192 | done |
| 193 | fi |
| 194 | targetJson=$targetJson"]" |
| 195 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 196 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 197 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 198 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 199 | __log_test_fail_body |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 200 | return 1 |
| 201 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 202 | fi |
| 203 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 204 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 205 | return 0 |
| 206 | } |
| 207 | |
| 208 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}/status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 209 | # args: <response-code> <type-id> <job-id> [<status>] |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 210 | # args (flat uri structure): <response-code> <job-id> [<status>] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 211 | # (Function for test scripts) |
| 212 | ecs_api_a1_get_job_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 213 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 214 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 215 | if [ -z "$FLAT_A1_EI" ]; then |
| 216 | if [ $# -ne 3 ] && [ $# -ne 4 ]; then |
| 217 | __print_err "<response-code> <type-id> <job-id> [<status>]" $@ |
| 218 | return 1 |
| 219 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 220 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 221 | query="/A1-EI/v1/eitypes/$2/eijobs/$3/status" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 222 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 223 | res="$(__do_curl_to_api ECS GET $query)" |
| 224 | status=${res:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 225 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 226 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 227 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 228 | return 1 |
| 229 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 230 | if [ $# -eq 4 ]; then |
| 231 | body=${res:0:${#res}-3} |
| 232 | targetJson="{\"operationalState\": \"$4\"}" |
| 233 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 234 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 235 | |
| 236 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 237 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 238 | return 1 |
| 239 | fi |
| 240 | fi |
| 241 | else |
| 242 | echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
| 243 | if [ $# -ne 2 ] && [ $# -ne 3 ]; then |
| 244 | __print_err "<response-code> <job-id> [<status>]" $@ |
| 245 | return 1 |
| 246 | fi |
| 247 | |
| 248 | query="/A1-EI/v1/eijobs/$2/status" |
| 249 | |
| 250 | res="$(__do_curl_to_api ECS GET $query)" |
| 251 | status=${res:${#res}-3} |
| 252 | |
| 253 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 254 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 255 | return 1 |
| 256 | fi |
| 257 | if [ $# -eq 3 ]; then |
| 258 | body=${res:0:${#res}-3} |
| 259 | targetJson="{\"eiJobStatus\": \"$3\"}" |
| 260 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 261 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 262 | |
| 263 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 264 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 265 | return 1 |
| 266 | fi |
| 267 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 268 | fi |
| 269 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 270 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 271 | return 0 |
| 272 | } |
| 273 | |
| 274 | # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 275 | # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>] |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 276 | # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 277 | # (Function for test scripts) |
| 278 | ecs_api_a1_get_job() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 279 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 280 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 281 | if [ -z "$FLAT_A1_EI" ]; then |
| 282 | if [ $# -ne 3 ] && [ $# -ne 6 ]; then |
| 283 | __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@ |
| 284 | return 1 |
| 285 | fi |
| 286 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
| 287 | else |
| 288 | echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
| 289 | if [ $# -ne 2 ] && [ $# -ne 7 ]; then |
| 290 | __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@ |
| 291 | return 1 |
| 292 | fi |
| 293 | query="/A1-EI/v1/eijobs/$2" |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 294 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 295 | res="$(__do_curl_to_api ECS GET $query)" |
| 296 | status=${res:${#res}-3} |
| 297 | |
| 298 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 299 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 300 | return 1 |
| 301 | fi |
| 302 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 303 | if [ -z "$FLAT_A1_EI" ]; then |
| 304 | if [ $# -eq 6 ]; then |
| 305 | body=${res:0:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 306 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 307 | if [ -f $6 ]; then |
| 308 | jobfile=$(cat $6) |
| 309 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 310 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 311 | _log_test_fail_general "Job template file "$6", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 312 | return 1 |
| 313 | fi |
| 314 | targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" |
| 315 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 316 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 317 | |
| 318 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 319 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 320 | return 1 |
| 321 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 322 | fi |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 323 | else |
| 324 | if [ $# -eq 7 ]; then |
| 325 | body=${res:0:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 326 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 327 | if [ -f $7 ]; then |
| 328 | jobfile=$(cat $7) |
| 329 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") |
| 330 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 331 | _log_test_fail_general "Job template file "$6", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 332 | return 1 |
| 333 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 334 | targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 335 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 336 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 337 | |
| 338 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 339 | __log_test_fail_body |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 340 | return 1 |
| 341 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 342 | fi |
| 343 | fi |
| 344 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 345 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 346 | return 0 |
| 347 | } |
| 348 | |
| 349 | # API Test function: DELETE /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 350 | # args: <response-code> <type-id> <job-id> |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 351 | # args (flat uri structure): <response-code> <job-id> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 352 | # (Function for test scripts) |
| 353 | ecs_api_a1_delete_job() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 354 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 355 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 356 | if [ -z "$FLAT_A1_EI" ]; then |
| 357 | if [ $# -ne 3 ]; then |
| 358 | __print_err "<response-code> <type-id> <job-id>" $@ |
| 359 | return 1 |
| 360 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 361 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 362 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
| 363 | else |
| 364 | echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
| 365 | if [ $# -ne 2 ]; then |
| 366 | __print_err "<response-code> <job-id>" $@ |
| 367 | return 1 |
| 368 | fi |
| 369 | query="/A1-EI/v1/eijobs/$2" |
| 370 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 371 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 372 | status=${res:${#res}-3} |
| 373 | |
| 374 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 375 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 376 | return 1 |
| 377 | fi |
| 378 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 379 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 380 | return 0 |
| 381 | } |
| 382 | |
| 383 | # API Test function: PUT /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 384 | # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file> |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 385 | # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 386 | # (Function for test scripts) |
| 387 | ecs_api_a1_put_job() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 388 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 389 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 390 | if [ -z "$FLAT_A1_EI" ]; then |
| 391 | if [ $# -lt 6 ]; then |
| 392 | __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@ |
| 393 | return 1 |
| 394 | fi |
| 395 | if [ -f $6 ]; then |
| 396 | jobfile=$(cat $6) |
| 397 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") |
| 398 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 399 | _log_test_fail_general "Job template file "$6", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 400 | return 1 |
| 401 | fi |
| 402 | |
| 403 | inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" |
| 404 | file="./tmp/.p.json" |
| 405 | echo "$inputJson" > $file |
| 406 | |
| 407 | query="/A1-EI/v1/eitypes/$2/eijobs/$3" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 408 | else |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 409 | echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW |
| 410 | if [ $# -lt 7 ]; then |
| 411 | __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@ |
| 412 | return 1 |
| 413 | fi |
| 414 | if [ -f $7 ]; then |
| 415 | jobfile=$(cat $7) |
| 416 | jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g") |
| 417 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 418 | _log_test_fail_general "Job template file "$7", does not exist" |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 419 | return 1 |
| 420 | fi |
| 421 | |
| 422 | inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}" |
| 423 | file="./tmp/.p.json" |
| 424 | echo "$inputJson" > $file |
| 425 | |
| 426 | query="/A1-EI/v1/eijobs/$2" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 427 | fi |
| 428 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 429 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 430 | status=${res:${#res}-3} |
| 431 | |
| 432 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 433 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 434 | return 1 |
| 435 | fi |
| 436 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 437 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 438 | return 0 |
| 439 | } |
| 440 | |
| 441 | |
| 442 | ########################################## |
| 443 | #### Enrichment Data Producer API #### |
| 444 | ########################################## |
| 445 | # Function prefix: ecs_api_edp |
| 446 | |
| 447 | # API Test function: GET /ei-producer/v1/eitypes |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 448 | # args: <response-code> [ EMPTY | <type-id>+] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 449 | # (Function for test scripts) |
| 450 | ecs_api_edp_get_type_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 451 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 452 | |
| 453 | if [ $# -lt 1 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 454 | __print_err "<response-code> [ EMPTY | <type-id>+]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 455 | return 1 |
| 456 | fi |
| 457 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 458 | query="/ei-producer/v1/eitypes" |
| 459 | res="$(__do_curl_to_api ECS GET $query)" |
| 460 | status=${res:${#res}-3} |
| 461 | |
| 462 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 463 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 464 | return 1 |
| 465 | fi |
| 466 | |
| 467 | if [ $# -gt 1 ]; then |
| 468 | body=${res:0:${#res}-3} |
| 469 | targetJson="[" |
| 470 | if [ $2 != "EMPTY" ]; then |
| 471 | for pid in ${@:2} ; do |
| 472 | if [ "$targetJson" != "[" ]; then |
| 473 | targetJson=$targetJson"," |
| 474 | fi |
| 475 | targetJson=$targetJson"\"$pid\"" |
| 476 | done |
| 477 | fi |
| 478 | targetJson=$targetJson"]" |
| 479 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 480 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 481 | |
| 482 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 483 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 484 | return 1 |
| 485 | fi |
| 486 | fi |
| 487 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 488 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 489 | return 0 |
| 490 | } |
| 491 | |
| 492 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 493 | # args: <response-code> <producer-id> [<status> [<timeout>]] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 494 | # (Function for test scripts) |
| 495 | ecs_api_edp_get_producer_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 496 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 497 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 498 | if [ $# -lt 2 ] || [ $# -gt 4 ]; then |
| 499 | __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 500 | return 1 |
| 501 | fi |
| 502 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 503 | query="/ei-producer/v1/eiproducers/$2/status" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 504 | start=$SECONDS |
| 505 | for (( ; ; )); do |
| 506 | res="$(__do_curl_to_api ECS GET $query)" |
| 507 | status=${res:${#res}-3} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 508 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 509 | if [ $# -eq 4 ]; then |
| 510 | duration=$((SECONDS-start)) |
| 511 | echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}" |
| 512 | if [ $duration -gt $4 ]; then |
| 513 | echo "" |
| 514 | duration=-1 #Last iteration |
| 515 | fi |
| 516 | else |
| 517 | duration=-1 #single test, no wait |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 518 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 519 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 520 | if [ $status -ne $1 ]; then |
| 521 | if [ $duration -eq -1 ]; then |
| 522 | __log_test_fail_status_code $1 $status |
| 523 | return 1 |
| 524 | fi |
| 525 | fi |
| 526 | if [ $# -ge 3 ] && [ $status -eq $1 ]; then |
| 527 | body=${res:0:${#res}-3} |
| 528 | targetJson="{\"operational_state\": \"$3\"}" |
| 529 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 530 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 531 | |
| 532 | if [ $res -ne 0 ]; then |
| 533 | if [ $duration -eq -1 ]; then |
| 534 | __log_test_fail_body |
| 535 | return 1 |
| 536 | fi |
| 537 | else |
| 538 | duration=-1 #Goto pass |
| 539 | fi |
| 540 | fi |
| 541 | if [ $duration -eq -1 ]; then |
| 542 | if [ $# -eq 4 ]; then |
| 543 | echo "" |
| 544 | fi |
| 545 | __log_test_pass |
| 546 | return 0 |
| 547 | else |
| 548 | sleep 1 |
| 549 | fi |
| 550 | done |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | |
| 554 | # API Test function: GET /ei-producer/v1/eiproducers |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 555 | # args: <response-code> [ EMPTY | <producer-id>+] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 556 | # (Function for test scripts) |
| 557 | ecs_api_edp_get_producer_ids() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 558 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 559 | |
| 560 | if [ $# -lt 1 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 561 | __print_err "<response-code> [ EMPTY | <producer-id>+]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 562 | return 1 |
| 563 | fi |
| 564 | |
| 565 | query="/ei-producer/v1/eiproducers" |
| 566 | res="$(__do_curl_to_api ECS GET $query)" |
| 567 | status=${res:${#res}-3} |
| 568 | |
| 569 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 570 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 571 | return 1 |
| 572 | fi |
| 573 | |
| 574 | if [ $# -gt 1 ]; then |
| 575 | body=${res:0:${#res}-3} |
| 576 | targetJson="[" |
| 577 | |
| 578 | for pid in ${@:2} ; do |
| 579 | if [ "$targetJson" != "[" ]; then |
| 580 | targetJson=$targetJson"," |
| 581 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 582 | if [ $pid != "EMPTY" ]; then |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 583 | targetJson=$targetJson"\"$pid\"" |
| 584 | fi |
| 585 | done |
| 586 | |
| 587 | targetJson=$targetJson"]" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 588 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 589 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 590 | |
| 591 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 592 | __log_test_fail_body |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 593 | return 1 |
| 594 | fi |
| 595 | fi |
| 596 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 597 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 598 | return 0 |
| 599 | } |
| 600 | |
| 601 | # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId} |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 602 | # args: <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 603 | # (Function for test scripts) |
| 604 | ecs_api_edp_get_type() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 605 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 606 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 607 | paramError=1 |
| 608 | if [ $# -eq 2 ]; then |
| 609 | paramError=0 |
| 610 | fi |
| 611 | if [ $# -gt 3 ]; then |
| 612 | paramError=0 |
| 613 | fi |
| 614 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 615 | __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 616 | return 1 |
| 617 | fi |
| 618 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 619 | query="/ei-producer/v1/eitypes/$2" |
| 620 | res="$(__do_curl_to_api ECS GET $query)" |
| 621 | status=${res:${#res}-3} |
| 622 | |
| 623 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 624 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 625 | return 1 |
| 626 | fi |
| 627 | if [ $# -gt 3 ]; then |
| 628 | body=${res:0:${#res}-3} |
| 629 | |
| 630 | if [ -f $3 ]; then |
| 631 | schema=$(cat $3) |
| 632 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 633 | __log_test_fail_general "Job template file "$3", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 634 | return 1 |
| 635 | fi |
| 636 | |
| 637 | targetJson="" |
| 638 | if [ $4 != "EMPTY" ]; then |
| 639 | for pid in ${@:4} ; do |
| 640 | if [ "$targetJson" != "" ]; then |
| 641 | targetJson=$targetJson"," |
| 642 | fi |
| 643 | targetJson=$targetJson"\"$pid\"" |
| 644 | done |
| 645 | fi |
| 646 | targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}" |
| 647 | |
| 648 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 649 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 650 | |
| 651 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 652 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 653 | return 1 |
| 654 | fi |
| 655 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 656 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 657 | return 0 |
| 658 | } |
| 659 | |
| 660 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 661 | # args: <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ] |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 662 | # (Function for test scripts) |
| 663 | ecs_api_edp_get_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 664 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 665 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 666 | #Possible arg count: 2, 5 6, 8, 10 etc |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 667 | paramError=1 |
| 668 | if [ $# -eq 2 ]; then |
| 669 | paramError=0 |
| 670 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 671 | if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 672 | paramError=0 |
| 673 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 674 | variablecount=$(($#-4)) |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 675 | if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then |
| 676 | paramError=0 |
| 677 | fi |
| 678 | |
| 679 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 680 | __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 681 | return 1 |
| 682 | fi |
| 683 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 684 | query="/ei-producer/v1/eiproducers/$2" |
| 685 | res="$(__do_curl_to_api ECS GET $query)" |
| 686 | status=${res:${#res}-3} |
| 687 | |
| 688 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 689 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 690 | return 1 |
| 691 | fi |
| 692 | |
| 693 | if [ $# -gt 2 ]; then |
| 694 | body=${res:0:${#res}-3} |
| 695 | targetJson="[" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 696 | if [ $# -gt 5 ]; then |
| 697 | arr=(${@:5}) |
| 698 | for ((i=0; i<$(($#-5)); i=i+2)); do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 699 | if [ "$targetJson" != "[" ]; then |
| 700 | targetJson=$targetJson"," |
| 701 | fi |
| 702 | if [ -f ${arr[$i+1]} ]; then |
| 703 | schema=$(cat ${arr[$i+1]}) |
| 704 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 705 | _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 706 | return 1 |
| 707 | fi |
| 708 | |
| 709 | targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" |
| 710 | done |
| 711 | fi |
| 712 | targetJson=$targetJson"]" |
| 713 | if [ $# -gt 4 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 714 | targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 715 | fi |
| 716 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 717 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
| 718 | |
| 719 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 720 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 721 | return 1 |
| 722 | fi |
| 723 | fi |
| 724 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 725 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 726 | return 0 |
| 727 | } |
| 728 | |
| 729 | # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 730 | # args: <response-code> <producer-id> |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 731 | # (Function for test scripts) |
| 732 | ecs_api_edp_delete_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 733 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 734 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 735 | if [ $# -lt 2 ]; then |
| 736 | __print_err "<response-code> <producer-id>" $@ |
| 737 | return 1 |
| 738 | fi |
| 739 | |
| 740 | query="/ei-producer/v1/eiproducers/$2" |
| 741 | res="$(__do_curl_to_api ECS DELETE $query)" |
| 742 | status=${res:${#res}-3} |
| 743 | |
| 744 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 745 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 746 | return 1 |
| 747 | fi |
| 748 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 749 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 750 | return 0 |
| 751 | } |
| 752 | |
| 753 | # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 754 | # args: <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 755 | # (Function for test scripts) |
| 756 | ecs_api_edp_put_producer() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 757 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 758 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 759 | #Valid number of parametrer 5,6,8,10, |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 760 | paramError=1 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 761 | if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 762 | paramError=0 |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 763 | elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 764 | paramError=0 |
| 765 | fi |
| 766 | if [ $paramError -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 767 | __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@ |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 768 | return 1 |
| 769 | fi |
| 770 | |
| 771 | inputJson="[" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 772 | if [ $# -gt 5 ]; then |
| 773 | arr=(${@:5}) |
| 774 | for ((i=0; i<$(($#-5)); i=i+2)); do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 775 | if [ "$inputJson" != "[" ]; then |
| 776 | inputJson=$inputJson"," |
| 777 | fi |
| 778 | if [ -f ${arr[$i+1]} ]; then |
| 779 | schema=$(cat ${arr[$i+1]}) |
| 780 | else |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 781 | _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 782 | return 1 |
| 783 | fi |
| 784 | inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" |
| 785 | done |
| 786 | fi |
| 787 | inputJson="\"supported_ei_types\":"$inputJson"]" |
| 788 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 789 | inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 790 | |
| 791 | inputJson="{"$inputJson"}" |
| 792 | |
| 793 | file="./tmp/.p.json" |
| 794 | echo "$inputJson" > $file |
| 795 | query="/ei-producer/v1/eiproducers/$2" |
| 796 | res="$(__do_curl_to_api ECS PUT $query $file)" |
| 797 | status=${res:${#res}-3} |
| 798 | |
| 799 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 800 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 801 | return 1 |
| 802 | fi |
| 803 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 804 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 805 | return 0 |
| 806 | } |
| 807 | |
| 808 | # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame^] | 809 | # args: <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+) |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 810 | # (Function for test scripts) |
| 811 | ecs_api_edp_get_producer_jobs() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 812 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 813 | |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame^] | 814 | #Valid number of parameter 2,3,7,11 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 815 | paramError=1 |
| 816 | if [ $# -eq 2 ]; then |
| 817 | paramError=0 |
| 818 | fi |
| 819 | if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then |
| 820 | paramError=0 |
| 821 | fi |
| 822 | variablecount=$(($#-2)) |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame^] | 823 | if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 824 | paramError=0 |
| 825 | fi |
| 826 | if [ $paramError -eq 1 ]; then |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame^] | 827 | __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 828 | return 1 |
| 829 | fi |
| 830 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 831 | query="/ei-producer/v1/eiproducers/$2/eijobs" |
| 832 | res="$(__do_curl_to_api ECS GET $query)" |
| 833 | status=${res:${#res}-3} |
| 834 | if [ $status -ne $1 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 835 | __log_test_fail_status_code $1 $status |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 836 | return 1 |
| 837 | fi |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 838 | if [ $# -gt 2 ]; then |
| 839 | body=${res:0:${#res}-3} |
| 840 | targetJson="[" |
| 841 | if [ $# -gt 3 ]; then |
| 842 | arr=(${@:3}) |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame^] | 843 | for ((i=0; i<$(($#-3)); i=i+5)); do |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 844 | if [ "$targetJson" != "[" ]; then |
| 845 | targetJson=$targetJson"," |
| 846 | fi |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame^] | 847 | if [ -f ${arr[$i+4]} ]; then |
| 848 | jobfile=$(cat ${arr[$i+4]}) |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 849 | jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g") |
| 850 | else |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame^] | 851 | _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 852 | return 1 |
| 853 | fi |
BjornMagnussonXA | 2138b63 | 2020-11-30 21:17:32 +0100 | [diff] [blame^] | 854 | targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile}" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 855 | done |
| 856 | fi |
| 857 | targetJson=$targetJson"]" |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 858 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 859 | echo " TARGET JSON: $targetJson" >> $HTTPLOG |
| 860 | res=$(python3 ../common/compare_json.py "$targetJson" "$body") |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 861 | |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 862 | if [ $res -ne 0 ]; then |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 863 | __log_test_fail_body |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 864 | return 1 |
| 865 | fi |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 866 | fi |
| 867 | |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 868 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 869 | return 0 |
| 870 | } |
| 871 | |
| 872 | |
| 873 | ########################################## |
| 874 | #### Service status #### |
| 875 | ########################################## |
| 876 | # Function prefix: ecs_api_service |
| 877 | |
| 878 | # API Test function: GET /status |
| 879 | # args: <response-code> |
| 880 | # (Function for test scripts) |
| 881 | ecs_api_service_status() { |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 882 | __log_test_start $@ |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 883 | |
| 884 | if [ $# -lt 1 ]; then |
| 885 | __print_err "<response-code> [<producer-id>]*|NOID" $@ |
| 886 | return 1 |
| 887 | fi |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 888 | res="$(__do_curl_to_api ECS GET /status)" |
| 889 | status=${res:${#res}-3} |
| 890 | if [ $status -ne $1 ]; then |
| 891 | __log_test_fail_status_code $1 $status |
| 892 | return 1 |
| 893 | fi |
| 894 | __log_test_pass |
BjornMagnussonXA | bf3700b | 2020-10-05 08:39:40 +0200 | [diff] [blame] | 895 | return 0 |
| 896 | } |