From f0084808229d6598ac921de192020debf9bcee8f Mon Sep 17 00:00:00 2001 From: jhadvig Date: Wed, 5 Aug 2015 12:25:55 +0200 Subject: [PATCH] Making test DRYer --- hack/test-cmd.sh | 72 ++--------------- hack/test-end-to-end.sh | 102 ++++-------------------- hack/test-extended/default.sh | 144 +++++++--------------------------- hack/util.sh | 119 ++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 269 deletions(-) diff --git a/hack/test-cmd.sh b/hack/test-cmd.sh index db63c3a17faf..d8056066a920 100755 --- a/hack/test-cmd.sh +++ b/hack/test-cmd.sh @@ -20,7 +20,7 @@ function cleanup() if [ $out -ne 0 ]; then echo "[FAIL] !!!!! Test Failed !!!!" echo - cat "${TEMP_DIR}/openshift.log" + cat "${BASETMPDIR}/openshift.log" echo echo ------------------------------------- echo @@ -57,25 +57,11 @@ if [[ -z "${USE_IMAGES-}" ]]; then USE_IMAGES="openshift/origin-\${component}:${tag}" fi +BASETMPDIR=${USE_TEMP:-$(mkdir -p /tmp/openshift-cmd && mktemp -d /tmp/openshift-cmd/XXXX)} +CONFIG_DIR="${BASETMPDIR}/configs" ETCD_HOST=${ETCD_HOST:-127.0.0.1} ETCD_PORT=${ETCD_PORT:-4001} -API_SCHEME=${API_SCHEME:-https} -API_PORT=${API_PORT:-8443} -API_HOST=${API_HOST:-127.0.0.1} -MASTER_ADDR="${API_SCHEME}://${API_HOST}:${API_PORT}" -PUBLIC_MASTER_HOST="${PUBLIC_MASTER_HOST:-${API_HOST}}" -KUBELET_SCHEME=${KUBELET_SCHEME:-https} -KUBELET_HOST=${KUBELET_HOST:-127.0.0.1} -KUBELET_PORT=${KUBELET_PORT:-10250} - -TEMP_DIR=${USE_TEMP:-$(mkdir -p /tmp/openshift-cmd && mktemp -d /tmp/openshift-cmd/XXXX)} -ETCD_DATA_DIR="${TEMP_DIR}/etcd" -VOLUME_DIR="${TEMP_DIR}/volumes" -FAKE_HOME_DIR="${TEMP_DIR}/openshift.local.home" -SERVER_CONFIG_DIR="${TEMP_DIR}/openshift.local.config" -MASTER_CONFIG_DIR="${SERVER_CONFIG_DIR}/master" -NODE_CONFIG_DIR="${SERVER_CONFIG_DIR}/node-${KUBELET_HOST}" -CONFIG_DIR="${TEMP_DIR}/configs" +setup_env_vars mkdir -p "${ETCD_DATA_DIR}" "${VOLUME_DIR}" "${FAKE_HOME_DIR}" "${MASTER_CONFIG_DIR}" "${NODE_CONFIG_DIR}" "${CONFIG_DIR}" # handle profiling defaults @@ -91,10 +77,6 @@ else export WEB_PROFILE=cpu fi -# set path so OpenShift is available -GO_OUT="${OS_ROOT}/_output/local/go/bin" -export PATH="${GO_OUT}:${PATH}" - # Check openshift version out=$(openshift version) echo openshift: $out @@ -107,46 +89,7 @@ echo "[INFO] Create certificates for the OpenShift server to ${MASTER_CONFIG_DIR # find the same IP that openshift start will bind to. This allows access from pods that have to talk back to master SERVER_HOSTNAME_LIST="${PUBLIC_MASTER_HOST},$(openshift start --print-ip),localhost" -openshift admin ca create-master-certs \ - --overwrite=false \ - --cert-dir="${MASTER_CONFIG_DIR}" \ - --hostnames="${SERVER_HOSTNAME_LIST}" \ - --master="${MASTER_ADDR}" \ - --public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}:${API_PORT}" - -openshift admin create-node-config \ - --listen="${KUBELET_SCHEME}://0.0.0.0:${KUBELET_PORT}" \ - --node-dir="${NODE_CONFIG_DIR}" \ - --node="${KUBELET_HOST}" \ - --hostnames="${KUBELET_HOST}" \ - --master="${MASTER_ADDR}" \ - --node-client-certificate-authority="${MASTER_CONFIG_DIR}/ca.crt" \ - --certificate-authority="${MASTER_CONFIG_DIR}/ca.crt" \ - --signer-cert="${MASTER_CONFIG_DIR}/ca.crt" \ - --signer-key="${MASTER_CONFIG_DIR}/ca.key" \ - --signer-serial="${MASTER_CONFIG_DIR}/ca.serial.txt" - -oadm create-bootstrap-policy-file --filename="${MASTER_CONFIG_DIR}/policy.json" - -# create openshift config -openshift start \ - --write-config=${SERVER_CONFIG_DIR} \ - --create-certs=false \ - --master="${API_SCHEME}://${API_HOST}:${API_PORT}" \ - --listen="${API_SCHEME}://${API_HOST}:${API_PORT}" \ - --hostname="${KUBELET_HOST}" \ - --volume-dir="${VOLUME_DIR}" \ - --etcd-dir="${ETCD_DATA_DIR}" \ - --images="${USE_IMAGES}" - - -# Start openshift -OPENSHIFT_ON_PANIC=crash openshift start \ - --master-config=${MASTER_CONFIG_DIR}/master-config.yaml \ - --node-config=${NODE_CONFIG_DIR}/node-config.yaml \ - --loglevel=4 \ - 1>&2 2>"${TEMP_DIR}/openshift.log" & -OS_PID=$! +configure_os_server ${BASETMPDIR} if [[ "${API_SCHEME}" == "https" ]]; then export CURL_CA_BUNDLE="${MASTER_CONFIG_DIR}/ca.crt" @@ -157,10 +100,7 @@ fi # set the home directory so we don't pick up the users .config export HOME="${FAKE_HOME_DIR}" -wait_for_url "${KUBELET_SCHEME}://${KUBELET_HOST}:${KUBELET_PORT}/healthz" "kubelet: " 0.25 80 -wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz" "apiserver: " 0.25 80 -wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz/ready" "apiserver(ready): " 0.25 80 -wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/api/v1beta3/nodes/${KUBELET_HOST}" "apiserver(nodes): " 0.25 80 +start_os_server # profile the cli commands export OPENSHIFT_PROFILE="${CLI_PROFILE-}" diff --git a/hack/test-end-to-end.sh b/hack/test-end-to-end.sh index 7d07740e46fd..ad6eec2fa53e 100755 --- a/hack/test-end-to-end.sh +++ b/hack/test-end-to-end.sh @@ -3,19 +3,6 @@ # This script tests the high level end-to-end functionality demonstrated # as part of the examples/sample-app -if [[ -z "$(which iptables)" ]]; then - echo "IPTables not found - the end-to-end test requires a system with iptables for Kubernetes services." - exit 1 -fi -iptables --list > /dev/null 2>&1 -if [ $? -ne 0 ]; then - sudo iptables --list > /dev/null 2>&1 - if [ $? -ne 0 ]; then - echo "You do not have iptables or sudo privileges. Kubernetes services will not work without iptables access. See https://github.com/GoogleCloudPlatform/kubernetes/issues/1859. Try 'sudo hack/test-end-to-end.sh'." - exit 1 - fi -fi - set -o errexit set -o nounset set -o pipefail @@ -23,6 +10,8 @@ set -o pipefail OS_ROOT=$(dirname "${BASH_SOURCE}")/.. source "${OS_ROOT}/hack/util.sh" +test_privileges + echo "[INFO] Starting end-to-end test" # Use either the latest release built images, or latest. @@ -37,33 +26,20 @@ fi ROUTER_TESTS_ENABLED="${ROUTER_TESTS_ENABLED:-true}" TEST_ASSETS="${TEST_ASSETS:-false}" -if [[ -z "${BASETMPDIR-}" ]]; then - TMPDIR="${TMPDIR:-"/tmp"}" - BASETMPDIR="${TMPDIR}/openshift-e2e" - sudo rm -rf "${BASETMPDIR}" - mkdir -p "${BASETMPDIR}" + +TEST_TYPE="openshift-e2e" +TMPDIR="${TMPDIR:-"/tmp"}" +BASETMPDIR="${TMPDIR}/${TEST_TYPE}" + +if [[ -d "${BASETMPDIR}" ]]; then + remove_tmp_dir $TEST_TYPE && mkdir -p "${BASETMPDIR}" fi -ETCD_DATA_DIR="${BASETMPDIR}/etcd" -VOLUME_DIR="${BASETMPDIR}/volumes" -FAKE_HOME_DIR="${BASETMPDIR}/openshift.local.home" + LOG_DIR="${LOG_DIR:-${BASETMPDIR}/logs}" ARTIFACT_DIR="${ARTIFACT_DIR:-${BASETMPDIR}/artifacts}" -mkdir -p $LOG_DIR -mkdir -p $ARTIFACT_DIR - -DEFAULT_SERVER_IP=`ifconfig | grep -Ev "(127.0.0.1|172.17.42.1)" | grep "inet " | head -n 1 | sed 's/adr://' | awk '{print $2}'` -API_HOST="${API_HOST:-${DEFAULT_SERVER_IP}}" -API_PORT="${API_PORT:-8443}" -API_SCHEME="${API_SCHEME:-https}" -MASTER_ADDR="${API_SCHEME}://${API_HOST}:${API_PORT}" -PUBLIC_MASTER_HOST="${PUBLIC_MASTER_HOST:-${API_HOST}}" -KUBELET_SCHEME="${KUBELET_SCHEME:-https}" -KUBELET_HOST="${KUBELET_HOST:-127.0.0.1}" -KUBELET_PORT="${KUBELET_PORT:-10250}" - -SERVER_CONFIG_DIR="${BASETMPDIR}/openshift.local.config" -MASTER_CONFIG_DIR="${SERVER_CONFIG_DIR}/master" -NODE_CONFIG_DIR="${SERVER_CONFIG_DIR}/node-${KUBELET_HOST}" +API_HOST="${API_HOST:-$(ifconfig | grep -Ev "(127.0.0.1|172.17.42.1)" | grep "inet " | head -n 1 | sed 's/adr://' | awk '{print $2}')}" +setup_env_vars +mkdir -p $LOG_DIR $ARTIFACT_DIR # use the docker bridge ip address until there is a good way to get the auto-selected address from master # this address is considered stable @@ -73,10 +49,6 @@ CONTAINER_ACCESSIBLE_API_HOST="${CONTAINER_ACCESSIBLE_API_HOST:-172.17.42.1}" STI_CONFIG_FILE="${LOG_DIR}/stiAppConfig.json" DOCKER_CONFIG_FILE="${LOG_DIR}/dockerAppConfig.json" CUSTOM_CONFIG_FILE="${LOG_DIR}/customAppConfig.json" -GO_OUT="${OS_ROOT}/_output/local/go/bin" - -# set path so OpenShift is available -export PATH="${GO_OUT}:${PATH}" function cleanup() @@ -197,47 +169,7 @@ do SERVER_HOSTNAME_LIST="${SERVER_HOSTNAME_LIST},${IP_ADDRESS}" done <<< "${ALL_IP_ADDRESSES}" -openshift admin ca create-master-certs \ - --overwrite=false \ - --cert-dir="${MASTER_CONFIG_DIR}" \ - --hostnames="${SERVER_HOSTNAME_LIST}" \ - --master="${MASTER_ADDR}" \ - --public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}:${API_PORT}" - -openshift admin create-node-config \ - --listen="${KUBELET_SCHEME}://0.0.0.0:${KUBELET_PORT}" \ - --node-dir="${NODE_CONFIG_DIR}" \ - --node="${KUBELET_HOST}" \ - --hostnames="${KUBELET_HOST}" \ - --master="${MASTER_ADDR}" \ - --node-client-certificate-authority="${MASTER_CONFIG_DIR}/ca.crt" \ - --certificate-authority="${MASTER_CONFIG_DIR}/ca.crt" \ - --signer-cert="${MASTER_CONFIG_DIR}/ca.crt" \ - --signer-key="${MASTER_CONFIG_DIR}/ca.key" \ - --signer-serial="${MASTER_CONFIG_DIR}/ca.serial.txt" - -oadm create-bootstrap-policy-file --filename="${MASTER_CONFIG_DIR}/policy.json" - -# create openshift config -openshift start \ - --write-config=${SERVER_CONFIG_DIR} \ - --create-certs=false \ - --listen="${API_SCHEME}://0.0.0.0:${API_PORT}" \ - --master="${MASTER_ADDR}" \ - --public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}:${API_PORT}" \ - --hostname="${KUBELET_HOST}" \ - --volume-dir="${VOLUME_DIR}" \ - --etcd-dir="${ETCD_DATA_DIR}" \ - --images="${USE_IMAGES}" - - -echo "[INFO] Starting OpenShift server" -sudo env "PATH=${PATH}" OPENSHIFT_PROFILE=web OPENSHIFT_ON_PANIC=crash openshift start \ - --master-config=${MASTER_CONFIG_DIR}/master-config.yaml \ - --node-config=${NODE_CONFIG_DIR}/node-config.yaml \ - --loglevel=4 \ - &> "${LOG_DIR}/openshift.log" & -OS_PID=$! +configure_os_server export HOME="${FAKE_HOME_DIR}" # This directory must exist so Docker can store credentials in $HOME/.dockercfg @@ -256,11 +188,7 @@ if [[ "${API_SCHEME}" == "https" ]]; then echo "[INFO] To debug: export KUBECONFIG=$KUBECONFIG" fi - -wait_for_url "${KUBELET_SCHEME}://${KUBELET_HOST}:${KUBELET_PORT}/healthz" "[INFO] kubelet: " 0.5 60 -wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz" "apiserver: " 0.25 80 -wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz/ready" "apiserver(ready): " 0.25 80 -wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/api/v1beta3/nodes/${KUBELET_HOST}" "apiserver(nodes): " 0.25 80 +start_os_server ${LOG_DIR} # add e2e-user as a viewer for the default namespace so we can see infrastructure pieces appear openshift admin policy add-role-to-user view e2e-user --namespace=default diff --git a/hack/test-extended/default.sh b/hack/test-extended/default.sh index 9293d0f46b81..c931174885c2 100755 --- a/hack/test-extended/default.sh +++ b/hack/test-extended/default.sh @@ -12,13 +12,33 @@ OS_ROOT=$(dirname "${BASH_SOURCE}")/../.. source ${OS_ROOT}/hack/util.sh source ${OS_ROOT}/hack/common.sh -echo "[INFO] Starting extended tests" +cleanup() { + stop_openshift_server + rm -rf ${ETCD_DIR-} + + echo "[INFO] Stopping k8s docker containers"; docker ps | awk 'index($NF,"k8s_")==1 { print $1 }' | xargs -l -r docker stop + if [[ -z "${SKIP_IMAGE_CLEANUP-}" ]]; then + echo "[INFO] Removing k8s docker containers"; docker ps -a | awk 'index($NF,"k8s_")==1 { print $1 }' | xargs -l -r docker rm + fi + + echo "[INFO] Cleanup complete" +} + +test_privileges +test_godep + +echo "[INFO] Starting 'default' extended tests" TIME_SEC=1000 TIME_MIN=$((60 * $TIME_SEC)) +TEST_TYPE="openshift-extended-tests" TMPDIR="${TMPDIR:-"/tmp"}" -BASETMPDIR="${TMPDIR}/openshift-extended-tests" +BASETMPDIR="${TMPDIR}/${TEST_TYPE}" + +if [[ -d "${BASETMPDIR}" ]]; then + remove_tmp_dir $TEST_TYPE && mkdir -p "${BASETMPDIR}" +fi # Use either the latest release built images, or latest. if [[ -z "${USE_IMAGES-}" ]]; then @@ -29,34 +49,11 @@ if [[ -z "${USE_IMAGES-}" ]]; then fi fi - -if [[ -z "${BASETMPDIR-}" ]]; then - remove_tmp_dir && mkdir -p "${BASETMPDIR}" -fi - -OS_TEST_NAMESPACE="extended-tests" - -ETCD_DATA_DIR="${BASETMPDIR}/etcd" -VOLUME_DIR="${BASETMPDIR}/volumes" -FAKE_HOME_DIR="${BASETMPDIR}/openshift.local.home" LOG_DIR="${LOG_DIR:-${BASETMPDIR}/logs}" ARTIFACT_DIR="${ARTIFACT_DIR:-${BASETMPDIR}/artifacts}" -mkdir -p $LOG_DIR -mkdir -p $ARTIFACT_DIR - -DEFAULT_SERVER_IP=`ifconfig | grep -Ev "(127.0.0.1|172.17.42.1)" | grep "inet " | head -n 1 | sed 's/adr://' | awk '{print $2}'` -API_HOST="${API_HOST:-${DEFAULT_SERVER_IP}}" -API_PORT="${API_PORT:-8443}" -API_SCHEME="${API_SCHEME:-https}" -MASTER_ADDR="${API_SCHEME}://${API_HOST}:${API_PORT}" -PUBLIC_MASTER_HOST="${PUBLIC_MASTER_HOST:-${API_HOST}}" -KUBELET_SCHEME="${KUBELET_SCHEME:-https}" -KUBELET_HOST="${KUBELET_HOST:-127.0.0.1}" -KUBELET_PORT="${KUBELET_PORT:-10250}" - -SERVER_CONFIG_DIR="${BASETMPDIR}/openshift.local.config" -MASTER_CONFIG_DIR="${SERVER_CONFIG_DIR}/master" -NODE_CONFIG_DIR="${SERVER_CONFIG_DIR}/node-${KUBELET_HOST}" +API_HOST="${API_HOST:-$(ifconfig | grep -Ev "(127.0.0.1|172.17.42.1)" | grep "inet " | head -n 1 | sed 's/adr://' | awk '{print $2}')}" +setup_env_vars +mkdir -p $LOG_DIR $ARTIFACT_DIR # use the docker bridge ip address until there is a good way to get the auto-selected address from master # this address is considered stable @@ -66,45 +63,6 @@ CONTAINER_ACCESSIBLE_API_HOST="${CONTAINER_ACCESSIBLE_API_HOST:-172.17.42.1}" STI_CONFIG_FILE="${LOG_DIR}/stiAppConfig.json" DOCKER_CONFIG_FILE="${LOG_DIR}/dockerAppConfig.json" CUSTOM_CONFIG_FILE="${LOG_DIR}/customAppConfig.json" -GO_OUT="${OS_ROOT}/_output/local/go/bin" - -# set path so OpenShift is available -export PATH="${GO_OUT}:${PATH}" - -cleanup() { - set +e - pid=$(cat ${BASETMPDIR}/server.pid 2>/dev/null) - if [ ! -z "$pid" ]; then - server_pids=$(pgrep -P $pid) - kill $server_pids $(cat ${BASETMPDIR}/server.pid) ${ETCD_PID} - fi - rm -rf ${ETCD_DIR-} - - echo "[INFO] Stopping k8s docker containers"; docker ps | awk 'index($NF,"k8s_")==1 { print $1 }' | xargs -l -r docker stop - if [[ -z "${SKIP_IMAGE_CLEANUP-}" ]]; then - echo "[INFO] Removing k8s docker containers"; docker ps -a | awk 'index($NF,"k8s_")==1 { print $1 }' | xargs -l -r docker rm - fi - - echo "[INFO] Removing ${BASETMPDIR}" - rm -rf ${BASETMPDIR} - if [[ $? != 0 ]]; then - echo "[INFO] Unmounting volumes ..." - findmnt -lo TARGET | grep openshift-${OS_TEST_NAMESPACE} | xargs -r sudo umount - rm -rf ${BASETMPDIR} - fi - - remove_tmp_dir - echo "[INFO] Cleanup complete" -} - -remove_tmp_dir() { - rm -rf ${BASETMPDIR} &>/dev/null - if [[ $? != 0 ]]; then - echo "[INFO] Unmounting volumes ..." - findmnt -lo TARGET | grep openshift-extended-tests | xargs -r sudo umount - rm -rf ${BASETMPDIR} - fi -} trap "exit" INT TERM trap "cleanup" EXIT @@ -128,48 +86,7 @@ do SERVER_HOSTNAME_LIST="${SERVER_HOSTNAME_LIST},${IP_ADDRESS}" done <<< "${ALL_IP_ADDRESSES}" -openshift admin ca create-master-certs \ - --overwrite=false \ - --cert-dir="${MASTER_CONFIG_DIR}" \ - --hostnames="${SERVER_HOSTNAME_LIST}" \ - --master="${MASTER_ADDR}" \ - --public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}:${API_PORT}" - -echo "[INFO] Creating OpenShift node config" -openshift admin create-node-config \ - --listen="${KUBELET_SCHEME}://0.0.0.0:${KUBELET_PORT}" \ - --node-dir="${NODE_CONFIG_DIR}" \ - --node="${KUBELET_HOST}" \ - --hostnames="${KUBELET_HOST}" \ - --master="${MASTER_ADDR}" \ - --node-client-certificate-authority="${MASTER_CONFIG_DIR}/ca.crt" \ - --certificate-authority="${MASTER_CONFIG_DIR}/ca.crt" \ - --signer-cert="${MASTER_CONFIG_DIR}/ca.crt" \ - --signer-key="${MASTER_CONFIG_DIR}/ca.key" \ - --signer-serial="${MASTER_CONFIG_DIR}/ca.serial.txt" - -oadm create-bootstrap-policy-file --filename="${MASTER_CONFIG_DIR}/policy.json" - -echo "[INFO] Creating OpenShift config" -openshift start \ - --write-config=${SERVER_CONFIG_DIR} \ - --create-certs=false \ - --listen="${API_SCHEME}://0.0.0.0:${API_PORT}" \ - --master="${MASTER_ADDR}" \ - --public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}:${API_PORT}" \ - --hostname="${KUBELET_HOST}" \ - --volume-dir="${VOLUME_DIR}" \ - --etcd-dir="${ETCD_DATA_DIR}" \ - --images="${USE_IMAGES}" - - -echo "[INFO] Starting OpenShift server" -sudo env "PATH=${PATH}" OPENSHIFT_PROFILE=web OPENSHIFT_ON_PANIC=crash openshift start \ - --master-config=${MASTER_CONFIG_DIR}/master-config.yaml \ - --node-config=${NODE_CONFIG_DIR}/node-config.yaml \ - --loglevel=4 \ - &> "${LOG_DIR}/openshift.log" & -OS_PID=$! +configure_os_server export HOME="${FAKE_HOME_DIR}" # This directory must exist so Docker can store credentials in $HOME/.dockercfg @@ -188,11 +105,7 @@ if [[ "${API_SCHEME}" == "https" ]]; then echo "[INFO] To debug: export ADMIN_KUBECONFIG=$ADMIN_KUBECONFIG" fi - -wait_for_url "${KUBELET_SCHEME}://${KUBELET_HOST}:${KUBELET_PORT}/healthz" "[INFO] kubelet: " 0.5 60 -wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz" "apiserver: " 0.25 80 -wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz/ready" "apiserver(ready): " 0.25 80 -wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/api/v1/nodes/${KUBELET_HOST}" "apiserver(nodes): " 0.25 80 +start_os_server ${LOG_DIR} # install the router echo "[INFO] Installing the router" @@ -218,7 +131,6 @@ echo "[INFO] Starting extended tests ..." echo "[INFO] MASTER IP - ${MASTER_ADDR}" echo "[INFO] SERVER CONFIG PATH - ${SERVER_CONFIG_DIR}" -MASTER_ADDR="${MASTER_ADDR}" \ - KUBECONFIG="${ADMIN_KUBECONFIG}" \ +KUBECONFIG="${ADMIN_KUBECONFIG}" \ GOPATH="${OS_ROOT}/Godeps/_workspace:/${GOPATH}" \ go test -v -tags=default ./test/extended diff --git a/hack/util.sh b/hack/util.sh index 4c60fabc9f5d..14892ee908f9 100644 --- a/hack/util.sh +++ b/hack/util.sh @@ -5,6 +5,111 @@ TIME_SEC=1000 TIME_MIN=$((60 * $TIME_SEC)) +# setup_env_vars exports all the necessary environment variables for configuring and +# starting OS server. +function setup_env_vars { + export ETCD_DATA_DIR="${BASETMPDIR}/etcd" + export VOLUME_DIR="${BASETMPDIR}/volumes" + export FAKE_HOME_DIR="${BASETMPDIR}/openshift.local.home" + export API_HOST="${API_HOST:-127.0.0.1}" + export API_PORT="${API_PORT:-8443}" + export API_SCHEME="${API_SCHEME:-https}" + export MASTER_ADDR="${API_SCHEME}://${API_HOST}:${API_PORT}" + export PUBLIC_MASTER_HOST="${PUBLIC_MASTER_HOST:-${API_HOST}}" + export KUBELET_SCHEME="${KUBELET_SCHEME:-https}" + export KUBELET_HOST="${KUBELET_HOST:-127.0.0.1}" + export KUBELET_PORT="${KUBELET_PORT:-10250}" + export SERVER_CONFIG_DIR="${BASETMPDIR}/openshift.local.config" + export MASTER_CONFIG_DIR="${SERVER_CONFIG_DIR}/master" + export NODE_CONFIG_DIR="${SERVER_CONFIG_DIR}/node-${KUBELET_HOST}" + + # set path so OpenShift is available + GO_OUT="${OS_ROOT}/_output/local/go/bin" + export PATH="${GO_OUT}:${PATH}" +} + +# configure_and_start_os will create and write OS master certificates, node config, +# OS config. +function configure_os_server { + openshift admin ca create-master-certs \ + --overwrite=false \ + --cert-dir="${MASTER_CONFIG_DIR}" \ + --hostnames="${SERVER_HOSTNAME_LIST}" \ + --master="${MASTER_ADDR}" \ + --public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}:${API_PORT}" + + echo "[INFO] Creating OpenShift node config" + openshift admin create-node-config \ + --listen="${KUBELET_SCHEME}://0.0.0.0:${KUBELET_PORT}" \ + --node-dir="${NODE_CONFIG_DIR}" \ + --node="${KUBELET_HOST}" \ + --hostnames="${KUBELET_HOST}" \ + --master="${MASTER_ADDR}" \ + --node-client-certificate-authority="${MASTER_CONFIG_DIR}/ca.crt" \ + --certificate-authority="${MASTER_CONFIG_DIR}/ca.crt" \ + --signer-cert="${MASTER_CONFIG_DIR}/ca.crt" \ + --signer-key="${MASTER_CONFIG_DIR}/ca.key" \ + --signer-serial="${MASTER_CONFIG_DIR}/ca.serial.txt" + + oadm create-bootstrap-policy-file --filename="${MASTER_CONFIG_DIR}/policy.json" + + echo "[INFO] Creating OpenShift config" + openshift start \ + --write-config=${SERVER_CONFIG_DIR} \ + --create-certs=false \ + --listen="${API_SCHEME}://0.0.0.0:${API_PORT}" \ + --master="${MASTER_ADDR}" \ + --public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}:${API_PORT}" \ + --hostname="${KUBELET_HOST}" \ + --volume-dir="${VOLUME_DIR}" \ + --etcd-dir="${ETCD_DATA_DIR}" \ + --images="${USE_IMAGES}" + + echo "[INFO] Starting OpenShift server" + sudo env "PATH=${PATH}" OPENSHIFT_PROFILE=web OPENSHIFT_ON_PANIC=crash openshift start \ + --master-config=${MASTER_CONFIG_DIR}/master-config.yaml \ + --node-config=${NODE_CONFIG_DIR}/node-config.yaml \ + --loglevel=4 \ + &> "${1}/openshift.log" & + export OS_PID=$! +} + +# start_os_server starts the OS server, exports the PID of the OS server +# and waits until OS server endpoints are available +# +# $1 - log dir for OS server +function start_os_server { + wait_for_url "${KUBELET_SCHEME}://${KUBELET_HOST}:${KUBELET_PORT}/healthz" "[INFO] kubelet: " 1 80 + wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz" "apiserver: " 0.25 80 + wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz/ready" "apiserver(ready): " 0.25 80 + wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/api/v1/nodes/${KUBELET_HOST}" "apiserver(nodes): " 0.25 80 +} + +# test_privileges tests if the testing machine has iptables available +# and in PATH. Also test whether current user has sudo privileges. +function test_privileges { + if [[ -z "$(which iptables)" ]]; then + echo "IPTables not found - the end-to-end test requires a system with iptables for Kubernetes services." + exit 1 + fi + iptables --list > /dev/null 2>&1 + if [ $? -ne 0 ]; then + sudo iptables --list > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "You do not have iptables or sudo privileges. Kubernetes services will not work without iptables access. See https://github.com/GoogleCloudPlatform/kubernetes/issues/1859. Try 'sudo hack/test-end-to-end.sh'." + exit 1 + fi + fi +} + +# test_godep tests if the godep is in PATH. +function test_godep { + if [[ -z "$(which godep)" ]];then + echo "You do not have godep in your PATH. Extended tests require godep in order to start." + exit 1 + fi +} + # wait_for_command executes a command and waits for it to # complete or times out after max_wait. # @@ -237,6 +342,20 @@ function start_etcd { echo } +# remove_tmp_dir will try to delete the testing directory. +# If it fails will unmount all the mounts associated with +# the test. +# +# $1 expression for which the mounts should be checked +remove_tmp_dir() { + sudo rm -rf ${BASETMPDIR} &>/dev/null + if [[ $? != 0 ]]; then + echo "[INFO] Unmounting previously used volumes ..." + findmnt -lo TARGET | grep $1 | xargs -r sudo umount + sudo rm -rf ${BASETMPDIR} + fi +} + # stop_openshift_server utility function to terminate an # all-in-one running instance of OpenShift function stop_openshift_server()