Fix: Skip sigul installation on Ubuntu
[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         if [ -f "$file" ]; then
37             # Set the $IMAGE_NAME variable to the the file's IMAGE_NAME value
38             export "$(grep ^IMAGE_NAME= "$file")"
39             # The image should be listed as active
40
41             if ! openstack image list --property name="$IMAGE_NAME" | grep "active"; then
42                 echo "ERROR: No matching image found for $IMAGE_NAME"
43                 error=true
44             fi
45             # Set the $HARDWARE_ID variable to the the file's HARDWARE_ID value
46             export "$(grep ^HARDWARE_ID= "$file")"
47             # The flavor should be listed. Spaces in grep string ensure complete match.
48
49             if ! openstack flavor list | grep " $HARDWARE_ID "; then
50                 echo "ERROR: No matching flavor found for $HARDWARE_ID"
51                 error=true
52             fi
53         fi
54     done
55 }
56
57 echo "Verifying that cloud has a master configuration file"
58 if [[ -d jenkins-config/clouds/openstack ]]; then
59     for cloud in jenkins-config/clouds/openstack/*; do
60         if [[ -f $cloud/cloud.cfg ]]; then
61             # Get the OS_CLOUD variable from cloud config
62             if ! os_cloud=$(grep -E "^OS_CLOUD=" "$cloud/cloud.cfg" | cut -d'=' -f2); then
63             os_cloud="vex"
64             fi
65             OS_CLOUD=$os_cloud verify_images "$cloud"
66         else
67             echo "ERROR: No cloud.cfg for $cloud"
68             error=true
69         fi
70     done
71 fi
72
73 if $error; then
74     exit 1
75 fi