|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Licensed to Elasticsearch B.V. under one or more contributor |
| 4 | +# license agreements. See the NOTICE file distributed with |
| 5 | +# this work for additional information regarding copyright |
| 6 | +# ownership. Elasticsearch B.V. licenses this file to you under |
| 7 | +# the Apache License, Version 2.0 (the "License"); you may |
| 8 | +# not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | + |
| 20 | +set -e |
| 21 | + |
| 22 | +readonly MIN_DOCKER_MEM_BYTES=$(expr 6 \* 1024 \* 1024 \* 1024) |
| 23 | + |
| 24 | +function check_prerequisites { |
| 25 | + exit_if_docker_not_running |
| 26 | + |
| 27 | + DOCKER_MEM_BYTES=$(docker info --format="{{.MemTotal}}") |
| 28 | + if [[ ${DOCKER_MEM_BYTES} -lt ${MIN_DOCKER_MEM_BYTES} ]]; then |
| 29 | + echo "Error: Docker is not configured with enough memory. ($DOCKER_MEM_BYTES bytes)" |
| 30 | + echo "Please increase memory available to Docker to at least ${MIN_DOCKER_MEM_BYTES} bytes" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | + |
| 34 | + if ! type docker-compose > /dev/null; then |
| 35 | + echo "docker compose is necessary to run the integration tests" |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | +} |
| 39 | + |
| 40 | +function log { |
| 41 | + local ts=$(date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 42 | + echo "[${ts}] [${1}] ${2}" |
| 43 | +} |
| 44 | + |
| 45 | +function info { |
| 46 | + log "INFO" "${1}" |
| 47 | +} |
| 48 | + |
| 49 | +function warn { |
| 50 | + log "WARN" "${1}" |
| 51 | +} |
| 52 | + |
| 53 | +function error { |
| 54 | + log "ERROR" "${1}" |
| 55 | +} |
| 56 | + |
| 57 | +function stop_and_clean_docker_container { |
| 58 | + docker stop ${1} > /dev/null || true |
| 59 | + docker rm ${1} > /dev/null || true |
| 60 | +} |
| 61 | + |
| 62 | +function kill_related_es_processes { |
| 63 | + # kill all lingering Rally instances that might still be hanging |
| 64 | + set +e |
| 65 | + # kill all lingering Elasticsearch Docker containers launched by Rally |
| 66 | + RUNNING_DOCKER_CONTAINERS=$(docker ps --filter "label=io.rally.description" --format "{{.ID}}") |
| 67 | + if [ -n "${RUNNING_DOCKER_CONTAINERS}" ]; then |
| 68 | + for container in "${RUNNING_DOCKER_CONTAINERS}" |
| 69 | + do |
| 70 | + stop_and_clean_docker_container ${container} |
| 71 | + done |
| 72 | + fi |
| 73 | + set -e |
| 74 | +} |
| 75 | + |
| 76 | +function exit_if_docker_not_running { |
| 77 | + if ! docker ps >/dev/null 2>&1; then |
| 78 | + error "Docker is required to run integration tests. Install and run Docker and try again." |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | +} |
| 82 | + |
| 83 | +function docker_compose { |
| 84 | + if [[ "$1" == "up" ]]; then |
| 85 | + docker-compose -f docker/docker-compose-tests.yml up --abort-on-container-exit |
| 86 | + elif [[ "$1" == "down" ]]; then |
| 87 | + docker-compose -f docker/docker-compose-tests.yml down -v |
| 88 | + else |
| 89 | + error "Unknown argument [$1] for docker-compose, exiting." |
| 90 | + fi |
| 91 | +} |
| 92 | + |
| 93 | +# This function gets called by release-docker.sh and assumes the image has been already built |
| 94 | +function test_docker_release_image { |
| 95 | + if [[ -z "${RALLY_VERSION}" ]]; then |
| 96 | + error "Environment variable [RALLY_VERSION] needs to be set to test the release image; exiting." |
| 97 | + elif [[ -z "${RALLY_LICENSE}" ]]; then |
| 98 | + error "Environment variable [RALLY_LICENSE] needs to be set to test the release image; exiting." |
| 99 | + fi |
| 100 | + |
| 101 | + docker_compose down |
| 102 | + |
| 103 | + info "Testing Rally docker image uses the right version" |
| 104 | + actual_version=$(docker run --rm elastic/rally:${RALLY_VERSION} esrally --version | cut -d ' ' -f 2,2) |
| 105 | + if [[ ${actual_version} != ${RALLY_VERSION} ]]; then |
| 106 | + echo "Rally version in Docker image: [${actual_version}] doesn't match the expected version [${RALLY_VERSION}]" |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | + |
| 110 | + info "Testing Rally docker image version label is correct" |
| 111 | + actual_version=$(docker inspect --format '{{ index .Config.Labels "org.label-schema.version"}}' elastic/rally:${RALLY_VERSION}) |
| 112 | + if [[ ${actual_version} != ${RALLY_VERSION} ]]; then |
| 113 | + echo "org.label-schema.version label in Rally Docker image: [${actual_version}] doesn't match the expected version [${RALLY_VERSION}]" |
| 114 | + exit 1 |
| 115 | + fi |
| 116 | + |
| 117 | + info "Testing Rally docker image license label is correct" |
| 118 | + actual_license=$(docker inspect --format '{{ index .Config.Labels "license"}}' elastic/rally:${RALLY_VERSION}) |
| 119 | + if [[ ${actual_license} != ${RALLY_LICENSE} ]]; then |
| 120 | + echo "license label in Rally Docker image: [${actual_license}] doesn't match the expected license [${RALLY_LICENSE}]" |
| 121 | + exit 1 |
| 122 | + fi |
| 123 | + |
| 124 | + export TEST_COMMAND="--pipeline=benchmark-only --test-mode --track=geonames --challenge=append-no-conflicts-index-only --target-hosts=es01:9200" |
| 125 | + info "Testing Rally docker image using parameters: ${TEST_COMMAND}" |
| 126 | + docker_compose up |
| 127 | + docker_compose down |
| 128 | + |
| 129 | + # list should work |
| 130 | + export TEST_COMMAND="list tracks" |
| 131 | + info "Testing Rally docker image using parameters: ${TEST_COMMAND}" |
| 132 | + docker_compose up |
| 133 | + docker_compose down |
| 134 | + |
| 135 | + # --help should work |
| 136 | + export TEST_COMMAND="--help" |
| 137 | + info "Testing Rally docker image using parameters: ${TEST_COMMAND}" |
| 138 | + docker_compose up |
| 139 | + docker_compose down |
| 140 | + |
| 141 | + # allow overriding CMD too |
| 142 | + export TEST_COMMAND="esrally --pipeline=benchmark-only --test-mode --track=geonames --challenge=append-no-conflicts-index-only --target-hosts=es01:9200" |
| 143 | + info "Testing Rally docker image using parameters: ${TEST_COMMAND}" |
| 144 | + docker_compose up |
| 145 | + docker_compose down |
| 146 | + unset TEST_COMMAND |
| 147 | +} |
| 148 | + |
| 149 | +function main { |
| 150 | + check_prerequisites |
| 151 | + test_docker_release_image |
| 152 | +} |
| 153 | + |
| 154 | + |
| 155 | +function tear_down { |
| 156 | + info "tearing down" |
| 157 | + kill_related_es_processes |
| 158 | +} |
| 159 | + |
| 160 | +trap "tear_down" EXIT |
| 161 | + |
| 162 | +main |
0 commit comments