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

Change-Id: I958e14c0a4ea4b5782d2c74dc895471b0f70b875
This commit is contained in:
Sergii Golovatiuk 2018-06-05 11:42:21 +02:00
parent e3d6a47a31
commit 9a37e5ac42

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