From ad8ab089a063f8300406be93fa89385787cf0aeb Mon Sep 17 00:00:00 2001 From: "Bartra, Rick (rb560u)" Date: Wed, 31 Mar 2021 22:01:14 -0400 Subject: [PATCH] Add test for pre-defined image tags This commit adds a test to verify that pre-defined image tags are preserved during development pipeline runs. The deployment-flow configmap is checked which would contain the original image tag and the image.json is also checked which would contain the image tag that is actually used. The test checks if the configmap tag matches the image.json tag, which it should. The test skips if there is no pre-defined tag. Change-Id: Ic7661dfc23bc92a460b3b0d5328a6f85b42a6ed4 --- .../templates/task-functional.yaml | 3 +++ .../functional/tasks/functional-test.yaml | 24 ++++++++++++++++++- .../roles/functional/tasks/main.yaml | 4 ++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tools/gate/jarvis/development-pipeline/templates/task-functional.yaml b/tools/gate/jarvis/development-pipeline/templates/task-functional.yaml index 977b4b8c..b0de53db 100644 --- a/tools/gate/jarvis/development-pipeline/templates/task-functional.yaml +++ b/tools/gate/jarvis/development-pipeline/templates/task-functional.yaml @@ -26,6 +26,9 @@ spec: image: {{ $.Values.tasks.functional.functionalTestImage }} script: | /jarvis/functional_test.sh + volumeMounts: + - mountPath: $(workspaces.development_pipeline_data.path)/config + name: kubeconfig volumes: - name: helm-publish-creds secret: diff --git a/tools/gate/jarvis/standard-container/assets/playbooks/roles/functional/tasks/functional-test.yaml b/tools/gate/jarvis/standard-container/assets/playbooks/roles/functional/tasks/functional-test.yaml index a2c58955..eda99028 100644 --- a/tools/gate/jarvis/standard-container/assets/playbooks/roles/functional/tasks/functional-test.yaml +++ b/tools/gate/jarvis/standard-container/assets/playbooks/roles/functional/tasks/functional-test.yaml @@ -1,4 +1,26 @@ +#Test pre-defined image tag +- name: test pre-defined image tag + shell: | + echo "Checking if pre-defined image tag is preserved during development pipeline run" ; + # The original image tag is what is in the deployment-flow configmap + ORIGINAL_TAG=$(kubectl get cm deployment-flow -o json | jq -r .'data'.'"image.json"' | jq -r .'[0]'.'tag') + # The actual image tag is the tag that is assigned during the development pipeline run and is ultimately + # what is used to tag the image in Harbor + ACTUAL_TAG=$(helm --kubeconfig /workspace/development_pipeline_data/config/kubeconfig ls -n mongodb -o json | jq -r .[0].app_version) + if [ "${ORIGINAL_TAG}" == "null" ] || [ "${ORIGINAL_TAG}" == "" ]; then + echo "Skipping as there is no pre-defined tag that should be used on the image" + else + if [ "${ACTUAL_TAG}" == "${ORIGINAL_TAG}" ]; then + echo "Actual tag: ${ACTUAL_TAG} matches expected tag: ${ORIGINAL_TAG}" + else + echo "Actual tag: ${ACTUAL_TAG} does NOT match expected tag: ${ORIGINAL_TAG}" + exit 1 + fi + fi + args: + executable: /bin/bash + #Test Deployed CNF - name: Chart has no Helm Tests, echo for now shell: echo "There are no helm tests yet" -# shell: echo 'helm test --kubeconfig="{{ cluster_kubeconfig_path }}/kubeconfig" "{{ name }}"' \ No newline at end of file +# shell: echo 'helm test --kubeconfig="{{ cluster_kubeconfig_path }}/kubeconfig" "{{ name }}"' diff --git a/tools/gate/jarvis/standard-container/assets/playbooks/roles/functional/tasks/main.yaml b/tools/gate/jarvis/standard-container/assets/playbooks/roles/functional/tasks/main.yaml index 98eb3782..f31b46bd 100644 --- a/tools/gate/jarvis/standard-container/assets/playbooks/roles/functional/tasks/main.yaml +++ b/tools/gate/jarvis/standard-container/assets/playbooks/roles/functional/tasks/main.yaml @@ -53,5 +53,5 @@ when: stage == "test" block: #Test Deployed CNF - - name: Chart currently has no Helm Tests, echo for now - shell: echo "There are no helm tests yet" + - name: Run tests + include_tasks: ./roles/functional/tasks/functional-test.yaml