From: Tim Beale Date: Tue, 18 Sep 2018 05:23:48 +0000 (+1200) Subject: tests: Add test-case for restore into non-default site X-Git-Tag: tdb-1.3.17~1507 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad69aaf7e13435111fc990954ff0bc81ed5325c5;p=thirdparty%2Fsamba.git tests: Add test-case for restore into non-default site 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 Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/domain_backup.py b/python/samba/tests/domain_backup.py index 9699ed0446e..d9bbddba423 100644 --- a/python/samba/tests/domain_backup.py +++ b/python/samba/tests/domain_backup.py @@ -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()