samba-tool drs replicate improvements

Stefan Metzmacher metze at samba.org
Thu Jul 28 06:47:24 UTC 2016


Hi Andrew and Garming,

can I get a review on the following patches.

The main change is a timeout of 5 minutes for DsReplicaSync()
instead of 1 minute.

This may help with the flakey tests.

As a bonus I added a --async-op option so that
we can also trigger a replication without waiting for the result.

Thanks!
metze
-------------- next part --------------
From 051430b8d0790f2775c97a4a2030140b163dafe4 Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze at samba.org>
Date: Thu, 28 Jul 2016 06:36:05 +0200
Subject: [PATCH 1/6] s4:pyrpc: correctly implement .request_timeout

Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
 source4/librpc/rpc/pyrpc.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c
index 948cad2..834000c 100644
--- a/source4/librpc/rpc/pyrpc.c
+++ b/source4/librpc/rpc/pyrpc.c
@@ -172,6 +172,31 @@ static PyObject *py_iface_user_session_key(PyObject *obj, void *closure)
 	return session_key_obj;
 }
 
+static PyObject *py_iface_get_timeout(PyObject *obj, void *closure)
+{
+	dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj;
+	uint32_t timeout;
+
+	timeout = dcerpc_binding_handle_set_timeout(iface->binding_handle, 0);
+	dcerpc_binding_handle_set_timeout(iface->binding_handle, timeout);
+
+	return PyLong_FromUnsignedLong(timeout);
+}
+
+static int py_iface_set_timeout(PyObject *obj, PyObject *value, void *closure)
+{
+	dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj;
+	uint32_t timeout;
+
+	timeout = PyLong_AsUnsignedLong(value);
+	if (PyErr_Occurred() != NULL) {
+		return -1;
+	}
+
+	dcerpc_binding_handle_set_timeout(iface->binding_handle, timeout);
+	return 0;
+}
+
 static PyGetSetDef dcerpc_interface_getsetters[] = {
 	{ discard_const_p(char, "server_name"), py_iface_server_name, NULL,
 	  discard_const_p(char, "name of the server, if connected over SMB") },
@@ -183,12 +208,7 @@ static PyGetSetDef dcerpc_interface_getsetters[] = {
 	  discard_const_p(char, "session key (as used for blob encryption on LSA and SAMR)") },
 	{ discard_const_p(char, "user_session_key"), py_iface_user_session_key, NULL,
 	  discard_const_p(char, "user_session key (as used for blob encryption on DRSUAPI)") },
-	{ NULL }
-};
-
-static PyMemberDef dcerpc_interface_members[] = {
-	{ discard_const_p(char, "request_timeout"), T_INT, 
-	  offsetof(struct dcerpc_pipe, request_timeout), 0,
+	{ discard_const_p(char, "request_timeout"), py_iface_get_timeout, py_iface_set_timeout,
 	  discard_const_p(char, "request timeout, in seconds") },
 	{ NULL }
 };
@@ -322,7 +342,6 @@ static PyTypeObject dcerpc_InterfaceType = {
 	.tp_basicsize = sizeof(dcerpc_InterfaceObject),
 	.tp_dealloc = dcerpc_interface_dealloc,
 	.tp_getset = dcerpc_interface_getsetters,
-	.tp_members = dcerpc_interface_members,
 	.tp_methods = dcerpc_interface_methods,
 	.tp_doc = "ClientConnection(binding, syntax, lp_ctx=None, credentials=None) -> connection\n"
 "\n"
-- 
1.9.1


From 5f43c6c3bd3f06db23b7a9fbd8a0c6da80ccc94f Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze at samba.org>
Date: Thu, 28 Jul 2016 07:48:44 +0200
Subject: [PATCH 2/6] samba-tool: use a timeout of 5 minutes in 'samba-tool drs
 replicate'

Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
 python/samba/netcmd/drs.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/python/samba/netcmd/drs.py b/python/samba/netcmd/drs.py
index 4098131..751f486 100644
--- a/python/samba/netcmd/drs.py
+++ b/python/samba/netcmd/drs.py
@@ -318,14 +318,16 @@ class cmd_drs_replicate(Command):
             return
 
         if local_online:
-            server_bind = drsuapi.drsuapi("irpc:dreplsrv", lp_ctx=self.lp,
-                                          timeout=IRPC_CALL_TIMEOUT_INF)
+            server_bind = drsuapi.drsuapi("irpc:dreplsrv", lp_ctx=self.lp)
             server_bind_handle = misc.policy_handle()
         else:
             drsuapi_connect(self)
             server_bind = self.drsuapi
             server_bind_handle = self.drsuapi_handle
 
+        # Give the sync replication 5 minutes time
+        server_bind.request_timeout = 5 * 60
+
         samdb_connect(self)
 
         # we need to find the NTDS GUID of the source DC
-- 
1.9.1


From c38cbe8106f431c3958c20edb8a6120a1c086f1c Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze at samba.org>
Date: Thu, 28 Jul 2016 07:50:03 +0200
Subject: [PATCH 3/6] samba-tool: add --async-rep option to 'samba-tool drs
 replicate'

We may not want to wait for the replication to finish.

Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
 python/samba/netcmd/drs.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/python/samba/netcmd/drs.py b/python/samba/netcmd/drs.py
index 751f486..50ade74 100644
--- a/python/samba/netcmd/drs.py
+++ b/python/samba/netcmd/drs.py
@@ -301,11 +301,12 @@ class cmd_drs_replicate(Command):
         Option("--full-sync", help="resync all objects", action="store_true"),
         Option("--local", help="pull changes directly into the local database (destination DC is ignored)", action="store_true"),
         Option("--local-online", help="pull changes into the local database (destination DC is ignored) as a normal online replication", action="store_true"),
+        Option("--async-op", help="use ASYNC_OP for the replication", action="store_true"),
         ]
 
     def run(self, DEST_DC, SOURCE_DC, NC,
             add_ref=False, sync_forced=False, sync_all=False, full_sync=False,
-            local=False, local_online=False,
+            local=False, local_online=False, async_op=False,
             sambaopts=None, credopts=None, versionopts=None, server=None):
 
         self.server = DEST_DC
@@ -325,8 +326,9 @@ class cmd_drs_replicate(Command):
             server_bind = self.drsuapi
             server_bind_handle = self.drsuapi_handle
 
-        # Give the sync replication 5 minutes time
-        server_bind.request_timeout = 5 * 60
+        if not async_op:
+            # Give the sync replication 5 minutes time
+            server_bind.request_timeout = 5 * 60
 
         samdb_connect(self)
 
@@ -360,12 +362,17 @@ class cmd_drs_replicate(Command):
             req_options |= drsuapi.DRSUAPI_DRS_SYNC_ALL
         if full_sync:
             req_options |= drsuapi.DRSUAPI_DRS_FULL_SYNC_NOW
+        if async_op:
+            req_options |= drsuapi.DRSUAPI_DRS_ASYNC_OP
 
         try:
             drs_utils.sendDsReplicaSync(server_bind, server_bind_handle, source_dsa_guid, NC, req_options)
         except drs_utils.drsException, estr:
             raise CommandError("DsReplicaSync failed", estr)
-        self.message("Replicate from %s to %s was successful." % (SOURCE_DC, DEST_DC))
+        if async_op:
+            self.message("Replicate from %s to %s was started." % (SOURCE_DC, DEST_DC))
+        else:
+            self.message("Replicate from %s to %s was successful." % (SOURCE_DC, DEST_DC))
 
 
 
-- 
1.9.1


From 4e21c579b46aea5516bc1bc7ead0c7fed71791ae Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze at samba.org>
Date: Thu, 28 Jul 2016 08:29:39 +0200
Subject: [PATCH 4/6] tests:samba_tool_drs: test samba-tool drs replicate with
 implicit machine credentials

Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
 python/samba/tests/blackbox/samba_tool_drs.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/python/samba/tests/blackbox/samba_tool_drs.py b/python/samba/tests/blackbox/samba_tool_drs.py
index afaa4af..27d3885 100644
--- a/python/samba/tests/blackbox/samba_tool_drs.py
+++ b/python/samba/tests/blackbox/samba_tool_drs.py
@@ -137,7 +137,7 @@ class SambaToolDrsTests(samba.tests.BlackboxTestCase):
         self.assertTrue("Replicate from" in out)
         self.assertTrue("was successful" in out)
 
-    def test_samba_tool_replicate_machine_creds(self):
+    def test_samba_tool_replicate_machine_creds_P(self):
         """Tests 'samba-tool drs replicate -P' command with machine creds."""
 
         # Output should be like 'Replicate from <DC-SRC> to <DC-DEST> was successful.'
@@ -148,6 +148,17 @@ class SambaToolDrsTests(samba.tests.BlackboxTestCase):
         self.assertTrue("Replicate from" in out)
         self.assertTrue("was successful" in out)
 
+    def test_samba_tool_replicate_machine_creds(self):
+        """Tests 'samba-tool drs replicate' command with implicit machine creds."""
+
+        # Output should be like 'Replicate from <DC-SRC> to <DC-DEST> was successful.'
+        nc_name = self._get_rootDSE(self.dc1)["defaultNamingContext"]
+        out = self.check_output("samba-tool drs replicate %s %s %s" % (self.dc1,
+                                                                       self.dc2,
+                                                                       nc_name))
+        self.assertTrue("Replicate from" in out)
+        self.assertTrue("was successful" in out)
+
     def test_samba_tool_drs_clone_dc(self):
         """Tests 'samba-tool drs clone-dc-database' command."""
         server_rootdse = self._get_rootDSE(self.dc1)
-- 
1.9.1


From 8afde2c7b5b0607b3656257f202d0b0a0e2ef149 Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze at samba.org>
Date: Thu, 28 Jul 2016 08:29:39 +0200
Subject: [PATCH 5/6] tests:samba_tool_drs: test samba-tool drs replicate with
 --async-op

Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
 python/samba/tests/blackbox/samba_tool_drs.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/python/samba/tests/blackbox/samba_tool_drs.py b/python/samba/tests/blackbox/samba_tool_drs.py
index 27d3885..90921f4 100644
--- a/python/samba/tests/blackbox/samba_tool_drs.py
+++ b/python/samba/tests/blackbox/samba_tool_drs.py
@@ -103,6 +103,18 @@ class SambaToolDrsTests(samba.tests.BlackboxTestCase):
         self.assertTrue("Replicate from" in out)
         self.assertTrue("was successful" in out)
 
+    def test_samba_tool_replicate_async(self):
+        """Tests 'samba-tool drs replicate --async-op' command."""
+
+        # Output should be like 'Replicate from <DC-SRC> to <DC-DEST> was started.'
+        nc_name = self._get_rootDSE(self.dc1)["defaultNamingContext"]
+        out = self.check_output("samba-tool drs replicate --async-op %s %s %s %s" % (self.dc1,
+                                                                          self.dc2,
+                                                                          nc_name,
+                                                                          self.cmdline_creds))
+        self.assertTrue("Replicate from" in out)
+        self.assertTrue("was started" in out)
+
     def test_samba_tool_replicate_local_online(self):
         """Tests 'samba-tool drs replicate --local-online' command."""
 
@@ -114,6 +126,17 @@ class SambaToolDrsTests(samba.tests.BlackboxTestCase):
         self.assertTrue("Replicate from" in out)
         self.assertTrue("was successful" in out)
 
+    def test_samba_tool_replicate_local_online_async(self):
+        """Tests 'samba-tool drs replicate --local-online --async-op' command."""
+
+        # Output should be like 'Replicate from <DC-SRC> to <DC-DEST> was started.'
+        nc_name = self._get_rootDSE(self.dc1)["defaultNamingContext"]
+        out = self.check_output("samba-tool drs replicate --local-online --async-op %s %s %s" % (self.dc1,
+                                                                                      self.dc2,
+                                                                                      nc_name))
+        self.assertTrue("Replicate from" in out)
+        self.assertTrue("was started" in out)
+
     def test_samba_tool_replicate_local_machine_creds(self):
         """Tests 'samba-tool drs replicate --local -P' command (uses machine creds)."""
 
-- 
1.9.1


From 9a57560f599fba166e2f0392b84271b8e4b188b9 Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze at samba.org>
Date: Thu, 28 Jul 2016 08:40:51 +0200
Subject: [PATCH 6/6] WHATSNEW: document new samba-tool drs replicate options

Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
 WHATSNEW.txt | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index 81cbef2..4b195c3 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -69,6 +69,17 @@ with the same name on different servers.
 
 Schema updates are also handled much more reliably.
 
+samba-tool drs replicate with new options
+-----------------------------------------
+
+samba-tool drs replicate got two new options:
+
+The option '--local-online' will do the DsReplicaSync() via IRPC
+to the local dreplsrv service.
+
+The option '--async-op' will add DRSUAPI_DRS_ASYNC_OP to the
+DsReplicaSync(), which won't wait for the replication result.
+
 replPropertyMetaData Changes
 ----------------------------
 
-- 
1.9.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160728/8a92f17a/signature.sig>


More information about the samba-technical mailing list