Merge "Add release note for capture-instance-metadata"
[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 error=false
18
19 verify_images()
20 {
21   echo "Verifying images on $1"
22   for file in "$1"/*; do
23     # Set the $IMAGE_NAME variable to the the file's IMAGE_NAME value
24     export "$(grep ^IMAGE_NAME= "$file")"
25     # The image should be listed as active
26
27     if ! openstack image list --property name="$IMAGE_NAME" | grep "active"; then
28       echo "ERROR: No matching image found for $IMAGE_NAME"
29       error=true
30     fi
31     # Set the $HARDWARE_ID variable to the the file's HARDWARE_ID value
32     export "$(grep ^HARDWARE_ID= "$file")"
33     # The flavor should be listed. Spaces in grep string ensure complete match.
34
35     if ! openstack flavor list | grep " $HARDWARE_ID "; then
36       echo "ERROR: No matching flavor found for $HARDWARE_ID"
37       error=true
38     fi
39   done
40 }
41
42 echo "Verifying that cloud has a master configuration file"
43 if [[ -d jenkins-config/clouds/openstack ]]; then
44   for cloud in jenkins-config/clouds/openstack/*; do
45     if [[ -f $cloud/cloud.cfg ]]; then
46       # Get the OS_CLOUD variable from cloud config
47       if ! os_cloud=$(grep -E "^OS_CLOUD=" "$cloud/cloud.cfg" | cut -d'=' -f2); then
48         os_cloud="vex"
49       fi
50       OS_CLOUD=$os_cloud verify_images "$cloud"
51     else
52       echo "ERROR: No cloud.cfg for $cloud"
53       error=true
54     fi
55   done
56 fi
57
58 if $error; then
59   exit 1
60 fi