Update README.md with instructions to run tests using testing-daily images
[osm/tests.git] / robot-systest / testsuite / heal_02-scale_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-02] Healing of scaled charm 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_02   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 ${flavor_name}   osm.heal_02
53 ${ns_name}   heal_02
54 ${scale_wait_time}   4min
55
56 # SSH keys and username to be used
57 ${publickey}   %{HOME}/.ssh/id_rsa.pub
58 ${privatekey}   %{HOME}/.ssh/id_rsa
59 ${username}   ubuntu
60 ${password}   ${EMPTY}
61
62 ${success_return_code}   0
63
64 @{vim_vdus}   @{EMPTY}
65 @{vim_volumes}   @{EMPTY}
66
67
68 *** Test Cases ***
69 Create VNF Descriptors
70     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_charm_pkg}'
71     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_volumes_pkg}'
72
73
74 Create NS Descriptor
75     Create NSD   '%{PACKAGES_FOLDER}/${nsd_pkg}'
76
77
78 Create Test Flavor
79     ${id}=   Create Flavor   ${flavor_name}
80     Set Suite Variable   ${flavor_id}   ${id}
81
82
83 Network Service Instance Test
84     ${ns_config}=   Set Variable   {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}}],vnf: [ {member-vnf-index: charm_vnf, vdu: [{ id: mgmtVM, vim-flavor-id: ${flavor_id}}]}] }
85     ${id}=   Create Network Service   ${nsd_name}   %{VIM_TARGET}   ${ns_name}   ${ns_config}   ${publickey}
86     Set Suite Variable   ${ns_id}   ${id}
87
88
89 Get NS Id
90     [Tags]   cleanup
91     ${variables}   Get Variables
92     IF   not "\${ns_id}" in "${variables}"
93         ${id}=   Get Ns Id   ${ns_name}
94         Set Suite Variable   ${ns_id}   ${id}
95     END
96
97
98 Scale Out Charm VNF
99     ${vnf_id}=   Get Vnf Id   ${ns_id}   ${vnf_charm_index}
100     Set Suite Variable   ${vnf_charm_id}   ${vnf_id}
101     @{vdur_list}=   Get Vnf Vdur Names   ${vnf_charm_id}
102     ${vdurs}=   Get Length   ${vdur_list}
103     Set Suite Variable   ${initial_vdur_count}   ${vdurs}
104     Execute Manual VNF Scale   ${ns_name}   ${vnf_charm_index}   ${vnf_charm_scaling_group}   SCALE_OUT   ${scale_wait_time}
105     @{vdur_list}=   Get Vnf Vdur Names   ${vnf_charm_id}
106     ${vdurs}=   Get Length   ${vdur_list}
107     Run Keyword If   ${vdurs} != ${initial_vdur_count} + 1   Fail   msg=There is no new VDU records in the VNF after Scale Out
108
109
110 Get VIM Objects
111     Variable Should Exist   ${ns_id}   msg=NS is not available
112     @{vnf_id_list}=   Get Ns Vnf List   ${ns_id}
113     Log   ${vnf_id_list}
114     FOR   ${vnf_id}   IN   @{vnf_id_list}
115         Log   ${vnf_id}
116         ${id}=   Get VNF VIM ID   ${vnf_id}
117         @{vdu_ids}=   Split String   ${id}
118         Append To List   ${vim_vdus}   @{vdu_ids}
119     END
120     FOR   ${vdu_id}   IN   @{vim_vdus}
121         ${volumes_attached}=   Get Server Property   ${vdu_id}   volumes_attached
122         ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
123         IF   ${match} != @{EMPTY}
124             IF   not "${match}[0]" in "@{vim_volumes}"
125                 Append To List   ${vim_volumes}   ${match}[0]
126             END
127         END
128     END
129     Log Many   @{vim_vdus}
130     Log Many   @{vim_volumes}
131
132
133 Get Charm VNF Info
134     Variable Should Exist   ${ns_id}   msg=NS is not available
135     ${variables}   Get Variables
136     IF   not "\${vnf_charm_id}" in "${variables}"
137         ${vnf_id}=   Get Vnf Id   ${ns_id}   ${vnf_charm_index}
138         Set Suite Variable   ${vnf_charm_id}   ${vnf_id}
139     END
140     ${id}=   Get VNF VIM ID   ${vnf_charm_id}
141     @{vdu_charm_ids}=   Split String   ${id}
142     Set Suite Variable   @{vdu_charm_ids}   @{vdu_charm_ids}
143     Log   ${vdu_charm_ids}[1]
144     @{charm_ip_list}=   Get Vnf Vdur IPs   ${vnf_charm_id}
145     Set Suite Variable   @{charm_ip_list}   @{charm_ip_list}
146
147
148 Halt Charm VDU
149     Variable Should Exist   @{vdu_charm_ids}   msg=VDU is not available
150     Halt Server   ${vdu_charm_ids}[1]
151     Sleep   15
152
153
154 Heal Charm VDU
155     Variable Should Exist   ${vnf_charm_id}   msg=VNF is not available
156     Heal Network Service   ${ns_id}   --vnf ${vnf_charm_id} --cause "Heal VM of charm_vnf" --vdu ${vdu_charm_name} --count-index 1 --run-day1
157
158
159 Check VNF After Healing
160     Variable Should Exist   ${vnf_charm_id}   msg=VNF is not available
161
162     @{ip_list}=   Get Vnf Vdur IPs   ${vnf_charm_id}
163     Should Be Equal   ${ip_list}   ${charm_ip_list}   IP addresses have changed after healing
164
165     ${id}=   Get VNF VIM ID   ${vnf_charm_id}
166     @{ids}=   Split String   ${id}
167     Should Be Equal   ${vdu_charm_ids}[0]   ${ids}[0]   VDU[0] id has changed after healing
168     Should Not Be Equal   ${vdu_charm_ids}[1]   ${ids}[1]   VDU[1] id has not changed after healing
169     Should Be Equal   ${vdu_charm_ids}[2]   ${ids}[2]   VDU[2] id has changed after healing
170
171     ${ip}=   Get Vdu Attribute   ${vnf_charm_id}   ip-address   1
172     ${stdout}=   Execute Remote Command Check Rc Return Output   ${ip}   ${username}   ${password}   ${privatekey}   sudo ls ${vnf_charm_cloudinit_file}
173     Log   ${stdout}
174     Check If remote File Exists   ${ip}   ${username}   ${password}   ${privatekey}   ${vnf_charm_day1_file}
175     ${vim_info}=   Get Vdu Attribute   ${vnf_charm_id}   vim_info
176     Should Contain   ${vim_info}   flavor: {id: ${flavor_id},   msg=Flavor ID is incorrect
177
178
179 Update VIM Objects
180     Variable Should Exist   ${ns_id}   msg=NS is not available
181     @{vdu_updated}=   Create List
182     @{vnf_id_list}=   Get Ns Vnf List   ${ns_id}
183     FOR   ${vnf_id}   IN   @{vnf_id_list}
184         ${id}=   Get VNF VIM ID   ${vnf_id}
185         @{vdu_ids}=   Split String   ${id}
186         Append To List   ${vdu_updated}   @{vdu_ids}
187         FOR   ${id}   IN   @{vdu_ids}
188             IF   not "${id}" in "@{vim_vdus}"
189                 Append To List   ${vim_vdus}   ${id}
190             END
191         END
192     END
193     FOR   ${vdu_id}   IN   @{vdu_updated}
194         ${volumes_attached}=   Get Server Property   ${vdu_id}   volumes_attached
195         ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
196         IF   ${match} != @{EMPTY}
197             IF   not "${match}[0]" in "@{vim_volumes}"
198                 Append To List   ${vim_volumes}   ${match}[0]
199             END
200         END
201     END
202     Log Many   @{vim_vdus}
203     Log Many   @{vim_volumes}
204
205
206 Delete NS Instance
207     [Tags]   cleanup
208     Delete NS   ${ns_name}
209
210
211 Delete NS Descriptor
212     [Tags]   cleanup
213     Delete NSD   ${nsd_name}
214
215
216 Delete VNF Descriptors
217     [Tags]   cleanup
218     Delete VNFD   ${vnfd_volumes_name}
219     Delete VNFD   ${vnfd_charm_name}
220
221
222 Delete Objects in VIM
223     [Tags]   cleanup
224     ${error}=   Set Variable   0
225     FOR   ${vol_id}   IN   @{vim_volumes}
226         Log   Checking if volume ${vol_id} is still in VIM
227         ${exists}=   Check If Volume Exists   ${vol_id}
228         IF   ${exists}!=0
229             ${error}=   Set Variable   1
230             Log   Deleting volume ${vol_id}
231             Run Keyword And Ignore Error   Delete Volume   ${vol_id}
232         END
233     END
234     FOR   ${vdu_id}   IN   @{vim_vdus}
235         Log   Checking if server ${vdu_id} is still in VIM
236         ${status}=   Run Keyword And Ignore Error   Get Server Property   ${vdu_id}   id
237         Log   ${status}[0]
238         IF   '${status}[0]' == 'PASS'
239             ${error}=   Set Variable   1
240             Log   Deleting server ${vdu_id}
241             Run Keyword And Ignore Error   Delete Server   ${vdu_id}
242         END
243     END
244     IF   ${error}==1
245         Fail   Some objects created by test were not deleted in VIM
246     END
247
248
249 Delete flavor
250     Delete Flavor   ${flavor_id}
251
252
253 *** Keywords ***
254 Suite Cleanup
255     [Documentation]   Test Suit Cleanup: Deleting Descriptor, instance and vim
256
257     Run Keyword If Any Tests Failed   Delete NS   ${ns_name}
258     Run Keyword If Any Tests Failed   Delete NSD   ${nsd_name}
259     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_volumes_name}
260     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_charm_name}
261     Run Keyword If Any Tests Failed   Delete Objects in VIM
262     Run Keyword If Any Tests Failed   Delete Flavor   ${flavor_id}