Skip to content

Commit 47290ee

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Clean up local variable usage - cinder"
2 parents 03dd659 + e8a35ac commit 47290ee

2 files changed

Lines changed: 58 additions & 51 deletions

File tree

lib/cinder

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ TEMPEST_SERVICES+=,cinder
9696
# Source the enabled backends
9797
if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
9898
for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
99-
BE_TYPE=${be%%:*}
100-
BE_NAME=${be##*:}
101-
if [[ -r $CINDER_BACKENDS/${BE_TYPE} ]]; then
102-
source $CINDER_BACKENDS/${BE_TYPE}
99+
be_type=${be%%:*}
100+
be_name=${be##*:}
101+
if [[ -r $CINDER_BACKENDS/${be_type} ]]; then
102+
source $CINDER_BACKENDS/${be_type}
103103
fi
104104
done
105105
fi
@@ -120,7 +120,7 @@ function is_cinder_enabled {
120120
function cleanup_cinder {
121121
# ensure the volume group is cleared up because fails might
122122
# leave dead volumes in the group
123-
TARGETS=$(sudo tgtadm --op show --mode target)
123+
local targets=$(sudo tgtadm --op show --mode target)
124124
if [ $? -ne 0 ]; then
125125
# If tgt driver isn't running this won't work obviously
126126
# So check the response and restart if need be
@@ -130,11 +130,11 @@ function cleanup_cinder {
130130
else
131131
restart_service tgtd
132132
fi
133-
TARGETS=$(sudo tgtadm --op show --mode target)
133+
targets=$(sudo tgtadm --op show --mode target)
134134
fi
135135

136-
if [[ -n "$TARGETS" ]]; then
137-
iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
136+
if [[ -n "$targets" ]]; then
137+
local iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
138138
for i in "${iqn_list[@]}"; do
139139
echo removing iSCSI target: $i
140140
sudo tgt-admin --delete $i
@@ -148,11 +148,12 @@ function cleanup_cinder {
148148
fi
149149

150150
if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
151+
local be be_name be_type
151152
for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
152-
BE_TYPE=${be%%:*}
153-
BE_NAME=${be##*:}
154-
if type cleanup_cinder_backend_${BE_TYPE} >/dev/null 2>&1; then
155-
cleanup_cinder_backend_${BE_TYPE} ${BE_NAME}
153+
be_type=${be%%:*}
154+
be_name=${be##*:}
155+
if type cleanup_cinder_backend_${be_type} >/dev/null 2>&1; then
156+
cleanup_cinder_backend_${be_type} ${be_name}
156157
fi
157158
done
158159
fi
@@ -161,7 +162,7 @@ function cleanup_cinder {
161162
# configure_cinder_rootwrap() - configure Cinder's rootwrap
162163
function configure_cinder_rootwrap {
163164
# Set the paths of certain binaries
164-
CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
165+
local cinder_rootwrap=$(get_rootwrap_location cinder)
165166

166167
# Deploy new rootwrap filters files (owned by root).
167168
# Wipe any existing rootwrap.d files first
@@ -179,14 +180,14 @@ function configure_cinder_rootwrap {
179180
sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
180181
sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
181182
# Specify rootwrap.conf as first parameter to rootwrap
182-
ROOTWRAP_CSUDOER_CMD="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf *"
183+
ROOTWRAP_CSUDOER_CMD="$cinder_rootwrap $CINDER_CONF_DIR/rootwrap.conf *"
183184

184185
# Set up the rootwrap sudoers for cinder
185-
TEMPFILE=`mktemp`
186-
echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_CSUDOER_CMD" >$TEMPFILE
187-
chmod 0440 $TEMPFILE
188-
sudo chown root:root $TEMPFILE
189-
sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
186+
local tempfile=`mktemp`
187+
echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_CSUDOER_CMD" >$tempfile
188+
chmod 0440 $tempfile
189+
sudo chown root:root $tempfile
190+
sudo mv $tempfile /etc/sudoers.d/cinder-rootwrap
190191
}
191192

192193
# configure_cinder() - Set config files, create data dirs, etc
@@ -237,18 +238,19 @@ function configure_cinder {
237238
iniset $CINDER_CONF DEFAULT enable_v1_api true
238239

239240
if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
240-
enabled_backends=""
241-
default_name=""
241+
local enabled_backends=""
242+
local default_name=""
243+
local be be_name be_type
242244
for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
243-
BE_TYPE=${be%%:*}
244-
BE_NAME=${be##*:}
245-
if type configure_cinder_backend_${BE_TYPE} >/dev/null 2>&1; then
246-
configure_cinder_backend_${BE_TYPE} ${BE_NAME}
245+
be_type=${be%%:*}
246+
be_name=${be##*:}
247+
if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
248+
configure_cinder_backend_${be_type} ${be_name}
247249
fi
248-
if [[ -z "$default_name" ]]; then
249-
default_name=$BE_NAME
250+
if [[ -z "$default_type" ]]; then
251+
default_name=$be_type
250252
fi
251-
enabled_backends+=$BE_NAME,
253+
enabled_backends+=$be_name,
252254
done
253255
iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
254256
if [[ -n "$default_name" ]]; then
@@ -316,28 +318,28 @@ function configure_cinder {
316318
# Migrated from keystone_data.sh
317319
function create_cinder_accounts {
318320

319-
SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
320-
ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
321+
local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
322+
local admin_role=$(openstack role list | awk "/ admin / { print \$2 }")
321323

322324
# Cinder
323325
if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
324326

325-
CINDER_USER=$(get_or_create_user "cinder" \
326-
"$SERVICE_PASSWORD" $SERVICE_TENANT)
327-
get_or_add_user_role $ADMIN_ROLE $CINDER_USER $SERVICE_TENANT
327+
local cinder_user=$(get_or_create_user "cinder" \
328+
"$SERVICE_PASSWORD" $service_tenant)
329+
get_or_add_user_role $admin_role $cinder_user $service_tenant
328330

329331
if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
330332

331-
CINDER_SERVICE=$(get_or_create_service "cinder" \
333+
local cinder_service=$(get_or_create_service "cinder" \
332334
"volume" "Cinder Volume Service")
333-
get_or_create_endpoint $CINDER_SERVICE "$REGION_NAME" \
335+
get_or_create_endpoint $cinder_service "$REGION_NAME" \
334336
"$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
335337
"$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
336338
"$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
337339

338-
CINDER_V2_SERVICE=$(get_or_create_service "cinderv2" \
340+
local cinder_v2_service=$(get_or_create_service "cinderv2" \
339341
"volumev2" "Cinder Volume Service V2")
340-
get_or_create_endpoint $CINDER_V2_SERVICE "$REGION_NAME" \
342+
get_or_create_endpoint $cinder_v2_service "$REGION_NAME" \
341343
"$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
342344
"$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s" \
343345
"$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(tenant_id)s"
@@ -354,6 +356,7 @@ function create_cinder_cache_dir {
354356
}
355357

356358
# init_cinder() - Initialize database and volume group
359+
# Uses global ``NOVA_ENABLED_APIS``
357360
function init_cinder {
358361
# Force nova volumes off
359362
NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
@@ -367,11 +370,12 @@ function init_cinder {
367370
fi
368371

369372
if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
373+
local be be_name be_type
370374
for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
371-
BE_TYPE=${be%%:*}
372-
BE_NAME=${be##*:}
373-
if type init_cinder_backend_${BE_TYPE} >/dev/null 2>&1; then
374-
init_cinder_backend_${BE_TYPE} ${BE_NAME}
375+
be_type=${be%%:*}
376+
be_name=${be##*:}
377+
if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
378+
init_cinder_backend_${be_type} ${be_name}
375379
fi
376380
done
377381
fi
@@ -450,6 +454,7 @@ function start_cinder {
450454
# stop_cinder() - Stop running processes
451455
function stop_cinder {
452456
# Kill the cinder screen windows
457+
local serv
453458
for serv in c-api c-bak c-sch c-vol; do
454459
screen_stop $serv
455460
done
@@ -467,12 +472,13 @@ function stop_cinder {
467472
function create_volume_types {
468473
# Create volume types
469474
if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
475+
local be be_name be_type
470476
for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
471-
BE_TYPE=${be%%:*}
472-
BE_NAME=${be##*:}
473-
# openstack volume type create --property volume_backend_name="${BE_TYPE}" ${BE_NAME}
474-
cinder type-create ${BE_NAME} && \
475-
cinder type-key ${BE_NAME} set volume_backend_name="${BE_NAME}"
477+
be_type=${be%%:*}
478+
be_name=${be##*:}
479+
# openstack volume type create --property volume_backend_name="${be_type}" ${be_name}
480+
cinder type-create ${be_name} && \
481+
cinder type-key ${be_name} set volume_backend_name="${be_name}"
476482
done
477483
fi
478484
}

lib/cinder_backends/lvm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ function _clean_lvm_lv {
112112
local lv_prefix=$2
113113

114114
# Clean out existing volumes
115+
local lv
115116
for lv in $(sudo lvs --noheadings -o lv_name $vg 2>/dev/null); do
116117
# lv_prefix prefixes the LVs we want
117118
if [[ "${lv#$lv_prefix}" != "$lv" ]]; then
@@ -132,9 +133,9 @@ function _clean_lvm_backing_file {
132133
# of the backing file
133134
if [[ -z "$(sudo lvs --noheadings -o lv_name $vg 2>/dev/null)" ]]; then
134135
# if the backing physical device is a loop device, it was probably setup by devstack
135-
VG_DEV=$(sudo losetup -j $backing_file | awk -F':' '/backing-file/ { print $1}')
136-
if [[ -n "$VG_DEV" ]] && [[ -e "$VG_DEV" ]]; then
137-
sudo losetup -d $VG_DEV
136+
local vg_dev=$(sudo losetup -j $backing_file | awk -F':' '/backing-file/ { print $1}')
137+
if [[ -n "$vg_dev" ]] && [[ -e "$vg_dev" ]]; then
138+
sudo losetup -d $vg_dev
138139
rm -f $backing_file
139140
fi
140141
fi
@@ -159,11 +160,11 @@ function _create_cinder_volume_group {
159160
if [ -z "$VOLUME_BACKING_DEVICE" ]; then
160161
# Only create if the file doesn't already exists
161162
[[ -f $backing_file ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $backing_file
162-
DEV=`sudo losetup -f --show $backing_file`
163+
local vg_dev=`sudo losetup -f --show $backing_file`
163164

164165
# Only create if the loopback device doesn't contain $VOLUME_GROUP
165166
if ! sudo vgs $vg_name; then
166-
sudo vgcreate $vg_name $DEV
167+
sudo vgcreate $vg_name $vg_dev
167168
fi
168169
else
169170
sudo vgcreate $vg_name $VOLUME_BACKING_DEVICE

0 commit comments

Comments
 (0)