Add Support of healthcheck in docker_container module (#46772)

* Add Support of healthcheck in docker_container module

Fixes #33622
Now container can be started with healthcheck enabled

Signed-off-by: Akshay Gaikwad <akgaikwad001@gmail.com>

* Extend docker_container healthcheck (#1)

* Allowing to disable healthcheck.

* Added test for healthcheck.

* Make sure correct types are used.

* Healthcheck needs to be explicitly disabled with test: ['NONE'].

* pep8 fixes

Signed-off-by: Akshay Gaikwad <akgaikwad001@gmail.com>

* Fix bug if healthcheck interval is 1 day or more

`timedelta` object has days too and seconds are up to one day.
Therefore use `total_seconds()` to convert time into seconds.

Signed-off-by: Akshay Gaikwad <akgaikwad001@gmail.com>

* Add test for healthcheck when healthcheck is not specified

This is to avoid the situation when healthcheck is not specified and
treat this as healthcheck is changed or removed.

Signed-off-by: Akshay Gaikwad <akgaikwad001@gmail.com>

* Convert string syntax for healthcheck test to CMD-SHELL

Also add another test case to check idempotency when healthcheck test
is specified as string

Signed-off-by: Akshay Gaikwad <akgaikwad001@gmail.com>

* Playbook fails if minimun docker version is not satisfy for healthcheck

This is to make more consistent with other non-supported options.

Signed-off-by: Akshay Gaikwad <akgaikwad001@gmail.com>
This commit is contained in:
Akshay Gaikwad 2018-10-24 16:19:56 +05:30 committed by John R Barker
commit 20b95adf2b
3 changed files with 269 additions and 0 deletions

View file

@ -1182,6 +1182,133 @@
- groups_3 is not changed
- groups_4 is changed
####################################################################
## healthcheck #####################################################
####################################################################
- name: healthcheck
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
healthcheck:
test:
- CMD
- sleep
- 1
timeout: 2s
interval: 0h0m2s3ms4us
retries: 2
stop_timeout: 1
register: healthcheck_1
- name: healthcheck (idempotency)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
healthcheck:
test:
- CMD
- sleep
- 1
timeout: 2s
interval: 0h0m2s3ms4us
retries: 2
stop_timeout: 1
register: healthcheck_2
- name: healthcheck (changed)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
healthcheck:
test:
- CMD
- sleep
- 1
timeout: 3s
interval: 0h1m2s3ms4us
retries: 3
stop_timeout: 1
register: healthcheck_3
- name: healthcheck (no change)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
stop_timeout: 1
register: healthcheck_4
- name: healthcheck (disabled)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
healthcheck:
test:
- NONE
stop_timeout: 1
register: healthcheck_5
- name: healthcheck (disabled, idempotency)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
healthcheck:
test:
- NONE
stop_timeout: 1
register: healthcheck_6
- name: healthcheck (string in healthcheck test, changed)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
healthcheck:
test: "sleep 1"
stop_timeout: 1
register: healthcheck_7
- name: healthcheck (string in healthcheck test, idempotency)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
healthcheck:
test: "sleep 1"
stop_timeout: 1
register: healthcheck_8
- name: cleanup
docker_container:
name: "{{ cname }}"
state: absent
stop_timeout: 1
- assert:
that:
- healthcheck_1 is changed
- healthcheck_2 is not changed
- healthcheck_3 is changed
- healthcheck_4 is not changed
- healthcheck_5 is changed
- healthcheck_6 is not changed
- healthcheck_7 is changed
- healthcheck_8 is not changed
####################################################################
## hostname ########################################################
####################################################################