Merge "NONRTRIC - Implement DMaaP mediator producer service in Java"
[nonrtric.git] / test / auto-test / FTC2001.sh
1 #!/usr/bin/env 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 TC_ONELINE_DESCR="Testing southbound proxy for PMS and ECS"
21
22 #App names to include in the test when running docker, space separated list
23 DOCKER_INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM ECS PRODSTUB HTTPPROXY NGW KUBEPROXY"
24
25 #App names to include in the test when running kubernetes, space separated list
26 KUBE_INCLUDED_IMAGES=" MR CR PA PRODSTUB RICSIM CP ECS HTTPPROXY KUBEPROXY NGW"
27 #Prestarted app (not started by script) to include in the test when running kubernetes, space separated list
28 KUBE_PRESTARTED_IMAGES=""
29
30 #Ignore image in DOCKER_INCLUDED_IMAGES, KUBE_INCLUDED_IMAGES if
31 #the image is not configured in the supplied env_file
32 #Used for images not applicable to all supported profile
33 CONDITIONALLY_IGNORED_IMAGES="NGW"
34
35 #Supported test environment profiles
36 SUPPORTED_PROFILES="ONAP-HONOLULU ONAP-ISTANBUL ORAN-CHERRY ORAN-D-RELEASE ORAN-E-RELEASE"
37 #Supported run modes
38 SUPPORTED_RUNMODES="DOCKER KUBE"
39
40 . ../common/testcase_common.sh $@
41 . ../common/agent_api_functions.sh
42 . ../common/ricsimulator_api_functions.sh
43 . ../common/ecs_api_functions.sh
44 . ../common/prodstub_api_functions.sh
45 . ../common/cr_api_functions.sh
46 . ../common/mr_api_functions.sh
47 . ../common/control_panel_api_functions.sh
48 . ../common/consul_cbs_functions.sh
49 . ../common/http_proxy_api_functions.sh
50 . ../common/kube_proxy_api_functions.sh
51 . ../common/gateway_api_functions.sh
52
53 setup_testenvironment
54
55 #### TEST BEGIN ####
56
57 #Local vars in test script
58 ##########################
59
60 use_cr_https
61 use_agent_rest_https
62 use_simulator_https
63 use_ecs_rest_https
64 use_prod_stub_https
65
66 if [ "$PMS_VERSION" == "V2" ]; then
67     notificationurl=$CR_SERVICE_APP_PATH"/test"
68 else
69    echo "PMS VERSION 2 (V2) is required"
70    exit 1
71 fi
72
73 clean_environment
74
75 start_kube_proxy
76
77 STD_NUM_RICS=2
78
79 start_http_proxy
80
81 start_ric_simulators $RIC_SIM_PREFIX"_g3" $STD_NUM_RICS STD_2.0.0
82
83 start_mr #Just to prevent errors in the agent log...
84
85 start_control_panel $SIM_GROUP/$CONTROL_PANEL_COMPOSE_DIR/$CONTROL_PANEL_CONFIG_FILE
86
87 if [ ! -z "$NRT_GATEWAY_APP_NAME" ]; then
88     start_gateway $SIM_GROUP/$NRT_GATEWAY_COMPOSE_DIR/$NRT_GATEWAY_CONFIG_FILE
89 fi
90
91 start_policy_agent PROXY $SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_CONFIG_FILE
92
93 if [ $RUNMODE == "DOCKER" ]; then
94     start_consul_cbs
95 fi
96
97 prepare_consul_config      NOSDNC  ".consul_config.json"
98
99 if [ $RUNMODE == "KUBE" ]; then
100     agent_load_config                       ".consul_config.json"
101 else
102     consul_config_app                      ".consul_config.json"
103 fi
104
105 start_cr
106
107 start_prod_stub
108
109 start_ecs PROXY $SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_CONFIG_FILE
110
111 set_agent_trace
112
113 set_ecs_debug
114
115 api_get_status 200
116
117 # Print the A1 version for STD 2.X
118 for ((i=1; i<=$STD_NUM_RICS; i++))
119 do
120     sim_print $RIC_SIM_PREFIX"_g3_"$i interface
121 done
122 # Load the polictypes in std
123 for ((i=1; i<=$STD_NUM_RICS; i++))
124 do
125     sim_put_policy_type 201 $RIC_SIM_PREFIX"_g3_"$i STD_QOS_0_2_0 demo-testdata/STD2/sim_qos.json
126     sim_put_policy_type 201 $RIC_SIM_PREFIX"_g3_"$i STD_QOS2_0.1.0 demo-testdata/STD2/sim_qos2.json
127 done
128
129 #Check the number of schemas and the individual schemas in STD
130 api_equal json:policy-types 2 120
131
132 for ((i=1; i<=$STD_NUM_RICS; i++))
133 do
134     api_equal json:policy-types?ric_id=$RIC_SIM_PREFIX"_g3_"$i 2 120
135 done
136
137 # Check the schemas in STD
138 for ((i=1; i<=$STD_NUM_RICS; i++))
139 do
140     api_get_policy_type 200 STD_QOS_0_2_0 demo-testdata/STD2/qos-agent-modified.json
141     api_get_policy_type 200 'STD_QOS2_0.1.0' demo-testdata/STD2/qos2-agent-modified.json
142 done
143
144 #Check the number of types
145 api_equal json:policy-types 2 300
146
147 api_put_service 201 "Emergency-response-app" 0 "$CR_SERVICE_APP_PATH/1"
148
149 # Create policies in STD
150 for ((i=1; i<=$STD_NUM_RICS; i++))
151 do
152     generate_policy_uuid
153     api_put_policy 201 "Emergency-response-app" $RIC_SIM_PREFIX"_g3_"$i STD_QOS_0_2_0 $((2300+$i)) NOTRANSIENT $notificationurl demo-testdata/STD2/pi1_template.json 1
154     generate_policy_uuid
155     api_put_policy 201 "Emergency-response-app" $RIC_SIM_PREFIX"_g3_"$i 'STD_QOS2_0.1.0' $((2400+$i)) NOTRANSIENT $notificationurl demo-testdata/STD2/pi1_template.json 1
156 done
157
158
159 # Check the number of policies in STD
160 for ((i=1; i<=$STD_NUM_RICS; i++))
161 do
162     sim_equal $RIC_SIM_PREFIX"_g3_"$i num_instances 2
163 done
164
165 # Print calling hosts STD 2.X
166 for ((i=1; i<=$STD_NUM_RICS; i++))
167 do
168     sim_print $RIC_SIM_PREFIX"_g3_"$i remote_hosts
169     sim_contains_str $RIC_SIM_PREFIX"_g3_"$i remote_hosts proxy
170 done
171
172 FLAT_A1_EI="1"
173
174 CB_JOB="$PROD_STUB_SERVICE_PATH$PROD_STUB_JOB_CALLBACK"
175 CB_SV="$PROD_STUB_SERVICE_PATH$PROD_STUB_SUPERVISION_CALLBACK"
176 RIC_G1_1=$RIC_SIM_PREFIX"_g3_1"
177 RIC_G1_2=$RIC_SIM_PREFIX"_g3_2"
178 if [ $RUNMODE == "KUBE" ]; then
179     RIC_G1_1=$(get_kube_sim_host $RIC_G1_1)
180     RIC_G1_2=$(get_kube_sim_host $RIC_G1_2)
181 fi
182 TARGET1="$RIC_SIM_HTTPX://$RIC_G1_1:$RIC_SIM_PORT/datadelivery"
183 TARGET2="$RIC_SIM_HTTPX://$RIC_G1_1:$RIC_SIM_PORT/datadelivery"
184
185 STATUS1="$CR_SERVICE_APP_PATH/job1-status"
186 STATUS2="$CR_SERVICE_APP_PATH/job2-status"
187
188 prodstub_arm_producer 200 prod-a
189 prodstub_arm_type 200 prod-a type1
190 prodstub_arm_job_create 200 prod-a job1
191 prodstub_arm_job_create 200 prod-a job2
192
193 ### ecs status
194 ecs_api_service_status 200
195
196 if [[ "$ECS_FEATURE_LEVEL" == *"TYPE-SUBSCRIPTIONS"* ]]; then
197     #Type registration status callbacks
198     TYPESTATUS1="$CR_SERVICE_APP_PATH/type-status1"
199
200     ecs_api_idc_put_subscription 201 subscription-id-1 owner1 $TYPESTATUS1
201
202     ecs_api_idc_get_subscription_ids 200 owner1 subscription-id-1
203 fi
204
205 ## Setup prod-a
206 if [ $ECS_VERSION == "V1-1" ]; then
207     ecs_api_edp_put_producer 201 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1 testdata/ecs/ei-type-1.json
208
209     ecs_api_edp_get_producer 200 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1 testdata/ecs/ei-type-1.json
210 else
211     ecs_api_edp_put_type_2 201 type1 testdata/ecs/ei-type-1.json
212
213     ecs_api_edp_put_producer_2 201 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1
214
215     ecs_api_edp_get_producer_2 200 prod-a $CB_JOB/prod-a $CB_SV/prod-a type1
216 fi
217
218 ecs_api_edp_get_producer_status 200 prod-a ENABLED
219
220
221 ## Create a job for prod-a
222 ## job1 - prod-a
223 if [  -z "$FLAT_A1_EI" ]; then
224     ecs_api_a1_put_job 201 type1 job1 $TARGET1 ricsim_g3_1 testdata/ecs/job-template.json
225 else
226     ecs_api_a1_put_job 201 job1 type1 $TARGET1 ricsim_g3_1 $STATUS1 testdata/ecs/job-template.json
227 fi
228
229 # Check the job data in the producer
230 if [ $ECS_VERSION == "V1-1" ]; then
231     prodstub_check_jobdata 200 prod-a job1 type1 $TARGET1 ricsim_g3_1 testdata/ecs/job-template.json
232 else
233     if [[ "$ECS_FEATURE_LEVEL" != *"INFO-TYPES"* ]]; then
234         prodstub_check_jobdata_2 200 prod-a job1 type1 $TARGET1 ricsim_g3_1 testdata/ecs/job-template.json
235     else
236         prodstub_check_jobdata_3 200 prod-a job1 type1 $TARGET1 ricsim_g3_1 testdata/ecs/job-template.json
237     fi
238 fi
239
240
241 ## Create a second job for prod-a
242 ## job2 - prod-a
243 if [  -z "$FLAT_A1_EI" ]; then
244     ecs_api_a1_put_job 201 type1 job2 $TARGET2 ricsim_g3_2 testdata/ecs/job-template.json
245 else
246     ecs_api_a1_put_job 201 job2 type1 $TARGET2 ricsim_g3_2 $STATUS2 testdata/ecs/job-template.json
247 fi
248
249 # Check the job data in the producer
250 if [ $ECS_VERSION == "V1-1" ]; then
251     prodstub_check_jobdata 200 prod-a job2 type1 $TARGET2 ricsim_g3_2 testdata/ecs/job-template.json
252 else
253     if [[ "$ECS_FEATURE_LEVEL" != *"INFO-TYPES"* ]]; then
254         prodstub_check_jobdata_2 200 prod-a job2 type1 $TARGET2 ricsim_g3_2 testdata/ecs/job-template.json
255     else
256         prodstub_check_jobdata_3 200 prod-a job2 type1 $TARGET2 ricsim_g3_2 testdata/ecs/job-template.json
257     fi
258 fi
259
260 # Arm producer prod-a for supervision failure
261 prodstub_arm_producer 200 prod-a 400
262
263 # Wait for producer prod-a to go disabled
264 ecs_api_edp_get_producer_status 200 prod-a DISABLED 360
265
266 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
267     ecs_equal json:data-producer/v1/info-producers 0 1000
268 else
269     ecs_equal json:ei-producer/v1/eiproducers 0 1000
270 fi
271
272 if [[ "$ECS_FEATURE_LEVEL" == *"TYPE-SUBSCRIPTIONS"* ]]; then
273     cr_equal received_callbacks 3 30
274     cr_api_check_all_ecs_subscription_events 200 type-status1 type1 testdata/ecs/ei-type-1.json REGISTERED
275     cr_api_check_all_ecs_events 200 job1-status DISABLED
276     cr_api_check_all_ecs_events 200 job2-status DISABLED
277 else
278     cr_equal received_callbacks 2 30
279     cr_api_check_all_ecs_events 200 job1-status DISABLED
280     cr_api_check_all_ecs_events 200 job2-status DISABLED
281 fi
282
283 cr_contains_str remote_hosts $HTTP_PROXY_APP_NAME
284
285 check_policy_agent_logs
286 check_ecs_logs
287
288 #### TEST COMPLETE ####
289
290 store_logs          END
291
292 print_result
293
294 auto_clean_environment