| 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 |
| 26 | ${CLUSTER_LAUNCH_MAX_WAIT_TIME} 12min |
| 27 | ${CLUSTER_LAUNCH_POL_TIME} 30sec |
| 28 | ${CLUSTER_DELETE_MAX_WAIT_TIME} 12min |
| 29 | ${CLUSTER_DELETE_POL_TIME} 30sec |
| 30 | ${OKA_OPERATION_MAX_WAIT_TIME} 5min |
| 31 | ${OKA_OPERATION_POL_TIME} 15sec |
| garciadeblas | 3ea9114 | 2025-02-26 11:18:33 +0100 | [diff] [blame] | 32 | ${KSU_CREATION_MAX_WAIT_TIME} 7min |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 33 | ${KSU_CREATION_POL_TIME} 30sec |
| garciadeblas | 3ea9114 | 2025-02-26 11:18:33 +0100 | [diff] [blame] | 34 | ${KSU_DELETION_MAX_WAIT_TIME} 5min |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 35 | ${KSU_DELETION_POL_TIME} 15sec |
| 36 | |
| 37 | |
| 38 | *** Keywords *** |
| 39 | Create Cluster |
| 40 | [Documentation] Create a Kubernetes cluster in OSM using the name, version, nodes, etc., passed as arguments. |
| 41 | [Arguments] ${name} ${vim_account} ${description} ${vm_size} ${version} ${nodes} ${region} ${resource_group} ${wait_flag}=True |
| 42 | ${command}= Catenate |
| 43 | ... osm cluster-create ${name} |
| 44 | ... --node-count ${nodes} |
| 45 | ... --node-size ${vm_size} |
| 46 | ... --version ${version} |
| 47 | ... --vim-account ${vim_account} |
| 48 | ... --description ${description} |
| 49 | ... --region-name ${region} |
| 50 | ... --resource-group ${resource_group} |
| 51 | ${rc} ${stdout}= Run And Return Rc And Output ${command} |
| 52 | Log ${rc},${stdout} |
| 53 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster creation failed: ${stdout} |
| 54 | ${cluster_id}= Set Variable ${stdout} |
| 55 | Log ${cluster_id} |
| 56 | Check Cluster Age Keys ${cluster_id} |
| 57 | IF ${wait_flag} == True |
| 58 | Wait Until Keyword Succeeds ${CLUSTER_LAUNCH_MAX_WAIT_TIME} ${CLUSTER_LAUNCH_POL_TIME} |
| 59 | ... Check For Cluster To Be Ready ${name} |
| 60 | END |
| 61 | RETURN ${cluster_id} |
| 62 | |
| 63 | Check Cluster Age Keys |
| 64 | [Documentation] Check AGE keys in the cluster |
| 65 | [Arguments] ${cluster_name} |
| 66 | ${rc} ${stdout}= Run And Return Rc And Output |
| 67 | ... osm cluster-show ${cluster_name} -o jsonpath='{.age_privkey}' |
| 68 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 69 | # TODO: Check if privkey contains the expected value |
| 70 | Log privkey is ${stdout} |
| 71 | ${rc} ${stdout}= Run And Return Rc And Output |
| 72 | ... osm cluster-show ${cluster_name} -o jsonpath='{.age_pubkey}' |
| 73 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 74 | # TODO: Check if pubkey contains the expected value |
| 75 | Log pubkey is ${stdout} |
| 76 | |
| 77 | Delete Cluster |
| 78 | [Documentation] Unregister/delete a Kubernetes cluster from OSM. |
| 79 | [Arguments] ${cluster_name} ${wait_flag}=True |
| 80 | ${rc} ${stdout}= Run And Return Rc And Output osm cluster-delete ${cluster_name} |
| 81 | Log ${rc},${stdout} |
| 82 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster deletion failed: ${stdout} |
| 83 | IF ${wait_flag} == True |
| 84 | Wait Until Keyword Succeeds ${CLUSTER_DELETE_MAX_WAIT_TIME} ${CLUSTER_DELETE_POL_TIME} |
| 85 | ... Check For Cluster Deletion Status ${cluster_name} |
| 86 | END |
| 87 | |
| 88 | Check For Cluster Deletion Status |
| 89 | [Documentation] Check if a Kubernetes cluster identified by name is deleted or in error state. |
| 90 | [Arguments] ${cluster_name} |
| 91 | ${rc} ${output}= Run And Return Rc And Output osm cluster-show ${cluster_name} |
| 92 | Log ${rc},${output} |
| 93 | ${rc} ${resourceState}= Run And Return Rc And Output osm cluster-show ${cluster_name} -o jsonpath='{.resourceState}' |
| 94 | Log ${rc},${resourceState} |
| 95 | IF '$rc' == '$SUCCESS_RETURN_CODE' and '$resourceState' == 'ERROR' |
| 96 | Fail Cluster is in error state and will not be deleted. |
| 97 | ELSE |
| 98 | Log Either the cluster ${cluster_name} has been deleted or it is in a valid state. |
| 99 | Check For Cluster To Be Deleted ${cluster_name} |
| 100 | END |
| 101 | |
| 102 | Get Clusters |
| 103 | [Documentation] Get the list of Kubernetes clusters in OSM, and return it. |
| 104 | ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list |
| 105 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 106 | Log ${stdout} |
| 107 | RETURN ${stdout} |
| 108 | |
| 109 | Check For Cluster To Be Ready |
| 110 | [Documentation] Check if a Kubernetes cluster is ready (the resourceState must be READY). |
| 111 | [Arguments] ${cluster_name} |
| 112 | ${rc} ${stdout}= Run And Return Rc And Output osm cluster-show ${cluster_name} |
| 113 | Log ${rc},${stdout} |
| 114 | ${rc} ${stdout}= Run And Return Rc And Output osm cluster-show ${cluster_name} -o jsonpath='{.resourceState}' |
| 115 | Log ${rc},${stdout} |
| 116 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 117 | Should Be Equal As Strings ${stdout} READY |
| 118 | |
| 119 | Check For Cluster To Be Deleted |
| 120 | [Documentation] Check if a Kubernetes cluster identified by name is not present in OSM. |
| 121 | [Arguments] ${cluster_name} |
| 122 | ${matches}= Get Regexp Matches ${cluster_name} ^[0-9a-fA-F-]{36}$ |
| 123 | Log ${matches} |
| 124 | IF ${matches} != @{EMPTY} |
| 125 | Log ${cluster_name} is a valid UUID |
| 126 | ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter _id="${cluster_name}" | grep ${cluster_name} |
| 127 | ELSE |
| 128 | Log ${cluster_name} is not a valid UUID, so it will be treated as a name |
| 129 | ${rc} ${stdout}= Run And Return Rc And Output osm cluster-list --filter name="${cluster_name}" | grep ${cluster_name} |
| 130 | END |
| 131 | Log ${rc},${stdout} |
| 132 | Should Be Empty ${stdout} |
| 133 | |
| 134 | Add OKA Package |
| 135 | [Documentation] Add OKA package to OSM |
| 136 | [Arguments] ${oka_name} ${oka_folder} ${oka_profile} ${wait_flag}=True |
| 137 | ${rc} ${stdout}= Run And Return Rc And Output |
| 138 | ... osm oka-add ${oka_name} ${oka_folder} --description ${oka_name} --profile-type ${oka_profile} |
| 139 | Log ${rc},${stdout} |
| 140 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=OKA addition failed: ${stdout} |
| 141 | ${oka_id}= Set Variable ${stdout} |
| 142 | Log ${oka_id} |
| 143 | IF ${wait_flag} == True |
| 144 | Wait Until Keyword Succeeds ${OKA_OPERATION_MAX_WAIT_TIME} ${OKA_OPERATION_POL_TIME} |
| 145 | ... Check For OKA To Be Ready ${oka_id} |
| 146 | END |
| 147 | RETURN ${oka_id} |
| 148 | |
| 149 | Delete OKA Package |
| 150 | [Documentation] Delete OKA package from OSM |
| 151 | [Arguments] ${oka_name} ${wait_flag}=True |
| 152 | ${rc} ${stdout}= Run And Return Rc And Output |
| 153 | ... osm oka-delete ${oka_name} |
| 154 | Log ${rc},${stdout} |
| 155 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=OKA deletion failed: ${stdout} |
| 156 | IF ${wait_flag} == True |
| 157 | Wait Until Keyword Succeeds ${OKA_OPERATION_MAX_WAIT_TIME} ${OKA_OPERATION_POL_TIME} |
| 158 | ... Check For OKA To Be Deleted ${oka_name} |
| 159 | END |
| 160 | |
| 161 | Check For OKA To Be Ready |
| 162 | [Documentation] Check if an OKA is ready (the resourceState must be READY). |
| 163 | [Arguments] ${oka_name} |
| 164 | ${rc} ${stdout}= Run And Return Rc And Output osm oka-show ${oka_name} |
| 165 | Log ${rc},${stdout} |
| 166 | ${rc} ${stdout}= Run And Return Rc And Output osm oka-show ${oka_name} -o jsonpath='{.resourceState}' |
| 167 | Log ${rc},${stdout} |
| 168 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 169 | Should Be Equal As Strings ${stdout} READY |
| 170 | |
| 171 | Check For OKA To Be Deleted |
| 172 | [Documentation] Check if an OKA identified by oka_name is not present in OSM. |
| 173 | [Arguments] ${oka_name} |
| 174 | ${rc} ${output}= Run And Return Rc And Output osm oka-show ${oka_name} |
| 175 | Log ${rc},${output} |
| 176 | ${matches}= Get Regexp Matches ${oka_name} ^[0-9a-fA-F-]{36}$ |
| 177 | Log ${matches} |
| 178 | IF ${matches} != @{EMPTY} |
| 179 | Log ${oka_name} is a valid UUID |
| 180 | ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter _id="${oka_name}" | grep ${oka_name} |
| 181 | ELSE |
| 182 | Log ${oka_name} is not a valid UUID, so it will be treated as a name |
| 183 | ${rc} ${stdout}= Run And Return Rc And Output osm oka-list --filter name="${oka_name}" | grep ${oka_name} |
| 184 | END |
| 185 | Log ${rc},${stdout} |
| 186 | Should Be Empty ${stdout} |
| 187 | |
| 188 | Create KSU |
| 189 | [Documentation] Create a KSU |
| garciadeblas | 3ea9114 | 2025-02-26 11:18:33 +0100 | [diff] [blame] | 190 | [Arguments] ${ksu_name} ${ksu_description} ${profile} ${profile_type} ${oka_name} ${ksu_params_file}=${EMPTY} ${wait_flag}=True |
| 191 | IF "${ksu_params_file}" != "${EMPTY}" |
| 192 | ${rc} ${stdout}= Run And Return Rc And Output |
| 193 | ... osm ksu-create --ksu ${ksu_name} --description ${ksu_description} --profile ${profile} --profile-type ${profile_type} --oka ${oka_name} --params ${ksu_params_file} |
| 194 | ELSE |
| 195 | ${rc} ${stdout}= Run And Return Rc And Output |
| 196 | ... osm ksu-create --ksu ${ksu_name} --description ${ksu_description} --profile ${profile} --profile-type ${profile_type} --oka ${oka_name} |
| 197 | END |
| garciadeblas | 0d27ceb | 2025-02-13 10:23:34 +0100 | [diff] [blame] | 198 | Log ${rc},${stdout} |
| 199 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=KSU creation failed: ${stdout} |
| 200 | ${ksu_id}= Set Variable ${stdout} |
| 201 | Log ${ksu_id} |
| 202 | IF ${wait_flag} == True |
| 203 | Wait Until Keyword Succeeds ${KSU_CREATION_MAX_WAIT_TIME} ${KSU_CREATION_POL_TIME} |
| 204 | ... Check For KSU To Be Ready ${ksu_id} |
| 205 | END |
| 206 | RETURN ${ksu_id} |
| 207 | |
| 208 | Delete KSU |
| 209 | [Documentation] Delete KSU from OSM |
| 210 | [Arguments] ${ksu_name} ${wait_flag}=True |
| 211 | ${rc} ${stdout}= Run And Return Rc And Output |
| 212 | ... osm ksu-delete ${ksu_name} |
| 213 | Log ${rc},${stdout} |
| 214 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=KSU deletion failed: ${stdout} |
| 215 | IF ${wait_flag} == True |
| 216 | Wait Until Keyword Succeeds ${KSU_DELETION_MAX_WAIT_TIME} ${KSU_DELETION_POL_TIME} |
| 217 | ... Check For KSU To Be Deleted ${ksu_name} |
| 218 | END |
| 219 | |
| 220 | Check For KSU To Be Ready |
| 221 | [Documentation] Check if a KSU is ready (the resourceState must be READY). |
| 222 | [Arguments] ${ksu_name} |
| 223 | ${rc} ${stdout}= Run And Return Rc And Output osm ksu-show ${ksu_name} |
| 224 | Log ${rc},${stdout} |
| 225 | ${rc} ${stdout}= Run And Return Rc And Output osm ksu-show ${ksu_name} -o jsonpath='{.resourceState}' |
| 226 | Log ${rc},${stdout} |
| 227 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 228 | Should Be Equal As Strings ${stdout} READY |
| 229 | |
| 230 | Check For KSU To Be Deleted |
| 231 | [Documentation] Check if a KSU identified by ksu_name is not present in OSM. |
| 232 | [Arguments] ${ksu_name} |
| 233 | ${rc} ${output}= Run And Return Rc And Output osm ksu-show ${ksu_name} |
| 234 | Log ${rc},${output} |
| 235 | ${matches}= Get Regexp Matches ${ksu_name} ^[0-9a-fA-F-]{36}$ |
| 236 | Log ${matches} |
| 237 | IF ${matches} != @{EMPTY} |
| 238 | Log ${ksu_name} is a valid UUID |
| 239 | ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter _id="${ksu_name}" | grep ${ksu_name} |
| 240 | ELSE |
| 241 | Log ${ksu_name} is not a valid UUID, so it will be treated as a name |
| 242 | ${rc} ${stdout}= Run And Return Rc And Output osm ksu-list --filter name="${ksu_name}" | grep ${ksu_name} |
| 243 | END |
| 244 | Log ${rc},${stdout} |
| 245 | Should Be Empty ${stdout} |