diff --git a/python/samba/tests/samba_tool/drs_clone_dc_data_lmdb_size.py b/python/samba/tests/samba_tool/drs_clone_dc_data_lmdb_size.py new file mode 100644 index 00000000000..ae78784a04d --- /dev/null +++ b/python/samba/tests/samba_tool/drs_clone_dc_data_lmdb_size.py @@ -0,0 +1,119 @@ +# 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 . +# + +from samba.tests.samba_tool.base import SambaToolCmdTest +import os +import shutil + + +class DrsCloneDcDataLmdbSizeTestCase(SambaToolCmdTest): + """Test setting of the lmdb map size during drs clone-dc-data""" + + def setUp(self): + super(DrsCloneDcDataLmdbSizeTestCase, self).setUp() + self.tempsambadir = os.path.join(self.tempdir, "samba") + os.mkdir(self.tempsambadir) + + # clone a domain and set the lmdb map size to size + # + # returns the tuple (ret, stdout, stderr) + def clone(self, size=None): + command = ( + "samba-tool " + + "drs clone-dc-database " + + os.environ["REALM"] + " " + + ("-U%s%%%s " % (os.environ["USERNAME"], os.environ["PASSWORD"])) + + ("--targetdir=%s " % self.tempsambadir) + + "--backend-store=mdb " + ) + 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.clone() + self.assertEquals(0, result) + self.check_lmdb_environment_sizes(8 * 1024 * 1024 * 1024) + + def test_64Mb(self): + (result, out, err) = self.clone("64Mb") + self.assertEquals(0, result) + self.check_lmdb_environment_sizes(64 * 1024 * 1024) + + def test_no_unit_suffix(self): + (result, out, err) = self.run_command( + 'samba-tool drs clone-dc-database --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 drs clone-dc-database --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 drs clone-dc-database --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(DrsCloneDcDataLmdbSizeTestCase, self).tearDown() + shutil.rmtree(self.tempsambadir) diff --git a/selftest/knownfail.d/drs_clone_dc_lmdb_size b/selftest/knownfail.d/drs_clone_dc_lmdb_size new file mode 100644 index 00000000000..607f2fbaa3b --- /dev/null +++ b/selftest/knownfail.d/drs_clone_dc_lmdb_size @@ -0,0 +1,5 @@ +samba.tests.samba_tool.drs_clone_dc_data_lmdb_size.samba.tests.samba_tool.drs_clone_dc_data_lmdb_size.DrsCloneDcDataLmdbSizeTestCase.test_64Mb\(ad_dc_default\) +samba.tests.samba_tool.drs_clone_dc_data_lmdb_size.samba.tests.samba_tool.drs_clone_dc_data_lmdb_size.DrsCloneDcDataLmdbSizeTestCase.test_default\(ad_dc_default\) +samba.tests.samba_tool.drs_clone_dc_data_lmdb_size.samba.tests.samba_tool.drs_clone_dc_data_lmdb_size.DrsCloneDcDataLmdbSizeTestCase.test_invalid_unit_suffix\(ad_dc_default\) +samba.tests.samba_tool.drs_clone_dc_data_lmdb_size.samba.tests.samba_tool.drs_clone_dc_data_lmdb_size.DrsCloneDcDataLmdbSizeTestCase.test_no_unit_suffix\(ad_dc_default\) +samba.tests.samba_tool.drs_clone_dc_data_lmdb_size.samba.tests.samba_tool.drs_clone_dc_data_lmdb_size.DrsCloneDcDataLmdbSizeTestCase.test_non_numeric\(ad_dc_default\) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 7f087c4c873..8bd04b24f61 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -647,6 +647,8 @@ planpythontestsuite("ad_dc_default:local", "samba.tests.samba_tool.timecmd") planpythontestsuite("ad_dc_default:local", "samba.tests.samba_tool.join") planpythontestsuite("ad_dc_default", "samba.tests.samba_tool.join_lmdb_size") +planpythontestsuite("ad_dc_default", + "samba.tests.samba_tool.drs_clone_dc_data_lmdb_size") planpythontestsuite("none", "samba.tests.samba_tool.visualize")