mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 22:51:23 -07:00
docker_* tests: check API version (#48620)
* Check minimal API and docker-py versions for all docker_* tests. * Improve docker_swarm creation/destruction for tests. * Fail when conditions aren't met. * Don't hardcode address for advertise_addr.
This commit is contained in:
parent
891687284f
commit
3bb41ccb8e
20 changed files with 537 additions and 481 deletions
|
@ -220,7 +220,7 @@ def main():
|
||||||
|
|
||||||
# Version checks
|
# Version checks
|
||||||
cache_min_version = '3.3.0'
|
cache_min_version = '3.3.0'
|
||||||
if client.module.params['builder_cache'] and LooseVersion(docker_version) < LooseVersion(cache_min_version):
|
if client.module.params['builder_cache'] and client.docker_py_version < LooseVersion(cache_min_version):
|
||||||
msg = "Error: docker version is %s. Minimum version required for builds option is %s. Use `pip install --upgrade docker` to upgrade."
|
msg = "Error: docker version is %s. Minimum version required for builds option is %s. Use `pip install --upgrade docker` to upgrade."
|
||||||
client.module.fail(msg=(msg % (docker_version, cache_min_version)))
|
client.module.fail(msg=(msg % (docker_version, cache_min_version)))
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
---
|
---
|
||||||
- include_tasks: test_docker_config.yml
|
- include_tasks: test_docker_config.yml
|
||||||
when: docker_api_version is version('1.30', '>=')
|
# Maximum of 1.30 (docker API version for docker_config) and 1.35 (docker API version for docker_swarm) is 1.35
|
||||||
|
when: docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.35', '>=')
|
||||||
|
|
||||||
|
- fail: msg="Too old docker / docker-py version to run docker_config tests!"
|
||||||
|
when: not(docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.35', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
---
|
---
|
||||||
|
- block:
|
||||||
- name: Make sure we're not already using Docker swarm
|
- name: Make sure we're not already using Docker swarm
|
||||||
docker_swarm:
|
docker_swarm:
|
||||||
state: absent
|
state: absent
|
||||||
|
@ -108,6 +109,7 @@
|
||||||
that:
|
that:
|
||||||
- not output.changed
|
- not output.changed
|
||||||
|
|
||||||
|
always:
|
||||||
- name: Remove a Swarm cluster
|
- name: Remove a Swarm cluster
|
||||||
docker_swarm:
|
docker_swarm:
|
||||||
state: absent
|
state: absent
|
||||||
|
|
|
@ -33,3 +33,6 @@
|
||||||
diff: no
|
diff: no
|
||||||
|
|
||||||
when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
|
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 all docker_container tests!"
|
||||||
|
when: not(docker_py_version is version('3.5.0', '>=') and docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
|
||||||
|
|
|
@ -58,5 +58,7 @@
|
||||||
- "result.docker_container"
|
- "result.docker_container"
|
||||||
- "result.docker_container == docker_inspect_result[0]"
|
- "result.docker_container == docker_inspect_result[0]"
|
||||||
|
|
||||||
# Skip for CentOS 6
|
when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
|
||||||
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|
|
||||||
|
- fail: msg="Too old docker / docker-py version to run docker_container_facts 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)
|
||||||
|
|
|
@ -47,5 +47,7 @@
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
with_items: "{{ cnames }}"
|
with_items: "{{ cnames }}"
|
||||||
|
|
||||||
# Skip for CentOS 6
|
when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
|
||||||
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|
|
||||||
|
- 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)
|
||||||
|
|
|
@ -48,5 +48,7 @@
|
||||||
- "'hello-world:latest' in result.images[0].RepoTags"
|
- "'hello-world:latest' in result.images[0].RepoTags"
|
||||||
- "'alpine:3.8' in result.images[1].RepoTags"
|
- "'alpine:3.8' in result.images[1].RepoTags"
|
||||||
|
|
||||||
# Skip for CentOS 6
|
when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
|
||||||
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|
|
||||||
|
- fail: msg="Too old docker / docker-py version to run docker_image_facts 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)
|
||||||
|
|
|
@ -27,5 +27,7 @@
|
||||||
force: yes
|
force: yes
|
||||||
loop: "{{ dnetworks }}"
|
loop: "{{ dnetworks }}"
|
||||||
|
|
||||||
# Skip for CentOS 6
|
when: docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.20', '>=') # FIXME: find out API version!
|
||||||
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|
|
||||||
|
- fail: msg="Too old docker / docker-py version to run docker_network tests!"
|
||||||
|
when: not(docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.20', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
|
||||||
|
|
|
@ -10,11 +10,12 @@
|
||||||
## overlay #########################################################
|
## overlay #########################################################
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
||||||
|
- block:
|
||||||
# Overlay networks require swarm initialization before they'll work
|
# Overlay networks require swarm initialization before they'll work
|
||||||
- name: swarm
|
- name: swarm
|
||||||
docker_swarm:
|
docker_swarm:
|
||||||
state: present
|
state: present
|
||||||
advertise_addr: 192.168.1.1
|
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||||
|
|
||||||
- name: overlay
|
- name: overlay
|
||||||
docker_network:
|
docker_network:
|
||||||
|
@ -44,13 +45,17 @@
|
||||||
state: absent
|
state: absent
|
||||||
force: yes
|
force: yes
|
||||||
|
|
||||||
- name: cleanup swarm
|
|
||||||
docker_swarm:
|
|
||||||
state: absent
|
|
||||||
force: yes
|
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- overlay_1 is changed
|
- overlay_1 is changed
|
||||||
- overlay_2 is not changed
|
- overlay_2 is not changed
|
||||||
- overlay_3 is changed
|
- overlay_3 is changed
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: cleanup swarm
|
||||||
|
docker_swarm:
|
||||||
|
state: absent
|
||||||
|
force: yes
|
||||||
|
|
||||||
|
# Requirements for docker_swarm
|
||||||
|
when: docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.35', '>=')
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
images: yes
|
images: yes
|
||||||
networks: yes
|
networks: yes
|
||||||
volumes: yes
|
volumes: yes
|
||||||
builder_cache: yes
|
builder_cache: "{{ docker_py_version is version('3.3.0', '>=') }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
# Analyze result
|
# Analyze result
|
||||||
|
@ -56,5 +56,7 @@
|
||||||
|
|
||||||
- debug: var=result
|
- debug: var=result
|
||||||
|
|
||||||
# Skip for CentOS 6
|
when: docker_py_version is version('2.1.0', '>=') and docker_api_version is version('1.25', '>=')
|
||||||
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|
|
||||||
|
- fail: msg="Too old docker / docker-py version to run docker_prune tests!"
|
||||||
|
when: not(docker_py_version is version('2.1.0', '>=') and docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
- name: disable_swarm
|
|
||||||
command: docker swarm leave --force
|
|
||||||
ignore_errors: yes
|
|
|
@ -1,2 +1,7 @@
|
||||||
- include_tasks: test_secrets.yml
|
- include_tasks: test_secrets.yml
|
||||||
when: ansible_os_family != 'RedHat' or ansible_distribution_major_version != '6'
|
# Maximum of 2.1.0 (docker-py version for docker_secrets) and 2.6.0 (docker-py version for docker_swarm) is 2.6.0
|
||||||
|
# Maximum of 1.25 (docker API version for docker_secrets) and 1.35 (docker API version for docker_swarm) is 1.35
|
||||||
|
when: docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.35', '>=')
|
||||||
|
|
||||||
|
- fail: msg="Too old docker / docker-py version to run docker_secrets tests!"
|
||||||
|
when: not(docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.35', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
- name: Check if already in swarm
|
---
|
||||||
shell: docker node ls 2>&1 | grep 'docker swarm init'
|
- block:
|
||||||
register: output
|
- name: Make sure we're not already using Docker swarm
|
||||||
ignore_errors: yes
|
docker_swarm:
|
||||||
|
state: absent
|
||||||
|
force: true
|
||||||
|
|
||||||
- name: Enable swarm mode
|
- name: Create a Swarm cluster
|
||||||
command: docker swarm init
|
docker_swarm:
|
||||||
when: output.rc == 0
|
state: present
|
||||||
notify: disable_swarm
|
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||||
|
|
||||||
- name: Parameter name should be required
|
- name: Parameter name should be required
|
||||||
docker_secret:
|
docker_secret:
|
||||||
|
@ -95,3 +97,9 @@
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- output.failed
|
- output.failed
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: Remove Swarm cluster
|
||||||
|
docker_swarm:
|
||||||
|
state: absent
|
||||||
|
force: true
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
- include_tasks: test_stack.yml
|
- include_tasks: test_stack.yml
|
||||||
when:
|
when: docker_api_version is version('1.25', '>=')
|
||||||
- ansible_os_family != 'RedHat' or ansible_distribution_major_version != '6'
|
|
||||||
- ansible_distribution != 'Fedora' or ansible_distribution_major_version|int >= 26
|
- fail: msg="Too old docker / docker-py version to run docker_stack tests!"
|
||||||
|
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
---
|
||||||
|
- block:
|
||||||
- name: Make sure we're not already using Docker swarm
|
- name: Make sure we're not already using Docker swarm
|
||||||
docker_swarm:
|
docker_swarm:
|
||||||
state: absent
|
state: absent
|
||||||
|
@ -104,6 +106,7 @@
|
||||||
that:
|
that:
|
||||||
- output is not changed
|
- output is not changed
|
||||||
|
|
||||||
|
always:
|
||||||
- name: Remove a Swarm cluster
|
- name: Remove a Swarm cluster
|
||||||
docker_swarm:
|
docker_swarm:
|
||||||
state: absent
|
state: absent
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
- include_tasks: test_swarm.yml
|
- include_tasks: test_swarm.yml
|
||||||
when: ansible_os_family != 'RedHat' or ansible_distribution_major_version != '6'
|
when: docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.35', '>=')
|
||||||
|
|
||||||
|
- fail: msg="Too old docker / docker-py version to run docker_swarm tests!"
|
||||||
|
when: not(docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.35', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
---
|
||||||
|
- block:
|
||||||
- name: Make sure we're not already using Docker swarm
|
- name: Make sure we're not already using Docker swarm
|
||||||
docker_swarm:
|
docker_swarm:
|
||||||
state: absent
|
state: absent
|
||||||
|
@ -51,3 +53,9 @@
|
||||||
that:
|
that:
|
||||||
- 'output.changed'
|
- 'output.changed'
|
||||||
- 'output.actions[0] == "Node has leaved the swarm cluster"'
|
- 'output.actions[0] == "Node has leaved the swarm cluster"'
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: Cleanup
|
||||||
|
docker_swarm:
|
||||||
|
state: absent
|
||||||
|
force: true
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
- include_tasks: test_swarm_service.yml
|
- include_tasks: test_swarm_service.yml
|
||||||
when:
|
# Maximum of 2.0.0 (docker-py version for docker_swarm_service) and 2.6.0 (docker-py version for docker_swarm) is 2.6.0
|
||||||
- ansible_os_family != 'RedHat' or ansible_distribution_major_version != '6'
|
when: docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.35', '>=')
|
||||||
- ansible_distribution != 'Fedora' or ansible_distribution_major_version|int >= 26
|
|
||||||
|
- fail: msg="Too old docker / docker-py version to run docker_swarm_service tests!"
|
||||||
|
when: not(docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.35', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
---
|
||||||
|
- block:
|
||||||
- name: Create a Swarm cluster
|
- name: Create a Swarm cluster
|
||||||
docker_swarm:
|
docker_swarm:
|
||||||
state: present
|
state: present
|
||||||
|
@ -116,6 +118,7 @@
|
||||||
state: present
|
state: present
|
||||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||||
|
|
||||||
|
always:
|
||||||
- name: Clean the docker daemon status
|
- name: Clean the docker daemon status
|
||||||
docker_swarm:
|
docker_swarm:
|
||||||
state: absent
|
state: absent
|
||||||
|
|
|
@ -20,5 +20,7 @@
|
||||||
force: yes
|
force: yes
|
||||||
with_items: "{{ vnames }}"
|
with_items: "{{ vnames }}"
|
||||||
|
|
||||||
# Skip for CentOS 6
|
when: docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.20', '>=') # FIXME: find out API version!
|
||||||
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|
|
||||||
|
- fail: msg="Too old docker / docker-py version to run docker_volume tests!"
|
||||||
|
when: not(docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.20', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue