From: Martin Schwenke Date: Fri, 27 Jun 2025 07:35:03 +0000 (+1000) Subject: ctdb-tests: Add tests for tunables directory loading X-Git-Tag: tdb-1.4.14~85 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=6863799ce93b655f2f412f304b1556b9f09dd1a9;p=thirdparty%2Fsamba.git ctdb-tests: Add tests for tunables directory loading The missing 2nd file testcase becomes the missing directory testcase, because you can't easily have both. See the comment in tunable_test.c. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/tests/UNIT/cunit/tunable_test_001.sh b/ctdb/tests/UNIT/cunit/tunable_test_001.sh index caac08bd245..a639c8772cb 100755 --- a/ctdb/tests/UNIT/cunit/tunable_test_001.sh +++ b/ctdb/tests/UNIT/cunit/tunable_test_001.sh @@ -4,10 +4,13 @@ tfile="${CTDB_TEST_TMP_DIR}/tunable.$$" tfile2="${CTDB_TEST_TMP_DIR}/tunable2.$$" +tdir="${CTDB_TEST_TMP_DIR}/tunabled.$$" remove_files() { rm -f "$tfile" "$tfile2" + rm -f "${tdir}/"* 2>/dev/null || true + rmdir "$tdir" 2>/dev/null || true } test_cleanup remove_files @@ -136,7 +139,18 @@ ok_tunable() ok_tunable_1 "$_f1" if [ -n "$_f2" ]; then - ok_tunable_1 "$_f2" + if [ -f "$_f2" ]; then + ok_tunable_1 "$_f2" + elif [ -d "$_f2" ]; then + for _t in "${_f2}/"*.tunables; do + if [ ! -e "$_t" ]; then + break + fi + ok_tunable_1 "$_t" + done + elif [ ! -e "$_f2" ]; then + tunable_log "INFO" "Optional tunables directory ${_f2} not found" + fi fi # Set result, stripping off lowercase tunable prefix @@ -406,7 +420,68 @@ EOF ok_tunable "$tfile" "$tfile2" unit_test tunable_test "$tfile" "$tfile2" -test_case "OK, several tunables, missing 2nd file" +# +# 2nd argument is a directory +# + +test_case "OK, several tunables, missing directory" rm -f "$tfile2" -ok_tunable "$tfile" "$tfile2" -unit_test tunable_test "$tfile" "$tfile2" +rmdir "$tdir" 2>/dev/null || true +ok_tunable "$tfile" "$tdir" +unit_test tunable_test "$tfile" "$tdir" + +test_case "OK, several tunables, empty directory" +mkdir -p "$tdir" +ok_tunable "$tfile" "$tdir" +unit_test tunable_test "$tfile" "$tdir" + +test_case "OK, several tunables, README in directory" +cat >"${tdir}/README" <"${tdir}/f70.tunables" <"${tdir}/f10.tunables" <"${tdir}/f40.tunables" <"${tdir}/f20.tunables" < [|]\n", + prog); + exit(1); +} + int main(int argc, const char **argv) { TALLOC_CTX *mem_ctx; @@ -37,8 +45,7 @@ int main(int argc, const char **argv) int i; if (argc != 2 && argc != 3) { - fprintf(stderr, "Usage: %s []\n", argv[0]); - return 1; + usage(argv[0]); } mem_ctx = talloc_new(NULL); @@ -55,7 +62,33 @@ int main(int argc, const char **argv) } if (argc == 3) { - status = ctdb_tunable_load_file(mem_ctx, &tun_list, argv[2]); + struct stat st = {}; + int stat_failed = false; + + ret = stat(argv[2], &st); + if (ret != 0) { + if (errno == ENOENT || errno == EACCES) { + stat_failed = true; + } else { + usage(argv[0]); + } + } + + /* + * If stat() failed then continue and test the failure + * path in directory loading. The failure path in + * file loading can already be tested with the + * mandatory 1st file argument. + */ + if (stat_failed || S_ISDIR(st.st_mode)) { + status = ctdb_tunable_load_directory(mem_ctx, + &tun_list, + argv[2]); + } else { + status = ctdb_tunable_load_file(mem_ctx, + &tun_list, + argv[2]); + } if (!status) { ret = EINVAL; goto done; @@ -65,6 +98,7 @@ int main(int argc, const char **argv) list = ctdb_tunable_names(mem_ctx); assert(list != NULL); + ret = 0; for (i = 0; i < list->count; i++) { const char *var = list->var[i]; uint32_t val;