Skip to content

Commit c40575e

Browse files
OpenStack Proposal BotJohn L. Villalovos
authored andcommitted
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
1 parent 3ebffd0 commit c40575e

8 files changed

Lines changed: 88 additions & 65 deletions

File tree

imagebuild/common/generate_upper_constraints.sh

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,74 @@ DESTINATION="$1"
66
TOX_INI_UPPER_CONSTRAINT_URL="$(${COMMON_ROOT}/extract_upper_constraints_from_tox_ini.sh ${COMMON_ROOT}/../../tox.ini)"
77

88
copy() {
9-
local src=$1
10-
local destination=$2
11-
12-
if test -z "${src}"; then
13-
return 1
14-
fi
15-
16-
if test -e "${src}"; then
17-
log "File '${src}' exists. Using as upper-constraints."
18-
cp "${src}" "${destination}"
19-
else
20-
log "File '${src}' not found. Skipping local file strategy."
21-
return 1
22-
fi
23-
return 0
9+
local src=$1
10+
local destination=$2
11+
12+
if test -z "${src}"; then
13+
return 1
14+
fi
15+
16+
if test -e "${src}"; then
17+
log "File '${src}' exists. Using as upper-constraints."
18+
cp "${src}" "${destination}"
19+
else
20+
log "File '${src}' not found. Skipping local file strategy."
21+
return 1
22+
fi
23+
return 0
2424
}
2525

2626
download() {
27-
local url=$1
28-
local destination=$2
29-
30-
if test -z "${url}"; then
31-
return 1
32-
else
33-
log "Downloading from '${url}'"
34-
curl ${url} -o "${destination}"
35-
fi
36-
return 0
27+
local url=$1
28+
local destination=$2
29+
30+
if test -z "${url}"; then
31+
return 1
32+
else
33+
log "Downloading from '${url}'"
34+
curl ${url} -o "${destination}"
35+
fi
36+
return 0
3737
}
3838

3939
log() {
40-
echo "${SCRIPT_NAME}: ${@}"
40+
echo "${SCRIPT_NAME}: ${@}"
4141
}
4242

4343
fail() {
44-
log ${@}
45-
exit 1
44+
log ${@}
45+
exit 1
4646
}
4747

4848
upper_constraints_is_not_null() {
49-
test "${UPPER_CONSTRAINTS_FILE:-""}" != ""
49+
test "${UPPER_CONSTRAINTS_FILE:-""}" != ""
5050
}
5151

5252
copy_uc() {
53-
copy "${UPPER_CONSTRAINTS_FILE:-""}" "${DESTINATION}"
53+
copy "${UPPER_CONSTRAINTS_FILE:-""}" "${DESTINATION}"
5454
}
5555

5656
download_uc() {
57-
download "${UPPER_CONSTRAINTS_FILE:-""}" "${DESTINATION}"
57+
download "${UPPER_CONSTRAINTS_FILE:-""}" "${DESTINATION}"
5858
}
5959

6060
copy_new_requirements_uc() {
61-
copy "/opt/stack/new/requirements/upper-constraints.txt" "${DESTINATION}"
61+
copy "/opt/stack/new/requirements/upper-constraints.txt" "${DESTINATION}"
6262
}
6363

6464
download_from_tox_ini_url() {
65-
log "tox.ini indicates '${TOX_INI_UPPER_CONSTRAINT_URL}' as fallback."
66-
download "${TOX_INI_UPPER_CONSTRAINT_URL}" "${DESTINATION}"
65+
log "tox.ini indicates '${TOX_INI_UPPER_CONSTRAINT_URL}' as fallback."
66+
download "${TOX_INI_UPPER_CONSTRAINT_URL}" "${DESTINATION}"
6767
}
6868

6969
log "Generating local constraints file..."
7070

7171
if upper_constraints_is_not_null; then
72-
log "UPPER_CONSTRAINTS_FILE is defined as '${UPPER_CONSTRAINTS_FILE:-""}'"
73-
copy_uc || download_uc || fail "Failed to copy or download file indicated in UPPER_CONSTRAINTS_FILE."
72+
log "UPPER_CONSTRAINTS_FILE is defined as '${UPPER_CONSTRAINTS_FILE:-""}'"
73+
copy_uc || download_uc || fail "Failed to copy or download file indicated in UPPER_CONSTRAINTS_FILE."
7474
else
75-
log "UPPER_CONSTRAINTS_FILE is not defined. Using fallback strategies."
75+
log "UPPER_CONSTRAINTS_FILE is not defined. Using fallback strategies."
7676

77-
copy_new_requirements_uc || \
78-
download_from_tox_ini_url || fail "Failed to download upper-constraints.txt from '${TOX_INI_UPPER_CONSTRAINT_URL}'."
77+
copy_new_requirements_uc || \
78+
download_from_tox_ini_url || fail "Failed to download upper-constraints.txt from '${TOX_INI_UPPER_CONSTRAINT_URL}'."
7979
fi

imagebuild/tinyipa/build_files/bootlocal.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fi
2020

2121
# Install IPA and dependecies
2222
if ! type "ironic-python-agent" > /dev/null ; then
23-
python /tmp/get-pip.py --no-wheel --no-index --find-links=file:///tmp/wheelhouse ironic_python_agent
23+
python /tmp/get-pip.py --no-wheel --no-index --find-links=file:///tmp/wheelhouse ironic_python_agent
2424
fi
2525

2626
export PYTHONOPTIMIZE=1

ironic_python_agent/shell/write_image.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
set -e
1818

1919
log() {
20-
echo "`basename $0`: $@"
20+
echo "`basename $0`: $@"
2121
}
2222

2323
usage() {
24-
[[ -z "$1" ]] || echo -e "USAGE ERROR: $@\n"
25-
echo "`basename $0`: IMAGEFILE DEVICE"
26-
echo " - This script images DEVICE with IMAGEFILE"
27-
exit 1
24+
[[ -z "$1" ]] || echo -e "USAGE ERROR: $@\n"
25+
echo "`basename $0`: IMAGEFILE DEVICE"
26+
echo " - This script images DEVICE with IMAGEFILE"
27+
exit 1
2828
}
2929

3030
IMAGEFILE="$1"

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ testtools>=1.4.0 # MIT
88
python-subunit>=0.0.18 # Apache-2.0/BSD
99
oslotest>=1.10.0 # Apache-2.0
1010
os-testr>=0.8.0 # Apache-2.0
11-
11+
bashate>=0.2 # Apache-2.0
1212
# Doc requirements
1313
doc8 # Apache-2.0
1414
sphinx!=1.3b1,<1.4,>=1.2.1 # BSD

tools/config/check_uptodate.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ trap "rm -rf $TEMPDIR" EXIT
1717

1818
tools/config/generate_sample.sh -b ./ -p ${PROJECT_NAME} -o ${TEMPDIR}
1919

20-
if ! diff -u ${TEMPDIR}/${CFGFILE_NAME} ${CFGFILE}
21-
then
22-
echo "${0##*/}: ${PROJECT_NAME}.conf.sample is not up to date."
23-
echo "${0##*/}: Please run ${0%%${0##*/}}generate_sample.sh."
24-
exit 1
20+
if ! diff -u ${TEMPDIR}/${CFGFILE_NAME} ${CFGFILE} ; then
21+
echo "${0##*/}: ${PROJECT_NAME}.conf.sample is not up to date."
22+
echo "${0##*/}: Please run ${0%%${0##*/}}generate_sample.sh."
23+
exit 1
2524
fi

tools/config/generate_sample.sh

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ print_hint() {
55
}
66

77
PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hb:p:m:l:o: \
8-
--long help,base-dir:,package-name:,output-dir:,module:,library: -- "$@")
8+
--long help,base-dir:,package-name:,output-dir:,module:,library: -- "$@")
99

10-
if [ $? != 0 ] ; then print_hint ; exit 1 ; fi
10+
if [ $? != 0 ] ; then
11+
print_hint ;
12+
exit 1
13+
fi
1114

1215
eval set -- "$PARSED_OPTIONS"
1316

@@ -57,30 +60,25 @@ while true; do
5760
done
5861

5962
BASEDIR=${BASEDIR:-`pwd`}
60-
if ! [ -d $BASEDIR ]
61-
then
63+
if ! [ -d $BASEDIR ] ; then
6264
echo "${0##*/}: missing project base directory" >&2 ; print_hint ; exit 1
63-
elif [[ $BASEDIR != /* ]]
64-
then
65+
elif [[ $BASEDIR != /* ]] ; then
6566
BASEDIR=$(cd "$BASEDIR" && pwd)
6667
fi
6768

6869
PACKAGENAME=${PACKAGENAME:-${BASEDIR##*/}}
6970
PACKAGENAME=`echo $PACKAGENAME | tr - _`
7071
TARGETDIR=$BASEDIR/$PACKAGENAME
71-
if ! [ -d $TARGETDIR ]
72-
then
72+
if ! [ -d $TARGETDIR ] ; then
7373
echo "${0##*/}: invalid project package name" >&2 ; print_hint ; exit 1
7474
fi
7575

7676
OUTPUTDIR=${OUTPUTDIR:-$BASEDIR/etc}
7777
# NOTE(bnemec): Some projects put their sample config in etc/,
7878
# some in etc/$PACKAGENAME/
79-
if [ -d $OUTPUTDIR/$PACKAGENAME ]
80-
then
79+
if [ -d $OUTPUTDIR/$PACKAGENAME ] ; then
8180
OUTPUTDIR=$OUTPUTDIR/$PACKAGENAME
82-
elif ! [ -d $OUTPUTDIR ]
83-
then
81+
elif ! [ -d $OUTPUTDIR ] ; then
8482
echo "${0##*/}: cannot access \`$OUTPUTDIR': No such file or directory" >&2
8583
exit 1
8684
fi
@@ -91,8 +89,7 @@ FILES=$(find $TARGETDIR -type f -name "*.py" ! -path "*/tests/*" ! -path "*/nova
9189
-exec grep -l "Opt(" {} + | sed -e "s/^$BASEDIRESC\///g" | sort -u)
9290

9391
RC_FILE="`dirname $0`/oslo.config.generator.rc"
94-
if test -r "$RC_FILE"
95-
then
92+
if test -r "$RC_FILE" ; then
9693
source "$RC_FILE"
9794
fi
9895

tools/run_bashate.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
# Ignoring E003(Indent not multiple of 4)
16+
# Ignoring E006(Line longer than 79 characters)
17+
18+
find "$@" -not \( -type d -name .?\* -prune \) \
19+
-type f \
20+
\( \
21+
-name \*.sh \
22+
\) \
23+
-print0 | xargs -0 bashate -v -iE003,E006 -eE005,E042

tox.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ setenv =
2626
commands = ostestr {posargs}
2727

2828
[testenv:pep8]
29+
whitelist_externals = bash
2930
commands =
3031
flake8 {posargs:ironic_python_agent imagebuild}
32+
# Run bashate during pep8 runs to ensure violations are caught by
33+
# the check and gate queues.
34+
{toxinidir}/tools/run_bashate.sh {toxinidir}
3135
doc8 doc/source README.rst
3236

3337
[testenv:cover]

0 commit comments

Comments
 (0)