blob: 23b3c023f7d58c5edc8bc706749b775e52e93e90 [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.
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
garciadeblas590e2952025-04-23 17:05:03 +020060 Wait Until Keyword Succeeds ${CLUSTER_REGISTER_MAX_WAIT_TIME} ${CLUSTER_REGISTER_POL_TIME}
61 ... 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
74 Catenate ${command} --bootstrap
75 ELSE
76 Catenate ${command} --no-bootstrap
77 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
garciadeblas353aeb52025-02-13 10:23:34 +010085 Wait Until Keyword Succeeds ${CLUSTER_LAUNCH_MAX_WAIT_TIME} ${CLUSTER_LAUNCH_POL_TIME}
86 ... 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
garciadeblas590e2952025-04-23 17:05:03 +0200105 [Documentation] Delete a Kubernetes cluster from OSM.
garciadeblas353aeb52025-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
garciadeblas590e2952025-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
garciadeblas353aeb52025-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
164 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter _id="${cluster_name}" | grep ${cluster_name}
165 ELSE
166 Log ${cluster_name} is not a valid UUID, so it will be treated as a name
167 ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter name="${cluster_name}" | grep ${cluster_name}
168 END
169 Log ${rc},${stdout}
170 Should Be Empty ${stdout}
171
172Add OKA Package
173 [Documentation] Add OKA package to OSM
174 [Arguments] ${oka_name} ${oka_folder} ${oka_profile} ${wait_flag}=True
175 ${rc} ${stdout}= Run And Return Rc And Output
176 ... osm oka-add ${oka_name} ${oka_folder} --description ${oka_name} --profile-type ${oka_profile}
177 Log ${rc},${stdout}
178 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=OKA addition failed: ${stdout}
179 ${oka_id}= Set Variable ${stdout}
180 Log ${oka_id}
181 IF ${wait_flag} == True
182 Wait Until Keyword Succeeds ${OKA_OPERATION_MAX_WAIT_TIME} ${OKA_OPERATION_POL_TIME}
183 ... Check For OKA To Be Ready ${oka_id}
184 END
185 RETURN ${oka_id}
186
187Delete OKA Package
188 [Documentation] Delete OKA package from OSM
189 [Arguments] ${oka_name} ${wait_flag}=True
190 ${rc} ${stdout}= Run And Return Rc And Output
191 ... osm oka-delete ${oka_name}
192 Log ${rc},${stdout}
193 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=OKA deletion failed: ${stdout}
194 IF ${wait_flag} == True
195 Wait Until Keyword Succeeds ${OKA_OPERATION_MAX_WAIT_TIME} ${OKA_OPERATION_POL_TIME}
196 ... Check For OKA To Be Deleted ${oka_name}
197 END
198
199Check For OKA To Be Ready
200 [Documentation] Check if an OKA is ready (the resourceState must be READY).
201 [Arguments] ${oka_name}
202 ${rc} ${stdout}= Run And Return Rc And Output osm oka-show ${oka_name}
203 Log ${rc},${stdout}
204 ${rc} ${stdout}= Run And Return Rc And Output osm oka-show ${oka_name} -o jsonpath='{.resourceState}'
205 Log ${rc},${stdout}
206 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
207 Should Be Equal As Strings ${stdout} READY
208
209Check For OKA To Be Deleted
210 [Documentation] Check if an OKA identified by oka_name is not present in OSM.
211 [Arguments] ${oka_name}
212 ${rc} ${output}= Run And Return Rc And Output osm oka-show ${oka_name}
213 Log ${rc},${output}
214 ${matches}= Get Regexp Matches ${oka_name} ^[0-9a-fA-F-]{36}$
215 Log ${matches}
216 IF ${matches} != @{EMPTY}
217 Log ${oka_name} is a valid UUID
218 ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter _id="${oka_name}" | grep ${oka_name}
219 ELSE
220 Log ${oka_name} is not a valid UUID, so it will be treated as a name
221 ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter name="${oka_name}" | grep ${oka_name}
222 END
223 Log ${rc},${stdout}
224 Should Be Empty ${stdout}
225
226Create KSU
227 [Documentation] Create a KSU
garciadeblas76790672025-02-26 11:18:33 +0100228 [Arguments] ${ksu_name} ${ksu_description} ${profile} ${profile_type} ${oka_name} ${ksu_params_file}=${EMPTY} ${wait_flag}=True
229 IF "${ksu_params_file}" != "${EMPTY}"
230 ${rc} ${stdout}= Run And Return Rc And Output
231 ... osm ksu-create --ksu ${ksu_name} --description ${ksu_description} --profile ${profile} --profile-type ${profile_type} --oka ${oka_name} --params ${ksu_params_file}
232 ELSE
233 ${rc} ${stdout}= Run And Return Rc And Output
234 ... osm ksu-create --ksu ${ksu_name} --description ${ksu_description} --profile ${profile} --profile-type ${profile_type} --oka ${oka_name}
235 END
garciadeblas353aeb52025-02-13 10:23:34 +0100236 Log ${rc},${stdout}
237 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=KSU creation failed: ${stdout}
238 ${ksu_id}= Set Variable ${stdout}
239 Log ${ksu_id}
240 IF ${wait_flag} == True
241 Wait Until Keyword Succeeds ${KSU_CREATION_MAX_WAIT_TIME} ${KSU_CREATION_POL_TIME}
242 ... Check For KSU To Be Ready ${ksu_id}
243 END
244 RETURN ${ksu_id}
245
246Delete KSU
247 [Documentation] Delete KSU from OSM
248 [Arguments] ${ksu_name} ${wait_flag}=True
249 ${rc} ${stdout}= Run And Return Rc And Output
250 ... osm ksu-delete ${ksu_name}
251 Log ${rc},${stdout}
252 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=KSU deletion failed: ${stdout}
253 IF ${wait_flag} == True
254 Wait Until Keyword Succeeds ${KSU_DELETION_MAX_WAIT_TIME} ${KSU_DELETION_POL_TIME}
255 ... Check For KSU To Be Deleted ${ksu_name}
256 END
257
258Check For KSU To Be Ready
259 [Documentation] Check if a KSU is ready (the resourceState must be READY).
260 [Arguments] ${ksu_name}
261 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-show ${ksu_name}
262 Log ${rc},${stdout}
263 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-show ${ksu_name} -o jsonpath='{.resourceState}'
264 Log ${rc},${stdout}
265 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
266 Should Be Equal As Strings ${stdout} READY
267
268Check For KSU To Be Deleted
269 [Documentation] Check if a KSU identified by ksu_name is not present in OSM.
270 [Arguments] ${ksu_name}
271 ${rc} ${output}= Run And Return Rc And Output osm ksu-show ${ksu_name}
272 Log ${rc},${output}
273 ${matches}= Get Regexp Matches ${ksu_name} ^[0-9a-fA-F-]{36}$
274 Log ${matches}
275 IF ${matches} != @{EMPTY}
276 Log ${ksu_name} is a valid UUID
garciadeblas590e2952025-04-23 17:05:03 +0200277 # ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter _id="${ksu_name}" | grep ${ksu_name}
278 ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter _id="${ksu_name}" -o jsonpath='[*].name'| grep -E "\^${ksu_name}\$""
garciadeblas353aeb52025-02-13 10:23:34 +0100279 ELSE
280 Log ${ksu_name} is not a valid UUID, so it will be treated as a name
garciadeblas590e2952025-04-23 17:05:03 +0200281 # ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter name="${ksu_name}" | grep ${ksu_name}
282 ${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 +0100283 END
284 Log ${rc},${stdout}
285 Should Be Empty ${stdout}