1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

docker_swarm_service: Add option tests (#50699)

* Add option tests

* Check for api version on publish

* Enable configs tests

* Remove unsupported test

* Let main.yml hande creation/destruction of swarms

* Revert "Remove unsupported test"

This reverts commit 50f46bb04ef679f4235cda805188dca769ca2f72.

* Revert "Enable configs tests"

This reverts commit a94054b0bb5a3d77632bbe5aa352a8774cf93d96.

* Fix typo to properly clear secrets
This commit is contained in:
Hannes Ljungberg 2019-01-16 09:50:06 +01:00 committed by ansibot
parent 1d51c425ba
commit d264bf4f4e
6 changed files with 1870 additions and 130 deletions

View file

@ -1,5 +1,75 @@
- include_tasks: test_swarm_service.yml
when: docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.25', '>=')
---
# Create random name prefix (for containers, networks, ...)
- name: Create random name prefix
set_fact:
name_prefix: "{{ 'ansible-test-%0x' % ((2**32) | random) }}"
service_names: []
network_names: []
config_names: []
secret_names: []
volume_names: []
- debug:
msg: "Using container name prefix {{ name_prefix }}"
# Run the tests
- block:
- name: Create a Swarm cluster
docker_swarm:
state: present
advertise_addr: "{{ansible_default_ipv4.address}}"
- include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
always:
- name: Make sure all services are removed
docker_swarm_service:
name: "{{ item }}"
state: absent
loop: "{{ service_names }}"
ignore_errors: yes
- name: Make sure all networks are removed
docker_network:
name: "{{ item }}"
state: absent
force: yes
loop: "{{ network_names }}"
ignore_errors: yes
- name: Make sure all configs are removed
docker_config:
name: "{{ item }}"
state: absent
force: yes
loop: "{{ config_names }}"
ignore_errors: yes
- name: Make sure all volumes are removed
docker_volume:
name: "{{ item }}"
state: absent
force: yes
loop: "{{ volume_names }}"
ignore_errors: yes
- name: Make sure all secrets are removed
docker_secret:
name: "{{ item }}"
state: absent
force: yes
loop: "{{ secret_names }}"
ignore_errors: yes
- name: Make sure swarm is removed
docker_swarm:
state: absent
force: yes
ignore_errors: yes
when: docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.24', '>=')
- 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.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
when: not(docker_py_version is version('2.6.0', '>=') and docker_api_version is version('1.24', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View file

@ -0,0 +1,3 @@
---
- name: "Loading tasks from {{ item }}"
include_tasks: "{{ item }}"

View file

@ -1,125 +0,0 @@
---
- 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: 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: 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: 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: 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: 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: 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: 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: Try reitializing the swarm cluster
docker_swarm:
state: present
advertise_addr: "{{ansible_default_ipv4.address}}"
always:
- name: Clean the docker daemon status
docker_swarm:
state: absent
force: true

View file

@ -0,0 +1,104 @@
---
- 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: 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: 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: 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: 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: 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: 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

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,5 @@
---
service_expected_output:
args: [sleep, '1800']
configs: null