Function to apply workarounds

The workarounds can be either patches posted on review.openstack.org
 or arbitrary shell commands.
Below is an example of a workarounds:

---
pre_undercloud_upgrade_workaround:
  - BZ#xxxxxyz:
     patch: false
     basedir: ''
     id: ''
     command: 'touch /home/stack/pre_workaround_applied'
post_undercloud_deploy_workarounds:
  - BZ#xxxyyzz:
     patch: true
     basedir: '/usr/share/openstack-tripleo-heat-templates/'
     id: 'xxxyyzz'
     command: ''

Change-Id: Id33c6d9c043433b395d4a4905a36820a18604860
(cherry picked from commit ed4cdcc948)
(cherry picked from commit 19c195ed66)
This commit is contained in:
Yurii Prokulevych 2018-10-22 16:30:53 +02:00 committed by Lukas Bezdicka
parent 0ff0c7e9c4
commit 84457754a9
1 changed files with 37 additions and 18 deletions

View File

@ -3,14 +3,39 @@
# Apply upgrade workarounds
set -euo pipefail
function apply_patch {
local patch_dir=$1
local patch_id=$2
local temp_dir=''
temp_dir=$( mktemp -d )
curl -4 --retry 5 https://review.openstack.org/changes/${patch_id}/revisions/current/patch?download | \
base64 -d > ${temp_dir}/patch.txt
if [[ ${?} -ne 0 ]] ; then
echo "Failed to download patch https://review.openstack.org/#/c/${patch_id}/"
exit 1
fi
if sudo patch --dry-run --reverse --force -d ${patch_dir} -p1 < ${temp_dir}/patch.txt >/dev/null 2>&1
then
echo "Patch ${patch_id} already applied, skipping"
else
sudo patch -Ns -d ${patch_dir} -p1 < ${temp_dir}/patch.txt
fi
sudo rm -Rf ${temp_dir}
}
{% if 'pre_undercloud_upgrade_workarounds' in item %}
{% for bugs in pre_undercloud_upgrade_workarounds|default([]) %}
{% for key, value in bugs.items() %}
echo {{ key }}
{% if value.patch %}
curl -4 https://review.openstack.org/changes/{{ value.id }}/revisions/current/patch?download | \
base64 -d | \
sudo patch -d {{ value.basedir }} -p1
apply_patch {{ value.basedir }} {{ value.id }}
{% else %}
{{ value.command }}
@ -24,9 +49,8 @@ curl -4 https://review.openstack.org/changes/{{ value.id }}/revisions/current/pa
{% for key, value in bugs.items() %}
echo {{ key }}
{% if value.patch %}
curl -4 https://review.openstack.org/changes/{{ value.id }}/revisions/current/patch?download | \
base64 -d | \
sudo patch -d {{ value.basedir }} -p1
apply_patch {{ value.basedir }} {{ value.id }}
{% else %}
{{ value.command }}
@ -40,9 +64,7 @@ curl -4 https://review.openstack.org/changes/{{ value.id }}/revisions/current/pa
{% for key, value in bugs.items() %}
echo {{ key }}
{% if value.patch %}
curl -4 https://review.openstack.org/changes/{{ value.id }}/revisions/current/patch?download | \
base64 -d | \
sudo patch -d {{ value.basedir }} -p1
apply_patch {{ value.basedir }} {{ value.id }}
{% else %}
{{ value.command }}
@ -56,9 +78,8 @@ curl -4 https://review.openstack.org/changes/{{ value.id }}/revisions/current/pa
{% for key, value in bugs.items() %}
echo {{ key }}
{% if value.patch %}
curl -4 https://review.openstack.org/changes/{{ value.id }}/revisions/current/patch?download | \
base64 -d | \
sudo patch -d {{ value.basedir }} -p1
apply_patch {{ value.basedir }} {{ value.id }}
{% else %}
{{ value.command }}
@ -72,9 +93,8 @@ curl -4 https://review.openstack.org/changes/{{ value.id }}/revisions/current/pa
{% for key, value in bugs.items() %}
echo {{ key }}
{% if value.patch %}
curl -4 https://review.openstack.org/changes/{{ value.id }}/revisions/current/patch?download | \
base64 -d | \
sudo patch -d {{ value.basedir }} -p1
apply_patch {{ value.basedir }} {{ value.id }}
{% else %}
{{ value.command }}
@ -88,9 +108,8 @@ curl -4 https://review.openstack.org/changes/{{ value.id }}/revisions/current/pa
{% for key, value in bugs.items() %}
echo {{ key }}
{% if value.patch %}
curl -4 https://review.openstack.org/changes/{{ value.id }}/revisions/current/patch?download | \
base64 -d | \
sudo patch -d {{ value.basedir }} -p1
apply_patch {{ value.basedir }} {{ value.id }}
{% else %}
{{ value.command }}