2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 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 is involked by 'builder-verify-image-protection', searches
14 # the jjb source code for the images presently used and verifies protection
15 # setting. If the image protect setting is not "True", sets the
16 # image protect setting to "True" to prevent the image from getting purged
17 # by the cleanup old images job.
18 echo "---> Check image protection"
20 # shellcheck source=/tmp/v/openstack/bin/activate disable=SC1091
21 source "/tmp/v/openstack/bin/activate"
23 declare -a yaml_images
24 readarray -t yaml_images <<< "$(grep -r _system_image: --include \*.yaml \
25 | awk -F": " -e '{print $3}' | sed "s:'::;s:'$::;/^$/d" | sort -u)"
27 readarray -t cfg_images <<< "$(grep -r IMAGE_NAME --include \*.cfg \
28 | awk -F'=' -e '{print $2}' | sort -u)"
29 combined=("${yaml_images[@]}" "${cfg_images[@]}")
31 readarray -t images <<< "$(printf '%s\n' "${combined[@]}" | sort -u)"
33 for image in "${images[@]}"; do
34 os_image_protected=$(openstack --os-cloud "$OS_CLOUD" image show "$image" -f value -c protected)
35 echo "Protected setting for $image: $os_image_protected"
36 if [[ $os_image_protected != True ]]; then
37 echo "Image: $image NOT set as protected, changing the protected value."
38 openstack --os-cloud "$OS_CLOUD" image set --protected "$image"