Integration tests for module docker_swarm_facts (#52208)

* * docker_swarm_facts integration tests

* * docker_swarm_facts integration tests

* * docker_swarm_facts integration tests

* Removing commented lines

* Extended and updated integration tests for docker_swarm_facts module

* Cosmetic integtration tests playbook changes

* Cosmetic integtration tests playbook changes from PR comments
This commit is contained in:
Piotr Wojciechowski 2019-02-16 22:20:54 +01:00 committed by ansibot
parent ef3d86255d
commit d27ac7a816
4 changed files with 145 additions and 0 deletions

View file

@ -0,0 +1,5 @@
shippable/posix/group2
skip/osx
skip/freebsd
destructive
skip/rhel8.0

View file

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

View file

@ -0,0 +1,5 @@
- include_tasks: test_swarm_facts.yml
when: docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.24', '>=')
- fail: msg="Too old docker / docker-py version to run docker_swarm_facts tests!"
when: not(docker_py_version is version('1.10.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,132 @@
---
- block:
- name: Make sure we're not already using Docker swarm
docker_swarm:
state: absent
force: true
- name: Try to get docker_swarm_facts when docker is not running in swarm mode
docker_swarm_facts:
ignore_errors: yes
register: output
- name: assert failure when called when swarm is not in use or not run on mamager node
assert:
that:
- 'output is failed'
- 'output.msg == "Error running docker swarm module: must run on swarm manager node"'
- 'output.can_talk_to_docker == true'
- 'output.docker_swarm_active == false'
- 'output.docker_swarm_manager == false'
- name: Create a Swarm cluster
docker_swarm:
state: present
register: output
- name: assert changed when create a new swarm cluster
assert:
that:
- 'output is changed'
- 'output.actions[0] | regex_search("New Swarm cluster created: ")'
- 'output.swarm_facts.JoinTokens.Manager'
- 'output.swarm_facts.JoinTokens.Worker'
- name: Try to get docker_swarm_facts when docker is running in swarm mode and as manager
docker_swarm_facts:
register: output
- name: assert creding docker swarm facts
assert:
that:
- 'output.docker_swarm_facts.JoinTokens.Manager'
- 'output.docker_swarm_facts.JoinTokens.Worker'
- 'output.docker_swarm_facts.ID'
- 'output.can_talk_to_docker == true'
- 'output.docker_swarm_active == true'
- 'output.docker_swarm_manager == true'
- name: Try to get docker_swarm_facts and list of nodes when docker is running in swarm mode and as manager
docker_swarm_facts:
nodes: yes
register: output
- name: assert reding swarm facts with list of nodes option
assert:
that:
- 'output.docker_swarm_facts.JoinTokens.Manager'
- 'output.docker_swarm_facts.JoinTokens.Worker'
- 'output.docker_swarm_facts.ID'
- 'output.docker_nodes_list[0].ID is string'
- 'output.can_talk_to_docker == true'
- 'output.docker_swarm_active == true'
- 'output.docker_swarm_manager == true'
- name: Get local docker node name
set_fact:
localnodename: "{{ output.docker_nodes_list[0].Hostname }}"
- name: Try to get docker_swarm_facts and verbose list of nodes when docker is running in swarm mode and as manager
docker_swarm_facts:
nodes: yes
verbose_output: yes
register: output
- name: assert reading swarm facts with list of nodes and versbose output options
assert:
that:
- 'output.docker_swarm_facts.JoinTokens.Manager'
- 'output.docker_swarm_facts.JoinTokens.Worker'
- 'output.docker_swarm_facts.ID'
- 'output.docker_nodes_list[0].ID is string'
- 'output.docker_nodes_list[0].CreatedAt'
- 'output.can_talk_to_docker == true'
- 'output.docker_swarm_active == true'
- 'output.docker_swarm_manager == true'
- name: Try to get docker_swarm_facts and list of nodes with filters providing existing node name
docker_swarm_facts:
nodes: yes
nodes_filters:
name: "{{ localnodename }}"
register: output
- name: assert reading reading swarm facts and using node filter (random node name)
assert:
that:
- 'output.docker_swarm_facts.JoinTokens.Manager'
- 'output.docker_swarm_facts.JoinTokens.Worker'
- 'output.docker_swarm_facts.ID'
- 'output.docker_nodes_list | length == 1'
- 'output.can_talk_to_docker == true'
- 'output.docker_swarm_active == true'
- 'output.docker_swarm_manager == true'
- name: Create random name
set_fact:
randomnodename: "{{ 'node-%0x' % ((2**32) | random) }}"
- name: Try to get docker_swarm_facts and list of nodes with filters providing non-existing random node name
docker_swarm_facts:
nodes: yes
nodes_filters:
name: "{{ randomnodename }}"
register: output
- name: assert reading reading swarm facts and using node filter (random node name)
assert:
that:
- 'output.docker_swarm_facts.JoinTokens.Manager'
- 'output.docker_swarm_facts.JoinTokens.Worker'
- 'output.docker_swarm_facts.ID'
- 'output.docker_nodes_list | length == 0'
- 'output.can_talk_to_docker == true'
- 'output.docker_swarm_active == true'
- 'output.docker_swarm_manager == true'
always:
- name: Cleanup
docker_swarm:
state: absent
force: true