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 <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2017-11-28 19:31:10 -06:00
parent 299213ba23
commit ff3441c90a
No known key found for this signature in database
GPG Key ID: 9443251A787B9FB3
2 changed files with 17 additions and 4 deletions

View File

@ -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.

View File

@ -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