Fix: Update verify-images script to avoid dirs
[releng/global-jjb.git] / shell / jenkins-verify-images.sh
index 483a51b..3b27e7d 100755 (executable)
@@ -14,27 +14,42 @@ echo "---> jenkins-verify-images.sh"
 
 set -eux -o pipefail
 
+# shellcheck disable=SC1090
+source ~/lf-env.sh
+
+if [ -f "/tmp/.os_lf_venv" ]; then
+    os_lf_venv=$(cat "/tmp/.os_lf_venv")
+fi
+
+if [ -d "${os_lf_venv}" ] && [ -f "${os_lf_venv}/bin/openstack" ]; then
+    echo "Re-use existing venv: ${os_lf_venv}"
+    PATH=$os_lf_venv/bin:$PATH
+else
+    lf-activate-venv --python python3 python-openstackclient
+fi
 error=false
 
 verify_images()
 {
     echo "Verifying images on $1"
     for file in "$1"/*; do
-        # Set the $IMAGE_NAME variable to the the file's IMAGE_NAME value
-        export "$(grep ^IMAGE_NAME= "$file")"
-        # The image should be listed as active
+        if [ -f "$file" ]; then
+            # Set the $IMAGE_NAME variable to the the file's IMAGE_NAME value
+            export "$(grep ^IMAGE_NAME= "$file")"
+            # The image should be listed as active
 
-        if ! openstack image list --property name="$IMAGE_NAME" | grep "active"; then
-            echo "ERROR: No matching image found for $IMAGE_NAME"
-            error=true
-        fi
-        # Set the $HARDWARE_ID variable to the the file's HARDWARE_ID value
-        export "$(grep ^HARDWARE_ID= "$file")"
-        # The flavor should be listed. Spaces in grep string ensure complete match.
+            if ! openstack image list --property name="$IMAGE_NAME" | grep "active"; then
+                echo "ERROR: No matching image found for $IMAGE_NAME"
+                error=true
+            fi
+            # Set the $HARDWARE_ID variable to the the file's HARDWARE_ID value
+            export "$(grep ^HARDWARE_ID= "$file")"
+            # The flavor should be listed. Spaces in grep string ensure complete match.
 
-        if ! openstack flavor list | grep " $HARDWARE_ID "; then
-            echo "ERROR: No matching flavor found for $HARDWARE_ID"
-            error=true
+            if ! openstack flavor list | grep " $HARDWARE_ID "; then
+                echo "ERROR: No matching flavor found for $HARDWARE_ID"
+                error=true
+            fi
         fi
     done
 }