Support MultiStrOpt options in configuration file.
Fixed bug #1136964. 1. Added 3 ini functions to support MultiStrOpt: Function "iniset_multiline config-file section option value1 value2 value3 ..." sets a MultiStrOpt option in an ini file. Function "iniget_multiline config-file section option" gets the MultiStrOpt option values. Function "iniadd config-file section option value1 value2 value3..." appends an option without relacing the old values, which would result the option to be MultiStrOpt. 2. Modified the nova configuation to correctly enable notification for ceilometer. Change-Id: I1c27db1a6e58b35bc4428e761f40627988f69e37
This commit is contained in:
parent
0d71d1ec56
commit
239f3246ad
50
functions
50
functions
@ -553,6 +553,56 @@ $option = $value
|
||||
fi
|
||||
}
|
||||
|
||||
# Get a multiple line option from an INI file
|
||||
# iniget_multiline config-file section option
|
||||
function iniget_multiline() {
|
||||
local file=$1
|
||||
local section=$2
|
||||
local option=$3
|
||||
local values
|
||||
values=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { s/^$option[ \t]*=[ \t]*//gp; }" "$file")
|
||||
echo ${values}
|
||||
}
|
||||
|
||||
# Set a multiple line option in an INI file
|
||||
# iniset_multiline config-file section option value1 value2 valu3 ...
|
||||
function iniset_multiline() {
|
||||
local file=$1
|
||||
local section=$2
|
||||
local option=$3
|
||||
shift 3
|
||||
local values
|
||||
for v in $@; do
|
||||
# The later sed command inserts each new value in the line next to
|
||||
# the section identifier, which causes the values to be inserted in
|
||||
# the reverse order. Do a reverse here to keep the original order.
|
||||
values="$v ${values}"
|
||||
done
|
||||
if ! grep -q "^\[$section\]" "$file"; then
|
||||
# Add section at the end
|
||||
echo -e "\n[$section]" >>"$file"
|
||||
else
|
||||
# Remove old values
|
||||
sed -i -e "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ d; }" "$file"
|
||||
fi
|
||||
# Add new ones
|
||||
for v in $values; do
|
||||
sed -i -e "/^\[$section\]/ a\\
|
||||
$option = $v
|
||||
" "$file"
|
||||
done
|
||||
}
|
||||
|
||||
# Append a new option in an ini file without replacing the old value
|
||||
# iniadd config-file section option value1 value2 value3 ...
|
||||
function iniadd() {
|
||||
local file=$1
|
||||
local section=$2
|
||||
local option=$3
|
||||
shift 3
|
||||
local values="$(iniget_multiline $file $section $option) $@"
|
||||
iniset_multiline $file $section $option $values
|
||||
}
|
||||
|
||||
# is_service_enabled() checks if the service(s) specified as arguments are
|
||||
# enabled by the user in ``ENABLED_SERVICES``.
|
||||
|
3
lib/nova
3
lib/nova
@ -428,8 +428,7 @@ function create_nova_conf() {
|
||||
if is_service_enabled ceilometer; then
|
||||
iniset $NOVA_CONF DEFAULT instance_usage_audit "True"
|
||||
iniset $NOVA_CONF DEFAULT instance_usage_audit_period "hour"
|
||||
iniset $NOVA_CONF DEFAULT notification_driver "nova.openstack.common.notifier.rpc_notifier"
|
||||
iniset $NOVA_CONF DEFAULT notification_driver "ceilometer.compute.nova_notifier"
|
||||
iniset_multiline $NOVA_CONF DEFAULT notification_driver "nova.openstack.common.notifier.rpc_notifier" "ceilometer.compute.nova_notifier"
|
||||
fi
|
||||
|
||||
|
||||
|
@ -60,6 +60,10 @@ spaces = yes
|
||||
|
||||
[ddd]
|
||||
empty =
|
||||
|
||||
[eee]
|
||||
multi = foo1
|
||||
multi = foo2
|
||||
EOF
|
||||
|
||||
# Test with spaces
|
||||
@ -193,6 +197,34 @@ else
|
||||
echo "inicomment failed: $VAL"
|
||||
fi
|
||||
|
||||
# Test multiple line iniset/iniget
|
||||
iniset_multiline test.ini eee multi bar1 bar2
|
||||
|
||||
VAL=$(iniget_multiline test.ini eee multi)
|
||||
if [[ "$VAL" == "bar1 bar2" ]]; then
|
||||
echo "OK: iniset_multiline"
|
||||
else
|
||||
echo "iniset_multiline failed: $VAL"
|
||||
fi
|
||||
|
||||
# Test iniadd with exiting values
|
||||
iniadd test.ini eee multi bar3
|
||||
VAL=$(iniget_multiline test.ini eee multi)
|
||||
if [[ "$VAL" == "bar1 bar2 bar3" ]]; then
|
||||
echo "OK: iniadd"
|
||||
else
|
||||
echo "iniadd failed: $VAL"
|
||||
fi
|
||||
|
||||
# Test iniadd with non-exiting values
|
||||
iniadd test.ini eee non-multi foobar1 foobar2
|
||||
VAL=$(iniget_multiline test.ini eee non-multi)
|
||||
if [[ "$VAL" == "foobar1 foobar2" ]]; then
|
||||
echo "OK: iniadd with non-exiting value"
|
||||
else
|
||||
echo "iniadd with non-exsting failed: $VAL"
|
||||
fi
|
||||
|
||||
rm test.ini
|
||||
|
||||
# Enabling/disabling services
|
||||
|
Loading…
Reference in New Issue
Block a user