From: Matthew Watkins Date: Thu, 13 Oct 2022 13:24:40 +0000 (+0100) Subject: Fix: set correct exit status when parsing openstack port objects X-Git-Tag: v0.82.1~1 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?p=releng%2Fglobal-jjb.git;a=commitdiff_plain;h=ce1354cc83932ef7ff52b401137aada7a7a8de75 Fix: set correct exit status when parsing openstack port objects Addresses a bug with the exit status of the orphaned ports script. Mirrors the same fix to the equivalent generic objects script. Issue: RELENG-4483 Signed-off-by: Matthew Watkins Change-Id: I7cb6465076817d2699970f450c2d7c8c3bda6c31 --- diff --git a/releasenotes/notes/fix-os-objects-exit-status-97d6a6c4a6cb1f6c.yaml b/releasenotes/notes/fix-os-objects-exit-status-97d6a6c4a6cb1f6c.yaml new file mode 100644 index 00000000..563c0095 --- /dev/null +++ b/releasenotes/notes/fix-os-objects-exit-status-97d6a6c4a6cb1f6c.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Addresses a bug whereby the openstack orphaned objects/ports scripts + exit early with an error when grep/awk do not match any orphaned + objects. The fix allows jobs using the scripts to continue when no + cleanups operations are required. diff --git a/shell/openstack-cleanup-orphaned-objects.sh b/shell/openstack-cleanup-orphaned-objects.sh index 3a3dbc20..6d845b76 100755 --- a/shell/openstack-cleanup-orphaned-objects.sh +++ b/shell/openstack-cleanup-orphaned-objects.sh @@ -74,11 +74,11 @@ _cleanup() if [[ -n ${filters} ]]; then # If a filter/match condition is requested/set openstack --os-cloud "$os_cloud" "${object}" list -f value -c ID $attributes \ - | $filters | awk '{print $1}'> "$tmpfile" + | { $filters || true; } | { awk '{print $1}' || true; } > "$tmpfile" else # Otherwise don't pipe through an additional command openstack --os-cloud "$os_cloud" "${object}" list -f value -c ID $attributes \ - | awk '{print $1}'> "$tmpfile" + | { awk '{print $1}' || true; } > "$tmpfile" fi # Count the number of objects to process @@ -89,7 +89,7 @@ echo "Using $threads parallel processes..." # Export variables and send to parallel for processing export -f _cleanup export os_cloud cutoff age object -# parallel --progress --retries 3 -j "$threads" _cleanup < "$tmpfile" +# Add --progress flag to the command below for additional debug output parallel --retries 3 -j "$threads" _cleanup < "$tmpfile" rm "$tmpfile" diff --git a/shell/openstack-cleanup-orphaned-ports.sh b/shell/openstack-cleanup-orphaned-ports.sh index 8549737b..b5c0af52 100755 --- a/shell/openstack-cleanup-orphaned-ports.sh +++ b/shell/openstack-cleanup-orphaned-ports.sh @@ -55,7 +55,8 @@ _cleanup() } # Output the initial list of port UUIDs to a temporary file -openstack --os-cloud "$os_cloud" port list -f value -c ID -c status | grep -e DOWN | awk '{print $1}'> "$tmpfile" +openstack --os-cloud "$os_cloud" port list -f value -c ID -c status \ + | { grep -e DOWN || true; } | { awk '{print $1}' || true; } > "$tmpfile" # Count the number to process total=$(wc -l "$tmpfile" | awk '{print $1}')