Bug 2327 fix to verify ipaddress in sol003_02 testsuite
[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
50 # SSH keys and username to be used
51 ${publickey}   %{HOME}/.ssh/id_rsa.pub
52 ${privatekey}   %{HOME}/.ssh/id_rsa
53 ${username}   ubuntu
54 ${password}   ${EMPTY}
55
56 ${success_return_code}   0
57
58
59 *** Test Cases ***
60 Create VNF Descriptors
61     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_charm_pkg}'
62     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_volumes_pkg}'
63
64
65 Create NS Descriptor
66     Create NSD   '%{PACKAGES_FOLDER}/${nsd_pkg}'
67
68
69 Network Service Instance Test
70     ${id}=   Create Network Service   ${nsd_name}   %{VIM_TARGET}   ${ns_name}   ${ns_config}   ${publickey}
71     Set Suite Variable   ${ns_id}   ${id}
72
73
74 Get NS Id
75     [Tags]   cleanup
76     ${variables}   Get Variables
77     IF   not "\${ns_id}" in "${variables}"
78         ${id}=   Get Ns Id   ${ns_name}
79         Set Suite Variable   ${ns_id}   ${id}
80     END
81
82
83 Get Volume VNF Info
84     Variable Should Exist   ${ns_id}   msg=NS is not available
85     ${ip_addr}=   Get Vnf Management Ip Address   ${ns_id}   ${vnf_several_index}
86     log   ${ip_addr}
87     Set Suite Variable   ${vnf_volumes_ip_addr}   ${ip_addr}
88
89     ${vnf_id}=   Get Vnf Id   ${ns_id}   ${vnf_several_index}
90     Set Suite Variable   ${vnf_volumes_id}   ${vnf_id}
91     ${id}=   Get VNF VIM ID   ${vnf_id}
92     Set Suite Variable   ${vdu_volumes_id}   ${id}
93     log   ${vdu_volumes_id}
94
95     @{volumes_ip_list}=   Get Vnf Vdur IPs   ${vnf_volumes_id}
96     Set Suite Variable   @{volumes_ip_list}   @{volumes_ip_list}
97     log   @{volumes_ip_list}
98
99
100 Get Volumes Info
101     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnfpkg-show ${vnfd_volumes_name} --literal | yq '.vdu[0]."virtual-storage-desc" | length'
102     Should Be Equal As Integers   ${rc}   ${success_return_code}   msg=${stdout}   values=False
103     ${num_virtual_storage}=   Convert To Integer   ${stdout}
104     Set Suite Variable   ${vnf_num_volumes}   ${num_virtual_storage}
105     log   ${vnf_num_volumes}
106     ${volumes_attached}=   Get Server Property   ${vdu_volumes_id}   volumes_attached
107     ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
108     Set Suite Variable   ${volume_id}   ${match}[0]
109
110
111 Check VDU Disks
112     Variable Should Exist   ${vnf_volumes_ip_addr}   msg=VNF is not available
113     Sleep   30 seconds   Wait for SSH daemon to be up
114     ${stdout}=   Execute Remote Command Check Rc Return Output   ${vnf_volumes_ip_addr}   ${username}   ${password}   ${privatekey}   sudo lsblk -l
115     log   ${stdout}
116     ${lines}=   Get Lines Containing String   ${stdout}   disk
117     ${num_lines}=   Get Line Count   ${lines}
118     Run Keyword If   ${num_lines} < ${vnf_num_volumes}   Fail   msg=Number of disks (${num_lines}) is less than specified in VDU (${vnf_num_volumes})
119
120
121 Delete Persistent Volume VDU
122     Variable Should Exist   ${vdu_volumes_id}   msg=VDU is not available
123     Delete Server   ${vdu_volumes_id}
124     Sleep   20
125
126
127 Heal Persistent Volume VDU
128     Variable Should Exist   ${vnf_volumes_id}   msg=VNF is not available
129     Heal Network Service   ${ns_id}   --vnf ${vnf_volumes_id} --cause "Heal VM of volumes_vnf" --vdu ${vdu_volumes_name}
130
131
132 Check VNF After Healing
133     Variable Should Exist   ${vnf_volumes_id}   msg=VNF is not available
134
135     @{ip_list}=   Get Vnf Vdur IPs   ${vnf_volumes_id}
136     log   @{ip_list}
137     Should Be Equal   ${ip_list}   ${volumes_ip_list}   IP addresses have changed after healing
138
139     ${id}=   Get VNF VIM ID   ${vnf_volumes_id}
140     log   ${id}
141     Should Not Be Equal   ${id}   ${vdu_volumes_id}   VDU id has not changed after healing
142
143     ${volumes_attached}=   Get Server Property   ${id}   volumes_attached
144     ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
145     Should Be Equal   ${match}[0]   ${volume_id}   Volume id has changed after healing
146
147     Sleep   30 seconds   Wait for SSH daemon to be up
148     ${stdout}=   Execute Remote Command Check Rc Return Output   ${vnf_volumes_ip_addr}   ${username}   ${password}   ${privatekey}   sudo lsblk -l
149     log   ${stdout}
150     ${lines}=   Get Lines Containing String   ${stdout}   disk
151     ${num_lines}=   Get Line Count   ${lines}
152     Run Keyword If   ${num_lines} < ${vnf_num_volumes}   Fail   msg=Number of disks (${num_lines}) is less than specified in VDU (${vnf_num_volumes})
153
154
155 Delete NS Instance
156     [Tags]   cleanup
157     Delete NS   ${ns_name}
158
159
160 Delete NS Descriptor
161     [Tags]   cleanup
162     Delete NSD   ${nsd_name}
163
164
165 Delete VNF Descriptors
166     [Tags]   cleanup
167     Delete VNFD   ${vnfd_volumes_name}
168     Delete VNFD   ${vnfd_charm_name}
169
170
171 *** Keywords ***
172 Suite Cleanup
173     [Documentation]   Test Suit Cleanup: Deleting Descriptor, instance and vim
174
175     Run Keyword If Any Tests Failed   Delete NS   ${ns_name}
176     Run Keyword If Any Tests Failed   Delete NSD   ${nsd_name}
177     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_volumes_name}
178     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_charm_name}