diff --git a/bareon/cmd/agent.py b/bareon/cmd/agent.py index cb5d89d..28838a2 100644 --- a/bareon/cmd/agent.py +++ b/bareon/cmd/agent.py @@ -39,6 +39,26 @@ CONF = cfg.CONF CONF.register_cli_opts(cli_opts) +def list_opts(): + """Returns a list of oslo.config options available in the library. + + The returned list includes all oslo.config options which may be registered + at runtime by the library. + + Each element of the list is a tuple. The first element is the name of the + group under which the list of elements in the second element will be + registered. A group name of None corresponds to the [DEFAULT] group in + config files. + + The purpose of this is to allow tools like the Oslo sample config file + generator (oslo-config-generator) to discover the options exposed to users + by this library. + + :returns: a list of (group_name, opts) tuples + """ + return [(None, (cli_opts))] + + def provision(): main(['do_provisioning']) diff --git a/bareon/manager.py b/bareon/manager.py index 6414604..e0009cc 100644 --- a/bareon/manager.py +++ b/bareon/manager.py @@ -1029,3 +1029,23 @@ class Manager(object): finally: LOG.info('Cleanup chroot') self.destroy_chroot(chroot) + + +def list_opts(): + """Returns a list of oslo.config options available in the library. + + The returned list includes all oslo.config options which may be registered + at runtime by the library. + + Each element of the list is a tuple. The first element is the name of the + group under which the list of elements in the second element will be + registered. A group name of None corresponds to the [DEFAULT] group in + config files. + + The purpose of this is to allow tools like the Oslo sample config file + generator (oslo-config-generator) to discover the options exposed to users + by this library. + + :returns: a list of (group_name, opts) tuples + """ + return [(None, (opts))] diff --git a/bareon/utils/artifact.py b/bareon/utils/artifact.py index d65168d..c73729a 100644 --- a/bareon/utils/artifact.py +++ b/bareon/utils/artifact.py @@ -229,3 +229,23 @@ class Chain(object): else: return next_proc(proc) return six.moves.reduce(jump, self.processors) + + +def list_opts(): + """Returns a list of oslo.config options available in the library. + + The returned list includes all oslo.config options which may be registered + at runtime by the library. + + Each element of the list is a tuple. The first element is the name of the + group under which the list of elements in the second element will be + registered. A group name of None corresponds to the [DEFAULT] group in + config files. + + The purpose of this is to allow tools like the Oslo sample config file + generator (oslo-config-generator) to discover the options exposed to users + by this library. + + :returns: a list of (group_name, opts) tuples + """ + return [(None, (au_opts))] diff --git a/bareon/utils/utils.py b/bareon/utils/utils.py index 9446b24..22c27bf 100644 --- a/bareon/utils/utils.py +++ b/bareon/utils/utils.py @@ -370,3 +370,23 @@ def get_interface_ip(mac_addr): match = ip_pattern.search(ip_line) if match: return match.group(1) + + +def list_opts(): + """Returns a list of oslo.config options available in the library. + + The returned list includes all oslo.config options which may be registered + at runtime by the library. + + Each element of the list is a tuple. The first element is the name of the + group under which the list of elements in the second element will be + registered. A group name of None corresponds to the [DEFAULT] group in + config files. + + The purpose of this is to allow tools like the Oslo sample config file + generator (oslo-config-generator) to discover the options exposed to users + by this library. + + :returns: a list of (group_name, opts) tuples + """ + return [(None, (u_opts))] diff --git a/etc/oslo-config-generator/bareon.conf b/etc/oslo-config-generator/bareon.conf new file mode 100644 index 0000000..3cf49d8 --- /dev/null +++ b/etc/oslo-config-generator/bareon.conf @@ -0,0 +1,7 @@ +[DEFAULT] +output_file = etc/bareon/bareon.conf.sample +namespace = bareon.manager +namespace = bareon.agent +namespace = oslo.log +namespace = bareon.artifact +namespace = bareon.utils diff --git a/openstack-common.conf b/openstack-common.conf index ccef55b..9b1d584 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -1,10 +1,9 @@ [DEFAULT] # The list of modules to copy from oslo-incubator -module=config.generator module=gettextutils module=log module=processutils # The base module to hold the copy of openstack.common -base=bareon \ No newline at end of file +base=bareon diff --git a/setup.cfg b/setup.cfg index 800a5b7..208b97c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,6 +30,12 @@ bareon.drivers = ironic = bareon.drivers.nailgun:Ironic bootstrap_build_image = bareon.drivers.bootstrap:BootstrapBuildImage +oslo.config.opts = + bareon.manager = bareon.manager:list_opts + bareon.agent = bareon.cmd.agent:list_opts + bareon.utils = bareon.utils.utils:list_opts + bareon.artifact= bareon.utils.artifact:list_opts + [pbr] autodoc_index_modules = True # this variable is needed to avoid including files diff --git a/tools/config/check_uptodate.sh b/tools/config/check_uptodate.sh deleted file mode 100755 index 8e65531..0000000 --- a/tools/config/check_uptodate.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -PROJECT_NAME=${PROJECT_NAME:-bareon} -CFGFILE_NAME=${PROJECT_NAME}.conf.sample - -if [ -e etc/${PROJECT_NAME}/${CFGFILE_NAME} ]; then - CFGFILE=etc/${PROJECT_NAME}/${CFGFILE_NAME} -elif [ -e etc/${CFGFILE_NAME} ]; then - CFGFILE=etc/${CFGFILE_NAME} -else - echo "${0##*/}: can not find config file" - exit 1 -fi - -TEMPDIR=`mktemp -d /tmp/${PROJECT_NAME}.XXXXXX` -trap "rm -rf $TEMPDIR" EXIT - -tools/config/generate_sample.sh -b ./ -p ${PROJECT_NAME} -o ${TEMPDIR} - -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." - exit 1 -fi diff --git a/tools/config/generate_sample.sh b/tools/config/generate_sample.sh deleted file mode 100755 index ce3e1d6..0000000 --- a/tools/config/generate_sample.sh +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env bash - -print_hint() { - echo "Try \`${0##*/} --help' for more information." >&2 -} - -PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hb:p:m:l:o:f: \ - --long help,base-dir:,package-name:,output-dir:,output-file:,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 "-f, --output-file=FILE 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 - ;; - -f|--output-file) - shift - OUTPUTFILE=`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:-${BASEDIR##*/}} -PACKAGENAME=`echo $PACKAGENAME | tr - _` -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/*" ! -path "*/nova/*" \ - -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 mod in ${FUEL_AGENT_CONFIG_GENERATOR_EXTRA_MODULES}; do - MODULES="$MODULES -m $mod" -done - -for lib in ${FUEL_AGENT_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=bareon.openstack.common.config.generator -MODULEPATH=${MODULEPATH:-$DEFAULT_MODULEPATH} -OUTPUTFILE=${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 diff --git a/tools/config/oslo.config.generator.rc b/tools/config/oslo.config.generator.rc deleted file mode 100644 index e69de29..0000000 diff --git a/tools/with_venv.sh b/tools/with_venv.sh deleted file mode 100755 index 94e05c1..0000000 --- a/tools/with_venv.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -tools_path=${tools_path:-$(dirname $0)} -venv_path=${venv_path:-${tools_path}} -venv_dir=${venv_name:-/../.venv} -TOOLS=${tools_path} -VENV=${venv:-${venv_path}/${venv_dir}} -source ${VENV}/bin/activate && "$@" diff --git a/tox.ini b/tox.ini index 3c72eae..3894524 100644 --- a/tox.ini +++ b/tox.ini @@ -36,6 +36,10 @@ usedevelop = True [testenv:docs] commands = python setup.py build_sphinx +[testenv:genconfig] +commands = + oslo-config-generator --config-file etc/oslo-config-generator/bareon.conf + [flake8] exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools,docs show-pep8 = True