Chore: Upgrade Jenkins-job-builder to 6.3.0
[releng/global-jjb.git] / shell / jenkins-verify-images.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2018 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 "---> jenkins-verify-images.sh"
12 # Verifies that openstack contains an image for each config file defined in the
13 # jenkins-config/clouds/openstack directory.
14
15 set -eux -o pipefail
16
17 # shellcheck disable=SC1090
18 source ~/lf-env.sh
19
20 if [ -f "/tmp/.os_lf_venv" ]; then
21     os_lf_venv=$(cat "/tmp/.os_lf_venv")
22 fi
23
24 if [ -d "${os_lf_venv}" ] && [ -f "${os_lf_venv}/bin/openstack" ]; then
25     echo "Re-use existing venv: ${os_lf_venv}"
26     PATH=$os_lf_venv/bin:$PATH
27 else
28     lf-activate-venv --python python3 python-openstackclient
29 fi
30 error=false
31
32 verify_images()
33 {
34     echo "Verifying images on $1"
35     for file in "$1"/*; do
36         # Set the $IMAGE_NAME variable to the the file's IMAGE_NAME value
37         export "$(grep ^IMAGE_NAME= "$file")"
38         # The image should be listed as active
39
40         if ! openstack image list --property name="$IMAGE_NAME" | grep "active"; then
41             echo "ERROR: No matching image found for $IMAGE_NAME"
42             error=true
43         fi
44         # Set the $HARDWARE_ID variable to the the file's HARDWARE_ID value
45         export "$(grep ^HARDWARE_ID= "$file")"
46         # The flavor should be listed. Spaces in grep string ensure complete match.
47
48         if ! openstack flavor list | grep " $HARDWARE_ID "; then
49             echo "ERROR: No matching flavor found for $HARDWARE_ID"
50             error=true
51         fi
52     done
53 }
54
55 echo "Verifying that cloud has a master configuration file"
56 if [[ -d jenkins-config/clouds/openstack ]]; then
57     for cloud in jenkins-config/clouds/openstack/*; do
58         if [[ -f $cloud/cloud.cfg ]]; then
59             # Get the OS_CLOUD variable from cloud config
60             if ! os_cloud=$(grep -E "^OS_CLOUD=" "$cloud/cloud.cfg" | cut -d'=' -f2); then
61             os_cloud="vex"
62             fi
63             OS_CLOUD=$os_cloud verify_images "$cloud"
64         else
65             echo "ERROR: No cloud.cfg for $cloud"
66             error=true
67         fi
68     done
69 fi
70
71 if $error; then
72     exit 1
73 fi