Bug 2327 fix to verify ipaddress in sol003_02 testsuite
[osm/tests.git] / robot-systest / testsuite / heal_02-scale_vdu_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-02] Healing of scaled 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_02   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 ${FLAVOR_NAME_PREFIX}   osm.heal02
55 ${NS_NAME}   heal_02
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 Create Test Flavor
82     [Documentation]   Create a flavor that will be used at NS instantiation time and save it as FLAVOR_ID.
83     ${rand}=   Generate Random String   6   [NUMBERS]
84     ${flavor_name}=   Catenate   SEPARATOR=_   ${FLAVOR_NAME_PREFIX}   ${rand}
85     ${id}=   Create Flavor   ${flavor_name}   1   1024   10
86     Set Suite Variable   ${FLAVOR_ID}   ${id}
87
88 Network Service Instance Test
89     [Documentation]   Instantiate NS for the testsuite using the previously created flavor.
90     ${ns_config}=   Set Variable   {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}}],vnf: [ {member-vnf-index: manual_scale_vnf, vdu: [{ id: mgmtVM, vim-flavor-id: ${FLAVOR_ID}}]}] }
91     ${id}=   Create Network Service   ${NSD_NAME}   %{VIM_TARGET}   ${NS_NAME}   ${ns_config}   ${PUBLICKEY}   ${NS_TIMEOUT}
92     Set Suite Variable   ${NS_ID}   ${id}
93
94 Get NS Id
95     [Documentation]   Get NS identifier.
96     [Tags]   cleanup
97     ${variables}=   Get Variables
98     IF   not "\${ns_id}" in "${variables}"
99         ${id}=   Get Ns Id   ${NS_NAME}
100         Set Suite Variable   ${NS_ID}   ${id}
101     END
102
103 Scale Out Manual Scale VNF
104     [Documentation]   Perform a manual scale-out operation of the manual-scale VNF.
105     ${vnf_id}=   Get Vnf Id   ${NS_ID}   ${VNF_MANUALSCALE_INDEX}
106     Set Suite Variable   ${VNF_MANUALSCALE_ID}   ${vnf_id}
107     @{vdur_list}=   Get Vnf Vdur Names   ${VNF_MANUALSCALE_ID}
108     ${vdurs}=   Get Length   ${vdur_list}
109     Set Suite Variable   ${INITIAL_VDUR_COUNT}   ${vdurs}
110     Execute Manual VNF Scale   ${NS_NAME}   ${VNF_MANUALSCALE_INDEX}   ${VNF_MANUALSCALE_SCALING_GROUP}   SCALE_OUT   ${SCALE_WAIT_TIME}
111     @{vdur_list}=   Get Vnf Vdur Names   ${VNF_MANUALSCALE_ID}
112     ${vdurs}=   Get Length   ${vdur_list}
113     IF   ${vdurs} != ${INITIAL_VDUR_COUNT} + 1   Fail   msg=There is no new VDU records in the VNF after Scale Out
114
115 Get VIM Objects
116     [Documentation]   Retrieve all VMs and volumes from the NS and stores them in VIM_VDUS and VIM_VOLUMES lists.
117     Variable Should Exist   ${NS_ID}   msg=NS is not available
118     @{vnf_id_list}=   Get Ns Vnf List   ${NS_ID}
119     Log   ${vnf_id_list}
120     FOR   ${vnf_id}   IN   @{vnf_id_list}
121         Log   ${vnf_id}
122         ${id}=   Get VNF VIM ID   ${vnf_id}
123         @{vdu_ids}=   Split String   ${id}
124         Append To List   ${VIM_VDUS}   @{vdu_ids}
125     END
126     FOR   ${vdu_id}   IN   @{VIM_VDUS}
127         ${volumes_attached}=   Get Server Property   ${vdu_id}   volumes_attached
128         ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
129         IF   ${match} != @{EMPTY}
130             IF   not "${match}[0]" in "@{VIM_VOLUMES}"
131                 Append To List   ${VIM_VOLUMES}   ${match}[0]
132             END
133         END
134     END
135     Log Many   @{VIM_VDUS}
136     Log Many   @{VIM_VOLUMES}
137
138 Get Manual Scale VNF Info
139     [Documentation]   Get VDU ID and IP addresses of the manual scale VNF and stores them in VDU_MANUALSCALE_IDS and MANUALSCALE_IP_LIST.
140     Variable Should Exist   ${NS_ID}   msg=NS is not available
141     ${variables}=   Get Variables
142     IF   not "\${VNF_MANUALSCALE_ID}" in "${variables}"
143         ${vnf_id}=   Get Vnf Id   ${NS_ID}   ${VNF_MANUALSCALE_INDEX}
144         Set Suite Variable   ${VNF_MANUALSCALE_ID}   ${vnf_id}
145     END
146     ${id}=   Get VNF VIM ID   ${VNF_MANUALSCALE_ID}
147     @{vdu_manualscale_ids}=   Split String   ${id}
148     Set Suite Variable   @{VDU_MANUALSCALE_IDS}   @{vdu_manualscale_ids}
149     Log   ${VDU_MANUALSCALE_IDS}[1]
150     @{manualscale_ip_list}=   Get Vnf Vdur IPs   ${VNF_MANUALSCALE_ID}
151     Set Suite Variable   @{MANUALSCALE_IP_LIST}   @{manualscale_ip_list}
152
153 Halt Manual Scale VDU
154     [Documentation]   Halt one of the VM of the Manual Scale VNF.
155     Variable Should Exist   @{VDU_MANUALSCALE_IDS}   msg=VDU is not available
156     Halt Server   ${VDU_MANUALSCALE_IDS}[1]
157     Sleep   15
158
159 Heal Manual Scale VDU
160     [Documentation]   Heal manually via OSM commands all stopped VMs . They should be started again.
161     Variable Should Exist   ${VNF_MANUALSCALE_ID}   msg=VNF is not available
162     Heal Network Service   ${NS_ID}   --vnf ${VNF_MANUALSCALE_ID} --cause "Heal VM of manual_scale_vnf" --vdu ${VDU_MANUALSCALE_NAME} --count-index 1 --run-day1
163
164 Check VNF After Healing
165     [Documentation]   Check that the IDs of the VM and volumes have not changed after healing.
166     Variable Should Exist   ${VNF_MANUALSCALE_ID}   msg=VNF is not available
167     @{ip_list}=   Get Vnf Vdur IPs   ${VNF_MANUALSCALE_ID}
168     Should Be Equal   ${ip_list}   ${MANUALSCALE_IP_LIST}   IP addresses have changed after healing
169     ${id}=   Get VNF VIM ID   ${VNF_MANUALSCALE_ID}
170     @{ids}=   Split String   ${id}
171     Should Be Equal   ${VDU_MANUALSCALE_IDS}[0]   ${ids}[0]   VDU[0] id has changed after healing
172     Should Not Be Equal   ${VDU_MANUALSCALE_IDS}[1]   ${ids}[1]   VDU[1] id has not changed after healing
173     Should Be Equal   ${VDU_MANUALSCALE_IDS}[2]   ${ids}[2]   VDU[2] id has changed after healing
174     ${ip}=   Get Vdu Attribute   ${VNF_MANUALSCALE_ID}   ip-address   1
175     ${stdout}=   Execute Remote Command Check Rc Return Output   ${ip}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}   sudo ls ${VNF_MANUALSCALE_CLOUDINIT_FILE}
176     Log   ${stdout}
177     Check If Remote File Exists   ${ip}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}   ${VNF_MANUALSCALE_DAY1_FILE}
178     ${vim_info}=   Get Vdu Attribute   ${VNF_MANUALSCALE_ID}   vim_info   1
179     Should Contain   ${vim_info}   id: ${FLAVOR_ID}   msg=Flavor ID is incorrect
180
181 Update VIM Objects
182     [Documentation]   Retrieve all VMs and volumes from the NS and stores them in VIM_VDUS and VIM_VOLUMES lists.
183     ...               This is done again to guarantee that all objects are cleaned in the VIM in case the heal operation
184     ...               added new objects.
185     Variable Should Exist   ${NS_ID}   msg=NS is not available
186     @{vdu_updated}=   Create List
187     @{vnf_id_list}=   Get Ns Vnf List   ${NS_ID}
188     FOR   ${vnf_id}   IN   @{vnf_id_list}
189         ${id}=   Get VNF VIM ID   ${vnf_id}
190         @{vdu_ids}=   Split String   ${id}
191         Append To List   ${vdu_updated}   @{vdu_ids}
192         FOR   ${id}   IN   @{vdu_ids}
193             IF   not "${id}" in "@{VIM_VDUS}"
194                 Append To List   ${VIM_VDUS}   ${id}
195             END
196         END
197     END
198     FOR   ${vdu_id}   IN   @{vdu_updated}
199         ${volumes_attached}=   Get Server Property   ${vdu_id}   volumes_attached
200         ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
201         IF   ${match} != @{EMPTY}
202             IF   not "${match}[0]" in "@{VIM_VOLUMES}"
203                 Append To List   ${VIM_VOLUMES}   ${match}[0]
204             END
205         END
206     END
207     Log Many   @{VIM_VDUS}
208     Log Many   @{VIM_VOLUMES}
209
210 Delete NS Instance
211     [Documentation]   Delete NS instance.
212     [Tags]   cleanup
213     Delete NS   ${NS_NAME}
214
215 Delete NS Descriptor
216     [Documentation]   Delete NS package from OSM.
217     [Tags]   cleanup
218     Delete NSD   ${NSD_NAME}
219
220 Delete VNF Descriptors
221     [Documentation]   Delete VNF packages from OSM.
222     [Tags]   cleanup
223     Delete VNFD   ${VNFD_VOLUMES_NAME}
224     Delete VNFD   ${VNFD_MANUALSCALE_NAME}
225
226 Delete Remaining Objects In VIM
227     [Documentation]   Delete any remaining objects (volumes, VMs, etc.) in the VIM.
228     [Tags]   cleanup
229     Delete Objects In VIM
230
231
232 *** Keywords ***
233 Suite Cleanup
234     [Documentation]   Test Suit Cleanup: Deleting Descriptor, instance and vim
235     Run Keyword If Any Tests Failed   Delete NS   ${NS_NAME}
236     Run Keyword If Any Tests Failed   Delete NSD   ${NSD_NAME}
237     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD_VOLUMES_NAME}
238     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD_MANUALSCALE_NAME}
239     Run Keyword If Any Tests Failed   Delete Objects In VIM
240
241 Delete Objects In VIM
242     [Documentation]   Clean up remaining VMs and volumes directly from the VIM.
243     Delete Flavor   ${FLAVOR_ID}
244     ${error}=   Set Variable   0
245     FOR   ${vol_id}   IN   @{VIM_VOLUMES}
246         Log   Checking if volume ${vol_id} is still in VIM
247         ${exists}=   Check If Volume Exists   ${vol_id}
248         IF   ${exists}
249             ${error}=   Set Variable   1
250             Log   Deleting volume ${vol_id}
251             Run Keyword And Ignore Error   Delete Volume   ${vol_id}
252         END
253     END
254     FOR   ${vdu_id}   IN   @{VIM_VDUS}
255         Log   Checking if server ${vdu_id} is still in VIM
256         ${status}=   Run Keyword And Ignore Error   Get Server Property   ${vdu_id}   id
257         Log   ${status}[0]
258         IF   '${status}[0]' == 'PASS'
259             ${error}=   Set Variable   1
260             Log   Deleting server ${vdu_id}
261             Run Keyword And Ignore Error   Delete Server   ${vdu_id}
262         END
263     END
264     IF   ${error}==1
265         Fail   Some objects created by test were not deleted in VIM
266     END