2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017, 2018 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 # Checks the image "protected" value and set "True" marker
13 # The script searches the ciman repo for the images presently used and ensures
14 # the protection setting is set for those images to prevent the image from
15 # getting purged by the image cleanup script.
16 # This script assumes images prefixed with the string "ZZCI - " are ci-managed
19 echo "---> Protect in-use images"
20 os_cloud="${OS_CLOUD:-vex}"
23 while read -r -d $'\n' ; do
25 done < <(grep -r IMAGE_NAME --include \*.cfg jenkins-config \
26 | awk -F'=' '{print $2}' \
30 while read -r -d $'\n' ; do
32 done < <(grep -r 'ZZCI - ' --include \*.yaml jjb \
33 | awk -F": " '{print $3}' \
34 | sed -e "s:'::;s:'$::;/^$/d" -e 's/^"//' -e 's/"$//' \
37 if ! [[ ${#images[@]} -eq 0 ]]; then
38 echo "INFO: There are images to protect defined in jenkins-config."
40 echo "ERROR: No images detected in the jenkins-config dir."
44 if ! [[ ${#jjbimages[@]} -eq 0 ]]; then
45 echo "INFO: There are additional images to protect in the jjb dir."
46 images=("${images[@]}" "${jjbimages[@]}")
48 readarray -t images < <(printf '%s\n' "${images[@]}" | sort -u)
52 echo "INFO: Protecting the following images:"
53 for image in "${images[@]}"; do
57 for image in "${images[@]}"; do
58 os_image_protected=$(openstack --os-cloud "$os_cloud" \
59 image show "$image" -f value -c protected)
60 echo "Protected setting for $image: $os_image_protected"
62 if [[ $os_image_protected != True ]]; then
63 echo " Image NOT set as protected, changing the protected value."
64 openstack --os-cloud "$os_cloud" image set --protected "$image"