Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #209 from SUSE/f0rmiga/run-cats-ci
Browse files Browse the repository at this point in the history
Add CATS to run on CI
  • Loading branch information
mook-as authored Nov 28, 2019
2 parents 8568fb2 + 30aae80 commit 2381912
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ build:chart:
- output/kubecf-*.tgz
expire_in: 1 week

smoke-tests:
tests:
stage: test
only: *common_refs
script:
Expand All @@ -39,6 +39,7 @@ smoke-tests:
- .gitlab/pipelines/stages/deploy/deploy_kubecf.sh
- .gitlab/pipelines/stages/deploy/wait_kubecf.sh
- .gitlab/pipelines/stages/tests/smoke_tests.sh
- .gitlab/pipelines/stages/tests/cf_acceptance_tests.sh
- .gitlab/pipelines/stages/deploy/stop_k8s.sh

publish:chart:
Expand Down
46 changes: 46 additions & 0 deletions .gitlab/pipelines/stages/tests/cf_acceptance_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

set -o errexit -o nounset

# shellcheck disable=SC1090
source "$(bazel info workspace)/.gitlab/pipelines/runtime/config.sh"
# shellcheck disable=SC1090
source "$(bazel info workspace)/.gitlab/pipelines/runtime/binaries.sh"

# Trigger cf-acceptance-tests.
bazel run //testing/acceptance_tests

cf_acceptance_tests_pod_name() {
"${KUBECTL}" get pods --namespace "${KUBECF_NAMESPACE}" --output name 2> /dev/null | grep "acceptance-tests"
}

# Wait for cf-acceptance-tests to start.
wait_for_cf_acceptance_tests_pod() {
local timeout="300"
until "${KUBECTL}" get pods --namespace "${KUBECF_NAMESPACE}" --output name 2> /dev/null | grep --quiet "acceptance-tests" || [[ "$timeout" == "0" ]]; do sleep 1; timeout=$((timeout - 1)); done
if [[ "${timeout}" == 0 ]]; then return 1; fi
pod_name="$(cf_acceptance_tests_pod_name)"
until [[ "$("${KUBECTL}" get "${pod_name}" --namespace "${KUBECF_NAMESPACE}" --output jsonpath='{.status.containerStatuses[?(@.name == "acceptance-tests-acceptance-tests")].state.running}' 2> /dev/null)" != "" ]] || [[ "$timeout" == "0" ]]; do sleep 1; timeout=$((timeout - 1)); done
if [[ "${timeout}" == 0 ]]; then return 1; fi
return 0
}

echo "Waiting for the cf-acceptance-tests pod to start..."
wait_for_cf_acceptance_tests_pod || {
>&2 echo "Timed out waiting for the cf-acceptance-tests pod"
exit 1
}

# Follow the logs. If the tests fail, the logs command will also fail.
pod_name="$(cf_acceptance_tests_pod_name)"
"${KUBECTL}" logs --follow "${pod_name}" --namespace "${KUBECF_NAMESPACE}" --container acceptance-tests-acceptance-tests

# Wait for the container to terminate and then exit the script with the container's exit code.
jsonpath='{.status.containerStatuses[?(@.name == "acceptance-tests-acceptance-tests")].state.terminated.exitCode}'
while true; do
exit_code="$("${KUBECTL}" get "${pod_name}" --namespace "${KUBECF_NAMESPACE}" --output "jsonpath=${jsonpath}")"
if [[ -n "${exit_code}" ]]; then
exit "${exit_code}"
fi
sleep 1
done

0 comments on commit 2381912

Please sign in to comment.