Browse code

Move nova volumes to lib/n-vol

The next in a line of changes to break down stack.sh and make
it a bit more manageable.

Part of blueprint devstack-modular

Change-Id: I9f7ba23391851959412779f842934f5b26724713

Dean Troyer authored on 2012/08/18 03:12:38
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,118 @@
0
+# lib/n-vol
1
+# Install and start Nova volume service
2
+
3
+# Dependencies:
4
+# - functions
5
+# - KEYSTONE_AUTH_* must be defined
6
+# SERVICE_{TENANT_NAME|PASSWORD} must be defined
7
+
8
+# stack.sh
9
+# ---------
10
+# install_nvol
11
+# configure_nvol
12
+# init_nvol
13
+# start_nvol
14
+# stop_nvol
15
+# cleanup_nvol
16
+
17
+# Print the commands being run so that we can see the command that triggers
18
+# an error.  It is also useful for following along as the install occurs.
19
+set -o xtrace
20
+
21
+
22
+# Defaults
23
+# --------
24
+
25
+# Name of the LVM volume group to use/create for iscsi volumes
26
+VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
27
+VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
28
+
29
+
30
+# cleanup_nvol() - Remove residual data files, anything left over from previous
31
+# runs that a clean run would need to clean up
32
+function cleanup_nvol() {
33
+    # kill instances (nova)
34
+    # delete image files (glance)
35
+    # This function intentionally left blank
36
+    :
37
+}
38
+
39
+# configure_nvol() - Set config files, create data dirs, etc
40
+function configure_nvol() {
41
+    # sudo python setup.py deploy
42
+    # iniset $XXX_CONF ...
43
+    # This function intentionally left blank
44
+    :
45
+}
46
+
47
+# init_nvol() - Initialize databases, etc.
48
+function init_nvol() {
49
+    # Configure a default volume group called '`stack-volumes`' for the volume
50
+    # service if it does not yet exist.  If you don't wish to use a file backed
51
+    # volume group, create your own volume group called ``stack-volumes`` before
52
+    # invoking ``stack.sh``.
53
+    #
54
+    # By default, the backing file is 5G in size, and is stored in ``/opt/stack/data``.
55
+
56
+    if ! sudo vgs $VOLUME_GROUP; then
57
+        VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
58
+        # Only create if the file doesn't already exists
59
+        [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
60
+        DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
61
+        # Only create if the loopback device doesn't contain $VOLUME_GROUP
62
+        if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
63
+    fi
64
+
65
+    mkdir -p $NOVA_DIR/volumes
66
+
67
+    if sudo vgs $VOLUME_GROUP; then
68
+        if [[ "$os_PACKAGE" = "rpm" ]]; then
69
+            # RPM doesn't start the service
70
+            start_service tgtd
71
+        fi
72
+
73
+        # Remove nova iscsi targets
74
+        sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
75
+        # Clean out existing volumes
76
+        for lv in `sudo lvs --noheadings -o lv_name $VOLUME_GROUP`; do
77
+            # ``VOLUME_NAME_PREFIX`` prefixes the LVs we want
78
+            if [[ "${lv#$VOLUME_NAME_PREFIX}" != "$lv" ]]; then
79
+                sudo lvremove -f $VOLUME_GROUP/$lv
80
+            fi
81
+        done
82
+    fi
83
+}
84
+
85
+# install_nvol() - Collect source and prepare
86
+function install_nvol() {
87
+    # git clone xxx
88
+    # Install is handled when installing Nova
89
+    :
90
+}
91
+
92
+# start_nvol() - Start running processes, including screen
93
+function start_nvol() {
94
+    # Setup the tgt configuration file
95
+    if [[ ! -f /etc/tgt/conf.d/nova.conf ]]; then
96
+       sudo mkdir -p /etc/tgt/conf.d
97
+       echo "include $NOVA_DIR/volumes/*" | sudo tee /etc/tgt/conf.d/nova.conf
98
+    fi
99
+
100
+    if [[ "$os_PACKAGE" = "deb" ]]; then
101
+        # tgt in oneiric doesn't restart properly if tgtd isn't running
102
+        # do it in two steps
103
+        sudo stop tgt || true
104
+        sudo start tgt
105
+    else
106
+        restart_service tgtd
107
+    fi
108
+
109
+    screen_it n-vol "cd $NOVA_DIR && $NOVA_DIR/bin/nova-volume"
110
+}
111
+
112
+# stop_nvol() - Stop running processes (non-screen)
113
+function stop_nvol() {
114
+    # FIXME(dtroyer): stop only the n-vol screen window?
115
+
116
+    stop_service tgt
117
+}
... ...
@@ -249,6 +249,7 @@ sudo chown `whoami` $DATA_DIR
249 249
 
250 250
 # Get project function libraries
251 251
 source $TOP_DIR/lib/cinder
252
+source $TOP_DIR/lib/n-vol
252 253
 source $TOP_DIR/lib/ceilometer
253 254
 source $TOP_DIR/lib/heat
254 255
 
... ...
@@ -1757,57 +1758,7 @@ fi
1757 1757
 if is_service_enabled cinder; then
1758 1758
     init_cinder
1759 1759
 elif is_service_enabled n-vol; then
1760
-    # Configure a default volume group called '`stack-volumes`' for the volume
1761
-    # service if it does not yet exist.  If you don't wish to use a file backed
1762
-    # volume group, create your own volume group called ``stack-volumes`` before
1763
-    # invoking ``stack.sh``.
1764
-    #
1765
-    # By default, the backing file is 5G in size, and is stored in ``/opt/stack/data``.
1766
-
1767
-    if ! sudo vgs $VOLUME_GROUP; then
1768
-        VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
1769
-        # Only create if the file doesn't already exists
1770
-        [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
1771
-        DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
1772
-        # Only create if the loopback device doesn't contain $VOLUME_GROUP
1773
-        if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
1774
-    fi
1775
-
1776
-    if sudo vgs $VOLUME_GROUP; then
1777
-        if [[ "$os_PACKAGE" = "rpm" ]]; then
1778
-            # RPM doesn't start the service
1779
-            start_service tgtd
1780
-        fi
1781
-
1782
-        # Setup tgtd configuration files
1783
-        mkdir -p $NOVA_DIR/volumes
1784
-
1785
-        # Remove nova iscsi targets
1786
-        sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
1787
-        # Clean out existing volumes
1788
-        for lv in `sudo lvs --noheadings -o lv_name $VOLUME_GROUP`; do
1789
-            # ``VOLUME_NAME_PREFIX`` prefixes the LVs we want
1790
-            if [[ "${lv#$VOLUME_NAME_PREFIX}" != "$lv" ]]; then
1791
-                sudo lvremove -f $VOLUME_GROUP/$lv
1792
-            fi
1793
-        done
1794
-    fi
1795
-
1796
-    if [[ "$os_PACKAGE" = "deb" ]]; then
1797
-
1798
-        # Setup the tgt configuration file
1799
-        if [[ ! -f /etc/tgt/conf.d/nova.conf ]]; then
1800
-           sudo mkdir -p /etc/tgt/conf.d
1801
-           echo "include $NOVA_DIR/volumes/*" | sudo tee /etc/tgt/conf.d/nova.conf
1802
-        fi
1803
-
1804
-        # tgt in oneiric doesn't restart properly if tgtd isn't running
1805
-        # do it in two steps
1806
-        sudo stop tgt || true
1807
-        sudo start tgt
1808
-    else
1809
-        restart_service tgtd
1810
-    fi
1760
+    init_nvol
1811 1761
 fi
1812 1762
 
1813 1763
 # Support entry points installation of console scripts
... ...
@@ -2179,12 +2130,14 @@ fi
2179 2179
 # ``screen_it`` checks ``is_service_enabled``, it is not needed here
2180 2180
 screen_it n-cpu "cd $NOVA_DIR && sg libvirtd $NOVA_BIN_DIR/nova-compute"
2181 2181
 screen_it n-crt "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-cert"
2182
-screen_it n-vol "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-volume"
2183 2182
 screen_it n-net "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-network"
2184 2183
 screen_it n-sch "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-scheduler"
2185 2184
 screen_it n-novnc "cd $NOVNC_DIR && ./utils/nova-novncproxy --config-file $NOVA_CONF_DIR/$NOVA_CONF --web ."
2186 2185
 screen_it n-xvnc "cd $NOVA_DIR && ./bin/nova-xvpvncproxy --config-file $NOVA_CONF_DIR/$NOVA_CONF"
2187 2186
 screen_it n-cauth "cd $NOVA_DIR && ./bin/nova-consoleauth"
2187
+if is_service_enabled n-vol; then
2188
+    start_nvol
2189
+fi
2188 2190
 if is_service_enabled cinder; then
2189 2191
     start_cinder
2190 2192
 fi