tests/samba_dnsupdate: Add a trivial test of automatic site coverage
authorGarming Sam <garming@catalyst.net.nz>
Mon, 19 Mar 2018 03:50:36 +0000 (16:50 +1300)
committerDouglas Bagnall <dbagnall@samba.org>
Wed, 21 Mar 2018 03:36:22 +0000 (04:36 +0100)
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/tests/blackbox/samba_dnsupdate.py
selftest/knownfail.d/autosite_coverage [new file with mode: 0644]

index 7ddaab7cff49d153cbf28bf2653e2e5e2947b3f6..e6cad3bbaba651fc6618441ba4ccd67f9c48f4b6 100644 (file)
 #
 
 import samba.tests
+from StringIO import StringIO
+from samba.netcmd.main import cmd_sambatool
+from samba.credentials import Credentials
+from samba.auth import system_session
+from samba.samdb import SamDB
+import ldb
 
 class SambaDnsUpdateTests(samba.tests.BlackboxTestCase):
     """Blackbox test case for samba_dnsupdate."""
@@ -57,3 +63,51 @@ class SambaDnsUpdateTests(samba.tests.BlackboxTestCase):
         self.assertTrue(" DNS deletes needed" in rpc_out, rpc_out)
         out = self.check_output("samba_dnsupdate --verbose")
         self.assertTrue("No DNS updates needed" in out, out + rpc_out)
+
+    def test_add_new_uncovered_site(self):
+        name = 'sites'
+        cmd = cmd_sambatool.subcommands[name]
+        cmd.outf = StringIO()
+        cmd.errf = StringIO()
+
+        site_name = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+
+        # Clear out any existing site
+        cmd._run("samba-tool %s" % name, 'remove', site_name)
+
+        result = cmd._run("samba-tool %s" % name, 'create', site_name)
+        if result is not None:
+            self.fail("Error creating new site")
+
+        self.lp = samba.tests.env_loadparm()
+        self.creds = Credentials()
+        self.creds.guess(self.lp)
+        self.session = system_session()
+
+        self.samdb = SamDB(session_info=self.session,
+                           credentials=self.creds,
+                           lp=self.lp)
+
+        m = ldb.Message()
+        m.dn = ldb.Dn(self.samdb, 'CN=DEFAULTIPSITELINK,CN=IP,'
+                      'CN=Inter-Site Transports,CN=Sites,{}'.format(
+                          self.samdb.get_config_basedn()))
+        m['siteList'] = ldb.MessageElement("CN={},CN=Sites,{}".format(
+            site_name,
+            self.samdb.get_config_basedn()),
+            ldb.FLAG_MOD_ADD, "siteList")
+
+        out = self.check_output("samba_dnsupdate --verbose")
+        self.assertTrue("No DNS updates needed" in out, out)
+
+        self.samdb.modify(m)
+
+        out = self.check_output("samba_dnsupdate --verbose --use-samba-tool"
+                                " --rpc-server-ip={}".format(self.server_ip))
+
+        self.assertFalse("No DNS updates needed" in out, out)
+        self.assertTrue(site_name.lower() in out, out)
+
+        result = cmd._run("samba-tool %s" % name, 'remove', site_name)
+        if result is not None:
+            self.fail("Error deleting site")
diff --git a/selftest/knownfail.d/autosite_coverage b/selftest/knownfail.d/autosite_coverage
new file mode 100644 (file)
index 0000000..1dd2df4
--- /dev/null
@@ -0,0 +1 @@
+^samba.tests.blackbox.samba_dnsupdate.samba.tests.blackbox.samba_dnsupdate.SambaDnsUpdateTests.test_add_new_uncovered_site