Merge "Fix jenkins-verify-images.sh crash on grep"
[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 for cloud in jenkins-config/clouds/openstack/*; do
44   if [[ -f $cloud/cloud.cfg ]]; then
45     # Get the OS_CLOUD variable from cloud config
46     if ! os_cloud=$(egrep "^OS_CLOUD=" "$cloud/cloud.cfg" | cut -d'=' -f2); then
47       os_cloud="vex"
48     fi
49     OS_CLOUD=$os_cloud verify_images "$cloud"
50   else
51     echo "ERROR: No cloud.cfg for $cloud"
52     error=true
53   fi
54 done
55
56 if $error; then
57   exit 1
58 fi