blob: 64be1b4ac97a5b397a188f3e2a36bc4c8cdc3e1b [file] [log] [blame]
garciadeblas7a9e0312023-12-11 22:24:46 +01001*** Comments ***
garciaale0e696252020-09-24 18:04:27 +00002# 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
garciadeblas7a9e0312023-12-11 22:24:46 +010014
15*** Settings ***
16Documentation Library providing keywords to interact with Openstack with openstack client.
17
18Library OperatingSystem
19Library String
20
21Resource ns_lib.resource
22Resource vnf_lib.resource
23
24
garciaale0e696252020-09-24 18:04:27 +000025*** Variables ***
garciadeblas7a9e0312023-12-11 22:24:46 +010026${SUCCESS_RETURN_CODE} 0
garciaale0e696252020-09-24 18:04:27 +000027
28
29*** Keywords ***
30Get Server Flavor ID
garciadeblas7a9e0312023-12-11 22:24:46 +010031 [Documentation] Get from Openstack the flavor id of a server/VM passed as argument.
garciaale0e696252020-09-24 18:04:27 +000032 [Arguments] ${server_id}
garciaale0e696252020-09-24 18:04:27 +000033 Should Not Be Empty ${server_id}
garciadeblas152f2712024-08-19 18:16:10 +020034 ${rc} ${stdout}= Run And Return Rc And Output openstack server show ${server_id} -c flavor -f value |yq -r '.id'
garciadeblas321726f2022-12-21 11:43:06 +010035 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +010036 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
37 RETURN ${stdout}
garciaale0e696252020-09-24 18:04:27 +000038
39Get Flavor Properties
garciadeblas7a9e0312023-12-11 22:24:46 +010040 [Documentation] Get from Openstack the properties of a flavor passed as argument.
garciaale0e696252020-09-24 18:04:27 +000041 [Arguments] ${flavor_id}
garciaale0e696252020-09-24 18:04:27 +000042 Should Not Be Empty ${flavor_id}
garciadeblas7a9e0312023-12-11 22:24:46 +010043 ${rc} ${stdout}= Run And Return Rc And Output openstack flavor show ${flavor_id} | grep properties | awk -F '|' '{print $3}'
garciadeblas321726f2022-12-21 11:43:06 +010044 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +010045 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
46 RETURN ${stdout}
aguilard3422ec32021-06-30 12:28:46 +020047
48Check NS Servers In VIM
garciadeblasf4ebaa82022-06-23 13:33:26 +020049 [Documentation] Check if the number of servers in Openstack by filtering by NS name is as expected.
aguilard3422ec32021-06-30 12:28:46 +020050 [Arguments] ${ns_name} ${number}
aguilard3422ec32021-06-30 12:28:46 +020051 Should Not Be Empty ${ns_name}
garciadeblas7a9e0312023-12-11 22:24:46 +010052 ${rc} ${stdout}= Run And Return Rc And Output openstack server list | grep ${ns_name} | awk '{print $4}'
garciadeblas321726f2022-12-21 11:43:06 +010053 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +010054 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
55 @{servers}= Split String ${stdout}
garciadeblasf4ebaa82022-06-23 13:33:26 +020056 ${n_servers}= Get Length ${servers}
aguilard3422ec32021-06-30 12:28:46 +020057 Should Be Equal As Integers ${number} ${n_servers}
aguilardceb1cb42022-02-24 10:54:14 +000058
Gulsum Atici8ceaee02022-12-09 16:38:22 +030059Check If Volume Bootable
60 [Documentation] Check the volume properties and return whether it is bootable or not.
61 [Arguments] ${volume_id}
Gulsum Atici8ceaee02022-12-09 16:38:22 +030062 Should Not Be Empty ${volume_id}
garciadeblas7a9e0312023-12-11 22:24:46 +010063 ${rc} ${stdout}= Run And Return Rc And Output openstack volume show ${volume_id} | grep bootable | awk '{print $4}'
64 Log ${stdout}
65 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
66 RETURN ${stdout}
Gulsum Atici8ceaee02022-12-09 16:38:22 +030067
aguilardceb1cb42022-02-24 10:54:14 +000068Get Project Quota
garciadeblasf4ebaa82022-06-23 13:33:26 +020069 [Documentation] Get a field (ram, cores, ports, etc.) from quota in current project.
aguilardceb1cb42022-02-24 10:54:14 +000070 [Arguments] ${field}
aguilardceb1cb42022-02-24 10:54:14 +000071 Should Not Be Empty ${field}
garciadeblas7a9e0312023-12-11 22:24:46 +010072 ${rc} ${stdout}= Run And Return Rc And Output openstack quota show -f yaml | yq '.[] | select(.Resource=="${field}") | .Limit'
garciadeblas321726f2022-12-21 11:43:06 +010073 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +010074 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
75 RETURN ${stdout}
aguilardbde67802022-03-18 14:15:17 +000076
77Get Server Property
garciadeblasf4ebaa82022-06-23 13:33:26 +020078 [Documentation] Get a field (flavor, image, volumes_attached, etc.) from a server.
79 [Arguments] ${server_id} ${field}
aguilardbde67802022-03-18 14:15:17 +000080 Should Not Be Empty ${server_id}
81 Should Not Be Empty ${field}
garciadeblas7a9e0312023-12-11 22:24:46 +010082 ${rc} ${stdout}= Run And Return Rc And Output openstack server show ${server_id} -c ${field} -f value
garciadeblas321726f2022-12-21 11:43:06 +010083 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +010084 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
85 RETURN ${stdout}
aguilardbde67802022-03-18 14:15:17 +000086
Alexis Romerodd1b09d2022-03-16 06:51:43 +010087Check 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}
Alexis Romerodd1b09d2022-03-16 06:51:43 +010090 Should Not Be Empty ${server_group_name}
91 Should Not Be Empty ${server_id}
garciadeblas7a9e0312023-12-11 22:24:46 +010092 ${rc} ${stdout}= Run And Return Rc And Output openstack server group show ${server_group_name} -c members -f value
garciadeblas321726f2022-12-21 11:43:06 +010093 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +010094 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
Alexis Romerodd1b09d2022-03-16 06:51:43 +010095 Should Contain ${stdout} ${server_id}
96
Gulsum Atici8ceaee02022-12-09 16:38:22 +030097Set Volume Id
98 [Documentation] Sets the root volume ID and ordinary volume ID by checking bootable property of volumes
99 [Arguments] ${volume_match} ${index}
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300100 Should Not Be Empty ${volume_match} ${index}
101 ${bootable}= Check If Volume Bootable ${volume_match}[${index}]
garciadeblas5e67d7d2025-10-22 09:24:42 +0200102 ${bootable}= Convert To Lowercase ${bootable}
garciadeblas23ff8f92023-12-11 16:26:40 +0100103 IF '${bootable}'=='true'
garciadeblas7a9e0312023-12-11 22:24:46 +0100104 Set Suite Variable ${ROOT_VOL_ID} ${volume_match}[${index}]
105 IF not ${index}
106 Set Suite Variable ${ORDINARY_VOL_ID} ${volume_match}[1]
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300107 ELSE
garciadeblas7a9e0312023-12-11 22:24:46 +0100108 Set Suite Variable ${ORDINARY_VOL_ID} ${volume_match}[0]
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300109 END
110 END
111
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300112Get Persistent Volumes Attached To Vm
113 [Documentation] Sets the root volume ID and ordinary volume ID by checking bootable property of volumes
114 [Arguments] ${ns_id}
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300115 Variable Should Exist ${ns_id} msg=NS is not available
116 ${vnfs_list}= Get Ns Vnf List ${ns_id}
117 ${vim_id}= Get VNF VIM ID ${vnfs_list}[0]
118 ${volumes_attached}= Get Server Property ${vim_id} volumes_attached
garciadeblas7a9e0312023-12-11 22:24:46 +0100119 Log ${volumes_attached}
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300120 ${stdout}= Get Regexp Matches ${volumes_attached} '([0-9a-f\-]+)' 1
garciadeblas7a9e0312023-12-11 22:24:46 +0100121 Log ${stdout}
122 RETURN ${stdout}
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300123
aguilardbde67802022-03-18 14:15:17 +0000124Check If Volume Exists
garciadeblasf4ebaa82022-06-23 13:33:26 +0200125 [Documentation] Checks if a volume id exists
126 [Arguments] ${volume_id}
aguilardbde67802022-03-18 14:15:17 +0000127 Should Not Be Empty ${volume_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100128 ${rc} ${stdout}= Run And Return Rc And Output openstack volume list | grep ${volume_id} | wc -l
garciadeblas321726f2022-12-21 11:43:06 +0100129 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100130 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
131 RETURN ${stdout}
aguilardbde67802022-03-18 14:15:17 +0000132
133Delete Volume
garciadeblasf4ebaa82022-06-23 13:33:26 +0200134 [Documentation] Delete a volume by its identifier
135 [Arguments] ${volume_id}
aguilardbde67802022-03-18 14:15:17 +0000136 Should Not Be Empty ${volume_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100137 ${rc} ${stdout}= Run And Return Rc And Output openstack volume delete ${volume_id}
garciadeblas321726f2022-12-21 11:43:06 +0100138 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100139 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
140 RETURN ${stdout}
aguilard845c2ea2022-04-08 09:36:03 +0000141
Gabriel Cuba245b04f2023-05-09 12:37:29 -0500142Get Subnet
143 [Documentation] Get subnet information in JSON format
144 [Arguments] ${subnet_id}
Gabriel Cuba245b04f2023-05-09 12:37:29 -0500145 Should Not Be Empty ${subnet_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100146 ${rc} ${stdout}= Run And Return Rc And Output openstack subnet show ${subnet_id} -f json
Gabriel Cuba245b04f2023-05-09 12:37:29 -0500147 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100148 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
149 RETURN ${stdout}
Gabriel Cuba245b04f2023-05-09 12:37:29 -0500150
aguilard845c2ea2022-04-08 09:36:03 +0000151Stop Server
garciadeblasf4ebaa82022-06-23 13:33:26 +0200152 [Documentation] Stop a server
153 [Arguments] ${server_id}
aguilard845c2ea2022-04-08 09:36:03 +0000154 Should Not Be Empty ${server_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100155 ${rc} ${stdout}= Run And Return Rc And Output openstack server stop ${server_id}
garciadeblas321726f2022-12-21 11:43:06 +0100156 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100157 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
158 RETURN ${stdout}
aguilard8f18bfd2022-06-22 10:44:20 +0000159
dhanasekaranc4da0672022-04-28 12:56:03 +0000160Halt Server
garciadeblasf4ebaa82022-06-23 13:33:26 +0200161 [Documentation] Reset a server
162 [Arguments] ${server_id}
dhanasekaranc4da0672022-04-28 12:56:03 +0000163 Should Not Be Empty ${server_id}
garciadeblas87c02fc2025-06-27 15:04:09 +0200164 ${rc} ${stdout}= Run And Return Rc And Output openstack server set --auto-approve --state error ${server_id}
garciadeblas321726f2022-12-21 11:43:06 +0100165 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100166 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
167 RETURN ${stdout}
aguilard8f18bfd2022-06-22 10:44:20 +0000168
169Delete Server
170 [Documentation] Delete a server
171 [Arguments] ${server_id}
aguilard8f18bfd2022-06-22 10:44:20 +0000172 Should Not Be Empty ${server_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100173 ${rc} ${stdout}= Run And Return Rc And Output openstack server delete ${server_id}
garciadeblas321726f2022-12-21 11:43:06 +0100174 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100175 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
176 RETURN ${stdout}
aguilard8f18bfd2022-06-22 10:44:20 +0000177
Gabriel Cuba8f994cc2023-05-12 13:44:16 -0500178Create Flavor
179 [Documentation] Create a Flavor
180 [Arguments] ${flavor_name} ${cpu}=1 ${ram}=1024 ${disk}=10
Gabriel Cuba8f994cc2023-05-12 13:44:16 -0500181 Should Not Be Empty ${flavor_name}
garciadeblas7a9e0312023-12-11 22:24:46 +0100182 ${rc} ${flavor_id}= Run And Return Rc And Output openstack flavor create ${flavor_name} --ram ${ram} --disk ${disk} --vcpus ${cpu} -c id -f value
Gabriel Cuba8f994cc2023-05-12 13:44:16 -0500183 Log ${flavor_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100184 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
185 RETURN ${flavor_id}
Gabriel Cuba8f994cc2023-05-12 13:44:16 -0500186
187Delete Flavor
188 [Documentation] Delete a Flavor
189 [Arguments] ${flavor_id}
Gabriel Cuba8f994cc2023-05-12 13:44:16 -0500190 Should Not Be Empty ${flavor_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100191 ${rc} ${stdout}= Run And Return Rc And Output openstack flavor delete ${flavor_id}
Gabriel Cuba8f994cc2023-05-12 13:44:16 -0500192 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100193 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
194 RETURN ${stdout}
rarik7d7628b2023-12-14 07:14:53 +0000195
196Openstack Server List
197 [Documentation] Get the openstack server list
198 [Arguments] ${ns_name}
199 ${result}= Run And Return Rc And Output openstack server list | grep ${ns_name} | awk 'index($0, "ipv6=") {gsub(/,$/, ""); gsub("ipv6=", ""); print $8, $9}'
200 ${rc}= Get From List ${result} 0
201 ${Ip}= Get From List ${result} 1
202 Log ${Ip}
203 Should Be Equal As Integers ${rc} ${success_return_code}
204 RETURN ${Ip}
205
206Source Openrc Command
207 [Documentation] Keyword to source openstack tenant
208 Write source openrc