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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
21 ### Admin API functions producer stub
24 # Excute a curl cmd towards the prodstub simulator and check the response code.
25 # args: TEST|CONF <expected-response-code> <curl-cmd-string> [<json-file-to-compare-output>]
26 __execute_curl_to_prodstub() {
27 #echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
28 echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
29 echo " CMD: $3" >> $HTTPLOG
31 echo " RESP: $res" >> $HTTPLOG
33 if [ $retcode -ne 0 ]; then
34 echo " RETCODE: "$retcode
35 echo -e $RED" FAIL - fatal error when executing curl."$ERED
38 status=${res:${#res}-3}
39 if [ $status -eq $2 ]; then
41 body=${res:0:${#res}-3}
43 echo " TARGET JSON: $jobfile" >> $HTTPLOG
44 res=$(python3 ../common/compare_json.py "$jobfile" "$body")
45 if [ $res -ne 0 ]; then
46 echo -e $RED" FAIL, returned body not correct"$ERED
50 if [ $1 == "TEST" ]; then
51 echo -e $GREEN" PASS"$EGREEN
53 echo -e $GREEN" OK"$EGREEN
57 echo -e $RED" FAIL - expected http response: "$2" but got http response: "$status $ERED
61 # Prodstub API: Set (or reset) response code for producer supervision
62 # <response-code> <producer-id> [<forced_response_code>]
63 # (Function for test scripts)
64 prodstub_arm_supervision() {
65 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
66 echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG
67 if [ $# -ne 2 ] && [ $# -ne 3 ]; then
69 __print_err "<response-code> <producer-id> [<forced_response_code>]" $@
73 curlString="curl -X PUT -skw %{http_code} $PROD_STUB_LOCALHOST/arm/supervision/"$2
75 curlString=$curlString"?response="$3
78 __execute_curl_to_prodstub CONF $1 "$curlString"
86 # Prodstub API: Set (or reset) response code job create
87 # <response-code> <producer-id> <job-id> [<forced_response_code>]
88 # (Function for test scripts)
89 prodstub_arm_create() {
90 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
91 echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG
92 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
94 __print_err "<response-code> <producer-id> <job-id> [<forced_response_code>]" $@
98 curlString="curl -X PUT -skw %{http_code} $PROD_STUB_LOCALHOST/arm/create/$2/$3"
100 curlString=$curlString"?response="$4
103 __execute_curl_to_prodstub CONF $1 "$curlString"
105 if [ $? -ne 0 ]; then
111 # Prodstub API: Set (or reset) response code job delete
112 # <response-code> <producer-id> <job-id> [<forced_response_code>]
113 # (Function for test scripts)
114 prodstub_arm_delete() {
115 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
116 echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG
117 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
119 __print_err "<response-code> <producer-id> <job-id> [<forced_response_code>]" $@
123 curlString="curl -X PUT -skw %{http_code} $PROD_STUB_LOCALHOST/arm/delete/$2/$3"
124 if [ $# -eq 4 ]; then
125 curlString=$curlString"?response="$4
128 __execute_curl_to_prodstub CONF $1 "$curlString"
130 if [ $? -ne 0 ]; then
136 # Prodstub API: Arm a type of a producer
137 # <response-code> <producer-id> <type-id>
138 # (Function for test scripts)
139 prodstub_arm_type() {
140 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
141 echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG
142 if [ $# -ne 3 ]; then
144 __print_err "<response-code> <producer-id> <type-id>" $@
148 curlString="curl -X PUT -skw %{http_code} $PROD_STUB_LOCALHOST/arm/type/$2/$3"
150 __execute_curl_to_prodstub CONF $1 "$curlString"
152 if [ $? -ne 0 ]; then
158 # Prodstub API: Disarm a type in a producer
159 # <response-code> <producer-id> <type-id>
160 # (Function for test scripts)
161 prodstub_disarm_type() {
162 echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
163 echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG
164 if [ $# -ne 3 ]; then
166 __print_err "<response-code> <producer-id> <type-id>" $@
170 curlString="curl -X DELETE -skw %{http_code} $PROD_STUB_LOCALHOST/arm/type/$2/$3"
172 __execute_curl_to_prodstub CONF $1 "$curlString"
174 if [ $? -ne 0 ]; then
180 # Prodstub API: Get job data for a job and compare with a target job json
181 # <response-code> <producer-id> <job-id> <type-id> <target-url> <template-job-file>
182 # (Function for test scripts)
183 prodstub_check_jobdata() {
184 echo -e $BOLD"TEST(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD
185 echo "TEST(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG
186 if [ $# -ne 6 ]; then
188 __print_err "<response-code> <producer-id> <job-id> <type-id> <target-url> <template-job-file>" $@
193 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
195 echo -e $RED" FAIL. Template file "$6" for jobdata, does not exist"$ERED
198 targetJson="{\"ei_job_identity\":\"$3\",\"ei_type_identity\":\"$4\",\"target_uri\":\"$5\",\"ei_job_data\":$jobfile}"
200 echo "$targetJson" > $file
202 curlString="curl -X GET -skw %{http_code} $PROD_STUB_LOCALHOST/jobdata/$2/$3"
204 __execute_curl_to_prodstub TEST $1 "$curlString" $file
206 if [ $? -ne 0 ]; then