From 485d5fff7df7f3805aeaec2cb28f2e2e7917b3b1 Mon Sep 17 00:00:00 2001 From: Seth Goings Date: Thu, 25 Feb 2016 00:34:58 -0700 Subject: [PATCH] feat(tests): move most of the infrastructure provisioning to chart-mate Fixes #115 --- .gitignore | 4 +- _scripts/chart-version-bumper.sh | 41 --------- _scripts/set-versions | 30 ------ _scripts/tests/check.sh | 8 +- _scripts/tests/config.sh | 8 -- _scripts/tests/create.sh | 5 - _scripts/tests/destroy.sh | 5 - _scripts/tests/init.sh | 7 +- _scripts/tests/install.sh | 46 +--------- _scripts/tests/shared.sh | 111 ----------------------- _scripts/tests/test.sh | 12 +-- _scripts/tests/uninstall.sh | 7 +- deis-tests/manifests/deis-tests-pod.yaml | 2 +- 13 files changed, 10 insertions(+), 276 deletions(-) delete mode 100755 _scripts/chart-version-bumper.sh delete mode 100755 _scripts/set-versions delete mode 100644 _scripts/tests/config.sh diff --git a/.gitignore b/.gitignore index 20d57f4..5999a05 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/_scripts/tests/helm -/_scripts/tests/rerun +rerun /_scripts/tests/.bin +/logs diff --git a/_scripts/chart-version-bumper.sh b/_scripts/chart-version-bumper.sh deleted file mode 100755 index 8c6180d..0000000 --- a/_scripts/chart-version-bumper.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -function usage() { - cat < -EOF -} - -if [ $# -ne 3 ]; then - usage - exit 1 -fi - -CHART_NAME="${1}" -COMPONENT_NAME="${2}" -VERSION="${3}" -SHORT_VERSION="${VERSION:0:7}" # short git hashes (what we use in registries) are the 7 characters -GIT_PREFIXED_TAG="git-${SHORT_VERSION}" - -# find the file where we reference the component -target_file="$(grep -Erl "image: quay.io/[a-z]+/${COMPONENT_NAME}:*" ${CHART_NAME})" - -echo "==> Operating on files: ${target_file}" - -# replace the version with VERSION -file="" -for file in ${target_file}; do - echo -e "\t${CHART_NAME}: set ${COMPONENT_NAME} to ${GIT_PREFIXED_TAG}" - sed -E -i.bak "s%image: quay\.io/([a-z]+)/${COMPONENT_NAME}:.*%image: quay.io/\1/${COMPONENT_NAME}:${GIT_PREFIXED_TAG}%" "${file}" -done - -# remove the backup file -find . -name "*.bak" | xargs -I {} rm {} - -# print out the updated file just for kicks -echo -echo -e "\tVerification:" -echo -e "\t\t$(grep -Er "image: quay.io/[a-z]+/${COMPONENT_NAME}:${GIT_PREFIXED_TAG}" ${target_file})" -echo diff --git a/_scripts/set-versions b/_scripts/set-versions deleted file mode 100755 index b4426f3..0000000 --- a/_scripts/set-versions +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail -o nounset - -if [ ${1:-""} == "-h" ]; then - cat < "${HOME}/.secrets/helm-testing-creds.json" -fi - -export GCLOUD_CREDENTIALS_FILE="${GCLOUD_CREDENTIALS_FILE:-${HOME}/.secrets/helm-testing-creds.json}" -export PATH="$(pwd):$(pwd)/.bin:${HOME}/google-cloud-sdk/bin:$PATH" diff --git a/_scripts/tests/create.sh b/_scripts/tests/create.sh index d47d4a7..97025ac 100755 --- a/_scripts/tests/create.sh +++ b/_scripts/tests/create.sh @@ -1,8 +1,3 @@ #!/usr/bin/env bash -cd "$(dirname $0)" - -source config.sh -source shared.sh - ./rerun chart-mate:up diff --git a/_scripts/tests/destroy.sh b/_scripts/tests/destroy.sh index 5a96cb4..a71a7c8 100755 --- a/_scripts/tests/destroy.sh +++ b/_scripts/tests/destroy.sh @@ -1,8 +1,3 @@ #!/usr/bin/env bash -cd "$(dirname $0)" - -source config.sh -source shared.sh - ./rerun chart-mate:down diff --git a/_scripts/tests/init.sh b/_scripts/tests/init.sh index 05996a9..0eba4e9 100755 --- a/_scripts/tests/init.sh +++ b/_scripts/tests/init.sh @@ -1,9 +1,8 @@ #!/usr/bin/env bash -cd "$(dirname $0)" - -source config.sh -source shared.sh +source _scripts/tests/shared.sh download-chart-mate download-jq + +./rerun chart-mate:init diff --git a/_scripts/tests/install.sh b/_scripts/tests/install.sh index b2e1f5e..a64a997 100755 --- a/_scripts/tests/install.sh +++ b/_scripts/tests/install.sh @@ -1,47 +1,3 @@ #!/usr/bin/env bash -cd "$(dirname $0)" - -source config.sh -source shared.sh - -function bumpver-if-set { - local chart="${1}" - local component="${2}" - local version="${3}" - - if [ ! -z "${version}" ]; then - local version_bumper="_scripts/chart-version-bumper.sh" - "${version_bumper}" "${chart}" "${component}" "${version}" - else - echo "No version set for ${chart}: ${component}" - fi -} - -if [ ! -z $CI ]; then - echo "INJECTING VERSIONS!" - echo "-------------------" - pushd ../../ &> /dev/null - bumpver-if-set "deis-tests" "deis-e2e" "${WORKFLOW_E2E_SHA}" - bumpver-if-set "deis-logger" "logger" "${LOGGER_GIT_SHA}" - bumpver-if-set "deis-dev" "builder" "${BUILDER_GIT_SHA}" - bumpver-if-set "deis-dev" "minio" "${MINIO_GIT_SHA}" - bumpver-if-set "deis-dev" "postgres" "${POSTGRES_GIT_SHA}" - bumpver-if-set "deis-dev" "registry" "${REGISTRY_GIT_SHA}" - bumpver-if-set "deis-dev" "router" "${ROUTER_GIT_SHA}" - bumpver-if-set "deis-dev" "workflow" "${WORKFLOW_GIT_SHA}" - popd &> /dev/null - echo "-------------------" -fi - -rm -rf ~/.helm/ -helm doctor -mkdir -p ~/.helm/cache/charts/deis -rsync -av ../../ ${HOME}/.helm/cache/deis/ > /dev/null -helm fetch deis/deis-dev -helm fetch deis/deis-logger - -test_root="$(dirname $(pwd))" - -helm generate deis-dev -helm install deis-dev +./rerun chart-mate:install diff --git a/_scripts/tests/shared.sh b/_scripts/tests/shared.sh index 2572b25..efb9d84 100644 --- a/_scripts/tests/shared.sh +++ b/_scripts/tests/shared.sh @@ -17,15 +17,6 @@ EOF fi } -function download-jq { - if ! command -v jq &>/dev/null && [ "${PLATFORM}" == linux ]; then - echo "Downloading jq..." - mkdir -p .bin - curl -Ls https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 > .bin/jq - chmod +x .bin/jq - fi -} - function get_latest_version { local name="${1}" local url="${2}" @@ -57,105 +48,3 @@ function download-chart-mate { curl -Ls "${CHART_MATE_URL_BASE}/rerun-${VERSION}" > rerun chmod +x rerun } - -function check-all-pods-running { - local namespace="${1:-deis}" - - kubectl --namespace="${name}" get pods -o json | jq -r ".items[].status.phase" | grep -v "Succeeded" | grep -qv "Running" -} - -function healthcheck-deis { - wait-for-all-pods "deis" - wait-for-http-status "http://deis.$(get-router-ip).xip.io/v2/" 200 -} - -function wait-for-all-pods { - local name="${1}" - - echo "Waiting for all pods to be in running state..." - wait-for-output ":" \ - "! check-all-pods-running "${name}"" \ - "All pods are running!" \ - "Not all pods started." \ - 1 -} - -function wait-for-http-status { - local url="${1}" - local status="${2}" - - echo "Checking DNS (${url})..." - - local successes - while [[ ${successes} -lt 5 ]]; do - wait-for-output "curl -s -o /dev/null -w '%{http_code}' "${url}"" \ - "[ \${command_output} -eq 401 ]" \ - "Deis is responding at ${url}." \ - "Deis is unresponsive at ${url}" \ - 10 - let successes+=1 - echo "Successfully interacted with Deis platform ${successes} time(s)." - sleep 5 - done -} - -function get-router-ip { - local ip="null" - - echo "Ensuring non-null router ip..." 1>&2 - wait-for-output "kubectl --namespace=deis get svc deis-router -o json | jq -r ".status.loadBalancer.ingress[0].ip"" \ - "[ ! -z \${command_output} ] && [ \${command_output} != "null" ]" \ - "\${command_output}" \ - "Router never exposed public IP" \ - 10 60 - -} - -function return-pod-exit-code { - local name="${1}" - local namespace="${2:-deis}" - local status - - echo "Waiting for pod exit code..." - local exit_code=$(wait-for-output "kubectl get po "${name}" -a --namespace="${namespace}" -o json | jq -r '.status.containerStatuses[0].state.terminated.exitCode'" \ - "[ \${command_output} != "null" ]" \ - "\${command_output}" \ - "100" \ - 1 15) - echo -e "\nExit code: ${exit_code}\n" - return ${exit_code} -} - -function wait-for-output { - local run_this="${1}" - local condition="${2}" - - local success_loop_msg=${3} - local failed_loop_msg="${4}" - - local increment_secs="${5:-5}" - local timeout_secs="${6:-120}" - - local command_output - - local waited_time=0 - while [ ${waited_time} -lt ${timeout_secs} ]; do - command_output=$(eval ${run_this}) - - if eval ${condition}; then - eval echo ${success_loop_msg} - return 0 - fi - - sleep ${increment_secs} - (( waited_time += ${increment_secs} )) - - if [ ${waited_time} -ge ${timeout_secs} ]; then - eval echo ${failed_loop_msg} - return 1 - fi - - echo -n . 1>&2 - - done -} diff --git a/_scripts/tests/test.sh b/_scripts/tests/test.sh index 171c99e..aade8f8 100755 --- a/_scripts/tests/test.sh +++ b/_scripts/tests/test.sh @@ -1,13 +1,3 @@ #!/usr/bin/env bash -cd "$(dirname $0)" - -source config.sh -source shared.sh - -helm fetch deis/deis-tests -helm uninstall -n deis -y deis-tests; helm install deis-tests - -wait-for-all-pods "deis" -kubectl --namespace=deis logs -f deis-tests -return-pod-exit-code "deis-tests" +./rerun chart-mate:test diff --git a/_scripts/tests/uninstall.sh b/_scripts/tests/uninstall.sh index 0257308..a36e734 100755 --- a/_scripts/tests/uninstall.sh +++ b/_scripts/tests/uninstall.sh @@ -1,8 +1,3 @@ #!/usr/bin/env bash -cd "$(dirname $0)" - -source config.sh -source shared.sh - -helm uninstall -n deis -y deis-dev; +./rerun chart-mate:uninstall diff --git a/deis-tests/manifests/deis-tests-pod.yaml b/deis-tests/manifests/deis-tests-pod.yaml index ffd22f4..5353a66 100644 --- a/deis-tests/manifests/deis-tests-pod.yaml +++ b/deis-tests/manifests/deis-tests-pod.yaml @@ -8,7 +8,7 @@ metadata: spec: containers: - name: deis-e2e - image: quay.io/deisci/deis-e2e:git-529bda0 + image: quay.io/deisci/deis-e2e:git-19f3efb imagePullPolicy: Always command: ["/bin/sh", "-c"] args: ["/bin/tests.test"]