forked from d2iq-archive/dcos-jenkins-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-runner.sh
executable file
·133 lines (105 loc) · 3.78 KB
/
test-runner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash
# Build a framework, package, upload it, and then run its integration tests.
# (Or all frameworks depending on arguments.) Expected to be called by test.sh
# Exit immediately on errors
set -e -x
# Export the required environment variables:
export DCOS_ENTERPRISE
export PYTHONUNBUFFERED=1
export SECURITY
REPO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ "$FRAMEWORK" = "all" ]; then
if [ -n "$STUB_UNIVERSE_URL" ]; then
echo "Cannot set \$STUB_UNIVERSE_URL when building all frameworks"
exit 1
fi
# randomize the FRAMEWORK_LIST
FRAMEWORK_LIST=$(ls $REPO_ROOT_DIR/frameworks | while read -r fw; do printf "%05d %s\n" "$RANDOM" "$fw"; done | sort -n | cut -c7- )
else
FRAMEWORK_LIST=$FRAMEWORK
fi
echo "Beginning integration tests at "`date`
# Strip the quotes from the -k and -m options to pytest
PYTEST_K_FROM_PYTEST_ARGS=`echo "$PYTEST_ARGS" \
| sed -e "s#.*-k [\'\"]\([^\'\"]*\)['\"].*#\1#"`
if [ "$PYTEST_K_FROM_PYTEST_ARGS" == "$PYTEST_ARGS" ]; then
PYTEST_K_FROM_PYTEST_ARGS=
else
if [ -n "$PYTEST_K" ]; then
PYTEST_K="$PYTEST_K "
fi
PYTEST_K="${PYTEST_K}${PYTEST_K_FROM_PYTEST_ARGS}"
PYTEST_ARGS=`echo "$PYTEST_ARGS" \
| sed -e "s#-k [\'\"]\([^\'\"]*\)['\"]##"`
fi
PYTEST_M_FROM_PYTEST_ARGS=`echo "$PYTEST_ARGS" \
| sed -e "s#.*-m [\'\"]\([^\'\"]*\)['\"].*#\1#"`
if [ "$PYTEST_M_FROM_PYTEST_ARGS" == "$PYTEST_ARGS" ]; then
PYTEST_M_FROM_PYTEST_ARGS=
else
if [ -n "$PYTEST_M" ]; then
PYTEST_M="$PYTEST_M "
fi
PYTEST_M="${PYTEST_M}${PYTEST_M_FROM_PYTEST_ARGS}"
PYTEST_ARGS=`echo "$PYTEST_ARGS" \
| sed -e "s#-m [\'\"]\([^\'\"]*\)['\"]##"`
fi
pytest_args=()
# PYTEST_K and PYTEST_M are treated as single strings, and should thus be added
# to the pytest_args array in quotes.
if [ -n "$PYTEST_K" ]; then
pytest_args+=(-k "$PYTEST_K")
fi
if [ -n "$PYTEST_M" ]; then
pytest_args+=(-m "$PYTEST_M")
fi
# Each of the space-separated parts of PYTEST_ARGS are treated separately.
if [ -n "$PYTEST_ARGS" ]; then
pytest_args+=($PYTEST_ARGS)
fi
if [ -f /ssh/key ]; then
eval "$(ssh-agent -s)"
ssh-add /ssh/key
fi
if [ -n $PYTHONPATH ]; then
if [ -d ${REPO_ROOT_DIR}/testing ]; then
export PYTHONPATH=${REPO_ROOT_DIR}/testing
fi
fi
for framework in $FRAMEWORK_LIST; do
echo "STARTING: $framework"
FRAMEWORK_DIR=$REPO_ROOT_DIR/frameworks/${framework}
if [ ! -d ${FRAMEWORK_DIR} -a "${FRAMEWORK}" != "all" ]; then
echo "FRAMEWORK_DIR=${FRAMEWORK_DIR} does not exist."
echo "Assuming single framework in ${REPO_ROOT}."
FRAMEWORK_DIR=${REPO_ROOT_DIR}
fi
if [ -z "$CLUSTER_URL" ]; then
echo "No DC/OS cluster specified. Attempting to create one now"
dcos-launch create -c /build/config.yaml
dcos-launch wait
# configure the dcos-cli/shakedown backend
export CLUSTER_URL=https://`dcos-launch describe | jq -r .masters[0].public_ip`
CLUSTER_WAS_CREATED=True
fi
echo "Configuring dcoscli for cluster: $CLUSTER_URL"
echo "\tDCOS_ENTERPRISE=$DCOS_ENTERPRISE"
/build/tools/dcos_login.py
if [ -f cluster_info.json ]; then
if [ `cat cluster_info.json | jq .key_helper` == 'true' ]; then
cat cluster_info.json | jq -r .ssh_private_key > /root/.ssh/id_rsa
chmod 600 /root/.ssh/id_rsa
fi
fi
echo "Starting test for $framework at "`date`
py.test -vv -s "${pytest_args[@]}" ${FRAMEWORK_DIR}/tests
exit_code=$?
echo "Finished test for $framework at "`date`
done
echo "Finished integration tests at "`date`
if [ -n "$CLUSTER_WAS_CREATED" ]; then
echo "The DC/OS cluster $CLUSTER_URL was created. Please run"
echo "\t\$ dcos-launch delete"
echo "to remove the cluster."
fi
exit $exit_code