diff --git a/test/integration/targets/docker_swarm/aliases b/test/integration/targets/docker_swarm/aliases index c23113ee2b4..47a4e975b6a 100644 --- a/test/integration/targets/docker_swarm/aliases +++ b/test/integration/targets/docker_swarm/aliases @@ -8,4 +8,3 @@ skip/docker # The tests sometimes make docker daemon unstable; hence, # after finishing the tests to minimize potential effects # on other tests. needs/root -unstable diff --git a/test/integration/targets/docker_swarm/tasks/cleanup.yml b/test/integration/targets/docker_swarm/tasks/cleanup.yml new file mode 100644 index 00000000000..3e19bfcdb35 --- /dev/null +++ b/test/integration/targets/docker_swarm/tasks/cleanup.yml @@ -0,0 +1,35 @@ +- name: CLEANUP | Leave Docker Swarm + docker_swarm: + state: absent + force: true + ignore_errors: yes + register: leave_swarm + +- name: CLEANUP | Kill Docker and cleanup + when: leave_swarm is failed + block: + - name: CLEANUP | Kill docker daemon + command: systemctl kill -s 9 docker + become: yes + + - name: CLEANUP | Clear out /var/lib/docker + shell: rm -rf /var/lib/docker/* + args: + warn: no + + - name: CLEANUP | Start docker daemon + service: + name: docker + state: started + become: yes + + - name: CLEANUP | Wait for docker daemon to be fully started + command: docker ps + register: result + until: result is success + retries: 10 + + - name: CLEANUP | Leave Docker Swarm + docker_swarm: + state: absent + force: true diff --git a/test/integration/targets/docker_swarm/tasks/main.yml b/test/integration/targets/docker_swarm/tasks/main.yml index 867bbbd1ee5..743d63ab232 100644 --- a/test/integration/targets/docker_swarm/tasks/main.yml +++ b/test/integration/targets/docker_swarm/tasks/main.yml @@ -1,38 +1,18 @@ ---- -# Run the tests -- block: - - include_tasks: run-test.yml - with_fileglob: - - "tests/*.yml" +- name: Run Docker Swarm tests + when: + - docker_py_version is version('1.10.0', '>=') + - docker_api_version is version('1.25', '>=') + + block: + - include_tasks: "{{ item }}" + with_fileglob: + - 'tests/*.yml' always: - - name: Cleanup (trying) - docker_swarm: - state: absent - force: true - diff: no - ignore_errors: yes + - import_tasks: cleanup.yml - - name: Kill docker daemon - command: systemctl kill -s 9 docker - become: yes - - - name: Restart docker daemon - service: - name: docker - state: restarted - become: yes - - - name: Wait for docker daemon to be fully restarted - command: docker ps - - - name: Cleanup - docker_swarm: - state: absent - force: true - diff: no - - when: docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.25', '>=') - -- fail: msg="Too old docker / docker-py version to run docker_swarm tests!" - when: not(docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6) +- fail: + msg: "Too old docker / docker-py version to run docker_swarm tests!" + when: + - not(docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.25', '>=')) + - (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6) diff --git a/test/integration/targets/docker_swarm/tasks/run-test.yml b/test/integration/targets/docker_swarm/tasks/run-test.yml index d9069c90b58..e69de29bb2d 100644 --- a/test/integration/targets/docker_swarm/tasks/run-test.yml +++ b/test/integration/targets/docker_swarm/tasks/run-test.yml @@ -1,8 +0,0 @@ ---- -- name: Make sure we're not already using Docker swarm - docker_swarm: - state: absent - force: true - diff: no -- name: "Loading tasks from {{ item }}" - include_tasks: "{{ item }}" diff --git a/test/integration/targets/docker_swarm/tasks/tests/basic.yml b/test/integration/targets/docker_swarm/tasks/tests/basic.yml index 7104b912a1f..d19532d4681 100644 --- a/test/integration/targets/docker_swarm/tasks/tests/basic.yml +++ b/test/integration/targets/docker_swarm/tasks/tests/basic.yml @@ -1,8 +1,9 @@ ---- +- debug: + msg: Running tests/basic.yml + #################################################################### ## Errors ########################################################## #################################################################### - - name: Test parameters with state=join docker_swarm: state: join @@ -140,16 +141,18 @@ - name: assert changed when remove a swarm cluster assert: that: - - 'output_1 is changed' - - 'output_1.diff.before is defined' - - 'output_1.diff.after is defined' - - 'output_2 is changed' - - 'output_2.actions[0] == "Node has left the swarm cluster"' - - 'output_2.diff.before is defined' - - 'output_2.diff.after is defined' - - 'output_3 is not changed' - - 'output_3.diff.before is defined' - - 'output_3.diff.after is defined' - - 'output_4 is not changed' - - 'output_4.diff.before is defined' - - 'output_4.diff.after is defined' + - 'output_1 is changed' + - 'output_1.diff.before is defined' + - 'output_1.diff.after is defined' + - 'output_2 is changed' + - 'output_2.actions[0] == "Node has left the swarm cluster"' + - 'output_2.diff.before is defined' + - 'output_2.diff.after is defined' + - 'output_3 is not changed' + - 'output_3.diff.before is defined' + - 'output_3.diff.after is defined' + - 'output_4 is not changed' + - 'output_4.diff.before is defined' + - 'output_4.diff.after is defined' + +- include_tasks: cleanup.yml diff --git a/test/integration/targets/docker_swarm/tasks/tests/options-ca.yml b/test/integration/targets/docker_swarm/tasks/tests/options-ca.yml index c1a342fb74b..7091e16000b 100644 --- a/test/integration/targets/docker_swarm/tasks/tests/options-ca.yml +++ b/test/integration/targets/docker_swarm/tasks/tests/options-ca.yml @@ -1,5 +1,10 @@ ---- -- block: +- debug: + msg: Running tests/options-ca.yml + +- name: options-ca + when: pyopenssl_version.stdout is version('0.15', '>=') or + cryptography_version.stdout is version('1.6', '>=') + block: - name: Generate privatekey openssl_privatekey: path: "{{ output_dir }}/ansible_{{ key }}.key" @@ -151,4 +156,4 @@ - "'Minimum version required is 2.6.0 ' in output_1.msg" when: docker_py_version is version('2.6.0', '<') - when: pyopenssl_version.stdout is version('0.15', '>=') or cryptography_version.stdout is version('1.6', '>=') + - include_tasks: cleanup.yml diff --git a/test/integration/targets/docker_swarm/tasks/tests/options.yml b/test/integration/targets/docker_swarm/tasks/tests/options.yml index f80b99bd92b..c23ab3a657e 100644 --- a/test/integration/targets/docker_swarm/tasks/tests/options.yml +++ b/test/integration/targets/docker_swarm/tasks/tests/options.yml @@ -1,4 +1,6 @@ ---- +- debug: + msg: Running tests/options.yml + - name: Create a Swarm cluster docker_swarm: state: present @@ -1152,3 +1154,5 @@ - 'output_6.actions[0] == "Swarm cluster updated"' - 'output_6.diff.before is defined' - 'output_6.diff.after is defined' + +- include_tasks: cleanup.yml diff --git a/test/integration/targets/docker_swarm/tasks/tests/remote-addr-pool.yml b/test/integration/targets/docker_swarm/tasks/tests/remote-addr-pool.yml index 28f40485ce0..a900953e015 100644 --- a/test/integration/targets/docker_swarm/tasks/tests/remote-addr-pool.yml +++ b/test/integration/targets/docker_swarm/tasks/tests/remote-addr-pool.yml @@ -1,11 +1,5 @@ ---- - -- name: Remove Swarm cluster - docker_swarm: - state: absent - force: true - diff: yes - register: output_2 +- debug: + msg: Running tests/remote-addr-pool.yml #################################################################### ## default_addr_pool ############################################### @@ -29,30 +23,34 @@ register: output_2 ignore_errors: yes -- name: cleanup - docker_swarm: - state: absent - force: true - diff: no - - name: assert default_addr_pool assert: that: - 'output_1 is changed' - 'output_2 is not changed' - 'output_2.swarm_facts.DefaultAddrPool == ["2.0.0.0/16"]' - when: docker_api_version is version('1.39', '>=') and docker_py_version is version('4.0.0', '>=') + when: + - docker_api_version is version('1.39', '>=') + - docker_py_version is version('4.0.0', '>=') - name: assert default_addr_pool failed when unsupported assert: that: - 'output_1 is failed' - "'Minimum version required' in output_1.msg" - when: docker_api_version is version('1.39', '<') or docker_py_version is version('4.0.0', '<') + when: docker_api_version is version('1.39', '<') or + docker_py_version is version('4.0.0', '<') #################################################################### ## subnet_size ##################################################### #################################################################### +- name: Leave swarm + docker_swarm: + state: absent + force: yes + default_addr_pool: + - "2.0.0.0/16" + diff: yes - name: subnet_size docker_swarm: @@ -77,17 +75,16 @@ - 'output_1 is changed' - 'output_2 is not changed' - 'output_2.swarm_facts.SubnetSize == 26' - when: docker_api_version is version('1.39', '>=') and docker_py_version is version('4.0.0', '>=') - -- name: cleanup - docker_swarm: - state: absent - force: true - diff: no + when: + - docker_api_version is version('1.39', '>=') + - docker_py_version is version('4.0.0', '>=') - name: assert subnet_size failed when unsupported assert: that: - output_1 is failed - "'Minimum version required' in output_1.msg" - when: docker_api_version is version('1.39', '<') or docker_py_version is version('4.0.0', '<') + when: docker_api_version is version('1.39', '<') or + docker_py_version is version('4.0.0', '<') + +- include_tasks: cleanup.yml