048e7adfc8542d2c4e0843fec2bdaf24f94a0ecd
[osm/tests.git] / robot-systest / testsuite / heal_04-autohealing.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-04] Autohealing of NS
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_04   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_PKG}   autoheal_vnf
40 ${VNFD_NAME}   autoheal_vnfd
41 ${VDU_NAME}   autoheal_vnfd-VM
42 ${VNF_INDEX}   autoheal-basic-1
43 ${NSD_PKG}   autoheal_ns
44 ${NSD_NAME}   autoheal_nsd
45 # NS instance name and configuration
46 ${NS_NAME}   heal_04
47 ${NS_CONFIG}   {vld: [ {name: mgmt, vim-network-name: %{VIM_MGMT_NET}} ] }
48
49 # SSH keys and username to be used
50 ${PUBLICKEY}   %{HOME}/.ssh/id_rsa.pub
51 ${PRIVATEKEY}   %{HOME}/.ssh/id_rsa
52 ${USERNAME}   ubuntu
53 ${PASSWORD}   ${EMPTY}
54
55 ${SUCCESS_RETURN_CODE}   0
56
57 # Healing wait time
58 ${HEALING_POL_TIME}   15sec
59 ${HEALING_MAX_WAIT_TIME}   10m
60
61 @{VIM_VDUS}   @{EMPTY}
62
63
64 *** Test Cases ***
65 Create VNF Descriptors
66     [Documentation]   Upload VNF package for the testsuite.
67     Create VNFD   '%{PACKAGES_FOLDER}/${VNFD_PKG}'
68
69 Create NS Descriptor
70     [Documentation]   Upload NS package for the testsuite.
71     Create NSD   '%{PACKAGES_FOLDER}/${NSD_PKG}'
72
73 Network Service Instance Test
74     [Documentation]   Instantiate NS for the testsuite.
75     ${id}=   Create Network Service   ${NSD_NAME}   %{VIM_TARGET}   ${NS_NAME}   ${NS_CONFIG}   ${PUBLICKEY}
76     Set Suite Variable   ${NS_ID}   ${id}
77
78 Get NS Id
79     [Documentation]   Get NS identifier and stores as suite variable to be used later on.
80     [Tags]   cleanup
81     ${variables}=   Get Variables
82     IF   not "\${ns_id}" in "${variables}"
83         ${id}=   Get Ns Id   ${NS_NAME}
84         Set Suite Variable   ${NS_ID}   ${id}
85     END
86
87 Get VIM Objects
88     [Documentation]   Retrieve all VMs and volumes from the NS and stores them in VIM_VDUS and VIM_VOLUMES lists.
89     Variable Should Exist   ${NS_ID}   msg=NS is not available
90     @{vnf_id_list}=   Get Ns Vnf List   ${NS_ID}
91     Log   ${vnf_id_list}
92     FOR   ${vnf_id}   IN   @{vnf_id_list}
93         Log   ${vnf_id}
94         ${id}=   Get VNF VIM ID   ${vnf_id}
95         @{vdu_ids}=   Split String   ${id}
96         Append To List   ${VIM_VDUS}   @{vdu_ids}
97     END
98     Log Many   @{VIM_VDUS}
99
100 Get VNF Info
101     [Documentation]   Get VDU ID and IP addresses of the VNF and stores them to be used later on.
102     Variable Should Exist   ${NS_ID}   msg=NS is not available
103     ${ip_addr}=   Get Vnf Management Ip Address   ${NS_ID}   ${VNF_INDEX}
104     Log   ${ip_addr}
105     Set Suite Variable   ${VNF_IP_ADDR}   ${ip_addr}
106     ${vnf_id}=   Get Vnf Id   ${NS_ID}   ${VNF_INDEX}
107     Set Suite Variable   ${VNF_AUTOHEAL_ID}   ${vnf_id}
108     ${id}=   Get VNF VIM ID   ${vnf_id}
109     Set Suite Variable   ${VDU_AUTOHEAL_ID}   ${id}
110     Log   ${VDU_AUTOHEAL_ID}
111     @{AUTOHEAL_IP_LIST}=   Get Vnf Vdur IPs   ${VNF_AUTOHEAL_ID}
112     Set Suite Variable   @{AUTOHEAL_IP_LIST}   @{AUTOHEAL_IP_LIST}
113     Log   @{AUTOHEAL_IP_LIST}
114
115 Stop Autoheal VDU
116     [Documentation]   Stop one VM of the VNF.
117     Variable Should Exist   ${VDU_AUTOHEAL_ID}   msg=VDU is not available
118     Halt Server   ${VDU_AUTOHEAL_ID}
119     Sleep   30
120
121 Wait For Autohealing To Be Completed
122     [Documentation]   Wait for auto-healing to be completed. OSM will detect that the VM is down and will re-create it.
123     ${healing_max_wait_time}=   Convert Time   ${HEALING_MAX_WAIT_TIME}   result_format=number
124     ${healing_max_wait_time}=   Evaluate   ${healing_max_wait_time} * ${VIM_TIMEOUT_MULTIPLIER}
125     Wait Until Keyword Succeeds   ${healing_max_wait_time}   ${HEALING_POL_TIME}   Get Operations By Type   ${NS_ID}   heal
126     ${stdout}=   Get Operations By Type   ${NS_ID}   heal
127     Wait Until Keyword Succeeds   ${healing_max_wait_time}   ${HEALING_POL_TIME}   Check For NS Operation Ended   ${stdout}
128     Check For NS Operation Completed   ${stdout}
129
130 Check VNF After Healing
131     [Documentation]   Check that the ID of the VM and the IP addresses have not changed after healing.
132     Variable Should Exist   ${VNF_AUTOHEAL_ID}   msg=VNF is not available
133     @{ip_list}=   Get Vnf Vdur IPs   ${VNF_AUTOHEAL_ID}
134     Log   @{ip_list}
135     Should Be Equal   ${ip_list}   ${AUTOHEAL_IP_LIST}   IP addresses have changed after healing
136     ${id}=   Get VNF VIM ID   ${VNF_AUTOHEAL_ID}
137     Log   ${id}
138     Should Not Be Equal   ${id}   ${VDU_AUTOHEAL_ID}   VDU id has not changed after healing
139
140 Update VIM Objects
141     [Documentation]   Retrieve all VMs from the NS and stores them in VIM_VDUS.
142     ...               This is done again to guarantee that all objects are cleaned in the VIM in case the heal operation
143     ...               added new objects.
144     Variable Should Exist   ${NS_ID}   msg=NS is not available
145     @{vnf_id_list}=   Get Ns Vnf List   ${NS_ID}
146     FOR   ${vnf_id}   IN   @{vnf_id_list}
147         ${id}=   Get VNF VIM ID   ${vnf_id}
148         @{vdu_ids}=   Split String   ${id}
149         FOR   ${id}   IN   @{vdu_ids}
150             IF   not "${id}" in "@{VIM_VDUS}"
151                 Append To List   ${VIM_VDUS}   ${id}
152             END
153         END
154     END
155     Log Many   @{VIM_VDUS}
156
157 Delete NS Instance
158     [Documentation]   Delete NS instance.
159     [Tags]   cleanup
160     Delete NS   ${NS_NAME}
161
162 Delete NS Descriptor
163     [Documentation]   Delete NS package from OSM.
164     [Tags]   cleanup
165     Delete NSD   ${NSD_NAME}
166
167 Delete VNF Descriptors
168     [Documentation]   Delete VNF package from OSM.
169     [Tags]   cleanup
170     Delete VNFD   ${VNFD_NAME}
171
172 Delete Objects In VIM
173     [Documentation]   Delete any remaining objects (volumes, VMs, etc.) in the VIM.
174     [Tags]   cleanup
175     ${error}=   Set Variable   0
176     FOR   ${vdu_id}   IN   @{VIM_VDUS}
177         Log   Checking if server ${vdu_id} is still in VIM
178         ${status}=   Run Keyword And Ignore Error   Get Server Property   ${vdu_id}   id
179         Log   ${status}[0]
180         IF   '${status}[0]' == 'PASS'
181             ${error}=   Set Variable   1
182             Log   Deleting server ${vdu_id}
183             Run Keyword And Ignore Error   Delete Server   ${vdu_id}
184         END
185     END
186     IF   ${error}==1
187         Fail   Some objects created by test were not deleted in VIM
188     END
189
190
191 *** Keywords ***
192 Suite Cleanup
193     [Documentation]   Test Suit Cleanup: Deleting Descriptor, instance and vim
194     Run Keyword If Any Tests Failed   Delete NS   ${NS_NAME}
195     Run Keyword If Any Tests Failed   Delete NSD   ${NSD_NAME}
196     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD_NAME}