]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Factor out functions to detect when generation changes
authorMartin Schwenke <martin@meltin.net>
Sat, 22 Jan 2022 19:42:52 +0000 (06:42 +1100)
committerAmitay Isaacs <amitay@samba.org>
Mon, 14 Feb 2022 01:47:31 +0000 (01:47 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14958

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/INTEGRATION/simple/cluster.015.reclock_remove_lock.sh
ctdb/tests/scripts/integration.bash

index 35363d11f1d1ec398afba928fdd90b08cce8670f..2283c30edbfdbd7a3243574f685570af28c62132 100755 (executable)
@@ -56,24 +56,14 @@ echo
 
 leader_get "$test_node"
 
-echo "Get initial generation"
-ctdb_onnode "$test_node" status
-# shellcheck disable=SC2154
-# $outfile set by ctdb_onnode() above
-generation_init=$(sed -n -e 's/^Generation:\([0-9]*\)/\1/p' "$outfile")
-echo "Initial generation is ${generation_init}"
-echo
+generation_get
 
 echo "Remove recovery lock"
 rm "$reclock"
 echo
 
 # This will mean an election has taken place and a recovery has occured
-echo "Wait until generation changes"
-wait_until 30 generation_has_changed "$test_node" "$generation_init"
-echo
-echo "Generation changed to ${generation_new}"
-echo
+wait_until_generation_has_changed "$test_node"
 
 # shellcheck disable=SC2154
 # $leader set by leader_get() above
index 25ee4d945cc9d94f7c04d6c2085accde7b6a692b..eb3db1e18495ab7a361d413b03c438d60144c783 100644 (file)
@@ -688,6 +688,50 @@ wait_until_leader_has_changed ()
 
 #######################################
 
+# sets: generation
+_generation_get ()
+{
+       local node="$1"
+
+       ctdb_onnode "$node" status
+       # shellcheck disable=SC2154
+       # $outfile set by ctdb_onnode() above
+       generation=$(sed -n -e 's/^Generation:\([0-9]*\)/\1/p' "$outfile")
+}
+
+generation_get ()
+{
+       local node="$1"
+
+       echo "Get generation"
+       _generation_get "$node"
+       echo "Generation is ${generation}"
+       echo
+}
+
+_generation_has_changed ()
+{
+       local node="$1"
+       local generation_old="$2"
+
+       _generation_get "$node"
+
+       [ "$generation" != "$generation_old" ]
+}
+
+# uses: generation
+wait_until_generation_has_changed ()
+{
+       local node="$1"
+
+       echo "Wait until generation changes..."
+       wait_until 30 _generation_has_changed "$node" "$generation"
+       echo "Generation changed to ${generation}"
+       echo
+}
+
+#######################################
+
 wait_for_monitor_event ()
 {
     local pnn="$1"