Make the minor update for docker idempotent

Via Ic08468854ce92e81cd84bd6c86a6b672b5a9d49b we fixed the problem of
docker being restarted when puppet triggers a change while pacemaker is
up and running. That approach, while more correct than what existed
previously, is still suboptimal because we are stopping all docker
containers even though we don't have to.

Let's detect if applying the profile::base::docker manifest would
introduce any changes and also detect if the docker rpm is going to be
updated. If one of the two conditions is true we need to stop
containers.

This way rerunning the update workflow on a node should be much less
disruptive. Tested this and correctly observed that the first run did
correctly stopped the docker containers whereas subsequent runs did not
stop containers.

Change-Id: I9176da730b0156d06e2a1ef5f2fcc061e2a6abf6
Related-Bug: #1747851
This commit is contained in:
Michele Baldessari 2018-02-23 12:17:21 +01:00
parent f7d076fd7c
commit dd9b008c11
1 changed files with 22 additions and 0 deletions

View File

@ -103,16 +103,38 @@ outputs:
yum: name=docker state=latest yum: name=docker state=latest
update_tasks: update_tasks:
block: block:
- name: Detect if puppet on the docker profile would restart the service
# Note that due to https://tickets.puppetlabs.com/browse/PUP-686 --noop
# always exits 0, so we cannot rely on that to detect if puppet is going to change stuff
shell: |
puppet apply --noop --summarize --detailed-exitcodes --verbose \
--modulepath /etc/puppet/modules:/opt/stack/puppet-modules:/usr/share/openstack-puppet/modules \
--color=false -e "class { 'tripleo::profile::base::docker': step => 1, }" 2>&1 | \
awk -F ":" '/Out of sync:/ { print $2}'
register: puppet_docker_noop_output
failed_when: false
- name: Is docker going to be updated
shell: yum check-update docker
register: docker_check_update
failed_when: docker_check_update.rc not in [0, 100]
changed_when: docker_check_update.rc == 100
- name: Set docker_rpm_needs_update fact
set_fact: docker_rpm_needs_update={{ docker_check_update.rc == 100 }}
- name: Set puppet_docker_is_outofsync fact
set_fact: puppet_docker_is_outofsync={{ puppet_docker_noop_output.stdout|trim|int >= 1 }}
- name: Stop all containers - name: Stop all containers
# xargs is preferable to docker stop $(docker ps -q) as that might generate a # xargs is preferable to docker stop $(docker ps -q) as that might generate a
# a too long command line # a too long command line
shell: docker ps -q | xargs --no-run-if-empty -n1 docker stop shell: docker ps -q | xargs --no-run-if-empty -n1 docker stop
when: puppet_docker_is_outofsync or docker_rpm_needs_update
- name: Stop docker - name: Stop docker
service: service:
name: docker name: docker
state: stopped state: stopped
when: puppet_docker_is_outofsync or docker_rpm_needs_update
- name: Update the docker package - name: Update the docker package
yum: name=docker state=latest update_cache=yes # cache for tripleo/+bug/1703830 yum: name=docker state=latest update_cache=yes # cache for tripleo/+bug/1703830
when: docker_rpm_needs_update
- name: Apply puppet which will start the service again - name: Apply puppet which will start the service again
shell: | shell: |
puppet apply --detailed-exitcodes --verbose \ puppet apply --detailed-exitcodes --verbose \