From 0c66e6ab1d80770ca7060237b436190f9fa274a0 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Wed, 12 Aug 2020 15:07:32 -0400 Subject: [PATCH] Revert "Minor cleanup of openstack-protect script" The "Minor cleanup" ended up breaking the script entirely as the image list array is not correctly created causing invalid image name to be passed to the openstack command. Also adds some code to strip double quotes from the prefix and suffix if there are any. This reverts commit b03a1792362654ad8fcd15092a64ed00f8509209. Change-Id: Id4f734113d6dede7e7603f85784b46d164b91392 Co-authored-by: Aric Gardner Signed-off-by: Thanh Ha --- shell/openstack-protect-in-use-images.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/shell/openstack-protect-in-use-images.sh b/shell/openstack-protect-in-use-images.sh index 08727f61..a422cd87 100644 --- a/shell/openstack-protect-in-use-images.sh +++ b/shell/openstack-protect-in-use-images.sh @@ -21,17 +21,18 @@ os_cloud="${OS_CLOUD:-vex}" set -eu -o pipefail -conf_images=("$(grep -r IMAGE_NAME --include \*.cfg jenkins-config \ - | awk -F'=' '{print $2}' | sort -u)") -# If there are no yaml files the 'grep' will fail, which is OK -yaml_images=("$(grep -r 'ZZCI - ' --include \*.yaml jjb \ - | awk -F": " '{print $3}' | sed "s:'::;s:'$::;/^$/d" \ - | sort -u)") || true -readarray -t images <<< "$(for i in "${conf_images[@]}" "${yaml_images[@]}"; do \ - echo "$i"; done | sort)" +declare -a images +images+=("$(grep -r IMAGE_NAME --include \*.cfg jenkins-config \ + | awk -F'=' '{print $2}' | sort -u)") +set +o pipefail # Not all projects have images in YAML files and grep returns non-zero on 0 results +# Ignore SC2179 since we do not want () to result in an empty array item. +#shellcheck disable=SC2179 +images+=("$(grep -r 'ZZCI - ' --include \*.yaml jjb \ + | awk -F": " '{print $3}' | sed -e "s:'::;s:'$::;/^$/d" -e 's/^"//' -e 's/"$//' | sort -u)") +set -o pipefail +readarray -t images <<< "$(for i in "${images[@]}"; do echo "$i"; done | sort -u)" for image in "${images[@]}"; do - [[ -z $image ]] && continue os_image_protected=$(openstack --os-cloud "$os_cloud" \ image show "$image" -f value -c protected) echo "Protected setting for $image: $os_image_protected" -- 2.16.6