From ff3441c90abbcb76a0f1b2fdf6d60b4ea0854cb2 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Tue, 28 Nov 2017 19:31:10 -0600 Subject: [PATCH] Fix container restart handler The handler would try and stop a container before restarting it however if the container was already stopped the handler would fail instead of simply moving on to the next task. This change makes the "stop" portion of the task detect the return status code of "2" when restarting the container. If the return code is "2" we know that the container is already stopped and that no change has occurred. For the sake of consistency and to ensure the greatest chance for success the test task that stops a container has also been given the same setup. Change-Id: Ia4856f36b2d106d987e3c774f31493e25a23d4b5 Signed-off-by: Kevin Carter --- handlers/main.yml | 8 ++++++-- tests/test-containers-functional.yml | 13 +++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 9f72a8e..53ad2dc 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -25,9 +25,13 @@ - Start Container delegate_to: "{{ physical_host }}" register: container_stop - until: container_stop | success + changed_when: true + failed_when: not container_stop.rc in [0, 2] + until: container_stop.rc in [0, 2] retries: 3 - when: lxc_container_allow_restarts | bool + delay: 2 + when: + - lxc_container_allow_restarts | bool # Due to https://github.com/ansible/ansible-modules-extras/issues/2691 # this uses the LXC CLI tools to ensure that we get logging. diff --git a/tests/test-containers-functional.yml b/tests/test-containers-functional.yml index 7fc5eb2..854fef2 100644 --- a/tests/test-containers-functional.yml +++ b/tests/test-containers-functional.yml @@ -134,11 +134,20 @@ tasks: - name: Stop container command: "lxc-stop -n container3" - changed_when: false + register: container_stop + changed_when: container_stop.rc == 0 + failed_when: not container_stop.rc in [0, 2] + until: container_stop.rc in [0, 2] + retries: 3 + delay: 2 - name: Start container command: "lxc-start -d -n container3" - changed_when: false + register: container_start + changed_when: container_start.rc == 0 + until: container_start | success + retries: 3 + delay: 2 - name: Check if the sysctl was well applied hosts: container3