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
- name: Enable swarm mode force: true
command: docker swarm init
when: output.rc == 0 - name: Create a Swarm cluster
notify: disable_swarm docker_swarm:
state: present
- name: Parameter name should be required advertise_addr: "{{ansible_default_ipv4.address}}"
docker_secret:
state: present - name: Parameter name should be required
ignore_errors: yes docker_secret:
register: output state: present
ignore_errors: yes
- name: assert failure when called with no name register: output
assert:
that: - name: assert failure when called with no name
- 'output.failed' assert:
- 'output.msg == "missing required arguments: name"' that:
- 'output.failed'
- name: Test parameters - 'output.msg == "missing required arguments: name"'
docker_secret:
name: foo - name: Test parameters
state: present docker_secret:
ignore_errors: yes name: foo
register: output state: present
ignore_errors: yes
- name: assert failure when called with no data register: output
assert:
that: - name: assert failure when called with no data
- 'output.failed' assert:
- 'output.msg == "state is present but all of the following are missing: data"' that:
- 'output.failed'
- name: Create secret - 'output.msg == "state is present but all of the following are missing: data"'
docker_secret:
name: db_password - name: Create secret
data: opensesame! docker_secret:
state: present name: db_password
register: output data: opensesame!
state: present
- name: Create variable secret_id register: output
set_fact:
secret_id: "{{ output.secret_id }}" - name: Create variable secret_id
set_fact:
- name: Inspect secret secret_id: "{{ output.secret_id }}"
command: "docker secret inspect {{ secret_id }}"
register: inspect - name: Inspect secret
command: "docker secret inspect {{ secret_id }}"
- debug: var=inspect register: inspect
- name: assert secret creation succeeded - debug: var=inspect
assert:
that: - name: assert secret creation succeeded
- "'db_password' in inspect.stdout" assert:
- "'ansible_key' in inspect.stdout" that:
- "'db_password' in inspect.stdout"
- name: Create secret again - "'ansible_key' in inspect.stdout"
docker_secret:
name: db_password - name: Create secret again
data: opensesame! docker_secret:
state: present name: db_password
register: output data: opensesame!
state: present
- name: assert create secret is idempotent register: output
assert:
that: - name: assert create secret is idempotent
- not output.changed assert:
that:
- name: Update secret - not output.changed
docker_secret:
name: db_password - name: Update secret
data: newpassword! docker_secret:
state: present name: db_password
register: output data: newpassword!
state: present
- name: assert secret was updated register: output
assert:
that: - name: assert secret was updated
- output.changed assert:
- output.secret_id != secret_id that:
- output.changed
- name: Remove secret - output.secret_id != secret_id
docker_secret:
name: db_password - name: Remove secret
state: absent docker_secret:
name: db_password
- name: Check that secret is removed state: absent
command: "docker secret inspect {{ secret_id }}"
register: output - name: Check that secret is removed
ignore_errors: yes command: "docker secret inspect {{ secret_id }}"
register: output
- name: assert secret was removed ignore_errors: yes
assert:
that: - name: assert secret was removed
- output.failed assert:
that:
- 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,53 +1,61 @@
- name: Make sure we're not already using Docker swarm ---
docker_swarm: - block:
state: absent - name: Make sure we're not already using Docker swarm
force: true docker_swarm:
state: absent
- name: Test parameters with state=join force: true
docker_swarm:
state: join - name: Test parameters with state=join
ignore_errors: yes docker_swarm:
register: output state: join
ignore_errors: yes
- name: assert failure when called with state=join and no advertise_addr,remote_addrs,join_token register: output
assert:
that: - name: assert failure when called with state=join and no advertise_addr,remote_addrs,join_token
- 'output.failed' assert:
- 'output.msg == "state is join but all of the following are missing: advertise_addr, remote_addrs, join_token"' that:
- 'output.failed'
- name: Test parameters with state=remove - 'output.msg == "state is join but all of the following are missing: advertise_addr, remote_addrs, join_token"'
docker_swarm:
state: remove - name: Test parameters with state=remove
ignore_errors: yes docker_swarm:
register: output state: remove
ignore_errors: yes
- name: assert failure when called with state=remove and no node_id register: output
assert:
that: - name: assert failure when called with state=remove and no node_id
- 'output.failed' assert:
- 'output.msg == "state is remove but all of the following are missing: node_id"' that:
- 'output.failed'
- name: Create a Swarm cluster - 'output.msg == "state is remove but all of the following are missing: node_id"'
docker_swarm:
state: present - name: Create a Swarm cluster
register: output docker_swarm:
state: present
- name: assert changed when create a new swarm cluster register: output
assert:
that: - name: assert changed when create a new swarm cluster
- 'output.changed' assert:
- 'output.actions[0] | regex_search("New Swarm cluster created: ")' that:
- 'output.swarm_facts.JoinTokens.Manager' - 'output.changed'
- 'output.swarm_facts.JoinTokens.Worker' - 'output.actions[0] | regex_search("New Swarm cluster created: ")'
- 'output.swarm_facts.JoinTokens.Manager'
- name: Remove a Swarm cluster - 'output.swarm_facts.JoinTokens.Worker'
docker_swarm:
state: absent - name: Remove a Swarm cluster
force: true docker_swarm:
register: output state: absent
force: true
- name: assert changed when remove a swarm cluster register: output
assert:
that: - name: assert changed when remove a swarm cluster
- 'output.changed' assert:
- 'output.actions[0] == "Node has leaved the swarm cluster"' that:
- 'output.changed'
- '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