Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Migrate first test_docker_dev_image #1026

Merged
merged 3 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -356,20 +356,6 @@ function tests_for_all_docker_images {
unset TEST_COMMAND
}

function test_docker_dev_image {
# First ensure any left overs have been cleaned up
docker_compose down

export RALLY_VERSION=$(cat version.txt)
export RALLY_LICENSE=$(awk 'FNR>=2 && FNR<=2' LICENSE | sed 's/^[ \t]*//')

# Build the docker image
docker build -t elastic/rally:${RALLY_VERSION} --build-arg RALLY_VERSION --build-arg RALLY_LICENSE -f docker/Dockerfiles/Dockerfile-dev $PWD

tests_for_all_docker_images
}


# This function gets called by release-docker.sh and assumes the image has been already built
function test_docker_release_image {
if [[ -z "${RALLY_VERSION}" ]]; then
Expand Down
23 changes: 22 additions & 1 deletion it/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@

import pytest

from esrally import client
from esrally import client, version
from esrally.utils import process, io

CONFIG_NAMES = ["in-memory-it", "es-it"]
DISTRIBUTIONS = ["2.4.6", "5.6.16", "6.8.0", "7.6.0"]
TRACKS = ["geonames", "nyc_taxis", "http_logs", "nested"]
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))


def all_rally_configs(t):
Expand Down Expand Up @@ -206,10 +207,30 @@ def remove_integration_test_config(config_names=None):
ES_METRICS_STORE = EsMetricsStore()


def get_license():
with open(os.path.join(ROOT_DIR, 'LICENSE')) as license_file:
return license_file.readlines()[1].strip()


def build_docker_image():
rally_version = version.__version__

env_variables = os.environ.copy()
env_variables['RALLY_VERSION'] = rally_version
env_variables['RALLY_LICENSE'] = get_license()

command = f"docker build -t elastic/rally:{rally_version} --build-arg RALLY_VERSION --build-arg RALLY_LICENSE " \
f"-f {ROOT_DIR}/docker/Dockerfiles/Dockerfile-dev {ROOT_DIR}"

if process.run_subprocess_with_logging(command, env=env_variables) != 0:
raise AssertionError("It was not possible to build the docker image from Dockerfile-dev")


def setup_module():
check_prerequisites()
install_integration_test_config()
ES_METRICS_STORE.start()
build_docker_image()


def teardown_module():
Expand Down
67 changes: 67 additions & 0 deletions it/docker_dev_image_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. 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.

import os
import it

from esrally.utils import process
from esrally import version


def test_docker_geonames():
test_command = "--pipeline=benchmark-only --test-mode --track=geonames " \
"--challenge=append-no-conflicts-index-only --target-hosts=es01:9200"
run_docker_compose_test(test_command)


def test_docker_list_tracks():
test_command = "list tracks"
run_docker_compose_test(test_command)


def test_docker_help():
test_command = "--help"
run_docker_compose_test(test_command)


def test_docker_override_cmd():
test_command = "esrally --pipeline=benchmark-only --test-mode --track=geonames " \
"--challenge=append-no-conflicts-index-only --target-hosts=es01:9200"
run_docker_compose_test(test_command)


def run_docker_compose_test(test_command):
try:
if run_docker_compose_up(test_command) != 0:
raise AssertionError(f"The docker-compose test failed with test command: {test_command}")
finally:
# Always ensure proper cleanup regardless of results
run_docker_compose_down()


def run_docker_compose_up(test_command):
env_variables = os.environ.copy()
env_variables["TEST_COMMAND"] = test_command
env_variables['RALLY_VERSION'] = version.__version__

return process.run_subprocess_with_logging(f"docker-compose -f {it.ROOT_DIR}/docker/docker-compose-tests.yml up "
f"--abort-on-container-exit", env=env_variables)


def run_docker_compose_down():
if process.run_subprocess_with_logging(f"docker-compose -f {it.ROOT_DIR}/docker/docker-compose-tests.yml down -v") != 0:
raise AssertionError(f"Failed to stop running containers from docker-compose-tests.yml")