New Docker Stack Task Info Module with Tests (#732)

* Add docker_stack_task_info with tests

* Change link

* Change ln

* Fix Documentation

* Small doc changes

* Remove node for RH
This commit is contained in:
Jose Angel Munoz 2020-08-05 08:16:32 +02:00 committed by GitHub
parent ce48751033
commit 107e956565
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 217 additions and 0 deletions

View file

@ -0,0 +1,8 @@
shippable/posix/group1
skip/aix
skip/osx
skip/freebsd
destructive
skip/docker # The tests sometimes make docker daemon unstable; hence,
# we skip all docker-based CI runs to avoid disrupting
# the whole CI system.

View file

@ -0,0 +1,5 @@
version: '3'
services:
busybox:
image: busybox:latest
command: sleep 3600

View file

@ -0,0 +1,5 @@
version: '3'
services:
busybox:
environment:
envvar: value

View file

@ -0,0 +1,3 @@
---
dependencies:
- setup_docker

View file

@ -0,0 +1,5 @@
- include_tasks: test_stack_task_info.yml
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)

View file

@ -0,0 +1,80 @@
---
- block:
- name: Make sure we're not already using Docker swarm
docker_swarm:
state: absent
force: true
- name: Get docker_stack_info when docker is not running in swarm mode
docker_stack_info:
ignore_errors: true
register: output
- name: Assert failure when called when swarm is not running
assert:
that:
- 'output is failed'
- '"Error running docker stack" in output.msg'
- name: Create a swarm cluster
docker_swarm:
state: present
advertise_addr: "{{ ansible_default_ipv4.address }}"
- name: Get docker_stack_info when docker is running and not stack available
docker_stack_info:
register: output
- name: Assert stack facts
assert:
that:
- 'output.results | type_debug == "list"'
- 'output.results | length == 0'
- name: Copy compose files
copy:
src: "{{ item }}"
dest: "{{ output_dir }}/"
with_items:
- stack_compose_base.yml
- stack_compose_overrides.yml
- name: Install docker_stack python requirements
pip:
name: jsondiff,pyyaml
- 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: Get docker_stack_info when docker is running
docker_stack_info:
register: output
- name: Get docker_stack_task_info first element
docker_stack_task_info:
name: "{{ output.results[0].Name }}"
register: output
- name: assert stack facts
assert:
that:
- 'output.results | type_debug == "list"'
- 'output.results[0].DesiredState == "Running"'
- 'output.results[0].Image == "busybox:latest"'
- 'output.results[0].Name == "test_stack_busybox.1"'
always:
- name: Cleanup
docker_swarm:
state: absent
force: true

View file

@ -0,0 +1,15 @@
stack_compose_base:
version: '3'
services:
busybox:
image: busybox:latest
command: sleep 3600
stack_compose_overrides:
version: '3'
services:
busybox:
environment:
envvar: value
stack_update_expected_diff: '{"test_stack_busybox": {"TaskTemplate": {"ContainerSpec": {"Env": ["envvar=value"]}}}}'