]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
test upgradedns: ensure lmdb lock files linked
authorGary Lockyer <gary@catalyst.net.nz>
Thu, 19 Dec 2019 03:31:24 +0000 (16:31 +1300)
committerKarolin Seeger <kseeger@samba.org>
Tue, 14 Jan 2020 08:30:24 +0000 (08:30 +0000)
Add tests to check that the '-lock' files for the dns partitions as well as
the data files are linked when running
    samba_dnsupgrade --dns-backend=BIND9_DLZ
failure to create these links can cause corruption of the corresponding
data file.

Changes to python/samba/tests/__init__.py adding run_command manually
copied from commit b27817d491794a292278832e3f59f955f418a6cb

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

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit f0cebbe4dd0317e2abfcbe252977383e6f37f3bd)

python/samba/tests/__init__.py
python/samba/tests/samba_upgradedns_lmdb.py [new file with mode: 0644]
selftest/knownfail.d/bug-14199 [new file with mode: 0644]
source4/selftest/tests.py

index 15824bd410ae53fec5595134c8a92718083eb96b..ef0fdabbfa26cb861239eed78214724941cc7941 100644 (file)
@@ -447,6 +447,22 @@ class BlackboxTestCase(TestCaseInTempDir):
         if retcode:
             raise BlackboxProcessError(retcode, line, stdoutdata, stderrdata)
         return stdoutdata
+    #
+    # Run a command without checking the return code, returns the tuple
+    # (ret, stdout, stderr)
+    # where ret is the return code
+    #       stdout is a string containing the commands stdout
+    #       stderr is a string containing the commands stderr
+    def run_command(self, line):
+        line = self._make_cmdline(line)
+        use_shell = not isinstance(line, list)
+        p = subprocess.Popen(line,
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE,
+                             shell=use_shell)
+        stdoutdata, stderrdata = p.communicate()
+        retcode = p.returncode
+        return (retcode, stdoutdata.decode('UTF8'), stderrdata.decode('UTF8'))
 
     # Generate a random password that can be safely  passed on the command line
     # i.e. it does not contain any shell meta characters.
diff --git a/python/samba/tests/samba_upgradedns_lmdb.py b/python/samba/tests/samba_upgradedns_lmdb.py
new file mode 100644 (file)
index 0000000..0489931
--- /dev/null
@@ -0,0 +1,75 @@
+# Unix SMB/CIFS implementation.
+# Copyright (C) Catalyst IT Ltd. 2019
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+from samba.tests.samba_tool.base import SambaToolCmdTest
+import os
+import shutil
+
+
+class UpgradeDnsLmdbTestCase(SambaToolCmdTest):
+    """
+        Tests for dns upgrade on a lmdb backend
+    """
+
+    def setUp(self):
+        super(UpgradeDnsLmdbTestCase, self).setUp()
+        self.tempsambadir = os.path.join(self.tempdir, "samba")
+        os.mkdir(self.tempsambadir)
+
+    # provision a domain
+    #
+    # returns the tuple (ret, stdout, stderr)
+    def provision(self):
+        command = (
+            "samba-tool "
+            "domain provision "
+            "--realm=foo.example.com "
+            "--domain=FOO "
+            "--targetdir=%s "
+            "--backend-store=mdb "
+            "--use-ntvfs " % self.tempsambadir)
+        return self.run_command(command)
+
+    # upgrade a domains dns to BIND9
+    #
+    # returns the tuple (ret, stdout, stderr)
+    def upgrade_dns(self):
+        command = (
+            "samba_upgradedns "
+            "--dns-backend=BIND9_DLZ "
+            "--configfile %s/etc/smb.conf" % self.tempsambadir)
+        return self.run_command(command)
+
+    def tearDown(self):
+        super(UpgradeDnsLmdbTestCase, self).tearDown()
+        shutil.rmtree(self.tempsambadir)
+
+    def test_lmdb_lock_files_linked_on_upgrade_to_bind9_dlz(self):
+        """
+            Ensure that links are created for the lock files as well as the
+            data files
+        """
+        self.provision()
+        self.upgrade_dns()
+        directory = ("%s/bind-dns/dns/sam.ldb.d" % self.tempsambadir)
+        for filename in os.listdir(directory):
+            if filename.endswith(".ldb") and "DNSZONES" in filename:
+                lock_file = ("%s/%s-lock" % (directory, filename))
+                self.assertTrue(
+                    os.path.isfile(lock_file),
+                    msg=("Lock file %s/%s-lock for %s, does not exist" %
+                         (directory, filename, filename)))
diff --git a/selftest/knownfail.d/bug-14199 b/selftest/knownfail.d/bug-14199
new file mode 100644 (file)
index 0000000..f950891
--- /dev/null
@@ -0,0 +1 @@
+^samba.tests.samba_upgradedns_lmdb.samba.tests.samba_upgradedns_lmdb.
index e1e395339df29afebbcd177d1535b0403f3adafa..ed4f2fc623e58d7d97a60fe79a03e6112851e363 100755 (executable)
@@ -689,6 +689,8 @@ planpythontestsuite("none", "samba.tests.samba_tool.provision_password_check",
 planpythontestsuite("none", "samba.tests.samba_tool.help", py3_compatible=True)
 planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.passwordsettings", py3_compatible=True)
 
+planpythontestsuite("none", "samba.tests.samba_upgradedns_lmdb")
+
 # Run these against chgdcpass to share the runtime load
 planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.sites", py3_compatible=True)
 planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.dnscmd", py3_compatible=True)