local.conf processing doesn't handle '=' in values

When attempting to add a libvirt section with a volume_drivers entry
to $NOVA_CONF, via a post-config block in the local.conf file, I
encountered problems; the value for this attribute takes the form

    driver=python.import.path.to.driver

but the value actually populated in the $NOVA_CONF was truncated at the
equals.

Taking the iscsi driver setting specified in the official nova.conf
documentation as an example, if I have the following in my local.conf
file:

[[post-config|$NOVA_CONF]]
[libvirt]
volume_drivers = iscsi=nova.virt.libvirt.volume.LibvirtISCSIVolumeDriver

I will see that the generated $NOVA_CONF has the following:

[libvirt]
volume_driver = iscsi

This occurs because the existing handling for a post-config setion, as
implemented in merge_config_file(), splits the line on the equals sign,
and then uses the first and seconds elements of the resulting array as
attribute name and value respectively.

However when an equals occurs as part of the value this results in the
value being truncated at the first equals in the value.

The fix I've implemented, based upon review feedback, extracts the
contents of $0 before the first equals as the attr name, and extracts
the remainder after the equals as the value. Then it strips the leading
and trailing whitespaces from both as appropriate.

I've also added test5 to tests/test_config.sh to test for, and verify,
correct operation when this scenario is encountered.  Similarly I've
added test6 to ensure that trailing spaces in values are stripped
correctly.

Change-Id: Id0cb1e6e1cece21bc5dbf427c4d756af86fbd927
Closes-Bug: #1374482
This commit is contained in:
Fergal Mc Carthy 2014-10-09 16:16:42 -04:00 committed by Robert Li
parent 284492cc11
commit cc87c2871d
2 changed files with 41 additions and 3 deletions

View File

@ -96,8 +96,17 @@ function merge_config_file {
next next
} }
/^[^ \t]+/ { /^[^ \t]+/ {
split($0, d, " *= *") # get offset of first '=' in $0
print "iniset " configfile " " section " " d[1] " \x27" d[2] "\x27 " eq_idx = index($0, "=")
# extract attr & value from $0
attr = substr($0, 1, eq_idx - 1)
value = substr($0, eq_idx + 1)
# only need to strip trailing whitespace from attr
sub(/[ \t]*$/, "", attr)
# need to strip leading & trailing whitespace from value
sub(/^[ \t]*/, "", value)
sub(/[ \t]*$/, "", value)
print "iniset " configfile " " section " " attr " \x27" value "\x27"
} }
' | while read a; do eval "$a"; done ' | while read a; do eval "$a"; done

View File

@ -95,6 +95,15 @@ type=new
[[test-quote|test-quote.conf]] [[test-quote|test-quote.conf]]
[foo] [foo]
foo="foo bar" "baz" foo="foo bar" "baz"
[[test5|test-equals.conf]]
[DEFAULT]
drivers = driver=python.import.path.Driver
[[test6|test-strip.conf]]
[DEFAULT]
# next line has trailing space
attr = strip_trailing_space
EOF EOF
echo -n "get_meta_section_files: test0 doesn't exist: " echo -n "get_meta_section_files: test0 doesn't exist: "
@ -238,5 +247,25 @@ EXPECT_VAL="
type = new" type = new"
check_result "$VAL" "$EXPECT_VAL" check_result "$VAL" "$EXPECT_VAL"
rm -f test.conf test1c.conf test2a.conf test-quote.conf test-space.conf echo -n "merge_config_file test5 equals in value: "
rm -f test-equals.conf
merge_config_file test.conf test5 test-equals.conf
VAL=$(cat test-equals.conf)
# iniset adds a blank line if it creates the file...
EXPECT_VAL="
[DEFAULT]
drivers = driver=python.import.path.Driver"
check_result "$VAL" "$EXPECT_VAL"
echo -n "merge_config_file test6 value stripped: "
rm -f test-strip.conf
merge_config_file test.conf test6 test-strip.conf
VAL=$(cat test-strip.conf)
# iniset adds a blank line if it creates the file...
EXPECT_VAL="
[DEFAULT]
attr = strip_trailing_space"
check_result "$VAL" "$EXPECT_VAL"
rm -f test.conf test1c.conf test2a.conf test-quote.conf test-space.conf test-equals.conf test-strip.conf
rm -rf test-etc rm -rf test-etc