diff options
author | Martin Schwenke <martin@meltin.net> | 2022-08-18 08:59:28 +1000 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2022-09-16 03:36:32 +0000 |
commit | 4ee0abaece92efd28901801c020cfdf5b80fcadb (patch) | |
tree | 794462cc40cc97d0572d18a70d732585b83652d5 /ctdb | |
parent | a31fb7e5ab8439349bc2670b3fde1020ba2c48b5 (diff) | |
download | samba-4ee0abaece92efd28901801c020cfdf5b80fcadb.tar.gz |
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>
Diffstat (limited to 'ctdb')
-rwxr-xr-x | ctdb/tests/UNIT/eventscripts/stubs/ctdb | 44 | ||||
-rwxr-xr-x | ctdb/tests/UNIT/eventscripts/stubs/ctdb_killtcp | 3 | ||||
-rwxr-xr-x | ctdb/tests/UNIT/eventscripts/stubs/ctdb_lvs | 6 | ||||
-rwxr-xr-x | ctdb/tests/UNIT/eventscripts/stubs/ctdb_natgw | 4 | ||||
-rwxr-xr-x | ctdb/tests/UNIT/eventscripts/stubs/df | 6 | ||||
-rwxr-xr-x | ctdb/tests/UNIT/eventscripts/stubs/ipvsadm | 9 | ||||
-rwxr-xr-x | ctdb/tests/UNIT/eventscripts/stubs/rpcinfo | 12 | ||||
-rwxr-xr-x | ctdb/tests/UNIT/eventscripts/stubs/smnotify | 2 | ||||
-rwxr-xr-x | ctdb/tests/UNIT/eventscripts/stubs/ss | 18 | ||||
-rwxr-xr-x | ctdb/tests/UNIT/eventscripts/stubs/tdbtool | 4 |
10 files changed, 64 insertions, 44 deletions
diff --git a/ctdb/tests/UNIT/eventscripts/stubs/ctdb b/ctdb/tests/UNIT/eventscripts/stubs/ctdb index fc7bd4fdd84..a1d1e2f4759 100755 --- a/ctdb/tests/UNIT/eventscripts/stubs/ctdb +++ b/ctdb/tests/UNIT/eventscripts/stubs/ctdb @@ -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 \#*) : ;; *) diff --git a/ctdb/tests/UNIT/eventscripts/stubs/ctdb_killtcp b/ctdb/tests/UNIT/eventscripts/stubs/ctdb_killtcp index cb5b6e57374..0f40058ee57 100755 --- a/ctdb/tests/UNIT/eventscripts/stubs/ctdb_killtcp +++ b/ctdb/tests/UNIT/eventscripts/stubs/ctdb_killtcp @@ -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 diff --git a/ctdb/tests/UNIT/eventscripts/stubs/ctdb_lvs b/ctdb/tests/UNIT/eventscripts/stubs/ctdb_lvs index 85e005c0b36..3a90d00581f 100755 --- a/ctdb/tests/UNIT/eventscripts/stubs/ctdb_lvs +++ b/ctdb/tests/UNIT/eventscripts/stubs/ctdb_lvs @@ -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" } diff --git a/ctdb/tests/UNIT/eventscripts/stubs/ctdb_natgw b/ctdb/tests/UNIT/eventscripts/stubs/ctdb_natgw index e64a95695bb..83ba59c555d 100755 --- a/ctdb/tests/UNIT/eventscripts/stubs/ctdb_natgw +++ b/ctdb/tests/UNIT/eventscripts/stubs/ctdb_natgw @@ -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" } diff --git a/ctdb/tests/UNIT/eventscripts/stubs/df b/ctdb/tests/UNIT/eventscripts/stubs/df index a2e7093293d..8abad178ffc 100755 --- a/ctdb/tests/UNIT/eventscripts/stubs/df +++ b/ctdb/tests/UNIT/eventscripts/stubs/df @@ -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" diff --git a/ctdb/tests/UNIT/eventscripts/stubs/ipvsadm b/ctdb/tests/UNIT/eventscripts/stubs/ipvsadm index 0567f881e54..226d7b4d9a8 100755 --- a/ctdb/tests/UNIT/eventscripts/stubs/ipvsadm +++ b/ctdb/tests/UNIT/eventscripts/stubs/ipvsadm @@ -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 diff --git a/ctdb/tests/UNIT/eventscripts/stubs/rpcinfo b/ctdb/tests/UNIT/eventscripts/stubs/rpcinfo index dd6de3b1826..45e4a97ca56 100755 --- a/ctdb/tests/UNIT/eventscripts/stubs/rpcinfo +++ b/ctdb/tests/UNIT/eventscripts/stubs/rpcinfo @@ -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 diff --git a/ctdb/tests/UNIT/eventscripts/stubs/smnotify b/ctdb/tests/UNIT/eventscripts/stubs/smnotify index 78710346998..c3b9f80c69b 100755 --- a/ctdb/tests/UNIT/eventscripts/stubs/smnotify +++ b/ctdb/tests/UNIT/eventscripts/stubs/smnotify @@ -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 diff --git a/ctdb/tests/UNIT/eventscripts/stubs/ss b/ctdb/tests/UNIT/eventscripts/stubs/ss index 54ff436edd7..b174243cd6f 100755 --- a/ctdb/tests/UNIT/eventscripts/stubs/ss +++ b/ctdb/tests/UNIT/eventscripts/stubs/ss @@ -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 diff --git a/ctdb/tests/UNIT/eventscripts/stubs/tdbtool b/ctdb/tests/UNIT/eventscripts/stubs/tdbtool index 816df3b3f58..c88615d35e3 100755 --- a/ctdb/tests/UNIT/eventscripts/stubs/tdbtool +++ b/ctdb/tests/UNIT/eventscripts/stubs/tdbtool @@ -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 |