From 7a4cae050cc3576c437e087e8083912507344012 Mon Sep 17 00:00:00 2001 From: Thomas LEVEIL Date: Wed, 25 Jan 2017 01:11:36 +0100 Subject: [PATCH] TESTS: abort test suite if the 'jwilder/nginx-proxy:test' image is missing --- test2/conftest.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test2/conftest.py b/test2/conftest.py index dd49261..40d6295 100644 --- a/test2/conftest.py +++ b/test2/conftest.py @@ -130,8 +130,11 @@ def get_nginx_conf_from_container(container_id): def docker_compose_up(compose_file='docker-compose.yml'): - subprocess.check_output(shlex.split('docker-compose -f %s up -d' % compose_file)) - + try: + subprocess.check_output(shlex.split('docker-compose -f %s up -d' % compose_file)) + except subprocess.CalledProcessError, e: + logging.error("Error while runninng 'docker-compose -f %s up -d':\n%s" % (compose_file, e.output)) + raise def wait_for_nginxproxy_to_be_ready(): """ @@ -148,7 +151,6 @@ def wait_for_nginxproxy_to_be_ready(): logging.debug("nginx-proxy ready") break - def find_docker_compose_file(request): """ helper for fixture functions to figure out the name of the docker-compose file to consider. @@ -182,6 +184,13 @@ def find_docker_compose_file(request): return docker_compose_file +def check_sut_image(): + """ + Return True if jwilder/nginx-proxy:test image exists + """ + docker_client = docker.from_env() + return any(map(lambda x: "jwilder/nginx-proxy:test" in x.get('RepoTags'), docker_client.images())) + ############################################################################### # # Py.test fixtures @@ -197,6 +206,8 @@ def docker_compose(request): """ docker_compose_file = find_docker_compose_file(request) original_dns_resolver = monkey_patch_urllib_dns_resolver() + if not check_sut_image(): + pytest.exit("The docker image 'jwilder/nginx-proxy:test' is missing") remove_all_containers() docker_compose_up(docker_compose_file) wait_for_nginxproxy_to_be_ready()