From 49de1f1c7c16cc6f7319e32168ae970f43514b2d Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 5 Nov 2018 12:34:23 +0100 Subject: [PATCH] Improve paused test and behavior. (#48056) (cherry picked from commit 569ec812e7a163a664eca2ba73b0f6fa67f895c5) --- .../modules/cloud/docker/docker_container.py | 1 + .../docker_container/tasks/tests/options.yml | 28 ++++++------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/ansible/modules/cloud/docker/docker_container.py b/lib/ansible/modules/cloud/docker/docker_container.py index 162d9d34258..56398078812 100644 --- a/lib/ansible/modules/cloud/docker/docker_container.py +++ b/lib/ansible/modules/cloud/docker/docker_container.py @@ -1870,6 +1870,7 @@ class ContainerManager(DockerBaseClass): self.fail("Error %s container %s: %s" % ( "pausing" if self.parameters.paused else "unpausing", container.Id, str(exc) )) + container = self._get_container(container.Id) self.results['changed'] = True self.results['actions'].append(dict(set_paused=self.parameters.paused)) diff --git a/test/integration/targets/docker_container/tasks/tests/options.yml b/test/integration/targets/docker_container/tasks/tests/options.yml index a8bad442004..1272d5c6eee 100644 --- a/test/integration/targets/docker_container/tasks/tests/options.yml +++ b/test/integration/targets/docker_container/tasks/tests/options.yml @@ -2238,24 +2238,21 @@ - name: paused docker_container: image: alpine:3.8 - command: "/bin/sh -c 'sleep 1s ; yes'" + command: "/bin/sh -c 'sleep 10m'" name: "{{ cname }}" state: started paused: yes stop_timeout: 1 register: paused_1 -- pause: - seconds: 2 - -- name: paused (logs) - command: docker logs --tail=20 "{{ cname }}" +- name: inspect paused + command: "docker inspect -f {% raw %}'{{.State.Status}} {{.State.Paused}}'{% endraw %} {{ cname }}" register: paused_2 - name: paused (idempotent) docker_container: image: alpine:3.8 - command: "/bin/sh -c 'sleep 1s ; yes'" + command: "/bin/sh -c 'sleep 10m'" name: "{{ cname }}" state: started paused: yes @@ -2272,17 +2269,8 @@ stop_timeout: 1 register: paused_4 -- pause: - seconds: 2 - -- name: paused (stop) - docker_container: - name: "{{ cname }}" - state: stopped - stop_timeout: 1 - -- name: paused (logs) - command: docker logs --tail=20 "{{ cname }}" +- name: inspect paused + command: "docker inspect -f {% raw %}'{{.State.Status}} {{.State.Paused}}'{% endraw %} {{ cname }}" register: paused_5 - name: cleanup @@ -2294,10 +2282,10 @@ - assert: that: - paused_1 is changed - - paused_2.stdout_lines | length == 0 + - 'paused_2.stdout == "paused true"' - paused_3 is not changed - paused_4 is changed - - paused_5.stdout_lines | length > 0 + - 'paused_5.stdout == "running false"' #################################################################### ## pid_mode ########################################################