Integration tests for docker_host_facts module (#52487)

* Integration tests for docker_host_facts

* Integration tests for docker_host_facts (update to cover #52432 fix)

* Integration tests for docker_host_facts updates after review

* Integration tests for docker_host_facts updates after review

* Integration tests for docker_host_facts updates after review

* Integration tests for docker_host_facts - adding comments and integrated test for all options combined together

* Integration tests for docker_host_facts - small code improvement

* Adjusting variable name
pull/52704/head
Piotr Wojciechowski 6 years ago committed by ansibot
parent d6ef07ca45
commit 995c4bf02e

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

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

@ -0,0 +1,5 @@
- include_tasks: test_host_facts.yml
when: docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.21', '>=')
- 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.21', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

@ -0,0 +1,274 @@
---
- name: Create random container/volume name
set_fact:
cname: "{{ 'ansible-test-%0x' % ((2**32) | random) }}"
vname: "{{ 'ansible-test-%0x' % ((2**32) | random) }}"
- debug:
msg: "Using container name '{{ cname }}' and volume name '{{ vname }}'"
- block:
- name: Get info on Docker host
docker_host_facts:
register: output
- name: assert reading docker host facts when docker is running
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_containers_list is not defined'
- 'output.docker_networks_list is not defined'
- 'output.docker_volumes_list is not defined'
- 'output.docker_images_list is not defined'
- 'output.docker_disk_usage is not defined'
# Container and volume are created so that all lists are non-empty:
# * container and volume lists are non-emtpy because of the created objects;
# * image list is non-empty because the image of the container is there;
# * network list is always non-empty (default networks).
- name: Create container
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
register: container_output
- assert:
that:
- container_output is changed
- name: Create a volume
docker_volume:
name: "{{ vname }}"
register: volume_output
- assert:
that:
- volume_output is changed
- name: Get info on Docker host and list containers
docker_host_facts:
containers: yes
register: output
- name: assert reading docker host facts when docker is running and list containers
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_networks_list is not defined'
- 'output.docker_volumes_list is not defined'
- 'output.docker_images_list is not defined'
- 'output.docker_disk_usage is not defined'
- 'output.docker_containers_list[0].Image is string'
- 'output.docker_containers_list[0].ImageID is not defined'
- name: Get info on Docker host and list containers with verbose output
docker_host_facts:
containers: yes
verbose_output: yes
register: output
- name: assert reading docker host facts when docker is running and list containers with verbose output
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_networks_list is not defined'
- 'output.docker_volumes_list is not defined'
- 'output.docker_images_list is not defined'
- 'output.docker_disk_usage is not defined'
- 'output.docker_containers_list[0].Image is string'
- 'output.docker_containers_list[0].ImageID is string'
- name: Get info on Docker host and list images
docker_host_facts:
images: yes
register: output
- name: assert reading docker host facts when docker is running and list images
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_containers_list is not defined'
- 'output.docker_networks_list is not defined'
- 'output.docker_volumes_list is not defined'
- 'output.docker_images_list[0].Id is string'
- 'output.docker_images_list[0].ParentId is not defined'
- 'output.docker_disk_usage is not defined'
- name: Get info on Docker host and list images with verbose output
docker_host_facts:
images: yes
verbose_output: yes
register: output
- name: assert reading docker host facts when docker is running and list images with verbose output
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_containers_list is not defined'
- 'output.docker_networks_list is not defined'
- 'output.docker_volumes_list is not defined'
- 'output.docker_images_list[0].Id is string'
- 'output.docker_images_list[0].ParentId is string'
- 'output.docker_disk_usage is not defined'
- name: Get info on Docker host and list networks
docker_host_facts:
networks: yes
register: output
- name: assert reading docker host facts when docker is running and list networks
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_containers_list is not defined'
- 'output.docker_networks_list[0].Id is string'
- 'output.docker_networks_list[0].Created is not defined'
- 'output.docker_volumes_list is not defined'
- 'output.docker_images_list is not defined'
- 'output.docker_disk_usage is not defined'
- name: Get info on Docker host and list networks with verbose output
docker_host_facts:
networks: yes
verbose_output: yes
register: output
- name: assert reading docker host facts when docker is running and list networks with verbose output
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_containers_list is not defined'
- 'output.docker_networks_list[0].Id is string'
- 'output.docker_networks_list[0].Created is string'
- 'output.docker_volumes_list is not defined'
- 'output.docker_images_list is not defined'
- 'output.docker_disk_usage is not defined'
- name: Get info on Docker host and list volumes
docker_host_facts:
volumes: yes
register: output
- name: assert reading docker host facts when docker is running and list volumes
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_containers_list is not defined'
- 'output.docker_networks_list is not defined'
- 'output.docker_volumes_list[0].Name is string'
- 'output.docker_volumes_list[0].Mountpoint is not defined'
- 'output.docker_images_list is not defined'
- 'output.docker_disk_usage is not defined'
- name: Get info on Docker host and list volumes with verbose output
docker_host_facts:
volumes: yes
verbose_output: yes
register: output
- name: assert reading docker host facts when docker is running and list volumes with verbose output
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_containers_list is not defined'
- 'output.docker_networks_list is not defined'
- 'output.docker_volumes_list[0].Name is string'
- 'output.docker_volumes_list[0].Mountpoint is string'
- 'output.docker_images_list is not defined'
- 'output.docker_disk_usage is not defined'
- name: Get info on Docker host and get disk usage
docker_host_facts:
disk_usage: yes
register: output
- name: assert reading docker host facts when docker is running and get disk usage
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_containers_list is not defined'
- 'output.docker_networks_list is not defined'
- 'output.docker_volumes_list is not defined'
- 'output.docker_images_list is not defined'
- 'output.docker_disk_usage.LayersSize is number'
- 'output.docker_disk_usage.BuilderSize is not defined'
- name: Get info on Docker host and get disk usage with verbose output
docker_host_facts:
disk_usage: yes
verbose_output: yes
register: output
- name: assert reading docker host facts when docker is running and get disk usage with verbose output
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_containers_list is not defined'
- 'output.docker_networks_list is not defined'
- 'output.docker_volumes_list is not defined'
- 'output.docker_images_list is not defined'
- 'output.docker_disk_usage.LayersSize is number'
- 'output.docker_disk_usage.BuilderSize is number'
- name: Get info on Docker host, disk usage and get all lists together
docker_host_facts:
volumes: yes
containers: yes
networks: yes
images: yes
disk_usage: yes
register: output
- name: assert reading docker host facts when docker is running, disk usage and get lists together
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_containers_list[0].Image is string'
- 'output.docker_containers_list[0].ImageID is not defined'
- 'output.docker_networks_list[0].Id is string'
- 'output.docker_networks_list[0].Created is not defined'
- 'output.docker_volumes_list[0].Name is string'
- 'output.docker_volumes_list[0].Mountpoint is not defined'
- 'output.docker_images_list[0].Id is string'
- 'output.docker_images_list[0].ParentId is not defined'
- 'output.docker_disk_usage.LayersSize is number'
- 'output.docker_disk_usage.BuilderSize is not defined'
- name: Get info on Docker host, disk usage and get all lists together with verbose output
docker_host_facts:
volumes: yes
containers: yes
networks: yes
images: yes
disk_usage: yes
verbose_output: yes
register: output
- name: assert reading docker host facts when docker is running and get disk usage with verbose output
assert:
that:
- 'output.docker_host_facts.Name is string'
- 'output.docker_containers_list[0].Image is string'
- 'output.docker_containers_list[0].ImageID is string'
- 'output.docker_networks_list[0].Id is string'
- 'output.docker_networks_list[0].Created is string'
- 'output.docker_volumes_list[0].Name is string'
- 'output.docker_volumes_list[0].Mountpoint is string'
- 'output.docker_images_list[0].Id is string'
- 'output.docker_images_list[0].ParentId is string'
- 'output.docker_disk_usage.LayersSize is number'
- 'output.docker_disk_usage.BuilderSize is number'
always:
- name: Delete container
docker_container:
name: "{{ cname }}"
state: absent
force_kill: yes
- name: Delete volume
docker_volume:
name: "{{ vname }}"
state: absent
Loading…
Cancel
Save