tests:samba_tool: pass stdout and stderr to assertCmdSuccess()
[nivanova/samba-autobuild/.git] / python / samba / tests / samba_tool / rodc.py
index 9ae5dd16cc012bddc9b5e467e2b0ac6602b70d8f..4851a53910a81c6aeb01b029085c58647cdc230b 100644 (file)
@@ -43,10 +43,12 @@ class RodcCmdTestCase(SambaToolCmdTest):
         self.ldb.newuser("sambatool2", "2wsxCDE#")
         self.ldb.newuser("sambatool3", "3edcVFR$")
         self.ldb.newuser("sambatool4", "4rfvBGT%")
+        self.ldb.newuser("sambatool5", "5tjbNHY*")
+        self.ldb.newuser("sambatool6", "6yknMJU*")
 
         self.ldb.add_remove_group_members("Allowed RODC Password Replication Group",
                                           ["sambatool1", "sambatool2", "sambatool3",
-                                           "sambatool4"],
+                                           "sambatool4", "sambatool5"],
                                           add_members_operation=True)
 
     def tearDown(self):
@@ -55,6 +57,8 @@ class RodcCmdTestCase(SambaToolCmdTest):
         self.ldb.deleteuser("sambatool2")
         self.ldb.deleteuser("sambatool3")
         self.ldb.deleteuser("sambatool4")
+        self.ldb.deleteuser("sambatool5")
+        self.ldb.deleteuser("sambatool6")
         (result, out, err) = self.runsubcmd("drs", "replicate", "--local", "unused",
                                             os.environ["DC_SERVER"], self.base_dn)
 
@@ -62,26 +66,26 @@ class RodcCmdTestCase(SambaToolCmdTest):
     def test_single_by_account_name(self):
         (result, out, err) = self.runsubcmd("rodc", "preload", "sambatool1",
                                             "--server", os.environ["DC_SERVER"])
-        self.assertCmdSuccess(result, "ensuring rodc prefetch ran successfully")
+        self.assertCmdSuccess(result, out, err, "ensuring rodc prefetch ran successfully")
         self.assertEqual(out, "Replicating DN CN=sambatool1,CN=Users,%s\n" % self.base_dn)
         self.assertEqual(err, "")
 
     def test_single_by_dn(self):
         (result, out, err) = self.runsubcmd("rodc", "preload", "cn=sambatool2,cn=users,%s" % self.base_dn,
                                             "--server", os.environ["DC_SERVER"])
-        self.assertCmdSuccess(result, "ensuring rodc prefetch ran successfully")
+        self.assertCmdSuccess(result, out, err, "ensuring rodc prefetch ran successfully")
         self.assertEqual(out, "Replicating DN CN=sambatool2,CN=Users,%s\n" % self.base_dn)
 
     def test_multi_by_account_name(self):
         (result, out, err) = self.runsubcmd("rodc", "preload", "sambatool1", "sambatool2",
                                             "--server", os.environ["DC_SERVER"])
-        self.assertCmdSuccess(result, "ensuring rodc prefetch ran successfully")
+        self.assertCmdSuccess(result, out, err, "ensuring rodc prefetch ran successfully")
         self.assertEqual(out, "Replicating DN CN=sambatool1,CN=Users,%s\nReplicating DN CN=sambatool2,CN=Users,%s\n" % (self.base_dn, self.base_dn))
 
     def test_multi_by_dn(self):
         (result, out, err) = self.runsubcmd("rodc", "preload", "cn=sambatool3,cn=users,%s" % self.base_dn, "cn=sambatool4,cn=users,%s" % self.base_dn,
                                             "--server", os.environ["DC_SERVER"])
-        self.assertCmdSuccess(result, "ensuring rodc prefetch ran successfully")
+        self.assertCmdSuccess(result, out, err, "ensuring rodc prefetch ran successfully")
         self.assertEqual(out, "Replicating DN CN=sambatool3,CN=Users,%s\nReplicating DN CN=sambatool4,CN=Users,%s\n" % (self.base_dn, self.base_dn))
 
     def test_multi_in_file(self):
@@ -89,6 +93,36 @@ class RodcCmdTestCase(SambaToolCmdTest):
         open(tempf, 'w').write("sambatool1\nsambatool2")
         (result, out, err) = self.runsubcmd("rodc", "preload", "--file", tempf,
                                             "--server", os.environ["DC_SERVER"])
-        self.assertCmdSuccess(result, "ensuring rodc prefetch ran successfully")
+        self.assertCmdSuccess(result, out, err, "ensuring rodc prefetch ran successfully")
         self.assertEqual(out, "Replicating DN CN=sambatool1,CN=Users,%s\nReplicating DN CN=sambatool2,CN=Users,%s\n" % (self.base_dn, self.base_dn))
         os.unlink(tempf)
+
+    def test_multi_with_missing_name_success(self):
+        (result, out, err) = self.runsubcmd("rodc", "preload",
+                                            "nonexistentuser1", "sambatool5",
+                                            "nonexistentuser2",
+                                            "--server", os.environ["DC_SERVER"],
+                                            "--ignore-errors")
+        self.assertCmdSuccess(result, out, err, "ensuring rodc prefetch ran successfully")
+        self.assertEqual(out, "Replicating DN CN=sambatool5,CN=Users,%s\n" % self.base_dn)
+
+    def test_multi_with_missing_name_failure(self):
+        (result, out, err) = self.runsubcmd("rodc", "preload",
+                                            "nonexistentuser1", "sambatool5",
+                                            "nonexistentuser2",
+                                            "--server", os.environ["DC_SERVER"])
+        self.assertCmdFail(result, "ensuring rodc prefetch quit on missing user")
+
+    def test_multi_without_group_success(self):
+        (result, out, err) = self.runsubcmd("rodc", "preload",
+                                            "sambatool6", "sambatool5",
+                                            "--server", os.environ["DC_SERVER"],
+                                            "--ignore-errors")
+        self.assertCmdSuccess(result, out, err, "ensuring rodc prefetch ran successfully")
+        self.assertEqual(out, "Replicating DN CN=sambatool6,CN=Users,%s\nReplicating DN CN=sambatool5,CN=Users,%s\n" % (self.base_dn, self.base_dn))
+
+    def test_multi_without_group_failure(self):
+        (result, out, err) = self.runsubcmd("rodc", "preload",
+                                            "sambatool6", "sambatool5",
+                                            "--server", os.environ["DC_SERVER"])
+        self.assertCmdFail(result, "ensuring rodc prefetch quit on non-replicated user")