ctdb-tests: Factor out function check_cattdb_num_records()
authorMartin Schwenke <martin@meltin.net>
Mon, 12 Aug 2019 11:02:47 +0000 (21:02 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 24 Oct 2019 04:06:44 +0000 (04:06 +0000)
This can be use in multiple vacuuming tests.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/INTEGRATION/database/recovery.003.no_resurrect.sh
ctdb/tests/INTEGRATION/database/scripts/local.bash [new file with mode: 0644]

index 51d806a5d47236cdfa22bcf638761d031ec953c0..b65452c0e0648a4cd36c79df731d37872f7f1ff7 100755 (executable)
@@ -43,16 +43,9 @@ try_command_on_node $second $CTDB deletekey "$testdb" test1
 
 database_has_zero_records ()
 {
-       local n
-       for n in $notfirst ; do
-               local num_records
-               num_records=$(db_ctdb_cattdb_count_records "$n" "$testdb")
-               if [ "$num_records" != 0 ] ; then
-                       return 1
-               fi
-       done
-
-       return 0
+       # shellcheck disable=SC2086
+       # $notfirst can be multi-word
+       check_cattdb_num_records "$testdb" 0 "$notfirst"
 }
 
 echo "Trigger a recovery"
diff --git a/ctdb/tests/INTEGRATION/database/scripts/local.bash b/ctdb/tests/INTEGRATION/database/scripts/local.bash
new file mode 100644 (file)
index 0000000..c36f155
--- /dev/null
@@ -0,0 +1,31 @@
+# Hey Emacs, this is a -*- shell-script -*- !!!  :-)
+
+check_cattdb_num_records ()
+{
+       local db="$1"
+       local num="$2"
+       local nodes="$3"
+
+       # $nodes has embedded newlines - put list on 1 line for printing
+       local t
+       t=$(echo "$nodes" | xargs)
+       echo "Confirm that ${db} has ${num} record(s) on node(s): ${t}"
+
+       local ret=0
+       local node
+       for node in $nodes ; do
+               local num_found
+
+               num_found=$(db_ctdb_cattdb_count_records "$node" "$db")
+               if [ "$num_found" = "$num" ] ; then
+                       continue
+               fi
+
+               printf 'BAD: %s on node %d has %d record(s), expected %d\n' \
+                      "$db" "$node" "$num_found" "$num"
+               ctdb_onnode -v "$node" "cattdb $db"
+               ret=1
+       done
+
+       return $ret
+}