From f53859f89e78cce80c0e9709a1ae769fec76e252 Mon Sep 17 00:00:00 2001 From: Bharat Kumar Kobagana Date: Mon, 19 Oct 2015 00:44:17 +0530 Subject: [PATCH] Refactoring devstack-plugin-glusterfs code This patch does the following: * Moved variable setting part from plugin.sh to settings file. * By default all Gluster-[Glance|Nova|Cinder|Manila] integrations disabled. Look at README file to know how to enable. * Keeping CINDER_ENABLED_BACKENDS intact when CONFIGURE_GLUSTERFS_CINDER=False (Bug #1500381) * Renamed CONFIGURE_GLUSTERFS_BACKUP to CONFIGURE_GLUSTERFS_CINDER_BACKUP * Avoid setting unnecessary variable when speicific configuraiton is disabled. * Documented the steps to enable in README.md file of this project. Closes-Bug: #1500381 Depends-On: Id6967499729dfaa12d8a338d8f72471ebc90fb0d Change-Id: I36f35f8af8e3491c8b0cffb40ba3980b7beab5df --- README.md | 37 +++++++-- devstack/gluster-functions.sh | 2 +- devstack/override-defaults | 5 +- devstack/plugin.sh | 98 +----------------------- devstack/settings | 138 ++++++++++++++++++++++++++++++---- 5 files changed, 162 insertions(+), 118 deletions(-) diff --git a/README.md b/README.md index fdf3419..c82980b 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,38 @@ Devstack GlusterFS Plugin # Goals -* To install GlusterFS (client and server) packages -* Creates GlusterFS volumes to provide them as shares to Cinder -* Configures Cinder with GlusterFS backend -* Also cleans up the GlusterFS volumes and data related to GlusterFS +As part of "stack.sh": +* To install Glusterfs (client and server) packages +* By default all Gluster-[Glance|Nova|Cinder|Manila] integrations disabled. Look at "How to use" section, to know how to enable. +* Configures Glusterfs as a backend for Glance, Nova, Cinder and Manila as per localrc configuration +* Creates Gluster volumes to provide them as storage to Glance, Nova, Cinder or Manila + +As part of "unstack.sh": +* Also cleans up the Gluster volumes and data related to Gluster * Uninstalls the Gluster packages when we run "unstack.sh" -# How to use +# How to use (localrc configuration) + +* Enable devstack-plugin-glusterfs plugin: + [[local|localrc]] + enable_plugin devstack-plugin-glusterfs https://github.com/stackforge/devstack-plugin-glusterfs + +* To enable Gluster as a backend for Glance: + CONFIGURE_GLUSTERFS_GLANCE=True + +* To enable Gluster as a backend for Nova: + CONFIGURE_GLUSTERFS_NOVA=True + +* To enable Gluster as a backend for Cinder: + CONFIGURE_GLUSTERFS_CINDER=True + Also we can enable/disable glusterfs as a backend for Cinder Backup (c-bak) driver: + # By default set to True when CONFIGURE_GLUSTERFS_CINDER=True + enable_service c-bak + CONFIGURE_GLUSTERFS_CINDER_BACKUP=[True OR False] + +* To enable Gluster as a backend for Manila: + CONFIGURE_GLUSTERFS_MANILA=True + Also select specific gluster backend type for manila, default is "glusterfs": + GLUSTERFS_MANILA_DRIVER_TYPE=[glusterfs OR glusterfs-native] -* Add "enable_plugin glusterfs https://github.com/stackforge/devstack-plugin-glusterfs" to localrc file inside devstack. * Then run "stack.sh" diff --git a/devstack/gluster-functions.sh b/devstack/gluster-functions.sh index 4383d56..465d244 100755 --- a/devstack/gluster-functions.sh +++ b/devstack/gluster-functions.sh @@ -93,7 +93,7 @@ function cleanup_glusterfs { fi # Cleaning up Cinder Backup GlusterFS shares - if [ "$CONFIGURE_GLUSTERFS_BACKUP" = "True" ]; then + if [ "$CONFIGURE_GLUSTERFS_CINDER_BACKUP" = "True" ]; then _delete_gluster_shares $CINDER_GLUSTERFS_BACKUP_SHARE fi # Cleaning up Glance GlusterFS share diff --git a/devstack/override-defaults b/devstack/override-defaults index 7c1ec1b..b558712 100644 --- a/devstack/override-defaults +++ b/devstack/override-defaults @@ -1,4 +1,5 @@ # Plug-in overrides -CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-glusterfs:glusterfs,lvm:lvm1} - +if [ "$CONFIGURE_GLUSTERFS_CINDER" == "True" ]; then + CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-glusterfs:glusterfs,lvm:lvm1} +fi diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 406ea69..bdbf1d5 100755 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -20,103 +20,11 @@ # - stop_glusterfs # - cleanup_glusterfs -# Defaults -# -------- - -# Set CONFIGURE_GLUSTERFS_CINDER to true, to enable GlusterFS as a backend for Cinder. -CONFIGURE_GLUSTERFS_CINDER=${CONFIGURE_GLUSTERFS_CINDER:-True} - -# Set CONFIGURE_GLUSTERFS_BACKUP to true, to configure GlusterFS as a backup driver for Cinder. -CONFIGURE_GLUSTERFS_BACKUP=${CONFIGURE_GLUSTERFS_BACKUP:-$CONFIGURE_GLUSTERFS_CINDER} - -# Set CONFIGURE_GLUSTERFS_GLANCE to true, to configure GlusterFS as a backend for Glance. -CONFIGURE_GLUSTERFS_GLANCE=${CONFIGURE_GLUSTERFS_GLANCE:-False} - -# Set CONFIGURE_GLUSTERFS_NOVA to true, to configure GlusterFS as a backend for Nova. -CONFIGURE_GLUSTERFS_NOVA=${CONFIGURE_GLUSTERFS_NOVA:-False} - -# Set CONFIGURE_GLUSTERFS_MANILA to true, to configure GlusterFS as a backend for Manila. -CONFIGURE_GLUSTERFS_MANILA=${CONFIGURE_GLUSTERFS_MANILA:-False} - -# Set GLUSTERFS_MANILA_DRIVER_TYPE to either 'glusterfs' or 'glusterfs-native'. -GLUSTERFS_MANILA_DRIVER_TYPE=${GLUSTERFS_MANILA_DRIVER_TYPE:-glusterfs} - -# Set GLUSTERFS_VG_NAME to the name of volume group. -GLUSTERFS_VG_NAME=${GLUSTERFS_VG_NAME:-glusterfs-vg} - -# Set GLUSTERFS_THIN_POOL_NAME to the name of thinpool. -GLUSTERFS_THIN_POOL_NAME=${GLUSTERFS_THIN_POOL_NAME:-glusterfs-thinpool} - -# Error out when devstack-plugin-glusterfs is enabled, but not selected as a backend for Cinder, Glance or Nova. -if [ "$CONFIGURE_GLUSTERFS_CINDER" = "False" ] && [ "$CONFIGURE_GLUSTERFS_GLANCE" = "False" ] && [ "$CONFIGURE_GLUSTERFS_NOVA" = "False" ] && [ "$CONFIGURE_GLUSTERFS_MANILA" = "False" && [ "$CONFIGURE_GLUSTERFS_BACKUP" = "False" ]; then - echo "GlusterFS plugin enabled but not selected as a backend for Cinder, Glance, Nova or Manila." - echo "Please set CONFIGURE_GLUSTERFS_CINDER, CONFIGURE_GLUSTERFS_BACKUP, CONFIGURE_GLUSTERFS_GLANCE, CONFIGURE_GLUSTERFS_NOVA and/or CONFIGURE_GLUSTERFS_MANILA 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]})) - -# Set ``GLUSTERFS_DATA_DIR`` to the location of GlusterFS drives. -# Default is /var/lib/glusterfs. -GLUSTERFS_DATA_DIR=${GLUSTERFS_DATA_DIR:-/var/lib/glusterfs} -GLUSTERFS_DISK_IMAGE=${DATA_DIR}/cinder/glusterfs.img - -# DevStack will create a loop-back disk formatted as XFS to store the -# GlusterFS data. Set ``GLUSTERFS_LOOPBACK_DISK_SIZE`` to the disk size in -# GB. -# Default is 4 gigabyte. But we can configure through localrc. -GLUSTERFS_LOOPBACK_DISK_SIZE=${GLUSTERFS_LOOPBACK_DISK_SIZE:-4G} - -# Devstack will create GlusterFS shares to store Cinder volumes. -# Those shares can be configured by seting CINDER_GLUSTERFS_SHARES. -# By default CINDER_GLUSTERFS_SHARES="127.0.0.1:/vol1" -CINDER_GLUSTERFS_SHARES=${CINDER_GLUSTERFS_SHARES:-"127.0.0.1:/cinder-vol"} - -# GlusterFS shares for Cinder backup -CINDER_GLUSTERFS_BACKUP_SHARE=${CINDER_GLUSTERFS_BACKUP_SHARE:-"127.0.0.1:/backup_vol"} - -# Glance GlusterFS share -GLANCE_GLUSTERFS_SHARE=${GLANCE_GLUSTERFS_SHARE:-"127.0.0.1:/glance-vol"} - -# Glance Nova share -NOVA_GLUSTERFS_SHARE=${NOVA_GLUSTERFS_SHARE:-"127.0.0.1:/nova-vol"} - -# Adding GlusterFS repo to CentOS / RHEL 7 platform. -GLUSTERFS_CENTOS_REPO=${GLUSTERFS_CENTOS_REPO:-"http://download.gluster.org/pub/gluster/glusterfs/LATEST/CentOS/glusterfs-epel.repo"} - -# Initializing gluster specific functions -source $GLUSTERFS_PLUGIN_DIR/gluster-functions.sh - if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then - if is_service_enabled manila && [[ "$CONFIGURE_GLUSTERFS_MANILA" == "True" ]]; then - echo_summary "Installing GlusterFS 3.7" - install_glusterfs 3.7 - else - echo_summary "Installing GlusterFS 3.6" - install_glusterfs 3.6 - fi + echo_summary "Installing GlusterFS 3.7" + install_glusterfs 3.7 elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then - if is_service_enabled c-bak && [[ "$CONFIGURE_GLUSTERFS_BACKUP" == "True" ]]; then + if is_service_enabled c-bak && [[ "$CONFIGURE_GLUSTERFS_CINDER_BACKUP" == "True" ]]; then echo_summary "Configuring GlusterFS as a backend for Cinder backup driver" configure_cinder_backup_backend_glusterfs fi diff --git a/devstack/settings b/devstack/settings index 6602a8e..25ee9e7 100644 --- a/devstack/settings +++ b/devstack/settings @@ -1,22 +1,132 @@ # Devstack settings -# We have to add glusterfs to enabled services for screen_it to work -enable_service glusterfs +# Defaults +# -------- -# Cinder encrypted volume tests are not supported with a GlusterFS -# backend due to bug 1473363 -ATTACH_ENCRYPTED_VOLUME_AVAILABLE=False -# Below are GlusterFS specific settings, with their defaults -TEMPEST_STORAGE_PROTOCOL=glusterfs +######### Plugin Specific ######### + +# GLUSTERFS_PLUGIN_DIR contains the path to devstack-plugin-glusterfs/devstack directory +GLUSTERFS_PLUGIN_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]})) + +# Set ``GLUSTERFS_DATA_DIR`` to the location of GlusterFS drives. +# Default is /var/lib/glusterfs. +GLUSTERFS_DATA_DIR=${GLUSTERFS_DATA_DIR:-/var/lib/glusterfs} +GLUSTERFS_DISK_IMAGE=${DATA_DIR}/glusterfs.img + +# DevStack will create a loop-back disk formatted as XFS to store the +# GlusterFS data. Set ``GLUSTERFS_LOOPBACK_DISK_SIZE`` to the disk size in GB. +# Default is 8 gigabyte. But we can configure through localrc. GLUSTERFS_LOOPBACK_DISK_SIZE=${GLUSTERFS_LOOPBACK_DISK_SIZE:-8G} -CINDER_GLUSTERFS_SHARES=${CINDER_GLUSTERFS_SHARES:-"127.0.0.1:/cinder-vol1;127.0.0.1:/cinder-vol2"} -# Set default volume prov type to thick as we don't yet support backup for thin (qcow2) files -GLUSTERFS_VOLUME_PROV_TYPE=${GLUSTERFS_VOLUME_PROV_TYPE:-thick} -# Enabling GlusterFS as a backend for Glace -CONFIGURE_GLUSTERFS_GLANCE=${CONFIGURE_GLUSTERFS_GLANCE:-True} +# GlusterFS repo for CentOS/RHEL 7 platform +if [[ ${DISTRO} =~ rhel7 ]] && [[ ! -f /etc/yum.repos.d/glusterfs-epel.repo ]]; then + GLUSTERFS_CENTOS_REPO=${GLUSTERFS_CENTOS_REPO:-"http://download.gluster.org/pub/gluster/glusterfs/LATEST/CentOS/glusterfs-epel.repo"} +fi -# Enabling GlusterFS as a backend for Nova -CONFIGURE_GLUSTERFS_NOVA=${CONFIGURE_GLUSTERFS_NOVA:-True} +TEMPEST_STORAGE_PROTOCOL=glusterfs + +######### Glance Specific Configuration ######### + +# Set CONFIGURE_GLUSTERFS_GLANCE to true, to configure GlusterFS as a backend for Glance. +CONFIGURE_GLUSTERFS_GLANCE=${CONFIGURE_GLUSTERFS_GLANCE:-False} + +if [ "$CONFIGURE_GLUSTERFS_GLANCE" == "True" ]; then + # Glance GlusterFS share + GLANCE_GLUSTERFS_SHARE=${GLANCE_GLUSTERFS_SHARE:-"127.0.0.1:/glance-vol"} +fi + +######### Nova Specific Configuration ######### + +# Set CONFIGURE_GLUSTERFS_NOVA to true, to configure GlusterFS as a backend for Nova. +CONFIGURE_GLUSTERFS_NOVA=${CONFIGURE_GLUSTERFS_NOVA:-False} + +if [ "$CONFIGURE_GLUSTERFS_NOVA" == "True" ]; then + # Glance Nova share + NOVA_GLUSTERFS_SHARE=${NOVA_GLUSTERFS_SHARE:-"127.0.0.1:/nova-vol"} +fi + +######### Cinder Specific Configuration ######### + +# Set CONFIGURE_GLUSTERFS_CINDER to true, to enable GlusterFS as a backend for Cinder. +CONFIGURE_GLUSTERFS_CINDER=${CONFIGURE_GLUSTERFS_CINDER:-False} + +if [ "$CONFIGURE_GLUSTERFS_CINDER" == "True" ]; then + CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-glusterfs:glusterfs,lvm:lvm1} + + # Devstack will create GlusterFS shares to store Cinder volumes. + # Those shares can be configured by seting CINDER_GLUSTERFS_SHARES. + # By default CINDER_GLUSTERFS_SHARES="127.0.0.1:/vol1" + CINDER_GLUSTERFS_SHARES=${CINDER_GLUSTERFS_SHARES:-"127.0.0.1:/cinder-vol1;127.0.0.1:/cinder-vol2"} + + # Set default volume prov type to thick as we don't yet support backup for thin (qcow2) files + GLUSTERFS_VOLUME_PROV_TYPE=${GLUSTERFS_VOLUME_PROV_TYPE:-thick} + + # Cinder encrypted volume tests are not supported with a GlusterFS + # backend due to bug 1473363 + ATTACH_ENCRYPTED_VOLUME_AVAILABLE=False +fi + +######### Cinder Backup Specific Configuration ######### + +# Set CONFIGURE_GLUSTERFS_CINDER_BACKUP to true, to configure GlusterFS as a backup driver for Cinder. +CONFIGURE_GLUSTERFS_CINDER_BACKUP=${CONFIGURE_GLUSTERFS_CINDER_BACKUP:-$CONFIGURE_GLUSTERFS_CINDER} + +if [ "$CONFIGURE_GLUSTERFS_CINDER_BACKUP" == "True" ]; then + # GlusterFS shares for Cinder backup + CINDER_GLUSTERFS_BACKUP_SHARE=${CINDER_GLUSTERFS_BACKUP_SHARE:-"127.0.0.1:/backup_vol"} +fi + +######### Manila Specific Configuration ######### + +# Set CONFIGURE_GLUSTERFS_MANILA to true, to configure GlusterFS as a backend for Manila. +CONFIGURE_GLUSTERFS_MANILA=${CONFIGURE_GLUSTERFS_MANILA:-False} + +if [ "$CONFIGURE_GLUSTERFS_MANILA" == "True" ]; then + # Set GLUSTERFS_MANILA_DRIVER_TYPE to either 'glusterfs' or 'glusterfs-native'. + GLUSTERFS_MANILA_DRIVER_TYPE=${GLUSTERFS_MANILA_DRIVER_TYPE:-glusterfs} + + # Set GLUSTERFS_VG_NAME to the name of volume group. + GLUSTERFS_VG_NAME=${GLUSTERFS_VG_NAME:-glusterfs-vg} + + # Set GLUSTERFS_THIN_POOL_NAME to the name of thinpool. + GLUSTERFS_THIN_POOL_NAME=${GLUSTERFS_THIN_POOL_NAME:-glusterfs-thinpool} +fi + + +# Validation +# ---------- + +# Error out when devstack-plugin-glusterfs is enabled, but not selected as a +# backend for Cinder, Glance or Nova. +if [ "$CONFIGURE_GLUSTERFS_CINDER" == "False" ] && [ "$CONFIGURE_GLUSTERFS_GLANCE" == "False" ] && [ "$CONFIGURE_GLUSTERFS_NOVA" == "False" ] && [ "$CONFIGURE_GLUSTERFS_MANILA" == "False" ] && [ "$CONFIGURE_GLUSTERFS_CINDER_BACKUP" == "False" ]; then + echo "GlusterFS plugin enabled but not selected as a backend for Cinder, Glance, Nova or Manila." + echo "Please set CONFIGURE_GLUSTERFS_CINDER, CONFIGURE_GLUSTERFS_CINDER_BACKUP, CONFIGURE_GLUSTERFS_GLANCE, CONFIGURE_GLUSTERFS_NOVA and/or CONFIGURE_GLUSTERFS_MANILA 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 "So please set one backend of type glusterfs to 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 + +# Initializing gluster specific functions +# --------------------------------------- + +source $GLUSTERFS_PLUGIN_DIR/gluster-functions.sh