Merge "Add missing licences"
[nonrtric.git] / test / auto-test / FTC810.sh
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 TC_ONELINE_DESCR="Repeatedly create and delete policies in each RICs for 24h. Via agent REST/DMAAP/DMAAP_BATCH and SDNC using http"
21
22 . ../common/testcase_common.sh  $@
23 . ../common/agent_api_functions.sh
24 . ../common/ricsimulator_api_functions.sh
25
26 #### TEST BEGIN ####
27
28 #Local vars in test script
29 ##########################
30 # Path to callback receiver
31 CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks"
32 # Number of RICs per interface type (OSC and STD)
33 NUM_RICS=30
34 # Number of policy instances per RIC
35 NUM_INSTANCES=5
36
37 clean_containers
38
39 start_ric_simulators ricsim_g1 $NUM_RICS OSC_2.1.0
40
41 start_ric_simulators ricsim_g2 $NUM_RICS STD_1.1.3
42
43 start_mr
44
45 start_cr
46
47 start_consul_cbs
48
49 prepare_consul_config      SDNC  ".consul_config.json"
50 consul_config_app                  ".consul_config.json"
51
52 start_sdnc
53
54 start_control_panel
55
56 start_policy_agent
57
58 use_agent_rest_http
59
60 api_get_status 200
61
62 echo "Print the interface for group 1 simulators, shall be OSC"
63 for ((i=1; i<=$NUM_RICS; i++))
64 do
65    sim_print ricsim_g1_$i interface
66 done
67
68 echo "Print the interface for group 2 simulators, shall be STD"
69 for ((i=1; i<=$NUM_RICS; i++))
70 do
71    sim_print ricsim_g2_$i interface
72 done
73
74 echo "Load policy type in group 1 simulators"
75 for ((i=1; i<=$NUM_RICS; i++))
76 do
77    sim_put_policy_type 201 ricsim_g1_$i 1 testdata/OSC/sim_1.json
78 done
79
80 echo "Check the number of instances in  group 1 simulators, shall be 0"
81 for ((i=1; i<=$NUM_RICS; i++))
82 do
83    sim_equal ricsim_g1_$i num_instances 0
84 done
85
86 echo "Check the number of instances in  group 2 simulators, shall be 0"
87 for ((i=1; i<=$NUM_RICS; i++))
88 do
89    sim_equal ricsim_g2_$i num_instances 0
90 done
91
92 echo "Wait for the agent to refresh types from the simulator"
93 api_equal json:policy_types 2 120
94
95 echo "Check the number of types in the agent for each ric is 1"
96 for ((i=1; i<=$NUM_RICS; i++))
97 do
98    api_equal json:policy_types?ric=ricsim_g1_$i 1 120
99 done
100
101 echo "Register a service"
102 api_put_service 201 "serv1" 0 "$CR_PATH/1"
103
104 TEST_DURATION=$((24*3600))
105 TEST_START=$SECONDS
106
107 AGENT_INTERFACES="REST DMAAP DMAAP-BATCH"
108
109 MR_MESSAGES=0
110
111 while [ $(($SECONDS-$TEST_START)) -lt $TEST_DURATION ]; do
112
113     echo ""
114     echo "#########################################################################################################"
115     echo -e $BOLD"INFO: Test executed for: "$(($SECONDS-$TEST_START)) "seconds. Target is: "$TEST_DURATION" seconds."$EBOLD
116     echo "#########################################################################################################"
117     echo ""
118
119    for interface in $AGENT_INTERFACES ; do
120
121       echo "############################################"
122       echo "## Testing using agent interface: $interface ##"
123       echo "############################################"
124
125       if [ $interface == "REST" ]; then
126          use_agent_rest_http
127       else
128          use_agent_dmaap
129       fi
130
131       echo "Create $NUM_INSTANCES instances in each OSC RIC"
132       INSTANCE_ID=200000
133       INSTANCES=0
134       for ((i=1; i<=$NUM_RICS; i++))
135       do
136          if [ $interface == "DMAAP-BATCH" ]; then
137             api_put_policy_batch 201 "serv1" ricsim_g1_$i 1 $INSTANCE_ID testdata/OSC/pi1_template.json $NUM_INSTANCES
138          else
139             api_put_policy 201 "serv1" ricsim_g1_$i 1 $INSTANCE_ID testdata/OSC/pi1_template.json $NUM_INSTANCES
140          fi
141          if [ $interface != "REST" ]; then
142             MR_MESSAGES=$(($MR_MESSAGES+$NUM_INSTANCES))
143          fi
144          sim_equal ricsim_g1_$i num_instances $NUM_INSTANCES
145          INSTANCE_ID=$(($INSTANCE_ID+$NUM_INSTANCES))
146          INSTANCES=$(($INSTANCES+$NUM_INSTANCES))
147       done
148
149       api_equal json:policy_ids $INSTANCES
150
151       echo "Create $NUM_INSTANCES instances in each STD RIC"
152       for ((i=1; i<=$NUM_RICS; i++))
153       do
154          if [ $interface == "DMAAP-BATCH" ]; then
155             api_put_policy_batch 201 "serv1" ricsim_g2_$i NOTYPE $INSTANCE_ID testdata/STD/pi1_template.json $NUM_INSTANCES
156          else
157             api_put_policy 201 "serv1" ricsim_g2_$i NOTYPE $INSTANCE_ID testdata/STD/pi1_template.json $NUM_INSTANCES
158          fi
159          if [ $interface != "REST" ]; then
160             MR_MESSAGES=$(($MR_MESSAGES+$NUM_INSTANCES))
161          fi
162          sim_equal ricsim_g2_$i num_instances $NUM_INSTANCES
163          INSTANCE_ID=$(($INSTANCE_ID+$NUM_INSTANCES))
164          INSTANCES=$(($INSTANCES+$NUM_INSTANCES))
165       done
166
167       api_equal json:policy_ids $INSTANCES
168
169
170       echo "Delete all instances in each OSC RIC"
171
172       INSTANCE_ID=200000
173       for ((i=1; i<=$NUM_RICS; i++))
174       do
175          if [ $interface == "DMAAP-BATCH" ]; then
176             api_delete_policy_batch 204 $INSTANCE_ID $NUM_INSTANCES
177          else
178             api_delete_policy 204 $INSTANCE_ID $NUM_INSTANCES
179          fi
180          if [ $interface != "REST" ]; then
181             MR_MESSAGES=$(($MR_MESSAGES+$NUM_INSTANCES))
182          fi
183          INSTANCES=$(($INSTANCES-$NUM_INSTANCES))
184          sim_equal ricsim_g1_$i num_instances 0
185          INSTANCE_ID=$(($INSTANCE_ID+$NUM_INSTANCES))
186       done
187
188       api_equal json:policy_ids $INSTANCES
189
190       echo "Delete all instances in each STD RIC"
191
192       for ((i=1; i<=$NUM_RICS; i++))
193       do
194          if [ $interface == "DMAAP-BATCH" ]; then
195             api_delete_policy_batch 204 $INSTANCE_ID $NUM_INSTANCES
196          else
197             api_delete_policy 204 $INSTANCE_ID $NUM_INSTANCES
198          fi
199          if [ $interface != "REST" ]; then
200             MR_MESSAGES=$(($MR_MESSAGES+$NUM_INSTANCES))
201          fi
202          INSTANCES=$(($INSTANCES-$NUM_INSTANCES))
203          sim_equal ricsim_g2_$i num_instances 0
204          INSTANCE_ID=$(($INSTANCE_ID+$NUM_INSTANCES))
205       done
206
207       api_equal json:policy_ids 0
208
209       cr_equal received_callbacks 0
210
211       mr_equal requests_submitted $MR_MESSAGES
212       mr_equal requests_fetched $MR_MESSAGES
213       mr_equal responses_submitted $MR_MESSAGES
214       mr_equal responses_fetched $MR_MESSAGES
215       mr_equal current_requests 0
216       mr_equal current_responses 0
217
218
219       for ((i=1; i<=$NUM_RICS; i++))
220       do
221          sim_contains_str ricsim_g1_$i remote_hosts "a1-controller"
222          sim_contains_str ricsim_g2_$i remote_hosts "a1-controller"
223       done
224
225    done
226
227 done
228
229 check_policy_agent_logs
230
231 #### TEST COMPLETE ####
232
233 store_logs          END
234
235 print_result
236
237 auto_clean_containers