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
This commit is contained in:
Sergii Golovatiuk 2018-06-05 11:42:21 +02:00
parent 3570a94a69
commit 1dfc4ff7e6
1 changed files with 3 additions and 3 deletions

View File

@ -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