[SCM] Samba Shared Repository - branch master updated

Martin Schwenke martins at samba.org
Sun Apr 13 22:07:03 MDT 2014


The branch, master has been updated
       via  2f2421b ctdb-eventscripts: CTDB_NATGW_PUBLIC_* optional on slave-only nodes
       via  ce8ac88 ctdb-tools-ctdb: Drop disconnected nodes when filtering by capability
       via  c048011 ctdb-tests: Add a simple test for "ctdb detach"
       via  89bf1d2 ctdb-doc: Remove commands that have been deleted
       via  b681e89 ctdb-doc: Add "ctdb detach" and update "ctdb attach"
       via  a3fdb56 ctdb-tools/ctdb: Add ctdb detach command to detach databases
       via  ce18b3b ctdb-client: Add client code to detach a database
       via  1c72842 ctdb-daemon: Add control CTDB_CONTROL_DB_DETACH
      from  e0cddcd Typo: s/preceeded/preceded/

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 2f2421bae1a8ff46ad54f76d02e6dd1c3ffe3300
Author: Martin Schwenke <martin at meltin.net>
Date:   Thu Apr 10 11:58:57 2014 +1000

    ctdb-eventscripts: CTDB_NATGW_PUBLIC_* optional on slave-only nodes
    
    Commit 4ee4925d416a86341bd76c11fa99ec9173682a1d forgot about
    CTDB_NATGW_SLAVE_ONLY so it introduces an incorrect failure when this
    is set, and CTDB_NATGW_PUBLIC_IFACE or CTDB_NATGW_PUBLIC_IP is unset.
    
    Relax the sanity check to see if CTDB_NATGW_SLAVE_ONLY is set.
    
    Update the documentation to explicitly state that
    CTDB_NATGW_PUBLIC_IFACE and CTDB_NATGW_PUBLIC_IP are optional and
    unused if CTDB_NATGW_SLAVE_ONLY is set.  It would be possible to
    insist that CTDB_NATGW_PUBLIC_IFACE and CTDB_NATGW_PUBLIC_IFACE should
    be unset in that case.  However, it is more reasonable to allow
    consistent configuration across nodes except with some nodes
    configured slave-only.
    
    Add tests, update infrastructure and fix a thinko in the stub's
    "natgwlist" implementation.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>
    
    Autobuild-User(master): Martin Schwenke <martins at samba.org>
    Autobuild-Date(master): Mon Apr 14 06:06:49 CEST 2014 on sn-devel-104

commit ce8ac88b969bb8bb7a94e62bb6e86aec389be6ac
Author: Martin Schwenke <martin at meltin.net>
Date:   Wed Apr 9 14:26:23 2014 +1000

    ctdb-tools-ctdb: Drop disconnected nodes when filtering by capability
    
    Commit ba69742ccd822562ca2135d2466e09bf1216644b missed the point of
    filtering disconnected nodes while limiting the nodemap to those in
    the NAT gateway group.  It was really to avoid trying to fetch
    capabilities from disconnected nodes.  This should be explicitly done
    in filter_nodemap_by_capabilities(), otherwise "ctdb natgwlist" simply
    fails when there is a disconnected node.
    
    Note that the alternate solution where filter_nodemap_by_flags() is
    called before filter_nodemap_by_capabilities() would not be not
    correct.  Filtering on flags first can produce a "healthier" set of
    nodes where none of them have the NAT gateway capability.
    
    Also extend stub for ctdb_ctrl_getcapabilities() to fail when trying
    to get capabilities from a disconnected node and add a corresponding
    test to confirm that "ctdb natgwlist" is no longer broken.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit c048011cd6a9ff976a88ac05ad15e0ffc73a73ae
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Wed Apr 9 11:38:57 2014 +1000

    ctdb-tests: Add a simple test for "ctdb detach"
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 89bf1d2e34c7f4afe8c75dd5cf48e8564104f71b
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Apr 7 12:00:54 2014 +1000

    ctdb-doc: Remove commands that have been deleted
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit b681e89a973d738b2f8590c078c7bcb79391469f
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Apr 7 12:06:49 2014 +1000

    ctdb-doc: Add "ctdb detach" and update "ctdb attach"
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit a3fdb5637688bfed89be7489bacd66d7cefc2923
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Mar 31 15:45:23 2014 +1100

    ctdb-tools/ctdb: Add ctdb detach command to detach databases
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit ce18b3b00ba2db83daa71bf73e843732f05b8f6e
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Mar 31 15:44:53 2014 +1100

    ctdb-client: Add client code to detach a database
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 1c72842217245fe99ddb6d26c29ae3f522db09c6
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Mar 31 15:44:21 2014 +1100

    ctdb-daemon: Add control CTDB_CONTROL_DB_DETACH
    
    This detaches specified database from all the nodes.
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

-----------------------------------------------------------------------

Summary of changes:
 ctdb/client/ctdb_client.c                |   19 ++++++
 ctdb/config/events.d/11.natgw            |   10 ++-
 ctdb/doc/ctdb.1.xml                      |  103 ++++++++++--------------------
 ctdb/doc/ctdbd.conf.5.xml                |    6 ++-
 ctdb/include/ctdb_client.h               |    1 +
 ctdb/include/ctdb_private.h              |    2 +
 ctdb/include/ctdb_protocol.h             |    1 +
 ctdb/server/ctdb_control.c               |    3 +
 ctdb/server/ctdb_ltdb_server.c           |   85 ++++++++++++++++++++++++
 ctdb/tests/eventscripts/11.natgw.003.sh  |   21 ++++++
 ctdb/tests/eventscripts/11.natgw.004.sh  |   21 ++++++
 ctdb/tests/eventscripts/11.natgw.005.sh  |   24 +++++++
 ctdb/tests/eventscripts/11.natgw.041.sh  |   22 ++++++
 ctdb/tests/eventscripts/11.natgw.042.sh  |   23 +++++++
 ctdb/tests/eventscripts/scripts/local.sh |    1 +
 ctdb/tests/eventscripts/stubs/ctdb       |   31 ++++++----
 ctdb/tests/simple/27_ctdb_detach.sh      |   85 ++++++++++++++++++++++++
 ctdb/tests/src/ctdb_test_stubs.c         |    9 +++
 ctdb/tests/tool/stubby.natgwlist.008.sh  |   37 +++++++++++
 ctdb/tools/ctdb.c                        |   53 ++++++++++++++-
 20 files changed, 468 insertions(+), 89 deletions(-)
 create mode 100755 ctdb/tests/eventscripts/11.natgw.003.sh
 create mode 100755 ctdb/tests/eventscripts/11.natgw.004.sh
 create mode 100755 ctdb/tests/eventscripts/11.natgw.005.sh
 create mode 100755 ctdb/tests/eventscripts/11.natgw.041.sh
 create mode 100755 ctdb/tests/eventscripts/11.natgw.042.sh
 create mode 100755 ctdb/tests/simple/27_ctdb_detach.sh
 create mode 100755 ctdb/tests/tool/stubby.natgwlist.008.sh


Changeset truncated at 500 lines:

diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c
index 7560115..51eec0e 100644
--- a/ctdb/client/ctdb_client.c
+++ b/ctdb/client/ctdb_client.c
@@ -2120,6 +2120,25 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
 	return ctdb_db;
 }
 
+/*
+ * detach from a specific database - client call
+ */
+int ctdb_detach(struct ctdb_context *ctdb, uint32_t db_id)
+{
+	int ret;
+	int32_t status;
+	TDB_DATA data;
+
+	data.dsize = sizeof(db_id);
+	data.dptr = (uint8_t *)&db_id;
+
+	ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_DB_DETACH,
+			   0, data, NULL, NULL, &status, NULL, NULL);
+	if (ret != 0 || status != 0) {
+		return -1;
+	}
+	return 0;
+}
 
 /*
   setup a call for a database
diff --git a/ctdb/config/events.d/11.natgw b/ctdb/config/events.d/11.natgw
index b2a219c..f925d4b 100755
--- a/ctdb/config/events.d/11.natgw
+++ b/ctdb/config/events.d/11.natgw
@@ -18,10 +18,12 @@ natgw_check_config ()
 {
     [ -r "$CTDB_NATGW_NODES" ] || \
 	die "error: CTDB_NATGW_NODES=${CTDB_NATGW_NODES} unreadable"
-    [ -n "$CTDB_NATGW_PUBLIC_IP" ] || \
-	die "Invalid configuration: CTDB_NATGW_PUBLIC_IP not set"
-    [ -n "$CTDB_NATGW_PUBLIC_IFACE" ] || \
-	die "Invalid configuration: CTDB_NATGW_PUBLIC_IFACE not set"
+    if [ "$CTDB_NATGW_SLAVE_ONLY" != "yes" ] ; then
+	[ -n "$CTDB_NATGW_PUBLIC_IP" ] || \
+	    die "Invalid configuration: CTDB_NATGW_PUBLIC_IP not set"
+	[ -n "$CTDB_NATGW_PUBLIC_IFACE" ] || \
+	    die "Invalid configuration: CTDB_NATGW_PUBLIC_IFACE not set"
+    fi
     [ -n "$CTDB_NATGW_PRIVATE_NETWORK" ] || \
 	die "Invalid configuration: CTDB_NATGW_PRIVATE_NETWORK not set"
 
diff --git a/ctdb/doc/ctdb.1.xml b/ctdb/doc/ctdb.1.xml
index d5db702..95a67db 100644
--- a/ctdb/doc/ctdb.1.xml
+++ b/ctdb/doc/ctdb.1.xml
@@ -94,10 +94,28 @@
     </para>
 
     <para>
-      Commands that reference a database have a
-      <parameter>DB</parameter> argument.  This is either a database
-      name, such as <filename>locking.tdb</filename> or a database ID
-      such as "0x42fe72c5".
+      Commands that reference a database use the following terms:
+      <variablelist>
+	<varlistentry>
+	  <term>DB</term>
+	  <listitem>
+	    <para>
+	      This is either a database name, such as
+	      <filename>locking.tdb</filename> or a database ID such
+	      as "0x42fe72c5".
+	    </para>
+	  </listitem>
+	</varlistentry>
+	<varlistentry>
+	  <term>DB-LIST</term>
+	  <listitem>
+	    <para>
+	      A space separated list of at least one
+	      <parameter>DB</parameter>.
+	    </para>
+	  </listitem>
+	</varlistentry>
+      </variablelist>
     </para>
   </refsect1>
 
@@ -1545,7 +1563,18 @@ HEALTH: NO-HEALTHY-NODES - ERROR - Backup of corrupted TDB in '/var/ctdb/persist
     <refsect2>
       <title>attach <parameter>DBNAME</parameter> [persistent]</title>
       <para>
-	This is a debugging command. This command will make the CTDB daemon create a new CTDB database and attach to it.
+	Create a new CTDB database called DBNAME and attach to it on
+	all nodes.
+      </para>
+    </refsect2>
+
+    <refsect2>
+      <title>detach <parameter>DB-LIST</parameter></title>
+      <para>
+	Detach specified non-persistent database(s) from the cluster. This
+	command will disconnect specified database(s) on all nodes in
+	the cluster.  This command should only be used when none of the
+	specified database(s) are in use.
       </para>
     </refsect2>
 
@@ -1644,70 +1673,6 @@ Server id 0:14765 exists
       </refsect3>
     </refsect2>
 
-    <refsect2>
-      <title>vacuum [<parameter>max-records</parameter>]</title>
-      <para>
-	Over time CTDB databases will fill up with empty deleted
-	records which will lead to a progressive slow down of CTDB
-	database access.  This command is used to prune all databases
-	and delete all empty records from the cluster.
-      </para>
-
-      <para>
-	By default, vacuum will delete all empty records from all databases.
-	If [max_records] is specified, the command will only delete the first
-	[max_records] empty records for each database.
-      </para>
-
-      <para>
-	Vacuum only deletes records where the local node is the
-	lmaster.  To delete all records from the entire cluster you
-	need to run a vacuum from each node.
-
-	This command is not disruptive. Samba is unaffected and will still be able to read/write records normally while the database is being vacuumed.
-      </para>
-
-      <para>
-	Example: ctdb vacuum
-      </para>
-
-      <para>
-	By default, this operation is issued from the 00.ctdb event script every 5 minutes.
-      </para>
-    </refsect2>
-
-    <refsect2>
-      <title>repack [max_freelist]</title>
-      <para>
-	Over time, when records are created and deleted in a TDB, the TDB list of free space will become fragmented. This can lead to a slowdown in accessing TDB records.
-	This command is used to defragment a TDB database and pruning the freelist.
-      </para>
-
-      <para>
-	If [max_freelist] is specified, then a database will only be repacked if it has more than this number of entries in the freelist.
-      </para>
-      <para>
-	During repacking of the database, the entire TDB database will be locked to prevent writes. If samba tries to write to a record in the database during a repack operation, samba will block until the repacking has completed.
-      </para>
-
-      <para>
-	This command can be disruptive and can cause samba to block for the duration of the repack operation. In general, a repack operation will take less than one second to complete.
-      </para>
-
-      <para>
-	A repack operation will only defragment the local TDB copy of the CTDB database. You need to run this command on all of the nodes to repack a CTDB database completely.
-      </para>
-
-      <para>
-	Example: ctdb repack 1000
-      </para>
-
-      <para>
-	By default, this operation is issued from the 00.ctdb event script every 5 minutes.
-      </para>
-
-    </refsect2>
-
   </refsect1>
 
   <!-- UNDOCUMENTED: showban stats disablemonitor enablemonitor
diff --git a/ctdb/doc/ctdbd.conf.5.xml b/ctdb/doc/ctdbd.conf.5.xml
index 188a4df..98d0924 100644
--- a/ctdb/doc/ctdbd.conf.5.xml
+++ b/ctdb/doc/ctdbd.conf.5.xml
@@ -537,7 +537,11 @@
 	  <term>CTDB_NATGW_SLAVE_ONLY=yes|no</term>
 	  <listitem>
 	    <para>
-	      When set to "yes" a node can not be a NAT gateway master node.
+	      When set to "yes" a node can not be a NAT gateway master
+	      node.  In this case
+	      <varname>CTDB_NATGW_PUBLIC_IFACE</varname> and
+	      <varname>CTDB_NATGW_PUBLIC_IP</varname> are optional
+	      and unused.
 	    </para>
 	    <para>
 	      Default is no.
diff --git a/ctdb/include/ctdb_client.h b/ctdb/include/ctdb_client.h
index d308427..1370ce9 100644
--- a/ctdb/include/ctdb_client.h
+++ b/ctdb/include/ctdb_client.h
@@ -97,6 +97,7 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
 				    bool persistent,
 				    uint32_t tdb_flags);
 
+int ctdb_detach(struct ctdb_context *ctdb, uint32_t db_id);
 
 /*
   find an attached ctdb_db handle given a name
diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h
index 2206f4e..8175978 100644
--- a/ctdb/include/ctdb_private.h
+++ b/ctdb/include/ctdb_private.h
@@ -900,6 +900,8 @@ int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
 			       bool persistent, uint32_t client_id,
 			       struct ctdb_req_control *c,
 			       bool *async_reply);
+int32_t ctdb_control_db_detach(struct ctdb_context *ctdb, TDB_DATA indata,
+			       uint32_t client_id);
 
 int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
 			 ctdb_fn_t fn, int id);
diff --git a/ctdb/include/ctdb_protocol.h b/ctdb/include/ctdb_protocol.h
index fa03a4b..f2d68f4 100644
--- a/ctdb/include/ctdb_protocol.h
+++ b/ctdb/include/ctdb_protocol.h
@@ -404,6 +404,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
 		    CTDB_CONTROL_RECEIVE_RECORDS	 = 136,
 		    CTDB_CONTROL_IPREALLOCATED		 = 137,
 		    CTDB_CONTROL_GET_RUNSTATE		 = 138,
+		    CTDB_CONTROL_DB_DETACH		 = 139,
 };
 
 /*
diff --git a/ctdb/server/ctdb_control.c b/ctdb/server/ctdb_control.c
index b56b624..b0220de 100644
--- a/ctdb/server/ctdb_control.c
+++ b/ctdb/server/ctdb_control.c
@@ -682,6 +682,9 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
 	case CTDB_CONTROL_RECEIVE_RECORDS:
 		return ctdb_control_receive_records(ctdb, indata, outdata);
 
+	case CTDB_CONTROL_DB_DETACH:
+		return ctdb_control_db_detach(ctdb, indata, client_id);
+
 	default:
 		DEBUG(DEBUG_CRIT,(__location__ " Unknown CTDB control opcode %u\n", opcode));
 		return -1;
diff --git a/ctdb/server/ctdb_ltdb_server.c b/ctdb/server/ctdb_ltdb_server.c
index aafba42..3d8772f 100644
--- a/ctdb/server/ctdb_ltdb_server.c
+++ b/ctdb/server/ctdb_ltdb_server.c
@@ -1164,6 +1164,91 @@ int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
 	return 0;
 }
 
+/*
+ * a client has asked to detach from a database
+ */
+int32_t ctdb_control_db_detach(struct ctdb_context *ctdb, TDB_DATA indata,
+			       uint32_t client_id)
+{
+	uint32_t db_id;
+	struct ctdb_db_context *ctdb_db;
+	struct ctdb_client *client = NULL;
+
+	db_id = *(uint32_t *)indata.dptr;
+	ctdb_db = find_ctdb_db(ctdb, db_id);
+	if (ctdb_db == NULL) {
+		DEBUG(DEBUG_ERR, ("Invalid dbid 0x%08x in DB detach\n",
+				  db_id));
+		return -1;
+	}
+
+	if (ctdb->tunable.allow_client_db_attach == 0) {
+		DEBUG(DEBUG_ERR, ("DB detach from database %s denied by "
+				  "tunable AllowClientDBAccess == 0\n",
+				  ctdb_db->db_name));
+		return -1;
+	}
+
+	if (ctdb_db->persistent) {
+		DEBUG(DEBUG_ERR, ("DB detach from persistent database %s "
+				  "denied\n", ctdb_db->db_name));
+		return -1;
+	}
+
+	/* Cannot detach from database when in recovery */
+	if (ctdb->recovery_mode == CTDB_RECOVERY_ACTIVE) {
+		DEBUG(DEBUG_ERR, ("DB detach denied while in recovery\n"));
+		return -1;
+	}
+
+	/* If a control comes from a client, then broadcast it to all nodes.
+	 * Do the actual detach only if the control comes from other daemons.
+	 */
+	if (client_id != 0) {
+		client = ctdb_reqid_find(ctdb, client_id, struct ctdb_client);
+		if (client != NULL) {
+			/* forward the control to all the nodes */
+			ctdb_daemon_send_control(ctdb, CTDB_BROADCAST_ALL, 0,
+						 CTDB_CONTROL_DB_DETACH, 0,
+						 CTDB_CTRL_FLAG_NOREPLY,
+						 indata, NULL, NULL);
+			return 0;
+		}
+		DEBUG(DEBUG_ERR, ("Client has gone away. Failing DB detach "
+				  "for database '%s'\n", ctdb_db->db_name));
+		return -1;
+	}
+
+	/* Disable vacuuming and drop all vacuuming data */
+	talloc_free(ctdb_db->vacuum_handle);
+	talloc_free(ctdb_db->delete_queue);
+
+	/* Terminate any deferred fetch */
+	talloc_free(ctdb_db->deferred_fetch);
+
+	/* Terminate any traverses */
+	while (ctdb_db->traverse) {
+		talloc_free(ctdb_db->traverse);
+	}
+
+	/* Terminate any revokes */
+	while (ctdb_db->revokechild_active) {
+		talloc_free(ctdb_db->revokechild_active);
+	}
+
+	/* Free readonly tracking database */
+	if (ctdb_db->readonly) {
+		talloc_free(ctdb_db->rottdb);
+	}
+
+	DLIST_REMOVE(ctdb->db_list, ctdb_db);
+
+	DEBUG(DEBUG_NOTICE, ("Detached from database '%s'\n",
+			     ctdb_db->db_name));
+	talloc_free(ctdb_db);
+
+	return 0;
+}
 
 /*
   attach to all existing persistent databases
diff --git a/ctdb/tests/eventscripts/11.natgw.003.sh b/ctdb/tests/eventscripts/11.natgw.003.sh
new file mode 100755
index 0000000..cb2358f
--- /dev/null
+++ b/ctdb/tests/eventscripts/11.natgw.003.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "CTDB_NATGW_PUBLIC_IFACE unset, not slave-only"
+
+setup_ctdb
+setup_ctdb_natgw <<EOF
+192.168.1.21 master
+192.168.1.22
+192.168.1.23
+192.168.1.24
+EOF
+
+CTDB_NATGW_PUBLIC_IFACE=""
+
+required_result 1 "Invalid configuration: CTDB_NATGW_PUBLIC_IFACE not set"
+
+for i in "startup" "ipreallocated" "monitor" ; do
+    simple_test_event "$i"
+done
diff --git a/ctdb/tests/eventscripts/11.natgw.004.sh b/ctdb/tests/eventscripts/11.natgw.004.sh
new file mode 100755
index 0000000..76f1a54
--- /dev/null
+++ b/ctdb/tests/eventscripts/11.natgw.004.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "CTDB_NATGW_PUBLIC_IP unset, not slave-only"
+
+setup_ctdb
+setup_ctdb_natgw <<EOF
+192.168.1.21 master
+192.168.1.22
+192.168.1.23
+192.168.1.24
+EOF
+
+CTDB_NATGW_PUBLIC_IP=""
+
+required_result 1 "Invalid configuration: CTDB_NATGW_PUBLIC_IP not set"
+
+for i in "startup" "ipreallocated" "monitor" ; do
+    simple_test_event "$i"
+done
diff --git a/ctdb/tests/eventscripts/11.natgw.005.sh b/ctdb/tests/eventscripts/11.natgw.005.sh
new file mode 100755
index 0000000..94a80c8
--- /dev/null
+++ b/ctdb/tests/eventscripts/11.natgw.005.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "Inconsistent test setup: slave-only but current node is master"
+
+setup_ctdb
+setup_ctdb_natgw <<EOF
+192.168.1.21 master
+192.168.1.22
+192.168.1.23
+192.168.1.24
+EOF
+
+CTDB_NATGW_SLAVE_ONLY="yes"
+
+required_result 1 <<EOF
+Inconsistent test configuration - master node is slave-only
+There is no NATGW master node
+EOF
+
+for i in "ipreallocated" "monitor" ; do
+    simple_test_event "$i"
+done
diff --git a/ctdb/tests/eventscripts/11.natgw.041.sh b/ctdb/tests/eventscripts/11.natgw.041.sh
new file mode 100755
index 0000000..22dd392
--- /dev/null
+++ b/ctdb/tests/eventscripts/11.natgw.041.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "CTDB_NATGW_SLAVE_ONLY=yes, CTDB_NATGW_PUBLIC_IFACE unset"
+
+setup_ctdb
+setup_ctdb_natgw <<EOF
+192.168.1.21
+192.168.1.22 master
+192.168.1.23
+192.168.1.24
+EOF
+
+CTDB_NATGW_PUBLIC_IFACE=""
+CTDB_NATGW_SLAVE_ONLY="yes"
+
+ok_null
+simple_test_event "ipreallocated"
+
+ok "default via ${FAKE_CTDB_NATGW_MASTER} dev ethXXX  metric 10 "
+simple_test_command ip route show
diff --git a/ctdb/tests/eventscripts/11.natgw.042.sh b/ctdb/tests/eventscripts/11.natgw.042.sh
new file mode 100755
index 0000000..9019d4a
--- /dev/null
+++ b/ctdb/tests/eventscripts/11.natgw.042.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "CTDB_NATGW_SLAVE_ONLY=yes, CTDB_NATGW_PUBLIC_IP unset"
+
+setup_ctdb
+setup_ctdb_natgw <<EOF
+192.168.1.21
+192.168.1.22 master
+192.168.1.23
+192.168.1.24
+EOF
+
+CTDB_NATGW_PUBLIC_IFACE=""
+CTDB_NATGW_PUBLIC_IP=""
+CTDB_NATGW_SLAVE_ONLY="yes"
+
+ok_null
+simple_test_event "ipreallocated"
+
+ok "default via ${FAKE_CTDB_NATGW_MASTER} dev ethXXX  metric 10 "
+simple_test_command ip route show
diff --git a/ctdb/tests/eventscripts/scripts/local.sh b/ctdb/tests/eventscripts/scripts/local.sh
index 4bc2e6c..deaab60 100644
--- a/ctdb/tests/eventscripts/scripts/local.sh
+++ b/ctdb/tests/eventscripts/scripts/local.sh
@@ -535,6 +535,7 @@ setup_ctdb_natgw ()
     export CTDB_NATGW_PUBLIC_IP="10.1.1.121/24"
     export CTDB_NATGW_PUBLIC_IFACE="eth1"
     export CTDB_NATGW_DEFAULT_GATEWAY="10.1.1.254"
+    export CTDB_NATGW_SLAVE_ONLY=""
 }
 
 ok_natgw_master_ip_addr_show ()
diff --git a/ctdb/tests/eventscripts/stubs/ctdb b/ctdb/tests/eventscripts/stubs/ctdb
index 51c1763..b8b3e67 100755
--- a/ctdb/tests/eventscripts/stubs/ctdb
+++ b/ctdb/tests/eventscripts/stubs/ctdb


-- 
Samba Shared Repository


More information about the samba-cvs mailing list