Skip to content

Commit 11e9a49

Browse files
committed
Run system test using Jenkins pipeline
Existing test at https://jenkins.confluent.io/job/client-python-system-test-kafka-1.0
1 parent f568ba8 commit 11e9a49

File tree

5 files changed

+304
-0
lines changed

5 files changed

+304
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ tmp-build
1919
wheelhouse
2020
dl-*
2121
*.whl
22+
.pytest_cache

tests/system/Jenkinsfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
def config = jobConfig {
2+
cron = '@midnight'
3+
nodeLabel = 'docker-oraclejdk7'
4+
realJobPrefixes = ['system-test-python-client']
5+
slackChannel = 'clients-eng'
6+
timeoutHours = 3
7+
}
8+
9+
def job = {
10+
withCredentials([
11+
file(credentialsId: 'muckrake-2017-06-01.pem', variable: 'MUCKRAKE_PEM')]) {
12+
sshagent(['ConfluentJenkins Github SSH Key']) {
13+
configFileProvider([configFile(fileId: 'jenkins-maven-global-settings',
14+
targetLocation: '/home/jenkins/.m2/settings.xml')]) {
15+
stage("Run tests") {
16+
sh 'tests/system/run-tests.sh'
17+
}
18+
}
19+
}
20+
}
21+
}
22+
23+
def post = {
24+
withCredentials([file(credentialsId: 'muckrake-2017-06-01.pem', variable: 'MUCKRAKE_PEM')]) {
25+
stage('Cleanup tests') {
26+
sh 'tests/system/cleanup-tests.sh'
27+
}
28+
29+
if (config.isRealJob) {
30+
stage('Upload test results') {
31+
def s3Bucket = sh(
32+
script: 'python jenkins-common/scripts/system-tests/test-result-storage/get_upload_location.py ' +
33+
'--project muckrake --branch python-client-' + env.BRANCH_NAME, returnStdout: true).trim()
34+
def resultsDir = sh(script: 'ls -tr results | tail -1', returnStdout: true).trim()
35+
36+
config.testResultSpecs['ducktape'] = "results/$resultsDir/report.json"
37+
config.testResultSpecs['ducktape_results_url'] = "s3://$s3Bucket/$resultsDir"
38+
39+
sh '''
40+
tests/system/upload-tests.sh muckrake python-client-$BRANCH_NAME \
41+
https://github.com/confluentinc/confluent-kafka-python tests/kafkatest/tests/client
42+
'''
43+
}
44+
}
45+
}
46+
}
47+
48+
runJob config, job, post

tests/system/cleanup-tests.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# Used by Jenkins in post step to cleanup after ./run-tests.sh
4+
5+
if [[ -z $WORKSPACE ]]; then
6+
echo "This should be run by Jenkins only"
7+
exit 1
8+
fi
9+
10+
set -e
11+
12+
. jenkins-common/resources/scripts/extract-iam-credential.sh
13+
14+
set -x
15+
16+
KAFKA_DIR=$WORKSPACE/kafka
17+
18+
if [ -d $KAFKA_DIR ]; then
19+
cd $KAFKA_DIR
20+
vagrant destroy -f
21+
fi

tests/system/run-tests.sh

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ -z $WORKSPACE ]]; then
4+
echo "This should be run by Jenkins only"
5+
exit 1
6+
fi
7+
8+
set -e
9+
10+
# Checkout supporting scripts
11+
# Used by add_suffix_to_latest_results function above and jenkins/upload-tests.sh
12+
rm -rf jenkins-common
13+
git clone git@github.com:confluentinc/jenkins-common.git
14+
15+
cp $MUCKRAKE_PEM muckrake.pem
16+
17+
. jenkins-common/resources/scripts/extract-iam-credential.sh
18+
19+
set -x
20+
21+
# Immediately flush output when running python
22+
export PYTHONUNBUFFERED=1
23+
24+
TEST_PATH=tests/kafkatest/tests/client
25+
26+
LIBRDKAFKA_BRANCH=master
27+
KAFKA_BRANCH=1.0
28+
REPO=https://github.com/apache/kafka.git
29+
30+
CACHE=$WORKSPACE/cache # Helps with reusing vagrant cluster
31+
RESULTS=$WORKSPACE/results
32+
KAFKA_DIR=$WORKSPACE/kafka
33+
34+
# Bringing up a Vagrant cluster is slow, so we may want to reuse a preexisting cluster
35+
# These flags provide some control over caching behavior
36+
DESTROY_BEFORE=true # Destroy cluster (if applicable) *before* test run?
37+
38+
# VAGRANT_CLEANUP specifies what action to take after running the tests
39+
NO_ACTION="no_action"
40+
DESTROY="destroy"
41+
SHUTDOWN="shutdown"
42+
VAGRANT_CLEANUP=$DESTROY
43+
44+
# Build python client wheels and deploy on vagrant workers
45+
# Note: a virtualenv must be active.
46+
function build_python_client {
47+
local this_host=`curl http://169.254.169.254/latest/meta-data/local-ipv4`
48+
export DOCKER_HOST="tcp://$this_host:2375"
49+
50+
tools/build-linux-selfcontained.sh $LIBRDKAFKA_BRANCH wheels
51+
52+
# Deploy wheels on workers
53+
confluent_kafka/kafkatest/deploy.sh --prepare $KAFKA_DIR wheels
54+
55+
# Synchronize workers
56+
pushd $KAFKA_DIR
57+
vagrant rsync
58+
popd # $KAFKA_DIR
59+
}
60+
61+
62+
function is_ducktape_session_id {
63+
local string="$1"
64+
65+
if [[ -z "$(echo "$string" | egrep "^[0-9]{4}-[0-9]{2}-[0-9]{2}--[0-9]{3}$")" ]]; then
66+
echo "false"
67+
else
68+
echo "true"
69+
fi
70+
}
71+
72+
# add a suffix which contains additional information such as
73+
# github user, branch, commit id
74+
function add_suffix_to_latest_results {
75+
if [[ -d "$RESULTS" ]]; then
76+
cd $RESULTS
77+
else
78+
return
79+
fi
80+
81+
# easier to reason about state if we get rid of symlink
82+
rm -f latest || true
83+
84+
# most recently modified
85+
latest_name="$(basename "$(ls -tr | tail -1)")"
86+
87+
# We only want to rename latest_name if it is an unadulterated ducktape session id
88+
if [[ "$(is_ducktape_session_id "$latest_name")" == "false" ]]; then
89+
return
90+
fi
91+
92+
suffix="$($WORKSPACE/jenkins-common/scripts/system-tests/kafka-system-test/make-repo-identifier.sh --directory $KAFKA_DIR)"
93+
archive_name="${latest_name}.${suffix}"
94+
95+
mv "$latest_name" "$archive_name"
96+
97+
echo "$BUILD_URL" > "$archive_name/jenkins.txt"
98+
}
99+
100+
trap cleanup EXIT
101+
function cleanup() {
102+
add_suffix_to_latest_results
103+
}
104+
105+
# Return false if at least one node is not running, else return true
106+
function vagrant_alive() {
107+
vagrant status | egrep "(poweroff)|(not)|(stopped)" > /dev/null
108+
result=$?
109+
if [ "x$result" != "x0" ]; then
110+
echo true
111+
else
112+
echo false
113+
fi
114+
}
115+
116+
117+
# Clear results from the last run
118+
# Do this before a test run rather than after so that jenkins can archive test output
119+
rm -rf $RESULTS
120+
121+
# Get kafka and build
122+
if [ ! -d $KAFKA_DIR ]; then
123+
echo "Downloading kafka..."
124+
git clone $REPO $KAFKA_DIR
125+
fi
126+
echo "Checking out $KAFKA_BRANCH ..."
127+
cd $KAFKA_DIR
128+
git pull
129+
git checkout $KAFKA_BRANCH
130+
gradle
131+
./gradlew clean systemTestLibs
132+
133+
# Cached vagrant data
134+
if [ -d $CACHE ]; then
135+
cd $CACHE
136+
137+
# Mark cluster for destruction if provisioning script has changed
138+
# TODO - vagrant doesn't seem to deal well with any changes, so
139+
# we might want to be more aggressive with overriding DESTROY_BEFORE
140+
if [ -f vagrant/base.sh ]; then
141+
if [ ! -z `diff vagrant/base.sh $KAFKA_DIR/vagrant/base.sh` ]; then
142+
echo "Vagrant provisioning has changed, so vagrant cluster will not be reused"
143+
DESTROY_BEFORE=true
144+
fi
145+
fi
146+
147+
# Cached VM data
148+
if [ -d .vagrant ]; then
149+
if [ "x$DESTROY_BEFORE" != "xtrue" ]; then
150+
echo "Pulling in cached Vagrant data from previous test run..."
151+
cp -r .vagrant/ $KAFKA_DIR/.vagrant/
152+
fi
153+
fi
154+
fi
155+
156+
echo "Grabbing Vagrantfile.local"
157+
cp $WORKSPACE/jenkins-common/scripts/system-tests/kafka-system-test/Vagrantfile.local $KAFKA_DIR
158+
159+
if [ "x$DESTROY_BEFORE" == "xtrue" ]; then
160+
echo "Destroying Vagrant cluster before running tests..."
161+
cd $KAFKA_DIR
162+
vagrant destroy -f || true
163+
fi
164+
165+
# Bring up cluster if necessary
166+
alive=`vagrant_alive`
167+
if [ "x$alive" == "xtrue" ]; then
168+
echo "Vagrant cluster is already running"
169+
echo "Syncing contents of kafka directory to virtual machines..."
170+
vagrant rsync
171+
else
172+
echo "Bringing up cluster..."
173+
if [[ -e vagrant/vagrant-up.sh ]]; then
174+
vagrant/vagrant-up.sh --aws
175+
else
176+
vagrant up --provider=aws --no-parallel --no-provision
177+
echo "Provisioning cluster..."
178+
vagrant provision
179+
fi
180+
fi
181+
182+
# Set up python dependencies
183+
cd $KAFKA_DIR
184+
virtualenv venv
185+
. venv/bin/activate
186+
cd tests
187+
python setup.py develop
188+
189+
# Build Python client
190+
cd $WORKSPACE
191+
build_python_client
192+
193+
# Run the tests
194+
cd $KAFKA_DIR
195+
python `which ducktape` --debug $TEST_PATH \
196+
--globals tests/confluent-kafka-python/globals.json \
197+
--results-root $RESULTS \
198+
--compress

tests/system/upload-tests.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
# Used by Jenkins in post step to upload results from ./run-tests.sh
4+
5+
if [[ $# -lt 4 ]]
6+
then
7+
echo "usage: upload-system-test-results <kafka|muckrake> branch repo test_path [ducktape_args]"
8+
exit -1
9+
fi
10+
11+
if [[ -z $WORKSPACE ]]; then
12+
echo "This should be run by Jenkins only"
13+
exit 1
14+
fi
15+
16+
set -e
17+
18+
. jenkins-common/resources/scripts/extract-iam-credential.sh
19+
20+
set -x
21+
22+
PROJECT=$1
23+
BRANCH=$2
24+
REPO=$3
25+
TEST_PATH=$4
26+
DUCKTAPE_ARGS=${DUCKTAPE_ARGS:-$5} # Existing caller might be setting it via env...
27+
DIRECTORY=$WORKSPACE/results
28+
BUILD_URL=$JOB_URL
29+
30+
subdir=$(ls -tr $DIRECTORY | tail -1)
31+
32+
bucket=$(python $WORKSPACE/jenkins-common/scripts/system-tests/test-result-storage/get_upload_location.py \
33+
--project $PROJECT --branch $BRANCH)
34+
bash -x $WORKSPACE/jenkins-common/scripts/system-tests/test-result-storage/s3-upload.sh \
35+
--bucket $bucket --directory $DIRECTORY
36+
echo Uploaded to S3 bucket: $bucket

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy