Fix OS_CLOUD export for image validation
[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 for cloud in jenkins-config/clouds/openstack/*; do
43   echo "Verifying that cloud has a master configuration file"
44   # Verify that we have a cloud config file
45   if [ -f "$cloud/cloud.cfg" ]; then
46     # Get the OS_CLOUD variable from cloud config and export it
47     os_cloud=$(grep ^OS_CLOUD= "$cloud/cloud.cfg" | cut -d'=' -f2)
48     OS_CLOUD="${os_cloud:-vex}"
49     export OS_CLOUD
50
51     verify_images "$cloud"
52   else
53     echo "ERROR: No cloud.cfg for $cloud"
54     error=true
55   fi
56 done
57
58 if $error; then
59   exit 1
60 fi