summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDevananda van der Veen <devananda.vdv@gmail.com>2013-12-06 15:40:24 -0800
committerDevananda van der Veen <devananda.vdv@gmail.com>2013-12-06 15:40:24 -0800
commit6ba95e62a6df910050a83bce5876cc33364ba301 (patch)
treec08b78fde2f87dec6a755f3261b9710c7413439e /tools
parent049cddda6716091fdcad190ca7a84fb938e61dbf (diff)
downloadironic-6ba95e62a6df910050a83bce5876cc33364ba301.tar.gz
Add tools/conf/check_uptodate to tox.ini
To ensure that our sample config file, etc/ironic/ironic.conf.sample, does not get out of sync with the code, this patch introduces a check to tox that will compare the proposed ironic.conf.sample to a freshly generated one, and error if they are not identical. Ported from Nova's tools/config/check_uptodate.sh script. Change-Id: Ic2898142754547e32bc4c03d23eca5d6a33721fc Closes-bug: 1255621
Diffstat (limited to 'tools')
-rwxr-xr-xtools/conf/check_uptodate.sh9
-rwxr-xr-xtools/conf/generate_sample.sh106
2 files changed, 92 insertions, 23 deletions
diff --git a/tools/conf/check_uptodate.sh b/tools/conf/check_uptodate.sh
new file mode 100755
index 000000000..4e9c9a727
--- /dev/null
+++ b/tools/conf/check_uptodate.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+TEMPDIR=`mktemp -d`
+CFGFILE=ironic.conf.sample
+tools/conf/generate_sample.sh -b ./ -p ironic -o $TEMPDIR
+if ! diff $TEMPDIR/$CFGFILE etc/ironic/$CFGFILE
+then
+ echo "E: ironic.conf.sample is not up to date, please run tools/conf/generate_sample.sh"
+ exit 42
+fi
diff --git a/tools/conf/generate_sample.sh b/tools/conf/generate_sample.sh
index 2b442ea2f..eab734ad3 100755
--- a/tools/conf/generate_sample.sh
+++ b/tools/conf/generate_sample.sh
@@ -1,27 +1,87 @@
#!/usr/bin/env bash
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2012 SINA Corporation
-# All Rights Reserved.
-# Author: Zhongyue Luo <lzyeval@gmail.com>
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-FILES=$(find ironic -type f -name "*.py" ! -path "ironic/tests/*" \
- ! -path "ironic/nova/*" -exec grep -l "Opt(" {} + | sort -u)
+
+print_hint() {
+ echo "Try \`${0##*/} --help' for more information." >&2
+}
+
+PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hb:p:o: \
+ --long help,base-dir:,package-name:,output-dir: -- "$@")
+
+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"
+ 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
+ ;;
+ --)
+ 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##*/}}
+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)
export EVENTLET_NO_GREENDNS=yes
-MODULEPATH=$(dirname "$0")/../../ironic/openstack/common/config/generator.py
-OUTPUTPATH=etc/ironic/ironic.conf.sample
-PYTHONPATH=./:${PYTHONPATH} python $MODULEPATH $FILES > $OUTPUTPATH
+OS_VARS=$(set | sed -n '/^OS_/s/=[^=]*$//gp' | xargs)
+[ "$OS_VARS" ] && eval "unset \$OS_VARS"
+
+MODULEPATH=ironic.openstack.common.config.generator
+OUTPUTFILE=$OUTPUTDIR/$PACKAGENAME.conf.sample
+python -m $MODULEPATH $FILES > $OUTPUTFILE