Merge "Increase ocata packer timeout from 60m to 75m"
[releng/builder.git] / jjb / opendaylight-infra-check-image-protection.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
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
12 # Checks the image "protected" value and set "True" marker
13 #
14 # The script is involked by 'builder-verify-image-protection', searches
15 # the jjb source code for the images presently used and verifies protection
16 # setting. If the image protect setting is not "True", sets the
17 # image protect setting to "True" to prevent the image from getting purged
18 # by the cleanup old images job.
19
20 virtualenv "/tmp/v/openstack"
21 # shellcheck source=/tmp/v/openstack/bin/activate disable=SC1091
22 source "/tmp/v/openstack/bin/activate"
23 pip install --upgrade pip
24 pip install --upgrade python-openstackclient
25 pip install --upgrade pipdeptree
26 pipdeptree
27
28 declare -a images
29 readarray -t images <<< "$(grep -r _system_image: --include \*.yaml \
30     | awk -F": " -e '{print $3}' | sed "s:'::;s:'$::;/^$/d" | sort | uniq)"
31
32 for image in "${images[@]}"; do
33     os_image_protected=$(openstack --os-cloud "$OS_CLOUD" image show "$image" -f value -c protected)
34     echo "Protected setting for $image: $os_image_protected"
35     if [[ $os_image_protected != True ]]; then
36         echo "Image: $image NOT set as protected, changing the protected value."
37         openstack --os-cloud "$OS_CLOUD" image set --protected "$image"
38     fi
39 done