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
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 Documentation Library providing keywords to interact with Openstack with openstack client.
18 Library OperatingSystem
21 Resource ns_lib.resource
22 Resource vnf_lib.resource
26 ${SUCCESS_RETURN_CODE} 0
31 [Documentation] Get from Openstack the flavor id of a server/VM passed as argument.
32 [Arguments] ${server_id}
33 Should Not Be Empty ${server_id}
34 ${rc} ${stdout}= Run And Return Rc And Output openstack server show ${server_id} | grep flavor | awk 'NR>1{print $1}' RS='(' FS=')'
36 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
40 [Documentation] Get from Openstack the properties of a flavor passed as argument.
41 [Arguments] ${flavor_id}
42 Should Not Be Empty ${flavor_id}
43 ${rc} ${stdout}= Run And Return Rc And Output openstack flavor show ${flavor_id} | grep properties | awk -F '|' '{print $3}'
45 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
48 Check NS Servers In VIM
49 [Documentation] Check if the number of servers in Openstack by filtering by NS name is as expected.
50 [Arguments] ${ns_name} ${number}
51 Should Not Be Empty ${ns_name}
52 ${rc} ${stdout}= Run And Return Rc And Output openstack server list | grep ${ns_name} | awk '{print $4}'
54 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
55 @{servers}= Split String ${stdout}
56 ${n_servers}= Get Length ${servers}
57 Should Be Equal As Integers ${number} ${n_servers}
59 Check If Volume Bootable
60 [Documentation] Check the volume properties and return whether it is bootable or not.
61 [Arguments] ${volume_id}
62 Should Not Be Empty ${volume_id}
63 ${rc} ${stdout}= Run And Return Rc And Output openstack volume show ${volume_id} | grep bootable | awk '{print $4}'
65 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
69 [Documentation] Get a field (ram, cores, ports, etc.) from quota in current project.
71 Should Not Be Empty ${field}
72 ${rc} ${stdout}= Run And Return Rc And Output openstack quota show -f yaml | yq '.[] | select(.Resource=="${field}") | .Limit'
74 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
78 [Documentation] Get a field (flavor, image, volumes_attached, etc.) from a server.
79 [Arguments] ${server_id} ${field}
80 Should Not Be Empty ${server_id}
81 Should Not Be Empty ${field}
82 ${rc} ${stdout}= Run And Return Rc And Output openstack server show ${server_id} -c ${field} -f value
84 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
87 Check VM In Server Group
88 [Documentation] Check if a given server is included in an Openstack server group
89 [Arguments] ${server_id} ${server_group_name}
90 Should Not Be Empty ${server_group_name}
91 Should Not Be Empty ${server_id}
92 ${rc} ${stdout}= Run And Return Rc And Output openstack server group show ${server_group_name} -c members -f value
94 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
95 Should Contain ${stdout} ${server_id}
98 [Documentation] Sets the root volume ID and ordinary volume ID by checking bootable property of volumes
99 [Arguments] ${volume_match} ${index}
100 Should Not Be Empty ${volume_match} ${index}
101 ${bootable}= Check If Volume Bootable ${volume_match}[${index}]
102 IF '${bootable}'=='true'
103 Set Suite Variable ${ROOT_VOL_ID} ${volume_match}[${index}]
105 Set Suite Variable ${ORDINARY_VOL_ID} ${volume_match}[1]
107 Set Suite Variable ${ORDINARY_VOL_ID} ${volume_match}[0]
111 Get Persistent Volumes Attached To Vm
112 [Documentation] Sets the root volume ID and ordinary volume ID by checking bootable property of volumes
114 Variable Should Exist ${ns_id} msg=NS is not available
115 ${vnfs_list}= Get Ns Vnf List ${ns_id}
116 ${vim_id}= Get VNF VIM ID ${vnfs_list}[0]
117 ${volumes_attached}= Get Server Property ${vim_id} volumes_attached
118 Log ${volumes_attached}
119 ${stdout}= Get Regexp Matches ${volumes_attached} '([0-9a-f\-]+)' 1
123 Check If Volume Exists
124 [Documentation] Checks if a volume id exists
125 [Arguments] ${volume_id}
126 Should Not Be Empty ${volume_id}
127 ${rc} ${stdout}= Run And Return Rc And Output openstack volume list | grep ${volume_id} | wc -l
129 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
133 [Documentation] Delete a volume by its identifier
134 [Arguments] ${volume_id}
135 Should Not Be Empty ${volume_id}
136 ${rc} ${stdout}= Run And Return Rc And Output openstack volume delete ${volume_id}
138 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
142 [Documentation] Get subnet information in JSON format
143 [Arguments] ${subnet_id}
144 Should Not Be Empty ${subnet_id}
145 ${rc} ${stdout}= Run And Return Rc And Output openstack subnet show ${subnet_id} -f json
147 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
151 [Documentation] Stop a server
152 [Arguments] ${server_id}
153 Should Not Be Empty ${server_id}
154 ${rc} ${stdout}= Run And Return Rc And Output openstack server stop ${server_id}
156 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
160 [Documentation] Reset a server
161 [Arguments] ${server_id}
162 Should Not Be Empty ${server_id}
163 ${rc} ${stdout}= Run And Return Rc And Output openstack server set --state error ${server_id}
165 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
169 [Documentation] Delete a server
170 [Arguments] ${server_id}
171 Should Not Be Empty ${server_id}
172 ${rc} ${stdout}= Run And Return Rc And Output openstack server delete ${server_id}
174 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
178 [Documentation] Create a Flavor
179 [Arguments] ${flavor_name} ${cpu}=1 ${ram}=1024 ${disk}=10
180 Should Not Be Empty ${flavor_name}
181 ${rc} ${flavor_id}= Run And Return Rc And Output openstack flavor create ${flavor_name} --ram ${ram} --disk ${disk} --vcpus ${cpu} -c id -f value
183 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
187 [Documentation] Delete a Flavor
188 [Arguments] ${flavor_id}
189 Should Not Be Empty ${flavor_id}
190 ${rc} ${stdout}= Run And Return Rc And Output openstack flavor delete ${flavor_id}
192 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
195 Openstack Server List
196 [Documentation] Get the openstack server list
197 [Arguments] ${ns_name}
198 ${result}= Run And Return Rc And Output openstack server list | grep ${ns_name} | awk 'index($0, "ipv6=") {gsub(/,$/, ""); gsub("ipv6=", ""); print $8, $9}'
199 ${rc}= Get From List ${result} 0
200 ${Ip}= Get From List ${result} 1
202 Should Be Equal As Integers ${rc} ${success_return_code}
205 Source Openrc Command
206 [Documentation] Keyword to source openstack tenant