-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathrun_integration_test.sh
executable file
·279 lines (253 loc) · 8.82 KB
/
run_integration_test.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
#
# This script is used in Gradle to run single or a set of Python integration tests
# locally or on Jenkins. Note, this script doesn't setup python environment which is
# required for integration test. In order to do so, run Gradle tasks defined in
# :sdks:python:test-suites instead.
#
# In order to run test with customer options, use following commandline flags:
#
# Pipeline related flags:
# runner -> Runner that execute pipeline job.
# e.g. TestDataflowRunner, TestDirectRunner
# project -> Project name of the cloud service.
# region -> Compute Engine region to create the Dataflow job.
# gcs_location -> Base location on GCS. Some pipeline options are
# derived from it including output, staging_location
# and temp_location.
# sdk_location -> Python tar ball location. Glob is accepted.
# num_workers -> Number of workers.
# sleep_secs -> Number of seconds to wait before verification.
# streaming -> True if a streaming job.
# kms_key_name -> Name of Cloud KMS encryption key to use in some tests.
# pipeline_opts -> List of space separated pipeline options. If this
# flag is specified, all above flag will be ignored.
# Please include all required pipeline options when
# using this flag.
#
# Test related flags:
# test_opts -> List of space separated options to configure Pytest test
# during execution. Commonly used options like `--capture=no`
# `--collect-only`. More can be found in
# https://docs.pytest.org/en/latest/reference.html#command-line-flags
# suite -> Namespace for this run of tests. Required if running
# under Jenkins. Used to differentiate runs of the same
# tests with different interpreters/dependencies/etc.
#
# Example usages:
# - Run full set of PostCommit tests with default pipeline options:
# `$ ./run_integration_test.sh`
#
# - Run single integration test with default pipeline options:
# `$ ./run_integration_test.sh --test_opts apache_beam/examples/wordcount_it_test.py::WordCountIT::test_wordcount_it`
#
# - Run full set of PostCommit tests with customized pipeline options:
# `$ ./run_integration_test.sh --project my-project --gcs_location gs://my-location`
###########################################################################
# Get pipeline options specified from commandline arguments.
# Default pipeline options
PROJECT=apache-beam-testing
RUNNER=TestDataflowRunner
REGION=us-central1
GCS_LOCATION=gs://temp-storage-for-end-to-end-tests
SDK_LOCATION=build/apache-beam.tar.gz
NUM_WORKERS=1
SLEEP_SECS=20
STREAMING=false
KMS_KEY_NAME="projects/apache-beam-testing/locations/global/keyRings/beam-it/cryptoKeys/test"
SUITE=""
COLLECT_MARKERS=
REQUIREMENTS_FILE=""
ARCH=""
PY_VERSION=""
# Default test (pytest) options.
# Run WordCountIT.test_wordcount_it by default if no test options are
# provided.
TEST_OPTS="apache_beam/examples/wordcount_it_test.py::WordCountIT::test_wordcount_it"
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--runner)
RUNNER="$2"
shift # past argument
shift # past value
;;
--project)
PROJECT="$2"
shift # past argument
shift # past value
;;
--region)
REGION="$2"
shift # past argument
shift # past value
;;
--gcs_location)
GCS_LOCATION="$2"
shift # past argument
shift # past value
;;
--sdk_location)
SDK_LOCATION="$2"
shift # past argument
shift # past value
;;
--requirements_file)
REQUIREMENTS_FILE="$2"
shift # past argument
shift # past value
;;
--num_workers)
NUM_WORKERS="$2"
shift # past argument
shift # past value
;;
--sleep_secs)
SLEEP_SECS="$2"
shift # past argument
shift # past value
;;
--streaming)
STREAMING="$2"
shift # past argument
shift # past value
;;
--kms_key_name)
KMS_KEY_NAME="$2"
shift # past argument
shift # past value
;;
--dataflow_endpoint)
DATAFLOW_ENDPOINT="$2"
shift # past argument
shift # past value
;;
--pipeline_opts)
PIPELINE_OPTS="$2"
shift # past argument
shift # past value
;;
--test_opts)
TEST_OPTS="$2"
shift # past argument
shift # past value
;;
--suite)
SUITE="$2"
shift # past argument
shift # past value
;;
--collect)
COLLECT_MARKERS="-m=$2"
shift # past argument
shift # past value
;;
--arch)
ARCH="$2"
shift # past argument
shift # past value
;;
--py_version)
PY_VERSION="$2"
shift # past argument
shift # past value
;;
*) # unknown option
echo "Unknown option: $1"
exit 1
;;
esac
done
if [[ "$JENKINS_HOME" != "" && "$SUITE" == "" ]]; then
echo "Argument --suite is required in a Jenkins environment."
exit 1
fi
set -o errexit
###########################################################################
# Check that the script is running in a known directory.
if [[ $PWD != *sdks/python* ]]; then
echo 'Unable to locate Apache Beam Python SDK root directory'
exit 1
fi
# Go to the Apache Beam Python SDK root
if [[ $PWD != *sdks/python ]]; then
cd $(pwd | sed 's/sdks\/python.*/sdks\/python/')
fi
###########################################################################
# Build pipeline options if not provided in --pipeline_opts from commandline
if [[ -z $PIPELINE_OPTS ]]; then
# Get tar ball path
if [[ $(find ${SDK_LOCATION} 2> /dev/null) ]]; then
SDK_LOCATION=$(find ${SDK_LOCATION} | tail -n1)
else
echo "[WARNING] Could not find SDK tarball in SDK_LOCATION: $SDK_LOCATION."
fi
# Options used to run testing pipeline on Cloud Dataflow Service. Also used for
# running on DirectRunner (some options ignored).
opts=(
"--runner=$RUNNER"
"--project=$PROJECT"
"--region=$REGION"
"--staging_location=$GCS_LOCATION/staging-it"
"--temp_location=$GCS_LOCATION/temp-it"
"--output=$GCS_LOCATION/py-it-cloud/output"
"--sdk_location=$SDK_LOCATION"
"--num_workers=$NUM_WORKERS"
"--sleep_secs=$SLEEP_SECS"
)
# Add --streaming if provided
if [[ "$STREAMING" = true ]]; then
opts+=("--streaming")
fi
if [[ -n "$REQUIREMENTS_FILE" ]]; then
opts+=("--requirements_file=$REQUIREMENTS_FILE")
fi
if [[ "$ARCH" == "ARM" ]]; then
opts+=("--machine_type=t2a-standard-1")
IMAGE_NAME="beam_python${PY_VERSION}_sdk"
opts+=("--sdk_container_image=us.gcr.io/$PROJECT/$USER/$IMAGE_NAME:$MULTIARCH_TAG")
fi
if [[ ! -z "$KMS_KEY_NAME" ]]; then
opts+=(
"--kms_key_name=$KMS_KEY_NAME"
"--dataflow_kms_key=$KMS_KEY_NAME"
)
fi
if [[ ! -z "$DATAFLOW_ENDPOINT" ]]; then
opts+=("--dataflow_endpoint=$DATAFLOW_ENDPOINT")
fi
PIPELINE_OPTS=$(IFS=" " ; echo "${opts[*]}")
fi
# Handle double quotes in PIPELINE_OPTS
# add a backslash before `"` to keep it in command line options
PIPELINE_OPTS=${PIPELINE_OPTS//\"/\\\"}
###########################################################################
# Run tests and validate that jobs finish successfully.
echo ">>> RUNNING integration tests with pipeline options: $PIPELINE_OPTS"
echo ">>> pytest options: $TEST_OPTS"
echo ">>> collect markers: $COLLECT_MARKERS"
ARGS="-v -rs -o junit_suite_name=$SUITE -o log_cli=true -o log_level=INFO --junitxml=pytest_$SUITE.xml $TEST_OPTS"
# Handle markers as an independent argument from $TEST_OPTS to prevent errors in space separated flags
if [ -z "$COLLECT_MARKERS" ]; then
pytest $ARGS --test-pipeline-options="$PIPELINE_OPTS"
else
pytest $ARGS --test-pipeline-options="$PIPELINE_OPTS" "$COLLECT_MARKERS"
fi