Added tests and improvements
[nonrtric.git] / test / auto-test / ONAP_UC.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
21 TC_ONELINE_DESCR="ONAP Use case REQ-626"
22 #App names to include in the test when running docker, space separated list
23 DOCKER_INCLUDED_IMAGES="CBS CONSUL CP CR MR DMAAPMR PA RICSIM SDNC NGW KUBEPROXY"
24
25 #App names to include in the test when running kubernetes, space separated list
26 KUBE_INCLUDED_IMAGES="CP CR MR DMAAPMR PA RICSIM SDNC 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"
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/mr_api_functions.sh
44 . ../common/control_panel_api_functions.sh
45 . ../common/controller_api_functions.sh
46 . ../common/cr_api_functions.sh
47 . ../common/consul_cbs_functions.sh
48 . ../common/kube_proxy_api_functions.sh
49 . ../common/gateway_api_functions.sh
50
51 setup_testenvironment
52
53 #### TEST BEGIN ####
54
55 #Local vars in test script
56 ##########################
57
58 use_cr_https
59 use_agent_rest_https
60 use_sdnc_https
61 use_simulator_https
62 use_mr_https
63
64 if [ "$PMS_VERSION" == "V2" ]; then
65     notificationurl=$CR_SERVICE_APP_PATH"/test"
66 else
67     echo "Version V2 of PMS is needed, exiting..."
68     exit 1
69 fi
70
71 generate_policy_uuid
72
73 # Tested variants of REST/DMAAP/SDNC config
74 TESTED_VARIANTS="REST   DMAAP   REST+SDNC   DMAAP+SDNC"
75 for interface in $TESTED_VARIANTS ; do
76
77     echo "#####################################################################"
78     echo "#####################################################################"
79     echo "### Testing agent: $interface using https"
80     echo "#####################################################################"
81     echo "#####################################################################"
82
83     clean_environment
84
85     start_kube_proxy
86
87     if [[ $interface = *"DMAAP"* ]]; then
88         use_agent_dmaap_https
89     else
90         use_agent_rest_https
91     fi
92
93     OSC_NUM_RICS=1
94     STD_NUM_RICS=1
95
96     start_ric_simulators  $RIC_SIM_PREFIX"_g1" $OSC_NUM_RICS OSC_2.1.0
97
98     start_ric_simulators  $RIC_SIM_PREFIX"_g2" $STD_NUM_RICS STD_1.1.3
99
100     start_ric_simulators $RIC_SIM_PREFIX"_g3" $STD_NUM_RICS STD_2.0.0
101
102     start_mr    "$MR_READ_TOPIC"  "/events" "users/policy-agent" \
103                 "$MR_WRITE_TOPIC" "/events" "users/mr-stub"
104
105     start_control_panel $SIM_GROUP/$CONTROL_PANEL_COMPOSE_DIR/$CONTROL_PANEL_CONFIG_FILE
106
107     if [ ! -z "$NRT_GATEWAY_APP_NAME" ]; then
108         start_gateway $SIM_GROUP/$NRT_GATEWAY_COMPOSE_DIR/$NRT_GATEWAY_CONFIG_FILE
109     fi
110
111     if [[ $interface = *"SDNC"* ]]; then
112         start_sdnc
113         prepare_consul_config      SDNC    ".consul_config.json"
114     else
115         prepare_consul_config      NOSDNC  ".consul_config.json"
116     fi
117
118     start_policy_agent NORPOXY $SIM_GROUP/$POLICY_AGENT_COMPOSE_DIR/$POLICY_AGENT_CONFIG_FILE
119
120     set_agent_trace
121
122     if [ $RUNMODE == "DOCKER" ]; then
123         start_consul_cbs
124     fi
125
126     if [ $RUNMODE == "KUBE" ]; then
127         agent_load_config                       ".consul_config.json"
128     else
129         consul_config_app                      ".consul_config.json"
130     fi
131
132     # Check that all rics are synced in
133     api_equal json:rics 3 300
134
135     api_get_status 200
136
137     # Print the A1 version for OSC
138     for ((i=1; i<=$OSC_NUM_RICS; i++))
139     do
140         sim_print $RIC_SIM_PREFIX"_g1_"$i interface
141     done
142
143
144     # Print the A1 version for STD 1.X
145     for ((i=1; i<=$STD_NUM_RICS; i++))
146     do
147         sim_print $RIC_SIM_PREFIX"_g2_"$i interface
148     done
149
150     # Print the A1 version for STD 2.X
151     for ((i=1; i<=$STD_NUM_RICS; i++))
152     do
153         sim_print $RIC_SIM_PREFIX"_g3_"$i interface
154     done
155
156     #################################################################
157     ## REQ: Synchronize A1 Policy Information in RAN
158     #################################################################
159
160     # Load the polictypes in osc
161     for ((i=1; i<=$OSC_NUM_RICS; i++))
162     do
163         sim_put_policy_type 201 $RIC_SIM_PREFIX"_g1_"$i 100 demo-testdata/OSC/sim_qos.json
164         sim_put_policy_type 201 $RIC_SIM_PREFIX"_g1_"$i 20008 demo-testdata/OSC/sim_tsa.json
165     done
166
167     #Check the number of schemas and the individual schemas in OSC
168     api_equal json:policy-types 3 300
169
170     for ((i=1; i<=$OSC_NUM_RICS; i++))
171     do
172         api_equal json:policy-types?ric_id=$RIC_SIM_PREFIX"_g1_"$i 2 120
173     done
174
175     # Check the schemas in OSC
176     for ((i=1; i<=$OSC_NUM_RICS; i++))
177     do
178         api_get_policy_type 200 100 demo-testdata/OSC/qos-agent-modified.json
179         api_get_policy_type 200 20008 demo-testdata/OSC/tsa-agent-modified.json
180     done
181
182
183     # Load the polictypes in std
184     for ((i=1; i<=$STD_NUM_RICS; i++))
185     do
186         sim_put_policy_type 201 $RIC_SIM_PREFIX"_g3_"$i STD_QOS_0_2_0 demo-testdata/STD2/sim_qos.json
187         sim_put_policy_type 201 $RIC_SIM_PREFIX"_g3_"$i STD_QOS2_0.1.0 demo-testdata/STD2/sim_qos2.json
188     done
189
190     #Check the number of schemas and the individual schemas in STD
191     api_equal json:policy-types 5 120
192
193     for ((i=1; i<=$STD_NUM_RICS; i++))
194     do
195         api_equal json:policy-types?ric_id=$RIC_SIM_PREFIX"_g3_"$i 2 120
196     done
197
198     # Check the schemas in STD
199     for ((i=1; i<=$STD_NUM_RICS; i++))
200     do
201         api_get_policy_type 200 STD_QOS_0_2_0 demo-testdata/STD2/qos-agent-modified.json
202         api_get_policy_type 200 'STD_QOS2_0.1.0' demo-testdata/STD2/qos2-agent-modified.json
203     done
204
205     #Check the number of types
206     api_equal json:policy-types 5 120
207
208     #################################################################
209     ##  REQ: A1 Policy Type / Instance Operations
210     #################################################################
211
212     # Create policies
213     use_agent_rest_http
214
215     api_put_service 201 "Emergency-response-app" 0 "$CR_SERVICE_APP_PATH/1"
216
217     # Create policies in OSC
218     for ((i=1; i<=$OSC_NUM_RICS; i++))
219     do
220         api_put_policy 201 "Emergency-response-app" $RIC_SIM_PREFIX"_g1_"$i 100 $((3000+$i)) NOTRANSIENT $notificationurl demo-testdata/OSC/piqos_template.json 1
221         api_put_policy 201 "Emergency-response-app" $RIC_SIM_PREFIX"_g1_"$i 20008 $((4000+$i)) NOTRANSIENT $notificationurl demo-testdata/OSC/pitsa_template.json 1
222     done
223
224
225     # Check the number of policies in OSC
226     for ((i=1; i<=$OSC_NUM_RICS; i++))
227     do
228         sim_equal $RIC_SIM_PREFIX"_g1_"$i num_instances 2
229     done
230
231
232     # Create policies in STD
233     for ((i=1; i<=$STD_NUM_RICS; i++))
234     do
235         api_put_policy 201 "Emergency-response-app" $RIC_SIM_PREFIX"_g2_"$i NOTYPE $((2100+$i)) NOTRANSIENT $notificationurl demo-testdata/STD/pi1_template.json 1
236         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
237         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
238     done
239
240
241     # Check the number of policies in STD
242     for ((i=1; i<=$STD_NUM_RICS; i++))
243     do
244         sim_equal $RIC_SIM_PREFIX"_g2_"$i num_instances 1
245         sim_equal $RIC_SIM_PREFIX"_g3_"$i num_instances 2
246     done
247
248     #################################################################
249     ##  REQ: A1 Policy Instance Status Operations
250     #################################################################
251
252     # Check status STD
253     for ((i=1; i<=$STD_NUM_RICS; i++))
254     do
255         api_get_policy_status 200 $((2100+$i)) STD "UNDEFINED"
256         api_get_policy_status 200 $((2300+$i)) STD2 EMPTY EMPTY
257         api_get_policy_status 200 $((2400+$i)) STD2 EMPTY EMPTY
258     done
259
260     # Check status OSC
261     VAL='NOT IN EFFECT'
262     for ((i=1; i<=$OSC_NUM_RICS; i++))
263     do
264         api_get_policy_status 200 $((3000+$i)) OSC "$VAL" "false"
265         api_get_policy_status 200 $((4000+$i)) OSC "$VAL" "false"
266     done
267
268     # Note: Status callback is not tested since this callback (http POST) is made from the
269     # ricsim directly to the receiver of the status, i.e. the status does NOT
270     # pass through PMS
271
272     check_policy_agent_logs
273
274     if [[ $interface = *"SDNC"* ]]; then
275         check_sdnc_logs
276     fi
277
278     #### TEST COMPLETE ####
279
280     store_logs          "https__${interface}"
281
282 done
283
284 print_result
285
286 auto_clean_environment