Enforce function declaration format in bash8
Check that function calls look like ^function foo {$ in bash8, and fix
all existing failures of that check. Add a note to HACKING.rst
Change-Id: Ic19eecb39e0b20273d1bcd551a42fe400d54e938
diff --git a/tools/bash8.py b/tools/bash8.py
index f89b241..3abf87b 100755
--- a/tools/bash8.py
+++ b/tools/bash8.py
@@ -102,6 +102,21 @@
if (len(m.group('indent')) % 4) != 0:
print_error('E003: Indent not multiple of 4', line)
+def check_function_decl(line):
+ failed = False
+ if line.startswith("function"):
+ if not re.search('^function [\w-]* \{$', line):
+ failed = True
+ else:
+ # catch the case without "function", e.g.
+ # things like '^foo() {'
+ if re.search('^\s*?\(\)\s*?\{', line):
+ failed = True
+
+ if failed:
+ print_error('E020: Function declaration not in format '
+ ' "^function name {$"', line)
+
def starts_multiline(line):
m = re.search("[^<]<<\s*(?P<token>\w+)", line)
@@ -169,6 +184,7 @@
check_indents(logical_line)
check_for_do(logical_line)
check_if_then(logical_line)
+ check_function_decl(logical_line)
prev_line = logical_line
prev_lineno = fileinput.filelineno()
diff --git a/tools/build_pxe_env.sh b/tools/build_pxe_env.sh
index e6f98b4..50d91d0 100755
--- a/tools/build_pxe_env.sh
+++ b/tools/build_pxe_env.sh
@@ -17,7 +17,7 @@
PROGDIR=`dirname $0`
# Clean up any resources that may be in use
-cleanup() {
+function cleanup {
set +o errexit
# Mop up temporary files
diff --git a/tools/build_ramdisk.sh b/tools/build_ramdisk.sh
index 7372555..50ba8ef 100755
--- a/tools/build_ramdisk.sh
+++ b/tools/build_ramdisk.sh
@@ -14,7 +14,7 @@
fi
# Clean up any resources that may be in use
-cleanup() {
+function cleanup {
set +o errexit
# Mop up temporary files
@@ -87,7 +87,7 @@
# Finds and returns full device path for the next available NBD device.
# Exits script if error connecting or none free.
# map_nbd image
-function map_nbd() {
+function map_nbd {
for i in `seq 0 15`; do
if [ ! -e /sys/block/nbd$i/pid ]; then
NBD=/dev/nbd$i
diff --git a/tools/build_uec_ramdisk.sh b/tools/build_uec_ramdisk.sh
index 3ab5daf..5f3acc5 100755
--- a/tools/build_uec_ramdisk.sh
+++ b/tools/build_uec_ramdisk.sh
@@ -20,7 +20,7 @@
fi
# Clean up resources that may be in use
-cleanup() {
+function cleanup {
set +o errexit
if [ -n "$MNT_DIR" ]; then
diff --git a/tools/build_usb_boot.sh b/tools/build_usb_boot.sh
index 8566229..c97e0a1 100755
--- a/tools/build_usb_boot.sh
+++ b/tools/build_usb_boot.sh
@@ -13,7 +13,7 @@
PXEDIR=${PXEDIR:-/opt/ramstack/pxe}
# Clean up any resources that may be in use
-cleanup() {
+function cleanup {
set +o errexit
# Mop up temporary files
diff --git a/tools/copy_dev_environment_to_uec.sh b/tools/copy_dev_environment_to_uec.sh
index 3fd4423..94a4926 100755
--- a/tools/copy_dev_environment_to_uec.sh
+++ b/tools/copy_dev_environment_to_uec.sh
@@ -22,7 +22,7 @@
source ./stackrc
# Echo usage
-usage() {
+function usage {
echo "Add stack user and keys"
echo ""
echo "Usage: $0 [full path to raw uec base image]"
diff --git a/tools/create_userrc.sh b/tools/create_userrc.sh
index cd5a1c9..47da334 100755
--- a/tools/create_userrc.sh
+++ b/tools/create_userrc.sh
@@ -11,8 +11,7 @@
ACCOUNT_DIR=./accrc
-display_help()
-{
+function display_help {
cat <<EOF
usage: $0 <options..>
@@ -151,7 +150,7 @@
fi
-function add_entry(){
+function add_entry {
local user_id=$1
local user_name=$2
local tenant_id=$3
@@ -213,7 +212,7 @@
}
#admin users expected
-function create_or_get_tenant(){
+function create_or_get_tenant {
local tenant_name=$1
local tenant_id=`keystone tenant-list | awk '/\|[[:space:]]*'"$tenant_name"'[[:space:]]*\|.*\|/ {print $2}'`
if [ -n "$tenant_id" ]; then
@@ -223,7 +222,7 @@
fi
}
-function create_or_get_role(){
+function create_or_get_role {
local role_name=$1
local role_id=`keystone role-list| awk '/\|[[:space:]]*'"$role_name"'[[:space:]]*\|/ {print $2}'`
if [ -n "$role_id" ]; then
@@ -234,7 +233,7 @@
}
# Provides empty string when the user does not exists
-function get_user_id(){
+function get_user_id {
local user_name=$1
keystone user-list | awk '/^\|[^|]*\|[[:space:]]*'"$user_name"'[[:space:]]*\|.*\|/ {print $2}'
}
diff --git a/tools/fixup_stuff.sh b/tools/fixup_stuff.sh
index 47b0cd1..7833278 100755
--- a/tools/fixup_stuff.sh
+++ b/tools/fixup_stuff.sh
@@ -40,7 +40,7 @@
# ---------------
# get_package_path python-package # in import notation
-function get_package_path() {
+function get_package_path {
local package=$1
echo $(python -c "import os; import $package; print(os.path.split(os.path.realpath($package.__file__))[0])")
}
diff --git a/tools/get_uec_image.sh b/tools/get_uec_image.sh
index da13f4b..225742c 100755
--- a/tools/get_uec_image.sh
+++ b/tools/get_uec_image.sh
@@ -18,7 +18,7 @@
set -o errexit
set -o xtrace
-usage() {
+function usage {
echo "Usage: $0 - Download and prepare Ubuntu UEC images"
echo ""
echo "$0 [-r rootsize] release imagefile [kernel]"
@@ -31,7 +31,7 @@
}
# Clean up any resources that may be in use
-cleanup() {
+function cleanup {
set +o errexit
# Mop up temporary files
diff --git a/tools/info.sh b/tools/info.sh
index 1e521b9..a8f9544 100755
--- a/tools/info.sh
+++ b/tools/info.sh
@@ -61,7 +61,7 @@
# -----
# git_report <dir>
-function git_report() {
+function git_report {
local dir=$1
local proj ref branch head
if [[ -d $dir/.git ]]; then
diff --git a/tools/install_openvpn.sh b/tools/install_openvpn.sh
index 2f52aa1..9a4f036 100755
--- a/tools/install_openvpn.sh
+++ b/tools/install_openvpn.sh
@@ -22,7 +22,7 @@
fi
# Do some IP manipulation
-function cidr2netmask() {
+function cidr2netmask {
set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
if [[ $1 -gt 1 ]]; then
shift $1
@@ -50,7 +50,7 @@
VPN_DIR=/etc/openvpn
CA_DIR=$VPN_DIR/easy-rsa
-usage() {
+function usage {
echo "$0 - OpenVPN install and certificate generation"
echo ""
echo "$0 --client name"
@@ -102,7 +102,7 @@
openvpn --genkey --secret $CA_DIR/keys/ta.key ## Build a TLS key
fi
-do_server() {
+function do_server {
NAME=$1
# Generate server certificate
$CA_DIR/pkitool --server $NAME
@@ -162,7 +162,7 @@
/etc/init.d/openvpn restart
}
-do_client() {
+function do_client {
NAME=$1
# Generate a client certificate
$CA_DIR/pkitool $NAME
diff --git a/tools/install_pip.sh b/tools/install_pip.sh
index d714d33..9fa161e 100755
--- a/tools/install_pip.sh
+++ b/tools/install_pip.sh
@@ -50,7 +50,7 @@
GetDistro
echo "Distro: $DISTRO"
-function get_versions() {
+function get_versions {
PIP=$(which pip 2>/dev/null || which pip-python 2>/dev/null || true)
if [[ -n $PIP ]]; then
PIP_VERSION=$($PIP --version | awk '{ print $2}')
@@ -61,7 +61,7 @@
}
-function install_get_pip() {
+function install_get_pip {
if [[ ! -r $FILES/get-pip.py ]]; then
(cd $FILES; \
curl -O $PIP_GET_PIP_URL; \
@@ -70,7 +70,7 @@
sudo -E python $FILES/get-pip.py
}
-function install_pip_tarball() {
+function install_pip_tarball {
(cd $FILES; \
curl -O $PIP_TAR_URL; \
tar xvfz pip-$INSTALL_PIP_VERSION.tar.gz 1>/dev/null; \
diff --git a/tools/jenkins/build_configuration.sh b/tools/jenkins/build_configuration.sh
index e295ef2..64ee159 100755
--- a/tools/jenkins/build_configuration.sh
+++ b/tools/jenkins/build_configuration.sh
@@ -5,7 +5,7 @@
ADAPTER=$3
RC=$4
-function usage() {
+function usage {
echo "Usage: $0 - Build a configuration"
echo ""
echo "$0 [EXECUTOR_NUMBER] [CONFIGURATION] [ADAPTER] [RC (optional)]"
diff --git a/tools/jenkins/configurations/kvm.sh b/tools/jenkins/configurations/kvm.sh
index d9a160a..6927fd7 100755
--- a/tools/jenkins/configurations/kvm.sh
+++ b/tools/jenkins/configurations/kvm.sh
@@ -9,7 +9,7 @@
ADAPTER=$3
RC=$4
-function usage() {
+function usage {
echo "Usage: $0 - Build a test configuration"
echo ""
echo "$0 [EXECUTOR_NUMBER] [CONFIGURATION] [ADAPTER] [RC (optional)]"
diff --git a/tools/jenkins/configurations/xs.sh b/tools/jenkins/configurations/xs.sh
index 864f949..7b671e9 100755
--- a/tools/jenkins/configurations/xs.sh
+++ b/tools/jenkins/configurations/xs.sh
@@ -8,7 +8,7 @@
ADAPTER=$3
RC=$4
-function usage() {
+function usage {
echo "Usage: $0 - Build a test configuration"
echo ""
echo "$0 [EXECUTOR_NUMBER] [CONFIGURATION] [ADAPTER] [RC (optional)]"
diff --git a/tools/jenkins/run_test.sh b/tools/jenkins/run_test.sh
index 4649563..d2b8284 100755
--- a/tools/jenkins/run_test.sh
+++ b/tools/jenkins/run_test.sh
@@ -4,7 +4,7 @@
ADAPTER=$2
RC=$3
-function usage() {
+function usage {
echo "Usage: $0 - Run a test"
echo ""
echo "$0 [EXECUTOR_NUMBER] [ADAPTER] [RC (optional)]"
diff --git a/tools/warm_apts_for_uec.sh b/tools/warm_apts_for_uec.sh
index 3c15f52..c57fc2e 100755
--- a/tools/warm_apts_for_uec.sh
+++ b/tools/warm_apts_for_uec.sh
@@ -16,7 +16,7 @@
cd $TOP_DIR
# Echo usage
-usage() {
+function usage {
echo "Cache OpenStack dependencies on a uec image to speed up performance."
echo ""
echo "Usage: $0 [full path to raw uec base image]"
diff --git a/tools/xen/build_xva.sh b/tools/xen/build_xva.sh
index fbbfd6f..cc3cbe1 100755
--- a/tools/xen/build_xva.sh
+++ b/tools/xen/build_xva.sh
@@ -42,7 +42,7 @@
#
GUEST_NAME="$1"
-function _print_interface_config() {
+function _print_interface_config {
local device_nr
local ip_address
local netmask
@@ -68,7 +68,7 @@
echo " post-up ethtool -K $device tx off"
}
-function print_interfaces_config() {
+function print_interfaces_config {
echo "auto lo"
echo "iface lo inet loopback"
diff --git a/tools/xen/install_os_domU.sh b/tools/xen/install_os_domU.sh
index 7b59bae..a4b3e06 100755
--- a/tools/xen/install_os_domU.sh
+++ b/tools/xen/install_os_domU.sh
@@ -166,7 +166,7 @@
SNAME_TEMPLATE="jeos_snapshot_for_devstack"
SNAME_FIRST_BOOT="before_first_boot"
-function wait_for_VM_to_halt() {
+function wait_for_VM_to_halt {
set +x
echo "Waiting for the VM to halt. Progress in-VM can be checked with vncviewer:"
mgmt_ip=$(echo $XENAPI_CONNECTION_URL | tr -d -c '1234567890.')
@@ -318,7 +318,7 @@
#
xe vm-start vm="$GUEST_NAME"
-function ssh_no_check() {
+function ssh_no_check {
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@"
}
@@ -349,7 +349,7 @@
xenstore-write /local/domain/$DOMID/authorized_keys/$DOMZERO_USER "$(cat /root/dom0key.pub)"
xenstore-chmod -u /local/domain/$DOMID/authorized_keys/$DOMZERO_USER r$DOMID
-function run_on_appliance() {
+function run_on_appliance {
ssh \
-i /root/dom0key \
-o UserKnownHostsFile=/dev/null \
diff --git a/tools/xen/prepare_guest.sh b/tools/xen/prepare_guest.sh
index 0946126..440774e 100755
--- a/tools/xen/prepare_guest.sh
+++ b/tools/xen/prepare_guest.sh
@@ -21,7 +21,7 @@
DOMZERO_USER="$4"
-function setup_domzero_user() {
+function setup_domzero_user {
local username
username="$1"