*** 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
--- /dev/null
+*** 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}
--- /dev/null
+# 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
--- /dev/null
+# 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"
--- /dev/null
+# 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
--- /dev/null
+*** 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}