|
| 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 |
0 commit comments