From 1dfc4ff7e6852db4bfb4a7c7ec4473e0c916a3a4 Mon Sep 17 00:00:00 2001 From: Sergii Golovatiuk Date: Tue, 5 Jun 2018 11:42:21 +0200 Subject: [PATCH] Fix fail_if_empty invocation with pipes * Since $@ parameter may have pipe '|' it should be processed correctly. Currenly the part before pipe is assigned as $@ so bash runs pipe with commands after it after execution of function. However, we want to assign command with pipe to $@ thus "" around command with pipe are required. * replace $() with eval as $() doesn't work correctly with pipe as it tries to escape pipe so output variable contains wrong data. * This patch adds tonumber to first invocation (cherry picked from commit I958e14c0a4ea4b5782d2c74dc895471b0f70b875) Change-Id: I681421573c1b04d2ddc1d80c7afe4780abcd4b26 --- deployed-server/scripts/get-occ-config.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deployed-server/scripts/get-occ-config.sh b/deployed-server/scripts/get-occ-config.sh index 77c6d71f57..634889600d 100755 --- a/deployed-server/scripts/get-occ-config.sh +++ b/deployed-server/scripts/get-occ-config.sh @@ -59,7 +59,7 @@ function with_backoff { # Return 1 if empty output received ####################################### function fail_if_empty { - local output="$(${@})" + local output="$(eval "${@}")" if [ -z "${output}" ]; then echo "Warning! Empty output for ($@)" 1>&2 return 1 @@ -103,10 +103,10 @@ for role in $OVERCLOUD_ROLES; do rg_stack=$(with_backoff fail_if_empty openstack stack resource show $STACK_NAME $role -c physical_resource_id -f value) done - stacks=$(with_backoff fail_if_empty openstack stack resource list $rg_stack -c resource_name -c physical_resource_id -f json | jq -r "sort_by(.resource_name) | .[] | .physical_resource_id") + stacks=$(with_backoff fail_if_empty "openstack stack resource list $rg_stack -c resource_name -c physical_resource_id -f json | jq -r 'sort_by(.resource_name | tonumber ) | .[] | .physical_resource_id'") rc=${?} while [ ${rc} -ne 0 ]; do - stacks=$(with_backoff fail_if_empty openstack stack resource list $rg_stack -c resource_name -c physical_resource_id -f json | jq -r "sort_by(.resource_name | tonumber) | .[] | .physical_resource_id") + stacks=$(with_backoff fail_if_empty "openstack stack resource list $rg_stack -c resource_name -c physical_resource_id -f json | jq -r 'sort_by(.resource_name | tonumber) | .[] | .physical_resource_id'") done i=0