X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=blobdiff_plain;f=shell%2Fopenstack-protect-in-use-images.sh;h=468ea0d8f2256f2f9215726fe1000c16fba11666;hb=a86c6e8d376c95aa00b179fce9d207e61c8f72d0;hp=4d9a2cc8badde81acab57ca7f7565b8b28685d69;hpb=0913c6350d626ce69174a05657988f753e6ea5ad;p=releng%2Fglobal-jjb.git diff --git a/shell/openstack-protect-in-use-images.sh b/shell/openstack-protect-in-use-images.sh index 4d9a2cc8..468ea0d8 100644 --- a/shell/openstack-protect-in-use-images.sh +++ b/shell/openstack-protect-in-use-images.sh @@ -15,21 +15,44 @@ # getting purged by the image cleanup script. # This script assumes images prefixed with the string "ZZCI - " are ci-managed # images. +set -eu -o pipefail echo "---> Protect in-use images" - os_cloud="${OS_CLOUD:-vex}" -set -eu -o pipefail +images=() +while read -r -d $'\n' ; do + images+=("$REPLY") +done < <(grep -r IMAGE_NAME --include \*.cfg jenkins-config \ + | awk -F'=' '{print $2}' \ + | sort -u) + +jjbimages=() +while read -r -d $'\n' ; do + jjbimages+=("$REPLY") +done < <(grep -r 'ZZCI - ' --include \*.yaml jjb \ + | awk -F": " '{print $3}' \ + | sed -e "s:'::;s:'$::;/^$/d" -e 's/^"//' -e 's/"$//' \ + | sort -u) -declare -a images -declare -a cfg_images -declare -a yaml_images -readarray -t cfg_images <<< "$(grep -r IMAGE_NAME --include \*.cfg jenkins-config \ - | awk -F'=' '{print $2}' | sort -u)" -readarray -t yaml_images <<< "$(grep -r 'ZZCI - ' --include \*.yaml jjb \ - | awk -F": " '{print $3}' | sed "s:'::;s:'$::;/^$/d" | sort -u)" -mapfile -t images < <(for R in "${cfg_images[@]}" "${yaml_images[@]}" ; do echo "$R" ; done | sort -u) +if ! [[ ${#images[@]} -eq 0 ]]; then + echo "INFO: There are images to protect defined in jenkins-config." +else + echo "ERROR: No images detected in the jenkins-config dir." + exit 1 +fi +if ! [[ ${#jjbimages[@]} -eq 0 ]]; then + echo "INFO: There are additional images to protect in the jjb dir." + images=("${images[@]}" "${jjbimages[@]}") + #dedupe + readarray -t images < <(printf '%s\n' "${images[@]}" | sort -u) +fi + + +echo "INFO: Protecting the following images:" +for image in "${images[@]}"; do + echo "$image" +done for image in "${images[@]}"; do os_image_protected=$(openstack --os-cloud "$os_cloud" \