Add bash scripts style checking for IPA

Updated file tox.ini allows to check code style in all ".sh" files
included in Ironic Python Agent. Checking can be invoked by calling either
"tox" or "tox -e pep8".

Change-Id: Ie76605737c7db10a064f2aebfda388372a4c0591
Closes-Bug: #1625215
This commit is contained in:
OpenStack Proposal Bot 2016-11-04 14:08:31 +00:00 committed by John L. Villalovos
parent 3ebffd0e42
commit c40575e4e0
8 changed files with 85 additions and 62 deletions

View File

@ -6,74 +6,74 @@ DESTINATION="$1"
TOX_INI_UPPER_CONSTRAINT_URL="$(${COMMON_ROOT}/extract_upper_constraints_from_tox_ini.sh ${COMMON_ROOT}/../../tox.ini)" TOX_INI_UPPER_CONSTRAINT_URL="$(${COMMON_ROOT}/extract_upper_constraints_from_tox_ini.sh ${COMMON_ROOT}/../../tox.ini)"
copy() { copy() {
local src=$1 local src=$1
local destination=$2 local destination=$2
if test -z "${src}"; then if test -z "${src}"; then
return 1 return 1
fi fi
if test -e "${src}"; then if test -e "${src}"; then
log "File '${src}' exists. Using as upper-constraints." log "File '${src}' exists. Using as upper-constraints."
cp "${src}" "${destination}" cp "${src}" "${destination}"
else else
log "File '${src}' not found. Skipping local file strategy." log "File '${src}' not found. Skipping local file strategy."
return 1 return 1
fi fi
return 0 return 0
} }
download() { download() {
local url=$1 local url=$1
local destination=$2 local destination=$2
if test -z "${url}"; then if test -z "${url}"; then
return 1 return 1
else else
log "Downloading from '${url}'" log "Downloading from '${url}'"
curl ${url} -o "${destination}" curl ${url} -o "${destination}"
fi fi
return 0 return 0
} }
log() { log() {
echo "${SCRIPT_NAME}: ${@}" echo "${SCRIPT_NAME}: ${@}"
} }
fail() { fail() {
log ${@} log ${@}
exit 1 exit 1
} }
upper_constraints_is_not_null() { upper_constraints_is_not_null() {
test "${UPPER_CONSTRAINTS_FILE:-""}" != "" test "${UPPER_CONSTRAINTS_FILE:-""}" != ""
} }
copy_uc() { copy_uc() {
copy "${UPPER_CONSTRAINTS_FILE:-""}" "${DESTINATION}" copy "${UPPER_CONSTRAINTS_FILE:-""}" "${DESTINATION}"
} }
download_uc() { download_uc() {
download "${UPPER_CONSTRAINTS_FILE:-""}" "${DESTINATION}" download "${UPPER_CONSTRAINTS_FILE:-""}" "${DESTINATION}"
} }
copy_new_requirements_uc() { copy_new_requirements_uc() {
copy "/opt/stack/new/requirements/upper-constraints.txt" "${DESTINATION}" copy "/opt/stack/new/requirements/upper-constraints.txt" "${DESTINATION}"
} }
download_from_tox_ini_url() { download_from_tox_ini_url() {
log "tox.ini indicates '${TOX_INI_UPPER_CONSTRAINT_URL}' as fallback." log "tox.ini indicates '${TOX_INI_UPPER_CONSTRAINT_URL}' as fallback."
download "${TOX_INI_UPPER_CONSTRAINT_URL}" "${DESTINATION}" download "${TOX_INI_UPPER_CONSTRAINT_URL}" "${DESTINATION}"
} }
log "Generating local constraints file..." log "Generating local constraints file..."
if upper_constraints_is_not_null; then if upper_constraints_is_not_null; then
log "UPPER_CONSTRAINTS_FILE is defined as '${UPPER_CONSTRAINTS_FILE:-""}'" log "UPPER_CONSTRAINTS_FILE is defined as '${UPPER_CONSTRAINTS_FILE:-""}'"
copy_uc || download_uc || fail "Failed to copy or download file indicated in UPPER_CONSTRAINTS_FILE." copy_uc || download_uc || fail "Failed to copy or download file indicated in UPPER_CONSTRAINTS_FILE."
else else
log "UPPER_CONSTRAINTS_FILE is not defined. Using fallback strategies." log "UPPER_CONSTRAINTS_FILE is not defined. Using fallback strategies."
copy_new_requirements_uc || \ copy_new_requirements_uc || \
download_from_tox_ini_url || fail "Failed to download upper-constraints.txt from '${TOX_INI_UPPER_CONSTRAINT_URL}'." download_from_tox_ini_url || fail "Failed to download upper-constraints.txt from '${TOX_INI_UPPER_CONSTRAINT_URL}'."
fi fi

View File

@ -20,7 +20,7 @@ fi
# Install IPA and dependecies # Install IPA and dependecies
if ! type "ironic-python-agent" > /dev/null ; then if ! type "ironic-python-agent" > /dev/null ; then
python /tmp/get-pip.py --no-wheel --no-index --find-links=file:///tmp/wheelhouse ironic_python_agent python /tmp/get-pip.py --no-wheel --no-index --find-links=file:///tmp/wheelhouse ironic_python_agent
fi fi
export PYTHONOPTIMIZE=1 export PYTHONOPTIMIZE=1

View File

@ -17,14 +17,14 @@
set -e set -e
log() { log() {
echo "`basename $0`: $@" echo "`basename $0`: $@"
} }
usage() { usage() {
[[ -z "$1" ]] || echo -e "USAGE ERROR: $@\n" [[ -z "$1" ]] || echo -e "USAGE ERROR: $@\n"
echo "`basename $0`: IMAGEFILE DEVICE" echo "`basename $0`: IMAGEFILE DEVICE"
echo " - This script images DEVICE with IMAGEFILE" echo " - This script images DEVICE with IMAGEFILE"
exit 1 exit 1
} }
IMAGEFILE="$1" IMAGEFILE="$1"

View File

@ -8,7 +8,7 @@ testtools>=1.4.0 # MIT
python-subunit>=0.0.18 # Apache-2.0/BSD python-subunit>=0.0.18 # Apache-2.0/BSD
oslotest>=1.10.0 # Apache-2.0 oslotest>=1.10.0 # Apache-2.0
os-testr>=0.8.0 # Apache-2.0 os-testr>=0.8.0 # Apache-2.0
bashate>=0.2 # Apache-2.0
# Doc requirements # Doc requirements
doc8 # Apache-2.0 doc8 # Apache-2.0
sphinx!=1.3b1,<1.4,>=1.2.1 # BSD sphinx!=1.3b1,<1.4,>=1.2.1 # BSD

View File

@ -17,9 +17,8 @@ trap "rm -rf $TEMPDIR" EXIT
tools/config/generate_sample.sh -b ./ -p ${PROJECT_NAME} -o ${TEMPDIR} tools/config/generate_sample.sh -b ./ -p ${PROJECT_NAME} -o ${TEMPDIR}
if ! diff -u ${TEMPDIR}/${CFGFILE_NAME} ${CFGFILE} if ! diff -u ${TEMPDIR}/${CFGFILE_NAME} ${CFGFILE} ; then
then echo "${0##*/}: ${PROJECT_NAME}.conf.sample is not up to date."
echo "${0##*/}: ${PROJECT_NAME}.conf.sample is not up to date." echo "${0##*/}: Please run ${0%%${0##*/}}generate_sample.sh."
echo "${0##*/}: Please run ${0%%${0##*/}}generate_sample.sh." exit 1
exit 1
fi fi

View File

@ -5,9 +5,12 @@ print_hint() {
} }
PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hb:p:m:l:o: \ PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hb:p:m:l:o: \
--long help,base-dir:,package-name:,output-dir:,module:,library: -- "$@") --long help,base-dir:,package-name:,output-dir:,module:,library: -- "$@")
if [ $? != 0 ] ; then print_hint ; exit 1 ; fi if [ $? != 0 ] ; then
print_hint ;
exit 1
fi
eval set -- "$PARSED_OPTIONS" eval set -- "$PARSED_OPTIONS"
@ -57,30 +60,25 @@ while true; do
done done
BASEDIR=${BASEDIR:-`pwd`} BASEDIR=${BASEDIR:-`pwd`}
if ! [ -d $BASEDIR ] if ! [ -d $BASEDIR ] ; then
then
echo "${0##*/}: missing project base directory" >&2 ; print_hint ; exit 1 echo "${0##*/}: missing project base directory" >&2 ; print_hint ; exit 1
elif [[ $BASEDIR != /* ]] elif [[ $BASEDIR != /* ]] ; then
then
BASEDIR=$(cd "$BASEDIR" && pwd) BASEDIR=$(cd "$BASEDIR" && pwd)
fi fi
PACKAGENAME=${PACKAGENAME:-${BASEDIR##*/}} PACKAGENAME=${PACKAGENAME:-${BASEDIR##*/}}
PACKAGENAME=`echo $PACKAGENAME | tr - _` PACKAGENAME=`echo $PACKAGENAME | tr - _`
TARGETDIR=$BASEDIR/$PACKAGENAME TARGETDIR=$BASEDIR/$PACKAGENAME
if ! [ -d $TARGETDIR ] if ! [ -d $TARGETDIR ] ; then
then
echo "${0##*/}: invalid project package name" >&2 ; print_hint ; exit 1 echo "${0##*/}: invalid project package name" >&2 ; print_hint ; exit 1
fi fi
OUTPUTDIR=${OUTPUTDIR:-$BASEDIR/etc} OUTPUTDIR=${OUTPUTDIR:-$BASEDIR/etc}
# NOTE(bnemec): Some projects put their sample config in etc/, # NOTE(bnemec): Some projects put their sample config in etc/,
# some in etc/$PACKAGENAME/ # some in etc/$PACKAGENAME/
if [ -d $OUTPUTDIR/$PACKAGENAME ] if [ -d $OUTPUTDIR/$PACKAGENAME ] ; then
then
OUTPUTDIR=$OUTPUTDIR/$PACKAGENAME OUTPUTDIR=$OUTPUTDIR/$PACKAGENAME
elif ! [ -d $OUTPUTDIR ] elif ! [ -d $OUTPUTDIR ] ; then
then
echo "${0##*/}: cannot access \`$OUTPUTDIR': No such file or directory" >&2 echo "${0##*/}: cannot access \`$OUTPUTDIR': No such file or directory" >&2
exit 1 exit 1
fi fi
@ -91,8 +89,7 @@ FILES=$(find $TARGETDIR -type f -name "*.py" ! -path "*/tests/*" ! -path "*/nova
-exec grep -l "Opt(" {} + | sed -e "s/^$BASEDIRESC\///g" | sort -u) -exec grep -l "Opt(" {} + | sed -e "s/^$BASEDIRESC\///g" | sort -u)
RC_FILE="`dirname $0`/oslo.config.generator.rc" RC_FILE="`dirname $0`/oslo.config.generator.rc"
if test -r "$RC_FILE" if test -r "$RC_FILE" ; then
then
source "$RC_FILE" source "$RC_FILE"
fi fi

23
tools/run_bashate.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
#
# 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.
# Ignoring E003(Indent not multiple of 4)
# Ignoring E006(Line longer than 79 characters)
find "$@" -not \( -type d -name .?\* -prune \) \
-type f \
\( \
-name \*.sh \
\) \
-print0 | xargs -0 bashate -v -iE003,E006 -eE005,E042

View File

@ -26,8 +26,12 @@ setenv =
commands = ostestr {posargs} commands = ostestr {posargs}
[testenv:pep8] [testenv:pep8]
whitelist_externals = bash
commands = commands =
flake8 {posargs:ironic_python_agent imagebuild} flake8 {posargs:ironic_python_agent imagebuild}
# Run bashate during pep8 runs to ensure violations are caught by
# the check and gate queues.
{toxinidir}/tools/run_bashate.sh {toxinidir}
doc8 doc/source README.rst doc8 doc/source README.rst
[testenv:cover] [testenv:cover]