test.sh
#!/usr/bin/env bash

# Exit immediately on errors -- the helper scripts all emit github statuses internally
set -e

REPO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $REPO_ROOT_DIR

# Grab dcos-commons build/release tools:
rm -rf dcos-commons-tools/ && curl https://infinity-artifacts.s3.amazonaws.com/dcos-commons-tools.tgz | tar xz

# Get a CCM cluster if not already configured (see available settings in dcos-commons/tools/README.md):
if [ -z "$CLUSTER_URL" ]; then
    echo "CLUSTER_URL is empty/unset, launching new cluster."
    export CCM_AGENTS=5
    CLUSTERINFOFILE=./cluster_info.json
    rm -f $CLUSTERINFOFILE
    ./dcos-commons-tools/launch_ccm_cluster.py --output $CLUSTERINFOFILE
    ls -l $CLUSTERINFOFILE
    CLUSTER_INFO="$(cat $CLUSTERINFOFILE)"
    echo "Launched cluster: ${CLUSTER_INFO}"
    export CLUSTER_URL=$(echo "${CLUSTER_INFO}" | jq .url)
    export CLUSTER_ID=$(echo "${CLUSTER_INFO}" | jq .id)
    export CLUSTER_AUTH_TOKEN=$(echo "${CLUSTER_INFO}" | jq .auth_token)
    CLUSTER_CREATED="true"
else
    echo "Using provided CLUSTER_URL as cluster: $CLUSTER_URL"
    CLUSTER_CREATED=""
fi

echo Security: $SECURITY
if [ "$SECURITY" = "strict" ]; then
    ${REPO_ROOT_DIR}/dcos-commons-tools/setup_permissions.sh nobody cassandra-role
fi

# Run shakedown tests:
${REPO_ROOT_DIR}/dcos-commons-tools/run_tests.py shakedown ${REPO_ROOT_DIR}/integration/tests/ ${REPO_ROOT_DIR}/integration/requirements.txt

# Run legacy dcos-tests:
if [ -d "${REPO_ROOT_DIR}/dcos-tests" ]; then
    ${REPO_ROOT_DIR}/dcos-commons-tools/run_tests.py dcos-tests ${REPO_ROOT_DIR}/dcos-tests/infinitytests/cassandra ${REPO_ROOT_DIR}/dcos-tests/
else
    echo "${REPO_ROOT_DIR}/dcos-tests/ not found, skipping dcos-tests"
fi

# Tests succeeded. Out of courtesy, trigger a teardown of the cluster if we created it ourselves.
# Don't wait for the cluster to complete teardown.
if [ -n "${CLUSTER_CREATED}" ]; then
    ./dcos-commons-tools/launch_ccm_cluster.py trigger-stop ${CLUSTER_ID}
fi
