netcmd: Add test for an offline backup of nested directories
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Wed, 17 Mar 2021 21:52:52 +0000 (10:52 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 23 Mar 2021 23:38:38 +0000 (23:38 +0000)
This test verifies that when performing an offline backup of a domain
where one of the directories to be backed up is nested inside another,
the contained files are only included once in the backup.

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz
python/samba/tests/domain_backup_offline.py
selftest/knownfail.d/bug-14027

index 80ccf3bb93b86ac436fe5c92cd69aaf0ca19e2b7..16d3e7c36f42cd45d5c252c466c5c1e9e0d2fc89 100644 (file)
@@ -21,6 +21,7 @@ import shutil
 import tempfile
 from samba.tests import BlackboxTestCase
 from samba.netcmd import CommandError
+from samba.param import LoadParm
 
 # The backup tests require that a completely clean LoadParm object gets used
 # for the restore. Otherwise the same global LP gets re-used, and the LP
@@ -31,6 +32,36 @@ from samba.netcmd import CommandError
 # so that we never inadvertently use .runcmd() by accident.
 class DomainBackupOfflineCmp(BlackboxTestCase):
 
+    def test_domain_backup_offline_nested_tdb(self):
+        self.nested_testcase('tdb')
+
+    def test_domain_backup_offline_nested_mdb(self):
+        self.nested_testcase('mdb')
+
+    def nested_testcase(self, backend):
+        self.prov_dir = self.provision(backend)
+        self.extract_dir = None
+
+        src = os.path.join(self.prov_dir, "private")
+        dst = os.path.join(self.prov_dir, "state", "private")
+
+        # Move private directory inside state directory
+        shutil.move(src, dst)
+
+        smbconf = os.path.join(self.prov_dir, "etc", "smb.conf")
+
+        # Update the conf file
+        lp = LoadParm(filename_for_non_global_lp=smbconf)
+        lp.set("private dir", dst)
+        lp.dump(False, smbconf)
+
+        backup_file = self.backup(self.prov_dir)
+
+        # Ensure each file is only present once in the tar file
+        tf = tarfile.open(backup_file)
+        names = tf.getnames()
+        self.assertEqual(len(names), len(set(names)))
+
     def test_domain_backup_offline_hard_link_tdb(self):
         self.hard_link_testcase('tdb')
 
index b1bb5270b3e75e57d30a47777d73a91892c361a7..f0746474be2baf79a9436f2e25a7edc87d465942 100644 (file)
@@ -1 +1,2 @@
 ^samba.tests.domain_backup_offline.samba.tests.domain_backup_offline.DomainBackupOfflineCmp.test_domain_backup_offline_hard_link
+^samba.tests.domain_backup_offline.samba.tests.domain_backup_offline.DomainBackupOfflineCmp.test_domain_backup_offline_nested