Revert "Single quote iniset argument in merge_config_file"

This reverts commit e2c9fee8ed.

We have decided that we don't want to support the json-style argument
as described by bug#1374118 (see thread at [1]).

This restores the old behavior of sending the argument in
double-quotes so environment variables get expanded.  As a bonus,
tests for this are added.

[1] http://lists.openstack.org/pipermail/openstack-dev/2014-October/049341.html

Change-Id: I9fc99f3716cc53366907878adb00ae6cf3898f14
Closes-Bug:#1386413
This commit is contained in:
Ian Wienand 2014-10-29 21:53:56 +11:00
parent 6fe32059de
commit f3bf8b6cc0
2 changed files with 24 additions and 17 deletions

View File

@ -82,8 +82,6 @@ function merge_config_file {
local matchgroup=$2 local matchgroup=$2
local configfile=$3 local configfile=$3
# note in the awk below, \x27 is ascii for ' -- this avoids
# having to do nasty quoting games
get_meta_section $file $matchgroup $configfile | \ get_meta_section $file $matchgroup $configfile | \
$CONFIG_AWK_CMD -v configfile=$configfile ' $CONFIG_AWK_CMD -v configfile=$configfile '
BEGIN { BEGIN {
@ -140,13 +138,13 @@ function merge_config_file {
for (attr_no = cfg_sec_attr_count[sno] - 1; attr_no >=0; attr_no--) { for (attr_no = cfg_sec_attr_count[sno] - 1; attr_no >=0; attr_no--) {
attr = cfg_sec_attr_name[sno, attr_no] attr = cfg_sec_attr_name[sno, attr_no]
if (cfg_attr_count[section, attr] == 1) if (cfg_attr_count[section, attr] == 1)
print "iniset " configfile " " section " " attr " \x27" cfg_attr[section, attr, 0] "\x27" print "iniset " configfile " " section " " attr " \"" cfg_attr[section, attr, 0] "\""
else { else {
# For multiline, invoke the ini routines in the reverse order # For multiline, invoke the ini routines in the reverse order
count = cfg_attr_count[section, attr] count = cfg_attr_count[section, attr]
print "iniset " configfile " " section " " attr " \x27" cfg_attr[section, attr, count - 1] "\x27" print "iniset " configfile " " section " " attr " \"" cfg_attr[section, attr, count - 1] "\""
for (l = count -2; l >= 0; l--) for (l = count -2; l >= 0; l--)
print "iniadd_literal " configfile " " section " " attr " \x27" cfg_attr[section, attr, l] "\x27" print "iniadd_literal " configfile " " section " " attr " \"" cfg_attr[section, attr, l] "\""
} }
} }
} }

View File

@ -92,9 +92,9 @@ attribute=value
[fff] [fff]
type=new type=new
[[test-quote|test-quote.conf]] [[test-env|test-env.conf]]
[foo] [foo]
foo="foo bar" "baz" foo=\${FOO_BAR_BAZ}
[[test5|test-equals.conf]] [[test5|test-equals.conf]]
[DEFAULT] [DEFAULT]
@ -126,9 +126,11 @@ cfg_item5 = 5555another
[[test-multiline|test-multiline.conf]] [[test-multiline|test-multiline.conf]]
[multi] [multi]
cfg_item1 = "ab":"cd", "ef": "gh" cfg_item1 = ab:cd:ef:gh
cfg_item1 = abcd cfg_item1 = abcd
cfg_item2 = efgh cfg_item2 = efgh
cfg_item2 = \${FOO_BAR_BAZ}
EOF EOF
echo -n "get_meta_section_files: test0 doesn't exist: " echo -n "get_meta_section_files: test0 doesn't exist: "
@ -236,14 +238,17 @@ check_result "$VAL" "$EXPECT_VAL"
echo -n "merge_config_file test-multiline: " echo -n "merge_config_file test-multiline: "
rm -f test-multiline.conf rm -f test-multiline.conf
FOO_BAR_BAZ="foo bar baz"
merge_config_file test.conf test-multiline test-multiline.conf merge_config_file test.conf test-multiline test-multiline.conf
VAL=$(cat test-multiline.conf) VAL=$(cat test-multiline.conf)
EXPECT_VAL=' EXPECT_VAL='
[multi] [multi]
cfg_item1 = "ab":"cd", "ef": "gh" cfg_item1 = ab:cd:ef:gh
cfg_item1 = abcd cfg_item1 = abcd
cfg_item2 = efgh' cfg_item2 = efgh
cfg_item2 = foo bar baz'
check_result "$VAL" "$EXPECT_VAL" check_result "$VAL" "$EXPECT_VAL"
unset FOO_BAR_BAZ
echo -n "merge_config_group test2: " echo -n "merge_config_group test2: "
rm test2a.conf rm test2a.conf
@ -275,14 +280,16 @@ EXPECT_VAL="
attribute = value" attribute = value"
check_result "$VAL" "$EXPECT_VAL" check_result "$VAL" "$EXPECT_VAL"
echo -n "merge_config_file test-quote: " echo -n "merge_config_file test-env: "
rm -f test-quote.conf rm -f test-env.conf
merge_config_file test.conf test-quote test-quote.conf FOO_BAR_BAZ="foo bar baz"
VAL=$(cat test-quote.conf) merge_config_file test.conf test-env test-env.conf
VAL=$(cat test-env.conf)
EXPECT_VAL=' EXPECT_VAL='
[foo] [foo]
foo = "foo bar" "baz"' foo = foo bar baz'
check_result "$VAL" "$EXPECT_VAL" check_result "$VAL" "$EXPECT_VAL"
unset FOO_BAR_BAZ
echo -n "merge_config_group test4 variable filename: " echo -n "merge_config_group test4 variable filename: "
setup_test4 setup_test4
@ -332,6 +339,8 @@ EXPECT_VAL="
servers = 10.11.12.13:80" servers = 10.11.12.13:80"
check_result "$VAL" "$EXPECT_VAL" 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 test-colon.conf rm -f test.conf test1c.conf test2a.conf \
rm -f test-multiline.conf test-multi-sections.conf test-space.conf test-equals.conf test-strip.conf \
test-colon.conf test-env.conf test-multiline.conf \
test-multi-sections.conf
rm -rf test-etc rm -rf test-etc