From 995c1ee62f8f213ded72fba4782a1c5dbbd51983 Mon Sep 17 00:00:00 2001 From: Bharat Kumar Kobagana Date: Thu, 23 Jul 2015 15:40:17 +0530 Subject: [PATCH] devstack-plugin-glusterfs: Adding checks for error conditions This patch introduces a new configuration parameter (knob) CONFIGURE_GLUSTERFS_CINDER to enable/disable glusterfs as a backend for Cinder. And added below error conditions: * glusterfs plugin enabled but CONFIGURE_GLUSTERFS_CINDER set to False * CONFIGURE_GLUSTERFS_CINDER set to True, but CINDER_ENABLED_BACKENDS doesn't have at least one backend of type glusterfs. Change-Id: Ic802a2f2bbbdc1af04fd1220d2055be1e853fef8 --- devstack/gluster-functions.sh | 4 +++- devstack/plugin.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/devstack/gluster-functions.sh b/devstack/gluster-functions.sh index 269a83b..54f1b3d 100644 --- a/devstack/gluster-functions.sh +++ b/devstack/gluster-functions.sh @@ -87,7 +87,9 @@ function cleanup_glusterfs { local vol_name # Cleaning up Cinder GlusterFS shares - _delete_gluster_shares $CINDER_GLUSTERFS_SHARES + if [ "$CONFIGURE_GLUSTERFS_CINDER" = "True" ]; then + _delete_gluster_shares $CINDER_GLUSTERFS_SHARES + fi if [[ -e ${GLUSTERFS_DISK_IMAGE} ]]; then sudo rm -f ${GLUSTERFS_DISK_IMAGE} diff --git a/devstack/plugin.sh b/devstack/plugin.sh index af77ed1..a6acdb6 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -19,6 +19,35 @@ # Defaults # -------- +# Set CONFIGURE_GLUSTERFS_CINDER to true, to enable GlusterFS as a backend for Cinder. +CONFIGURE_GLUSTERFS_CINDER=${CONFIGURE_GLUSTERFS_CINDER:-True} + +# Error out when devstack-plugin-glusterfs is enabled, but not selected as a backend for cinder. +if [ "$CONFIGURE_GLUSTERFS_CINDER" = "False" ]; then + echo "GlusterFS plugin enabled but not selected as a backend for Cinder." + echo "Please set CONFIGURE_GLUSTERFS_CINDER to True in localrc." + exit 1 +fi + +# When CONFIGURE_GLUSTERFS_CINDER is true, CINDER_ENABLED_BACKENDS should have +# at least one backend of type 'glusterfs', error out otherwise. +local is_gluster_backend_configured=False +for be in ${CINDER_ENABLED_BACKENDS//,/ }; do + if [ "${be%%:*}" = "glusterfs" ]; then + is_gluster_backend_configured=True + break + fi +done +if [ "$CONFIGURE_GLUSTERFS_CINDER" = "True" ] && [ "$is_gluster_backend_configured" = "False" ]; then + echo "CONFIGURE_GLUSTERFS_CINDER is set to True, to configure GlusterFS as a backend for Cinder." + echo "But, glusterfs backend type not present in CINDER_ENABLED_BACKENDS." + echo "Please enable at least one backend of type glusterfs in CINDER_ENABLED_BACKENDS." + exit 1 +elif [ "$CONFIGURE_GLUSTERFS_CINDER" = "False" ] && [ "$is_gluster_backend_configured" = "True" ]; then + echo "Configured Glusterfs as backend type in CINDER_ENABLED_BACKENDS. But CONFIGURE_GLUSTERFS_CINDER set to False." + exit 1 +fi + # GLUSTERFS_PLUGIN_DIR contains the path to devstack-plugin-glusterfs/devstack directory GLUSTERFS_PLUGIN_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]}))