selftest: Port DrsBaseTestCase._net_drs_replicate() to self.runsubcmd()
authorAndrew Bartlett <abartlet@samba.org>
Thu, 6 Jul 2017 03:25:36 +0000 (15:25 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 27 Jul 2017 22:25:14 +0000 (00:25 +0200)
This avoids forking a subprocess with self.check_run()

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
source4/torture/drs/python/drs_base.py

index f07592d9e5619ea1c12b40a9923042cd27d13026..8703617837540090f35421024b55552f2b31621c 100644 (file)
@@ -108,20 +108,32 @@ class DrsBaseTestCase(SambaToolCmdTest):
         # bin/samba-tool drs <drs_command> <cmdline_auth>
         return "%s drs %s %s" % (samba_tool_cmd, drs_command, cmdline_auth)
 
+    def _samba_tool_cmd_list(self, drs_command):
+        # make command line credentials string
+        creds = self.get_credentials()
+        cmdline_auth = "-U%s/%s%%%s" % (creds.get_domain(),
+                                        creds.get_username(), creds.get_password())
+        # bin/samba-tool drs <drs_command> <cmdline_auth>
+        return ["drs", drs_command, cmdline_auth]
+
     def _net_drs_replicate(self, DC, fromDC, nc_dn=None, forced=True, local=False, full_sync=False):
         if nc_dn is None:
             nc_dn = self.domain_dn
         # make base command line
-        samba_tool_cmdline = self._samba_tool_cmdline("replicate")
+        samba_tool_cmdline = self._samba_tool_cmd_list("replicate")
+        # bin/samba-tool drs replicate <Dest_DC_NAME> <Src_DC_NAME> <Naming Context>
+        samba_tool_cmdline += [DC, fromDC, nc_dn]
+
         if forced:
-            samba_tool_cmdline += " --sync-forced"
+            samba_tool_cmdline += ["--sync-forced"]
         if local:
-            samba_tool_cmdline += " --local"
+            samba_tool_cmdline += ["--local"]
         if full_sync:
-            samba_tool_cmdline += " --full-sync"
-        # bin/samba-tool drs replicate <Dest_DC_NAME> <Src_DC_NAME> <Naming Context>
-        cmd_line = "%s %s %s %s" % (samba_tool_cmdline, DC, fromDC, nc_dn)
-        return self.check_output(cmd_line)
+            samba_tool_cmdline += ["--full-sync"]
+
+        (result, out, err) = self.runsubcmd(*samba_tool_cmdline)
+        self.assertCmdSuccess(result, out, err)
+        self.assertEquals(err,"","Shouldn't be any error messages")
 
     def _enable_inbound_repl(self, DC):
         # make base command line