1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-11 16:58:40 +03:00

ctdb-tests: Avoid shellcheck warnings in remaining test stubs

A small amount of effort...

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2022-08-18 08:59:28 +10:00 committed by Amitay Isaacs
parent a31fb7e5ab
commit 4ee0abaece
10 changed files with 64 additions and 44 deletions

View File

@ -5,7 +5,7 @@ prog="ctdb"
# Print a message and exit.
die ()
{
echo "$1" >&2 ; exit ${2:-1}
echo "$1" >&2 ; exit "${2:-1}"
}
not_implemented_exit_code=1
@ -55,13 +55,15 @@ while [ $# -gt 0 ] ; do
done
[ -n "$args" ] || usage
# Want word splitting
# shellcheck disable=SC2086
set -- $args
setup_tickles ()
{
# Make sure tickles file exists.
tickles_file="${CTDB_TEST_TMP_DIR}/fake-ctdb/tickles"
mkdir -p $(dirname "$tickles_file")
mkdir -p "$(dirname "$tickles_file")"
touch "$tickles_file"
}
@ -73,9 +75,9 @@ ctdb_gettickles ()
setup_tickles
echo "|source ip|port|destination ip|port|"
while read _src _dst ; do
if [ -z "$_ip" -o "$_ip" = "${_dst%:*}" ] ; then
if [ -z "$_port" -o "$_port" = "${_dst##*:}" ] ; then
while read -r _src _dst ; do
if [ -z "$_ip" ] || [ "$_ip" = "${_dst%:*}" ] ; then
if [ -z "$_port" ] || [ "$_port" = "${_dst##*:}" ] ; then
echo "|${_src%:*}|${_src##*:}|${_dst%:*}|${_dst##*:}|"
fi
fi
@ -107,7 +109,7 @@ ctdb_deltickle ()
_t=$(grep -F -v "${_src} $${_dst}" "$tickles_file")
else
_t=$(cat "$tickles_file")
while read _src _dst ; do
while read -r _src _dst ; do
_t=$(echo "$_t" | grep -F -v "${_src} ${_dst}")
done
fi
@ -119,9 +121,9 @@ parse_nodespec ()
if [ "$nodespec" = "all" ] ; then
nodes="$(seq 0 $((FAKE_CTDB_NUMNODES - 1)) )"
elif [ -n "$nodespec" ] ; then
nodes="$(echo $nodespec | sed -e 's@,@ @g')"
nodes="$(echo "$nodespec" | sed -e 's@,@ @g')"
else
node=$(ctdb_pnn)
nodes=$(ctdb_pnn)
fi
}
@ -153,6 +155,8 @@ ip_reallocate ()
{
touch "$FAKE_CTDB_IP_LAYOUT"
# ShellCheck doesn't understand this flock pattern
# shellcheck disable=SC2094
(
flock 0
@ -173,7 +177,7 @@ ip_reallocate ()
for _j in "$FAKE_CTDB_STATE/node-state/"*"/$_i" ; do
_tf="${_j%/*}" # dirname
_f="${_tf##*/}" # basename
_this=$(( $_this | $_f ))
_this=$(( _this | _f ))
done
else
_this="0"
@ -209,7 +213,7 @@ ctdb_ip ()
# process output line by line...
_pa="${CTDB_BASE}/public_addresses"
sed -e 's@/@ @' "$_pa" | sort | join - "$FAKE_CTDB_IP_LAYOUT" |
while read _ip _bit _ifaces _pnn ; do
while read -r _ip _ _ifaces _pnn ; do
if $verbose ; then
# If more than 1 interface, assume all addresses are on the 1st.
_first_iface="${_ifaces%%,*}"
@ -240,12 +244,14 @@ ctdb_moveip ()
ip_reallocate # should be harmless and ensures we have good state
# ShellCheck doesn't understand this flock pattern
# shellcheck disable=SC2094
(
flock 0
_t="${FAKE_CTDB_IP_LAYOUT}.new"
while read _i _pnn ; do
while read -r _i _pnn ; do
if [ "$_ip" = "$_i" ] ; then
echo "$_i $_target"
else
@ -261,7 +267,7 @@ ctdb_moveip ()
ctdb_enable ()
{
parse_nodespec
for _i in $nodes ; do
rm -f "${FAKE_CTDB_NODES_DISABLED}/${_i}"
done
@ -298,7 +304,7 @@ ctdb_shutdown ()
ctdb_nodestatus ()
{
echo '|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|'
_line=$(( $FAKE_CTDB_PNN + 1 ))
_line=$(( FAKE_CTDB_PNN + 1 ))
_ip=$(sed -e "${_line}p" "${CTDB_NATGW_NODES:-${CTDB_LVS_NODES}}")
echo "|${FAKE_CTDB_PNN}|${_ip}|0|0|0|0|0|0|0|Y|"
}
@ -371,10 +377,10 @@ ctdb_ptrans ()
{
_t_setup "$1"
while IFS="" read _line ; do
while IFS="" read -r _line ; do
_k=$(echo "$_line" | sed -n -e 's@^"\([^"]*\)" "[^"]*"$@\1@p')
_v=$(echo "$_line" | sed -e 's@^"[^"]*" "\([^"]*\)"$@\1@')
[ -n "$_k" ] || die "ctdb ptrans: bad line \"${line}\""
[ -n "$_k" ] || die "ctdb ptrans: bad line \"${_line}\""
if [ -n "$_v" ] ; then
_t_put "$_k" "$_v"
else
@ -394,8 +400,8 @@ ctdb_catdb ()
[ -r "$_i" ] || continue
_k="${_i##*/}" # basename
_v=$(_t_get "$_k")
_kn=$(echo -n "$_k" | wc -c)
_vn=$(echo -n "$_v" | wc -c)
_kn=$(printf '%s' "$_k" | wc -c)
_vn=$(printf '%s' "$_v" | wc -c)
cat <<EOF
key(${_kn}) = "${_k}"
dmaster: 0
@ -403,7 +409,7 @@ rsn: 1
data(${_vn}) = "${_v}"
EOF
_count=$(($_count + 1))
_count=$((_count + 1))
done
echo "Dumped ${_count} records"
@ -424,7 +430,7 @@ ctdb_ifaces()
# Assume -Y.
echo "|Name|LinkStatus|References|"
while read _ip _iface ; do
while read -r _ip _iface ; do
case "$_ip" in
\#*) : ;;
*)

View File

@ -2,8 +2,9 @@
# Only supports reading from stdin
# shellcheck disable=SC2034
iface="$1" # ignored
while read src dst ; do
while read -r src dst; do
sed -i -e "/^${dst} ${src}\$/d" "$FAKE_NETSTAT_TCP_ESTABLISHED_FILE"
done

View File

@ -5,7 +5,7 @@ prog="ctdb_lvs"
# Print a message and exit.
die ()
{
echo "$1" >&2 ; exit ${2:-1}
echo "$1" >&2 ; exit "${2:-1}"
}
not_implemented_exit_code=1
@ -37,9 +37,9 @@ ctdb_lvs_leader ()
ctdb_lvs_list ()
{
_pnn=0
while read _ip _opts ; do
while read -r _ip _ ; do
echo "${_pnn} ${_ip}"
_pnn=$(($_pnn + 1))
_pnn=$((_pnn + 1))
done <"$CTDB_LVS_NODES"
}

View File

@ -18,12 +18,12 @@ ctdb_natgw_leader ()
# Determine the leader node
_leader="-1 0.0.0.0"
_pnn=0
while read _ip ; do
while read -r _ip ; do
if [ "$FAKE_CTDB_NATGW_LEADER" = "$_ip" ] ; then
_leader="${_pnn} ${_ip}"
break
fi
_pnn=$(($_pnn + 1))
_pnn=$((_pnn + 1))
done <"$CTDB_NATGW_NODES"
echo "$_leader"
}

View File

@ -19,7 +19,7 @@ fs="${1:-/}"
# Anything starting with CTDB_DBDIR_BASE gets canonicalised to
# CTDB_DBDIR_BASE. This helps with the setting of defaults for the
# filesystem checks.
if [ "${fs#${CTDB_DBDIR_BASE}}" != "$fs" ] ; then
if [ "${fs#"${CTDB_DBDIR_BASE}"}" != "$fs" ] ; then
fs="$CTDB_DBDIR_BASE"
fi
@ -31,8 +31,8 @@ fi
echo "Filesystem 1024-blocks Used Available Capacity Mounted on"
blocks="1000000"
used=$(($blocks * $FAKE_FS_USE / 100))
available=$(($blocks - $used))
used=$((blocks * FAKE_FS_USE / 100))
available=$((blocks - used))
printf "%-36s %10d %10d %10d %10d%% %s\n" \
"/dev/sda1" "$blocks" "$used" "$available" "$FAKE_FS_USE" "$fs"

View File

@ -3,7 +3,7 @@
die ()
{
echo "$1" >&2
exit ${2:-1}
exit "${2:-1}"
}
@ -103,16 +103,15 @@ IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
EOF
[ -d "$FAKE_LVS_STATE_DIR" ] || exit 0
cd "$FAKE_LVS_STATE_DIR" || exit 0
(
cd "$FAKE_LVS_STATE_DIR"
for d in *; do
[ -d "$d" ] || continue
echo -n "$d "
printf '%s ' "$d"
cat "${d}/.info"
for f in "${d}/"* ; do
[ -f "$f" ] || continue
read forwarding_method <"$f"
read -r forwarding_method <"$f"
printf " -> %-28s %-7s %-6s %-10s %-10s\n" \
"${f##*/}" "$forwarding_method" 1 0 0
done

View File

@ -27,9 +27,11 @@ parse_options ()
[ "$netid" = "tcp" ] || usage
host="$1" ; shift
[ "$host" = "localhost" -o "$host" = "127.0.0.1" ] || usage
[ "$host" = "localhost" ] || [ "$host" = "127.0.0.1" ] || usage
[ 1 -le $# -a $# -le 2 ] || usage
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
usage
fi
p="$1"
v="$2"
@ -41,12 +43,14 @@ for i in ${FAKE_RPCINFO_SERVICES} ; do
# This is stupidly cummulative, but needs to happen after the
# initial split of the list above.
IFS="${IFS}:"
# Want glob expansion
# shellcheck disable=SC2086
set -- $i
# $1 = program, $2 = low version, $3 = high version
if [ "$1" = "$p" ] ; then
if [ -n "$v" ] ; then
if [ "$2" -le "$v" -a "$v" -le "$3" ] ; then
if [ "$2" -le "$v" ] && [ "$v" -le "$3" ] ; then
echo "program ${p} version ${v} ready and waiting"
exit 0
else
@ -55,7 +59,7 @@ for i in ${FAKE_RPCINFO_SERVICES} ; do
exit 1
fi
else
for j in $(seq $2 $3) ; do
for j in $(seq "$2" "$3") ; do
echo "program ${p} version ${j} ready and waiting"
done
exit 0

View File

@ -31,7 +31,7 @@ while [ $# -gt 0 ] ; do
done
[ $# -eq 0 ] || usage
if [ -z "$cip" -o -z "$sip" -o -z "$mon_name" -o -z "$state" ] ; then
if [ -z "$cip" ] || [ -z "$sip" ] || [ -z "$mon_name" ] || [ -z "$state" ]; then
usage
fi

View File

@ -82,10 +82,11 @@ filter_socket ()
ip="${socket%:*}"
port="${socket##*:}"
if [ "$ok_ports" != "|" -a "${ok_ports#*|${port}|}" = "$ok_ports" ] ; then
if [ "$ok_ports" != "|" ] &&
[ "${ok_ports#*|"${port}"|}" = "$ok_ports" ]; then
return 1
fi
if [ "$ok_ips" != "|" -a "${ok_ips#*|${ip}|}" = "$ok_ips" ] ; then
if [ "$ok_ips" != "|" ] && [ "${ok_ips#*|"${ip}"|}" = "$ok_ips" ]; then
return 1
fi
@ -98,6 +99,8 @@ ss_tcp_established ()
echo "Recv-Q Send-Q Local Address:Port Peer Address:Port"
fi
# Yes, lose the quoting so we can do a hacky parsing job
# shellcheck disable=SC2048,SC2086
parse_filter $*
for i in $FAKE_NETSTAT_TCP_ESTABLISHED ; do
@ -111,7 +114,7 @@ ss_tcp_established ()
if [ -z "$FAKE_NETSTAT_TCP_ESTABLISHED_FILE" ] ; then
return
fi
while read src dst ; do
while read -r src dst ; do
if filter_socket "$srcs" "$sports" "$src" ; then
echo 0 0 "$src" "$dst"
fi
@ -128,6 +131,8 @@ Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port"
EOF
fi
# Yes, lose the quoting so we can do a hacky parsing job
# shellcheck disable=SC2048,SC2086
parse_filter $*
_n=12345
@ -167,15 +172,19 @@ done
shift $((OPTIND - 1))
$tcp || $unix || not_supported "$*"
if [ -z "$all" ]; then
nosupported "$*"
fi
if $tcp ; then
if [ "$1" != "state" -o "$2" != "established" ] || $listen ; then
if [ "$1" != "state" ] || [ "$2" != "established" ] || $listen; then
usage
fi
shift 2
# Yes, lose the quoting so we can do a hacky parsing job
# shellcheck disable=SC2048,SC2086
ss_tcp_established $*
exit
@ -187,6 +196,7 @@ if $unix ; then
fi
# Yes, lose the quoting so we can do a hacky parsing job
# shellcheck disable=SC2048,SC2086
unix_listen $*
exit

View File

@ -23,11 +23,11 @@ do_cmd ()
case "$*" in
*check) do_check ;;
help) do_help ;;
"") read tdb_cmd && [ -n "$tdb_cmd" ] && do_cmd $tdb_cmd ;;
"") read -r tdb_cmd && [ -n "$tdb_cmd" ] && do_cmd "$tdb_cmd" ;;
*) echo "$0: Not implemented: $*" ; exit 1 ;;
esac
}
do_cmd $*
do_cmd "$@"
exit 0