X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=blobdiff_plain;f=shell%2Fopenstack-protect-in-use-images.sh;h=e2299060e678aa6b6cae766b50b85ff8753cf1a5;hb=c8b9acd166fcbd88139a65f7721e522980a0e013;hp=9152348e270d5c4b940cc02009b4e615d3240667;hpb=2b811ee74f223040ff6071969566de72aed71b2a;p=releng%2Fglobal-jjb.git diff --git a/shell/openstack-protect-in-use-images.sh b/shell/openstack-protect-in-use-images.sh index 9152348e..e2299060 100644 --- a/shell/openstack-protect-in-use-images.sh +++ b/shell/openstack-protect-in-use-images.sh @@ -15,23 +15,46 @@ # 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) + +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 -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)" +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 - [[ -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"