docker_container: use restart() API function instead of stop/start sequence (#55894)

* Improve container restart.

* Adjust tests.

* Add changelog.

* Quote options.

* Move tests for restart/recreate options to start/stop tests.

* Fix changelog name.
This commit is contained in:
Felix Fontein
2019-05-03 17:30:39 +02:00
committed by ansibot
parent 93f0112953
commit 95d1564f70
4 changed files with 138 additions and 112 deletions

View File

@@ -2776,8 +2776,8 @@ avoid such warnings, please quote the value.' in log_options_2.warnings"
name: "{{ cname }}"
state: started
published_ports:
- 9001
- 9002
- '9001'
- '9002'
register: published_ports_1
- name: published_ports (idempotency)
@@ -2787,8 +2787,8 @@ avoid such warnings, please quote the value.' in log_options_2.warnings"
name: "{{ cname }}"
state: started
published_ports:
- 9002
- 9001
- '9002'
- '9001'
register: published_ports_2
- name: published_ports (less published_ports)
@@ -2798,7 +2798,7 @@ avoid such warnings, please quote the value.' in log_options_2.warnings"
name: "{{ cname }}"
state: started
published_ports:
- 9002
- '9002'
register: published_ports_3
- name: published_ports (more published_ports)
@@ -2808,8 +2808,8 @@ avoid such warnings, please quote the value.' in log_options_2.warnings"
name: "{{ cname }}"
state: started
published_ports:
- 9002
- 9003
- '9002'
- '9003'
force_kill: yes
register: published_ports_4
@@ -2878,109 +2878,6 @@ avoid such warnings, please quote the value.' in log_options_2.warnings"
- read_only_2 is not changed
- read_only_3 is changed
####################################################################
## recreate ########################################################
####################################################################
- name: recreate (created)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: present
force_kill: yes
register: recreate_1
- name: recreate (created, recreate)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
recreate: yes
state: present
force_kill: yes
register: recreate_2
- name: recreate (started)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
force_kill: yes
register: recreate_3
- name: recreate (started, recreate)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
recreate: yes
state: started
force_kill: yes
register: recreate_4
- name: cleanup
docker_container:
name: "{{ cname }}"
state: absent
force_kill: yes
diff: no
- debug: var=recreate_1
- debug: var=recreate_2
- debug: var=recreate_3
- debug: var=recreate_4
- assert:
that:
- recreate_1 is changed
- recreate_2 is changed
- recreate_3 is changed
- recreate_4 is changed
- recreate_1.container.Id != recreate_2.container.Id
- recreate_2.container.Id == recreate_3.container.Id
- recreate_3.container.Id != recreate_4.container.Id
####################################################################
## restart #########################################################
####################################################################
- name: restart
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
force_kill: yes
register: restart_1
- name: restart (restart)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
restart: yes
state: started
force_kill: yes
register: restart_2
- name: cleanup
docker_container:
name: "{{ cname }}"
state: absent
force_kill: yes
diff: no
- debug: var=restart_1
- debug: var=restart_2
- assert:
that:
- restart_1 is changed
- restart_2 is changed
- restart_1.container.Id == restart_2.container.Id
####################################################################
## restart_policy ##################################################
####################################################################

View File

@@ -169,6 +169,120 @@
- start_scratch_3 is not changed
- start_scratch_4 is not changed
####################################################################
## Recreating ######################################################
####################################################################
- name: Recreating container (created)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: present
force_kill: yes
register: recreate_1
- name: Recreating container (created, recreate)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
recreate: yes
state: present
force_kill: yes
register: recreate_2
- name: Recreating container (started)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
force_kill: yes
register: recreate_3
- name: Recreating container (started, recreate)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
recreate: yes
state: started
force_kill: yes
register: recreate_4
- name: cleanup
docker_container:
name: "{{ cname }}"
state: absent
force_kill: yes
diff: no
- debug: var=recreate_1
- debug: var=recreate_2
- debug: var=recreate_3
- debug: var=recreate_4
- assert:
that:
- recreate_2 is changed
- recreate_3 is changed
- recreate_4 is changed
- recreate_1.container.Id != recreate_2.container.Id
- recreate_2.container.Id == recreate_3.container.Id
- recreate_3.container.Id != recreate_4.container.Id
####################################################################
## Restarting ######################################################
####################################################################
- name: Restarting
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
stop_timeout: 1
volumes:
- /tmp/tmp
register: restart_1
- name: Restarting (restart)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
restart: yes
state: started
stop_timeout: 1
force_kill: yes
register: restart_2
- name: Restarting (verify volumes)
docker_container:
image: alpine:3.8
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
stop_timeout: 1
volumes:
- /tmp/tmp
register: restart_3
- name: cleanup
docker_container:
name: "{{ cname }}"
state: absent
force_kill: yes
diff: no
- assert:
that:
- restart_1 is changed
- restart_2 is changed
- restart_1.container.Id == restart_2.container.Id
- restart_3 is not changed
####################################################################
## Stopping ########################################################
####################################################################