Revert "Feature 11001: Robot framework linting for E2E tests"
[osm/tests.git] / robot-systest / testsuite / heal_03-multiple_healing.robot
1 #   Licensed under the Apache License, Version 2.0 (the "License");
2 #   you may not use this file except in compliance with the License.
3 #   You may obtain a copy of the License at
4 #
5 #       http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #   Unless required by applicable law or agreed to in writing, software
8 #   distributed under the License is distributed on an "AS IS" BASIS,
9 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 #   See the License for the specific language governing permissions and
11 #   limitations under the License.
12
13 *** Settings ***
14 Documentation   [HEAL-03] Healing of multiple VDUs
15
16 Library   OperatingSystem
17 Library   String
18 Library   Collections
19 Library   Process
20 Library   SSHLibrary
21
22 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/vnfd_lib.robot
23 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/vnf_lib.robot
24 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/nsd_lib.robot
25 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/ns_lib.robot
26 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/ssh_lib.robot
27 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/openstack_lib.robot
28
29 Force Tags   heal_03   cluster_heal   daily
30
31
32 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
33
34
35 *** Variables ***
36 # NS and VNF descriptor package folder and ids
37 ${vnfd_volumes_pkg}   several_volumes_vnf
38 ${vnfd_volumes_name}   several_volumes-vnf
39 ${vdu_volumes_name}   several_volumes-VM
40 ${vnf_several_index}   several_volumes_vnf
41 ${vnfd_charm_pkg}   charm-packages/native_manual_scale_charm_vnf
42 ${vnfd_charm_name}   native_manual_scale_charm-vnf
43 ${vdu_charm_name}   mgmtVM
44 ${vnf_charm_index}   charm_vnf
45 ${vnf_charm_scaling_group}   manual-scaling_mgmtVM
46 ${vnf_charm_cloudinit_file}   /root/helloworld.txt
47 ${vnf_charm_day1_file}   /home/ubuntu/first-touch
48 ${nsd_pkg}   volumes_nativecharm_ns
49 ${nsd_name}   volumes_nativecharm-ns
50
51 # NS instance name and configuration
52 ${ns_name}   heal_03
53 ${ns_config}   {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}} ] }
54 ${ns_timeout}   6min
55 ${scale_wait_time}   5min
56
57 # SSH keys and username to be used
58 ${publickey}   %{HOME}/.ssh/id_rsa.pub
59 ${privatekey}   %{HOME}/.ssh/id_rsa
60 ${username}   ubuntu
61 ${password}   ${EMPTY}
62
63 ${success_return_code}   0
64
65 @{vim_vdus}   @{EMPTY}
66 @{vim_volumes}   @{EMPTY}
67
68
69 *** Test Cases ***
70 Create VNF Descriptors
71     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_charm_pkg}'
72     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_volumes_pkg}'
73
74
75 Create NS Descriptor
76     Create NSD   '%{PACKAGES_FOLDER}/${nsd_pkg}'
77
78
79 Network Service Instance Test
80     ${id}=   Create Network Service   ${nsd_name}   %{VIM_TARGET}   ${ns_name}   ${ns_config}   ${publickey}   ${ns_timeout}
81     Set Suite Variable   ${ns_id}   ${id}
82
83
84 Get NS Id
85     [Tags]   cleanup
86     ${variables}   Get Variables
87     IF   not "\${ns_id}" in "${variables}"
88         ${id}=   Get Ns Id   ${ns_name}
89         Set Suite Variable   ${ns_id}   ${id}
90     END
91
92
93 Scale Out Charm VNF
94     ${vnf_id}=   Get Vnf Id   ${ns_id}   ${vnf_charm_index}
95     Set Suite Variable   ${vnf_charm_id}   ${vnf_id}
96     @{vdur_list}=   Get Vnf Vdur Names   ${vnf_charm_id}
97     ${vdurs}=   Get Length   ${vdur_list}
98     Set Suite Variable   ${initial_vdur_count}   ${vdurs}
99     Execute Manual VNF Scale   ${ns_name}   ${vnf_charm_index}   ${vnf_charm_scaling_group}   SCALE_OUT   ${scale_wait_time}
100     @{vdur_list}=   Get Vnf Vdur Names   ${vnf_charm_id}
101     ${vdurs}=   Get Length   ${vdur_list}
102     Run Keyword If   ${vdurs} != ${initial_vdur_count} + 1   Fail   msg=There is no new VDU records in the VNF after Scale Out
103
104
105 Get VIM Objects
106     Variable Should Exist   ${ns_id}   msg=NS is not available
107     @{vnf_id_list}=   Get Ns Vnf List   ${ns_id}
108     Log   ${vnf_id_list}
109     FOR   ${vnf_id}   IN   @{vnf_id_list}
110         Log   ${vnf_id}
111         ${id}=   Get VNF VIM ID   ${vnf_id}
112         @{vdu_ids}=   Split String   ${id}
113         Append To List   ${vim_vdus}   @{vdu_ids}
114     END
115     FOR   ${vdu_id}   IN   @{vim_vdus}
116         ${volumes_attached}=   Get Server Property   ${vdu_id}   volumes_attached
117         ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
118         IF   ${match} != @{EMPTY}
119             IF   not "${match}[0]" in "@{vim_volumes}"
120                 Append To List   ${vim_volumes}   ${match}[0]
121             END
122         END
123     END
124     Log Many   @{vim_vdus}
125     Log Many   @{vim_volumes}
126
127
128 Get Charm VNF Info
129     Variable Should Exist   ${ns_id}   msg=NS is not available
130     ${variables}   Get Variables
131     IF   not "\${vnf_charm_id}" in "${variables}"
132         ${vnf_id}=   Get Vnf Id   ${ns_id}   ${vnf_charm_index}
133         Set Suite Variable   ${vnf_charm_id}   ${vnf_id}
134     END
135     ${id}=   Get VNF VIM ID   ${vnf_charm_id}
136     @{vdu_charm_ids}=   Split String   ${id}
137     Set Suite Variable   @{vdu_charm_ids}   @{vdu_charm_ids}
138     Log   ${vdu_charm_ids}[1]
139     @{charm_ip_list}=   Get Vnf Vdur IPs   ${vnf_charm_id}
140     Set Suite Variable   @{charm_ip_list}   @{charm_ip_list}
141
142
143 Get Volume VNF Info
144     Variable Should Exist   ${ns_id}   msg=NS is not available
145     ${ip_addr}=   Get Vnf Management Ip Address   ${ns_id}   ${vnf_several_index}
146     Log   ${ip_addr}
147     Set Suite Variable   ${vnf_volumes_ip_addr}   ${ip_addr}
148
149     ${vnf_id}=   Get Vnf Id   ${ns_id}   ${vnf_several_index}
150     Set Suite Variable   ${vnf_volumes_id}   ${vnf_id}
151     ${id}=   Get VNF VIM ID   ${vnf_id}
152     Set Suite Variable   ${vdu_volumes_id}   ${id}
153     Log   ${vdu_volumes_id}
154
155     @{volumes_ip_list}=   Get Vnf Vdur IPs   ${vnf_volumes_id}
156     Set Suite Variable   @{volumes_ip_list}   @{volumes_ip_list}
157     Log   @{volumes_ip_list}
158
159
160 Stop VDUs
161     Variable Should Exist   @{vdu_charm_ids}   msg=Charm VDUs are not available
162     Variable Should Exist   ${vdu_volumes_id}   msg=Volume VDU is not available
163     Stop Server   ${vdu_charm_ids}[1]
164     Stop Server   ${vdu_charm_ids}[2]
165     Stop Server   ${vdu_volumes_id}
166     Sleep   30
167
168
169 Heal VDUs
170     Variable Should Exist   ${vnf_charm_id}   msg=Charm VNF is not available
171     Variable Should Exist   ${vnf_volumes_id}   msg=Volume VNF is not available
172     Heal Network Service   ${ns_id}   --vnf ${vnf_volumes_id} --cause "Heal myvdu1 of several_volumes_vnf" --vdu several_volumes-VM --vnf ${vnf_charm_id} --cause "Heal two VMs of native_manual_scale_charm_vnf" --vdu mgmtVM --count-index 1 --run-day1 --vdu mgmtVM --count-index 2
173
174
175 Check VNFs After Healing
176     Variable Should Exist   ${vnf_charm_id}   msg=Charm VNF is not available
177     Variable Should Exist   ${vnf_volumes_id}   msg=Volume VNF is not available
178     ${id}=   Get VNF VIM ID   ${vnf_charm_id}
179     @{ids}=   Split String   ${id}
180     Should Be Equal   ${vdu_charm_ids}[0]   ${ids}[0]   VDU[0] id has changed after healing
181     Should Not Be Equal   ${vdu_charm_ids}[1]   ${ids}[1]   VDU[1] id has not changed after healing
182     Should Not Be Equal   ${vdu_charm_ids}[2]   ${ids}[2]   VDU[2] id has not changed after healing
183
184     ${id}=   Get VNF VIM ID   ${vnf_volumes_id}
185     Should Not Be Equal   ${id}   ${vdu_volumes_id}   VDU id has not changed after healing
186
187     ${ip}=   Get Vdu Attribute   ${vnf_charm_id}   ip-address   1
188     ${stdout}=   Execute Remote Command Check Rc Return Output   ${ip}   ${username}   ${password}   ${privatekey}   sudo ls ${vnf_charm_cloudinit_file}
189     Log   ${stdout}
190     Check If remote File Exists   ${ip}   ${username}   ${password}   ${privatekey}   ${vnf_charm_day1_file}
191
192
193 Update VIM Objects
194     Variable Should Exist   ${ns_id}   msg=NS is not available
195     @{vdu_updated}=   Create List
196     @{vnf_id_list}=   Get Ns Vnf List   ${ns_id}
197     FOR   ${vnf_id}   IN   @{vnf_id_list}
198         ${id}=   Get VNF VIM ID   ${vnf_id}
199         @{vdu_ids}=   Split String   ${id}
200         Append To List   ${vdu_updated}   @{vdu_ids}
201         FOR   ${id}   IN   @{vdu_ids}
202             IF   not "${id}" in "@{vim_vdus}"
203                 Append To List   ${vim_vdus}   ${id}
204             END
205         END
206     END
207     FOR   ${vdu_id}   IN   @{vdu_updated}
208         ${volumes_attached}=   Get Server Property   ${vdu_id}   volumes_attached
209         ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
210         IF   ${match} != @{EMPTY}
211             IF   not "${match}[0]" in "@{vim_volumes}"
212                 Append To List   ${vim_volumes}   ${match}[0]
213             END
214         END
215     END
216     Log Many   @{vim_vdus}
217     Log Many   @{vim_volumes}
218
219
220 Delete NS Instance
221     [Tags]   cleanup
222     Delete NS   ${ns_name}
223
224
225 Delete NS Descriptor
226     [Tags]   cleanup
227     Delete NSD   ${nsd_name}
228
229
230 Delete VNF Descriptors
231     [Tags]   cleanup
232     Delete VNFD   ${vnfd_volumes_name}
233     Delete VNFD   ${vnfd_charm_name}
234
235
236 Delete Objects in VIM
237     [Tags]   cleanup
238     ${error}=   Set Variable   0
239     FOR   ${vol_id}   IN   @{vim_volumes}
240         Log   Checking if volume ${vol_id} is still in VIM
241         ${exists}=   Check If Volume Exists   ${vol_id}
242         IF   ${exists}!=0
243             ${error}=   Set Variable   1
244             Log   Deleting volume ${vol_id}
245             Run Keyword And Ignore Error   Delete Volume   ${vol_id}
246         END
247     END
248     FOR   ${vdu_id}   IN   @{vim_vdus}
249         Log   Checking if server ${vdu_id} is still in VIM
250         ${status}=   Run Keyword And Ignore Error   Get Server Property   ${vdu_id}   id
251         Log   ${status}[0]
252         IF   '${status}[0]' == 'PASS'
253             ${error}=   Set Variable   1
254             Log   Deleting server ${vdu_id}
255             Run Keyword And Ignore Error   Delete Server   ${vdu_id}
256         END
257     END
258     IF   ${error}==1
259         Fail   Some objects created by test were not deleted in VIM
260     END
261
262
263 *** Keywords ***
264 Suite Cleanup
265     [Documentation]   Test Suit Cleanup: Deleting Descriptor, instance and vim
266
267     Run Keyword If Any Tests Failed   Delete NS   ${ns_name}
268     Run Keyword If Any Tests Failed   Delete NSD   ${nsd_name}
269     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_volumes_name}
270     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_charm_name}