ctdb-tools: Add logging config options to config tool
authorAmitay Isaacs <amitay@gmail.com>
Tue, 17 Apr 2018 12:15:41 +0000 (22:15 +1000)
committerMartin Schwenke <martins@samba.org>
Sat, 12 May 2018 13:01:32 +0000 (15:01 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Autobuild-User(master): Martin Schwenke <martins@samba.org>
Autobuild-Date(master): Sat May 12 15:01:32 CEST 2018 on sn-devel-144

ctdb/common/conf_tool.c
ctdb/tests/cunit/config_test_001.sh
ctdb/tests/cunit/config_test_002.sh [new file with mode: 0755]
ctdb/wscript

index 108cf67b651a2ea911df00ad881b497a21c6f2d0..1ee4b027de7ec363b0f053852a1c8970637c7994 100644 (file)
@@ -28,6 +28,8 @@
 #include "common/conf.h"
 #include "common/path.h"
 
+#include "common/logging_conf.h"
+
 #include "common/conf_tool.h"
 
 struct conf_tool_context {
@@ -233,6 +235,7 @@ int conf_tool_run(struct conf_tool_context *ctx, int *result)
        }
 
        /* Call functions to initialize config sections/variables */
+       logging_conf_init(ctx->conf, NULL);
 
        if (! conf_valid(ctx->conf)) {
                D_ERR("Failed to define configuration options\n");
index 6c95c05f0b8165125d1e55ac3ebd2fae5ad18555..084f1a3b29d391984a6191425b296624f17aeb54 100755 (executable)
@@ -15,7 +15,13 @@ remove_files ()
 
 test_cleanup remove_files
 
+# Get the default values that are dependent on install prefix
+logging_location=$(ctdb-config get "logging" "location")
+
 ok <<EOF
+[logging]
+       # location = ${logging_location}
+       # log level = ERROR
 EOF
 unit_test ctdb-config dump
 
diff --git a/ctdb/tests/cunit/config_test_002.sh b/ctdb/tests/cunit/config_test_002.sh
new file mode 100755 (executable)
index 0000000..6491fa8
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+PATH="$PATH:$CTDB_SCRIPTS_TOOLS_HELPER_DIR"
+
+setup_ctdb_base "${TEST_VAR_DIR}" "cunit"
+
+conffile="${CTDB_BASE}/ctdb.conf"
+
+remove_files ()
+{
+       rm -f "$conffile"
+}
+
+test_cleanup remove_files
+
+cat > "$conffile" <<EOF
+EOF
+
+ok <<EOF
+ERROR
+EOF
+unit_test ctdb-config get "logging" "log level"
+
+cat > "$conffile" <<EOF
+[logging]
+    location = syslog:magic
+EOF
+
+required_result 22 <<EOF
+conf: validation for option "location" failed
+Failed to load config file $conffile
+EOF
+unit_test ctdb-config validate
+
+cat > "$conffile" <<EOF
+[logging]
+    log level = high
+EOF
+
+required_result 22 <<EOF
+conf: validation for option "log level" failed
+Failed to load config file $conffile
+EOF
+unit_test ctdb-config validate
+
+cat > "$conffile" <<EOF
+[logging]
+    location = syslog
+    log level = notice
+EOF
+
+ok_null
+unit_test ctdb-config validate
+
+ok <<EOF
+syslog
+EOF
+unit_test ctdb-config get "logging" "location"
+
+ok <<EOF
+notice
+EOF
+unit_test ctdb-config get "logging" "log level"
index e90b9a02a49bc799eac94240b132800fb538dc30..0546cbe2077cfcecb03181ca18d052a51cfb5d61 100644 (file)
@@ -467,7 +467,8 @@ def build(bld):
     bld.SAMBA_BINARY('ctdb-config',
                      source='common/conf_tool.c',
                      cflags='-DCTDB_CONF_TOOL',
-                     deps='''ctdb-util samba-util talloc replace popt''',
+                     deps='''ctdb-logging-conf
+                             ctdb-util samba-util talloc replace popt''',
                      install_path='${CTDB_HELPER_BINDIR}')
 
     bld.SAMBA_BINARY('ctdbd',