Feature 11072. Enhanced OSM declarative modelling for applications. Model-driven... 05/15305/4
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 28 Jul 2025 17:16:39 +0000 (19:16 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 1 Aug 2025 08:34:01 +0000 (10:34 +0200)
Change-Id: I814a7edfab5f9631b95163d4cfae5f6b63c3ffe7
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
robot-systest/lib/advanced_cluster_mgmt_lib.resource
robot-systest/lib/app_modeling.resource [new file with mode: 0644]
robot-systest/resources/gitops_05-clear-params.yaml [new file with mode: 0644]
robot-systest/resources/gitops_05-model-params.yaml [new file with mode: 0644]
robot-systest/resources/gitops_05-secret-params.yaml [new file with mode: 0644]
robot-systest/testsuite/gitops_05-declarative_app_instance_modeling.robot [new file with mode: 0644]

index 4389315..ab8a9fd 100644 (file)
@@ -1,6 +1,4 @@
 *** Comments ***
-# Copyright 2020 Canonical Ltd.
-#
 #   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
diff --git a/robot-systest/lib/app_modeling.resource b/robot-systest/lib/app_modeling.resource
new file mode 100644 (file)
index 0000000..2718639
--- /dev/null
@@ -0,0 +1,95 @@
+*** 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   Library providing keywords for CRUD operations over app instances
+...             with OSM client.
+Library   OperatingSystem
+Library   String
+
+
+*** Variables ***
+${SUCCESS_RETURN_CODE}   0
+${APP_CREATION_MAX_WAIT_TIME}   7min
+${APP_CREATION_POL_TIME}   30sec
+${APP_DELETION_MAX_WAIT_TIME}   5min
+${APP_DELETION_POL_TIME}   15sec
+
+
+*** Keywords ***
+Create App Instance
+    [Documentation]   Create an App Instance in OSM
+    [Arguments]   ${app_name}   ${app_description}   ${profile}   ${profile_type}   ${oka_name}   ${app_model_file}=${EMPTY}   ${app_params_file}=${EMPTY}   ${app_secret_params_file}=${EMPTY}   ${wait_flag}=True
+    ${app_params}=   Set Variable   ${EMPTY}
+    IF   "${app_model_file}" != "${EMPTY}"
+        ${app_params}=   Catenate   ${app_params}   --model ${app_model_file}
+    END
+    IF   "${app_params_file}" != "${EMPTY}"
+        ${app_params}=   Catenate   ${app_params}   --params ${app_params_file}
+    END
+    IF   "${app_secret_params_file}" != "${EMPTY}"
+        ${app_params}=   Catenate   ${app_params}   --secret-params ${app_secret_params_file}
+    END
+    ${rc}   ${stdout}=   Run And Return Rc And Output
+    ...   osm app-create ${app_name} --description ${app_description} --oka ${oka_name} --profile ${profile} --profile-type ${profile_type} ${app_params}
+    Log   ${rc},${stdout}
+    Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}   msg=App Instance creation failed: ${stdout}
+    ${app_id}=   Set Variable   ${stdout}
+    Log   ${app_id}
+    IF   ${wait_flag} == True
+        Wait Until Keyword Succeeds   ${APP_CREATION_MAX_WAIT_TIME}   ${APP_CREATION_POL_TIME}
+        ...    Check For App Instance To Be Ready   ${app_id}
+    END
+    RETURN   ${app_id}
+
+Delete App Instance
+    [Documentation]   Delete App Instance from OSM
+    [Arguments]   ${app_name}   ${wait_flag}=True
+    ${rc}   ${stdout}=   Run And Return Rc And Output
+    ...   osm app-delete ${app_name}
+    Log   ${rc},${stdout}
+    Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}   msg=App Instance deletion failed: ${stdout}
+    IF   ${wait_flag} == True
+       Wait Until Keyword Succeeds   ${APP_DELETION_MAX_WAIT_TIME}   ${APP_DELETION_POL_TIME}
+       ...    Check For App Instance To Be Deleted   ${app_name}
+    END
+
+Check For App Instance To Be Ready
+    [Documentation]   Check if an App Instance is ready (the resourceState must be READY).
+    [Arguments]   ${app_name}
+    ${rc}   ${stdout}=   Run And Return Rc And Output   osm app-show ${app_name}
+    Log   ${rc},${stdout}
+    ${rc}   ${stdout}=   Run And Return Rc And Output   osm app-show ${app_name} -o jsonpath='{.resourceState}'
+    Log   ${rc},${stdout}
+    Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}
+    Should Be Equal As Strings   ${stdout}   READY
+
+Check For App Instance To Be Deleted
+    [Documentation]   Check if an App Instance identified by app_name is not present in OSM.
+    [Arguments]   ${app_name}
+    ${rc}   ${output}=   Run And Return Rc And Output   osm app-show ${app_name}
+    Log   ${rc},${output}
+    ${matches}=   Get Regexp Matches   ${app_name}   ^[0-9a-fA-F-]{36}$
+    Log   ${matches}
+    IF   ${matches} != @{EMPTY}
+       Log   ${app_name} is a valid UUID
+       # ${rc}   ${stdout}=   Run And Return Rc And Output   osm app-list --filter _id="${app_name}" | grep ${app_name}
+       ${rc}   ${stdout}=   Run And Return Rc And Output   osm app-list --filter _id="${app_name}" -o jsonpath='[*]._id'| grep -E "\^${app_name}\$"
+    ELSE
+       Log   ${app_name} is not a valid UUID, so it will be treated as a name
+       # ${rc}   ${stdout}=   Run And Return Rc And Output   osm app-list --filter name="${app_name}" | grep ${app_name}
+       ${rc}   ${stdout}=   Run And Return Rc And Output   osm app-list --filter name="${app_name}" -o jsonpath='[*].name'| grep -E "\^${app_name}\$"
+    END
+    Log   ${rc},${stdout}
+    Should Be Empty   ${stdout}
diff --git a/robot-systest/resources/gitops_05-clear-params.yaml b/robot-systest/resources/gitops_05-clear-params.yaml
new file mode 100644 (file)
index 0000000..d6112e4
--- /dev/null
@@ -0,0 +1,16 @@
+# 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.
+
+TARGET_JENKINS_NS: jenkins
+TARGET_GITLAB_NS: gitlab
+TARGET_HARBOR_NS: harbor
diff --git a/robot-systest/resources/gitops_05-model-params.yaml b/robot-systest/resources/gitops_05-model-params.yaml
new file mode 100644 (file)
index 0000000..6441b84
--- /dev/null
@@ -0,0 +1,28 @@
+# 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.
+
+spec:
+  ksus:
+  - name: jenkins
+    patterns:
+    - name: jenkins
+      bricks:
+      - name: jenkins
+        type: HelmReleaseSet
+        hrset-values:
+          - name: jenkins
+            inline-values:
+              service:
+                ports:
+                  http: "8080"
+                  https: "8443"
diff --git a/robot-systest/resources/gitops_05-secret-params.yaml b/robot-systest/resources/gitops_05-secret-params.yaml
new file mode 100644 (file)
index 0000000..d8e3509
--- /dev/null
@@ -0,0 +1,16 @@
+# 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.
+
+jenkins:
+  jenkinsUser: admin
+  jenkinsPassword: J3nk1n2P2ssw0rd
diff --git a/robot-systest/testsuite/gitops_05-declarative_app_instance_modeling.robot b/robot-systest/testsuite/gitops_05-declarative_app_instance_modeling.robot
new file mode 100644 (file)
index 0000000..07d954e
--- /dev/null
@@ -0,0 +1,116 @@
+*** 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-05] App Instance Test
+
+Library   OperatingSystem
+Library   String
+Library   Collections
+Library   Process
+
+Resource   ../lib/advanced_cluster_mgmt_lib.resource
+Resource   ../lib/app_modeling.resource
+Resource   ../lib/vim_lib.resource
+
+Test Tags   gitops_05   cluster_gitops
+
+Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
+
+
+*** Variables ***
+# OKA packages
+${OKA_FOLDER}   '%{PACKAGES_FOLDER}/oka'
+${OKA1_PKG}   apps/cicd-full-suite
+${OKA1_NAME}   cicd-gitops05
+${OKA1_PROFILE}   app-profile
+
+# VIM and Cluster
+${VIM_NAME}   gitops05vim
+${CLUSTER_NAME}   cl-gitops05
+${CLUSTER_DESCRIPTION}   "Cluster for gitops05 Robot test suite"
+
+# APP Instances
+${APP1_NAME}   myapp
+${APP1_MODEL_PARAMS}   ${CURDIR}/../resources/gitops_05-model-params.yaml
+${APP1_CLEAR_PARAMS}   ${CURDIR}/../resources/gitops_05-clear-params.yaml
+${APP1_SECRET_PARAMS}   ${CURDIR}/../resources/gitops_05-cicd-secret-params.yaml
+${APP1_ID}   ${EMPTY}
+
+
+*** Test Cases ***
+Create Dummy VIM For The Testsuite
+    [Documentation]   Create dummy VIM for the testsuite.
+    [Tags]   vim   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   ${OKA1_NAME}   '${OKA_FOLDER}/${OKA1_PKG}'   ${OKA1_PROFILE}
+
+Register Cluster For Testsuite
+    [Documentation]   Register K8s cluster for the testsuite.
+    [Tags]   cluster   create
+    ${id}=   Register Cluster   ${CLUSTER_NAME}   ${VIM_NAME}   %{CLUSTER_KUBECONFIG_CREDENTIALS}   ${CLUSTER_DESCRIPTION}
+    Set Suite Variable   ${CLUSTER_ID}   ${id}
+    Log   ${CLUSTER_ID}
+
+Get Cluster Kubeconfig
+    [Documentation]   Get Kubeconfig for the 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 App1 With Params
+    [Documentation]   Create App1 based on ${OKA1_NAME} with params.
+    [Tags]   app   create
+    ${id}=   Create App Instance   ${APP1_NAME}   ${APP1_NAME}   ${CLUSTER_NAME}   app-profile   ${OKA1_NAME}   ${APP1_MODEL_PARAMS}   ${APP1_CLEAR_PARAMS}   ${APP1_SECRET_PARAMS}
+    Set Suite Variable   ${APP1_ID}   ${id}
+    Log   ${APP1_ID}
+
+Delete App1
+    [Documentation]   Delete App1 based on ${OKA1_NAME}.
+    [Tags]   cleanup   app
+    IF   '${APP1_ID}' != ''
+       ${APP_TO_BE_DELETED}=   Set Variable   ${APP1_ID}
+    ELSE
+       ${APP_TO_BE_DELETED}=   Set Variable   ${APP1_NAME}
+    END
+    Delete App Instance   ${APP_TO_BE_DELETED}
+
+Deregister Cluster For Testsuite
+    [Documentation]   Deregister K8s cluster for the testsuite.
+    [Tags]   cleanup   cluster
+    Deregister Cluster   ${CLUSTER_NAME}
+
+Delete Dummy VIM For The Testsuite
+    [Documentation]   Delete dummy VIM for the testsuite.
+    [Tags]   vim   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   ${OKA1_NAME}
+
+
+*** Keywords ***
+Suite Cleanup
+    [Documentation]   Test Suit Cleanup: Deleting cluster, OKAs
+    Run Keyword If Any Tests Failed   Deregister Cluster   ${CLUSTER_NAME}
+    Run Keyword If Any Tests Failed   Delete OKA Package   ${OKA1_NAME}