Split up docker-registry test target. (#65211)

* Copy relevant docker-registry files:

docker-registry/files/nginx.conf -> setup_docker_registry/files/nginx.conf
docker-registry/files/nginx.htpasswd -> setup_docker_registry/files/nginx.htpasswd
docker-registry/meta/main.yml -> setup_docker_registry/meta/main.yml
docker-registry/tasks/main.yml -> setup_docker_registry/tasks/main.yml
docker-registry/tasks/main.yml -> setup_docker_registry/handlers/cleanup.yml

* Remove non-cleanup code from handlers/cleanup.yml.

* Remove tests and cleanup from tasks/main.yml.

* Register cleanup handler.

* Use setup_docker_registry in docker-registry test.

* Fix handler execution order.

* Split out docker_login integration test.

* Move remaining tests into docker_image test.

* Cleanup before running docker_image options test.

* Improve reliability of test cleanup.

* Move files for conditional inclusion.

* Set proper conditions on tests.

* Rename tasks file for conditional inclusion.

* Conditionally include tasks.
This commit is contained in:
Matt Clay 2019-12-04 14:14:43 -08:00 committed by GitHub
parent a8efe7442c
commit 567c860027
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 113 additions and 79 deletions

View file

@ -1,3 +0,0 @@
FROM busybox
ENV foo /bar
WORKDIR ${foo}

View file

@ -1,4 +0,0 @@
---
dependencies:
- setup_docker
- setup_openssl

View file

@ -1,3 +1,3 @@
---
dependencies:
- setup_docker
- setup_docker_registry

View file

@ -1,34 +1,3 @@
---
- name: Create random name prefix
set_fact:
name_prefix: "{{ 'ansible-test-%0x' % ((2**32) | random) }}"
- name: Create image and container list
set_fact:
inames: []
cnames: []
- debug:
msg: "Using name prefix {{ name_prefix }}"
- block:
- include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
always:
- name: "Make sure all images are removed"
docker_image:
name: "{{ item }}"
state: absent
with_items: "{{ inames }}"
- name: "Make sure all containers are removed"
docker_container:
name: "{{ item }}"
state: absent
force_kill: yes
with_items: "{{ cnames }}"
when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image tests!"
when: not(docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
include_tasks:
file: test.yml

View file

@ -0,0 +1,34 @@
---
- name: Create random name prefix
set_fact:
name_prefix: "{{ 'ansible-test-%0x' % ((2**32) | random) }}"
- name: Create image and container list
set_fact:
inames: []
cnames: []
- debug:
msg: "Using name prefix {{ name_prefix }}"
- block:
- include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
always:
- name: "Make sure all images are removed"
docker_image:
name: "{{ item }}"
state: absent
with_items: "{{ inames }}"
- name: "Make sure all containers are removed"
docker_container:
name: "{{ item }}"
state: absent
force_kill: yes
with_items: "{{ cnames }}"
when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image tests!"
when: not(docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View file

@ -12,6 +12,12 @@
## build.args ######################################################
####################################################################
- name: cleanup
docker_image:
name: "{{ iname }}"
state: absent
force_absent: yes
- name: buildargs
docker_image:
name: "{{ iname }}"

View file

@ -2,6 +2,3 @@ shippable/posix/group3
skip/osx
skip/freebsd
destructive
docker_image
docker_image_info
docker_login

View file

@ -0,0 +1,3 @@
---
dependencies:
- setup_docker_registry

View file

@ -0,0 +1,3 @@
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
include_tasks:
file: test.yml

View file

@ -0,0 +1,8 @@
- block:
- include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image tests!"
when: not(docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View file

@ -62,6 +62,9 @@
- name: "Remove all ansible-test-* docker containers"
shell: 'docker ps --no-trunc --format {% raw %}"{{.Names}}"{% endraw %} | grep "^ansible-test-" | xargs -r docker rm -f'
register: docker_containers
retries: 3
delay: 3
until: docker_containers is success
- name: "Remove all ansible-test-* docker volumes"
shell: 'docker volume ls --format {% raw %}"{{.Name}}"{% endraw %} | grep "^ansible-test-" | xargs -r docker volume rm -f'

View file

@ -0,0 +1,2 @@
needs/target/setup_docker
needs/target/setup_openssl

View file

@ -0,0 +1,31 @@
- name: "Make sure all images are removed"
docker_image:
name: "{{ item }}"
state: absent
with_items: "{{ inames }}"
- name: "Get registry logs"
command: "docker logs {{ registry_name }}"
register: registry_logs
no_log: yes
- name: "Printing registry logs"
debug: var=registry_logs.stdout_lines
- name: "Get nginx logs"
command: "docker logs {{ nginx_name }}"
register: nginx_logs
no_log: yes
- name: "Printing nginx logs"
debug: var=nginx_logs.stdout_lines
- name: "Make sure all containers are removed"
docker_container:
name: "{{ item }}"
state: absent
force_kill: yes
with_items: "{{ cnames }}"
register: result
retries: 3
delay: 3
until: result is success
- name: "Make sure all volumes are removed"
command: "docker rm -f {{ item }}"
with_items: "{{ vnames }}"
ignore_errors: yes

View file

@ -0,0 +1,2 @@
- name: Remove test registry
include_tasks: ../handlers/cleanup.yml

View file

@ -0,0 +1,3 @@
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
include_tasks:
file: setup.yml

View file

@ -1,4 +1,18 @@
---
- name: Setup OpenSSL
include_role:
name: setup_openssl
- name: Register registry cleanup
command: 'true'
# this must be registered before setup_docker is included
# otherwise setup_docker's own cleanup handler will run before registry cleanup, which will cause registry cleanup to fail
notify: Remove test registry
- name: Setup Docker
include_role:
name: setup_docker
- name: Create random name prefix and test registry name
set_fact:
name_prefix: "{{ 'ansible-test-%0x' % ((2**32) | random) }}"
@ -100,40 +114,6 @@
- debug: msg="Registry available under {{ registry_address }}, NGINX frontend available under {{ registry_frontend_address }}"
- include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
always:
- name: "Make sure all images are removed"
docker_image:
name: "{{ item }}"
state: absent
with_items: "{{ inames }}"
- name: "Get registry logs"
command: "docker logs {{ registry_name }}"
register: registry_logs
no_log: yes
- name: "Printing registry logs"
debug: var=registry_logs.stdout_lines
- name: "Get nginx logs"
command: "docker logs {{ nginx_name }}"
register: nginx_logs
no_log: yes
- name: "Printing nginx logs"
debug: var=nginx_logs.stdout_lines
- name: "Make sure all containers are removed"
docker_container:
name: "{{ item }}"
state: absent
force_kill: yes
with_items: "{{ cnames }}"
- name: "Make sure all volumes are removed"
docker_volume:
name: "{{ item }}"
state: absent
with_items: "{{ vnames }}"
when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image tests!"