2f9e4163f4
This patch adds the opts.py file to the tree as a fix for deployers that package cinder. The opts.py file is no longer being deleted right away by generate_sample.sh after the cinder.sample.conf is being generated. This patch also introduces a pep8 check to make sure that the opts.py file is up to date, so that it will catch when new opts get added to Cinder without the opts.py being updated. To support the ability to keep and check the opts file a number of changes were needed in the check_uptodate.sh script as well as the generate_sample.sh script: - check_uptodate now takes --checkopts instead of --checkonly When checkopts is used the opts.py file is generated using the current code and the generated file is compared to the existing file. The check fails if there are differences. - generate_sample now has the --nosamplefile option. When this option is used, only the opts.py file is generated. The oslo-config-generator code is skipped so no sample file is created. - generate_sample also has some coding style consistency changes. - Added the 'genopts' option to tox so users can generate a fresh opts.py without a sample file when necessary. Closes-Bug: 1501820 Co-Author: Jay Bryant <jsbryant@us.ibm.com> Change-Id: I1f5494ebb19d5f4e8c651cbeef0acad07ad96829
103 lines
3.1 KiB
Bash
Executable File
103 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
|
||
# Generate sample configuration for your project.
|
||
#
|
||
# Aside from the command line flags, it also respects a config file which
|
||
# should be named oslo.config.generator.rc and be placed in the same directory.
|
||
#
|
||
# You can then export the following variables:
|
||
# CINDER_CONFIG_GENERATOR_EXTRA_MODULES: list of modules to interrogate for options.
|
||
# CINDER_CONFIG_GENERATOR_EXTRA_LIBRARIES: list of libraries to discover.
|
||
# CINDER_CONFIG_GENERATOR_EXCLUDED_FILES: list of files to remove from automatic listing.
|
||
|
||
BASEDIR=${BASEDIR:-`pwd`}
|
||
|
||
NOSAMPLE=0
|
||
if [ ! -z ${2} ] ; then
|
||
if [ "${2}" == "--nosamplefile" ]; then
|
||
NOSAMPLE=1
|
||
fi
|
||
fi
|
||
|
||
print_error ()
|
||
{
|
||
echo -en "\n\n##########################################################"
|
||
echo -en "\nERROR: ${0} was not called from tox."
|
||
echo -en "\n Execute 'tox -e genconfig' for cinder.conf.sample"
|
||
echo -en "\n generation."
|
||
echo -en "\n##########################################################\n\n"
|
||
}
|
||
|
||
if [ -z ${1} ] ; then
|
||
print_error
|
||
exit 1
|
||
fi
|
||
|
||
if [ ${1} != "from_tox" ] ; then
|
||
print_error
|
||
exit 1
|
||
fi
|
||
|
||
if ! [ -d $BASEDIR ] ; then
|
||
echo "${0##*/}: missing project base directory" >&2 ; exit 1
|
||
elif [[ $BASEDIR != /* ]] ; then
|
||
BASEDIR=$(cd "$BASEDIR" && pwd)
|
||
fi
|
||
|
||
PACKAGENAME=${PACKAGENAME:-$(python setup.py --name)}
|
||
TARGETDIR=$BASEDIR/$PACKAGENAME
|
||
if ! [ -d $TARGETDIR ] ; then
|
||
echo "${0##*/}: invalid project package name" >&2 ; exit 1
|
||
fi
|
||
|
||
BASEDIRESC=`echo $BASEDIR | sed -e 's/\//\\\\\//g'`
|
||
find $TARGETDIR -type f -name "*.pyc" -delete
|
||
|
||
export TARGETDIR=$TARGETDIR
|
||
export BASEDIRESC=$BASEDIRESC
|
||
|
||
if [ -e $TARGETDIR/opts.py ] ; then
|
||
mv $TARGETDIR/opts.py $TARGETDIR/opts.py.bak
|
||
fi
|
||
|
||
python cinder/config/generate_cinder_opts.py
|
||
|
||
if [ $? -ne 0 ] ; then
|
||
echo -en "\n\n#################################################"
|
||
echo -en "\nERROR: Non-zero exit from generate_cinder_opts.py."
|
||
echo -en "\n See output above for details.\n"
|
||
echo -en "#################################################\n"
|
||
if [ -e $TARGETDIR/opts.py.bak ] ; then
|
||
mv $TARGETDIR/opts.py.bak $TARGETDIR/opts.py
|
||
fi
|
||
exit 1
|
||
fi
|
||
|
||
if [ $NOSAMPLE -eq 0 ] ; then
|
||
oslo-config-generator --config-file=cinder/config/cinder-config-generator.conf
|
||
|
||
diff $TARGETDIR/opts.py $TARGETDIR/opts.py.bak &> /dev/null
|
||
if [ $? -ne 0 ] ; then
|
||
mv $TARGETDIR/opts.py.bak $TARGETDIR/opts.py
|
||
else
|
||
rm -f $TARGETDIR/opts.py.bak
|
||
fi
|
||
|
||
if [ $? -ne 0 ] ; then
|
||
echo -en "\n\n#################################################"
|
||
echo -en "\nERROR: Non-zero exit from oslo-config-generator."
|
||
echo -en "\n See output above for details.\n"
|
||
echo -en "#################################################\n"
|
||
exit 1
|
||
fi
|
||
if [ ! -s ./etc/cinder/cinder.conf.sample ] ; then
|
||
echo -en "\n\n#########################################################"
|
||
echo -en "\nERROR: etc/cinder/cinder.sample.conf not created properly."
|
||
echo -en "\n See above output for details.\n"
|
||
echo -en "###########################################################\n"
|
||
exit 1
|
||
fi
|
||
else
|
||
rm -f $TARGETDIR/opts.py.bak
|
||
fi
|