Fix: set correct exit status when parsing openstack port objects 58/70858/3
authorMatthew Watkins <mwatkins@linuxfoundation.org>
Thu, 13 Oct 2022 13:24:40 +0000 (14:24 +0100)
committerMatthew Watkins <mwatkins@linuxfoundation.org>
Thu, 13 Oct 2022 13:55:44 +0000 (14:55 +0100)
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 <mwatkins@linuxfoundation.org>
Change-Id: I7cb6465076817d2699970f450c2d7c8c3bda6c31

releasenotes/notes/fix-os-objects-exit-status-97d6a6c4a6cb1f6c.yaml [new file with mode: 0644]
shell/openstack-cleanup-orphaned-objects.sh
shell/openstack-cleanup-orphaned-ports.sh

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 (file)
index 0000000..563c009
--- /dev/null
@@ -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.
index 3a3dbc2..6d845b7 100755 (executable)
@@ -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"
index 8549737..b5c0af5 100755 (executable)
@@ -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}')