Update heal tests to use new NF and NS packages without charms
[osm/tests.git] / robot-systest / testsuite / heal_03-multiple_healing.robot
1 *** Comments ***
2 #   Licensed under the Apache License, Version 2.0 (the "License");
3 #   you may not use this file except in compliance with the License.
4 #   You may obtain a copy of the License at
5 #
6 #       http://www.apache.org/licenses/LICENSE-2.0
7 #
8 #   Unless required by applicable law or agreed to in writing, software
9 #   distributed under the License is distributed on an "AS IS" BASIS,
10 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 #   See the License for the specific language governing permissions and
12 #   limitations under the License.
13
14
15 *** Settings ***
16 Documentation   [HEAL-03] Healing of multiple VDUs
17
18 Library   OperatingSystem
19 Library   String
20 Library   Collections
21 Library   Process
22 Library   SSHLibrary
23
24 Resource   ../lib/vnfd_lib.resource
25 Resource   ../lib/vnf_lib.resource
26 Resource   ../lib/nsd_lib.resource
27 Resource   ../lib/ns_lib.resource
28 Resource   ../lib/ns_operation_lib.resource
29 Resource   ../lib/ssh_lib.resource
30 Resource   ../lib/openstack_lib.resource
31
32 Test Tags   heal_03   cluster_heal   daily   regression
33
34 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
35
36
37 *** Variables ***
38 # NS and VNF descriptor package folder and ids
39 ${VNFD_VOLUMES_PKG}   several_volumes_vnf
40 ${VNFD_VOLUMES_NAME}   several_volumes-vnf
41 ${VDU_VOLUMES_NAME}   several_volumes-VM
42 ${VNF_SEVERAL_INDEX}   several_volumes_vnf
43 ${VNFD_MANUALSCALE_PKG}   manual_scale_vnf
44 ${VNFD_MANUALSCALE_NAME}   manual_scale-vnf
45 ${VDU_MANUALSCALE_NAME}   mgmtVM
46 ${VNF_MANUALSCALE_INDEX}   manual_scale_vnf
47 ${VNF_MANUALSCALE_SCALING_GROUP}   manual-scaling_mgmtVM
48 ${VNF_MANUALSCALE_CLOUDINIT_FILE}   /root/helloworld.txt
49 ${VNF_MANUALSCALE_DAY1_FILE}   /home/ubuntu/first-touch
50 ${NSD_PKG}   volumes_healing_ns
51 ${NSD_NAME}   volumes_healing-ns
52
53 # NS instance name and configuration
54 ${NS_NAME}   heal_03
55 ${NS_CONFIG}   {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}} ] }
56 ${NS_TIMEOUT}   6min
57 ${SCALE_WAIT_TIME}   5min
58
59 # SSH keys and username to be used
60 ${PUBLICKEY}   %{HOME}/.ssh/id_rsa.pub
61 ${PRIVATEKEY}   %{HOME}/.ssh/id_rsa
62 ${USERNAME}   ubuntu
63 ${PASSWORD}   ${EMPTY}
64
65 ${SUCCESS_RETURN_CODE}   0
66
67 @{VIM_VDUS}   @{EMPTY}
68 @{VIM_VOLUMES}   @{EMPTY}
69
70
71 *** Test Cases ***
72 Create VNF Descriptors
73     [Documentation]   Upload VNF packages for the testsuite.
74     Create VNFD   '%{PACKAGES_FOLDER}/${VNFD_MANUALSCALE_PKG}'
75     Create VNFD   '%{PACKAGES_FOLDER}/${VNFD_VOLUMES_PKG}'
76
77 Create NS Descriptor
78     [Documentation]   Upload NS package for the testsuite.
79     Create NSD   '%{PACKAGES_FOLDER}/${NSD_PKG}'
80
81 Network Service Instance Test
82     [Documentation]   Instantiate NS for the testsuite.
83     ${id}=   Create Network Service   ${NSD_NAME}   %{VIM_TARGET}   ${NS_NAME}   ${NS_CONFIG}   ${PUBLICKEY}   ${NS_TIMEOUT}
84     Set Suite Variable   ${NS_ID}   ${id}
85
86 Get NS Id
87     [Documentation]   Get NS identifier and stores as suite variable to be used later on.
88     [Tags]   cleanup
89     ${variables}=   Get Variables
90     IF   not "\${ns_id}" in "${variables}"
91         ${id}=   Get Ns Id   ${NS_NAME}
92         Set Suite Variable   ${NS_ID}   ${id}
93     END
94
95 Scale Out Manual Scale VNF
96     [Documentation]   Perform a manual scale-out operation of the manual scale VNF.
97     ${vnf_id}=   Get Vnf Id   ${NS_ID}   ${VNF_MANUALSCALE_INDEX}
98     Set Suite Variable   ${VNF_MANUALSCALE_ID}   ${vnf_id}
99     @{vdur_list}=   Get Vnf Vdur Names   ${VNF_MANUALSCALE_ID}
100     ${vdurs}=   Get Length   ${vdur_list}
101     Set Suite Variable   ${INITIAL_VDUR_COUNT}   ${vdurs}
102     Execute Manual VNF Scale   ${NS_NAME}   ${VNF_MANUALSCALE_INDEX}   ${VNF_MANUALSCALE_SCALING_GROUP}   SCALE_OUT   ${SCALE_WAIT_TIME}
103     @{vdur_list}=   Get Vnf Vdur Names   ${VNF_MANUALSCALE_ID}
104     ${vdurs}=   Get Length   ${vdur_list}
105     IF   ${vdurs} != ${INITIAL_VDUR_COUNT} + 1   Fail   msg=There is no new VDU records in the VNF after Scale Out
106
107 Get VIM Objects
108     [Documentation]   Retrieve all VMs and volumes from the NS and stores them in VIM_VDUS and VIM_VOLUMES lists.
109     Variable Should Exist   ${NS_ID}   msg=NS is not available
110     @{vnf_id_list}=   Get Ns Vnf List   ${NS_ID}
111     Log   ${vnf_id_list}
112     FOR   ${vnf_id}   IN   @{vnf_id_list}
113         Log   ${vnf_id}
114         ${id}=   Get VNF VIM ID   ${vnf_id}
115         @{vdu_ids}=   Split String   ${id}
116         Append To List   ${VIM_VDUS}   @{vdu_ids}
117     END
118     FOR   ${vdu_id}   IN   @{VIM_VDUS}
119         ${volumes_attached}=   Get Server Property   ${vdu_id}   volumes_attached
120         ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
121         IF   ${match} != @{EMPTY}
122             IF   not "${match}[0]" in "@{VIM_VOLUMES}"
123                 Append To List   ${VIM_VOLUMES}   ${match}[0]
124             END
125         END
126     END
127     Log Many   @{VIM_VDUS}
128     Log Many   @{VIM_VOLUMES}
129
130 Get Manual Scale VNF Info
131     [Documentation]   Get VDU ID and IP addresses of the manual scale VNF and stores them in VDU_MANUALSCALE_IDS and MANUALSCALE_IP_LIST.
132     Variable Should Exist   ${NS_ID}   msg=NS is not available
133     ${variables}=   Get Variables
134     IF   not "\${VNF_MANUALSCALE_ID}" in "${variables}"
135         ${vnf_id}=   Get Vnf Id   ${NS_ID}   ${VNF_MANUALSCALE_INDEX}
136         Set Suite Variable   ${VNF_MANUALSCALE_ID}   ${vnf_id}
137     END
138     ${id}=   Get VNF VIM ID   ${VNF_MANUALSCALE_ID}
139     @{vdu_manualscale_ids}=   Split String   ${id}
140     Set Suite Variable   @{VDU_MANUALSCALE_IDS}   @{vdu_manualscale_ids}
141     Log   ${VDU_MANUALSCALE_IDS}[1]
142     @{manualscale_ip_list}=   Get Vnf Vdur IPs   ${VNF_MANUALSCALE_ID}
143     Set Suite Variable   @{MANUALSCALE_IP_LIST}   @{manualscale_ip_list}
144
145 Get Volume VNF Info
146     [Documentation]   Get info about volumes and VM of the VNF with several volumes and stores them in suite variables.
147     Variable Should Exist   ${NS_ID}   msg=NS is not available
148     ${ip_addr}=   Get Vnf Management Ip Address   ${NS_ID}   ${VNF_SEVERAL_INDEX}
149     Log   ${ip_addr}
150     Set Suite Variable   ${VNF_VOLUMES_IP_ADDR}   ${ip_addr}
151     ${vnf_id}=   Get Vnf Id   ${NS_ID}   ${VNF_SEVERAL_INDEX}
152     Set Suite Variable   ${VNF_VOLUMES_ID}   ${vnf_id}
153     ${id}=   Get VNF VIM ID   ${vnf_id}
154     Set Suite Variable   ${VDU_VOLUMES_ID}   ${id}
155     Log   ${VDU_VOLUMES_ID}
156     @{volumes_ip_list}=   Get Vnf Vdur IPs   ${VNF_VOLUMES_ID}
157     Set Suite Variable   @{VOLUMES_IP_LIST}   @{volumes_ip_list}
158     Log   @{VOLUMES_IP_LIST}
159
160 Stop VDUs
161     [Documentation]   Stop all VMs.
162     Variable Should Exist   @{VDU_MANUALSCALE_IDS}   msg=Manual Scale VDUs are not available
163     Variable Should Exist   ${VDU_VOLUMES_ID}   msg=Volume VDU is not available
164     Stop Server   ${VDU_MANUALSCALE_IDS}[1]
165     Stop Server   ${VDU_MANUALSCALE_IDS}[2]
166     Stop Server   ${VDU_VOLUMES_ID}
167     Sleep   30
168
169 Heal VDUs
170     [Documentation]   Heal manually via OSM commands all stopped VMs . They should be started again.
171     Variable Should Exist   ${VNF_MANUALSCALE_ID}   msg=Manual Scale VNF is not available
172     Variable Should Exist   ${VNF_VOLUMES_ID}   msg=Volume VNF is not available
173     Heal Network Service   ${NS_ID}   --vnf ${VNF_VOLUMES_ID} --cause "Heal myvdu1 of several_volumes_vnf" --vdu several_volumes-VM --vnf ${VNF_MANUALSCALE_ID} --cause "Heal two VMs of manual_scale_vnf" --vdu mgmtVM --count-index 1 --run-day1 --vdu mgmtVM --count-index 2
174
175 Check VNFs After Healing
176     [Documentation]   Check that the IDs of the VM and volumes have not changed after healing.
177     Variable Should Exist   ${VNF_MANUALSCALE_ID}   msg=Manual scale VNF is not available
178     Variable Should Exist   ${VNF_VOLUMES_ID}   msg=Volume VNF is not available
179     ${id}=   Get VNF VIM ID   ${VNF_MANUALSCALE_ID}
180     @{ids}=   Split String   ${id}
181     Should Be Equal   ${VDU_MANUALSCALE_IDS}[0]   ${ids}[0]   VDU[0] id has changed after healing
182     Should Not Be Equal   ${VDU_MANUALSCALE_IDS}[1]   ${ids}[1]   VDU[1] id has not changed after healing
183     Should Not Be Equal   ${VDU_MANUALSCALE_IDS}[2]   ${ids}[2]   VDU[2] id has not changed after healing
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     ${ip}=   Get Vdu Attribute   ${VNF_MANUALSCALE_ID}   ip-address   1
187     ${stdout}=   Execute Remote Command Check Rc Return Output   ${ip}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}   sudo ls ${VNF_MANUALSCALE_CLOUDINIT_FILE}
188     Log   ${stdout}
189     Check If Remote File Exists   ${ip}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}   ${VNF_MANUALSCALE_DAY1_FILE}
190
191 Update VIM Objects
192     [Documentation]   Retrieve all VMs and volumes from the NS and stores them in VIM_VDUS and VIM_VOLUMES lists.
193     ...               This is done again to guarantee that all objects are cleaned in the VIM in case the heal operation
194     ...               added new objects.
195     Variable Should Exist   ${NS_ID}   msg=NS is not available
196     @{vdu_updated}=   Create List
197     @{vnf_id_list}=   Get Ns Vnf List   ${NS_ID}
198     FOR   ${vnf_id}   IN   @{vnf_id_list}
199         ${id}=   Get VNF VIM ID   ${vnf_id}
200         @{vdu_ids}=   Split String   ${id}
201         Append To List   ${vdu_updated}   @{vdu_ids}
202         FOR   ${id}   IN   @{vdu_ids}
203             IF   not "${id}" in "@{VIM_VDUS}"
204                 Append To List   ${VIM_VDUS}   ${id}
205             END
206         END
207     END
208     FOR   ${vdu_id}   IN   @{vdu_updated}
209         ${volumes_attached}=   Get Server Property   ${vdu_id}   volumes_attached
210         ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
211         IF   ${match} != @{EMPTY}
212             IF   not "${match}[0]" in "@{VIM_VOLUMES}"
213                 Append To List   ${VIM_VOLUMES}   ${match}[0]
214             END
215         END
216     END
217     Log Many   @{VIM_VDUS}
218     Log Many   @{VIM_VOLUMES}
219
220 Delete NS Instance
221     [Documentation]   Delete NS instance.
222     [Tags]   cleanup
223     Delete NS   ${NS_NAME}
224
225 Delete NS Descriptor
226     [Documentation]   Delete NS package from OSM.
227     [Tags]   cleanup
228     Delete NSD   ${NSD_NAME}
229
230 Delete VNF Descriptors
231     [Documentation]   Delete VNF packages from OSM.
232     [Tags]   cleanup
233     Delete VNFD   ${VNFD_VOLUMES_NAME}
234     Delete VNFD   ${VNFD_MANUALSCALE_NAME}
235
236 Delete Objects In VIM
237     [Documentation]   Delete any remaining objects (volumes, VMs, etc.) in the VIM.
238     [Tags]   cleanup
239     ${error}=   Set Variable   0
240     FOR   ${vol_id}   IN   @{VIM_VOLUMES}
241         Log   Checking if volume ${vol_id} is still in VIM
242         ${exists}=   Check If Volume Exists   ${vol_id}
243         IF   ${exists}
244             ${error}=   Set Variable   1
245             Log   Deleting volume ${vol_id}
246             Run Keyword And Ignore Error   Delete Volume   ${vol_id}
247         END
248     END
249     FOR   ${vdu_id}   IN   @{VIM_VDUS}
250         Log   Checking if server ${vdu_id} is still in VIM
251         ${status}=   Run Keyword And Ignore Error   Get Server Property   ${vdu_id}   id
252         Log   ${status}[0]
253         IF   '${status}[0]' == 'PASS'
254             ${error}=   Set Variable   1
255             Log   Deleting server ${vdu_id}
256             Run Keyword And Ignore Error   Delete Server   ${vdu_id}
257         END
258     END
259     IF   ${error}==1
260         Fail   Some objects created by test were not deleted in VIM
261     END
262
263
264 *** Keywords ***
265 Suite Cleanup
266     [Documentation]   Test Suit Cleanup: Deleting Descriptor, instance and vim
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_MANUALSCALE_NAME}