Skip to content

Commit 67787e6

Browse files
Dean TroyerJohn Griffith
authored andcommitted
Add cinder support
* using the new functional pattern: cinder_XXX functions are in lib/cinder * enable with 'c-api,c-sch,c-vol' in ENABLED_SERVICES, n-vol is still the default * exercises/volumes.sh runs for cinder and n-vol * move config to /etc/cinder * change volume_group to stack-volumes; this also renames the backing file to /opt/stack/data/stack-volumes-backing-file. * removes osapi_volume from nova.conf enabled_apis * integrates cinder + keystone * launches c-sch * tweaks for multi node * move enabled_apis substitution to init_cinder 18Jun2010 * restored & rebased * update setup.py to use setup_develop() in lib/cinder Change-Id: I1e1aa4387031c56e4fa239eb73bea2af8cef0e38
1 parent 1c620df commit 67787e6

File tree

11 files changed

+248
-10
lines changed

11 files changed

+248
-10
lines changed

exerciserc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ export RUNNING_TIMEOUT=${RUNNING_TIMEOUT:-$(($BOOT_TIMEOUT + $ACTIVE_TIMEOUT))}
2020

2121
# Max time to wait for a vm to terminate
2222
export TERMINATE_TIMEOUT=${TERMINATE_TIMEOUT:-30}
23+
24+
# Max time to wait for a euca-volume command to propogate
25+
export VOLUME_TIMEOUT=${VOLUME_TIMEOUT:-30}
26+
27+
# Max time to wait for a euca-delete command to propogate
28+
export VOLUME_DELETE_TIMEOUT=${SNAPSHOT_DELETE_TIMEOUT:-60}

exercises/euca.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ set -o xtrace
2424
# Keep track of the current directory
2525
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
2626
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
27+
VOLUME_ZONE=cinder
28+
VOLUME_SIZE=1
29+
ATTACH_DEVICE=/dev/vdc
2730

2831
# Import common functions
2932
source $TOP_DIR/functions

exercises/volumes.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ source $TOP_DIR/openrc
3333
# Import exercise configuration
3434
source $TOP_DIR/exerciserc
3535

36+
# If cinder or n-vol are not enabled we exit with exitcode 55 which mean
37+
# exercise is skipped.
38+
is_service_enabled cinder n-vol || exit 55
39+
3640
# Instance type to create
3741
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
3842

files/apts/cinder

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tgt
2+
lvm2

files/keystone_data.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# service nova admin, [ResellerAdmin (swift only)]
1010
# service quantum admin # if enabled
1111
# service swift admin # if enabled
12+
# service cinder admin # if enabled
1213
# demo admin admin
1314
# demo demo Member, anotherrole
1415
# invisible_to_admin demo Member
@@ -128,3 +129,13 @@ if [[ "$ENABLED_SERVICES" =~ "tempest" ]]; then
128129
--email=alt_demo@example.com)
129130
keystone user-role-add --user $ALT_DEMO_USER --role $MEMBER_ROLE --tenant_id $ALT_DEMO_TENANT
130131
fi
132+
133+
if [[ "$ENABLED_SERVICES" =~ "cinder" ]]; then
134+
CINDER_USER=$(get_id keystone user-create --name=cinder \
135+
--pass="$SERVICE_PASSWORD" \
136+
--tenant_id $SERVICE_TENANT \
137+
--email=cinder@example.com)
138+
keystone user-role-add --tenant_id $SERVICE_TENANT \
139+
--user_id $CINDER_USER \
140+
--role_id $ADMIN_ROLE
141+
fi

files/rpms/cinder

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lvm2
2+
scsi-target-utils

functions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ function is_service_enabled() {
253253
for service in ${services}; do
254254
[[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0
255255
[[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0
256+
[[ ${service} == "cinder" && ${ENABLED_SERVICES} =~ "c-" ]] && return 0
256257
[[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0
257258
[[ ${service} == "quantum" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0
258259
done

lib/cinder

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# lib/cinder
2+
# Install and start Cinder volume service
3+
4+
# Dependencies:
5+
# - functions
6+
# - KEYSTONE_AUTH_* must be defined
7+
# SERVICE_{TENANT_NAME|PASSWORD} must be defined
8+
9+
# stack.sh
10+
# ---------
11+
# install_XXX
12+
# configure_XXX
13+
# init_XXX
14+
# start_XXX
15+
# stop_XXX
16+
# cleanup_XXX
17+
18+
# Print the commands being run so that we can see the command that triggers
19+
# an error. It is also useful for following along as the install occurs.
20+
set -o xtrace
21+
22+
23+
# Defaults
24+
# --------
25+
26+
# set up default directories
27+
CINDER_DIR=$DEST/cinder
28+
CINDERCLIENT_DIR=$DEST/python-cinderclient
29+
CINDER_CONF_DIR=/etc/cinder
30+
CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
31+
32+
# Name of the lvm volume group to use/create for iscsi volumes
33+
VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
34+
VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
35+
36+
# cleanup_cinder() - Remove residual data files, anything left over from previous
37+
# runs that a clean run would need to clean up
38+
function cleanup_cinder() {
39+
# This function intentionally left blank
40+
:
41+
}
42+
43+
# configure_cinder() - Set config files, create data dirs, etc
44+
function configure_cinder() {
45+
setup_develop $CINDER_DIR
46+
setup_develop $CINDERCLIENT_DIR
47+
48+
if [[ ! -d $CINDER_CONF_DIR ]]; then
49+
sudo mkdir -p $CINDER_CONF_DIR
50+
fi
51+
sudo chown `whoami` $CINDER_CONF_DIR
52+
53+
cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
54+
55+
CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
56+
cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
57+
iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
58+
iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
59+
iniset $CINDER_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
60+
iniset $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
61+
iniset $CINDER_API_PASTE_INI filter:authtoken admin_user cinder
62+
iniset $CINDER_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
63+
64+
cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
65+
iniset $CINDER_CONF DEFAULT auth_strategy keystone
66+
iniset $CINDER_CONF DEFAULT verbose True
67+
iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
68+
iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
69+
iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
70+
iniset $CINDER_CONF DEFAULT sql_connection $BASE_SQL_CONN/cinder?charset=utf8
71+
iniset $CINDER_CONF DEFAULT rabbit_host $RABBIT_HOST
72+
iniset $CINDER_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
73+
iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
74+
}
75+
76+
# init_cinder() - Initialize database and volume group
77+
function init_cinder() {
78+
# Force nova volumes off
79+
NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
80+
81+
if is_service_enabled mysql; then
82+
# (re)create cinder database
83+
mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS cinder;'
84+
mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE cinder;'
85+
86+
# (re)create cinder database
87+
$CINDER_DIR/bin/cinder-manage db sync
88+
fi
89+
90+
if is_service_enabled c-vol; then
91+
# Configure a default volume group called '`stack-volumes`' for the volume
92+
# service if it does not yet exist. If you don't wish to use a file backed
93+
# volume group, create your own volume group called ``stack-volumes`` before
94+
# invoking ``stack.sh``.
95+
#
96+
# By default, the backing file is 2G in size, and is stored in ``/opt/stack/data``.
97+
98+
if ! sudo vgs $VOLUME_GROUP; then
99+
VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
100+
VOLUME_BACKING_FILE_SIZE=${VOLUME_BACKING_FILE_SIZE:-2052M}
101+
# Only create if the file doesn't already exists
102+
[[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
103+
DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
104+
# Only create if the loopback device doesn't contain $VOLUME_GROUP
105+
if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
106+
fi
107+
108+
if sudo vgs $VOLUME_GROUP; then
109+
# Remove iscsi targets
110+
sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
111+
# Clean out existing volumes
112+
for lv in `sudo lvs --noheadings -o lv_name $VOLUME_GROUP`; do
113+
# VOLUME_NAME_PREFIX prefixes the LVs we want
114+
if [[ "${lv#$VOLUME_NAME_PREFIX}" != "$lv" ]]; then
115+
sudo lvremove -f $VOLUME_GROUP/$lv
116+
fi
117+
done
118+
fi
119+
fi
120+
}
121+
122+
# install_cinder() - Collect source and prepare
123+
function install_cinder() {
124+
git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
125+
git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
126+
}
127+
128+
# start_cinder() - Start running processes, including screen
129+
function start_cinder() {
130+
if is_service_enabled c-vol; then
131+
if [[ "$os_PACKAGE" = "deb" ]]; then
132+
# tgt in oneiric doesn't restart properly if tgtd isn't running
133+
# do it in two steps
134+
sudo stop tgt || true
135+
sudo start tgt
136+
else
137+
# bypass redirection to systemctl during restart
138+
sudo /sbin/service --skip-redirect tgtd restart
139+
fi
140+
fi
141+
142+
screen_it c-api "cd $CINDER_DIR && $CINDER_DIR/bin/cinder-api --config-file $CINDER_CONF"
143+
screen_it c-vol "cd $CINDER_DIR && $CINDER_DIR/bin/cinder-volume --config-file $CINDER_CONF"
144+
screen_it c-sch "cd $CINDER_DIR && $CINDER_DIR/bin/cinder-scheduler --config-file $CINDER_CONF"
145+
}
146+
147+
# stop_cinder() - Stop running processes (non-screen)
148+
function stop_cinder() {
149+
# FIXME(dtroyer): stop only the cinder screen window?
150+
151+
if is_service_enabled c-vol; then
152+
stop_service tgt
153+
fi
154+
}

stack.sh

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ else
112112
NOVA_ROOTWRAP=/usr/bin/nova-rootwrap
113113
fi
114114

115+
# ``stack.sh`` keeps function libraries here
116+
# Make sure ``$TOP_DIR/lib`` directory is present
117+
if [ ! -d $TOP_DIR/lib ]; then
118+
echo "ERROR: missing devstack/lib - did you grab more than just stack.sh?"
119+
exit 1
120+
fi
121+
115122
# stack.sh keeps the list of ``apt`` and ``pip`` dependencies in external
116123
# files, along with config templates and other useful files. You can find these
117124
# in the ``files`` directory (next to this script). We will reference this
@@ -130,6 +137,12 @@ if type -p screen >/dev/null && screen -ls | egrep -q "[0-9].stack"; then
130137
exit 1
131138
fi
132139

140+
# Make sure we only have one volume service enabled.
141+
if is_service_enabled cinder && is_service_enabled n-vol; then
142+
echo "ERROR: n-vol and cinder must not be enabled at the same time"
143+
exit 1
144+
fi
145+
133146
# OpenStack is designed to be run as a regular user (Horizon will fail to run
134147
# as root, since apache refused to startup serve content from root user). If
135148
# ``stack.sh`` is run as **root**, it automatically creates a **stack** user with
@@ -201,6 +214,19 @@ fi
201214
# prerequisites and initialize ``$DEST``.
202215
OFFLINE=`trueorfalse False $OFFLINE`
203216

217+
# Destination path for service data
218+
DATA_DIR=${DATA_DIR:-${DEST}/data}
219+
sudo mkdir -p $DATA_DIR
220+
sudo chown `whoami` $DATA_DIR
221+
222+
223+
# Projects
224+
# --------
225+
226+
# Get project function libraries
227+
source $TOP_DIR/lib/cinder
228+
229+
204230
# Set the destination directories for openstack projects
205231
NOVA_DIR=$DEST/nova
206232
HORIZON_DIR=$DEST/horizon
@@ -234,7 +260,7 @@ M_HOST=${M_HOST:-localhost}
234260
M_MAC_RANGE=${M_MAC_RANGE:-FE-EE-DD-00-00-00/24}
235261

236262
# Name of the lvm volume group to use/create for iscsi volumes
237-
VOLUME_GROUP=${VOLUME_GROUP:-nova-volumes}
263+
VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
238264
VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
239265
INSTANCE_NAME_PREFIX=${INSTANCE_NAME_PREFIX:-instance-}
240266

@@ -607,6 +633,10 @@ function get_packages() {
607633
if [[ ! $file_to_parse =~ glance ]]; then
608634
file_to_parse="${file_to_parse} glance"
609635
fi
636+
elif [[ $service == c-* ]]; then
637+
if [[ ! $file_to_parse =~ cinder ]]; then
638+
file_to_parse="${file_to_parse} cinder"
639+
fi
610640
elif [[ $service == n-* ]]; then
611641
if [[ ! $file_to_parse =~ nova ]]; then
612642
file_to_parse="${file_to_parse} nova"
@@ -704,10 +734,12 @@ if is_service_enabled m-svc; then
704734
# melange
705735
git_clone $MELANGE_REPO $MELANGE_DIR $MELANGE_BRANCH
706736
fi
707-
708737
if is_service_enabled melange; then
709738
git_clone $MELANGECLIENT_REPO $MELANGECLIENT_DIR $MELANGECLIENT_BRANCH
710739
fi
740+
if is_service_enabled cinder; then
741+
install_cinder
742+
fi
711743

712744

713745
# Initialization
@@ -743,6 +775,9 @@ fi
743775
if is_service_enabled melange; then
744776
setup_develop $MELANGECLIENT_DIR
745777
fi
778+
if is_service_enabled cinder; then
779+
configure_cinder
780+
fi
746781

747782
# Do this _after_ glance is installed to override the old binary
748783
setup_develop $GLANCECLIENT_DIR
@@ -1643,17 +1678,18 @@ fi
16431678
# Volume Service
16441679
# --------------
16451680
1646-
if is_service_enabled n-vol; then
1647-
#
1648-
# Configure a default volume group called 'nova-volumes' for the nova-volume
1681+
if is_service_enabled cinder; then
1682+
init_cinder
1683+
elif is_service_enabled n-vol; then
1684+
# Configure a default volume group called '`stack-volumes`' for the volume
16491685
# service if it does not yet exist. If you don't wish to use a file backed
1650-
# volume group, create your own volume group called 'nova-volumes' before
1651-
# invoking stack.sh.
1686+
# volume group, create your own volume group called ``stack-volumes`` before
1687+
# invoking ``stack.sh``.
16521688
#
1653-
# By default, the backing file is 2G in size, and is stored in /opt/stack.
1689+
# By default, the backing file is 2G in size, and is stored in ``/opt/stack/data``.
16541690
16551691
if ! sudo vgs $VOLUME_GROUP; then
1656-
VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DEST/nova-volumes-backing-file}
1692+
VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
16571693
VOLUME_BACKING_FILE_SIZE=${VOLUME_BACKING_FILE_SIZE:-2052M}
16581694
# Only create if the file doesn't already exists
16591695
[[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
@@ -1801,6 +1837,10 @@ else
18011837
add_nova_opt "logging_context_format_string=%(asctime)s %(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s] %(instance)s%(message)s"
18021838
fi
18031839
1840+
# If cinder is enabled, use the cinder volume driver
1841+
if is_service_enabled cinder; then
1842+
add_nova_opt "volume_api_class=nova.volume.cinder.API"
1843+
fi
18041844
18051845
# Provide some transition from EXTRA_FLAGS to EXTRA_OPTS
18061846
if [[ -z "$EXTRA_OPTS" && -n "$EXTRA_FLAGS" ]]; then
@@ -1968,6 +2008,7 @@ fi
19682008
19692009
# launch the nova-api and wait for it to answer before continuing
19702010
if is_service_enabled n-api; then
2011+
add_nova_opt "enabled_apis=$NOVA_ENABLED_APIS"
19712012
screen_it n-api "cd $NOVA_DIR && $NOVA_DIR/bin/nova-api"
19722013
echo "Waiting for nova-api to start..."
19732014
if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://127.0.0.1:8774; do sleep 1; done"; then
@@ -2003,6 +2044,9 @@ screen_it n-sch "cd $NOVA_DIR && $NOVA_DIR/bin/nova-scheduler"
20032044
screen_it n-novnc "cd $NOVNC_DIR && ./utils/nova-novncproxy --config-file $NOVA_CONF_DIR/$NOVA_CONF --web ."
20042045
screen_it n-xvnc "cd $NOVA_DIR && ./bin/nova-xvpvncproxy --config-file $NOVA_CONF_DIR/$NOVA_CONF"
20052046
screen_it n-cauth "cd $NOVA_DIR && ./bin/nova-consoleauth"
2047+
if is_service_enabled cinder; then
2048+
start_cinder
2049+
fi
20062050
screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
20072051
screen_it swift "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONFIG_DIR}/proxy-server.conf -v"
20082052

stackrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ RC_DIR=$(cd $(dirname "$BASH_SOURCE") && pwd)
99
# ENABLED_SERVICES="$ENABLED_SERVICES,swift"
1010
ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-net,n-vol,n-sch,n-novnc,n-xvnc,n-cauth,horizon,mysql,rabbit
1111

12+
# Set the default Nova APIs to enable
13+
NOVA_ENABLED_APIS=ec2,osapi_compute,osapi_volume,metadata
14+
15+
# volume service
16+
CINDER_REPO=https://github.com/openstack/cinder
17+
CINDER_BRANCH=master
18+
19+
# volume client
20+
CINDERCLIENT_REPO=https://github.com/openstack/python-cinderclient
21+
CINDERCLIENT_BRANCH=master
22+
1223
# compute service
1324
NOVA_REPO=https://github.com/openstack/nova.git
1425
NOVA_BRANCH=master

0 commit comments

Comments
 (0)