Skip to content

Commit

Permalink
feat(tests): move most of the infrastructure provisioning to chart-mate
Browse files Browse the repository at this point in the history
Fixes #115
  • Loading branch information
Seth Goings committed Feb 25, 2016
1 parent 4db45fb commit 485d5ff
Show file tree
Hide file tree
Showing 13 changed files with 10 additions and 276 deletions.
4 changes: 2 additions & 2 deletions .gitignore
@@ -1,3 +1,3 @@
/_scripts/tests/helm
/_scripts/tests/rerun
rerun
/_scripts/tests/.bin
/logs
41 changes: 0 additions & 41 deletions _scripts/chart-version-bumper.sh

This file was deleted.

30 changes: 0 additions & 30 deletions _scripts/set-versions

This file was deleted.

8 changes: 1 addition & 7 deletions _scripts/tests/check.sh
@@ -1,9 +1,3 @@
#!/usr/bin/env bash

cd "$(dirname $0)"

source config.sh
source shared.sh

helm uninstall -n deis -y deis-tests
healthcheck-deis
./rerun chart-mate:check
8 changes: 0 additions & 8 deletions _scripts/tests/config.sh

This file was deleted.

5 changes: 0 additions & 5 deletions _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
5 changes: 0 additions & 5 deletions _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
7 changes: 3 additions & 4 deletions _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
46 changes: 1 addition & 45 deletions _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
111 changes: 0 additions & 111 deletions _scripts/tests/shared.sh
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
}
12 changes: 1 addition & 11 deletions _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
7 changes: 1 addition & 6 deletions _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
2 changes: 1 addition & 1 deletion deis-tests/manifests/deis-tests-pod.yaml
Expand Up @@ -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"]
Expand Down

0 comments on commit 485d5ff

Please sign in to comment.