]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Allow tunables unit test to process a second file
authorMartin Schwenke <mschwenke@ddn.com>
Wed, 25 Jun 2025 12:14:05 +0000 (22:14 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 22 Jul 2025 23:02:34 +0000 (23:02 +0000)
The second file is optional.

Make $tfile the default to avoid having to update all of the single
file testcases.

Add test cases for second file.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/UNIT/cunit/tunable_test_001.sh
ctdb/tests/src/tunable_test.c

index 1b67cc831894e9aa4ab39ef10e54ad5a1db9b38f..caac08bd2451cdb09b3bce96cd93a48ecc7ecf6c 100755 (executable)
@@ -3,10 +3,11 @@
 . "${TEST_SCRIPTS_DIR}/unit.sh"
 
 tfile="${CTDB_TEST_TMP_DIR}/tunable.$$"
+tfile2="${CTDB_TEST_TMP_DIR}/tunable2.$$"
 
 remove_files()
 {
-       rm -f "$tfile"
+       rm -f "$tfile" "$tfile2"
 }
 test_cleanup remove_files
 
@@ -111,9 +112,12 @@ ok_tunable_1()
 }
 
 # Set required output to a version of $defaults where values for
-# tunables specified in $tfile replace the default values
+# tunables specified in the given file(s) replace the default values
 ok_tunable()
 {
+       _f1="${1:-"${tfile}"}"
+       _f2="${2:-""}"
+
        # Construct a version of $defaults prepended with a lowercase
        # version of the tunable variable, to allow case-insensitive
        # matching.  This would be easier with the GNU sed
@@ -125,7 +129,15 @@ ok_tunable()
 
        log=""
 
-       ok_tunable_1 "$tfile"
+       #
+       # Replace values for tunables that are set in each file
+       #
+
+       ok_tunable_1 "$_f1"
+
+       if [ -n "$_f2" ]; then
+               ok_tunable_1 "$_f2"
+       fi
 
        # Set result, stripping off lowercase tunable prefix
        ok "${log}$(echo "$_map" | awk -F: '{ print $2 }')"
@@ -359,3 +371,42 @@ ReCoVerInTeRvAl     =    10
 EOF
 ok_tunable
 unit_test tunable_test "$tfile"
+
+#
+# Subsequent tests will use the same 1st file, to reduce clutter
+#
+
+cat >"$tfile" <<EOF
+EnableBans=0
+RecoverInterval=10
+ElectionTimeout=5
+EOF
+
+#
+# 2nd argument is a file
+#
+
+test_case "OK, several tunables, empty 2nd file"
+: >"$tfile2"
+ok_tunable "$tfile" "$tfile2"
+unit_test tunable_test "$tfile" "$tfile2"
+
+test_case "OK, several tunables, 2nd file disjoint"
+cat >"$tfile2" <<EOF
+RecoverTimeout=123
+EOF
+ok_tunable "$tfile" "$tfile2"
+unit_test tunable_test "$tfile" "$tfile2"
+
+test_case "OK, several tunables, 2nd file overlaps"
+cat >"$tfile2" <<EOF
+RecoverTimeout=123
+ElectionTimeout=10
+EOF
+ok_tunable "$tfile" "$tfile2"
+unit_test tunable_test "$tfile" "$tfile2"
+
+test_case "OK, several tunables, missing 2nd file"
+rm -f "$tfile2"
+ok_tunable "$tfile" "$tfile2"
+unit_test tunable_test "$tfile" "$tfile2"
index d98900e4e10216b7110d877f0d4d4dd49e51da0e..2a40eddbc1dd27f4c6bd3149e086e1828bf72984 100644 (file)
@@ -36,8 +36,8 @@ int main(int argc, const char **argv)
        int ret = 0;
        int i;
 
-       if (argc != 2) {
-               fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
+       if (argc != 2 && argc != 3) {
+               fprintf(stderr, "Usage: %s <filename> [<filename>]\n", argv[0]);
                return 1;
        }
 
@@ -54,6 +54,14 @@ int main(int argc, const char **argv)
                goto done;
        }
 
+       if (argc == 3) {
+               status = ctdb_tunable_load_file(mem_ctx, &tun_list, argv[2]);
+               if (!status) {
+                       ret = EINVAL;
+                       goto done;
+               }
+       }
+
        list = ctdb_tunable_names(mem_ctx);
        assert(list != NULL);