]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
provision tests: Add --backend-store-size option.
authorGary Lockyer <gary@catalyst.net.nz>
Tue, 25 Jun 2019 04:14:34 +0000 (16:14 +1200)
committerGary Lockyer <gary@samba.org>
Tue, 2 Jul 2019 02:23:08 +0000 (02:23 +0000)
Tests for the new "samba-tool domain provision" option
"backend-store-size".  This allows the lmdb map size to be set during a
provision, instead of hard-wiring it to 8Gb

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/__init__.py
python/samba/tests/samba_tool/provision_lmdb_size.py [new file with mode: 0644]
selftest/knownfail.d/provision_lmdb_size [new file with mode: 0644]
source4/selftest/tests.py

index cbd164de1f9d19bd637e5fcf6ba327e9cbf18b9c..674cdee1a3e4bcc72ecb690a37ed62c6ee29680d 100644 (file)
@@ -448,6 +448,23 @@ class BlackboxTestCase(TestCaseInTempDir):
             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.
     def random_password(self, count=32):
diff --git a/python/samba/tests/samba_tool/provision_lmdb_size.py b/python/samba/tests/samba_tool/provision_lmdb_size.py
new file mode 100644 (file)
index 0000000..c48cb67
--- /dev/null
@@ -0,0 +1,132 @@
+# 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 ProvisionLmdbSizeTestCase(SambaToolCmdTest):
+    """Test setting of the lmdb map size during provision"""
+
+    def setUp(self):
+        super(ProvisionLmdbSizeTestCase, self).setUp()
+        self.tempsambadir = os.path.join(self.tempdir, "samba")
+        os.mkdir(self.tempsambadir)
+
+    # provision a domain and set the lmdb map size to size
+    #
+    # returns the tuple (ret, stdout, stderr)
+    def provision(self, size=None):
+        command = (
+            "samba-tool " +
+            "domain provision " +
+            "--realm=foo.example.com " +
+            "--domain=FOO " +
+            ("--targetdir=%s " % self.tempsambadir) +
+            "--backend-store=mdb " +
+            "--use-ntvfs "
+        )
+        if size:
+            command += ("--backend-store-size=%s" % size)
+
+        return self.run_command(command)
+
+    #
+    # Get the lmdb map size for the specified command
+    #
+    # While there is a python lmdb package available we use the lmdb command
+    # line utilities to avoid introducing a dependancy.
+    #
+    def get_lmdb_environment_size(self, path):
+        (result, out, err) = self.run_command("mdb_stat -ne %s" % path)
+        if result:
+            self.fail("Unable to run mdb_stat\n")
+        for line in out.split("\n"):
+            line = line.strip()
+            if line.startswith("Map size:"):
+                line = line.replace(" ", "")
+                (label, size) = line.split(":")
+                return int(size)
+
+    #
+    # Check the lmdb files created by provision and ensure that the map size
+    # has been set to size.
+    #
+    # Currently this is all the *.ldb files in private/sam.ldb.d
+    #
+    def check_lmdb_environment_sizes(self, size):
+        directory = os.path.join(self.tempsambadir, "private", "sam.ldb.d")
+        for name in os.listdir(directory):
+            if name.endswith(".ldb"):
+                path = os.path.join(directory, name)
+                s = self.get_lmdb_environment_size(path)
+                if s != size:
+                    self.fail("File %s, size=%d larger than %d" %
+                              (name, s, size))
+
+    #
+    # Ensure that if --backend-store-size is not specified the default of
+    # 8Gb is used
+    def test_default(self):
+        (result, out, err) = self.provision()
+        self.assertEquals(0, result)
+        self.check_lmdb_environment_sizes(8 * 1024 * 1024 * 1024)
+
+    def test_64Mb(self):
+        (result, out, err) = self.provision("64Mb")
+        self.assertEquals(0, result)
+        self.check_lmdb_environment_sizes(64 * 1024 * 1024)
+
+    def test_1Gb(self):
+        (result, out, err) = self.provision("1Gb")
+        self.assertEquals(0, result)
+        self.check_lmdb_environment_sizes(1 * 1024 * 1024 * 1024)
+
+    # 128Mb specified in bytes.
+    #
+    def test_134217728b(self):
+        (result, out, err) = self.provision("134217728b")
+        self.assertEquals(0, result)
+        self.check_lmdb_environment_sizes(134217728)
+
+    def test_no_unit_suffix(self):
+        (result, out, err) = self.run_command(
+            'samba-tool domain provision --backend-store-size "2"')
+        self.assertGreater(result, 0)
+        self.assertRegexpMatches(err,
+                                 r"--backend-store-size invalid suffix ''")
+
+    def test_invalid_unit_suffix(self):
+        (result, out, err) = self.run_command(
+            'samba-tool domain provision --backend-store-size "2 cd"')
+        self.assertGreater(result, 0)
+        self.assertRegexpMatches(err,
+                                 r"--backend-store-size invalid suffix 'cd'")
+
+    def test_non_numeric(self):
+        (result, out, err) = self.run_command(
+            'samba-tool domain provision --backend-store-size "two Gb"')
+        self.assertGreater(result, 0)
+        self.assertRegexpMatches(
+            err,
+            r"backend-store-size option requires a numeric value, with an"
+            " optional unit suffix")
+
+    def tearDown(self):
+        super(ProvisionLmdbSizeTestCase, self).tearDown()
+        shutil.rmtree(self.tempsambadir)
diff --git a/selftest/knownfail.d/provision_lmdb_size b/selftest/knownfail.d/provision_lmdb_size
new file mode 100644 (file)
index 0000000..f2992c3
--- /dev/null
@@ -0,0 +1,7 @@
+^samba.tests.samba_tool.provision_lmdb_size.samba.tests.samba_tool.provision_lmdb_size.ProvisionLmdbSizeTestCase.test_134217728b\(none\)
+^samba.tests.samba_tool.provision_lmdb_size.samba.tests.samba_tool.provision_lmdb_size.ProvisionLmdbSizeTestCase.test_1Gb\(none\)
+^samba.tests.samba_tool.provision_lmdb_size.samba.tests.samba_tool.provision_lmdb_size.ProvisionLmdbSizeTestCase.test_64Mb\(none\)
+^samba.tests.samba_tool.provision_lmdb_size.samba.tests.samba_tool.provision_lmdb_size.ProvisionLmdbSizeTestCase.test_invalid_unit_suffix\(none\)
+^samba.tests.samba_tool.provision_lmdb_size.samba.tests.samba_tool.provision_lmdb_size.ProvisionLmdbSizeTestCase.test_no_unit_suffix\(none\)
+^samba.tests.samba_tool.provision_lmdb_size.samba.tests.samba_tool.provision_lmdb_size.ProvisionLmdbSizeTestCase.test_non_numeric\(none\)
+
index dec43d3a29651d7f2ca6b8f58172e6929167de35..5aad3c63e48f70ebc1d13a8cbabd5ab12f2cdd55 100755 (executable)
@@ -680,6 +680,7 @@ planpythontestsuite("ad_dc_default:local", "samba.tests.samba_tool.schema")
 planpythontestsuite("schema_dc:local", "samba.tests.samba_tool.schema")
 planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.ntacl")
 planpythontestsuite("none", "samba.tests.samba_tool.provision_password_check")
+planpythontestsuite("none", "samba.tests.samba_tool.provision_lmdb_size")
 planpythontestsuite("none", "samba.tests.samba_tool.help")
 planpythontestsuite("ad_dc_default:local", "samba.tests.samba_tool.passwordsettings")
 planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.dsacl")