Browse Source

devstack-plugin-glusterfs: Refactoring plugin code

This patch modifies the plugin code into more reusable manner.
Also adds a new file "devstack/gluster-functions.sh", which
contains gluster specific functions.

Change-Id: Ibe1231d5f2244ea7e9b7e7a5e1b138192e372206
Bharat Kumar Kobagana 3 years ago
parent
commit
d4bf5d44e3
2 changed files with 167 additions and 124 deletions
  1. 154
    0
      devstack/gluster-functions.sh
  2. 13
    124
      devstack/plugin.sh

+ 154
- 0
devstack/gluster-functions.sh View File

@@ -0,0 +1,154 @@
1
+#!/bin/bash
2
+
3
+# devstack/gluster-functions.sh
4
+# Functions to control the installation and configuration of the **GlusterFS** storage
5
+
6
+# Installs 3.6.x version of glusterfs
7
+# Triggered from devstack/plugin.sh as part of devstack "pre-install"
8
+function install_glusterfs {
9
+    if [[ ${DISTRO} =~ rhel7 ]] && [[ ! -f /etc/yum.repos.d/glusterfs-epel.repo ]]; then
10
+        sudo wget $GLUSTERFS_CENTOS_REPO -O /etc/yum.repos.d/glusterfs-epel.repo
11
+    elif is_ubuntu; then
12
+        sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 3FE869A9
13
+        echo "deb http://ppa.launchpad.net/gluster/glusterfs-3.6/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/glusterfs-3_6-trusty.list
14
+        echo "deb-src http://ppa.launchpad.net/gluster/glusterfs-3.6/ubuntu trusty main" | sudo tee --append /etc/apt/sources.list.d/glusterfs-3_6-trusty.list
15
+        NO_UPDATE_REPOS=False
16
+        REPOS_UPDATED=False
17
+    fi
18
+
19
+    install_package glusterfs-server
20
+    install_package xfsprogs
21
+
22
+    if is_fedora; then
23
+        stop_glusterfs
24
+        _start_glusterfs
25
+    fi
26
+
27
+    _create_glusterfs_disk
28
+
29
+    # Changing file permissions of glusterfs logs.
30
+    # This avoids creation of zero sized glusterfs log files while running CI job (Bug: 1455951).
31
+    sudo chmod 755 -R /var/log/glusterfs/
32
+}
33
+
34
+# Start gluster service
35
+function _start_glusterfs {
36
+    if is_ubuntu; then
37
+        sudo service glusterfs-server start
38
+    else
39
+        sudo service glusterd start
40
+    fi
41
+}
42
+
43
+# Stop running gluster service
44
+# Triggered from devstack/plugin.sh as part of devstack "unstack"
45
+function stop_glusterfs {
46
+    if is_ubuntu; then
47
+        sudo service glusterfs-server stop
48
+    else
49
+        sudo service glusterd stop
50
+    fi
51
+}
52
+
53
+# Clean Shares
54
+function _umount_shares {
55
+    local shares=$1
56
+    local share
57
+    local mount_point
58
+    for share in $(echo $shares | sed "s/;/ /");  do
59
+        mount_point=$(grep $share /proc/mounts | awk '{print $2}')
60
+        if [[ -n $mount_point ]]; then
61
+            sudo umount $mount_point
62
+        fi
63
+    done
64
+}
65
+
66
+# Delete gluster volumes
67
+function _delete_gluster_shares {
68
+    local shares=$1
69
+    local share
70
+    local gluster_volumes
71
+    _umount_shares $shares
72
+
73
+    for share in $(echo $shares | sed "s/;/ /"); do
74
+        gluster_volumes+=,$(echo $share | cut -d/ -f2);
75
+    done
76
+
77
+    for vol_name in $(echo $gluster_volumes | sed "s/,/ /g"); do
78
+        sudo gluster --mode=script volume stop $vol_name
79
+        sudo gluster --mode=script volume delete $vol_name
80
+    done
81
+}
82
+
83
+# Cleanup GlusterFS
84
+# Triggered from devstack/plugin.sh as part of devstack "clean"
85
+function cleanup_glusterfs {
86
+    local glusterfs_volumes
87
+    local vol_name
88
+
89
+    # Cleaning up Cinder GlusterFS shares
90
+    _delete_gluster_shares $CINDER_GLUSTERFS_SHARES
91
+
92
+    if [[ -e ${GLUSTERFS_DISK_IMAGE} ]]; then
93
+        sudo rm -f ${GLUSTERFS_DISK_IMAGE}
94
+    fi
95
+
96
+    if [[ "$OFFLINE" = "False" ]]; then
97
+        uninstall_package glusterfs-server
98
+    fi
99
+
100
+    if egrep -q ${GLUSTERFS_DATA_DIR} /proc/mounts; then
101
+        sudo umount ${GLUSTERFS_DATA_DIR}
102
+    fi
103
+
104
+    sudo rm -rf ${GLUSTERFS_DATA_DIR}
105
+}
106
+
107
+# Setting up glusterfs
108
+function _create_glusterfs_disk {
109
+    # create a backing file disk
110
+    local disk_image_directory=$(dirname "${GLUSTERFS_DISK_IMAGE}")
111
+    mkdir -p $disk_image_directory
112
+    create_disk ${GLUSTERFS_DISK_IMAGE} ${GLUSTERFS_DATA_DIR} ${GLUSTERFS_LOOPBACK_DISK_SIZE}
113
+}
114
+
115
+function _create_gluster_volume {
116
+    local glusterfs_volume=$1
117
+
118
+    sudo mkdir -p ${GLUSTERFS_DATA_DIR}/$glusterfs_volume
119
+    sudo gluster --mode=script volume \
120
+            create $glusterfs_volume $(hostname):${GLUSTERFS_DATA_DIR}/$glusterfs_volume
121
+    sudo gluster --mode=script volume start $glusterfs_volume
122
+    sudo gluster --mode=script volume set $glusterfs_volume server.allow-insecure on
123
+}
124
+
125
+function _create_gluster_volumes {
126
+    local gluster_shares=$1
127
+    local share
128
+    local glusterfs_volumes
129
+    for share in $(echo $gluster_shares | sed "s/;/ /"); do
130
+        glusterfs_volumes+=,$(echo $share | cut -d/ -f2);
131
+    done
132
+
133
+    local vol_name
134
+
135
+    for vol_name in $(echo $glusterfs_volumes | sed "s/,/ /g"); do
136
+        _create_gluster_volume $vol_name
137
+    done
138
+}
139
+
140
+# Configure GlusterFS as a backend for Cinder
141
+# Triggered from stack.sh
142
+function configure_cinder_backend_glusterfs {
143
+    _create_gluster_volumes $CINDER_GLUSTERFS_SHARES
144
+
145
+    local be_name=$1
146
+    iniset $CINDER_CONF $be_name volume_backend_name $be_name
147
+    iniset $CINDER_CONF $be_name volume_driver "cinder.volume.drivers.glusterfs.GlusterfsDriver"
148
+    iniset $CINDER_CONF $be_name glusterfs_shares_config "$CINDER_CONF_DIR/glusterfs-shares-$be_name.conf"
149
+
150
+    if [[ -n "$CINDER_GLUSTERFS_SHARES" ]]; then
151
+        CINDER_GLUSTERFS_SHARES=$(echo $CINDER_GLUSTERFS_SHARES | tr ";" "\n")
152
+        echo "$CINDER_GLUSTERFS_SHARES" | tee "$CINDER_CONF_DIR/glusterfs-shares-$be_name.conf"
153
+    fi
154
+}

+ 13
- 124
devstack/plugin.sh View File

@@ -1,163 +1,52 @@
1
-# 60-glusterfs.sh - DevStack extras script to install GlusterFS
2
-# Functions to control the configuration and operation of the **GlusterFS** storage service
1
+#!/bin/bash
2
+
3
+# devstack/plugin.sh
4
+# Triggers glusterfs specific functions to install and configure GlusterFS
3 5
 
4 6
 # Dependencies:
5 7
 #
6 8
 # - ``functions`` file
7
-# - ``GLUSTERFS_DATA_DIR`` or ``DATA_DIR`` must be defined
9
+# - ``DATA_DIR`` must be defined
8 10
 
9 11
 # ``stack.sh`` calls the entry points in this order:
10 12
 #
11 13
 # - install_glusterfs
12
-# - configure_glusterfs_cinder & configure_privileged_user
13 14
 # - start_glusterfs
15
+# - configure_cinder_backend_glusterfs
14 16
 # - stop_glusterfs
15 17
 # - cleanup_glusterfs
16 18
 
17 19
 # Defaults
18 20
 # --------
19 21
 
22
+# GLUSTERFS_PLUGIN_DIR contains the path to devstack-plugin-glusterfs/devstack directory
23
+GLUSTERFS_PLUGIN_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
24
+
20 25
 # Set ``GLUSTERFS_DATA_DIR`` to the location of GlusterFS drives.
21
-# Default is the common DevStack data directory.
26
+# Default is /var/lib/glusterfs.
22 27
 GLUSTERFS_DATA_DIR=${GLUSTERFS_DATA_DIR:-/var/lib/glusterfs}
23 28
 GLUSTERFS_DISK_IMAGE=${DATA_DIR}/cinder/glusterfs.img
24 29
 
25 30
 # DevStack will create a loop-back disk formatted as XFS to store the
26 31
 # GlusterFS data. Set ``GLUSTERFS_LOOPBACK_DISK_SIZE`` to the disk size in
27
-# kilobytes.
32
+# GB.
28 33
 # Default is 4 gigabyte. But we can configure through localrc.
29 34
 GLUSTERFS_LOOPBACK_DISK_SIZE=${GLUSTERFS_LOOPBACK_DISK_SIZE:-4G}
30 35
 
31 36
 # Devstack will create GlusterFS shares to store Cinder volumes.
32 37
 # Those shares can be configured by seting CINDER_GLUSTERFS_SHARES.
33 38
 # By default CINDER_GLUSTERFS_SHARES="127.0.0.1:/vol1"
34
-
35 39
 CINDER_GLUSTERFS_SHARES=${CINDER_GLUSTERFS_SHARES:-"127.0.0.1:/vol1"}
36 40
 
37
-# Glusterfs volume provisioned type, allowed values are 'thin' or 'thick'.
38
-# Since we only support raw volumes for backup, using 'thick' as default value.
39
-GLUSTERFS_VOLUME_PROV_TYPE=${GLUSTERFS_VOLUME_PROV_TYPE:-"thick"}
40
-
41 41
 # Adding GlusterFS repo to CentOS / RHEL 7 platform.
42
-
43 42
 GLUSTERFS_CENTOS_REPO=${GLUSTERFS_CENTOS_REPO:-"http://download.gluster.org/pub/gluster/glusterfs/LATEST/CentOS/glusterfs-epel.repo"}
44 43
 
45
-# Functions
46
-# ------------
47
-
48
-# cleanup_glusterfs() - Remove residual data files, anything left over from previous
49
-# runs that a clean run would need to clean up
50
-function cleanup_glusterfs {
51
-    for share in $(echo $CINDER_GLUSTERFS_SHARES | sed "s/;/ /");  do
52
-        local mount_point=$(grep $share /proc/mounts | awk '{print $2}')
53
-        if [[ -n $mount_point ]]; then
54
-            sudo umount $mount_point
55
-        fi
56
-    done
57
-
58
-    if [[ -e ${GLUSTERFS_DISK_IMAGE} ]]; then
59
-        sudo rm -f ${GLUSTERFS_DISK_IMAGE}
60
-    fi
61
-
62
-    for share in $(echo $CINDER_GLUSTERFS_SHARES | sed "s/;/ /"); do
63
-        GLUSTERFS_VOLUMES+=,$(echo $share | cut -d/ -f2);
64
-    done
65
-
66
-    for vol_name in $(echo $GLUSTERFS_VOLUMES | sed "s/,/ /g"); do
67
-        sudo gluster --mode=script volume stop $vol_name
68
-        sudo gluster --mode=script volume delete $vol_name
69
-    done
70
-
71
-    if [[ "$OFFLINE" = "False" ]]; then
72
-        uninstall_package glusterfs-server
73
-    fi
74
-
75
-    if egrep -q ${GLUSTERFS_DATA_DIR} /proc/mounts; then
76
-        sudo umount ${GLUSTERFS_DATA_DIR}
77
-    fi
78
-    sudo rm -rf ${GLUSTERFS_DATA_DIR}
79
-}
80
-
81
-# configure_glusterfs_cinder() - Create GlusterFS volumes
82
-function configure_glusterfs_cinder {
83
-    for share in $(echo $CINDER_GLUSTERFS_SHARES | sed "s/;/ /"); do
84
-        GLUSTERFS_VOLUMES+=,$(echo $share | cut -d/ -f2);
85
-    done
86
-
87
-    if is_fedora; then
88
-        stop_glusterfs
89
-        start_glusterfs
90
-    fi
91
-    # create a backing file disk
92
-    create_disk ${GLUSTERFS_DISK_IMAGE} ${GLUSTERFS_DATA_DIR} ${GLUSTERFS_LOOPBACK_DISK_SIZE}
93
-
94
-    for vol_name in $(echo $GLUSTERFS_VOLUMES | sed "s/,/ /g"); do
95
-        sudo mkdir -p ${GLUSTERFS_DATA_DIR}/$vol_name
96
-        sudo gluster --mode=script volume \
97
-            create $vol_name $(hostname):${GLUSTERFS_DATA_DIR}/$vol_name
98
-        sudo gluster --mode=script volume start $vol_name
99
-        sudo gluster --mode=script volume set $vol_name server.allow-insecure on
100
-    done
101
-
102
-    # Changing file permissions of glusterfs logs.
103
-    # This avoids creation of zero sized glusterfs log files while running CI job (Bug: 1455951).
104
-    sudo chmod 755 -R /var/log/glusterfs/
105
-}
106
-
107
-# this modifies the cinder.conf file and create glusterfs_shares_config file.
108
-function configure_cinder_backend_glusterfs {
109
-    local be_name=$1
110
-    iniset $CINDER_CONF $be_name volume_backend_name $be_name
111
-    iniset $CINDER_CONF $be_name volume_driver "cinder.volume.drivers.glusterfs.GlusterfsDriver"
112
-    iniset $CINDER_CONF $be_name glusterfs_shares_config "$CINDER_CONF_DIR/glusterfs-shares-$be_name.conf"
113
-    #iniset $CINDER_CONF $be_name volume_prov_type $GLUSTERFS_VOLUME_PROV_TYPE
114
-
115
-    if [[ -n "$CINDER_GLUSTERFS_SHARES" ]]; then
116
-        CINDER_GLUSTERFS_SHARES=$(echo $CINDER_GLUSTERFS_SHARES | tr ";" "\n")
117
-        echo "$CINDER_GLUSTERFS_SHARES" | tee "$CINDER_CONF_DIR/glusterfs-shares-$be_name.conf"
118
-    fi
119
-}
120
-
121
-# install_glusterfs() - Collect source and prepare
122
-function install_glusterfs {
123
-    if [[ ${DISTRO} =~ rhel7 ]] && [[ ! -f /etc/yum.repos.d/glusterfs-epel.repo ]]; then
124
-        sudo wget $GLUSTERFS_CENTOS_REPO -O /etc/yum.repos.d/glusterfs-epel.repo
125
-    elif is_ubuntu; then
126
-        sudo wget -O - http://download.gluster.org/pub/gluster/glusterfs/3.6/3.6.2/Debian/wheezy/pubkey.gpg |  sudo apt-key add -
127
-        sudo echo deb http://download.gluster.org/pub/gluster/glusterfs/3.6/3.6.2/Debian/wheezy/apt wheezy main | sudo tee  /etc/apt/sources.list.d/gluster.list
128
-        NO_UPDATE_REPOS=False
129
-        REPOS_UPDATED=False
130
-    fi
131
-    install_package glusterfs-server
132
-    install_package xfsprogs
133
-}
134
-
135
-# start_glusterfs() - Start running processes
136
-function start_glusterfs {
137
-    if is_ubuntu; then
138
-        sudo service glusterfs-server start
139
-    else
140
-        sudo service glusterd start
141
-    fi
142
-}
143
-
144
-# stop_glusterfs() - Stop running processes
145
-function stop_glusterfs {
146
-    if is_ubuntu; then
147
-        sudo service glusterfs-server stop
148
-    else
149
-        sudo service glusterd stop
150
-    fi
151
-}
44
+# Initializing gluster specific functions
45
+source $GLUSTERFS_PLUGIN_DIR/gluster-functions.sh
152 46
 
153 47
 if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then
154 48
     echo_summary "Installing GlusterFS"
155 49
     install_glusterfs
156
-elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
157
-    if is_service_enabled cinder; then
158
-        echo_summary "Configuring Cinder for GlusterFS"
159
-        configure_glusterfs_cinder
160
-    fi
161 50
 fi
162 51
 
163 52
 if [[ "$1" == "unstack" ]]; then

Loading…
Cancel
Save