Skip to content

Commit 73de4a4

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Provide an error message on bogus config file spec"
2 parents c9f6f11 + 85f42f6 commit 73de4a4

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

inc/meta-config

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function merge_config_file {
9292
local real_configfile
9393
real_configfile=$(eval echo $configfile)
9494
if [ ! -f $real_configfile ]; then
95-
touch $real_configfile
95+
touch $real_configfile || die $LINENO "could not create config file $real_configfile ($configfile)"
9696
fi
9797

9898
get_meta_section $file $matchgroup $configfile | \
@@ -178,8 +178,18 @@ function merge_config_group {
178178
local configfile group
179179
for group in $matchgroups; do
180180
for configfile in $(get_meta_section_files $localfile $group); do
181-
if [[ -d $(dirname $(eval "echo $configfile")) ]]; then
181+
local realconfigfile
182+
local dir
183+
184+
realconfigfile=$(eval "echo $configfile")
185+
if [[ -z $realconfigfile ]]; then
186+
die $LINENO "bogus config file specification: $configfile is undefined"
187+
fi
188+
dir=$(dirname $realconfigfile)
189+
if [[ -d $dir ]]; then
182190
merge_config_file $localfile $group $configfile
191+
else
192+
die $LINENO "bogus config file specification $configfile ($configfile=$realconfigfile, $dir is not a directory)"
183193
fi
184194
done
185195
done

tests/test_meta_config.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ function check_result {
2323
fi
2424
}
2525

26+
# mock function-common:die so that it does not
27+
# interupt our test script
28+
function die {
29+
exit -1
30+
}
31+
2632
TEST_1C_ADD="[eee]
2733
type=new
2834
multi = foo2"
@@ -110,6 +116,15 @@ attr = strip_trailing_space
110116
[DEFAULT]
111117
servers=10.11.12.13:80
112118
119+
[[test8|/permission-denied.conf]]
120+
foo=bar
121+
122+
[[test9|\$UNDEF]]
123+
foo=bar
124+
125+
[[test10|does-not-exist-dir/test.conf]]
126+
foo=bar
127+
113128
[[test-multi-sections|test-multi-sections.conf]]
114129
[sec-1]
115130
cfg_item1 = abcd
@@ -340,6 +355,36 @@ EXPECT_VAL="
340355
servers = 10.11.12.13:80"
341356
check_result "$VAL" "$EXPECT_VAL"
342357

358+
echo "merge_config_file test8 non-touchable conf file: "
359+
set +e
360+
# function is expected to fail and exit, running it
361+
# in a subprocess to let this script proceed
362+
(merge_config_file test.conf test8 /permission-denied.conf)
363+
VAL=$?
364+
EXPECT_VAL=255
365+
check_result "$VAL" "$EXPECT_VAL"
366+
set -e
367+
368+
echo -n "merge_config_group test9 undefined conf file: "
369+
set +e
370+
# function is expected to fail and exit, running it
371+
# in a subprocess to let this script proceed
372+
(merge_config_group test.conf test9)
373+
VAL=$?
374+
EXPECT_VAL=255
375+
check_result "$VAL" "$EXPECT_VAL"
376+
set -e
377+
378+
echo -n "merge_config_group test10 not directory: "
379+
set +e
380+
# function is expected to fail and exit, running it
381+
# in a subprocess to let this script proceed
382+
(merge_config_group test.conf test10)
383+
VAL=$?
384+
EXPECT_VAL=255
385+
check_result "$VAL" "$EXPECT_VAL"
386+
set -e
387+
343388
rm -f test.conf test1c.conf test2a.conf \
344389
test-space.conf test-equals.conf test-strip.conf \
345390
test-colon.conf test-env.conf test-multiline.conf \

0 commit comments

Comments
 (0)