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