blob: add717a443d7d41fca6af2d3308ef3b2acfb9a6f [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}]
garciadeblas23ff8f92023-12-11 16:26:40 +0100102 IF '${bootable}'=='true'
garciadeblas7a9e0312023-12-11 22:24:46 +0100103 Set Suite Variable ${ROOT_VOL_ID} ${volume_match}[${index}]
104 IF not ${index}
105 Set Suite Variable ${ORDINARY_VOL_ID} ${volume_match}[1]
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300106 ELSE
garciadeblas7a9e0312023-12-11 22:24:46 +0100107 Set Suite Variable ${ORDINARY_VOL_ID} ${volume_match}[0]
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300108 END
109 END
110
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300111Get Persistent Volumes Attached To Vm
112 [Documentation] Sets the root volume ID and ordinary volume ID by checking bootable property of volumes
113 [Arguments] ${ns_id}
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300114 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
garciadeblas7a9e0312023-12-11 22:24:46 +0100118 Log ${volumes_attached}
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300119 ${stdout}= Get Regexp Matches ${volumes_attached} '([0-9a-f\-]+)' 1
garciadeblas7a9e0312023-12-11 22:24:46 +0100120 Log ${stdout}
121 RETURN ${stdout}
Gulsum Atici8ceaee02022-12-09 16:38:22 +0300122
aguilardbde67802022-03-18 14:15:17 +0000123Check If Volume Exists
garciadeblasf4ebaa82022-06-23 13:33:26 +0200124 [Documentation] Checks if a volume id exists
125 [Arguments] ${volume_id}
aguilardbde67802022-03-18 14:15:17 +0000126 Should Not Be Empty ${volume_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100127 ${rc} ${stdout}= Run And Return Rc And Output openstack volume list | grep ${volume_id} | wc -l
garciadeblas321726f2022-12-21 11:43:06 +0100128 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100129 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
130 RETURN ${stdout}
aguilardbde67802022-03-18 14:15:17 +0000131
132Delete Volume
garciadeblasf4ebaa82022-06-23 13:33:26 +0200133 [Documentation] Delete a volume by its identifier
134 [Arguments] ${volume_id}
aguilardbde67802022-03-18 14:15:17 +0000135 Should Not Be Empty ${volume_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100136 ${rc} ${stdout}= Run And Return Rc And Output openstack volume delete ${volume_id}
garciadeblas321726f2022-12-21 11:43:06 +0100137 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100138 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
139 RETURN ${stdout}
aguilard845c2ea2022-04-08 09:36:03 +0000140
Gabriel Cuba245b04f2023-05-09 12:37:29 -0500141Get Subnet
142 [Documentation] Get subnet information in JSON format
143 [Arguments] ${subnet_id}
Gabriel Cuba245b04f2023-05-09 12:37:29 -0500144 Should Not Be Empty ${subnet_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100145 ${rc} ${stdout}= Run And Return Rc And Output openstack subnet show ${subnet_id} -f json
Gabriel Cuba245b04f2023-05-09 12:37:29 -0500146 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100147 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
148 RETURN ${stdout}
Gabriel Cuba245b04f2023-05-09 12:37:29 -0500149
aguilard845c2ea2022-04-08 09:36:03 +0000150Stop Server
garciadeblasf4ebaa82022-06-23 13:33:26 +0200151 [Documentation] Stop a server
152 [Arguments] ${server_id}
aguilard845c2ea2022-04-08 09:36:03 +0000153 Should Not Be Empty ${server_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100154 ${rc} ${stdout}= Run And Return Rc And Output openstack server stop ${server_id}
garciadeblas321726f2022-12-21 11:43:06 +0100155 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100156 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
157 RETURN ${stdout}
aguilard8f18bfd2022-06-22 10:44:20 +0000158
dhanasekaranc4da0672022-04-28 12:56:03 +0000159Halt Server
garciadeblasf4ebaa82022-06-23 13:33:26 +0200160 [Documentation] Reset a server
161 [Arguments] ${server_id}
dhanasekaranc4da0672022-04-28 12:56:03 +0000162 Should Not Be Empty ${server_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100163 ${rc} ${stdout}= Run And Return Rc And Output openstack server set --state error ${server_id}
garciadeblas321726f2022-12-21 11:43:06 +0100164 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100165 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
166 RETURN ${stdout}
aguilard8f18bfd2022-06-22 10:44:20 +0000167
168Delete Server
169 [Documentation] Delete a server
170 [Arguments] ${server_id}
aguilard8f18bfd2022-06-22 10:44:20 +0000171 Should Not Be Empty ${server_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100172 ${rc} ${stdout}= Run And Return Rc And Output openstack server delete ${server_id}
garciadeblas321726f2022-12-21 11:43:06 +0100173 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100174 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
175 RETURN ${stdout}
aguilard8f18bfd2022-06-22 10:44:20 +0000176
Gabriel Cuba8f994cc2023-05-12 13:44:16 -0500177Create Flavor
178 [Documentation] Create a Flavor
179 [Arguments] ${flavor_name} ${cpu}=1 ${ram}=1024 ${disk}=10
Gabriel Cuba8f994cc2023-05-12 13:44:16 -0500180 Should Not Be Empty ${flavor_name}
garciadeblas7a9e0312023-12-11 22:24:46 +0100181 ${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 -0500182 Log ${flavor_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100183 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
184 RETURN ${flavor_id}
Gabriel Cuba8f994cc2023-05-12 13:44:16 -0500185
186Delete Flavor
187 [Documentation] Delete a Flavor
188 [Arguments] ${flavor_id}
Gabriel Cuba8f994cc2023-05-12 13:44:16 -0500189 Should Not Be Empty ${flavor_id}
garciadeblas7a9e0312023-12-11 22:24:46 +0100190 ${rc} ${stdout}= Run And Return Rc And Output openstack flavor delete ${flavor_id}
Gabriel Cuba8f994cc2023-05-12 13:44:16 -0500191 Log ${stdout}
garciadeblas7a9e0312023-12-11 22:24:46 +0100192 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
193 RETURN ${stdout}
rarik7d7628b2023-12-14 07:14:53 +0000194
195Openstack 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
201 Log ${Ip}
202 Should Be Equal As Integers ${rc} ${success_return_code}
203 RETURN ${Ip}
204
205Source Openrc Command
206 [Documentation] Keyword to source openstack tenant
207 Write source openrc