tests: Add test-case for restore into non-default site
authorTim Beale <timbeale@catalyst.net.nz>
Tue, 18 Sep 2018 05:23:48 +0000 (17:23 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 26 Sep 2018 05:49:17 +0000 (07:49 +0200)
Add a test-case that exercises the new '--site' restore option and
ensures the restored DC gets added to the correct site.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13621

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/domain_backup.py

index 9699ed0446ed43f9a5f52bc29f0ea61c23b8f155..d9bbddba423d7450ea6465a2aa892f840d6d0a23 100644 (file)
@@ -27,6 +27,7 @@ from samba.auth import system_session
 from samba import Ldb, dn_from_dns_name
 from samba.netcmd.fsmo import get_fsmo_roleowner
 import re
+from samba import sites
 
 
 def get_prim_dom(secrets_path, lp):
@@ -149,6 +150,32 @@ class DomainBackupBase(SambaToolCmdTest, TestCaseInTempDir):
         # assert that we don't find user secrets in the DB
         self.check_restored_database(lp, expect_secrets=False)
 
+    def _test_backup_restore_into_site(self):
+        """Does a backup and restores into a non-default site"""
+
+        # create a new non-default site
+        sitename = "Test-Site-For-Backups"
+        sites.create_site(self.ldb, self.ldb.get_config_basedn(), sitename)
+        self.addCleanup(sites.delete_site, self.ldb,
+                        self.ldb.get_config_basedn(), sitename)
+
+        # restore the backup DC into the site we just created
+        backup_file = self.create_backup()
+        self.restore_backup(backup_file, ["--site=" + sitename])
+
+        lp = self.check_restored_smbconf()
+        restored_ldb = self.check_restored_database(lp)
+
+        # check the restored DC was added to the site we created, i.e. there's
+        # an entry matching the new DC sitting underneath the site DN
+        site_dn = "CN={0},CN=Sites,{1}".format(sitename,
+                                               restored_ldb.get_config_basedn())
+        match_server = "(&(objectClass=server)(cn={0}))".format(self.new_server)
+        res = restored_ldb.search(site_dn, scope=ldb.SCOPE_SUBTREE,
+                                  expression=match_server)
+        self.assertTrue(len(res) == 1,
+                        "Failed to find new DC under site")
+
     def create_smbconf(self, settings):
         """Creates a very basic smb.conf to pass to the restore tool"""
 
@@ -372,6 +399,9 @@ class DomainBackupOnline(DomainBackupBase):
     def test_backup_restore_no_secrets(self):
         self._test_backup_restore_no_secrets()
 
+    def test_backup_restore_into_site(self):
+        self._test_backup_restore_into_site()
+
 
 class DomainBackupRename(DomainBackupBase):
 
@@ -400,6 +430,9 @@ class DomainBackupRename(DomainBackupBase):
     def test_backup_restore_no_secrets(self):
         self._test_backup_restore_no_secrets()
 
+    def test_backup_restore_into_site(self):
+        self._test_backup_restore_into_site()
+
     def test_backup_invalid_args(self):
         """Checks that rename commands with invalid args are rejected"""
 
@@ -524,3 +557,6 @@ class DomainBackupOffline(DomainBackupBase):
 
     def test_backup_restore(self):
         self._test_backup_restore()
+
+    def test_backup_restore_into_site(self):
+        self._test_backup_restore_into_site()