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.

(cherry picked from commit 3bb41ccb8e)
pull/48898/head
Felix Fontein 7 years ago committed by Toshio Kuratomi
parent 1469ec4487
commit a96efa43f0

@ -31,3 +31,6 @@
when: docker_py_version is version('1.10.0', '>=') when: docker_py_version is version('1.10.0', '>=')
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)

@ -47,5 +47,7 @@
stop_timeout: 1 stop_timeout: 1
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)

@ -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,97 +1,105 @@
- 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:
state: present state: present
ignore_errors: yes ignore_errors: yes
register: output register: output
- name: assert failure when called with no name - name: assert failure when called with no name
assert: assert:
that: that:
- 'output.failed' - 'output.failed'
- 'output.msg == "missing required arguments: name"' - 'output.msg == "missing required arguments: name"'
- name: Test parameters - name: Test parameters
docker_secret: docker_secret:
name: foo name: foo
state: present state: present
ignore_errors: yes ignore_errors: yes
register: output register: output
- name: assert failure when called with no data - name: assert failure when called with no data
assert: assert:
that: that:
- 'output.failed' - 'output.failed'
- 'output.msg == "state is present but all of the following are missing: data"' - 'output.msg == "state is present but all of the following are missing: data"'
- name: Create secret - name: Create secret
docker_secret: docker_secret:
name: db_password name: db_password
data: opensesame! data: opensesame!
state: present state: present
register: output register: output
- name: Create variable secret_id - name: Create variable secret_id
set_fact: set_fact:
secret_id: "{{ output.secret_id }}" secret_id: "{{ output.secret_id }}"
- name: Inspect secret - name: Inspect secret
command: "docker secret inspect {{ secret_id }}" command: "docker secret inspect {{ secret_id }}"
register: inspect register: inspect
- debug: var=inspect - debug: var=inspect
- name: assert secret creation succeeded - name: assert secret creation succeeded
assert: assert:
that: that:
- "'db_password' in inspect.stdout" - "'db_password' in inspect.stdout"
- "'ansible_key' in inspect.stdout" - "'ansible_key' in inspect.stdout"
- name: Create secret again - name: Create secret again
docker_secret: docker_secret:
name: db_password name: db_password
data: opensesame! data: opensesame!
state: present state: present
register: output register: output
- name: assert create secret is idempotent - name: assert create secret is idempotent
assert: assert:
that: that:
- not output.changed - not output.changed
- name: Update secret - name: Update secret
docker_secret: docker_secret:
name: db_password name: db_password
data: newpassword! data: newpassword!
state: present state: present
register: output register: output
- name: assert secret was updated - name: assert secret was updated
assert: assert:
that: that:
- output.changed - output.changed
- output.secret_id != secret_id - output.secret_id != secret_id
- name: Remove secret - name: Remove secret
docker_secret: docker_secret:
name: db_password name: db_password
state: absent state: absent
- name: Check that secret is removed - name: Check that secret is removed
command: "docker secret inspect {{ secret_id }}" command: "docker secret inspect {{ secret_id }}"
register: output register: output
ignore_errors: yes ignore_errors: yes
- name: assert secret was removed - name: assert secret was removed
assert: assert:
that: that:
- output.failed - output.failed
always:
- name: Remove Swarm cluster
docker_swarm:
state: absent
force: true

@ -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,38 +1,40 @@
- name: Make sure we're not already using Docker swarm ---
- block:
- name: Make sure we're not already using Docker swarm
docker_swarm: docker_swarm:
state: absent state: absent
force: true force: true
- name: Test parameters with state=join - name: Test parameters with state=join
docker_swarm: docker_swarm:
state: join state: join
ignore_errors: yes ignore_errors: yes
register: output register: output
- name: assert failure when called with state=join and no advertise_addr,remote_addrs,join_token - name: assert failure when called with state=join and no advertise_addr,remote_addrs,join_token
assert: assert:
that: that:
- 'output.failed' - 'output.failed'
- 'output.msg == "state is join but all of the following are missing: advertise_addr, remote_addrs, join_token"' - 'output.msg == "state is join but all of the following are missing: advertise_addr, remote_addrs, join_token"'
- name: Test parameters with state=remove - name: Test parameters with state=remove
docker_swarm: docker_swarm:
state: remove state: remove
ignore_errors: yes ignore_errors: yes
register: output register: output
- name: assert failure when called with state=remove and no node_id - name: assert failure when called with state=remove and no node_id
assert: assert:
that: that:
- 'output.failed' - 'output.failed'
- 'output.msg == "state is remove but all of the following are missing: node_id"' - 'output.msg == "state is remove but all of the following are missing: node_id"'
- name: Create a Swarm cluster - name: Create a Swarm cluster
docker_swarm: docker_swarm:
state: present state: present
register: output register: output
- name: assert changed when create a new swarm cluster - name: assert changed when create a new swarm cluster
assert: assert:
that: that:
- 'output.changed' - 'output.changed'
@ -40,14 +42,20 @@
- 'output.swarm_facts.JoinTokens.Manager' - 'output.swarm_facts.JoinTokens.Manager'
- 'output.swarm_facts.JoinTokens.Worker' - 'output.swarm_facts.JoinTokens.Worker'
- name: Remove a Swarm cluster - name: Remove a Swarm cluster
docker_swarm: docker_swarm:
state: absent state: absent
force: true force: true
register: output register: output
- name: assert changed when remove a swarm cluster - name: assert changed when remove a swarm cluster
assert: assert:
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

@ -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…
Cancel
Save