Make docker swarm integration tests more reliable (#59473)

This commit is contained in:
Sam Doran 2019-07-25 12:49:30 -04:00 committed by GitHub
parent 723da33176
commit 3ceeae0de9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 102 additions and 87 deletions

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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 }}"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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