!/bin/bash
warning, the ordering of commands and tests in this file is very fragile, do not re-order without expecting failures
LOGFILE="/tmp/integration-test.log"
setup preqrequisites (expected default account admin user, test dependencies, etc.) and drive the integration test
ADMINEMAIL="admin@example.com" ADMINPASSWORD="mypassword"
IPADDRESS=/sbin/ifconfig | grep Bc | cut -d: -f2 | awk '{print $1}' | tr -d ' '
echo "$IPADDRESS" >> "$LOGFILE"
brittle: tests depends on the exact location of the phantomjs version and binary defined in the setup-selenium script, must wait for phantomjs to initialize
sudo /web/tests/setup-selenium-phantomjs.sh sleep 2
extract ssl cert and discover host and domain
cd /tmp tar -xf /tmp/integration-tests.tar.gz
cd /tmp/test/integration-tests; PEM=ls *.pem
echo $PEM >> "$LOGFILE"
ary=(${PEM//./ })
HOST=${ary[0]}
DOMAIN=() COUNTER=0
skip the host name and skip the .pem ending
for ((i=1; i < ${#ary[@]}; i++))
do
temp=${ary[$i]}
if ! [ $temp == "pem" ]; then
DOMAIN[$COUNTER]=$temp
COUNTER=expr $COUNTER + 1
fi
done
join
SAVE_IFS=$IFS IFS="." DOMAINSTRING="${DOMAIN[*]}" IFS=$SAVE_IFS
end globals
function seleniumTest { if [ "$#" -ne 5 ]; then echo "incorrect number of parameters" exit 1 else TARGET=$1 EMAIL=$2 PASSWORD=$3 LOG=$4 OUTPUT=$5 python /web/tests/selenium-integration-tests.py -H "$TARGET" -AE "$EMAIL" -AP "$PASSWORD" -B /tmp/phantomjs-1.9.2-linux-x86_64/bin/phantomjs -L "$LOG" --btf > "$OUTPUT" fi }
function apiV1Test { if [ "$#" -ne 5 ]; then echo "incorrect number of parameters" exit 1 else TESTFILE=$1 TARGET=$2 TOKEN=$3 LOG=$4 OUTPUT=$5 python /web/tests/APIv1/"$TESTFILE" -H "$TARGET" -T "$TOKEN" --nossl -L "$LOG" > "$OUTPUT" fi }
function getAPITokens
{
if [ "$#" -ne 4 ]; then
echo "incorrect number of parameters"
exit 1
else
TARGET=$1
EMAIL=$2
PASSWORD=$3
LOG=$4
APITOKENS=python /web/tests/selenium-get-info.py -H "$TARGET" -AE "$EMAIL" -AP "$PASSWORD" -B /tmp/phantomjs-1.9.2-linux-x86_64/bin/phantomjs -L "$LOG"
echo "$APITOKENS" >> "$LOG" # newline delimited list
i=0;
for TOKEN in $APITOKENS # convert newlines to array elements
do
ARRAY[$i]=$TOKEN
((i++))
done
echo "${ARRAY[@]}" # return array by printing all elements as a space delimited list
fi
}
end preparations, begin testing
echo /bin/date +%Y-%m-%d--%H-%M-%S
>> "$LOGFILE"
sleep 2
while [ "$CHEFLOG" -nt "$LOGFILE" ]; do
echo "chef log is still active, sleeping" >> "$LOGFILE"
echo /bin/date +%Y-%m-%d--%H-%M-%S
>> "$LOGFILE"
sleep 5
done
echo /bin/date +%Y-%m-%d--%H-%M-%S
>> "$LOGFILE"
echo "running ip address based selenium tests..." >> "$LOGFILE"
seleniumTest "$IPADDRESS" "$ADMINEMAIL" "$ADMINPASSWORD" "/tmp/ip-selenium-integration-test.log" "/tmp/ip-selenium-integration-test.xml"
if [ ! -s /tmp/ip-selenium-integration-test.xml ]; then echo "ip address based selenium tests failed" >> "$LOGFILE" exit 1 fi
echo /bin/date +%Y-%m-%d--%H-%M-%S
>> "$LOGFILE"
echo "getting api tokens (assumes at least 2 tokens were created)" >> "$LOGFILE"
TOKENS=( $( getAPITokens "$IPADDRESS" "$ADMINEMAIL" "$ADMINPASSWORD" "/tmp/get-info-selenium.log" ) )
echo "returned array size = ${#TOKENS[@]}" >> "$LOGFILE"
echo "tokens = ${TOKENS[@]}" >> "$LOGFILE"
echo /bin/date +%Y-%m-%d--%H-%M-%S
>> "$LOGFILE"
echo "running ip address based api v1 tests with token: ${TOKENS[0]}" >> "$LOGFILE"
apiV1Test "api_v1_integration_test.py" "$IPADDRESS" "${TOKENS[0]}" "/tmp/ip-v1-api-integration-test.log" "/tmp/ip-v1-api-integration-test.xml"
echo /bin/date +%Y-%m-%d--%H-%M-%S
>> "$LOGFILE"
echo "running ip address based api v1 history test with token: ${TOKENS[1]}" >> "$LOGFILE"
apiV1Test "api_v1_message_history_test.py" "$IPADDRESS" "${TOKENS[1]}" "/tmp/ip-v1-api-message-history-test.log" "/tmp/ip-v1-api-message-history-test.xml"
echo "$DOMAINSTRING" >> "$LOGFILE" echo "network -n $HOST -d $DOMAINSTRING" >> "$LOGFILE" network -n "$HOST" -d "$DOMAINSTRING" >> "$LOGFILE" echo "ssl --import /tmp/test/integration-tests/$PEM" >> "$LOGFILE" ssl --import "/tmp/test/integration-tests/$PEM" >> "$LOGFILE"
echo /bin/date +%Y-%m-%d--%H-%M-%S
>> "$LOGFILE"
echo "running fqdn with ssl cert based selenium tests..." >> "$LOGFILE"
seleniumTest "$HOST.$DOMAINSTRING" "$ADMINEMAIL" "$ADMINPASSWORD" "/tmp/fqdn-selenium-integration-test.log" "/tmp/fqdn-selenium-integration-test.xml"
echo /bin/date +%Y-%m-%d--%H-%M-%S
>> "$LOGFILE"
echo "getting api tokens (assumes at least 2 tokens were created)" >> "$LOGFILE"
TOKENS=( $( getAPITokens "$IPADDRESS" "$ADMINEMAIL" "$ADMINPASSWORD" "/tmp/get-info-selenium2.log" ) )
TOKENCOUNT=${#TOKENS[@]} echo "returned array size = $TOKENCOUNT" >> "$LOGFILE" echo "tokens = ${TOKENS[@]}" >> "$LOGFILE"
LASTINDEX=TOKENCOUNT-1 BEFORELASTINDEX=TOKENCOUNT-2
echo /bin/date +%Y-%m-%d--%H-%M-%S
>> "$LOGFILE"
echo "running ip address based api v1 tests with token: ${TOKENS[$BEFORELASTINDEX]}" >> "$LOGFILE"
apiV1Test "api_v1_integration_test.py" "$HOST.$DOMAINSTRING" "${TOKENS[$BEFORELASTINDEX]}" "/tmp/fqdn-v1-api-integration-test.log" "/tmp/fqdn-v1-api-integration-test.xml"
echo /bin/date +%Y-%m-%d--%H-%M-%S
>> "$LOGFILE"
echo "running ip address based api v1 history test with token: ${TOKENS[$LASTINDEX]}" >> "$LOGFILE"
apiV1Test "api_v1_message_history_test.py" "$HOST.$DOMAINSTRING" "${TOKENS[$LASTINDEX]}" "/tmp/fdqn-v1-api-message-history-test.log" "/tmp/fqdn-v1-api-message-history-test.xml"