docker_swarm inventory plugin: add basic integration tests (#53908)

* Add basic docker_swarm inventory plugin integration tests.

* Call dependency explicitly.
This commit is contained in:
Felix Fontein 2019-03-17 09:16:18 +01:00 committed by John R Barker
parent ef6da8ec5c
commit 259b2e06a4
7 changed files with 90 additions and 0 deletions

View file

@ -0,0 +1,10 @@
shippable/posix/group2
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. On VMs, we restart docker daemon
# after finishing the tests to minimize potential effects
# on other tests.
needs/root

View file

@ -0,0 +1,3 @@
---
plugin: docker_swarm
host: unix://var/run/docker.sock

View file

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

View file

@ -0,0 +1,9 @@
---
- hosts: 127.0.0.1
connection: local
gather_facts: no
tasks:
- name: Make sure swarm is removed
docker_swarm:
state: absent
force: yes

View file

@ -0,0 +1,11 @@
---
- hosts: 127.0.0.1
connection: local
tasks:
- name: Setup docker
include_role:
name: ../../setup_docker
- name: Create a Swarm cluster
docker_swarm:
state: present
advertise_addr: "{{ansible_default_ipv4.address | default('127.0.0.1')}}"

View file

@ -0,0 +1,34 @@
---
- hosts: all
connection: local # otherwise Ansible will complain that it cannot connect via ssh to 127.0.0.1:22
tasks:
- name: Check for groups
assert:
that:
- "groups.manager | length > 0"
- "groups.worker | length >= 0"
- "groups.leader | length == 1"
run_once: yes
- name: List manager group
debug:
var: groups.manager
run_once: yes
- name: List worker group
debug:
var: groups.worker
run_once: yes
- name: List leader group
debug:
var: groups.leader
run_once: yes
- name: Print ansible_host per host
debug:
var: ansible_host
- name: Print docker_swarm_node_attributes per host
debug:
var: docker_swarm_node_attributes

View file

@ -0,0 +1,20 @@
#!/usr/bin/env bash
[[ -n "$DEBUG" || -n "$ANSIBLE_DEBUG" ]] && set -x
set -euo pipefail
cleanup() {
echo "Cleanup"
ansible-playbook playbooks/swarm_cleanup.yml
echo "Done"
exit 0
}
trap cleanup INT TERM EXIT
echo "Setup"
ansible-playbook playbooks/swarm_setup.yml
echo "Test docker_swarm inventory 1"
ansible-playbook -i inventory_1.docker_swarm.yml playbooks/test_inventory_1.yml