Files
f70c914319c2617ebc3249b757ef0ef0f1bb012f
devstack /inc /meta-config

224 lines
7.5 KiB
Plaintext
Raw Normal View History

#
#
# Support for DevStack's local.conf meta-config sections
#
#
# CONFIG_AWK_CMD is defined, default is ``awk``
# Meta-config files contain multiple INI-style configuration files
# using a specific new section header to delimit them:
#
# [[group-name|file-name]]
#
# group-name refers to the group of configuration file changes to be processed
#
# file-name is the destination of the config file
# Save trace setting
# Allow the awk command to be overridden on legacy platforms
CONFIG_AWK_CMD=${CONFIG_AWK_CMD:-awk}
# Get the section for the specific group and config file
# get_meta_section infile group configfile
local matchgroup=2ドル
local configfile=3ドル
[[ -r $file ]] || return 0
[[ -z $configfile ]] && return 0
$CONFIG_AWK_CMD -v matchgroup=$matchgroup -v configfile=$configfile '
BEGIN { group = "" }
split(1,ドル a, "|");
if (a[1] == matchgroup && a[2] == configfile) {
group=a[1]
group=""
}
next
}
{
if (group != "")
print 0ドル
}
' $file
}
# Get a list of config files for a specific group
# get_meta_section_files infile group
local matchgroup=2ドル
[[ -r $file ]] || return 0
$CONFIG_AWK_CMD -v matchgroup=$matchgroup '
gsub("[][]", "", 1ドル);
split(1,ドル a, "|");
if (a[1] == matchgroup)
print a[2]
}
}
# Merge the contents of a meta-config file into its destination config file
# If configfile does not exist it will be created.
# merge_config_file infile group configfile
local matchgroup=2ドル
local configfile=3ドル
# created in the mega-awk below is "eval"ed too, so we just leave
# it alone.
real_configfile=$(eval echo $configfile)
$CONFIG_AWK_CMD -v configfile=$configfile '
section = ""
last_section = ""
section_count = 0
}
gsub("[][]", "", 1ドル);
section=1ドル
next
}
/^ *\#/ {
next
}
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
2014年10月09日 16:16:42 -04:00
# get offset of first '=' in 0ドル
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)
# cfg_attr_count: number of config lines per [section, attr]
# cfg_attr: three dimensional array to keep all the config lines per [section, attr]
# cfg_section: keep the section names in the same order as they appear in local.conf
# cfg_sec_attr_name: keep the attr names in the same order as they appear in local.conf
if (! (section, attr) in cfg_attr_count) {
if (section != last_section) {
cfg_section[section_count++] = section
last_section = section
}
attr_count = cfg_sec_attr_count[section_count - 1]++
cfg_sec_attr_name[section_count - 1, attr_count] = attr
cfg_attr[section, attr, 0] = value
cfg_attr_count[section, attr] = 1
} else {
lno = cfg_attr_count[section, attr]++
cfg_attr[section, attr, lno] = value
}
}
END {
# Process each section in order
for (sno = 0; sno < section_count; sno++) {
section = cfg_section[sno]
# The ini routines simply append a config item immediately
# after the section header. To keep the same order as defined
# in local.conf, invoke the ini routines in the reverse order
for (attr_no = cfg_sec_attr_count[sno] - 1; attr_no >=0; attr_no--) {
attr = cfg_sec_attr_name[sno, attr_no]
if (cfg_attr_count[section, attr] == 1)
# For multiline, invoke the ini routines in the reverse order
count = cfg_attr_count[section, attr]
}
}
' | while read a; do eval "$a"; done
}
# Merge all of the files specified by group
# merge_config_group infile group [group ...]
local matchgroups=$@
[[ -r $localfile ]] || return 0
for configfile in $(get_meta_section_files $localfile $group); do
local dir
realconfigfile=$(eval "echo $configfile")
if [[ -z $realconfigfile ]]; then
break
dir=$(dirname $realconfigfile)
if [[ -d $dir ]]; then
die $LINENO "bogus config file specification $configfile ($configfile=$realconfigfile, $dir is not a directory)"
done
done
}
local configfile=1ドル # top_dir/local.conf
local localrcfile=2ドル # top_dir/localrc
local localautofile=3ドル # top_dir/.localrc.auto
if [[ -r $configfile ]]; then
LRC=$(get_meta_section_files $configfile local)
for lfile in $LRC; do
if [[ "$lfile" == "localrc" ]]; then
if [[ -r $localrcfile ]]; then
echo "localrc and local.conf:[[local]] both exist, using localrc"
else
echo "# Generated file, do not edit" >$localautofile
get_meta_section $configfile local $lfile >>$localautofile
fi
fi
done
fi
}
# Restore xtrace
# Local variables:
# mode: shell-script
# End: