Add bash script style checker to pep8 check

Added the bashate script style checker to the pep8
check target in tox.ini. It actually found two valid
issues - a bad function declaration and a local variable
issue, but mostly just indentation noise. Fixed all the
complaints.

Change-Id: I43b60e7dcf53acf259c8a52b248fbb8c63d3c8d4
This commit is contained in:
Brian Haley 2019-10-10 13:54:58 -04:00
parent ca80bc9e03
commit 98448dce44
8 changed files with 86 additions and 67 deletions

View File

@ -204,7 +204,7 @@ function create_octavia_accounts {
# This is imporant for concurrent tempest testing # This is imporant for concurrent tempest testing
openstack quota set --secgroups 100 $SERVICE_PROJECT_NAME openstack quota set --secgroups 100 $SERVICE_PROJECT_NAME
local octavia_service=$(get_or_create_service "octavia" \ octavia_service=$(get_or_create_service "octavia" \
$OCTAVIA_SERVICE_TYPE "Octavia Load Balancing Service") $OCTAVIA_SERVICE_TYPE "Octavia Load Balancing Service")
if [[ "$WSGI_MODE" == "uwsgi" ]] && [[ "$OCTAVIA_NODE" == "main" ]] ; then if [[ "$WSGI_MODE" == "uwsgi" ]] && [[ "$OCTAVIA_NODE" == "main" ]] ; then
@ -493,10 +493,10 @@ function configure_octavia_api_haproxy {
NODES=(${OCTAVIA_NODES//,/ }) NODES=(${OCTAVIA_NODES//,/ })
for NODE in ${NODES[@]}; do for NODE in ${NODES[@]}; do
DATA=(${NODE//:/ }) DATA=(${NODE//:/ })
NAME=$(echo -e "${DATA[0]}" | tr -d '[[:space:]]') NAME=$(echo -e "${DATA[0]}" | tr -d '[[:space:]]')
IP=$(echo -e "${DATA[1]}" | tr -d '[[:space:]]') IP=$(echo -e "${DATA[1]}" | tr -d '[[:space:]]')
echo " server octavia-${NAME} ${IP}:80 weight 1" >> ${OCTAVIA_CONF_DIR}/haproxy.cfg echo " server octavia-${NAME} ${IP}:80 weight 1" >> ${OCTAVIA_CONF_DIR}/haproxy.cfg
done done
} }
@ -564,19 +564,19 @@ function octavia_stop {
function octavia_cleanup { function octavia_cleanup {
if [ ${OCTAVIA_AMP_IMAGE_NAME}x != x ] ; then if [ ${OCTAVIA_AMP_IMAGE_NAME}x != x ] ; then
rm -rf ${OCTAVIA_AMP_IMAGE_NAME}* rm -rf ${OCTAVIA_AMP_IMAGE_NAME}*
fi fi
if [ ${OCTAVIA_AMP_SSH_KEY_NAME}x != x ] ; then if [ ${OCTAVIA_AMP_SSH_KEY_NAME}x != x ] ; then
rm -f ${OCTAVIA_AMP_SSH_KEY_NAME}* rm -f ${OCTAVIA_AMP_SSH_KEY_NAME}*
fi fi
if [ ${OCTAVIA_SSH_DIR}x != x ] ; then if [ ${OCTAVIA_SSH_DIR}x != x ] ; then
rm -rf ${OCTAVIA_SSH_DIR} rm -rf ${OCTAVIA_SSH_DIR}
fi fi
if [ ${OCTAVIA_CONF_DIR}x != x ] ; then if [ ${OCTAVIA_CONF_DIR}x != x ] ; then
sudo rm -rf ${OCTAVIA_CONF_DIR} sudo rm -rf ${OCTAVIA_CONF_DIR}
fi fi
if [ ${OCTAVIA_RUN_DIR}x != x ] ; then if [ ${OCTAVIA_RUN_DIR}x != x ] ; then
sudo rm -rf ${OCTAVIA_RUN_DIR} sudo rm -rf ${OCTAVIA_RUN_DIR}
fi fi
if [ ${OCTAVIA_AMP_SSH_KEY_PATH}x != x ] ; then if [ ${OCTAVIA_AMP_SSH_KEY_PATH}x != x ] ; then
rm -f ${OCTAVIA_AMP_SSH_KEY_PATH} ${OCTAVIA_AMP_SSH_KEY_PATH}.pub rm -f ${OCTAVIA_AMP_SSH_KEY_PATH} ${OCTAVIA_AMP_SSH_KEY_PATH}.pub
@ -610,66 +610,66 @@ function add_load-balancer_roles {
} }
function octavia_init { function octavia_init {
if [ $OCTAVIA_NODE != 'main' ] && [ $OCTAVIA_NODE != 'standalone' ] && [ $OCTAVIA_NODE != 'api' ]; then if [ $OCTAVIA_NODE != 'main' ] && [ $OCTAVIA_NODE != 'standalone' ] && [ $OCTAVIA_NODE != 'api' ]; then
# without the other services enabled apparently we don't have # without the other services enabled apparently we don't have
# credentials at this point # credentials at this point
# TOP_DIR=$(cd $(dirname "$0") && pwd) # TOP_DIR=$(cd $(dirname "$0") && pwd)
source ${TOP_DIR}/openrc admin admin source ${TOP_DIR}/openrc admin admin
OCTAVIA_AMP_NETWORK_ID=$(openstack network show lb-mgmt-net -f value -c id) OCTAVIA_AMP_NETWORK_ID=$(openstack network show lb-mgmt-net -f value -c id)
iniset $OCTAVIA_CONF controller_worker amp_boot_network_list ${OCTAVIA_AMP_NETWORK_ID} iniset $OCTAVIA_CONF controller_worker amp_boot_network_list ${OCTAVIA_AMP_NETWORK_ID}
fi fi
if [ $OCTAVIA_NODE == 'main' ] || [ $OCTAVIA_NODE == 'standalone' ] ; then if [ $OCTAVIA_NODE == 'main' ] || [ $OCTAVIA_NODE == 'standalone' ] ; then
# things that should only happen on the ha main node / or once # things that should only happen on the ha main node / or once
if ! openstack keypair show ${OCTAVIA_AMP_SSH_KEY_NAME} ; then if ! openstack keypair show ${OCTAVIA_AMP_SSH_KEY_NAME} ; then
openstack keypair create --public-key ${OCTAVIA_AMP_SSH_KEY_PATH}.pub ${OCTAVIA_AMP_SSH_KEY_NAME} openstack keypair create --public-key ${OCTAVIA_AMP_SSH_KEY_PATH}.pub ${OCTAVIA_AMP_SSH_KEY_NAME}
fi fi
# Check if an amphora image is already loaded # Check if an amphora image is already loaded
AMPHORA_IMAGE_NAME=$(openstack image list --property name=${OCTAVIA_AMP_IMAGE_NAME} -f value -c Name) AMPHORA_IMAGE_NAME=$(openstack image list --property name=${OCTAVIA_AMP_IMAGE_NAME} -f value -c Name)
export AMPHORA_IMAGE_NAME export AMPHORA_IMAGE_NAME
if [ "$AMPHORA_IMAGE_NAME" == ${OCTAVIA_AMP_IMAGE_NAME} ]; then if [ "$AMPHORA_IMAGE_NAME" == ${OCTAVIA_AMP_IMAGE_NAME} ]; then
echo "Found existing amphora image: $AMPHORA_IMAGE_NAME" echo "Found existing amphora image: $AMPHORA_IMAGE_NAME"
echo "Skipping amphora image build" echo "Skipping amphora image build"
export DISABLE_AMP_IMAGE_BUILD=True export DISABLE_AMP_IMAGE_BUILD=True
fi fi
if ! [ "$DISABLE_AMP_IMAGE_BUILD" == 'True' ]; then if ! [ "$DISABLE_AMP_IMAGE_BUILD" == 'True' ]; then
build_octavia_worker_image build_octavia_worker_image
fi fi
OCTAVIA_AMP_IMAGE_ID=$(openstack image list -f value --property name=${OCTAVIA_AMP_IMAGE_NAME} -c ID) OCTAVIA_AMP_IMAGE_ID=$(openstack image list -f value --property name=${OCTAVIA_AMP_IMAGE_NAME} -c ID)
if [ -n "$OCTAVIA_AMP_IMAGE_ID" ]; then if [ -n "$OCTAVIA_AMP_IMAGE_ID" ]; then
openstack image set --tag ${OCTAVIA_AMP_IMAGE_TAG} --property hw_architecture='x86_64' --property hw_rng_model=virtio ${OCTAVIA_AMP_IMAGE_ID} openstack image set --tag ${OCTAVIA_AMP_IMAGE_TAG} --property hw_architecture='x86_64' --property hw_rng_model=virtio ${OCTAVIA_AMP_IMAGE_ID}
fi fi
# Create a management network. # Create a management network.
build_mgmt_network build_mgmt_network
OCTAVIA_AMP_NETWORK_ID=$(openstack network show lb-mgmt-net -f value -c id) OCTAVIA_AMP_NETWORK_ID=$(openstack network show lb-mgmt-net -f value -c id)
iniset $OCTAVIA_CONF controller_worker amp_boot_network_list ${OCTAVIA_AMP_NETWORK_ID} iniset $OCTAVIA_CONF controller_worker amp_boot_network_list ${OCTAVIA_AMP_NETWORK_ID}
create_octavia_accounts create_octavia_accounts
add_load-balancer_roles add_load-balancer_roles
configure_rsyslog configure_rsyslog
elif [ $OCTAVIA_NODE == 'api' ] ; then elif [ $OCTAVIA_NODE == 'api' ] ; then
create_octavia_accounts create_octavia_accounts
add_load-balancer_roles add_load-balancer_roles
fi fi
if [ $OCTAVIA_NODE != 'api' ] ; then if [ $OCTAVIA_NODE != 'api' ] ; then
create_mgmt_network_interface create_mgmt_network_interface
create_amphora_flavor create_amphora_flavor
configure_lb_mgmt_sec_grp configure_lb_mgmt_sec_grp
fi fi
if ! [ "$DISABLE_AMP_IMAGE_BUILD" == 'True' ]; then if ! [ "$DISABLE_AMP_IMAGE_BUILD" == 'True' ]; then
set_octavia_worker_image_owner_id set_octavia_worker_image_owner_id
fi fi
} }
function _configure_tempest { function _configure_tempest {

View File

@ -18,11 +18,11 @@ source ${TOP_DIR}/stackrc
DEST=${DEST:-/opt/stack} DEST=${DEST:-/opt/stack}
# Polling functions # Polling functions
function wait_for_loadbalancer_active() { function wait_for_loadbalancer_active {
lb_name=$1 lb_name=$1
while [ $(openstack loadbalancer show $lb_name -f value -c provisioning_status) != "ACTIVE" ]; do while [ $(openstack loadbalancer show $lb_name -f value -c provisioning_status) != "ACTIVE" ]; do
sleep 2 sleep 2
done done
} }
if is_service_enabled nova; then if is_service_enabled nova; then

View File

@ -21,8 +21,7 @@ PRIVATE_SUBNET_NAME=${PRIVATE_SUBNET_NAME:-"private-subnet"}
# $3..n: command with arguments and parameters # $3..n: command with arguments and parameters
# TODO(cgoncalves): set timeout # TODO(cgoncalves): set timeout
function _wait_for_status { function _wait_for_status {
while : while true; do
do
eval $("${@:3}" -f shell -c provisioning_status -c operating_status) eval $("${@:3}" -f shell -c provisioning_status -c operating_status)
[[ $operating_status == "ONLINE" && $provisioning_status == "ACTIVE" ]] && break [[ $operating_status == "ONLINE" && $provisioning_status == "ACTIVE" ]] && break
if [ $provisioning_status == "ERROR" ]; then if [ $provisioning_status == "ERROR" ]; then

View File

@ -1,4 +1,6 @@
#!/bin/sh -v #!/bin/sh -v
Body=$(hostname) Body=$(hostname)
Response="HTTP/1.1 200 OK\r\nContent-Length: ${#Body}\r\n\r\n$Body" Response="HTTP/1.1 200 OK\r\nContent-Length: ${#Body}\r\n\r\n$Body"
while true ; do echo -e $Response | nc -llp 80; done while true; do
echo -e $Response | nc -llp 80
done

View File

@ -7,6 +7,7 @@ astroid==1.3.8
automaton==1.14.0 automaton==1.14.0
Babel==2.3.4 Babel==2.3.4
bandit==1.4.0 bandit==1.4.0
bashate==0.5.1
bcrypt==3.1.4 bcrypt==3.1.4
beautifulsoup4==4.6.0 beautifulsoup4==4.6.0
cachetools==2.0.1 cachetools==2.0.1

View File

@ -21,3 +21,4 @@ tempest>=17.1.0 # Apache-2.0
# Required for pep8 - doc8 tests # Required for pep8 - doc8 tests
sphinx!=1.6.6,!=1.6.7,>=1.6.2,<2.0.0;python_version=='2.7' # BSD sphinx!=1.6.6,!=1.6.7,>=1.6.2,<2.0.0;python_version=='2.7' # BSD
sphinx!=1.6.6,!=1.6.7,>=1.6.2;python_version>='3.4' # BSD sphinx!=1.6.6,!=1.6.7,>=1.6.2;python_version>='3.4' # BSD
bashate>=0.5.1 # Apache-2.0

View File

@ -25,8 +25,8 @@ FAILURES=$TMPDIR/failures
check_pot_files_errors () { check_pot_files_errors () {
find octavia -type f -regex '.*\.pot?' \ find octavia -type f -regex '.*\.pot?' \
-print0|xargs -0 -n 1 --no-run-if-empty msgfmt \ -print0|xargs -0 -n 1 --no-run-if-empty msgfmt \
--check-format -o /dev/null --check-format -o /dev/null
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "PO files syntax is not correct!" >>$FAILURES echo "PO files syntax is not correct!" >>$FAILURES
fi fi

16
tox.ini
View File

@ -86,9 +86,11 @@ commands = flake8
python -m unittest specs-tests.test_titles python -m unittest specs-tests.test_titles
sh ./tools/misc-sanity-checks.sh sh ./tools/misc-sanity-checks.sh
{toxinidir}/tools/coding-checks.sh --pylint {posargs} {toxinidir}/tools/coding-checks.sh --pylint {posargs}
{[testenv:bashate]commands}
whitelist_externals = whitelist_externals =
sh sh
find find
bash
[testenv:docs] [testenv:docs]
basepython = python3 basepython = python3
@ -166,6 +168,20 @@ import-order-style = pep8
# [H904]: Delay string interpolations at logging calls # [H904]: Delay string interpolations at logging calls
enable-extensions=H106,H203,H204,H205,H904 enable-extensions=H106,H203,H204,H205,H904
[testenv:bashate]
basepython = python3
envdir = {toxworkdir}/shared
commands = bash -c "find {toxinidir} \
-not \( -type d -name .tox\* -prune \) \
-not \( -type d -name .venv\* -prune \) \
-type f \
-name \*.sh \
# [E005]: File does not begin with #! or have a .sh prefix
# [E006]: Check for lines longer than 79 columns
# [E042]: Local declaration hides errors
# [E043]: Arithmetic compound has inconsistent return semantics
-print0 | xargs -0 bashate -v -iE006 -eE005,E042,E043"
[hacking] [hacking]
import_exceptions = octavia.i18n import_exceptions = octavia.i18n
local-check-factory = octavia.hacking.checks.factory local-check-factory = octavia.hacking.checks.factory