blob: fa2d47d3a7eb21815c3acfe89b99ebb9193bae70 [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.
70 [Arguments] ${name} ${vim_account} ${creds} ${description} ${bootstrap_flag}=True ${wait_flag}=True
71 ${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
81 ${rc} ${stdout}= Run And Return Rc And Output ${command}
82 Log ${rc},${stdout}
83 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster registration failed: ${stdout}
84 ${cluster_id}= Set Variable ${stdout}
85 Log ${cluster_id}
86 Check Cluster Age Keys ${cluster_id}
87 IF ${wait_flag} == True
garciadeblas353aeb52025-02-13 10:23:34 +010088 Wait Until Keyword Succeeds ${CLUSTER_LAUNCH_MAX_WAIT_TIME} ${CLUSTER_LAUNCH_POL_TIME}
89 ... Check For Cluster To Be Ready ${name}
90 END
91 RETURN ${cluster_id}
92
93Check Cluster Age Keys
94 [Documentation] Check AGE keys in the cluster
95 [Arguments] ${cluster_name}
96 ${rc} ${stdout}= Run And Return Rc And Output
97 ... osm cluster-show ${cluster_name} -o jsonpath='{.age_privkey}'
98 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
99 # TODO: Check if privkey contains the expected value
100 Log privkey is ${stdout}
101 ${rc} ${stdout}= Run And Return Rc And Output
102 ... osm cluster-show ${cluster_name} -o jsonpath='{.age_pubkey}'
103 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
104 # TODO: Check if pubkey contains the expected value
105 Log pubkey is ${stdout}
106
107Delete Cluster
garciadeblas590e2952025-04-23 17:05:03 +0200108 [Documentation] Delete a Kubernetes cluster from OSM.
garciadeblas353aeb52025-02-13 10:23:34 +0100109 [Arguments] ${cluster_name} ${wait_flag}=True
110 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-delete ${cluster_name}
111 Log ${rc},${stdout}
112 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster deletion failed: ${stdout}
113 IF ${wait_flag} == True
114 Wait Until Keyword Succeeds ${CLUSTER_DELETE_MAX_WAIT_TIME} ${CLUSTER_DELETE_POL_TIME}
115 ... Check For Cluster Deletion Status ${cluster_name}
116 END
117
garciadeblas590e2952025-04-23 17:05:03 +0200118Deregister Cluster
119 [Documentation] Deregister a Kubernetes cluster from OSM.
120 [Arguments] ${cluster_name} ${wait_flag}=True
121 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-deregister ${cluster_name}
122 Log ${rc},${stdout}
123 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster deregistration failed: ${stdout}
124 IF ${wait_flag} == True
125 Wait Until Keyword Succeeds ${CLUSTER_DELETE_MAX_WAIT_TIME} ${CLUSTER_DELETE_POL_TIME}
126 ... Check For Cluster Deletion Status ${cluster_name}
127 END
128
garciadeblas353aeb52025-02-13 10:23:34 +0100129Check For Cluster Deletion Status
130 [Documentation] Check if a Kubernetes cluster identified by name is deleted or in error state.
131 [Arguments] ${cluster_name}
132 ${rc} ${output}= Run And Return Rc And Output osm cluster-show ${cluster_name}
133 Log ${rc},${output}
134 ${rc} ${resourceState}= Run And Return Rc And Output osm cluster-show ${cluster_name} -o jsonpath='{.resourceState}'
135 Log ${rc},${resourceState}
136 IF '$rc' == '$SUCCESS_RETURN_CODE' and '$resourceState' == 'ERROR'
137 Fail Cluster is in error state and will not be deleted.
138 ELSE
139 Log Either the cluster ${cluster_name} has been deleted or it is in a valid state.
140 Check For Cluster To Be Deleted ${cluster_name}
141 END
142
143Get Clusters
144 [Documentation] Get the list of Kubernetes clusters in OSM, and return it.
145 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list
146 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
147 Log ${stdout}
148 RETURN ${stdout}
149
150Check For Cluster To Be Ready
151 [Documentation] Check if a Kubernetes cluster is ready (the resourceState must be READY).
152 [Arguments] ${cluster_name}
153 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-show ${cluster_name}
154 Log ${rc},${stdout}
155 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-show ${cluster_name} -o jsonpath='{.resourceState}'
156 Log ${rc},${stdout}
157 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
158 Should Be Equal As Strings ${stdout} READY
159
160Check For Cluster To Be Deleted
161 [Documentation] Check if a Kubernetes cluster identified by name is not present in OSM.
162 [Arguments] ${cluster_name}
163 ${matches}= Get Regexp Matches ${cluster_name} ^[0-9a-fA-F-]{36}$
164 Log ${matches}
165 IF ${matches} != @{EMPTY}
166 Log ${cluster_name} is a valid UUID
garciadeblas71ae92c2025-04-25 13:18:58 +0200167 # ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter _id="${cluster_name}" | grep ${cluster_name}
garciadeblasc25ac022025-06-17 12:32:23 +0200168 ${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 +0100169 ELSE
170 Log ${cluster_name} is not a valid UUID, so it will be treated as a name
garciadeblas71ae92c2025-04-25 13:18:58 +0200171 # ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter name="${cluster_name}" | grep ${cluster_name}
garciadeblasc25ac022025-06-17 12:32:23 +0200172 ${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 +0100173 END
174 Log ${rc},${stdout}
175 Should Be Empty ${stdout}
176
177Add OKA Package
178 [Documentation] Add OKA package to OSM
179 [Arguments] ${oka_name} ${oka_folder} ${oka_profile} ${wait_flag}=True
180 ${rc} ${stdout}= Run And Return Rc And Output
181 ... osm oka-add ${oka_name} ${oka_folder} --description ${oka_name} --profile-type ${oka_profile}
182 Log ${rc},${stdout}
183 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=OKA addition failed: ${stdout}
184 ${oka_id}= Set Variable ${stdout}
185 Log ${oka_id}
186 IF ${wait_flag} == True
187 Wait Until Keyword Succeeds ${OKA_OPERATION_MAX_WAIT_TIME} ${OKA_OPERATION_POL_TIME}
188 ... Check For OKA To Be Ready ${oka_id}
189 END
190 RETURN ${oka_id}
191
192Delete OKA Package
193 [Documentation] Delete OKA package from OSM
194 [Arguments] ${oka_name} ${wait_flag}=True
195 ${rc} ${stdout}= Run And Return Rc And Output
196 ... osm oka-delete ${oka_name}
197 Log ${rc},${stdout}
198 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=OKA deletion failed: ${stdout}
199 IF ${wait_flag} == True
200 Wait Until Keyword Succeeds ${OKA_OPERATION_MAX_WAIT_TIME} ${OKA_OPERATION_POL_TIME}
201 ... Check For OKA To Be Deleted ${oka_name}
202 END
203
204Check For OKA To Be Ready
205 [Documentation] Check if an OKA is ready (the resourceState must be READY).
206 [Arguments] ${oka_name}
207 ${rc} ${stdout}= Run And Return Rc And Output osm oka-show ${oka_name}
208 Log ${rc},${stdout}
209 ${rc} ${stdout}= Run And Return Rc And Output osm oka-show ${oka_name} -o jsonpath='{.resourceState}'
210 Log ${rc},${stdout}
211 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
212 Should Be Equal As Strings ${stdout} READY
213
214Check For OKA To Be Deleted
215 [Documentation] Check if an OKA identified by oka_name is not present in OSM.
216 [Arguments] ${oka_name}
217 ${rc} ${output}= Run And Return Rc And Output osm oka-show ${oka_name}
218 Log ${rc},${output}
219 ${matches}= Get Regexp Matches ${oka_name} ^[0-9a-fA-F-]{36}$
220 Log ${matches}
221 IF ${matches} != @{EMPTY}
222 Log ${oka_name} is a valid UUID
garciadeblas71ae92c2025-04-25 13:18:58 +0200223 # ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter _id="${oka_name}" | grep ${oka_name}
garciadeblasc25ac022025-06-17 12:32:23 +0200224 ${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 +0100225 ELSE
226 Log ${oka_name} is not a valid UUID, so it will be treated as a name
garciadeblas71ae92c2025-04-25 13:18:58 +0200227 # ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter name="${oka_name}" | grep ${oka_name}
garciadeblasc25ac022025-06-17 12:32:23 +0200228 ${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 +0100229 END
230 Log ${rc},${stdout}
231 Should Be Empty ${stdout}
232
233Create KSU
234 [Documentation] Create a KSU
garciadeblas76790672025-02-26 11:18:33 +0100235 [Arguments] ${ksu_name} ${ksu_description} ${profile} ${profile_type} ${oka_name} ${ksu_params_file}=${EMPTY} ${wait_flag}=True
236 IF "${ksu_params_file}" != "${EMPTY}"
237 ${rc} ${stdout}= Run And Return Rc And Output
238 ... osm ksu-create --ksu ${ksu_name} --description ${ksu_description} --profile ${profile} --profile-type ${profile_type} --oka ${oka_name} --params ${ksu_params_file}
239 ELSE
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}
242 END
garciadeblas353aeb52025-02-13 10:23:34 +0100243 Log ${rc},${stdout}
244 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=KSU creation failed: ${stdout}
245 ${ksu_id}= Set Variable ${stdout}
246 Log ${ksu_id}
247 IF ${wait_flag} == True
248 Wait Until Keyword Succeeds ${KSU_CREATION_MAX_WAIT_TIME} ${KSU_CREATION_POL_TIME}
249 ... Check For KSU To Be Ready ${ksu_id}
250 END
251 RETURN ${ksu_id}
252
253Delete KSU
254 [Documentation] Delete KSU from OSM
255 [Arguments] ${ksu_name} ${wait_flag}=True
256 ${rc} ${stdout}= Run And Return Rc And Output
257 ... osm ksu-delete ${ksu_name}
258 Log ${rc},${stdout}
259 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=KSU deletion failed: ${stdout}
260 IF ${wait_flag} == True
261 Wait Until Keyword Succeeds ${KSU_DELETION_MAX_WAIT_TIME} ${KSU_DELETION_POL_TIME}
262 ... Check For KSU To Be Deleted ${ksu_name}
263 END
264
265Check For KSU To Be Ready
266 [Documentation] Check if a KSU is ready (the resourceState must be READY).
267 [Arguments] ${ksu_name}
268 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-show ${ksu_name}
269 Log ${rc},${stdout}
270 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-show ${ksu_name} -o jsonpath='{.resourceState}'
271 Log ${rc},${stdout}
272 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
273 Should Be Equal As Strings ${stdout} READY
274
275Check For KSU To Be Deleted
276 [Documentation] Check if a KSU identified by ksu_name is not present in OSM.
277 [Arguments] ${ksu_name}
278 ${rc} ${output}= Run And Return Rc And Output osm ksu-show ${ksu_name}
279 Log ${rc},${output}
280 ${matches}= Get Regexp Matches ${ksu_name} ^[0-9a-fA-F-]{36}$
281 Log ${matches}
282 IF ${matches} != @{EMPTY}
283 Log ${ksu_name} is a valid UUID
garciadeblas590e2952025-04-23 17:05:03 +0200284 # ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter _id="${ksu_name}" | grep ${ksu_name}
garciadeblasc25ac022025-06-17 12:32:23 +0200285 ${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 +0100286 ELSE
287 Log ${ksu_name} is not a valid UUID, so it will be treated as a name
garciadeblas590e2952025-04-23 17:05:03 +0200288 # ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter name="${ksu_name}" | grep ${ksu_name}
289 ${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 +0100290 END
291 Log ${rc},${stdout}
292 Should Be Empty ${stdout}