Consolidate a single openstack-cron job
[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 echo "---> Protect used images"
12
13 # Checks the image "protected" value and set "True" marker
14 #
15 # The script is involked by 'builder-verify-image-protection', searches
16 # the jjb source code for the images presently used and verifies protection
17 # setting. If the image protect setting is not "True", sets the
18 # image protect setting to "True" to prevent the image from getting purged
19 # by the cleanup old images job.
20
21 virtualenv "/tmp/v/openstack"
22 # shellcheck source=/tmp/v/openstack/bin/activate disable=SC1091
23 source "/tmp/v/openstack/bin/activate"
24 pip install --upgrade pip
25 pip install --upgrade python-openstackclient
26 pip install --upgrade pipdeptree
27 pipdeptree
28
29 declare -a images
30 readarray -t images <<< "$(grep -r _system_image: --include \*.yaml \
31     | awk -F": " -e '{print $3}' | sed "s:'::;s:'$::;/^$/d" | sort | uniq)"
32
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"
39     fi
40 done