Add purging of objects in VIM on exit in healing tests
[osm/tests.git] / robot-systest / testsuite / heal_01-volume_vdu_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-01] Healing of a multi-volume VDU
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_01   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 ${nsd_pkg}   volumes_nativecharm_ns
44 ${nsd_name}   volumes_nativecharm-ns
45
46 # NS instance name and configuration
47 ${ns_name}   heal_01
48 ${ns_config}   {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}} ] }
49
50 # SSH keys and username to be used
51 ${publickey}   %{HOME}/.ssh/id_rsa.pub
52 ${privatekey}   %{HOME}/.ssh/id_rsa
53 ${username}   ubuntu
54 ${password}   ${EMPTY}
55
56 ${success_return_code}   0
57
58 @{vim_vdus}   @{EMPTY}
59 @{vim_volumes}   @{EMPTY}
60
61
62 *** Test Cases ***
63 Create VNF Descriptors
64     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_charm_pkg}'
65     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_volumes_pkg}'
66
67
68 Create NS Descriptor
69     Create NSD   '%{PACKAGES_FOLDER}/${nsd_pkg}'
70
71
72 Network Service Instance Test
73     ${id}=   Create Network Service   ${nsd_name}   %{VIM_TARGET}   ${ns_name}   ${ns_config}   ${publickey}
74     Set Suite Variable   ${ns_id}   ${id}
75
76
77 Get NS Id
78     [Tags]   cleanup
79     ${variables}   Get Variables
80     IF   not "\${ns_id}" in "${variables}"
81         ${id}=   Get Ns Id   ${ns_name}
82         Set Suite Variable   ${ns_id}   ${id}
83     END
84
85
86 Get VIM Objects
87     Variable Should Exist   ${ns_id}   msg=NS is not available
88     @{vnf_id_list}=   Get Ns Vnf List   ${ns_id}
89     log   ${vnf_id_list}
90     FOR   ${vnf_id}   IN   @{vnf_id_list}
91         log   ${vnf_id}
92         ${id}=   Get VNF VIM ID   ${vnf_id}
93         @{vdu_ids}=   Split String   ${id}
94         Append To List   ${vim_vdus}   @{vdu_ids}
95     END
96     FOR   ${vdu_id}   IN   @{vim_vdus}
97         ${volumes_attached}=   Get Server Property   ${vdu_id}   volumes_attached
98         ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
99         IF   ${match} != @{EMPTY}
100             IF   not "${match}[0]" in "@{vim_volumes}"
101                 Append To List   ${vim_volumes}   ${match}[0]
102             END
103         END
104     END
105     log Many   @{vim_vdus}
106     log Many   @{vim_volumes}
107
108
109 Get Volume VNF Info
110     Variable Should Exist   ${ns_id}   msg=NS is not available
111     ${ip_addr}=   Get Vnf Management Ip Address   ${ns_id}   ${vnf_several_index}
112     log   ${ip_addr}
113     Set Suite Variable   ${vnf_volumes_ip_addr}   ${ip_addr}
114
115     ${vnf_id}=   Get Vnf Id   ${ns_id}   ${vnf_several_index}
116     Set Suite Variable   ${vnf_volumes_id}   ${vnf_id}
117     ${id}=   Get VNF VIM ID   ${vnf_id}
118     Set Suite Variable   ${vdu_volumes_id}   ${id}
119     log   ${vdu_volumes_id}
120
121     @{volumes_ip_list}=   Get Vnf Vdur IPs   ${vnf_volumes_id}
122     Set Suite Variable   @{volumes_ip_list}   @{volumes_ip_list}
123     log   @{volumes_ip_list}
124
125
126 Get Volumes Info
127     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnfpkg-show ${vnfd_volumes_name} --literal | yq '.vdu[0]."virtual-storage-desc" | length'
128     Should Be Equal As Integers   ${rc}   ${success_return_code}   msg=${stdout}   values=False
129     ${num_virtual_storage}=   Convert To Integer   ${stdout}
130     Set Suite Variable   ${vnf_num_volumes}   ${num_virtual_storage}
131     log   ${vnf_num_volumes}
132     ${volumes_attached}=   Get Server Property   ${vdu_volumes_id}   volumes_attached
133     ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
134     Set Suite Variable   ${volume_id}   ${match}[0]
135
136
137 Check VDU Disks
138     Variable Should Exist   ${vnf_volumes_ip_addr}   msg=VNF is not available
139     Sleep   20 seconds   Wait for SSH daemon to be up
140     ${stdout}=   Execute Remote Command Check Rc Return Output   ${vnf_volumes_ip_addr}   ${username}   ${password}   ${privatekey}   sudo lsblk -l
141     log   ${stdout}
142     ${lines}=   Get Lines Containing String   ${stdout}   disk
143     ${num_lines}=   Get Line Count   ${lines}
144     Run Keyword If   ${num_lines} < ${vnf_num_volumes}   Fail   msg=Number of disks (${num_lines}) is less than specified in VDU (${vnf_num_volumes})
145
146
147 Delete Persistent Volume VDU
148     Variable Should Exist   ${vdu_volumes_id}   msg=VDU is not available
149     Delete Server   ${vdu_volumes_id}
150     Sleep   20
151
152
153 Heal Persistent Volume VDU
154     Variable Should Exist   ${vnf_volumes_id}   msg=VNF is not available
155     Heal Network Service   ${ns_id}   --vnf ${vnf_volumes_id} --cause "Heal VM of volumes_vnf" --vdu ${vdu_volumes_name}
156
157
158 Check VNF After Healing
159     Variable Should Exist   ${vnf_volumes_id}   msg=VNF is not available
160
161     @{ip_list}=   Get Vnf Vdur IPs   ${vnf_volumes_id}
162     log   @{ip_list}
163     Should Be Equal   ${ip_list}   ${volumes_ip_list}   IP addresses have changed after healing
164
165     ${id}=   Get VNF VIM ID   ${vnf_volumes_id}
166     log   ${id}
167     Should Not Be Equal   ${id}   ${vdu_volumes_id}   VDU id has not changed after healing
168
169     ${volumes_attached}=   Get Server Property   ${id}   volumes_attached
170     ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
171     Should Be Equal   ${match}[0]   ${volume_id}   Volume id has changed after healing
172
173     Sleep   30 seconds   Wait for SSH daemon to be up
174     ${stdout}=   Execute Remote Command Check Rc Return Output   ${vnf_volumes_ip_addr}   ${username}   ${password}   ${privatekey}   sudo lsblk -l
175     log   ${stdout}
176     ${lines}=   Get Lines Containing String   ${stdout}   disk
177     ${num_lines}=   Get Line Count   ${lines}
178     Run Keyword If   ${num_lines} < ${vnf_num_volumes}   Fail   msg=Number of disks (${num_lines}) is less than specified in VDU (${vnf_num_volumes})
179
180
181 Update VIM Objects
182     Variable Should Exist   ${ns_id}   msg=NS is not available
183     @{vdu_updated}=   Create List
184     @{vnf_id_list}=   Get Ns Vnf List   ${ns_id}
185     FOR   ${vnf_id}   IN   @{vnf_id_list}
186         ${id}=   Get VNF VIM ID   ${vnf_id}
187         @{vdu_ids}=   Split String   ${id}
188         Append To List   ${vdu_updated}   @{vdu_ids}
189         FOR   ${id}   IN   @{vdu_ids}
190             IF   not "${id}" in "@{vim_vdus}"
191                 Append To List   ${vim_vdus}   ${id}
192             END
193         END
194     END
195     FOR   ${vdu_id}   IN   @{vdu_updated}
196         ${volumes_attached}=   Get Server Property   ${vdu_id}   volumes_attached
197         ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
198         IF   ${match} != @{EMPTY}
199             IF   not "${match}[0]" in "@{vim_volumes}"
200                 Append To List   ${vim_volumes}   ${match}[0]
201             END
202         END
203     END
204     log Many   @{vim_vdus}
205     log Many   @{vim_volumes}
206
207
208 Delete NS Instance
209     [Tags]   cleanup
210     Delete NS   ${ns_name}
211
212
213 Delete NS Descriptor
214     [Tags]   cleanup
215     Delete NSD   ${nsd_name}
216
217
218 Delete VNF Descriptors
219     [Tags]   cleanup
220     Delete VNFD   ${vnfd_volumes_name}
221     Delete VNFD   ${vnfd_charm_name}
222
223
224 Delete Objects in VIM
225     [Tags]   cleanup
226     ${error}=   Set Variable   0
227     FOR   ${vol_id}   IN   @{vim_volumes}
228         log   Checking if volume ${vol_id} is still in VIM
229         ${exists}=   Check If Volume Exists   ${vol_id}
230         IF   ${exists}!=0
231             ${error}=   Set Variable   1
232             log   Deleting volume ${vol_id}
233             Run Keyword And Ignore Error   Delete Volume   ${vol_id}
234         END
235     END
236     FOR   ${vdu_id}   IN   @{vim_vdus}
237         log   Checking if server ${vdu_id} is still in VIM
238         ${status}=   Run Keyword And Ignore Error   Get Server Property   ${vdu_id}   id
239         log   ${status}[0]
240         IF   '${status}[0]' == 'PASS'
241             ${error}=   Set Variable   1
242             log   Deleting server ${vdu_id}
243             Run Keyword And Ignore Error   Delete Server   ${vdu_id}
244         END
245     END
246     IF   ${error}==1
247         Fail   Some objects created by test were not deleted in VIM
248     END
249
250
251 *** Keywords ***
252 Suite Cleanup
253     [Documentation]   Test Suit Cleanup: Deleting Descriptor, instance and vim
254
255     Run Keyword If Any Tests Failed   Delete NS   ${ns_name}
256     Run Keyword If Any Tests Failed   Delete NSD   ${nsd_name}
257     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_volumes_name}
258     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_charm_name}
259     Run Keyword If Any Tests Failed   Delete Objects in VIM