Properly parse and quote arguments in upgrade script

This patch fixes the following:

1. Properly quote arguments to run_lock function
2. Properly parse out the playbook filename in run_lock

Specifically the upgrade steps where we were using

   "-e 'rabbitmq_upgrade=true' setup-infrastructure.yml"
   "/tmp/fix_container_interfaces.yml || true"

Were causing issues and this patch resolves them.

Closes-bug: 1479916
Change-Id: I809085d6da493f7f7d545547a0d984c0e7b1bf45
(cherry picked from commit 560fbbdb07)
This commit is contained in:
Ian Cordasco 2015-07-30 21:03:23 -05:00 committed by Jesse Pretorius
parent d82bbb4336
commit ef3e743113

View File

@ -59,11 +59,28 @@ function remove_inv_items(){
function run_lock() {
set +e
run_item="${RUN_TASKS[$1]}"
upgrade_marker_file=$(basename $run_item .yml)
file_part="${run_item}"
# NOTE(sigmavirus24): This handles tasks like:
# "-e 'rabbitmq_upgrade=true' setup-infrastructure.yml"
# "/tmp/fix_container_interfaces.yml || true"
# So we can get the appropriate basename for the upgrade_marker
for part in $run_item; do
if [[ "$part" == *.yml ]];then
file_part="$part"
break
fi
done
upgrade_marker_file=$(basename ${file_part} .yml)
upgrade_marker="/etc/openstack_deploy/upgrade-juno/$upgrade_marker_file.complete"
if [ ! -f "$upgrade_marker" ];then
openstack-ansible "$2"
# NOTE(sigmavirus24): Use eval so that we properly turn strings like
# "/tmp/fix_container_interfaces.yml || true"
# Into a command, otherwise we'll get an error that there's no playbook
# named ||
eval "openstack-ansible $2"
echo "ran $run_item"
if [ "$?" == "0" ];then
@ -631,6 +648,6 @@ pushd playbooks
# Run the tasks in order
for item in ${!RUN_TASKS[@]}; do
run_lock $item ${RUN_TASKS[$item]}
run_lock $item "${RUN_TASKS[$item]}"
done
popd