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
|
||||
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."
|
||||
client.module.fail(msg=(msg % (docker_version, cache_min_version)))
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
---
|
||||
- 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,114 +1,116 @@
|
|||
---
|
||||
- name: Make sure we're not already using Docker swarm
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
- block:
|
||||
- name: Make sure we're not already using Docker swarm
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
|
||||
- name: Create a Swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
- name: Create a Swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
|
||||
- name: Parameter name should be required
|
||||
docker_config:
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
- name: Parameter name should be required
|
||||
docker_config:
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: assert failure when called with no name
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "missing required arguments: name"'
|
||||
- name: assert failure when called with no name
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "missing required arguments: name"'
|
||||
|
||||
- name: Test parameters
|
||||
docker_config:
|
||||
name: foo
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
- name: Test parameters
|
||||
docker_config:
|
||||
name: foo
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: assert failure when called with no data
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "state is present but all of the following are missing: data"'
|
||||
- name: assert failure when called with no data
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "state is present but all of the following are missing: data"'
|
||||
|
||||
- name: Create config
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
state: present
|
||||
register: output
|
||||
- name: Create config
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: Create variable config_id
|
||||
set_fact:
|
||||
config_id: "{{ output.config_id }}"
|
||||
- name: Create variable config_id
|
||||
set_fact:
|
||||
config_id: "{{ output.config_id }}"
|
||||
|
||||
- name: Inspect config
|
||||
command: "docker config inspect {{ config_id }}"
|
||||
register: inspect
|
||||
- name: Inspect config
|
||||
command: "docker config inspect {{ config_id }}"
|
||||
register: inspect
|
||||
|
||||
- debug: var=inspect
|
||||
- debug: var=inspect
|
||||
|
||||
- name: assert config creation succeeded
|
||||
assert:
|
||||
that:
|
||||
- "'db_password' in inspect.stdout"
|
||||
- "'ansible_key' in inspect.stdout"
|
||||
- name: assert config creation succeeded
|
||||
assert:
|
||||
that:
|
||||
- "'db_password' in inspect.stdout"
|
||||
- "'ansible_key' in inspect.stdout"
|
||||
|
||||
- name: Create config again
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
state: present
|
||||
register: output
|
||||
- name: Create config again
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: assert create config is idempotent
|
||||
assert:
|
||||
that:
|
||||
- not output.changed
|
||||
- name: assert create config is idempotent
|
||||
assert:
|
||||
that:
|
||||
- not output.changed
|
||||
|
||||
- name: Update config
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: newpassword!
|
||||
state: present
|
||||
register: output
|
||||
- name: Update config
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: newpassword!
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: assert config was updated
|
||||
assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.config_id != config_id
|
||||
- name: assert config was updated
|
||||
assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.config_id != config_id
|
||||
|
||||
- name: Remove config
|
||||
docker_config:
|
||||
name: db_password
|
||||
state: absent
|
||||
- name: Remove config
|
||||
docker_config:
|
||||
name: db_password
|
||||
state: absent
|
||||
|
||||
- name: Check that config is removed
|
||||
command: "docker config inspect {{ config_id }}"
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
- name: Check that config is removed
|
||||
command: "docker config inspect {{ config_id }}"
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
|
||||
- name: assert config was removed
|
||||
assert:
|
||||
that:
|
||||
- output.failed
|
||||
- name: assert config was removed
|
||||
assert:
|
||||
that:
|
||||
- output.failed
|
||||
|
||||
- name: Remove config
|
||||
docker_config:
|
||||
name: db_password
|
||||
state: absent
|
||||
register: output
|
||||
- name: Remove config
|
||||
docker_config:
|
||||
name: db_password
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- name: assert remove config is idempotent
|
||||
assert:
|
||||
that:
|
||||
- not output.changed
|
||||
- name: assert remove config is idempotent
|
||||
assert:
|
||||
that:
|
||||
- not output.changed
|
||||
|
||||
- name: Remove a Swarm cluster
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
always:
|
||||
- name: Remove a Swarm cluster
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
|
|
|
@ -33,3 +33,6 @@
|
|||
diff: no
|
||||
|
||||
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 == docker_inspect_result[0]"
|
||||
|
||||
# Skip for CentOS 6
|
||||
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|
||||
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 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
|
||||
with_items: "{{ cnames }}"
|
||||
|
||||
# Skip for CentOS 6
|
||||
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|
||||
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 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"
|
||||
- "'alpine:3.8' in result.images[1].RepoTags"
|
||||
|
||||
# Skip for CentOS 6
|
||||
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|
||||
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 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
|
||||
loop: "{{ dnetworks }}"
|
||||
|
||||
# Skip for CentOS 6
|
||||
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|
||||
when: docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.20', '>=') # FIXME: find out API version!
|
||||
|
||||
- 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,47 +10,52 @@
|
|||
## overlay #########################################################
|
||||
####################################################################
|
||||
|
||||
# Overlay networks require swarm initialization before they'll work
|
||||
- name: swarm
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: 192.168.1.1
|
||||
- block:
|
||||
# Overlay networks require swarm initialization before they'll work
|
||||
- name: swarm
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
|
||||
- name: overlay
|
||||
docker_network:
|
||||
name: "{{ nname_1 }}"
|
||||
driver: overlay
|
||||
driver_options:
|
||||
com.docker.network.driver.overlay.vxlanid_list: "257"
|
||||
register: overlay_1
|
||||
- name: overlay
|
||||
docker_network:
|
||||
name: "{{ nname_1 }}"
|
||||
driver: overlay
|
||||
driver_options:
|
||||
com.docker.network.driver.overlay.vxlanid_list: "257"
|
||||
register: overlay_1
|
||||
|
||||
- name: overlay (idempotency)
|
||||
docker_network:
|
||||
name: "{{ nname_1 }}"
|
||||
driver: overlay
|
||||
driver_options:
|
||||
com.docker.network.driver.overlay.vxlanid_list: "257"
|
||||
register: overlay_2
|
||||
- name: overlay (idempotency)
|
||||
docker_network:
|
||||
name: "{{ nname_1 }}"
|
||||
driver: overlay
|
||||
driver_options:
|
||||
com.docker.network.driver.overlay.vxlanid_list: "257"
|
||||
register: overlay_2
|
||||
|
||||
- name: overlay (change)
|
||||
docker_network:
|
||||
name: "{{ nname_1 }}"
|
||||
driver: bridge
|
||||
register: overlay_3
|
||||
- name: overlay (change)
|
||||
docker_network:
|
||||
name: "{{ nname_1 }}"
|
||||
driver: bridge
|
||||
register: overlay_3
|
||||
|
||||
- name: cleanup network
|
||||
docker_network:
|
||||
name: "{{ nname_1 }}"
|
||||
state: absent
|
||||
force: yes
|
||||
- name: cleanup network
|
||||
docker_network:
|
||||
name: "{{ nname_1 }}"
|
||||
state: absent
|
||||
force: yes
|
||||
|
||||
- name: cleanup swarm
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: yes
|
||||
- assert:
|
||||
that:
|
||||
- overlay_1 is changed
|
||||
- overlay_2 is not changed
|
||||
- overlay_3 is changed
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- overlay_1 is changed
|
||||
- overlay_2 is not 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
|
||||
networks: yes
|
||||
volumes: yes
|
||||
builder_cache: yes
|
||||
builder_cache: "{{ docker_py_version is version('3.3.0', '>=') }}"
|
||||
register: result
|
||||
|
||||
# Analyze result
|
||||
|
@ -56,5 +56,7 @@
|
|||
|
||||
- debug: var=result
|
||||
|
||||
# Skip for CentOS 6
|
||||
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|
||||
when: docker_py_version is version('2.1.0', '>=') and docker_api_version is version('1.25', '>=')
|
||||
|
||||
- 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
|
||||
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'
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
---
|
||||
- block:
|
||||
- name: Make sure we're not already using Docker swarm
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
|
||||
- name: Enable swarm mode
|
||||
command: docker swarm init
|
||||
when: output.rc == 0
|
||||
notify: disable_swarm
|
||||
- name: Create a Swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
|
||||
- name: Parameter name should be required
|
||||
docker_secret:
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
- name: Parameter name should be required
|
||||
docker_secret:
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: assert failure when called with no name
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "missing required arguments: name"'
|
||||
- name: assert failure when called with no name
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "missing required arguments: name"'
|
||||
|
||||
- name: Test parameters
|
||||
docker_secret:
|
||||
name: foo
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
- name: Test parameters
|
||||
docker_secret:
|
||||
name: foo
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: assert failure when called with no data
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "state is present but all of the following are missing: data"'
|
||||
- name: assert failure when called with no data
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "state is present but all of the following are missing: data"'
|
||||
|
||||
- name: Create secret
|
||||
docker_secret:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
state: present
|
||||
register: output
|
||||
- name: Create secret
|
||||
docker_secret:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: Create variable secret_id
|
||||
set_fact:
|
||||
secret_id: "{{ output.secret_id }}"
|
||||
- name: Create variable secret_id
|
||||
set_fact:
|
||||
secret_id: "{{ output.secret_id }}"
|
||||
|
||||
- name: Inspect secret
|
||||
command: "docker secret inspect {{ secret_id }}"
|
||||
register: inspect
|
||||
- name: Inspect secret
|
||||
command: "docker secret inspect {{ secret_id }}"
|
||||
register: inspect
|
||||
|
||||
- debug: var=inspect
|
||||
- debug: var=inspect
|
||||
|
||||
- name: assert secret creation succeeded
|
||||
assert:
|
||||
that:
|
||||
- "'db_password' in inspect.stdout"
|
||||
- "'ansible_key' in inspect.stdout"
|
||||
- name: assert secret creation succeeded
|
||||
assert:
|
||||
that:
|
||||
- "'db_password' in inspect.stdout"
|
||||
- "'ansible_key' in inspect.stdout"
|
||||
|
||||
- name: Create secret again
|
||||
docker_secret:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
state: present
|
||||
register: output
|
||||
- name: Create secret again
|
||||
docker_secret:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: assert create secret is idempotent
|
||||
assert:
|
||||
that:
|
||||
- not output.changed
|
||||
- name: assert create secret is idempotent
|
||||
assert:
|
||||
that:
|
||||
- not output.changed
|
||||
|
||||
- name: Update secret
|
||||
docker_secret:
|
||||
name: db_password
|
||||
data: newpassword!
|
||||
state: present
|
||||
register: output
|
||||
- name: Update secret
|
||||
docker_secret:
|
||||
name: db_password
|
||||
data: newpassword!
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: assert secret was updated
|
||||
assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.secret_id != secret_id
|
||||
- name: assert secret was updated
|
||||
assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.secret_id != secret_id
|
||||
|
||||
- name: Remove secret
|
||||
docker_secret:
|
||||
name: db_password
|
||||
state: absent
|
||||
- name: Remove secret
|
||||
docker_secret:
|
||||
name: db_password
|
||||
state: absent
|
||||
|
||||
- name: Check that secret is removed
|
||||
command: "docker secret inspect {{ secret_id }}"
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
- name: Check that secret is removed
|
||||
command: "docker secret inspect {{ secret_id }}"
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
|
||||
- name: assert secret was removed
|
||||
assert:
|
||||
that:
|
||||
- output.failed
|
||||
- name: assert secret was removed
|
||||
assert:
|
||||
that:
|
||||
- output.failed
|
||||
|
||||
always:
|
||||
- name: Remove Swarm cluster
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
- include_tasks: test_stack.yml
|
||||
when:
|
||||
- ansible_os_family != 'RedHat' or ansible_distribution_major_version != '6'
|
||||
- ansible_distribution != 'Fedora' or ansible_distribution_major_version|int >= 26
|
||||
when: docker_api_version is version('1.25', '>=')
|
||||
|
||||
- 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,110 +1,113 @@
|
|||
- name: Make sure we're not already using Docker swarm
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
---
|
||||
- block:
|
||||
- name: Make sure we're not already using Docker swarm
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
|
||||
- name: Create a Swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
- name: Create a Swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
|
||||
- name: install docker_stack python requirements
|
||||
pip:
|
||||
name: jsondiff,pyyaml
|
||||
- name: install docker_stack python requirements
|
||||
pip:
|
||||
name: jsondiff,pyyaml
|
||||
|
||||
- name: Create a stack without name
|
||||
register: output
|
||||
docker_stack:
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
- name: Create a stack without name
|
||||
register: output
|
||||
docker_stack:
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
|
||||
- name: assert failure when name not set
|
||||
assert:
|
||||
that:
|
||||
- output is failed
|
||||
- 'output.msg == "missing required arguments: name"'
|
||||
- name: assert failure when name not set
|
||||
assert:
|
||||
that:
|
||||
- output is failed
|
||||
- 'output.msg == "missing required arguments: name"'
|
||||
|
||||
- name: Create a stack without compose
|
||||
register: output
|
||||
docker_stack:
|
||||
name: test_stack
|
||||
ignore_errors: yes
|
||||
- name: Create a stack without compose
|
||||
register: output
|
||||
docker_stack:
|
||||
name: test_stack
|
||||
ignore_errors: yes
|
||||
|
||||
- name: assert failure when compose not set
|
||||
assert:
|
||||
that:
|
||||
- output is failed
|
||||
- 'output.msg == "compose parameter must be a list containing at least one element"'
|
||||
- name: assert failure when compose not set
|
||||
assert:
|
||||
that:
|
||||
- output is failed
|
||||
- 'output.msg == "compose parameter must be a list containing at least one element"'
|
||||
|
||||
- name: Ensure stack is absent
|
||||
register: output
|
||||
docker_stack:
|
||||
state: absent
|
||||
name: test_stack
|
||||
absent_retries: 30
|
||||
- name: Ensure stack is absent
|
||||
register: output
|
||||
docker_stack:
|
||||
state: absent
|
||||
name: test_stack
|
||||
absent_retries: 30
|
||||
|
||||
- name: Copy compose files
|
||||
copy:
|
||||
src: "{{item}}"
|
||||
dest: "{{output_dir}}/"
|
||||
with_items:
|
||||
- stack_compose_base.yml
|
||||
- stack_compose_overrides.yml
|
||||
- name: Copy compose files
|
||||
copy:
|
||||
src: "{{item}}"
|
||||
dest: "{{output_dir}}/"
|
||||
with_items:
|
||||
- stack_compose_base.yml
|
||||
- stack_compose_overrides.yml
|
||||
|
||||
- name: Create stack with compose file
|
||||
register: output
|
||||
docker_stack:
|
||||
state: present
|
||||
name: test_stack
|
||||
compose:
|
||||
- "{{output_dir}}/stack_compose_base.yml"
|
||||
- name: Create stack with compose file
|
||||
register: output
|
||||
docker_stack:
|
||||
state: present
|
||||
name: test_stack
|
||||
compose:
|
||||
- "{{output_dir}}/stack_compose_base.yml"
|
||||
|
||||
- name: assert test_stack changed on stack creation with compose file
|
||||
assert:
|
||||
that:
|
||||
- output is changed
|
||||
- name: assert test_stack changed on stack creation with compose file
|
||||
assert:
|
||||
that:
|
||||
- output is changed
|
||||
|
||||
# FIXME: updating the stack prevents leaving the swarm on Shippable
|
||||
#- name: Update stack with YAML
|
||||
# register: output
|
||||
# docker_stack:
|
||||
# state: present
|
||||
# name: test_stack
|
||||
# compose:
|
||||
# - "{{stack_compose_base}}"
|
||||
# - "{{stack_compose_overrides}}"
|
||||
#
|
||||
#- name: assert test_stack correctly changed on update with yaml
|
||||
# assert:
|
||||
# that:
|
||||
# - output is changed
|
||||
# - output.docker_stack_spec_diff == stack_update_expected_diff
|
||||
# FIXME: updating the stack prevents leaving the swarm on Shippable
|
||||
#- name: Update stack with YAML
|
||||
# register: output
|
||||
# docker_stack:
|
||||
# state: present
|
||||
# name: test_stack
|
||||
# compose:
|
||||
# - "{{stack_compose_base}}"
|
||||
# - "{{stack_compose_overrides}}"
|
||||
#
|
||||
#- name: assert test_stack correctly changed on update with yaml
|
||||
# assert:
|
||||
# that:
|
||||
# - output is changed
|
||||
# - output.docker_stack_spec_diff == stack_update_expected_diff
|
||||
|
||||
- name: Delete stack
|
||||
register: output
|
||||
docker_stack:
|
||||
state: absent
|
||||
name: test_stack
|
||||
absent_retries: 30
|
||||
- name: Delete stack
|
||||
register: output
|
||||
docker_stack:
|
||||
state: absent
|
||||
name: test_stack
|
||||
absent_retries: 30
|
||||
|
||||
- name: assert delete of existing stack returns changed
|
||||
assert:
|
||||
that:
|
||||
- output is changed
|
||||
- name: assert delete of existing stack returns changed
|
||||
assert:
|
||||
that:
|
||||
- output is changed
|
||||
|
||||
- name: Delete stack again
|
||||
register: output
|
||||
docker_stack:
|
||||
state: absent
|
||||
name: test_stack
|
||||
absent_retries: 30
|
||||
- name: Delete stack again
|
||||
register: output
|
||||
docker_stack:
|
||||
state: absent
|
||||
name: test_stack
|
||||
absent_retries: 30
|
||||
|
||||
- name: assert state=absent idempotency
|
||||
assert:
|
||||
that:
|
||||
- output is not changed
|
||||
- name: assert state=absent idempotency
|
||||
assert:
|
||||
that:
|
||||
- output is not changed
|
||||
|
||||
- name: Remove a Swarm cluster
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
always:
|
||||
- name: Remove a Swarm cluster
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
- 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:
|
||||
state: absent
|
||||
force: true
|
||||
---
|
||||
- block:
|
||||
- name: Make sure we're not already using Docker swarm
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
|
||||
- name: Test parameters with state=join
|
||||
docker_swarm:
|
||||
state: join
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
- name: Test parameters with state=join
|
||||
docker_swarm:
|
||||
state: join
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: assert failure when called with state=join and no advertise_addr,remote_addrs,join_token
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "state is join but all of the following are missing: advertise_addr, remote_addrs, join_token"'
|
||||
- name: assert failure when called with state=join and no advertise_addr,remote_addrs,join_token
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "state is join but all of the following are missing: advertise_addr, remote_addrs, join_token"'
|
||||
|
||||
- name: Test parameters with state=remove
|
||||
docker_swarm:
|
||||
state: remove
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
- name: Test parameters with state=remove
|
||||
docker_swarm:
|
||||
state: remove
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: assert failure when called with state=remove and no node_id
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "state is remove but all of the following are missing: node_id"'
|
||||
- name: assert failure when called with state=remove and no node_id
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "state is remove but all of the following are missing: node_id"'
|
||||
|
||||
- name: Create a Swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
register: output
|
||||
- name: Create a Swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: assert changed when create a new swarm cluster
|
||||
assert:
|
||||
that:
|
||||
- 'output.changed'
|
||||
- 'output.actions[0] | regex_search("New Swarm cluster created: ")'
|
||||
- 'output.swarm_facts.JoinTokens.Manager'
|
||||
- 'output.swarm_facts.JoinTokens.Worker'
|
||||
- name: assert changed when create a new swarm cluster
|
||||
assert:
|
||||
that:
|
||||
- 'output.changed'
|
||||
- 'output.actions[0] | regex_search("New Swarm cluster created: ")'
|
||||
- 'output.swarm_facts.JoinTokens.Manager'
|
||||
- 'output.swarm_facts.JoinTokens.Worker'
|
||||
|
||||
- name: Remove a Swarm cluster
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
register: output
|
||||
- name: Remove a Swarm cluster
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
register: output
|
||||
|
||||
- name: assert changed when remove a swarm cluster
|
||||
assert:
|
||||
that:
|
||||
- 'output.changed'
|
||||
- 'output.actions[0] == "Node has leaved the swarm cluster"'
|
||||
- name: assert changed when remove a swarm cluster
|
||||
assert:
|
||||
that:
|
||||
- 'output.changed'
|
||||
- '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
|
||||
when:
|
||||
- ansible_os_family != 'RedHat' or ansible_distribution_major_version != '6'
|
||||
- ansible_distribution != 'Fedora' or ansible_distribution_major_version|int >= 26
|
||||
# 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
|
||||
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_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,122 +1,125 @@
|
|||
- name: Create a Swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
---
|
||||
- block:
|
||||
- name: Create a Swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
|
||||
- name: Create a swarm service without name
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
- name: Create a swarm service without name
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
|
||||
- name: assert failure when name not set
|
||||
assert:
|
||||
that:
|
||||
- output is failed
|
||||
- 'output.msg == "missing required arguments: name"'
|
||||
- name: assert failure when name not set
|
||||
assert:
|
||||
that:
|
||||
- output is failed
|
||||
- 'output.msg == "missing required arguments: name"'
|
||||
|
||||
- name: Remove an non-existing service
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
state: absent
|
||||
name: non_existing_service
|
||||
- name: Remove an non-existing service
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
state: absent
|
||||
name: non_existing_service
|
||||
|
||||
- name: assert output not changed when deleting non-existing service
|
||||
assert:
|
||||
that:
|
||||
- output is not changed
|
||||
- name: assert output not changed when deleting non-existing service
|
||||
assert:
|
||||
that:
|
||||
- output is not changed
|
||||
|
||||
- name: create sample service
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
name: test_service
|
||||
endpoint_mode: dnsrr
|
||||
image: busybox
|
||||
args:
|
||||
- sleep
|
||||
- "3600"
|
||||
- name: create sample service
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
name: test_service
|
||||
endpoint_mode: dnsrr
|
||||
image: busybox
|
||||
args:
|
||||
- sleep
|
||||
- "3600"
|
||||
|
||||
- name: assert sample service is created
|
||||
assert:
|
||||
that:
|
||||
- output is changed
|
||||
- name: assert sample service is created
|
||||
assert:
|
||||
that:
|
||||
- output is changed
|
||||
|
||||
- name: change service args
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
name: test_service
|
||||
image: busybox
|
||||
args:
|
||||
- sleep
|
||||
- "1800"
|
||||
- name: change service args
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
name: test_service
|
||||
image: busybox
|
||||
args:
|
||||
- sleep
|
||||
- "1800"
|
||||
|
||||
- name: assert service args are correct
|
||||
assert:
|
||||
that:
|
||||
- output.ansible_docker_service.args == ['sleep', '1800']
|
||||
- name: assert service args are correct
|
||||
assert:
|
||||
that:
|
||||
- output.ansible_docker_service.args == ['sleep', '1800']
|
||||
|
||||
- name: set service mode to global
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
name: test_service
|
||||
image: busybox
|
||||
endpoint_mode: vip
|
||||
mode: global
|
||||
args:
|
||||
- sleep
|
||||
- "1800"
|
||||
- name: set service mode to global
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
name: test_service
|
||||
image: busybox
|
||||
endpoint_mode: vip
|
||||
mode: global
|
||||
args:
|
||||
- sleep
|
||||
- "1800"
|
||||
|
||||
- name: assert service mode changed caused service rebuild
|
||||
assert:
|
||||
that:
|
||||
- output.rebuilt
|
||||
- name: assert service mode changed caused service rebuild
|
||||
assert:
|
||||
that:
|
||||
- output.rebuilt
|
||||
|
||||
- name: add published ports to service
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
name: test_service
|
||||
image: busybox
|
||||
mode: global
|
||||
args:
|
||||
- sleep
|
||||
- "1800"
|
||||
endpoint_mode: vip
|
||||
publish:
|
||||
- protocol: tcp
|
||||
published_port: 60001
|
||||
target_port: 60001
|
||||
- protocol: udp
|
||||
published_port: 60001
|
||||
target_port: 60001
|
||||
- name: add published ports to service
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
name: test_service
|
||||
image: busybox
|
||||
mode: global
|
||||
args:
|
||||
- sleep
|
||||
- "1800"
|
||||
endpoint_mode: vip
|
||||
publish:
|
||||
- protocol: tcp
|
||||
published_port: 60001
|
||||
target_port: 60001
|
||||
- protocol: udp
|
||||
published_port: 60001
|
||||
target_port: 60001
|
||||
|
||||
- name: assert service matches expectations
|
||||
assert:
|
||||
that:
|
||||
- output.ansible_docker_service == service_expected_output
|
||||
- name: assert service matches expectations
|
||||
assert:
|
||||
that:
|
||||
- output.ansible_docker_service == service_expected_output
|
||||
|
||||
- name: delete sample service
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
name: test_service
|
||||
state: absent
|
||||
- name: delete sample service
|
||||
register: output
|
||||
docker_swarm_service:
|
||||
name: test_service
|
||||
state: absent
|
||||
|
||||
- name: assert service deletion returns changed
|
||||
assert:
|
||||
that:
|
||||
- output is success
|
||||
- output is changed
|
||||
- name: assert service deletion returns changed
|
||||
assert:
|
||||
that:
|
||||
- output is success
|
||||
- output is changed
|
||||
|
||||
- name: Remove the Swarm cluster
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
- name: Remove the Swarm cluster
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
|
||||
- name: Try reitializing the swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
- name: Try reitializing the swarm cluster
|
||||
docker_swarm:
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
|
||||
- name: Clean the docker daemon status
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
always:
|
||||
- name: Clean the docker daemon status
|
||||
docker_swarm:
|
||||
state: absent
|
||||
force: true
|
||||
|
|
|
@ -20,5 +20,7 @@
|
|||
force: yes
|
||||
with_items: "{{ vnames }}"
|
||||
|
||||
# Skip for CentOS 6
|
||||
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|
||||
when: docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.20', '>=') # FIXME: find out API version!
|
||||
|
||||
- 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…
Reference in a new issue