Make mistral use of oslo-config-generator

Change-Id: I01f36e4b0080e10b9d39a6adbfe4b6cd43957fc6
This commit is contained in:
Nikolay Mahotkin 2015-05-26 12:53:32 +03:00
parent 4e699ce21b
commit f34edb7e27
9 changed files with 645 additions and 641 deletions

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,8 @@
Configuration options registration and useful routines.
"""
import itertools
from oslo.config import cfg
from mistral.openstack.common import log
@ -55,9 +57,9 @@ use_debugger = cfg.BoolOpt(
"use-debugger",
default=False,
help='Enables debugger. Note that using this option changes how the '
'eventlet library is used to support async IO. This could result '
'in failures that do not occur under normal operation. '
'Use at your own risk.'
'eventlet library is used to support async IO. This could result '
'in failures that do not occur under normal operation. '
'Use at your own risk.'
)
engine_opts = [
@ -88,19 +90,28 @@ wf_trace_log_name_opt = cfg.StrOpt(
'workflow_trace_log_name',
default='workflow_trace',
help='Logger name for pretty '
'workflow trace output.'
'workflow trace output.'
)
CONF = cfg.CONF
CONF.register_opts(api_opts, group='api')
CONF.register_opts(engine_opts, group='engine')
CONF.register_opts(pecan_opts, group='pecan')
CONF.register_opts(executor_opts, group='executor')
API_GROUP = 'api'
ENGINE_GROUP = 'engine'
EXECUTOR_GROUP = 'executor'
PECAN_GROUP = 'pecan'
CONF.register_opts(api_opts, group=API_GROUP)
CONF.register_opts(engine_opts, group=ENGINE_GROUP)
CONF.register_opts(pecan_opts, group=PECAN_GROUP)
CONF.register_opts(executor_opts, group=EXECUTOR_GROUP)
CONF.register_opt(wf_trace_log_name_opt)
CONF.register_cli_opt(use_debugger)
CONF.register_cli_opt(launch_opt)
CLI_OPTS = [
use_debugger,
launch_opt
]
CONF.register_cli_opts(CLI_OPTS)
CONF.import_opt('verbose', 'mistral.openstack.common.log')
CONF.set_default('verbose', True)
@ -139,6 +150,19 @@ cfg.set_defaults(
)
def list_opts():
return [
(API_GROUP, api_opts),
(ENGINE_GROUP, engine_opts),
(EXECUTOR_GROUP, executor_opts),
(PECAN_GROUP, pecan_opts),
(None, itertools.chain(
CLI_OPTS,
[wf_trace_log_name_opt]
))
]
def parse_args(args=None, usage=None, default_config_files=None):
CONF(
args=args,

View File

@ -1,7 +1,6 @@
[DEFAULT]
# The list of modules to copy from oslo-incubator.git
module=config.generator
module=log
module=jsonutils
module=lockutils

View File

@ -35,6 +35,9 @@ console_scripts =
mistral-server = mistral.cmd.launch:main
mistral-db-manage = mistral.db.sqlalchemy.migration.cli:main
oslo.config.opts =
mistral.config = mistral.config:list_opts
mistral.actions =
std.async_noop = mistral.actions.std_actions:AsyncNoOpAction
std.noop = mistral.actions.std_actions:NoOpAction

View File

@ -15,11 +15,11 @@ fi
TEMPDIR=$(mktemp -d /tmp/${PROJECT_NAME}.XXXXXX)
trap "rm -rf $TEMPDIR" EXIT
tools/config/generate_sample.sh -b ./ -p ${PROJECT_NAME} -o ${TEMPDIR}
oslo-config-generator --config-file tools/config/config-generator.mistral.conf --output-file ${TEMPDIR}/${CFGFILE_NAME}
if ! diff -u ${TEMPDIR}/${CFGFILE_NAME} ${CFGFILE}
then
echo "${0##*/}: ${PROJECT_NAME}.conf.sample is not up to date."
echo "${0##*/}: Please run ${0%%${0##*/}}generate_sample.sh."
echo "${0##*/}: Please run tox -egenconfig."
exit 1
fi

View File

@ -0,0 +1,7 @@
[DEFAULT]
namespace = mistral.config
namespace = oslo.db
namespace = oslo.messaging
namespace = keystonemiddleware.auth_token
namespace = periodic.config
namespace = oslo.log

View File

@ -1,133 +0,0 @@
#!/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:
# MISTRAL_CONFIG_GENERATOR_EXTRA_MODULES: list of modules to interrogate for options.
# MISTRAL_CONFIG_GENERATOR_EXTRA_LIBRARIES: list of libraries to discover.
# MISTRAL_CONFIG_GENERATOR_EXCLUDED_FILES: list of files to remove from automatic listing.
print_hint() {
echo "Try '${0##*/} --help' for more information." >&2
}
PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hb:p:m:l:o: \
--long help,base-dir:,package-name:,output-dir:,module:,library: -- "$@")
if [ $? != 0 ] ; then print_hint ; exit 1 ; fi
eval set -- "$PARSED_OPTIONS"
while true; do
case "$1" in
-h|--help)
echo "${0##*/} [options]"
echo ""
echo "options:"
echo "-h, --help show brief help"
echo "-b, --base-dir=DIR project base directory"
echo "-p, --package-name=NAME project package name"
echo "-o, --output-dir=DIR file output directory"
echo "-m, --module=MOD extra python module to interrogate for options"
echo "-l, --library=LIB extra library that registers options for discovery"
exit 0
;;
-b|--base-dir)
shift
BASEDIR=$(echo $1 | sed -e 's/\/*$//g')
shift
;;
-p|--package-name)
shift
PACKAGENAME=$(echo $1)
shift
;;
-o|--output-dir)
shift
OUTPUTDIR=$(echo $1 | sed -e 's/\/*$//g')
shift
;;
-m|--module)
shift
MODULES="$MODULES -m $1"
shift
;;
-l|--library)
shift
LIBRARIES="$LIBRARIES -l $1"
shift
;;
--)
break
;;
esac
done
BASEDIR=${BASEDIR:-$(pwd)}
if ! [ -d $BASEDIR ]
then
echo "${0##*/}: missing project base directory" >&2 ; print_hint ; 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 ; print_hint ; exit 1
fi
OUTPUTDIR=${OUTPUTDIR:-$BASEDIR/etc}
# NOTE(bnemec): Some projects put their sample config in etc/,
# some in etc/$PACKAGENAME/
if [ -d $OUTPUTDIR/$PACKAGENAME ]
then
OUTPUTDIR=$OUTPUTDIR/$PACKAGENAME
elif ! [ -d $OUTPUTDIR ]
then
echo "${0##*/}: cannot access '$OUTPUTDIR': No such file or directory" >&2
exit 1
fi
BASEDIRESC=$(echo $BASEDIR | sed -e 's/\//\\\\\//g')
find $TARGETDIR -type f -name "*.pyc" -delete
FILES=$(find $TARGETDIR -type f -name "*.py" ! -path "*/tests/*" \
-exec grep -l "Opt(" {} + | sed -e "s/^$BASEDIRESC\///g" | sort -u)
RC_FILE="$(dirname $0)/oslo.config.generator.rc"
if test -r "$RC_FILE"
then
source "$RC_FILE"
fi
for filename in ${MISTRAL_CONFIG_GENERATOR_EXCLUDED_FILES}; do
FILES="${FILES[@]/$filename/}"
done
for mod in ${MISTRAL_CONFIG_GENERATOR_EXTRA_MODULES}; do
MODULES="$MODULES -m $mod"
done
for lib in ${MISTRAL_CONFIG_GENERATOR_EXTRA_LIBRARIES}; do
LIBRARIES="$LIBRARIES -l $lib"
done
export EVENTLET_NO_GREENDNS=yes
OS_VARS=$(set | sed -n '/^OS_/s/=[^=]*$//gp' | xargs)
[ "$OS_VARS" ] && eval "unset \$OS_VARS"
DEFAULT_MODULEPATH=mistral.openstack.common.config.generator
MODULEPATH=${MODULEPATH:-$DEFAULT_MODULEPATH}
OUTPUTFILE=$OUTPUTDIR/$PACKAGENAME.conf.sample
python -m $MODULEPATH $MODULES $LIBRARIES $FILES > $OUTPUTFILE
# Hook to allow projects to append custom config file snippets
CONCAT_FILES=$(ls $BASEDIR/tools/config/*.conf.sample 2>/dev/null)
for CONCAT_FILE in $CONCAT_FILES; do
cat $CONCAT_FILE >> $OUTPUTFILE
done

View File

@ -1,2 +0,0 @@
export MISTRAL_CONFIG_GENERATOR_EXTRA_LIBRARIES="oslo.messaging oslo.db"
export MISTRAL_CONFIG_GENERATOR_EXTRA_MODULES=keystoneclient.middleware.auth_token

View File

@ -26,6 +26,11 @@ commands =
python setup.py testr --coverage \
--testr-args='^(?!.*test.*coverage).*$'
[testenv:genconfig]
commands =
oslo-config-generator --config-file tools/config/config-generator.mistral.conf \
--output-file etc/mistral.conf.sample
[testenv:venv]
commands = {posargs}