summaryrefslogtreecommitdiffstats
path: root/testsuite/Testsrc/Testlib
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/Testsrc/Testlib')
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py28
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py54
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py8
-rw-r--r--testsuite/Testsrc/Testlib/TestOptions/TestComponents.py10
-rw-r--r--testsuite/Testsrc/Testlib/TestOptions/TestConfigFiles.py8
-rw-r--r--testsuite/Testsrc/Testlib/TestOptions/TestTypes.py20
-rw-r--r--testsuite/Testsrc/Testlib/TestOptions/Two.py3
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py10
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py4
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py9
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py7
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py8
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py15
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestRules.py18
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py33
-rw-r--r--testsuite/Testsrc/Testlib/TestUtils.py15
16 files changed, 170 insertions, 80 deletions
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py
index 69dd562be..47d3b84ed 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py
@@ -37,22 +37,6 @@ class TestPOSIXFile(TestPOSIXTool):
entry.text = "text"
self.assertTrue(ptool.fully_specified(entry))
- def test_is_string(self):
- ptool = self.get_obj()
-
- for char in list(range(8)) + list(range(14, 32)):
- self.assertFalse(ptool._is_string("foo" + chr(char) + "bar",
- 'UTF-8'))
- for char in list(range(9, 14)) + list(range(33, 128)):
- self.assertTrue(ptool._is_string("foo" + chr(char) + "bar",
- 'UTF-8'))
- ustr = 'é'
- self.assertTrue(ptool._is_string(ustr, 'UTF-8'))
- if not inPy3k:
- self.assertFalse(ptool._is_string("foo" + chr(128) + "bar",
- 'ascii'))
- self.assertFalse(ptool._is_string(ustr, 'ascii'))
-
def test_get_data(self):
orig_entry = lxml.etree.Element("Path", name="/test", type="file")
Bcfg2.Options.setup.encoding = "ascii"
@@ -216,7 +200,8 @@ class TestPOSIXFile(TestPOSIXTool):
mock_unlink.assert_called_with(newfile)
@patch("%s.open" % builtins)
- def test__get_diffs(self, mock_open):
+ @patch("Bcfg2.Utils")
+ def test__get_diffs(self, mock_utils, mock_open):
orig_entry = lxml.etree.Element("Path", name="/test", type="file",
mode='0644', owner='root',
group='root')
@@ -226,16 +211,15 @@ class TestPOSIXFile(TestPOSIXTool):
ptool = self.get_obj()
ptool._get_data = Mock()
ptool._diff = Mock()
- ptool._is_string = Mock()
def reset():
- ptool._is_string.reset_mock()
+ mock_utils.is_string.reset_mock()
ptool._get_data.reset_mock()
ptool._diff.reset_mock()
mock_open.reset_mock()
return copy.deepcopy(orig_entry)
- ptool._is_string.return_value = True
+ mock_utils.is_string.return_value = True
ptool._get_data.return_value = (orig_entry.text, False)
mock_open.return_value.read.return_value = ondisk
ptool._diff.return_value = ["-test2", "+test"]
@@ -250,7 +234,7 @@ class TestPOSIXFile(TestPOSIXTool):
# binary data on disk
entry = reset()
- ptool._is_string.return_value = False
+ mock_utils.is_string.return_value = False
ptool._get_diffs(entry, content=ondisk)
self.assertFalse(mock_open.called)
self.assertFalse(ptool._diff.called)
@@ -258,7 +242,7 @@ class TestPOSIXFile(TestPOSIXTool):
# sensitive, non-interactive -- do nothing
entry = reset()
- ptool._is_string.return_value = True
+ mock_utils.is_string.return_value = True
ptool._get_diffs(entry, sensitive=True, interactive=False)
self.assertFalse(mock_open.called)
self.assertFalse(ptool._diff.called)
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py
index ea4ca3f5f..b137b0f0c 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py
@@ -194,11 +194,11 @@ class TestPOSIXTool(TestTool):
mock_lstat.assert_called_with(entry.get('name'))
ptool._remove.assert_called_with(entry)
- @patch("os.chown")
+ @patch("os.lchown")
@patch("os.chmod")
@patch("os.utime")
@patch("os.geteuid")
- def test_set_perms(self, mock_geteuid, mock_utime, mock_chmod, mock_chown):
+ def test_set_perms(self, mock_geteuid, mock_utime, mock_chmod, mock_lchown):
ptool = self.get_obj()
ptool._norm_entry_uid = Mock()
ptool._norm_entry_gid = Mock()
@@ -210,7 +210,7 @@ class TestPOSIXTool(TestTool):
ptool._norm_entry_gid.reset_mock()
ptool._norm_entry_uid.reset_mock()
mock_chmod.reset_mock()
- mock_chown.reset_mock()
+ mock_lchown.reset_mock()
mock_utime.reset_mock()
mock_geteuid.reset_mock()
@@ -235,7 +235,7 @@ class TestPOSIXTool(TestTool):
self.assertTrue(ptool._set_perms(entry))
ptool._norm_entry_uid.assert_called_with(entry)
ptool._norm_entry_gid.assert_called_with(entry)
- mock_chown.assert_called_with(entry.get("name"), 10, 100)
+ mock_lchown.assert_called_with(entry.get("name"), 10, 100)
mock_chmod.assert_called_with(entry.get("name"),
int(entry.get("mode"), 8))
self.assertFalse(mock_utime.called)
@@ -250,7 +250,7 @@ class TestPOSIXTool(TestTool):
self.assertTrue(ptool._set_perms(entry))
self.assertFalse(ptool._norm_entry_uid.called)
self.assertFalse(ptool._norm_entry_gid.called)
- self.assertFalse(mock_chown.called)
+ self.assertFalse(mock_lchown.called)
mock_chmod.assert_called_with(entry.get("name"),
int(entry.get("mode"), 8))
self.assertFalse(mock_utime.called)
@@ -265,7 +265,7 @@ class TestPOSIXTool(TestTool):
self.assertTrue(ptool._set_perms(entry))
ptool._norm_entry_uid.assert_called_with(entry)
ptool._norm_entry_gid.assert_called_with(entry)
- mock_chown.assert_called_with(entry.get("name"), 10, 100)
+ mock_lchown.assert_called_with(entry.get("name"), 10, 100)
mock_chmod.assert_called_with(entry.get("name"),
int(entry.get("mode"), 8))
mock_utime.assert_called_with(entry.get("name"), (mtime, mtime))
@@ -276,26 +276,26 @@ class TestPOSIXTool(TestTool):
self.assertTrue(ptool._set_perms(entry, path='/etc/bar'))
ptool._norm_entry_uid.assert_called_with(entry)
ptool._norm_entry_gid.assert_called_with(entry)
- mock_chown.assert_called_with('/etc/bar', 10, 100)
+ mock_lchown.assert_called_with('/etc/bar', 10, 100)
mock_chmod.assert_called_with('/etc/bar', int(entry.get("mode"), 8))
mock_utime.assert_called_with(entry.get("name"), (mtime, mtime))
ptool._set_secontext.assert_called_with(entry, path='/etc/bar')
ptool._set_acls.assert_called_with(entry, path='/etc/bar')
- # test dev_type modification of perms, failure of chown
+ # test dev_type modification of perms, failure of lchown
reset()
def chown_rv(path, owner, group):
if owner == 0 and group == 0:
return True
else:
raise KeyError
- os.chown.side_effect = chown_rv
+ os.lchown.side_effect = chown_rv
entry.set("type", "device")
entry.set("dev_type", list(device_map.keys())[0])
self.assertFalse(ptool._set_perms(entry))
ptool._norm_entry_uid.assert_called_with(entry)
ptool._norm_entry_gid.assert_called_with(entry)
- mock_chown.assert_called_with(entry.get("name"), 0, 0)
+ mock_lchown.assert_called_with(entry.get("name"), 0, 0)
mock_chmod.assert_called_with(entry.get("name"),
int(entry.get("mode"), 8) | list(device_map.values())[0])
mock_utime.assert_called_with(entry.get("name"), (mtime, mtime))
@@ -304,14 +304,14 @@ class TestPOSIXTool(TestTool):
# test failure of chmod
reset()
- os.chown.side_effect = None
+ os.lchown.side_effect = None
os.chmod.side_effect = OSError
entry.set("type", "file")
del entry.attrib["dev_type"]
self.assertFalse(ptool._set_perms(entry))
ptool._norm_entry_uid.assert_called_with(entry)
ptool._norm_entry_gid.assert_called_with(entry)
- mock_chown.assert_called_with(entry.get("name"), 10, 100)
+ mock_lchown.assert_called_with(entry.get("name"), 10, 100)
mock_chmod.assert_called_with(entry.get("name"),
int(entry.get("mode"), 8))
mock_utime.assert_called_with(entry.get("name"), (mtime, mtime))
@@ -322,14 +322,14 @@ class TestPOSIXTool(TestTool):
# e.g., when chmod fails, we still try to apply acls, set
# selinux context, etc.
reset()
- os.chown.side_effect = OSError
+ os.lchown.side_effect = OSError
os.utime.side_effect = OSError
ptool._set_acls.return_value = False
ptool._set_secontext.return_value = False
self.assertFalse(ptool._set_perms(entry))
ptool._norm_entry_uid.assert_called_with(entry)
ptool._norm_entry_gid.assert_called_with(entry)
- mock_chown.assert_called_with(entry.get("name"), 10, 100)
+ mock_lchown.assert_called_with(entry.get("name"), 10, 100)
mock_chmod.assert_called_with(entry.get("name"),
int(entry.get("mode"), 8))
mock_utime.assert_called_with(entry.get("name"), (mtime, mtime))
@@ -481,11 +481,16 @@ class TestPOSIXTool(TestTool):
@skipUnless(HAS_SELINUX, "SELinux not found, skipping")
@patchIf(HAS_SELINUX, "selinux.restorecon")
+ @patchIf(HAS_SELINUX, "selinux.lgetfilecon")
@patchIf(HAS_SELINUX, "selinux.lsetfilecon")
- def test_set_secontext(self, mock_lsetfilecon, mock_restorecon):
+ def test_set_secontext(self, mock_lsetfilecon, mock_lgetfilecon,
+ mock_restorecon):
+ Bcfg2.Options.setup.secontext_ignore = ['dosfs_t']
ptool = self.get_obj()
entry = lxml.etree.Element("Path", name="/etc/foo", type="file")
+ mock_lgetfilecon.return_value = (0, "system_u:object_r:foo_t")
+
# disable selinux for the initial test
Bcfg2.Client.Tools.POSIX.base.HAS_SELINUX = False
self.assertTrue(ptool._set_secontext(entry))
@@ -495,29 +500,46 @@ class TestPOSIXTool(TestTool):
self.assertTrue(ptool._set_secontext(entry))
self.assertFalse(mock_restorecon.called)
self.assertFalse(mock_lsetfilecon.called)
+ self.assertFalse(mock_lgetfilecon.called)
mock_restorecon.reset_mock()
mock_lsetfilecon.reset_mock()
+ mock_lgetfilecon.reset_mock()
entry.set("secontext", "__default__")
self.assertTrue(ptool._set_secontext(entry))
mock_restorecon.assert_called_with(entry.get("name"))
+ mock_lgetfilecon.assert_called_once_with(entry.get("name"))
self.assertFalse(mock_lsetfilecon.called)
mock_restorecon.reset_mock()
mock_lsetfilecon.reset_mock()
+ mock_lgetfilecon.reset_mock()
mock_lsetfilecon.return_value = 0
entry.set("secontext", "foo_t")
self.assertTrue(ptool._set_secontext(entry))
self.assertFalse(mock_restorecon.called)
+ mock_lgetfilecon.assert_called_once_with(entry.get("name"))
mock_lsetfilecon.assert_called_with(entry.get("name"), "foo_t")
mock_restorecon.reset_mock()
mock_lsetfilecon.reset_mock()
+ mock_lgetfilecon.reset_mock()
mock_lsetfilecon.return_value = 1
self.assertFalse(ptool._set_secontext(entry))
self.assertFalse(mock_restorecon.called)
+ mock_lgetfilecon.assert_called_once_with(entry.get("name"))
mock_lsetfilecon.assert_called_with(entry.get("name"), "foo_t")
+ # ignored filesystem
+ mock_restorecon.reset_mock()
+ mock_lsetfilecon.reset_mock()
+ mock_lgetfilecon.reset_mock()
+ mock_lgetfilecon.return_value = (0, "system_u:object_r:dosfs_t")
+ self.assertTrue(ptool._set_secontext(entry))
+ self.assertFalse(mock_restorecon.called)
+ self.assertFalse(mock_lsetfilecon.called)
+ mock_lgetfilecon.assert_called_once_with(entry.get("name"))
+
@patch("grp.getgrnam")
def test_norm_gid(self, mock_getgrnam):
ptool = self.get_obj()
@@ -686,7 +708,7 @@ class TestPOSIXTool(TestTool):
ptool._gather_data = Mock()
entry = lxml.etree.Element("Path", name="/test", type="file",
group="group", owner="user", mode="664",
- secontext='etc_t')
+ secontext='unconfined_u:object_r:etc_t:s0')
# _verify_metadata() mutates the entry, so we keep a backup so we
# can start fresh every time
orig_entry = copy.deepcopy(entry)
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
index cc1ea6fd7..08c20981d 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
@@ -103,26 +103,26 @@ class TestPOSIXUsers(TestTool):
# test failure of inherited method
entry = lxml.etree.Element("POSIXUser", name="test")
self.assertFalse(users.canInstall(entry))
- mock_canInstall.assertCalledWith(users, entry)
+ mock_canInstall.assert_called_with(users, entry)
# test with no uid specified
reset()
mock_canInstall.return_value = True
self.assertTrue(users.canInstall(entry))
- mock_canInstall.assertCalledWith(users, entry)
+ mock_canInstall.assert_called_with(users, entry)
# test with uid specified, not in managed range
reset()
entry.set("uid", "1000")
self.assertFalse(users.canInstall(entry))
- mock_canInstall.assertCalledWith(users, entry)
+ mock_canInstall.assert_called_with(users, entry)
users._in_managed_range.assert_called_with(entry.tag, "1000")
# test with uid specified, in managed range
reset()
users._in_managed_range.return_value = True
self.assertTrue(users.canInstall(entry))
- mock_canInstall.assertCalledWith(users, entry)
+ mock_canInstall.assert_called_with(users, entry)
users._in_managed_range.assert_called_with(entry.tag, "1000")
@patch("Bcfg2.Client.Tools.Tool.Inventory")
diff --git a/testsuite/Testsrc/Testlib/TestOptions/TestComponents.py b/testsuite/Testsrc/Testlib/TestOptions/TestComponents.py
index 61b87de2a..b1ed4cb2b 100644
--- a/testsuite/Testsrc/Testlib/TestOptions/TestComponents.py
+++ b/testsuite/Testsrc/Testlib/TestOptions/TestComponents.py
@@ -182,7 +182,8 @@ class TestImportComponentOptions(OptionTestCase):
"""test cases for component loading."""
def setUp(self):
- self.options = [Option("--cls", action=ImportComponentAction),
+ self.options = [Option("--cls", cf=("config", "cls"),
+ action=ImportComponentAction),
Option("--module", action=ImportModuleAction)]
self.result = argparse.Namespace()
@@ -227,3 +228,10 @@ class TestImportComponentOptions(OptionTestCase):
self.assertRaises(SystemExit,
self.parser.parse,
["-C", config_file, "--cls", "Bcfg2.No.Such.Thing"])
+
+ @make_config({"config": {"test": "foo", "cls": "Two"}})
+ def test_default_from_config_for_component_options(self, config_file):
+ """use default value from config file for options added by dynamic loaded component."""
+ self.parser.parse(["-C", config_file])
+ self.assertEqual(self.result.cls, Two.Two)
+ self.assertEqual(self.result.test, "foo")
diff --git a/testsuite/Testsrc/Testlib/TestOptions/TestConfigFiles.py b/testsuite/Testsrc/Testlib/TestOptions/TestConfigFiles.py
index 78acadf1f..4277c8efe 100644
--- a/testsuite/Testsrc/Testlib/TestOptions/TestConfigFiles.py
+++ b/testsuite/Testsrc/Testlib/TestOptions/TestConfigFiles.py
@@ -45,6 +45,10 @@ class TestConfigFiles(OptionTestCase):
inner1()
@mock.patch("os.path.exists", mock.Mock(return_value=False))
- def test_no_config_file(self):
+ @make_config()
+ def test_no_config_file(self, config):
"""fail to read config file."""
- self.assertRaises(SystemExit, self.parser.parse, [])
+ try:
+ self.parser.parse(['-C', config])
+ except SystemExit:
+ self.fail('Missing config file should not raise SystemExit')
diff --git a/testsuite/Testsrc/Testlib/TestOptions/TestTypes.py b/testsuite/Testsrc/Testlib/TestOptions/TestTypes.py
index 404d67fdc..0b67db38a 100644
--- a/testsuite/Testsrc/Testlib/TestOptions/TestTypes.py
+++ b/testsuite/Testsrc/Testlib/TestOptions/TestTypes.py
@@ -46,21 +46,23 @@ class TestOptionTypes(Bcfg2TestCase):
self.assertItemsEqual(self._test_options(["--test", "one:two three"]),
["one", "two three"])
- def test_comma_dict(self):
- """parse comma-dict values."""
- self.options = [Option("--test", type=Types.comma_dict)]
+ def test_literal_dict(self):
+ """parse literal-dict values."""
+ self.options = [Option("--test", type=Types.literal_dict)]
expected = {
"one": True,
"two": 2,
"three": "three",
- "four": False}
+ "four": False,
+ "five": {
+ "a": 1,
+ "b": 2
+ }}
self.assertDictEqual(
self._test_options(["--test",
- "one=yes, two=2 , three=three,four=no"]),
- expected)
-
- self.assertDictEqual(
- self._test_options(["--test", "one,two=2,three=three,four=off"]),
+ '''{ "one": True, "two": 2,
+ "three": "three", "four": False,
+ "five": { "a": 1, "b": 2 }}''']),
expected)
def test_anchored_regex_list(self):
diff --git a/testsuite/Testsrc/Testlib/TestOptions/Two.py b/testsuite/Testsrc/Testlib/TestOptions/Two.py
index 189e0817f..0120e8b77 100644
--- a/testsuite/Testsrc/Testlib/TestOptions/Two.py
+++ b/testsuite/Testsrc/Testlib/TestOptions/Two.py
@@ -1,6 +1,7 @@
"""Test module for component loading."""
+from Bcfg2.Options import Option
class Two(object):
"""Test class for component loading."""
- pass
+ options = [Option('--test', cf=("config", "test"), dest="test", default="bar")]
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py
index 5a82100d0..9f6a9f320 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py
@@ -51,6 +51,7 @@ class TestFunctions(Bcfg2TestCase):
class TestDatabaseBacked(TestPlugin):
test_obj = DatabaseBacked
+ synced = False
def setUp(self):
TestPlugin.setUp(self)
@@ -76,6 +77,15 @@ class TestDatabaseBacked(TestPlugin):
setattr(Bcfg2.Options.setup, attr, True)
self.assertRaises(PluginInitError, self.get_obj, core)
+ def syncdb(self, modeltest):
+ """ Given an instance of a :class:`DBModelTestCase` object, sync
+ and clean the database """
+ inst = modeltest(methodName='test_syncdb')
+ if not self.__class__.synced:
+ inst.test_syncdb()
+ self.__class__.synced = True
+ inst.test_cleandb()
+
class TestPluginDatabaseModel(Bcfg2TestCase):
""" placeholder for future tests """
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py
index 1bf208c3e..5a8c44cd5 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestBundler.py
@@ -98,7 +98,7 @@ class TestBundler(TestPlugin, TestStructure, TestXMLDirectoryBacked):
lxml.etree.SubElement(expected['indep'], "Service", name="baz")
metadata = Mock()
- metadata.bundles = ["error", "xinclude", "has_dep", "indep"]
+ metadata.bundles = set(["error", "xinclude", "has_dep", "indep"])
metadata.version_info = Bcfg2VersionInfo('1.4.0')
rv = b.BuildStructures(metadata)
@@ -131,7 +131,7 @@ class TestBundler(TestPlugin, TestStructure, TestXMLDirectoryBacked):
lxml.etree.SubElement(expected['has_dep'], "Package", name="foo")
metadata = Mock()
- metadata.bundles = ["has_dep"]
+ metadata.bundles = set(["has_dep"])
metadata.version_info = Bcfg2VersionInfo('1.3.0')
rv = b.BuildStructures(metadata)
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py
index 9b4a6af88..3c660099e 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py
@@ -22,6 +22,10 @@ from Testinterfaces import TestGoalValidator
class TestDefaults(TestRules, TestGoalValidator):
test_obj = Defaults
+ def setUp(self):
+ TestRules.setUp(self)
+ set_setup_default("defaults_replace_name", True)
+
def get_obj(self, *args, **kwargs):
return TestRules.get_obj(self, *args, **kwargs)
@@ -91,3 +95,8 @@ class TestDefaults(TestRules, TestGoalValidator):
def test_regex(self):
self._do_test('regex')
+
+ def test_replace_name(self):
+ Bcfg2.Options.setup.defaults_replace_name = True
+ self._do_test('replace_name')
+ Bcfg2.Options.setup.defaults_replace_name = False
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py
index f2721c9ea..8b9a631c1 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py
@@ -123,7 +123,7 @@ class TestClientVersions(TestDatabaseBacked):
def setUp(self):
TestDatabaseBacked.setUp(self)
self.test_obj = ClientVersions
- syncdb(TestMetadataDB)
+ self.syncdb(TestMetadataDB)
for client, version in self.test_clients.items():
MetadataClientModel(hostname=client, version=version).save()
@@ -302,8 +302,7 @@ class TestXMLMetadataConfig(TestXMLFileBacked):
self.assertIsNotNone(config.basedata)
reset()
- mock_parse.side_effect = lxml.etree.XMLSyntaxError(None, None, None,
- None)
+ mock_parse.side_effect = lxml.etree.XMLSyntaxError(None, 0, 0, 0)
config.load_xml()
mock_parse.assert_called_with(os.path.join(config.basedir,
"clients.xml"),
@@ -1252,7 +1251,7 @@ class TestMetadataBase(TestMetadata):
TestClientRunHooks.setUp(self)
TestDatabaseBacked.setUp(self)
Bcfg2.Options.setup.metadata_db = True
- syncdb(TestMetadataDB)
+ self.syncdb(TestMetadataDB)
def load_clients_data(self, metadata=None, xdata=None):
if metadata is None:
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py
index 32766b5c1..9729a0449 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py
@@ -201,7 +201,7 @@ group-specific"""
assert False, "Strange probe found in get_probe_data() return"
-class TestProbes(TestPlugin):
+class TestProbes(TestDatabaseBacked):
test_obj = Probes
test_xdata = lxml.etree.Element("test")
@@ -241,7 +241,7 @@ group: group:with:colons
self.datastore = None
Bcfg2.Options.setup.repository = datastore
- def get_obj(self):
+ def get_obj(self, core=None):
if not Bcfg2.Options.setup.probes_db:
# actually use a real datastore so we can read and write
# probed.xml
@@ -251,7 +251,7 @@ group: group:with:colons
datadir = os.path.join(self.datastore, self.test_obj.name)
if not os.path.exists(datadir):
os.makedirs(datadir)
- return TestPlugin.get_obj(self)
+ return TestPlugin.get_obj(self, core)
def test__init(self):
if Bcfg2.Options.setup.probes_db:
@@ -278,7 +278,7 @@ group: group:with:colons
def test_probes_db(self):
""" Set and retrieve probe data with database enabled """
Bcfg2.Options.setup.probes_db = True
- syncdb(TestProbesDB)
+ self.syncdb(TestProbesDB)
self._perform_tests()
def test_allowed_cgroups(self):
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py
index 36baee899..8c7f3c5d7 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py
@@ -29,11 +29,14 @@ class TestPropertyFile(Bcfg2TestCase):
test_obj = PropertyFile
path = os.path.join(datastore, "test")
- def get_obj(self, path=None):
+ def get_obj(self, path=None, core=None, *args, **kwargs):
set_setup_default("writes_enabled", False)
if path is None:
path = self.path
- return self.test_obj(path)
+ if core is None:
+ core = Mock()
+ core.metadata_cache_mode = 'none'
+ return self.test_obj(path, core, *args, **kwargs)
def test_write(self):
pf = self.get_obj()
@@ -97,6 +100,9 @@ class TestJSONPropertyFile(TestFileBacked, TestPropertyFile):
TestFileBacked.setUp(self)
TestPropertyFile.setUp(self)
+ def get_obj(self, *args, **kwargs):
+ return TestPropertyFile.get_obj(self, *args, **kwargs)
+
@patch("%s.loads" % JSON)
def test_Index(self, mock_loads):
pf = self.get_obj()
@@ -137,6 +143,9 @@ class TestYAMLPropertyFile(TestFileBacked, TestPropertyFile):
TestFileBacked.setUp(self)
TestPropertyFile.setUp(self)
+ def get_obj(self, *args, **kwargs):
+ return TestPropertyFile.get_obj(self, *args, **kwargs)
+
@patch("yaml.load")
def test_Index(self, mock_load):
pf = self.get_obj()
@@ -179,7 +188,7 @@ class TestXMLPropertyFile(TestPropertyFile, TestStructFile):
set_setup_default("automatch", False)
def get_obj(self, *args, **kwargs):
- return TestStructFile.get_obj(self, *args, **kwargs)
+ return TestPropertyFile.get_obj(self, *args, **kwargs)
@patch("%s.open" % builtins)
def test__write(self, mock_open):
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestRules.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestRules.py
index 45f3671e8..88b334edf 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestRules.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestRules.py
@@ -32,6 +32,7 @@ class TestRules(TestPrioDir):
group=lxml.etree.Element("SEPort", name="6789/tcp"),
children=lxml.etree.Element("Path", name="/etc/child-entries"),
regex=lxml.etree.Element("Package", name="regex"),
+ replace_name=lxml.etree.Element("POSIXUser", name="regex"),
slash=lxml.etree.Element("Path", name="/etc/trailing/slash"),
no_slash=lxml.etree.Element("Path", name="/etc/no/trailing/slash/"))
@@ -53,6 +54,8 @@ class TestRules(TestPrioDir):
group="root", mode="0775"),
regex=lxml.etree.Element("Package", name="regex", type="yum",
version="any"),
+ replace_name=lxml.etree.Element("POSIXUser", name="regex",
+ home="/foobar%{bar}/regex"),
slash=lxml.etree.Element("Path", name="/etc/trailing/slash",
type="directory", owner="root", group="root",
mode="0600"),
@@ -70,6 +73,8 @@ class TestRules(TestPrioDir):
in_file = copy.deepcopy(concrete)
in_file['regex'].set("name", ".*")
+ in_file['replace_name'].set("home", "/foobar%{bar}/%{name}")
+ in_file['replace_name'].set("name", ".*")
in_file['slash'].set("name", "/etc/trailing/slash/")
in_file['no_slash'].set("name", "/etc/no/trailing/slash")
@@ -91,6 +96,7 @@ class TestRules(TestPrioDir):
rules3 = lxml.etree.Element("Rules", priority="10")
rules3.append(in_file['duplicate'])
rules3.append(in_file['regex'])
+ rules3.append(in_file['replace_name'])
rules3.append(in_file['slash'])
rules = {"rules1.xml": rules1, "rules2.xml": rules2, "rules3.xml": rules3}
@@ -99,6 +105,7 @@ class TestRules(TestPrioDir):
TestPrioDir.setUp(self)
set_setup_default("lax_decryption", True)
set_setup_default("rules_regex", False)
+ set_setup_default("rules_replace_name", False)
def get_child(self, name):
""" Turn one of the XML documents in `rules` into a child
@@ -169,6 +176,17 @@ class TestRules(TestPrioDir):
self._do_test('regex')
Bcfg2.Options.setup.rules_regex = False
+ def test_replace_name(self):
+ """ Test that Rules handles replaces name in attribues with regular expressions """
+ Bcfg2.Options.setup.rules_regex = False
+ Bcfg2.Options.setup.rules_replace_name = False
+ self._do_test_failure('replace_name', handles=False)
+ Bcfg2.Options.setup.rules_regex = True
+ Bcfg2.Options.setup.rules_replace_name = True
+ self._do_test('replace_name')
+ Bcfg2.Options.setup.rules_regex = False
+ Bcfg2.Options.setup.rules_replace_name = False
+
def test_slash(self):
""" Test that Rules handles trailing slashes on Path entries """
self._do_test('slash')
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py
index 128d6cae5..a470dca67 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py
@@ -2,6 +2,7 @@ import os
import sys
import Bcfg2.Server.Plugin
from mock import Mock, MagicMock, patch
+from Bcfg2.Utils import safe_module_name
from Bcfg2.Server.Plugins.TemplateHelper import *
# add all parent testsuite directories to sys.path to allow (most)
@@ -22,10 +23,13 @@ class TestHelperModule(Bcfg2TestCase):
test_obj = HelperModule
path = os.path.join(datastore, "test.py")
- def get_obj(self, path=None):
+ def get_obj(self, path=None, core=None):
if path is None:
path = self.path
- return self.test_obj(path)
+ if core is None:
+ core = Mock()
+ core.metadata_cache_mode = 'none'
+ return self.test_obj(path, core)
def test__init(self):
hm = self.get_obj()
@@ -39,8 +43,9 @@ class TestHelperModule(Bcfg2TestCase):
mock_load_source.side_effect = ImportError
attrs = dir(hm)
hm.HandleEvent()
- mock_load_source.assert_called_with(safe_module_name(hm._module_name),
- hm.name)
+ mock_load_source.assert_called_with(
+ safe_module_name('TemplateHelper', hm._module_name),
+ hm.name)
self.assertEqual(attrs, dir(hm))
self.assertEqual(hm._attrs, [])
@@ -51,8 +56,9 @@ class TestHelperModule(Bcfg2TestCase):
mock_load_source.return_value = Mock()
attrs = dir(hm)
hm.HandleEvent()
- mock_load_source.assert_called_with(safe_module_name(hm._module_name),
- hm.name)
+ mock_load_source.assert_called_with(
+ safe_module_name('TemplateHelper', hm._module_name),
+ hm.name)
self.assertEqual(attrs, dir(hm))
self.assertEqual(hm._attrs, [])
@@ -63,8 +69,9 @@ class TestHelperModule(Bcfg2TestCase):
mock_load_source.return_value = module
attrs = dir(hm)
hm.HandleEvent()
- mock_load_source.assert_called_with(safe_module_name(hm._module_name),
- hm.name)
+ mock_load_source.assert_called_with(
+ safe_module_name('TemplateHelper', hm._module_name),
+ hm.name)
self.assertEqual(attrs, dir(hm))
self.assertEqual(hm._attrs, [])
@@ -74,8 +81,9 @@ class TestHelperModule(Bcfg2TestCase):
mock_load_source.reset()
mock_load_source.return_value = module
hm.HandleEvent()
- mock_load_source.assert_called_with(safe_module_name(hm._module_name),
- hm.name)
+ mock_load_source.assert_called_with(
+ safe_module_name('TemplateHelper', hm._module_name),
+ hm.name)
self.assertTrue(hasattr(hm, "foo"))
self.assertTrue(hasattr(hm, "bar"))
self.assertTrue(hasattr(hm, "baz"))
@@ -87,8 +95,9 @@ class TestHelperModule(Bcfg2TestCase):
mock_load_source.reset()
mock_load_source.return_value = module
hm.HandleEvent()
- mock_load_source.assert_called_with(safe_module_name(hm._module_name),
- hm.name)
+ mock_load_source.assert_called_with(
+ safe_module_name('TemplateHelper', hm._module_name),
+ hm.name)
self.assertTrue(hasattr(hm, "foo"))
self.assertTrue(hasattr(hm, "bar"))
self.assertTrue(hasattr(hm, "quux"))
diff --git a/testsuite/Testsrc/Testlib/TestUtils.py b/testsuite/Testsrc/Testlib/TestUtils.py
index 4bed67248..a37f2ecbe 100644
--- a/testsuite/Testsrc/Testlib/TestUtils.py
+++ b/testsuite/Testsrc/Testlib/TestUtils.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
import os
import sys
from Bcfg2.Utils import *
@@ -42,3 +43,17 @@ class TestPackedDigitRange(Bcfg2TestCase):
for test in exc:
self.assertNotIn(test, rng)
self.assertFalse(rng.includes(test))
+
+
+class TestIsString(Bcfg2TestCase):
+ def test_is_string(self):
+ for char in list(range(8)) + list(range(14, 32)):
+ self.assertFalse(is_string("foo" + chr(char) + "bar", 'UTF-8'))
+ for char in list(range(9, 14)) + list(range(33, 128)):
+ self.assertTrue(is_string("foo" + chr(char) + "bar", 'UTF-8'))
+
+ ustr = 'é'
+ self.assertTrue(is_string(ustr, 'UTF-8'))
+ if not inPy3k:
+ self.assertFalse(is_string("foo" + chr(128) + "bar", 'ascii'))
+ self.assertFalse(is_string(ustr, 'ascii'))