]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tools: Change ctdb CLI to have a single "lvs" command
authorMartin Schwenke <martin@meltin.net>
Tue, 12 Apr 2016 01:31:41 +0000 (11:31 +1000)
committerAmitay Isaacs <amitay@samba.org>
Fri, 15 Apr 2016 03:57:18 +0000 (05:57 +0200)
This simply calls out to the wrapper, so that commands are changed as
follows:

  ctdb lvsmaster -> ctdb lvs master
  ctdb lvs       -> ctdb lvs list

This provides a simple, extensible interface and means that "ctdb lvs
status" is also available.

Unit tests are streamlined so that there is a single test for each
CTDB state.  Each test does "master", "list" and "status" sub-tests.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
13 files changed:
ctdb/doc/ctdb.1.xml
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.lvs.004.sh [moved from ctdb/tests/tool/stubby.lvsmaster.004.sh with 53% similarity]
ctdb/tests/tool/stubby.lvs.005.sh [moved from ctdb/tests/tool/stubby.lvsmaster.005.sh with 51% similarity]
ctdb/tests/tool/stubby.lvs.006.sh [moved from ctdb/tests/tool/stubby.lvsmaster.006.sh with 55% similarity]
ctdb/tests/tool/stubby.lvs.007.sh [moved from ctdb/tests/tool/stubby.lvsmaster.007.sh with 55% similarity]
ctdb/tests/tool/stubby.lvs.008.sh [new file with mode: 0755]
ctdb/tests/tool/stubby.lvsmaster.001.sh [deleted file]
ctdb/tests/tool/stubby.lvsmaster.002.sh [deleted file]
ctdb/tests/tool/stubby.lvsmaster.003.sh [deleted file]
ctdb/tools/ctdb.c

index 7c5822cd89d4b2d3218034632ff04cf8c20e4cf3..326c69580a0c7a70bd796bb57bb1f6d0d79f1537 100644 (file)
@@ -723,38 +723,36 @@ MonitorInterval         = 15
     </refsect2>
 
     <refsect2>
-      <title>lvsmaster</title>
+      <title>lvs {master|list|status}</title>
       <para>
-       This command shows which node is currently the LVSMASTER. The
-       LVSMASTER is the node in the cluster which drives the LVS system and
-       which receives all incoming traffic from clients.
-      </para>
-      <para>
-       LVS is the mode where the entire CTDB/Samba cluster uses a single
-       ip address for the entire cluster. In this mode all clients connect to
-       one specific node which will then multiplex/loadbalance the clients
-       evenly onto the other nodes in the cluster. This is an alternative to using
-       public ip addresses. See the manpage for ctdbd for more information
-       about LVS.
-      </para>
-    </refsect2>
-
-    <refsect2>
-      <title>lvs</title>
-      <para>
-       This command shows which nodes in the cluster are currently active in the
-       LVS configuration. I.e. which nodes we are currently loadbalancing
-       the single ip address across.
+       This command shows different aspects of LVS status.  For an
+       overview of CTDB's LVS functionality please see the
+       <citetitle>LVS</citetitle> section in
+       <citerefentry><refentrytitle>ctdb</refentrytitle>
+       <manvolnum>7</manvolnum></citerefentry>.
       </para>
 
+      <variablelist>
+       <varlistentry>
+         <term>master</term>
+         <listitem>
+           <para>
+             Shows the PNN of the current LVS master node.
+           </para>
       <para>
-       LVS will by default only loadbalance across those nodes that are both
-       LVS capable and also HEALTHY. Except if all nodes are UNHEALTHY in which
-       case LVS will loadbalance across all UNHEALTHY nodes as well.
-       LVS will never use nodes that are DISCONNECTED, STOPPED, BANNED or
-       DISABLED.
+       Example output:
       </para>
-
+      <screen>
+Node 2 is LVS master
+      </screen>
+         </listitem>
+       </varlistentry>
+       <varlistentry>
+         <term>list</term>
+         <listitem>
+           <para>
+             Lists the currently usable LVS nodes.
+           </para>
       <para>
        Example output:
       </para>
@@ -762,6 +760,26 @@ MonitorInterval         = 15
 2:10.0.0.13
 3:10.0.0.14
       </screen>
+         </listitem>
+       </varlistentry>
+       <varlistentry>
+         <term>status</term>
+         <listitem>
+           <para>
+             List the nodes in the current LVS group and their status.
+           </para>
+      <para>
+       Example output:
+      </para>
+      <screen>
+pnn:0 10.0.0.11        UNHEALTHY (THIS NODE)
+pnn:1 10.0.0.12        UNHEALTHY
+pnn:2 10.0.0.13        OK
+pnn:3 10.0.0.14        OK
+      </screen>
+         </listitem>
+       </varlistentry>
+      </variablelist>
 
     </refsect2>
 
index 2ff8eaa931471da771da943a720dcef935f35381..46fbef55feab89a0320315adb592407b3b674fef 100755 (executable)
@@ -7,10 +7,7 @@ define_test "3 nodes, no LVS, all ok"
 setup_lvs <<EOF
 EOF
 
-required_result 0 <<EOF
-EOF
-
-simple_test <<EOF
+ctdb_state="\
 NODEMAP
 0       192.168.20.41   0x0     CURRENT RECMASTER
 1       192.168.20.42   0x0
@@ -26,4 +23,32 @@ VNNMAP
 0
 1
 2
+"
+
+#####
+
+required_result 255 <<EOF
+There is no LVS master
+EOF
+
+simple_test master <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+EOF
+
+simple_test list <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+EOF
+
+simple_test status <<EOF
+$ctdb_state
 EOF
index 6abab2093ba641585a0d670a7591ffc2eb8faa23..eb6ee56a19e144789c33145f6e4bf254c8fdfd67 100755 (executable)
@@ -10,13 +10,7 @@ setup_lvs <<EOF
 192.168.20.43
 EOF
 
-required_result 0 <<EOF
-0:192.168.20.41
-1:192.168.20.42
-2:192.168.20.43
-EOF
-
-simple_test <<EOF
+ctdb_state="\
 NODEMAP
 0       192.168.20.41   0x0     CURRENT RECMASTER
 1       192.168.20.42   0x0
@@ -32,4 +26,38 @@ VNNMAP
 0
 1
 2
+"
+
+#####
+
+required_result 0 <<EOF
+Node 0 is LVS master
+EOF
+
+simple_test master <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+0:192.168.20.41
+1:192.168.20.42
+2:192.168.20.43
+EOF
+
+simple_test list <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+pnn:0 192.168.20.41    OK (THIS NODE)
+pnn:1 192.168.20.42    OK
+pnn:2 192.168.20.43    OK
+EOF
+
+simple_test status <<EOF
+$ctdb_state
 EOF
index ddab8885b49abc4201cf105b792f539ffa8bd549..a5155a919d4b9112e3a21d714650d33370ece946 100755 (executable)
@@ -9,12 +9,7 @@ setup_lvs <<EOF
 192.168.20.43
 EOF
 
-required_result 0 <<EOF
-0:192.168.20.41
-2:192.168.20.43
-EOF
-
-simple_test <<EOF
+ctdb_state="\
 NODEMAP
 0       192.168.20.41   0x0     CURRENT RECMASTER
 1       192.168.20.42   0x0
@@ -30,4 +25,35 @@ VNNMAP
 0
 1
 2
+"
+#####
+
+required_result 0 <<EOF
+Node 0 is LVS master
+EOF
+
+simple_test master <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+0:192.168.20.41
+2:192.168.20.43
+EOF
+
+simple_test list <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+pnn:0 192.168.20.41    OK (THIS NODE)
+pnn:2 192.168.20.43    OK
+EOF
+
+simple_test status <<EOF
+$ctdb_state
 EOF
similarity index 53%
rename from ctdb/tests/tool/stubby.lvsmaster.004.sh
rename to ctdb/tests/tool/stubby.lvs.004.sh
index 0edad320bf51c3127316ebd71bf495b62ff6e20b..1db4f9ee1a7b5d7d589164889e5f6646cd6245b3 100755 (executable)
@@ -10,11 +10,7 @@ setup_lvs <<EOF
 192.168.20.43
 EOF
 
-required_result 0 <<EOF
-Node 1 is LVS master
-EOF
-
-simple_test <<EOF
+ctdb_state="\
 NODEMAP
 0       192.168.20.41   0x2    CURRENT RECMASTER
 1       192.168.20.42   0x0
@@ -30,4 +26,37 @@ VNNMAP
 0
 1
 2
+"
+
+#####
+
+required_result 0 <<EOF
+Node 1 is LVS master
+EOF
+
+simple_test master <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+1:192.168.20.42
+2:192.168.20.43
+EOF
+
+simple_test list <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+pnn:0 192.168.20.41    UNHEALTHY (THIS NODE)
+pnn:1 192.168.20.42    OK
+pnn:2 192.168.20.43    OK
+EOF
+
+simple_test status <<EOF
+$ctdb_state
 EOF
similarity index 51%
rename from ctdb/tests/tool/stubby.lvsmaster.005.sh
rename to ctdb/tests/tool/stubby.lvs.005.sh
index a527af687954d198ab2cb5c63fee85930d44f7ed..c866555d5ecad583b4639d4262ba5f7671fc3d13 100755 (executable)
@@ -10,11 +10,7 @@ setup_lvs <<EOF
 192.168.20.43
 EOF
 
-required_result 0 <<EOF
-Node 0 is LVS master
-EOF
-
-simple_test <<EOF
+ctdb_state="\
 NODEMAP
 0       192.168.20.41   0x2    CURRENT RECMASTER
 1       192.168.20.42   0x2
@@ -30,4 +26,38 @@ VNNMAP
 0
 1
 2
+"
+
+#####
+
+required_result 0 <<EOF
+Node 0 is LVS master
+EOF
+
+simple_test master <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+0:192.168.20.41
+1:192.168.20.42
+2:192.168.20.43
+EOF
+
+simple_test list <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+pnn:0 192.168.20.41    UNHEALTHY (THIS NODE)
+pnn:1 192.168.20.42    UNHEALTHY
+pnn:2 192.168.20.43    UNHEALTHY
+EOF
+
+simple_test status <<EOF
+$ctdb_state
 EOF
similarity index 55%
rename from ctdb/tests/tool/stubby.lvsmaster.006.sh
rename to ctdb/tests/tool/stubby.lvs.006.sh
index 88a7d4a84c3cf06302e31be8f9d7774f87127d8d..3767acdff5471667b50706a04d81ebd6a3f561e2 100755 (executable)
@@ -10,11 +10,7 @@ setup_lvs <<EOF
 192.168.20.43
 EOF
 
-required_result 0 <<EOF
-Node 2 is LVS master
-EOF
-
-simple_test <<EOF
+ctdb_state="\
 NODEMAP
 0       192.168.20.41   0x4    CURRENT RECMASTER
 1       192.168.20.42   0x4
@@ -30,4 +26,36 @@ VNNMAP
 0
 1
 2
+"
+
+#####
+
+required_result 0 <<EOF
+Node 2 is LVS master
+EOF
+
+simple_test master <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+2:192.168.20.43
+EOF
+
+simple_test list <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+pnn:0 192.168.20.41    DISABLED (THIS NODE)
+pnn:1 192.168.20.42    DISABLED
+pnn:2 192.168.20.43    UNHEALTHY
+EOF
+
+simple_test status <<EOF
+$ctdb_state
 EOF
similarity index 55%
rename from ctdb/tests/tool/stubby.lvsmaster.007.sh
rename to ctdb/tests/tool/stubby.lvs.007.sh
index f95df241e20610613b6d3208eafcb105da8444db..0e0addd82524e3667d459b4b8c13978b26206a59 100755 (executable)
@@ -10,11 +10,7 @@ setup_lvs <<EOF
 192.168.20.43
 EOF
 
-required_result 255 <<EOF
-There is no LVS master
-EOF
-
-simple_test <<EOF
+ctdb_state="\
 NODEMAP
 0       192.168.20.41   0x4    CURRENT RECMASTER
 1       192.168.20.42   0x4
@@ -30,4 +26,35 @@ VNNMAP
 0
 1
 2
+"
+
+#####
+
+required_result 255 <<EOF
+There is no LVS master
+EOF
+
+simple_test master <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+EOF
+
+simple_test list <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 0 <<EOF
+pnn:0 192.168.20.41    DISABLED (THIS NODE)
+pnn:1 192.168.20.42    DISABLED
+pnn:2 192.168.20.43    DISABLED
+EOF
+
+simple_test status <<EOF
+$ctdb_state
 EOF
diff --git a/ctdb/tests/tool/stubby.lvs.008.sh b/ctdb/tests/tool/stubby.lvs.008.sh
new file mode 100755 (executable)
index 0000000..6ceba68
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "3 nodes, no LVS, current disconnected"
+
+setup_lvs <<EOF
+EOF
+
+ctdb_state="\
+NODEMAP
+0       192.168.20.41   0x1     CURRENT RECMASTER
+1       192.168.20.42   0x0
+2       192.168.20.43   0x0
+
+IFACES
+:Name:LinkStatus:References:
+:eth2:1:2:
+:eth1:1:4:
+
+VNNMAP
+654321
+0
+1
+2
+"
+
+#####
+
+required_result 10 <<EOF
+${TEST_DATE_STAMP}Unable to get nodemap from local node
+EOF
+
+simple_test list <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 10 <<EOF
+${TEST_DATE_STAMP}Unable to get nodemap from local node
+EOF
+
+simple_test master <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 10 <<EOF
+${TEST_DATE_STAMP}Unable to get nodemap from local node
+EOF
+
+simple_test list <<EOF
+$ctdb_state
+EOF
+
+#####
+
+required_result 10 <<EOF
+${TEST_DATE_STAMP}Unable to get nodemap from local node
+EOF
+
+simple_test status <<EOF
+$ctdb_state
+EOF
diff --git a/ctdb/tests/tool/stubby.lvsmaster.001.sh b/ctdb/tests/tool/stubby.lvsmaster.001.sh
deleted file mode 100755 (executable)
index 5a7d79b..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-. "${TEST_SCRIPTS_DIR}/unit.sh"
-
-define_test "3 nodes, no LVS, all ok"
-
-setup_lvs <<EOF
-EOF
-
-required_result 255 <<EOF
-There is no LVS master
-EOF
-
-simple_test <<EOF
-NODEMAP
-0       192.168.20.41   0x0     CURRENT RECMASTER
-1       192.168.20.42   0x0
-2       192.168.20.43   0x0
-
-IFACES
-:Name:LinkStatus:References:
-:eth2:1:2:
-:eth1:1:4:
-
-VNNMAP
-654321
-0
-1
-2
-EOF
diff --git a/ctdb/tests/tool/stubby.lvsmaster.002.sh b/ctdb/tests/tool/stubby.lvsmaster.002.sh
deleted file mode 100755 (executable)
index ae8a97f..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-. "${TEST_SCRIPTS_DIR}/unit.sh"
-
-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
-
-simple_test -Y <<EOF
-NODEMAP
-0       192.168.20.41   0x1     CURRENT RECMASTER
-1       192.168.20.42   0x0
-2       192.168.20.43   0x0
-
-IFACES
-:Name:LinkStatus:References:
-:eth2:1:2:
-:eth1:1:4:
-
-VNNMAP
-654321
-0
-1
-2
-EOF
diff --git a/ctdb/tests/tool/stubby.lvsmaster.003.sh b/ctdb/tests/tool/stubby.lvsmaster.003.sh
deleted file mode 100755 (executable)
index 45a9eee..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-
-. "${TEST_SCRIPTS_DIR}/unit.sh"
-
-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
-1       192.168.20.42   0x0
-2       192.168.20.43   0x0
-
-IFACES
-:Name:LinkStatus:References:
-:eth2:1:2:
-:eth1:1:4:
-
-VNNMAP
-654321
-0
-1
-2
-EOF
index dca4b752e8bd823b1efbe073deb673d1ce003b8a..b4816adfb45018ea2ecad4842a148f40cac71ae7 100644 (file)
@@ -3118,37 +3118,13 @@ static int control_getcapabilities(struct ctdb_context *ctdb, int argc, const ch
        return 0;
 }
 
-/* display lvs configuration */
+/* Display LVS status */
 static int control_lvs(struct ctdb_context *ctdb,
                       int argc, const char **argv)
 {
        static char prog[PATH_MAX+1] = "";
 
-       if (argc != 0) {
-               usage();
-       }
-
-       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);
-       }
-
-       execl(prog, prog, "list", NULL);
-
-       DEBUG(DEBUG_ERR,
-             ("Unable to run LVS helper %s\n", strerror(errno)));
-       exit(1);
-}
-
-/* display who the lvs is */
-static int control_lvsmaster(struct ctdb_context *ctdb,
-                            int argc, const char **argv)
-{
-       static char prog[PATH_MAX+1] = "";
-
-       if (argc != 0) {
+       if (argc != 1) {
                usage();
        }
 
@@ -3159,7 +3135,7 @@ static int control_lvsmaster(struct ctdb_context *ctdb,
                exit(1);
        }
 
-       execl(prog, prog, "master", NULL);
+       execl(prog, prog, argv[0], NULL);
 
        DEBUG(DEBUG_ERR,
              ("Unable to run LVS helper %s\n", strerror(errno)));
@@ -5926,8 +5902,7 @@ 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,               false,  true,   "show lvs configuration" },
-       { "lvsmaster",       control_lvsmaster,         false,  true,   "show which node is the lvs master" },
+       { "lvs",             control_lvs,               false,  true,   "show lvs configuration", "[master|list|status]" },
        { "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>" },