blob: 6c1a0ce7134baf080b3e62b270ed2c1312d08c88 [file] [log] [blame]
garciadeblas0d27ceb2025-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
garciadeblas69ee33d2025-10-08 16:59:09 +020026${CLUSTER_CREATE_MAX_WAIT_TIME} 16min
27${CLUSTER_CREATE_POL_TIME} 30sec
28${CLUSTER_REGISTER_MAX_WAIT_TIME} 16min
garciadeblasb62d9942025-04-23 17:05:03 +020029${CLUSTER_REGISTER_POL_TIME} 30sec
garciadeblas0d27ceb2025-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
garciadeblas3ea91142025-02-26 11:18:33 +010034${KSU_CREATION_MAX_WAIT_TIME} 7min
garciadeblas0d27ceb2025-02-13 10:23:34 +010035${KSU_CREATION_POL_TIME} 30sec
garciadeblas3ea91142025-02-26 11:18:33 +010036${KSU_DELETION_MAX_WAIT_TIME} 5min
garciadeblas0d27ceb2025-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.
43 [Arguments] ${name} ${vim_account} ${description} ${vm_size} ${version} ${nodes} ${region} ${resource_group} ${wait_flag}=True
44 ${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}
53 ${rc} ${stdout}= Run And Return Rc And Output ${command}
54 Log ${rc},${stdout}
55 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster creation failed: ${stdout}
56 ${cluster_id}= Set Variable ${stdout}
57 Log ${cluster_id}
58 Check Cluster Age Keys ${cluster_id}
59 IF ${wait_flag} == True
garciadeblas69ee33d2025-10-08 16:59:09 +020060 Wait Until Keyword Succeeds ${CLUSTER_CREATE_MAX_WAIT_TIME} ${CLUSTER_CREATE_POL_TIME}
garciadeblasb62d9942025-04-23 17:05:03 +020061 ... Check For Cluster To Be Ready ${name}
62 END
63 RETURN ${cluster_id}
64
65Register Cluster
66 [Documentation] Register a Kubernetes cluster in OSM using a provided name and kubeconfig credentials.
67 [Arguments] ${name} ${vim_account} ${creds} ${description} ${bootstrap_flag}=True ${wait_flag}=True
68 ${command}= Catenate
69 ... osm cluster-register ${name}
70 ... --vim-account ${vim_account}
71 ... --creds ${creds}
72 ... --description ${description}
73 IF ${bootstrap_flag} == True
garciadeblase7cd8302025-06-17 12:40:07 +020074 ${command}= Catenate ${command} --bootstrap
garciadeblasb62d9942025-04-23 17:05:03 +020075 ELSE
garciadeblase7cd8302025-06-17 12:40:07 +020076 ${command}= Catenate ${command} --no-bootstrap
garciadeblasb62d9942025-04-23 17:05:03 +020077 END
78 ${rc} ${stdout}= Run And Return Rc And Output ${command}
79 Log ${rc},${stdout}
80 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster registration failed: ${stdout}
81 ${cluster_id}= Set Variable ${stdout}
82 Log ${cluster_id}
83 Check Cluster Age Keys ${cluster_id}
84 IF ${wait_flag} == True
garciadeblas69ee33d2025-10-08 16:59:09 +020085 Wait Until Keyword Succeeds ${CLUSTER_REGISTER_MAX_WAIT_TIME} ${CLUSTER_REGISTER_POL_TIME}
garciadeblas0d27ceb2025-02-13 10:23:34 +010086 ... Check For Cluster To Be Ready ${name}
87 END
88 RETURN ${cluster_id}
89
90Check Cluster Age Keys
91 [Documentation] Check AGE keys in the cluster
92 [Arguments] ${cluster_name}
93 ${rc} ${stdout}= Run And Return Rc And Output
94 ... osm cluster-show ${cluster_name} -o jsonpath='{.age_privkey}'
95 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
96 # TODO: Check if privkey contains the expected value
97 Log privkey is ${stdout}
98 ${rc} ${stdout}= Run And Return Rc And Output
99 ... osm cluster-show ${cluster_name} -o jsonpath='{.age_pubkey}'
100 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
101 # TODO: Check if pubkey contains the expected value
102 Log pubkey is ${stdout}
103
104Delete Cluster
garciadeblasb62d9942025-04-23 17:05:03 +0200105 [Documentation] Delete a Kubernetes cluster from OSM.
garciadeblas0d27ceb2025-02-13 10:23:34 +0100106 [Arguments] ${cluster_name} ${wait_flag}=True
107 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-delete ${cluster_name}
108 Log ${rc},${stdout}
109 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster deletion failed: ${stdout}
110 IF ${wait_flag} == True
111 Wait Until Keyword Succeeds ${CLUSTER_DELETE_MAX_WAIT_TIME} ${CLUSTER_DELETE_POL_TIME}
112 ... Check For Cluster Deletion Status ${cluster_name}
113 END
114
garciadeblasb62d9942025-04-23 17:05:03 +0200115Deregister Cluster
116 [Documentation] Deregister a Kubernetes cluster from OSM.
117 [Arguments] ${cluster_name} ${wait_flag}=True
118 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-deregister ${cluster_name}
119 Log ${rc},${stdout}
120 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster deregistration failed: ${stdout}
121 IF ${wait_flag} == True
122 Wait Until Keyword Succeeds ${CLUSTER_DELETE_MAX_WAIT_TIME} ${CLUSTER_DELETE_POL_TIME}
123 ... Check For Cluster Deletion Status ${cluster_name}
124 END
125
garciadeblas0d27ceb2025-02-13 10:23:34 +0100126Check For Cluster Deletion Status
127 [Documentation] Check if a Kubernetes cluster identified by name is deleted or in error state.
128 [Arguments] ${cluster_name}
129 ${rc} ${output}= Run And Return Rc And Output osm cluster-show ${cluster_name}
130 Log ${rc},${output}
131 ${rc} ${resourceState}= Run And Return Rc And Output osm cluster-show ${cluster_name} -o jsonpath='{.resourceState}'
132 Log ${rc},${resourceState}
133 IF '$rc' == '$SUCCESS_RETURN_CODE' and '$resourceState' == 'ERROR'
134 Fail Cluster is in error state and will not be deleted.
135 ELSE
136 Log Either the cluster ${cluster_name} has been deleted or it is in a valid state.
137 Check For Cluster To Be Deleted ${cluster_name}
138 END
139
140Get Clusters
141 [Documentation] Get the list of Kubernetes clusters in OSM, and return it.
142 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list
143 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
144 Log ${stdout}
145 RETURN ${stdout}
146
147Check For Cluster To Be Ready
148 [Documentation] Check if a Kubernetes cluster is ready (the resourceState must be READY).
149 [Arguments] ${cluster_name}
150 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-show ${cluster_name}
151 Log ${rc},${stdout}
152 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-show ${cluster_name} -o jsonpath='{.resourceState}'
153 Log ${rc},${stdout}
154 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
155 Should Be Equal As Strings ${stdout} READY
156
157Check For Cluster To Be Deleted
158 [Documentation] Check if a Kubernetes cluster identified by name is not present in OSM.
159 [Arguments] ${cluster_name}
160 ${matches}= Get Regexp Matches ${cluster_name} ^[0-9a-fA-F-]{36}$
161 Log ${matches}
162 IF ${matches} != @{EMPTY}
163 Log ${cluster_name} is a valid UUID
garciadeblase2035062025-04-25 13:18:58 +0200164 # ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter _id="${cluster_name}" | grep ${cluster_name}
garciadeblas16e878c2025-06-17 12:32:23 +0200165 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter _id="${cluster_name}" -o jsonpath='[*]._id'| grep -E "\^${cluster_name}\$"
garciadeblas0d27ceb2025-02-13 10:23:34 +0100166 ELSE
167 Log ${cluster_name} is not a valid UUID, so it will be treated as a name
garciadeblase2035062025-04-25 13:18:58 +0200168 # ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter name="${cluster_name}" | grep ${cluster_name}
garciadeblas16e878c2025-06-17 12:32:23 +0200169 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter name="${cluster_name}" -o jsonpath='[*].name'| grep -E "\^${cluster_name}\$"
garciadeblas0d27ceb2025-02-13 10:23:34 +0100170 END
171 Log ${rc},${stdout}
172 Should Be Empty ${stdout}
173
174Add OKA Package
175 [Documentation] Add OKA package to OSM
176 [Arguments] ${oka_name} ${oka_folder} ${oka_profile} ${wait_flag}=True
177 ${rc} ${stdout}= Run And Return Rc And Output
178 ... osm oka-add ${oka_name} ${oka_folder} --description ${oka_name} --profile-type ${oka_profile}
179 Log ${rc},${stdout}
180 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=OKA addition failed: ${stdout}
181 ${oka_id}= Set Variable ${stdout}
182 Log ${oka_id}
183 IF ${wait_flag} == True
184 Wait Until Keyword Succeeds ${OKA_OPERATION_MAX_WAIT_TIME} ${OKA_OPERATION_POL_TIME}
185 ... Check For OKA To Be Ready ${oka_id}
186 END
187 RETURN ${oka_id}
188
189Delete OKA Package
190 [Documentation] Delete OKA package from OSM
191 [Arguments] ${oka_name} ${wait_flag}=True
192 ${rc} ${stdout}= Run And Return Rc And Output
193 ... osm oka-delete ${oka_name}
194 Log ${rc},${stdout}
195 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=OKA deletion failed: ${stdout}
196 IF ${wait_flag} == True
197 Wait Until Keyword Succeeds ${OKA_OPERATION_MAX_WAIT_TIME} ${OKA_OPERATION_POL_TIME}
198 ... Check For OKA To Be Deleted ${oka_name}
199 END
200
201Check For OKA To Be Ready
202 [Documentation] Check if an OKA is ready (the resourceState must be READY).
203 [Arguments] ${oka_name}
204 ${rc} ${stdout}= Run And Return Rc And Output osm oka-show ${oka_name}
205 Log ${rc},${stdout}
206 ${rc} ${stdout}= Run And Return Rc And Output osm oka-show ${oka_name} -o jsonpath='{.resourceState}'
207 Log ${rc},${stdout}
208 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
209 Should Be Equal As Strings ${stdout} READY
210
211Check For OKA To Be Deleted
212 [Documentation] Check if an OKA identified by oka_name is not present in OSM.
213 [Arguments] ${oka_name}
214 ${rc} ${output}= Run And Return Rc And Output osm oka-show ${oka_name}
215 Log ${rc},${output}
216 ${matches}= Get Regexp Matches ${oka_name} ^[0-9a-fA-F-]{36}$
217 Log ${matches}
218 IF ${matches} != @{EMPTY}
219 Log ${oka_name} is a valid UUID
garciadeblase2035062025-04-25 13:18:58 +0200220 # ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter _id="${oka_name}" | grep ${oka_name}
garciadeblas16e878c2025-06-17 12:32:23 +0200221 ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter _id="${oka_name}" -o jsonpath='[*]._id'| grep -E "\^${oka_name}\$"
garciadeblas0d27ceb2025-02-13 10:23:34 +0100222 ELSE
223 Log ${oka_name} is not a valid UUID, so it will be treated as a name
garciadeblase2035062025-04-25 13:18:58 +0200224 # ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter name="${oka_name}" | grep ${oka_name}
garciadeblas16e878c2025-06-17 12:32:23 +0200225 ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter name="${oka_name}" -o jsonpath='[*].name'| grep -E "\^${oka_name}\$"
garciadeblas0d27ceb2025-02-13 10:23:34 +0100226 END
227 Log ${rc},${stdout}
228 Should Be Empty ${stdout}
229
230Create KSU
231 [Documentation] Create a KSU
garciadeblas3ea91142025-02-26 11:18:33 +0100232 [Arguments] ${ksu_name} ${ksu_description} ${profile} ${profile_type} ${oka_name} ${ksu_params_file}=${EMPTY} ${wait_flag}=True
233 IF "${ksu_params_file}" != "${EMPTY}"
234 ${rc} ${stdout}= Run And Return Rc And Output
235 ... osm ksu-create --ksu ${ksu_name} --description ${ksu_description} --profile ${profile} --profile-type ${profile_type} --oka ${oka_name} --params ${ksu_params_file}
236 ELSE
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}
239 END
garciadeblas0d27ceb2025-02-13 10:23:34 +0100240 Log ${rc},${stdout}
241 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=KSU creation failed: ${stdout}
242 ${ksu_id}= Set Variable ${stdout}
243 Log ${ksu_id}
244 IF ${wait_flag} == True
245 Wait Until Keyword Succeeds ${KSU_CREATION_MAX_WAIT_TIME} ${KSU_CREATION_POL_TIME}
246 ... Check For KSU To Be Ready ${ksu_id}
247 END
248 RETURN ${ksu_id}
249
250Delete KSU
251 [Documentation] Delete KSU from OSM
252 [Arguments] ${ksu_name} ${wait_flag}=True
253 ${rc} ${stdout}= Run And Return Rc And Output
254 ... osm ksu-delete ${ksu_name}
255 Log ${rc},${stdout}
256 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=KSU deletion failed: ${stdout}
257 IF ${wait_flag} == True
258 Wait Until Keyword Succeeds ${KSU_DELETION_MAX_WAIT_TIME} ${KSU_DELETION_POL_TIME}
259 ... Check For KSU To Be Deleted ${ksu_name}
260 END
261
262Check For KSU To Be Ready
263 [Documentation] Check if a KSU is ready (the resourceState must be READY).
264 [Arguments] ${ksu_name}
265 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-show ${ksu_name}
266 Log ${rc},${stdout}
267 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-show ${ksu_name} -o jsonpath='{.resourceState}'
268 Log ${rc},${stdout}
269 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
270 Should Be Equal As Strings ${stdout} READY
271
272Check For KSU To Be Deleted
273 [Documentation] Check if a KSU identified by ksu_name is not present in OSM.
274 [Arguments] ${ksu_name}
275 ${rc} ${output}= Run And Return Rc And Output osm ksu-show ${ksu_name}
276 Log ${rc},${output}
277 ${matches}= Get Regexp Matches ${ksu_name} ^[0-9a-fA-F-]{36}$
278 Log ${matches}
279 IF ${matches} != @{EMPTY}
280 Log ${ksu_name} is a valid UUID
garciadeblasb62d9942025-04-23 17:05:03 +0200281 # ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter _id="${ksu_name}" | grep ${ksu_name}
garciadeblas16e878c2025-06-17 12:32:23 +0200282 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter _id="${ksu_name}" -o jsonpath='[*]._id'| grep -E "\^${ksu_name}\$"
garciadeblas0d27ceb2025-02-13 10:23:34 +0100283 ELSE
284 Log ${ksu_name} is not a valid UUID, so it will be treated as a name
garciadeblasb62d9942025-04-23 17:05:03 +0200285 # ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter name="${ksu_name}" | grep ${ksu_name}
286 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter name="${ksu_name}" -o jsonpath='[*].name'| grep -E "\^${ksu_name}\$"
garciadeblas0d27ceb2025-02-13 10:23:34 +0100287 END
288 Log ${rc},${stdout}
289 Should Be Empty ${stdout}