255 lines
11 KiB
Django/Jinja
255 lines
11 KiB
Django/Jinja
#!/bin/bash
|
|
#
|
|
# Apply upgrade workarounds
|
|
# These arguments are only used when the workaround contains
|
|
# the ansible_hosts option.
|
|
# Args:
|
|
# -l|--limit: Host to be passed in the --limit option when
|
|
# calling ansible-playbook. If not argument passed
|
|
# no --limit will be used = --limit all.
|
|
# -u|--ssh-ansible-user: User to be passed when creating the
|
|
# tripleo-inventory. Defaults to heat-admin.
|
|
|
|
set -euo pipefail
|
|
|
|
function usage {
|
|
echo "Usage: ${0} [ [-l|--limit <ansible_host_to_limit>] [-u|--ssh-ansible-user <ansible_ssh_user_for_inventory>]]"
|
|
}
|
|
|
|
|
|
function apply_patch {
|
|
local patch_dir=$1
|
|
local patch_id=$2
|
|
local patch_revision=$3
|
|
local patch_strip=$4
|
|
local gerrit_url=$5
|
|
local temp_dir=''
|
|
|
|
temp_dir=$( mktemp -d )
|
|
|
|
curl -4sSL --retry 10 ${gerrit_url}/changes/${patch_id}/revisions/${patch_revision}/patch?download | \
|
|
base64 -d > ${temp_dir}/patch.txt
|
|
|
|
if filterdiff -x "*/tests/*" < ${temp_dir}/patch.txt | sudo patch --dry-run --force -d ${patch_dir} -p${patch_strip} 2>&1
|
|
then
|
|
filterdiff -x "*/tests/*" < ${temp_dir}/patch.txt | sudo patch -Ns -d ${patch_dir} -p${patch_strip}
|
|
else
|
|
echo "Patch ${patch_id} fails to apply - either already applied or you need to fix it."
|
|
fi
|
|
|
|
sudo rm -Rf ${temp_dir}
|
|
|
|
}
|
|
|
|
# Applies a patch into overcloud containers with Container Image Preparation.
|
|
function overcloud_container_apply_patch {
|
|
local bz_key=$1
|
|
local scripts=$2
|
|
PARAMS_FILE=$HOME/containers_workarounds/${bz_key}-params.yaml
|
|
IFS=',' read -ra SCRIPTS <<< "$scripts"
|
|
sudo openstack tripleo container image prepare -e $HOME/containers_workarounds/${bz_key}.yaml \
|
|
--output-env-file $PARAMS_FILE
|
|
for i in "${SCRIPTS[@]}"; do
|
|
cat /home/stack/$i | \
|
|
sed -e 's,2>&1,-e '${PARAMS_FILE}' \\\n 2>\&1,' \
|
|
> /home/stack/${i}.new.sh
|
|
cp "/home/stack/${i}"{,.original.sh}
|
|
cat "/home/stack/${i}".new.sh > "/home/stack/${i}"
|
|
done
|
|
}
|
|
|
|
# Applies a patch into undercloud containers with Container Image Preparation.
|
|
function undercloud_container_apply_patch {
|
|
local bz_key=$1
|
|
local undercloud_conf=$HOME/undercloud.conf
|
|
PARAMS_FILE=$HOME/containers_workarounds/${bz_key}-params.yaml
|
|
sudo openstack tripleo container image prepare -e $HOME/containers_workarounds/${bz_key}.yaml --output-env-file $PARAMS_FILE
|
|
cat $undercloud_conf | \
|
|
sed "\|custom_env_files|s|$|,$PARAMS_FILE|" \
|
|
> ${undercloud_conf}.new.sh
|
|
cp "${undercloud_conf}"{,.original.sh}
|
|
cat "${undercloud_conf}".new.sh > "${undercloud_conf}"
|
|
}
|
|
|
|
function ansible_patch {
|
|
local ansible_filename=$1
|
|
local ansible_limit=""
|
|
local ansible_ssh_user="heat-admin"
|
|
local overcloud_stack_name="overcloud"
|
|
local ansible_dir=$HOME/ansible_workarounds
|
|
|
|
if [ ! -z $LIMIT ]
|
|
then
|
|
ansible_limit="--limit ${LIMIT}"
|
|
fi
|
|
if [ ! -z $ANSIBLE_SSH_USER ]
|
|
then
|
|
ansible_ssh_user=$ANSIBLE_SSH_USER
|
|
fi
|
|
if [ -n "${OVERCLOUD_STACK_NAME}" ];
|
|
then
|
|
overcloud_stack_name="${OVERCLOUD_STACK_NAME}"
|
|
fi
|
|
inventory_file=$HOME/overcloud-deploy/${overcloud_stack_name}/config-download/${overcloud_stack_name}/tripleo-ansible-inventory.yaml
|
|
|
|
# Run ansible playbook
|
|
ansible-playbook -v -i ${inventory_file} --become --become-user root ${ansible_dir}/${ansible_filename}.yaml ${ansible_limit}
|
|
|
|
}
|
|
|
|
# Global vars
|
|
LIMIT=""
|
|
ANSIBLE_SSH_USER=""
|
|
OVERCLOUD_STACK_NAME="{{ overcloud_stack_name }}"
|
|
|
|
while [[ $# -gt 0 ]]
|
|
do
|
|
key="$1"
|
|
|
|
case $key in
|
|
-l|--limit)
|
|
LIMIT="$2"
|
|
shift # past argument
|
|
shift # past value
|
|
;;
|
|
-u|--ssh-ansible-user)
|
|
ANSIBLE_SSH_USER="$2"
|
|
shift # past argument
|
|
shift # past value
|
|
;;
|
|
-o|--overcloud-stack-name)
|
|
OVERCLOUD_STACK_NAME="$2"
|
|
shift # past argument
|
|
shift # past value
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
exit 1
|
|
;;
|
|
*)
|
|
usage
|
|
exit 1 # unknown option
|
|
;;
|
|
esac
|
|
done
|
|
|
|
{% macro render_workarounds(workaround_var, workaround_name) -%}
|
|
{% if workaround_name in item -%}
|
|
{% for bugs in workaround_var -%}
|
|
{% for key, value in bugs.items() -%}
|
|
echo {{ key }}
|
|
{% if value.patch -%}
|
|
{% set _patch_revision = value.patch_revision | default('current', True) -%}
|
|
{% set _patch_strip = value.patch_strip | default(1, True) -%}
|
|
{% set _gerrit_url = value.gerrit_url | default('https://review.opendev.org', True) -%}
|
|
apply_patch {{ value.basedir }} {{ value.id }} {{ _patch_revision }} {{ _patch_strip }} {{ _gerrit_url }}
|
|
{% elif value.containers is defined and value.containers == true -%}
|
|
{{ value.preparation_commands }}
|
|
[ -d $HOME/containers_workarounds ] || mkdir $HOME/containers_workarounds
|
|
cat << EOF | cat $HOME/containers-prepare-parameter.yaml - > "$HOME/containers_workarounds/{{ key }}.yaml"
|
|
{{ value.containers_file_modifications | to_nice_yaml | indent(width=4, first=True) }}
|
|
EOF
|
|
{% if value.environment|lower == 'overcloud' -%}
|
|
overcloud_container_apply_patch {{ key }} {{ value.deploy_scripts }}
|
|
{% elif value.environment|lower == 'undercloud' -%}
|
|
undercloud_container_apply_patch {{ key }}
|
|
{% endif -%}
|
|
{% elif value.ansible_hosts is defined and value.ansible_hosts != '' -%}
|
|
|
|
[ -d $HOME/ansible_workarounds ] || mkdir $HOME/ansible_workarounds
|
|
|
|
cat <<'EOF' > "$HOME/ansible_workarounds/{{ key }}.yaml"
|
|
- hosts: {{ value.ansible_hosts }}
|
|
tasks:
|
|
- name: {{key}} workaround
|
|
shell: |
|
|
{{ value.command | indent(width=8) }}
|
|
EOF
|
|
|
|
ansible_patch {{ key }}
|
|
{% else -%}
|
|
{{ value.command }}
|
|
{% endif -%}
|
|
################################################################################
|
|
{% endfor -%}
|
|
{% endfor -%}
|
|
{% endif -%}
|
|
{% endmacro -%}
|
|
|
|
{% if upgrade_workarounds|bool -%}
|
|
# Render for Upgrades
|
|
{{ render_workarounds(pre_undercloud_os_upgrade_workarounds|default([]),'pre_undercloud_os_upgrade_workarounds') }}
|
|
{# finish pre_undercloud_os_upgrade_workarounds #}
|
|
{{ render_workarounds(pre_undercloud_upgrade_workarounds|default([]),'pre_undercloud_upgrade_workarounds') }}
|
|
{# finish pre_undercloud_upgrade_workarounds #}
|
|
{{ render_workarounds(post_undercloud_upgrade_workarounds|default([]),'post_undercloud_upgrade_workarounds') }}
|
|
{# finish post_undercloud_upgrade_workarounds #}
|
|
{{ render_workarounds(pre_overcloud_upgrade_prepare_workarounds|default([]),'pre_overcloud_upgrade_prepare_workarounds') }}
|
|
{# finish pre_overcloud_upgrade_prepare_workarounds #}
|
|
{{ render_workarounds(post_overcloud_upgrade_prepare_workarounds|default([]),'post_overcloud_upgrade_prepare_workarounds') }}
|
|
{# finish post_overcloud_upgrade_prepare_workarounds #}
|
|
{{ render_workarounds(pre_overcloud_system_upgrade_workarounds|default([]),'pre_overcloud_system_upgrade_workarounds') }}
|
|
{# finish pre_overcloud_system_upgrade_workarounds #}
|
|
{{ render_workarounds(post_overcloud_system_upgrade_workarounds|default([]),'post_overcloud_system_upgrade_workarounds') }}
|
|
{# finish post_overcloud_system_upgrade_workarounds #}
|
|
{{ render_workarounds(pre_overcloud_upgrade_workarounds|default([]),'pre_overcloud_upgrade_workarounds') }}
|
|
{# finish pre_overcloud_upgrade_workarounds #}
|
|
{{ render_workarounds(post_overcloud_upgrade_workarounds|default([]),'post_overcloud_upgrade_workarounds') }}
|
|
{# finish post_overcloud_upgrade_workarounds #}
|
|
{{ render_workarounds(pre_overcloud_upgrade_converge_workarounds|default([]),'pre_overcloud_upgrade_converge_workarounds') }}
|
|
{# finish pre_overcloud_upgrade_converge_workarounds #}
|
|
{{ render_workarounds(post_overcloud_upgrade_converge_workarounds|default([]),'post_overcloud_upgrade_converge_workarounds') }}
|
|
{# finish post_overcloud_upgrade_converge_workarounds #}
|
|
{{ render_workarounds(pre_ceph_upgrade_workarounds|default([]),'pre_ceph_upgrade_workarounds') }}
|
|
{# finish pre_ceph_upgrade_workarounds #}
|
|
{{ render_workarounds(post_ceph_upgrade_workarounds|default([]),'post_ceph_upgrade_workarounds') }}
|
|
{# finish post_ceph_upgrade_workarounds #}
|
|
{% endif -%}
|
|
|
|
{% if updates_workarounds|bool -%}
|
|
# Render for Updates
|
|
{{ render_workarounds(pre_undercloud_update_workarounds|default([]),'pre_undercloud_update_workarounds') }}
|
|
{# finish pre_undercloud_update_workarounds #}
|
|
{{ render_workarounds(post_undercloud_update_workarounds|default([]),'post_undercloud_update_workarounds') }}
|
|
{# finish post_undercloud_update_workarounds #}
|
|
{{ render_workarounds(pre_overcloud_update_prepare_workarounds|default([]),'pre_overcloud_update_prepare_workarounds') }}
|
|
{# finish pre_overcloud_update_prepare_workarounds #}
|
|
{{ render_workarounds(post_overcloud_update_prepare_workarounds|default([]),'post_overcloud_update_prepare_workarounds') }}
|
|
{# finish post_overcloud_update_prepare_workarounds #}
|
|
{{ render_workarounds(pre_overcloud_update_run_workarounds|default([]),'pre_overcloud_update_run_workarounds') }}
|
|
{# finish pre_overcloud_update_run_workarounds #}
|
|
{{ render_workarounds(post_overcloud_update_run_workarounds|default([]),'post_overcloud_update_run_workarounds') }}
|
|
{# finish post_overcloud_update_run_workarounds #}
|
|
{% endif -%}
|
|
|
|
{% if ffu_upgrade_workarounds|bool -%}
|
|
{{ render_workarounds(pre_ffu_undercloud_os_upgrade_workarounds|default([]),'pre_ffu_undercloud_os_upgrade_workarounds') }}
|
|
{# finish pre_ffu_undercloud_os_upgrade_workarounds #}
|
|
{{ render_workarounds(post_ffu_undercloud_os_upgrade_workarounds|default([]),'post_ffu_undercloud_os_upgrade_workarounds') }}
|
|
{# finish post_ffu_undercloud_os_upgrade_workarounds #}
|
|
{{ render_workarounds(pre_ffu_undercloud_upgrade_workarounds|default([]),'pre_ffu_undercloud_upgrade_workarounds') }}
|
|
{# finish pre_ffu_undercloud_upgrade_workarounds #}
|
|
{{ render_workarounds(post_ffu_undercloud_upgrade_workarounds|default([]),'post_ffu_undercloud_upgrade_workarounds') }}
|
|
{# finish post_ffu_undercloud_upgrade_workarounds #}
|
|
{{ render_workarounds(pre_ffu_overcloud_upgrade_prepare_workarounds|default([]),'pre_ffu_overcloud_upgrade_prepare_workarounds') }}
|
|
{# finish pre_ffu_overcloud_upgrade_prepare_workarounds #}
|
|
{{ render_workarounds(post_ffu_overcloud_upgrade_prepare_workarounds|default([]),'post_ffu_overcloud_upgrade_prepare_workarounds') }}
|
|
{# finish post_ffu_overcloud_upgrade_prepare_workarounds #}
|
|
{{ render_workarounds(pre_ffu_overcloud_os_upgrade_workarounds|default([]),'pre_ffu_overcloud_os_upgrade_workarounds') }}
|
|
{# finish pre_ffu_overcloud_os_upgrade_workarounds #}
|
|
{{ render_workarounds(post_ffu_overcloud_os_upgrade_workarounds|default([]),'post_ffu_overcloud_os_upgrade_workarounds') }}
|
|
{# finish post_ffu_overcloud_os_upgrade_workarounds #}
|
|
{{ render_workarounds(pre_ffu_overcloud_upgrade_workarounds|default([]),'pre_ffu_overcloud_upgrade_workarounds') }}
|
|
{# finish pre_ffu_overcloud_upgrade_workarounds #}
|
|
{{ render_workarounds(post_ffu_overcloud_upgrade_workarounds|default([]),'post_ffu_overcloud_upgrade_workarounds') }}
|
|
{# finish post_ffu_overcloud_upgrade_workarounds #}
|
|
{{ render_workarounds(pre_ffu_overcloud_converge_workarounds|default([]),'pre_ffu_overcloud_converge_workarounds') }}
|
|
{# finish pre_ffu_overcloud_converge_workarounds #}
|
|
{{ render_workarounds(post_ffu_overcloud_converge_workarounds|default([]),'post_ffu_overcloud_converge_workarounds') }}
|
|
{# finish post_ffu_overcloud_converge_workarounds #}
|
|
{{ render_workarounds(pre_ffu_overcloud_ceph_workarounds|default([]),'pre_ffu_overcloud_ceph_workarounds') }}
|
|
{# finish pre_ffu_overcloud_ceph_workarounds #}
|
|
{{ render_workarounds(post_ffu_overcloud_ceph_workarounds|default([]),'post_ffu_overcloud_ceph_workarounds') }}
|
|
{# finish post_ffu_overcloud_ceph_workarounds #}
|
|
{% endif -%}
|