From ec15323fe93ff836b14ada05b15356241367c7ec Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Fri, 1 Aug 2025 10:13:03 +0200 Subject: [PATCH] Feature 11057: Cluster management in Openshift-based infrastructures Change-Id: I2600a510fb18fc52b42fb23bc3cb14698114cb24 Signed-off-by: garciadeblas --- .../lib/advanced_cluster_mgmt_lib.resource | 5 +- ...gitops_04-openshift_cluster_creation.robot | 169 ++++++++++++++++++ 2 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 robot-systest/testsuite/gitops_04-openshift_cluster_creation.robot diff --git a/robot-systest/lib/advanced_cluster_mgmt_lib.resource b/robot-systest/lib/advanced_cluster_mgmt_lib.resource index fa2d47d..4389315 100644 --- a/robot-systest/lib/advanced_cluster_mgmt_lib.resource +++ b/robot-systest/lib/advanced_cluster_mgmt_lib.resource @@ -67,7 +67,7 @@ Create Cluster Register Cluster [Documentation] Register a Kubernetes cluster in OSM using a provided name and kubeconfig credentials. - [Arguments] ${name} ${vim_account} ${creds} ${description} ${bootstrap_flag}=True ${wait_flag}=True + [Arguments] ${name} ${vim_account} ${creds} ${description} ${bootstrap_flag}=True ${openshift_flag}=False ${wait_flag}=True ${command}= Catenate ... osm cluster-register ${name} ... --vim-account ${vim_account} @@ -78,6 +78,9 @@ Register Cluster ELSE ${command}= Catenate ${command} --no-bootstrap END + IF ${openshift_flag} == True + ${command}= Catenate ${command} --openshift + END ${rc} ${stdout}= Run And Return Rc And Output ${command} Log ${rc},${stdout} Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=Cluster registration failed: ${stdout} diff --git a/robot-systest/testsuite/gitops_04-openshift_cluster_creation.robot b/robot-systest/testsuite/gitops_04-openshift_cluster_creation.robot new file mode 100644 index 0000000..5984762 --- /dev/null +++ b/robot-systest/testsuite/gitops_04-openshift_cluster_creation.robot @@ -0,0 +1,169 @@ +*** Comments *** +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +*** Settings *** +Documentation [GITOPS-04] Cluster creation in Openshift via ACM + +Library OperatingSystem +Library String +Library Collections +Library Process + +Resource ../lib/advanced_cluster_mgmt_lib.resource +Resource ../lib/vim_lib.resource + +Test Tags gitops_04 cluster_gitops + +Suite Teardown Run Keyword And Ignore Error Suite Cleanup + + +*** Variables *** +# OKA packages +${OKA_FOLDER} '%{PACKAGES_FOLDER}/oka' +${OKA1_PKG} apps/jenkins +${OKA1_NAME} jenkins +${OKA1_PROFILE} app-profile +${OKA_NS_PKG} apps/namespace +${OKA_NS_NAME} namespace +${OKA_NS_PROFILE} app-profile + +# VIM and Clusters +${VIM_NAME} gitops04vim +${ACM_CLUSTER_NAME} acm-gitops04 +${ACM_CLUSTER_DESCRIPTION} "ACM Cluster for gitops04 Robot test suite" +${CLUSTER_NAME} gitops04 +${CLUSTER_DESCRIPTION} "Cluster for gitops04 Robot test suite" +${CLUSTER_VM_SIZE} m1.large +${CLUSTER_NODES} 1 +${REGION_NAME} northeurope +${RESOURCE_GROUP} OSM-CTIO +${KUBERNETES_VERSION} "1.31.7" +${OPENSHIFT_RELEASE} "4.18.13-multi" +${CLUSTER_CONFIG} --config '{"openshift": {"openshift-release": ${OPENSHIFT_RELEASE}, "worker-cores": "8", "workder-memory": "16", "worker-disk": "100", "storage-class": "ocs-storagecluster-ceph-rbd", "base-domain": "base.domain.com", "acm-cluster": ${ACM_CLUSTER_NAME}, "hosted-clusters-project": "clusters"}}' + +# KSUs +${KSU_NS_NAME} jenkins-ns +${KSU1_NAME} jenkins +${KSU1_PARAMS} ${CURDIR}/../resources/gitops-jenkins-params.yaml +${KSU_NS_ID} ${EMPTY} +${KSU1_ID} ${EMPTY} + + +*** Test Cases *** +Create Dummy VIM For The Testsuite + [Documentation] Create dummy VIM for the testsuite. + [Tags] vim acm-cluster create + ${vim_id}= Create VIM Target ${VIM_NAME} u p http://localhost/dummy t dummy + Set Suite Variable ${VIM_ID} ${vim_id} + +Add OKA Packages For The Testsuite + [Documentation] Add OKA packages for the testsuite. + [Tags] oka create + Add OKA Package ${OKA_NS_NAME} '${OKA_FOLDER}/${OKA_NS_PKG}' ${OKA_NS_PROFILE} + Add OKA Package ${OKA1_NAME} '${OKA_FOLDER}/${OKA1_PKG}' ${OKA1_PROFILE} + +Register ACM Cluster For Testsuite + [Documentation] Register ACM K8s cluster for the testsuite. + [Tags] acm-cluster create + ${id}= Register Cluster ${ACM_CLUSTER_NAME} ${VIM_NAME} %{ACM_CLUSTER_KUBECONFIG_CREDENTIALS} ${ACM_CLUSTER_DESCRIPTION} + Set Suite Variable ${ACM_CLUSTER_ID} ${id} + Log ${ACM_CLUSTER_ID} + +Get Cluster Kubeconfig + [Documentation] Get Kubeconfig for the ACM cluster. + [Tags] acm-cluster + ${rc} ${stdout}= Run And Return Rc And Output + ... osm cluster-show ${ACM_CLUSTER_NAME} -o jsonpath='{.credentials}' | yq -y + Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} + Log ${stdout} + +Create Openshift Cluster + [Documentation] Create Openshift K8s cluster for the testsuite. + [Tags] cluster create + ${id}= Create Cluster ${CLUSTER_NAME} ${VIM_NAME} ${CLUSTER_DESCRIPTION} ${CLUSTER_VM_SIZE} ${KUBERNETES_VERSION} ${CLUSTER_NODES} ${REGION_NAME} ${RESOURCE_GROUP} ${CLUSTER_CONFIG} + Set Suite Variable ${CLUSTER_ID} ${id} + Log ${CLUSTER_ID} + +Get Openshift Cluster Kubeconfig + [Documentation] Get Kubeconfig for the Openshift cluster. + [Tags] cluster + ${rc} ${stdout}= Run And Return Rc And Output + ... osm cluster-show ${CLUSTER_NAME} -o jsonpath='{.credentials}' | yq -y + Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} + Log ${stdout} + +Create KSU Namespace For All KSUs + [Documentation] Create KSU based on ${OKA_NS_NAME} with params. + [Tags] ksu ksu-ns create + ${id}= Create KSU ${KSU_NS_NAME} ${KSU_NS_NAME} ${CLUSTER_NAME} app-profile ${OKA_NS_NAME} ${OKA_FOLDER}/apps/jenkins-ns-params.yaml + Set Suite Variable ${KSU_NS_ID} ${id} + Log ${KSU_NS_ID} + +Create KSU1 With Params + [Documentation] Create KSU based on ${OKA1_NAME} with params. + [Tags] ksu ksu1 create + ${id}= Create KSU ${KSU1_NAME} ${KSU1_NAME} ${CLUSTER_NAME} app-profile ${OKA1_NAME} ${KSU1_PARAMS} + Set Suite Variable ${KSU1_ID} ${id} + Log ${KSU1_ID} + +Delete KSU1 + [Documentation] Delete KSU1 based on ${OKA1_NAME}. + [Tags] cleanup ksu ksu1 + IF '${KSU1_ID}' != '' + ${KSU_TO_BE_DELETED}= Set Variable ${KSU1_ID} + ELSE + ${KSU_TO_BE_DELETED}= Set Variable ${KSU1_NAME} + END + Delete KSU ${KSU_TO_BE_DELETED} + +Delete KSU Namespace + [Documentation] Delete KSU based on ${OKA_NS_NAME}. + [Tags] cleanup ksu ksu-ns + IF '${KSU_NS_ID}' != '' + ${KSU_TO_BE_DELETED}= Set Variable ${KSU_NS_ID} + ELSE + ${KSU_TO_BE_DELETED}= Set Variable ${KSU_NS_NAME} + END + Delete KSU ${KSU_TO_BE_DELETED} + +Delete Cluster For Testsuite + [Documentation] Delete K8s cluster for the testsuite. + [Tags] cleanup cluster + Delete Cluster ${CLUSTER_NAME} + +Deregister ACM Cluster For Testsuite + [Documentation] Deregister ACM K8s cluster for the testsuite. + [Tags] cleanup acm-cluster + Deregister Cluster ${ACM_CLUSTER_NAME} + +Delete Dummy VIM For The Testsuite + [Documentation] Delete dummy VIM for the testsuite. + [Tags] vim acm-cluster cleanup + Delete VIM Target ${VIM_NAME} + +Delete OKA Packages For The Testsuite + [Documentation] Delete OKA packages for the testsuite. + [Tags] cleanup oka + Delete OKA Package ${OKA_NS_NAME} + Delete OKA Package ${OKA1_NAME} + + +*** Keywords *** +Suite Cleanup + [Documentation] Test Suit Cleanup: Deleting cluster, KSUs, OKAs + Run Keyword If Any Tests Failed Delete Cluster ${CLUSTER_NAME} + Run Keyword If Any Tests Failed Deregister Cluster ${ACM_CLUSTER_NAME} + Run Keyword If Any Tests Failed Delete VIM Target ${VIM_NAME} + Run Keyword If Any Tests Failed Delete OKA Package ${OKA_NS_NAME} + Run Keyword If Any Tests Failed Delete OKA Package ${OKA1_NAME} -- 2.25.1