Skip to content

Commit

Permalink
Improved guestbook.sh test to become actual test
Browse files Browse the repository at this point in the history
After change test waits until pods come up, then adds
entry to guestbook and verify if operation succeed

This fixes kubernetes#3693
  • Loading branch information
piosz committed Mar 2, 2015
1 parent 6c5b390 commit cc707ab
Showing 1 changed file with 65 additions and 13 deletions.
78 changes: 65 additions & 13 deletions hack/e2e-suite/guestbook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,77 @@ export KUBECTL KUBE_CONFIG_FILE
source "${KUBE_ROOT}/cluster/kube-env.sh"
source "${KUBE_VERSION_ROOT}/cluster/${KUBERNETES_PROVIDER}/util.sh"

function wait_for_running() {
echo "Waiting for pods to come up."
frontends=$(${KUBECTL} get pods -l name=frontend -o template '--template={{range.items}}{{.id}} {{end}}')
master=$(${KUBECTL} get pods -l name=redis-master -o template '--template={{range.items}}{{.id}} {{end}}')
slaves=$(${KUBECTL} get pods -l name=redisslave -o template '--template={{range.items}}{{.id}} {{end}}')
pods=$(echo $frontends $master $slaves)

all_running=0
for i in $(seq 1 30); do
sleep 10
all_running=1
for pod in $pods; do
status=$(${KUBECTL} get pods $pod -o template '--template={{.currentState.status}}') || true
if [[ "$status" == "Pending" ]]; then
all_running=0
break
fi
done
if [[ "${all_running}" == 1 ]]; then
break
fi
done
if [[ "${all_running}" == 0 ]]; then
echo "Pods did not come up in time"
exit 1
fi
}

function teardown() {
${KUBECTL} stop -f "${GUESTBOOK}"
}

prepare-e2e

GUESTBOOK="${KUBE_ROOT}/examples/guestbook"

echo "WARNING: this test is a no op that only attempts to launch guestbook resources."
# Launch the guestbook example
${KUBECTL} create -f "${GUESTBOOK}"

sleep 15

POD_LIST_1=$(${KUBECTL} get pods -o template '--template={{range.items}}{{.id}} {{end}}')
echo "Pods running: ${POD_LIST_1}"

# TODO make this an actual test. Open up a firewall and use curl to post and
# read a message via the frontend

${KUBECTL} stop -f "${GUESTBOOK}"

POD_LIST_2=$(${KUBECTL} get pods -o template '--template={{range.items}}{{.id}} {{end}}')
echo "Pods running after shutdown: ${POD_LIST_2}"
trap "teardown" EXIT

# Verify that all pods are running
wait_for_running

get-password
detect-master

# Add a new entry to the guestbook and verify that it was remembered
FRONTEND_ADDR=https://${KUBE_MASTER_IP}/api/v1beta1/proxy/services/frontend
echo "Waiting for frontend to serve content"
serving=0
for i in $(seq 1 12); do
ENTRY=$(curl ${FRONTEND_ADDR}/index.php?cmd=get\&key=messages --insecure --user ${KUBE_USER}:${KUBE_PASSWORD})
echo $ENTRY
if [[ $ENTRY == '{"data": ""}' ]]; then
serving=1
break
fi
sleep 10
done
if [[ "${serving}" == 0 ]]; then
echo "Pods did not start serving content in time"
exit 1
fi

curl ${FRONTEND_ADDR}/index.php?cmd=set\&key=messages\&value=TestEntry --insecure --user ${KUBE_USER}:${KUBE_PASSWORD}
ENTRY=$(curl ${FRONTEND_ADDR}/index.php?cmd=get\&key=messages --insecure --user ${KUBE_USER}:${KUBE_PASSWORD})

if [[ $ENTRY != '{"data": "TestEntry"}' ]]; then
echo "Wrong entry received: ${ENTRY}"
exit 1
fi

exit 0

0 comments on commit cc707ab

Please sign in to comment.