| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 1 | *** 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 *** |
| 18 | Documentation Library providing keywords for CRUD operations over clusters, |
| 19 | ... OKAs and KSUs with OSM client. |
| 20 | Library OperatingSystem |
| 21 | Library String |
| 22 | |
| 23 | |
| 24 | *** Variables *** |
| 25 | ${SUCCESS_RETURN_CODE} 0 |
| garciadeblas | 69ee33d | 2025-10-08 16:59:09 +0200 | [diff] [blame] | 26 | ${CLUSTER_CREATE_MAX_WAIT_TIME} 16min |
| 27 | ${CLUSTER_CREATE_POL_TIME} 30sec |
| 28 | ${CLUSTER_REGISTER_MAX_WAIT_TIME} 16min |
| garciadeblas | b62d994 | 2025-04-23 17:05:03 +0200 | [diff] [blame] | 29 | ${CLUSTER_REGISTER_POL_TIME} 30sec |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 30 | ${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 |
| garciadeblas | 3ea9114 | 2025-02-26 11:18:33 +0100 | [diff] [blame] | 34 | ${KSU_CREATION_MAX_WAIT_TIME} 7min |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 35 | ${KSU_CREATION_POL_TIME} 30sec |
| garciadeblas | 3ea9114 | 2025-02-26 11:18:33 +0100 | [diff] [blame] | 36 | ${KSU_DELETION_MAX_WAIT_TIME} 5min |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 37 | ${KSU_DELETION_POL_TIME} 15sec |
| 38 | |
| 39 | |
| 40 | *** Keywords *** |
| 41 | Create 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 |
| garciadeblas | 69ee33d | 2025-10-08 16:59:09 +0200 | [diff] [blame] | 60 | Wait Until Keyword Succeeds ${CLUSTER_CREATE_MAX_WAIT_TIME} ${CLUSTER_CREATE_POL_TIME} |
| garciadeblas | b62d994 | 2025-04-23 17:05:03 +0200 | [diff] [blame] | 61 | ... Check For Cluster To Be Ready ${name} |
| 62 | END |
| 63 | RETURN ${cluster_id} |
| 64 | |
| 65 | Register 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 |
| garciadeblas | e7cd830 | 2025-06-17 12:40:07 +0200 | [diff] [blame] | 74 | ${command}= Catenate ${command} --bootstrap |
| garciadeblas | b62d994 | 2025-04-23 17:05:03 +0200 | [diff] [blame] | 75 | ELSE |
| garciadeblas | e7cd830 | 2025-06-17 12:40:07 +0200 | [diff] [blame] | 76 | ${command}= Catenate ${command} --no-bootstrap |
| garciadeblas | b62d994 | 2025-04-23 17:05:03 +0200 | [diff] [blame] | 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 |
| garciadeblas | 69ee33d | 2025-10-08 16:59:09 +0200 | [diff] [blame] | 85 | Wait Until Keyword Succeeds ${CLUSTER_REGISTER_MAX_WAIT_TIME} ${CLUSTER_REGISTER_POL_TIME} |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 86 | ... Check For Cluster To Be Ready ${name} |
| 87 | END |
| 88 | RETURN ${cluster_id} |
| 89 | |
| 90 | Check 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 | |
| 104 | Delete Cluster |
| garciadeblas | b62d994 | 2025-04-23 17:05:03 +0200 | [diff] [blame] | 105 | [Documentation] Delete a Kubernetes cluster from OSM. |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 106 | [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 | |
| garciadeblas | b62d994 | 2025-04-23 17:05:03 +0200 | [diff] [blame] | 115 | Deregister 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 | |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 126 | Check 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 | |
| 140 | Get 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 | |
| 147 | Check 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 | |
| 157 | Check 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 |
| garciadeblas | e203506 | 2025-04-25 13:18:58 +0200 | [diff] [blame] | 164 | # ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter _id="${cluster_name}" | grep ${cluster_name} |
| garciadeblas | 16e878c | 2025-06-17 12:32:23 +0200 | [diff] [blame] | 165 | ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter _id="${cluster_name}" -o jsonpath='[*]._id'| grep -E "\^${cluster_name}\$" |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 166 | ELSE |
| 167 | Log ${cluster_name} is not a valid UUID, so it will be treated as a name |
| garciadeblas | e203506 | 2025-04-25 13:18:58 +0200 | [diff] [blame] | 168 | # ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter name="${cluster_name}" | grep ${cluster_name} |
| garciadeblas | 16e878c | 2025-06-17 12:32:23 +0200 | [diff] [blame] | 169 | ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter name="${cluster_name}" -o jsonpath='[*].name'| grep -E "\^${cluster_name}\$" |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 170 | END |
| 171 | Log ${rc},${stdout} |
| 172 | Should Be Empty ${stdout} |
| 173 | |
| 174 | Add 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 | |
| 189 | Delete 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 | |
| 201 | Check 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 | |
| 211 | Check 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 |
| garciadeblas | e203506 | 2025-04-25 13:18:58 +0200 | [diff] [blame] | 220 | # ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter _id="${oka_name}" | grep ${oka_name} |
| garciadeblas | 16e878c | 2025-06-17 12:32:23 +0200 | [diff] [blame] | 221 | ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter _id="${oka_name}" -o jsonpath='[*]._id'| grep -E "\^${oka_name}\$" |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 222 | ELSE |
| 223 | Log ${oka_name} is not a valid UUID, so it will be treated as a name |
| garciadeblas | e203506 | 2025-04-25 13:18:58 +0200 | [diff] [blame] | 224 | # ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter name="${oka_name}" | grep ${oka_name} |
| garciadeblas | 16e878c | 2025-06-17 12:32:23 +0200 | [diff] [blame] | 225 | ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter name="${oka_name}" -o jsonpath='[*].name'| grep -E "\^${oka_name}\$" |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 226 | END |
| 227 | Log ${rc},${stdout} |
| 228 | Should Be Empty ${stdout} |
| 229 | |
| 230 | Create KSU |
| 231 | [Documentation] Create a KSU |
| garciadeblas | 3ea9114 | 2025-02-26 11:18:33 +0100 | [diff] [blame] | 232 | [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 |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 240 | 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 | |
| 250 | Delete 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 | |
| 262 | Check 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 | |
| 272 | Check 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 |
| garciadeblas | b62d994 | 2025-04-23 17:05:03 +0200 | [diff] [blame] | 281 | # ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter _id="${ksu_name}" | grep ${ksu_name} |
| garciadeblas | 16e878c | 2025-06-17 12:32:23 +0200 | [diff] [blame] | 282 | ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter _id="${ksu_name}" -o jsonpath='[*]._id'| grep -E "\^${ksu_name}\$" |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 283 | ELSE |
| 284 | Log ${ksu_name} is not a valid UUID, so it will be treated as a name |
| garciadeblas | b62d994 | 2025-04-23 17:05:03 +0200 | [diff] [blame] | 285 | # ${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}\$" |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 287 | END |
| 288 | Log ${rc},${stdout} |
| 289 | Should Be Empty ${stdout} |