diff --git a/test/integration/targets/docker-registry/files/Dockerfile b/test/integration/targets/docker-registry/files/Dockerfile deleted file mode 100644 index c2951375fa..0000000000 --- a/test/integration/targets/docker-registry/files/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM busybox -ENV foo /bar -WORKDIR ${foo} diff --git a/test/integration/targets/docker-registry/meta/main.yml b/test/integration/targets/docker-registry/meta/main.yml deleted file mode 100644 index 078660a8ab..0000000000 --- a/test/integration/targets/docker-registry/meta/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -dependencies: - - setup_docker - - setup_openssl diff --git a/test/integration/targets/docker_image/meta/main.yml b/test/integration/targets/docker_image/meta/main.yml index 07da8c6dda..21d7a58f93 100644 --- a/test/integration/targets/docker_image/meta/main.yml +++ b/test/integration/targets/docker_image/meta/main.yml @@ -1,3 +1,3 @@ --- dependencies: - - setup_docker + - setup_docker_registry diff --git a/test/integration/targets/docker_image/tasks/main.yml b/test/integration/targets/docker_image/tasks/main.yml index 47c629860b..3b4f9357a6 100644 --- a/test/integration/targets/docker_image/tasks/main.yml +++ b/test/integration/targets/docker_image/tasks/main.yml @@ -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 diff --git a/test/integration/targets/docker_image/tasks/test.yml b/test/integration/targets/docker_image/tasks/test.yml new file mode 100644 index 0000000000..47c629860b --- /dev/null +++ b/test/integration/targets/docker_image/tasks/test.yml @@ -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) diff --git a/test/integration/targets/docker-registry/tasks/tests/docker_image.yml b/test/integration/targets/docker_image/tasks/tests/docker_image.yml similarity index 100% rename from test/integration/targets/docker-registry/tasks/tests/docker_image.yml rename to test/integration/targets/docker_image/tasks/tests/docker_image.yml diff --git a/test/integration/targets/docker_image/tasks/tests/options.yml b/test/integration/targets/docker_image/tasks/tests/options.yml index 1ff729c6fa..42c23e0c1a 100644 --- a/test/integration/targets/docker_image/tasks/tests/options.yml +++ b/test/integration/targets/docker_image/tasks/tests/options.yml @@ -12,6 +12,12 @@ ## build.args ###################################################### #################################################################### +- name: cleanup + docker_image: + name: "{{ iname }}" + state: absent + force_absent: yes + - name: buildargs docker_image: name: "{{ iname }}" diff --git a/test/integration/targets/docker-registry/aliases b/test/integration/targets/docker_login/aliases similarity index 56% rename from test/integration/targets/docker-registry/aliases rename to test/integration/targets/docker_login/aliases index 1817f0dae4..1e2b2ce41b 100644 --- a/test/integration/targets/docker-registry/aliases +++ b/test/integration/targets/docker_login/aliases @@ -2,6 +2,3 @@ shippable/posix/group3 skip/osx skip/freebsd destructive -docker_image -docker_image_info -docker_login diff --git a/test/integration/targets/docker_login/meta/main.yml b/test/integration/targets/docker_login/meta/main.yml new file mode 100644 index 0000000000..21d7a58f93 --- /dev/null +++ b/test/integration/targets/docker_login/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_docker_registry diff --git a/test/integration/targets/docker_login/tasks/main.yml b/test/integration/targets/docker_login/tasks/main.yml new file mode 100644 index 0000000000..3b4f9357a6 --- /dev/null +++ b/test/integration/targets/docker_login/tasks/main.yml @@ -0,0 +1,3 @@ +- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6'] + include_tasks: + file: test.yml diff --git a/test/integration/targets/docker-registry/tasks/run-test.yml b/test/integration/targets/docker_login/tasks/run-test.yml similarity index 100% rename from test/integration/targets/docker-registry/tasks/run-test.yml rename to test/integration/targets/docker_login/tasks/run-test.yml diff --git a/test/integration/targets/docker_login/tasks/test.yml b/test/integration/targets/docker_login/tasks/test.yml new file mode 100644 index 0000000000..e1b584a392 --- /dev/null +++ b/test/integration/targets/docker_login/tasks/test.yml @@ -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) diff --git a/test/integration/targets/docker-registry/tasks/tests/docker_login.yml b/test/integration/targets/docker_login/tasks/tests/docker_login.yml similarity index 100% rename from test/integration/targets/docker-registry/tasks/tests/docker_login.yml rename to test/integration/targets/docker_login/tasks/tests/docker_login.yml diff --git a/test/integration/targets/setup_docker/tasks/main.yml b/test/integration/targets/setup_docker/tasks/main.yml index ca8ed38f41..359a6d4493 100644 --- a/test/integration/targets/setup_docker/tasks/main.yml +++ b/test/integration/targets/setup_docker/tasks/main.yml @@ -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' diff --git a/test/integration/targets/setup_docker_registry/aliases b/test/integration/targets/setup_docker_registry/aliases new file mode 100644 index 0000000000..688c8884b2 --- /dev/null +++ b/test/integration/targets/setup_docker_registry/aliases @@ -0,0 +1,2 @@ +needs/target/setup_docker +needs/target/setup_openssl diff --git a/test/integration/targets/docker-registry/files/nginx.conf b/test/integration/targets/setup_docker_registry/files/nginx.conf similarity index 100% rename from test/integration/targets/docker-registry/files/nginx.conf rename to test/integration/targets/setup_docker_registry/files/nginx.conf diff --git a/test/integration/targets/docker-registry/files/nginx.htpasswd b/test/integration/targets/setup_docker_registry/files/nginx.htpasswd similarity index 100% rename from test/integration/targets/docker-registry/files/nginx.htpasswd rename to test/integration/targets/setup_docker_registry/files/nginx.htpasswd diff --git a/test/integration/targets/setup_docker_registry/handlers/cleanup.yml b/test/integration/targets/setup_docker_registry/handlers/cleanup.yml new file mode 100644 index 0000000000..b789174700 --- /dev/null +++ b/test/integration/targets/setup_docker_registry/handlers/cleanup.yml @@ -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 diff --git a/test/integration/targets/setup_docker_registry/handlers/main.yml b/test/integration/targets/setup_docker_registry/handlers/main.yml new file mode 100644 index 0000000000..b2b858a624 --- /dev/null +++ b/test/integration/targets/setup_docker_registry/handlers/main.yml @@ -0,0 +1,2 @@ +- name: Remove test registry + include_tasks: ../handlers/cleanup.yml diff --git a/test/integration/targets/setup_docker_registry/tasks/main.yml b/test/integration/targets/setup_docker_registry/tasks/main.yml new file mode 100644 index 0000000000..fd935f0ee5 --- /dev/null +++ b/test/integration/targets/setup_docker_registry/tasks/main.yml @@ -0,0 +1,3 @@ +- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6'] + include_tasks: + file: setup.yml diff --git a/test/integration/targets/docker-registry/tasks/main.yml b/test/integration/targets/setup_docker_registry/tasks/setup.yml similarity index 79% rename from test/integration/targets/docker-registry/tasks/main.yml rename to test/integration/targets/setup_docker_registry/tasks/setup.yml index 790c1bbd67..416a0303c4 100644 --- a/test/integration/targets/docker-registry/tasks/main.yml +++ b/test/integration/targets/setup_docker_registry/tasks/setup.yml @@ -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!"