Return correct error response code from A1 controller
[nonrtric.git] / test / auto-test / FTC320.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="Create and delete 50 policies in each 50 RICs, 25 STD version, 25 OSC version. Via agent REST"
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
33 NUM_RICS=25
34 # Number of instances per RIC
35 NUM_INST=50
36
37 # Clean and start all containers
38 clean_containers
39
40 start_ric_simulators ricsim_g1 $NUM_RICS OSC_2.1.0
41
42 start_ric_simulators ricsim_g2 $NUM_RICS STD_1.1.3
43
44 start_mr
45
46 start_cr
47
48 start_consul_cbs
49
50 prepare_consul_config      NOSDNC  ".consul_config.json"
51 consul_config_app                  ".consul_config.json"
52
53 start_control_panel
54
55 start_policy_agent
56
57 use_agent_rest_http
58
59 set_agent_debug
60
61 # Main tests
62
63 echo "Checking agent is alive"
64 api_get_status 200
65
66
67 echo "Print the interface for group 1 simulators, shall be OSC"
68 for ((i=1; i<=$NUM_RICS; i++))
69 do
70    sim_print ricsim_g1_$i interface
71 done
72
73 echo "Print the interface for group 2 simulators, shall be STD"
74 for ((i=1; i<=$NUM_RICS; i++))
75 do
76    sim_print ricsim_g2_$i interface
77 done
78
79 echo "Checking the number of policy instances in each group 1 simulator, shall be 0"
80 for ((i=1; i<=$NUM_RICS; i++))
81 do
82    sim_equal ricsim_g1_$i num_instances 0
83 done
84
85 echo "Checking the number of policy instances in each group 2 simulator, shall be 0"
86 for ((i=1; i<=$NUM_RICS; i++))
87 do
88    sim_equal ricsim_g1_$i num_instances 0
89 done
90
91 echo "Load policy type 1 in each group 1 simulator"
92 for ((i=1; i<=$NUM_RICS; i++))
93 do
94    sim_put_policy_type 201 ricsim_g1_$i 1 testdata/OSC/sim_1.json
95 done
96
97 echo "Checking the number of policy types in each group 1 simulator, shall be 1"
98 for ((i=1; i<=$NUM_RICS; i++))
99 do
100    sim_equal ricsim_g1_$i num_types 1
101 done
102
103 echo "Checking the number of policy types in each group 2 simulator, shall be 0"
104 for ((i=1; i<=$NUM_RICS; i++))
105 do
106    sim_equal ricsim_g2_$i num_types 0
107 done
108
109 echo "Check the number of rics, shall be the configured number: ""$(($NUM_RICS*2))"
110 api_equal json:rics "$(($NUM_RICS*2))" 120
111
112 api_equal json:policy_types 2 120  #Wait for the agent to refresh types from the simulator
113
114 sleep_wait 120 "Wait for the agent to refresh the types from all rics"
115
116 echo "Check the number of types in the agent for each group 1 rics, shall be 1"
117 for ((i=1; i<=$NUM_RICS; i++))
118 do
119    api_equal json:policy_types?ric=ricsim_g1_$i 1
120 done
121
122 echo "Check the number of types in the agent for each group 2 rics, shall be 1"
123 for ((i=1; i<=$NUM_RICS; i++))
124 do
125    api_equal json:policy_types?ric=ricsim_g2_$i 1
126 done
127
128 echo "Register the service"
129 api_put_service 201 "rapp1" 0 "$CR_PATH/1"
130
131 echo "Loading "$NUM_INST" policies in each group 1 ric"
132 for ((i=1; i<=$NUM_RICS; i++))
133 do
134    inst=$((1000000+$i*$NUM_INST))
135    api_put_policy 201 "rapp1" ricsim_g1_$i 1 $inst testdata/OSC/pi1_template.json $NUM_INST
136 done
137
138 echo "Loading "$NUM_INST" policies in each group 2 ric"
139 for ((i=1; i<=$NUM_RICS; i++))
140 do
141    inst=$((2000000+$i*$NUM_INST))
142    api_put_policy 201 "rapp1" ricsim_g2_$i NOTYPE $inst testdata/STD/pi1_template.json $NUM_INST
143 done
144
145 echo "Check the number of types in the agent for each group 1 rics, shall be 1"
146 for ((i=1; i<=$NUM_RICS; i++))
147 do
148    api_equal json:policy_types?ric=ricsim_g1_$i 1
149 done
150
151 echo "Check the number of types in the agent for each group 2 rics, shall be 1"
152 for ((i=1; i<=$NUM_RICS; i++))
153 do
154    api_equal json:policy_types?ric=ricsim_g2_$i 1
155 done
156
157 echo "Checking the number of policy instances in each group 1 simulator, shall be "$NUM_INST
158 for ((i=1; i<=$NUM_RICS; i++))
159 do
160    sim_equal ricsim_g1_$i num_instances 50
161 done
162
163 echo "Checking the number of policy instances in each group 2 simulator, shall be "$NUM_INST
164 for ((i=1; i<=$NUM_RICS; i++))
165 do
166    sim_equal ricsim_g2_$i num_instances 50
167 done
168
169 echo "Deleting "$NUM_INST" policies in each group 1 ric"
170 for ((i=1; i<=$NUM_RICS; i++))
171 do
172    inst=$((1000000+$i*$NUM_INST))
173    api_delete_policy 201 $NUM_INST
174 done
175
176 echo "Deleting "$NUM_INST" policies in each group 2 ric"
177 for ((i=1; i<=$NUM_RICS; i++))
178 do
179    inst=$((2000000+$i*$NUM_INST))
180    api_delete_policy 201 $NUM_INST
181 done
182
183 echo "Checking the number of policy instances in each group 1 simulator, shall be 0"
184 for ((i=1; i<=$NUM_RICS; i++))
185 do
186    sim_equal ricsim_g1_$i num_instances 50
187 done
188
189 echo "Checking the number of policy instances in each group 1 simulator, shall be 0"
190 for ((i=1; i<=$NUM_RICS; i++))
191 do
192    sim_equal ricsim_g2_$i num_instances 50
193 done
194
195
196 check_policy_agent_logs
197
198 #### TEST COMPLETE ####
199
200 store_logs          END
201
202 print_result