]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tool: Change ctdb lvs/lvsmaster CLI commands to use ctdb_lvs helper
authorMartin Schwenke <martin@meltin.net>
Fri, 8 Apr 2016 07:14:44 +0000 (17:14 +1000)
committerAmitay Isaacs <amitay@samba.org>
Fri, 15 Apr 2016 03:57:18 +0000 (05:57 +0200)
Update tests accordingly.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
12 files changed:
ctdb/tests/tool/scripts/local.sh
ctdb/tests/tool/stubby.lvs.001.sh
ctdb/tests/tool/stubby.lvs.002.sh
ctdb/tests/tool/stubby.lvs.003.sh
ctdb/tests/tool/stubby.lvsmaster.001.sh
ctdb/tests/tool/stubby.lvsmaster.002.sh
ctdb/tests/tool/stubby.lvsmaster.003.sh
ctdb/tests/tool/stubby.lvsmaster.004.sh
ctdb/tests/tool/stubby.lvsmaster.005.sh
ctdb/tests/tool/stubby.lvsmaster.006.sh
ctdb/tests/tool/stubby.lvsmaster.007.sh
ctdb/tools/ctdb.c

index f85262b117ff6c554894f8bb8986885cc4a5d841..5db2a78fc9457b5bcb04ba88270e853a109a1993 100644 (file)
@@ -60,6 +60,30 @@ setup_natgw ()
        cat >"$CTDB_NATGW_NODES"
 }
 
+setup_lvs ()
+{
+       debug "Setting up LVS"
+
+       # Use in-tree binaries if running against local daemons.
+       # Otherwise CTDB need to be installed on all nodes.
+       if [ -n "$ctdb_dir" -a -d "${ctdb_dir}/bin" ] ; then
+               if [ -z "$CTDB_LVS_HELPER" ] ; then
+                       export CTDB_LVS_HELPER="${ctdb_dir}/tools/ctdb_lvs"
+               fi
+               # Only want to find functions file, so this is OK
+               export CTDB_BASE="${ctdb_dir}/config"
+       fi
+
+       lvs_config_dir="${TEST_VAR_DIR}/lvs_config"
+       mkdir -p "$lvs_config_dir"
+
+       # These will accumulate, 1 per test... but will be cleaned up
+       # at the end.
+       export CTDB_LVS_NODES=$(mktemp --tmpdir="$lvs_config_dir")
+
+       cat >"$CTDB_LVS_NODES"
+}
+
 setup_nodes ()
 {
     _pnn="$1"
index 22600763bf9921eaed5e3992e86644b1d8cffa65..2ff8eaa931471da771da943a720dcef935f35381 100755 (executable)
@@ -4,6 +4,9 @@
 
 define_test "3 nodes, no LVS, all ok"
 
+setup_lvs <<EOF
+EOF
+
 required_result 0 <<EOF
 EOF
 
index e045273d6cc5ff24aee00cdc983f405648252266..6abab2093ba641585a0d670a7591ffc2eb8faa23 100755 (executable)
@@ -4,6 +4,12 @@
 
 define_test "3 nodes, all LVS, all ok"
 
+setup_lvs <<EOF
+192.168.20.41
+192.168.20.42
+192.168.20.43
+EOF
+
 required_result 0 <<EOF
 0:192.168.20.41
 1:192.168.20.42
@@ -12,9 +18,9 @@ EOF
 
 simple_test <<EOF
 NODEMAP
-0       192.168.20.41   0x0     CURRENT RECMASTER CTDB_CAP_LVS
-1       192.168.20.42   0x0    CTDB_CAP_LVS
-2       192.168.20.43   0x0    CTDB_CAP_LVS
+0       192.168.20.41   0x0     CURRENT RECMASTER
+1       192.168.20.42   0x0
+2       192.168.20.43   0x0
 
 IFACES
 :Name:LinkStatus:References:
index 6870760c7c087f178c0ef59e3e459ac71a383c65..ddab8885b49abc4201cf105b792f539ffa8bd549 100755 (executable)
@@ -4,6 +4,11 @@
 
 define_test "3 nodes, some LVS, all ok"
 
+setup_lvs <<EOF
+192.168.20.41
+192.168.20.43
+EOF
+
 required_result 0 <<EOF
 0:192.168.20.41
 2:192.168.20.43
@@ -11,9 +16,9 @@ EOF
 
 simple_test <<EOF
 NODEMAP
-0       192.168.20.41   0x0     CURRENT RECMASTER CTDB_CAP_LVS
+0       192.168.20.41   0x0     CURRENT RECMASTER
 1       192.168.20.42   0x0
-2       192.168.20.43   0x0    CTDB_CAP_LVS
+2       192.168.20.43   0x0
 
 IFACES
 :Name:LinkStatus:References:
index d883fb9cf5c967085328adfec0841a175ff2bba2..5a7d79bbfc78d9cc2cd9d15355e5ab114c05a1e6 100755 (executable)
@@ -4,6 +4,9 @@
 
 define_test "3 nodes, no LVS, all ok"
 
+setup_lvs <<EOF
+EOF
+
 required_result 255 <<EOF
 There is no LVS master
 EOF
index 10def3a62e7c962bdb2699eda8fa0d3911847143..ae8a97f5a59abe97d065cc8c77a4cd0a33b3156b 100755 (executable)
@@ -4,6 +4,9 @@
 
 define_test "3 nodes, current disconnected"
 
+setup_lvs <<EOF
+EOF
+
 required_result 10 <<EOF
 ${TEST_DATE_STAMP}Unable to get nodemap from local node
 EOF
index 35c1da6b700567f3d98277c10b57554595b05e37..45a9eeec8b466a7e2d297cc0571e0100de7f5541 100755 (executable)
@@ -4,15 +4,21 @@
 
 define_test "3 nodes, all LVS, all ok"
 
+setup_lvs <<EOF
+192.168.20.41
+192.168.20.42
+192.168.20.43
+EOF
+
 required_result 0 <<EOF
 Node 0 is LVS master
 EOF
 
 simple_test <<EOF
 NODEMAP
-0       192.168.20.41   0x0     CURRENT RECMASTER CTDB_CAP_LVS
-1       192.168.20.42   0x0    CTDB_CAP_LVS
-2       192.168.20.43   0x0    CTDB_CAP_LVS
+0       192.168.20.41   0x0     CURRENT RECMASTER
+1       192.168.20.42   0x0
+2       192.168.20.43   0x0
 
 IFACES
 :Name:LinkStatus:References:
index 09ed57d631944cc71e18b8d4cbc64da96a4e0337..0edad320bf51c3127316ebd71bf495b62ff6e20b 100755 (executable)
@@ -4,15 +4,21 @@
 
 define_test "3 nodes, all LVS, node 0 unhealthy"
 
+setup_lvs <<EOF
+192.168.20.41
+192.168.20.42
+192.168.20.43
+EOF
+
 required_result 0 <<EOF
 Node 1 is LVS master
 EOF
 
 simple_test <<EOF
 NODEMAP
-0       192.168.20.41   0x2    CURRENT RECMASTER CTDB_CAP_LVS
-1       192.168.20.42   0x0    CTDB_CAP_LVS
-2       192.168.20.43   0x0    CTDB_CAP_LVS
+0       192.168.20.41   0x2    CURRENT RECMASTER
+1       192.168.20.42   0x0
+2       192.168.20.43   0x0
 
 IFACES
 :Name:LinkStatus:References:
index 0bb0759592a08eba15314a3806e9c9a95200bf93..a527af687954d198ab2cb5c63fee85930d44f7ed 100755 (executable)
@@ -4,15 +4,21 @@
 
 define_test "3 nodes, all LVS, all unhealthy"
 
+setup_lvs <<EOF
+192.168.20.41
+192.168.20.42
+192.168.20.43
+EOF
+
 required_result 0 <<EOF
 Node 0 is LVS master
 EOF
 
 simple_test <<EOF
 NODEMAP
-0       192.168.20.41   0x2    CURRENT RECMASTER CTDB_CAP_LVS
-1       192.168.20.42   0x2    CTDB_CAP_LVS
-2       192.168.20.43   0x2    CTDB_CAP_LVS
+0       192.168.20.41   0x2    CURRENT RECMASTER
+1       192.168.20.42   0x2
+2       192.168.20.43   0x2
 
 IFACES
 :Name:LinkStatus:References:
index fb3f689a048347ab38270d8c119672a3b1fe8326..88a7d4a84c3cf06302e31be8f9d7774f87127d8d 100755 (executable)
@@ -4,15 +4,21 @@
 
 define_test "3 nodes, all LVS, nodes 0,1 disabled, node 2 unhealthy"
 
+setup_lvs <<EOF
+192.168.20.41
+192.168.20.42
+192.168.20.43
+EOF
+
 required_result 0 <<EOF
 Node 2 is LVS master
 EOF
 
 simple_test <<EOF
 NODEMAP
-0       192.168.20.41   0x4    CURRENT RECMASTER CTDB_CAP_LVS
-1       192.168.20.42   0x4    CTDB_CAP_LVS
-2       192.168.20.43   0x2    CTDB_CAP_LVS
+0       192.168.20.41   0x4    CURRENT RECMASTER
+1       192.168.20.42   0x4
+2       192.168.20.43   0x2
 
 IFACES
 :Name:LinkStatus:References:
index 3057706ec0dd00cd4acafcabf4a6d9558151ffdd..f95df241e20610613b6d3208eafcb105da8444db 100755 (executable)
@@ -4,15 +4,21 @@
 
 define_test "3 nodes, all LVS, all nodes disabled"
 
+setup_lvs <<EOF
+192.168.20.41
+192.168.20.42
+192.168.20.43
+EOF
+
 required_result 255 <<EOF
 There is no LVS master
 EOF
 
 simple_test <<EOF
 NODEMAP
-0       192.168.20.41   0x4    CURRENT RECMASTER CTDB_CAP_LVS
-1       192.168.20.42   0x4    CTDB_CAP_LVS
-2       192.168.20.43   0x4    CTDB_CAP_LVS
+0       192.168.20.41   0x4    CURRENT RECMASTER
+1       192.168.20.42   0x4
+2       192.168.20.43   0x4
 
 IFACES
 :Name:LinkStatus:References:
index bc7427cab8160021c92eff8a017dd9218e7f7e8c..dca4b752e8bd823b1efbe073deb673d1ce003b8a 100644 (file)
@@ -1148,85 +1148,6 @@ static int control_nodestatus(struct ctdb_context *ctdb, int argc, const char **
        return ret;
 }
 
-/* talloc off the existing nodemap... */
-static struct ctdb_node_map_old *talloc_nodemap(struct ctdb_node_map_old *nodemap)
-{
-       return talloc_zero_size(nodemap,
-                               offsetof(struct ctdb_node_map_old, nodes) +
-                               nodemap->num * sizeof(struct ctdb_node_and_flags));
-}
-
-static struct ctdb_node_map_old *
-filter_nodemap_by_capabilities(struct ctdb_context *ctdb,
-                              struct ctdb_node_map_old *nodemap,
-                              uint32_t required_capabilities,
-                              bool first_only)
-{
-       int i;
-       uint32_t capabilities;
-       struct ctdb_node_map_old *ret;
-
-       ret = talloc_nodemap(nodemap);
-       CTDB_NO_MEMORY_NULL(ctdb, ret);
-
-       ret->num = 0;
-
-       for (i = 0; i < nodemap->num; i++) {
-               int res;
-
-               /* Disconnected nodes have no capabilities! */
-               if (nodemap->nodes[i].flags & NODE_FLAGS_DISCONNECTED) {
-                       continue;
-               }
-
-               res = ctdb_ctrl_getcapabilities(ctdb, TIMELIMIT(),
-                                               nodemap->nodes[i].pnn,
-                                               &capabilities);
-               if (res != 0) {
-                       DEBUG(DEBUG_ERR, ("Unable to get capabilities from node %u\n",
-                                         nodemap->nodes[i].pnn));
-                       talloc_free(ret);
-                       return NULL;
-               }
-               if (!(capabilities & required_capabilities)) {
-                       continue;
-               }
-
-               ret->nodes[ret->num] = nodemap->nodes[i];
-               ret->num++;
-               if (first_only) {
-                       break;
-               }
-       }
-
-       return ret;
-}
-
-static struct ctdb_node_map_old *
-filter_nodemap_by_flags(struct ctdb_context *ctdb,
-                       struct ctdb_node_map_old *nodemap,
-                       uint32_t flags_mask)
-{
-       int i;
-       struct ctdb_node_map_old *ret;
-
-       ret = talloc_nodemap(nodemap);
-       CTDB_NO_MEMORY_NULL(ctdb, ret);
-
-       ret->num = 0;
-
-       for (i = 0; i < nodemap->num; i++) {
-               if (nodemap->nodes[i].flags & flags_mask) {
-                       continue;
-               }
-
-               ret->nodes[ret->num] = nodemap->nodes[i];
-               ret->num++;
-       }
-
-       return ret;
-}
-
 /*
   display the list of nodes belonging to this natgw configuration
  */
@@ -3197,123 +3118,52 @@ static int control_getcapabilities(struct ctdb_context *ctdb, int argc, const ch
        return 0;
 }
 
-/*
-  display lvs configuration
- */
-
-static uint32_t lvs_exclude_flags[] = {
-       /* Look for a nice healthy node */
-       NODE_FLAGS_INACTIVE|NODE_FLAGS_DISABLED,
-       /* If not found, an UNHEALTHY node will do */
-       NODE_FLAGS_INACTIVE|NODE_FLAGS_PERMANENTLY_DISABLED,
-       0,
-};
-
-static int control_lvs(struct ctdb_context *ctdb, int argc, const char **argv)
+/* display lvs configuration */
+static int control_lvs(struct ctdb_context *ctdb,
+                      int argc, const char **argv)
 {
-       TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
-       struct ctdb_node_map_old *orig_nodemap=NULL;
-       struct ctdb_node_map_old *nodemap;
-       int i, ret;
+       static char prog[PATH_MAX+1] = "";
 
-       ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn,
-                                  tmp_ctx, &orig_nodemap);
-       if (ret != 0) {
-               DEBUG(DEBUG_ERR, ("Unable to get nodemap from node %u\n", options.pnn));
-               talloc_free(tmp_ctx);
-               return -1;
+       if (argc != 0) {
+               usage();
        }
 
-       nodemap = filter_nodemap_by_capabilities(ctdb, orig_nodemap,
-                                                CTDB_CAP_LVS, false);
-       if (nodemap == NULL) {
-               /* No memory */
-               ret = -1;
-               goto done;
+       if (!ctdb_set_helper("LVS helper", prog, sizeof(prog),
+                            "CTDB_LVS_HELPER", CTDB_HELPER_BINDIR,
+                            "ctdb_lvs")) {
+               DEBUG(DEBUG_ERR, ("Unable to set LVS helper\n"));
+               exit(1);
        }
 
-       ret = 0;
+       execl(prog, prog, "list", NULL);
 
-       for (i = 0; lvs_exclude_flags[i] != 0; i++) {
-               struct ctdb_node_map_old *t =
-                       filter_nodemap_by_flags(ctdb, nodemap,
-                                               lvs_exclude_flags[i]);
-               if (t == NULL) {
-                       /* No memory */
-                       ret = -1;
-                       goto done;
-               }
-               if (t->num > 0) {
-                       /* At least 1 node without excluded flags */
-                       int j;
-                       for (j = 0; j < t->num; j++) {
-                               printf("%d:%s\n", t->nodes[j].pnn, 
-                                      ctdb_addr_to_str(&t->nodes[j].addr));
-                       }
-                       goto done;
-               }
-               talloc_free(t);
-       }
-done:
-       talloc_free(tmp_ctx);
-       return ret;
+       DEBUG(DEBUG_ERR,
+             ("Unable to run LVS helper %s\n", strerror(errno)));
+       exit(1);
 }
 
-/*
-  display who is the lvs master
- */
-static int control_lvsmaster(struct ctdb_context *ctdb, int argc, const char **argv)
+/* display who the lvs is */
+static int control_lvsmaster(struct ctdb_context *ctdb,
+                            int argc, const char **argv)
 {
-       TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
-       struct ctdb_node_map_old *nodemap=NULL;
-       int i, ret;
+       static char prog[PATH_MAX+1] = "";
 
-       ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn,
-                                  tmp_ctx, &nodemap);
-       if (ret != 0) {
-               DEBUG(DEBUG_ERR, ("Unable to get nodemap from node %u\n", options.pnn));
-               talloc_free(tmp_ctx);
-               return -1;
+       if (argc != 0) {
+               usage();
        }
 
-       for (i = 0; lvs_exclude_flags[i] != 0; i++) {
-               struct ctdb_node_map_old *t =
-                       filter_nodemap_by_flags(ctdb, nodemap,
-                                               lvs_exclude_flags[i]);
-               if (t == NULL) {
-                       /* No memory */
-                       ret = -1;
-                       goto done;
-               }
-               if (t->num > 0) {
-                       struct ctdb_node_map_old *n;
-                       n = filter_nodemap_by_capabilities(ctdb,
-                                                          t,
-                                                          CTDB_CAP_LVS,
-                                                          true);
-                       if (n == NULL) {
-                               /* No memory */
-                               ret = -1;
-                               goto done;
-                       }
-                       if (n->num > 0) {
-                               ret = 0;
-                               if (options.machinereadable) {
-                                       printm("%d\n", n->nodes[0].pnn);
-                               } else {
-                                       printf("Node %d is LVS master\n", n->nodes[0].pnn);
-                               }
-                               goto done;
-                       }
-               }
-               talloc_free(t);
+       if (!ctdb_set_helper("LVS helper", prog, sizeof(prog),
+                            "CTDB_LVS_HELPER", CTDB_HELPER_BINDIR,
+                            "ctdb_lvs")) {
+               DEBUG(DEBUG_ERR, ("Unable to set LVS helper\n"));
+               exit(1);
        }
 
-       printf("There is no LVS master\n");
-       ret = 255;
-done:
-       talloc_free(tmp_ctx);
-       return ret;
+       execl(prog, prog, "master", NULL);
+
+       DEBUG(DEBUG_ERR,
+             ("Unable to run LVS helper %s\n", strerror(errno)));
+       exit(1);
 }
 
 /*
@@ -6076,8 +5926,8 @@ static const struct {
        { "getmonmode",      control_getmonmode,        true,   false,  "show monitoring mode" },
        { "getcapabilities", control_getcapabilities,   true,   false,  "show node capabilities" },
        { "pnn",             control_pnn,               true,   false,  "show the pnn of the currnet node" },
-       { "lvs",             control_lvs,               true,   false,  "show lvs configuration" },
-       { "lvsmaster",       control_lvsmaster,         true,   false,  "show which node is the lvs master" },
+       { "lvs",             control_lvs,               false,  true,   "show lvs configuration" },
+       { "lvsmaster",       control_lvsmaster,         false,  true,   "show which node is the lvs master" },
        { "disablemonitor",      control_disable_monmode,true,  false,  "set monitoring mode to DISABLE" },
        { "enablemonitor",      control_enable_monmode, true,   false,  "set monitoring mode to ACTIVE" },
        { "setdebug",        control_setdebug,          true,   false,  "set debug level",                      "<EMERG|ALERT|CRIT|ERR|WARNING|NOTICE|INFO|DEBUG>" },