blob: 43893153cebf04f0f3079ba771f9bf40bfb32419 [file] [log] [blame]
garciadeblas353aeb52025-02-13 10:23:34 +01001*** Comments ***
2# Copyright 2020 Canonical Ltd.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
17*** Settings ***
18Documentation Library providing keywords for CRUD operations over clusters,
19... OKAs and KSUs with OSM client.
20Library OperatingSystem
21Library String
22
23
24*** Variables ***
25${SUCCESS_RETURN_CODE} 0
26${CLUSTER_LAUNCH_MAX_WAIT_TIME} 12min
27${CLUSTER_LAUNCH_POL_TIME} 30sec
garciadeblas590e2952025-04-23 17:05:03 +020028${CLUSTER_REGISTER_MAX_WAIT_TIME} 7min
29${CLUSTER_REGISTER_POL_TIME} 30sec
garciadeblas353aeb52025-02-13 10:23:34 +010030${CLUSTER_DELETE_MAX_WAIT_TIME} 12min
31${CLUSTER_DELETE_POL_TIME} 30sec
32${OKA_OPERATION_MAX_WAIT_TIME} 5min
33${OKA_OPERATION_POL_TIME} 15sec
garciadeblas76790672025-02-26 11:18:33 +010034${KSU_CREATION_MAX_WAIT_TIME} 7min
garciadeblas353aeb52025-02-13 10:23:34 +010035${KSU_CREATION_POL_TIME} 30sec
garciadeblas76790672025-02-26 11:18:33 +010036${KSU_DELETION_MAX_WAIT_TIME} 5min
garciadeblas353aeb52025-02-13 10:23:34 +010037${KSU_DELETION_POL_TIME} 15sec
38
39
40*** Keywords ***
41Create Cluster
42 [Documentation] Create a Kubernetes cluster in OSM using the name, version, nodes, etc., passed as arguments.
garciadeblasc7088602025-07-31 18:23:48 +020043 [Arguments] ${name} ${vim_account} ${description} ${vm_size} ${version} ${nodes} ${region} ${resource_group} ${cluster_config}=${EMPTY} ${wait_flag}=True
garciadeblas353aeb52025-02-13 10:23:34 +010044 ${command}= Catenate
45 ... osm cluster-create ${name}
46 ... --node-count ${nodes}
47 ... --node-size ${vm_size}
48 ... --version ${version}
49 ... --vim-account ${vim_account}
50 ... --description ${description}
51 ... --region-name ${region}
52 ... --resource-group ${resource_group}
garciadeblasc7088602025-07-31 18:23:48 +020053 IF "${cluster_config}" != "${EMPTY}"
54 ${command}= Catenate ${command} ${cluster_config}
55 END
garciadeblas353aeb52025-02-13 10:23:34 +010056 ${rc} ${stdout}= Run And Return Rc And Output ${command}
57 Log ${rc},${stdout}
58 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster creation failed: ${stdout}
59 ${cluster_id}= Set Variable ${stdout}
60 Log ${cluster_id}
61 Check Cluster Age Keys ${cluster_id}
62 IF ${wait_flag} == True
garciadeblas590e2952025-04-23 17:05:03 +020063 Wait Until Keyword Succeeds ${CLUSTER_REGISTER_MAX_WAIT_TIME} ${CLUSTER_REGISTER_POL_TIME}
64 ... Check For Cluster To Be Ready ${name}
65 END
66 RETURN ${cluster_id}
67
68Register Cluster
69 [Documentation] Register a Kubernetes cluster in OSM using a provided name and kubeconfig credentials.
garciadeblasec153232025-08-01 10:13:03 +020070 [Arguments] ${name} ${vim_account} ${creds} ${description} ${bootstrap_flag}=True ${openshift_flag}=False ${wait_flag}=True
garciadeblas590e2952025-04-23 17:05:03 +020071 ${command}= Catenate
72 ... osm cluster-register ${name}
73 ... --vim-account ${vim_account}
74 ... --creds ${creds}
75 ... --description ${description}
76 IF ${bootstrap_flag} == True
garciadeblasc50555f2025-06-17 12:40:07 +020077 ${command}= Catenate ${command} --bootstrap
garciadeblas590e2952025-04-23 17:05:03 +020078 ELSE
garciadeblasc50555f2025-06-17 12:40:07 +020079 ${command}= Catenate ${command} --no-bootstrap
garciadeblas590e2952025-04-23 17:05:03 +020080 END
garciadeblasec153232025-08-01 10:13:03 +020081 IF ${openshift_flag} == True
82 ${command}= Catenate ${command} --openshift
83 END
garciadeblas590e2952025-04-23 17:05:03 +020084 ${rc} ${stdout}= Run And Return Rc And Output ${command}
85 Log ${rc},${stdout}
86 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster registration failed: ${stdout}
87 ${cluster_id}= Set Variable ${stdout}
88 Log ${cluster_id}
89 Check Cluster Age Keys ${cluster_id}
90 IF ${wait_flag} == True
garciadeblas353aeb52025-02-13 10:23:34 +010091 Wait Until Keyword Succeeds ${CLUSTER_LAUNCH_MAX_WAIT_TIME} ${CLUSTER_LAUNCH_POL_TIME}
92 ... Check For Cluster To Be Ready ${name}
93 END
94 RETURN ${cluster_id}
95
96Check Cluster Age Keys
97 [Documentation] Check AGE keys in the cluster
98 [Arguments] ${cluster_name}
99 ${rc} ${stdout}= Run And Return Rc And Output
100 ... osm cluster-show ${cluster_name} -o jsonpath='{.age_privkey}'
101 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
102 # TODO: Check if privkey contains the expected value
103 Log privkey is ${stdout}
104 ${rc} ${stdout}= Run And Return Rc And Output
105 ... osm cluster-show ${cluster_name} -o jsonpath='{.age_pubkey}'
106 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
107 # TODO: Check if pubkey contains the expected value
108 Log pubkey is ${stdout}
109
110Delete Cluster
garciadeblas590e2952025-04-23 17:05:03 +0200111 [Documentation] Delete a Kubernetes cluster from OSM.
garciadeblas353aeb52025-02-13 10:23:34 +0100112 [Arguments] ${cluster_name} ${wait_flag}=True
113 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-delete ${cluster_name}
114 Log ${rc},${stdout}
115 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster deletion failed: ${stdout}
116 IF ${wait_flag} == True
117 Wait Until Keyword Succeeds ${CLUSTER_DELETE_MAX_WAIT_TIME} ${CLUSTER_DELETE_POL_TIME}
118 ... Check For Cluster Deletion Status ${cluster_name}
119 END
120
garciadeblas590e2952025-04-23 17:05:03 +0200121Deregister Cluster
122 [Documentation] Deregister a Kubernetes cluster from OSM.
123 [Arguments] ${cluster_name} ${wait_flag}=True
124 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-deregister ${cluster_name}
125 Log ${rc},${stdout}
126 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster deregistration failed: ${stdout}
127 IF ${wait_flag} == True
128 Wait Until Keyword Succeeds ${CLUSTER_DELETE_MAX_WAIT_TIME} ${CLUSTER_DELETE_POL_TIME}
129 ... Check For Cluster Deletion Status ${cluster_name}
130 END
131
garciadeblas353aeb52025-02-13 10:23:34 +0100132Check For Cluster Deletion Status
133 [Documentation] Check if a Kubernetes cluster identified by name is deleted or in error state.
134 [Arguments] ${cluster_name}
135 ${rc} ${output}= Run And Return Rc And Output osm cluster-show ${cluster_name}
136 Log ${rc},${output}
137 ${rc} ${resourceState}= Run And Return Rc And Output osm cluster-show ${cluster_name} -o jsonpath='{.resourceState}'
138 Log ${rc},${resourceState}
139 IF '$rc' == '$SUCCESS_RETURN_CODE' and '$resourceState' == 'ERROR'
140 Fail Cluster is in error state and will not be deleted.
141 ELSE
142 Log Either the cluster ${cluster_name} has been deleted or it is in a valid state.
143 Check For Cluster To Be Deleted ${cluster_name}
144 END
145
146Get Clusters
147 [Documentation] Get the list of Kubernetes clusters in OSM, and return it.
148 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list
149 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
150 Log ${stdout}
151 RETURN ${stdout}
152
153Check For Cluster To Be Ready
154 [Documentation] Check if a Kubernetes cluster is ready (the resourceState must be READY).
155 [Arguments] ${cluster_name}
156 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-show ${cluster_name}
157 Log ${rc},${stdout}
158 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-show ${cluster_name} -o jsonpath='{.resourceState}'
159 Log ${rc},${stdout}
160 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
161 Should Be Equal As Strings ${stdout} READY
162
163Check For Cluster To Be Deleted
164 [Documentation] Check if a Kubernetes cluster identified by name is not present in OSM.
165 [Arguments] ${cluster_name}
166 ${matches}= Get Regexp Matches ${cluster_name} ^[0-9a-fA-F-]{36}$
167 Log ${matches}
168 IF ${matches} != @{EMPTY}
169 Log ${cluster_name} is a valid UUID
garciadeblas71ae92c2025-04-25 13:18:58 +0200170 # ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter _id="${cluster_name}" | grep ${cluster_name}
garciadeblasc25ac022025-06-17 12:32:23 +0200171 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter _id="${cluster_name}" -o jsonpath='[*]._id'| grep -E "\^${cluster_name}\$"
garciadeblas353aeb52025-02-13 10:23:34 +0100172 ELSE
173 Log ${cluster_name} is not a valid UUID, so it will be treated as a name
garciadeblas71ae92c2025-04-25 13:18:58 +0200174 # ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter name="${cluster_name}" | grep ${cluster_name}
garciadeblasc25ac022025-06-17 12:32:23 +0200175 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter name="${cluster_name}" -o jsonpath='[*].name'| grep -E "\^${cluster_name}\$"
garciadeblas353aeb52025-02-13 10:23:34 +0100176 END
177 Log ${rc},${stdout}
178 Should Be Empty ${stdout}
179
180Add OKA Package
181 [Documentation] Add OKA package to OSM
182 [Arguments] ${oka_name} ${oka_folder} ${oka_profile} ${wait_flag}=True
183 ${rc} ${stdout}= Run And Return Rc And Output
184 ... osm oka-add ${oka_name} ${oka_folder} --description ${oka_name} --profile-type ${oka_profile}
185 Log ${rc},${stdout}
186 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=OKA addition failed: ${stdout}
187 ${oka_id}= Set Variable ${stdout}
188 Log ${oka_id}
189 IF ${wait_flag} == True
190 Wait Until Keyword Succeeds ${OKA_OPERATION_MAX_WAIT_TIME} ${OKA_OPERATION_POL_TIME}
191 ... Check For OKA To Be Ready ${oka_id}
192 END
193 RETURN ${oka_id}
194
195Delete OKA Package
196 [Documentation] Delete OKA package from OSM
197 [Arguments] ${oka_name} ${wait_flag}=True
198 ${rc} ${stdout}= Run And Return Rc And Output
199 ... osm oka-delete ${oka_name}
200 Log ${rc},${stdout}
201 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=OKA deletion failed: ${stdout}
202 IF ${wait_flag} == True
203 Wait Until Keyword Succeeds ${OKA_OPERATION_MAX_WAIT_TIME} ${OKA_OPERATION_POL_TIME}
204 ... Check For OKA To Be Deleted ${oka_name}
205 END
206
207Check For OKA To Be Ready
208 [Documentation] Check if an OKA is ready (the resourceState must be READY).
209 [Arguments] ${oka_name}
210 ${rc} ${stdout}= Run And Return Rc And Output osm oka-show ${oka_name}
211 Log ${rc},${stdout}
212 ${rc} ${stdout}= Run And Return Rc And Output osm oka-show ${oka_name} -o jsonpath='{.resourceState}'
213 Log ${rc},${stdout}
214 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
215 Should Be Equal As Strings ${stdout} READY
216
217Check For OKA To Be Deleted
218 [Documentation] Check if an OKA identified by oka_name is not present in OSM.
219 [Arguments] ${oka_name}
220 ${rc} ${output}= Run And Return Rc And Output osm oka-show ${oka_name}
221 Log ${rc},${output}
222 ${matches}= Get Regexp Matches ${oka_name} ^[0-9a-fA-F-]{36}$
223 Log ${matches}
224 IF ${matches} != @{EMPTY}
225 Log ${oka_name} is a valid UUID
garciadeblas71ae92c2025-04-25 13:18:58 +0200226 # ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter _id="${oka_name}" | grep ${oka_name}
garciadeblasc25ac022025-06-17 12:32:23 +0200227 ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter _id="${oka_name}" -o jsonpath='[*]._id'| grep -E "\^${oka_name}\$"
garciadeblas353aeb52025-02-13 10:23:34 +0100228 ELSE
229 Log ${oka_name} is not a valid UUID, so it will be treated as a name
garciadeblas71ae92c2025-04-25 13:18:58 +0200230 # ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter name="${oka_name}" | grep ${oka_name}
garciadeblasc25ac022025-06-17 12:32:23 +0200231 ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter name="${oka_name}" -o jsonpath='[*].name'| grep -E "\^${oka_name}\$"
garciadeblas353aeb52025-02-13 10:23:34 +0100232 END
233 Log ${rc},${stdout}
234 Should Be Empty ${stdout}
235
236Create KSU
237 [Documentation] Create a KSU
garciadeblas76790672025-02-26 11:18:33 +0100238 [Arguments] ${ksu_name} ${ksu_description} ${profile} ${profile_type} ${oka_name} ${ksu_params_file}=${EMPTY} ${wait_flag}=True
239 IF "${ksu_params_file}" != "${EMPTY}"
240 ${rc} ${stdout}= Run And Return Rc And Output
241 ... osm ksu-create --ksu ${ksu_name} --description ${ksu_description} --profile ${profile} --profile-type ${profile_type} --oka ${oka_name} --params ${ksu_params_file}
242 ELSE
243 ${rc} ${stdout}= Run And Return Rc And Output
244 ... osm ksu-create --ksu ${ksu_name} --description ${ksu_description} --profile ${profile} --profile-type ${profile_type} --oka ${oka_name}
245 END
garciadeblas353aeb52025-02-13 10:23:34 +0100246 Log ${rc},${stdout}
247 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=KSU creation failed: ${stdout}
248 ${ksu_id}= Set Variable ${stdout}
249 Log ${ksu_id}
250 IF ${wait_flag} == True
251 Wait Until Keyword Succeeds ${KSU_CREATION_MAX_WAIT_TIME} ${KSU_CREATION_POL_TIME}
252 ... Check For KSU To Be Ready ${ksu_id}
253 END
254 RETURN ${ksu_id}
255
256Delete KSU
257 [Documentation] Delete KSU from OSM
258 [Arguments] ${ksu_name} ${wait_flag}=True
259 ${rc} ${stdout}= Run And Return Rc And Output
260 ... osm ksu-delete ${ksu_name}
261 Log ${rc},${stdout}
262 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=KSU deletion failed: ${stdout}
263 IF ${wait_flag} == True
264 Wait Until Keyword Succeeds ${KSU_DELETION_MAX_WAIT_TIME} ${KSU_DELETION_POL_TIME}
265 ... Check For KSU To Be Deleted ${ksu_name}
266 END
267
268Check For KSU To Be Ready
269 [Documentation] Check if a KSU is ready (the resourceState must be READY).
270 [Arguments] ${ksu_name}
271 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-show ${ksu_name}
272 Log ${rc},${stdout}
273 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-show ${ksu_name} -o jsonpath='{.resourceState}'
274 Log ${rc},${stdout}
275 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
276 Should Be Equal As Strings ${stdout} READY
277
278Check For KSU To Be Deleted
279 [Documentation] Check if a KSU identified by ksu_name is not present in OSM.
280 [Arguments] ${ksu_name}
281 ${rc} ${output}= Run And Return Rc And Output osm ksu-show ${ksu_name}
282 Log ${rc},${output}
283 ${matches}= Get Regexp Matches ${ksu_name} ^[0-9a-fA-F-]{36}$
284 Log ${matches}
285 IF ${matches} != @{EMPTY}
286 Log ${ksu_name} is a valid UUID
garciadeblas590e2952025-04-23 17:05:03 +0200287 # ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter _id="${ksu_name}" | grep ${ksu_name}
garciadeblasc25ac022025-06-17 12:32:23 +0200288 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter _id="${ksu_name}" -o jsonpath='[*]._id'| grep -E "\^${ksu_name}\$"
garciadeblas353aeb52025-02-13 10:23:34 +0100289 ELSE
290 Log ${ksu_name} is not a valid UUID, so it will be treated as a name
garciadeblas590e2952025-04-23 17:05:03 +0200291 # ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter name="${ksu_name}" | grep ${ksu_name}
292 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter name="${ksu_name}" -o jsonpath='[*].name'| grep -E "\^${ksu_name}\$"
garciadeblas353aeb52025-02-13 10:23:34 +0100293 END
294 Log ${rc},${stdout}
295 Should Be Empty ${stdout}