summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2014-04-16 10:16:29 -0500
committerSol Jerome <sol.jerome@gmail.com>2014-04-16 10:16:29 -0500
commitd510e918e41b7b2b7b0b9351a40eab2794b49c83 (patch)
tree250715ab112c10612ee131925ad07b68591c09f3 /testsuite
parent9ebdcdb2f7718ae9203b20dafea4bca9f310ed75 (diff)
parent24a261f842a4bc1d4dc125fad0f43343d5d4c9d8 (diff)
downloadbcfg2-d510e918e41b7b2b7b0b9351a40eab2794b49c83.tar.gz
bcfg2-d510e918e41b7b2b7b0b9351a40eab2794b49c83.tar.bz2
bcfg2-d510e918e41b7b2b7b0b9351a40eab2794b49c83.zip
Merge branch 'maint' into master
Signed-off-by: Sol Jerome <sol.jerome@gmail.com> Conflicts: doc/appendix/guides/import-existing-ssh-keys.txt misc/bcfg2.spec src/lib/Bcfg2/Client/Tools/VCS.py src/lib/Bcfg2/Client/Tools/YUM.py src/lib/Bcfg2/Encryption.py src/lib/Bcfg2/Reporting/Collector.py src/lib/Bcfg2/Reporting/Storage/DjangoORM.py src/lib/Bcfg2/Server/Core.py src/lib/Bcfg2/Server/FileMonitor/__init__.py src/lib/Bcfg2/Server/Lint/RequiredAttrs.py src/lib/Bcfg2/Server/Plugin/helpers.py src/lib/Bcfg2/Server/Plugins/Metadata.py src/lib/Bcfg2/Server/Plugins/Packages/Yum.py src/lib/Bcfg2/Server/Plugins/Packages/__init__.py src/lib/Bcfg2/settings.py src/sbin/bcfg2-crypt src/sbin/bcfg2-reports src/sbin/bcfg2-yum-helper testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py397
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py50
-rw-r--r--testsuite/pylintrc.conf11
3 files changed, 237 insertions, 221 deletions
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
index 74ca617af..b8534f5a8 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
@@ -48,203 +48,200 @@ test_data = """<Test>
test_xdata = lxml.etree.XML(test_data)
-class TestPOSIXAugeas(TestPOSIXTool):
- test_obj = POSIXAugeas
-
- applied_commands = dict(
- insert=lxml.etree.Element(
- "Insert", label="Thing",
- path='Test/Children[#attribute/identical = "true"]/Thing'),
- set=lxml.etree.Element("Set", path="Test/Text/#text",
- value="content with spaces"),
- move=lxml.etree.Element(
- "Move", source="Test/Foo",
- destination='Test/Children[#attribute/identical = "false"]/Foo'),
- remove=lxml.etree.Element("Remove", path="Test/Bar"),
- clear=lxml.etree.Element("Clear", path="Test/Empty/#text"),
- setm=lxml.etree.Element(
- "SetMulti", sub="#text", value="same",
- base='Test/Children[#attribute/multi = "true"]/Thing'))
-
- @skipUnless(HAS_AUGEAS, "Python Augeas libraries not found")
- def setUp(self):
- TestPOSIXTool.setUp(self)
- fd, self.tmpfile = tempfile.mkstemp()
- os.fdopen(fd, 'w').write(test_data)
-
- def tearDown(self):
- tmpfile = getattr(self, "tmpfile", None)
- if tmpfile:
- os.unlink(tmpfile)
-
- def test_fully_specified(self):
- ptool = self.get_obj()
-
- entry = lxml.etree.Element("Path", name="/test", type="augeas")
- self.assertFalse(ptool.fully_specified(entry))
-
- entry.text = "text"
- self.assertTrue(ptool.fully_specified(entry))
-
- def test_install(self):
- # this is tested adequately by the other tests
- pass
-
- def test_verify(self):
- # this is tested adequately by the other tests
- pass
-
- @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.verify")
- def _verify(self, commands, mock_verify):
- ptool = self.get_obj()
- mock_verify.return_value = True
-
- entry = lxml.etree.Element("Path", name=self.tmpfile,
- type="augeas", lens="Xml")
- entry.extend(commands)
-
- modlist = []
- self.assertTrue(ptool.verify(entry, modlist))
- mock_verify.assert_called_with(ptool, entry, modlist)
- self.assertXMLEqual(lxml.etree.parse(self.tmpfile).getroot(),
- test_xdata)
-
- def test_verify_insert(self):
- """ Test successfully verifying an Insert command """
- self._verify([self.applied_commands['insert']])
-
- def test_verify_set(self):
- """ Test successfully verifying a Set command """
- self._verify([self.applied_commands['set']])
-
- def test_verify_move(self):
- """ Test successfully verifying a Move command """
- self._verify([self.applied_commands['move']])
-
- def test_verify_remove(self):
- """ Test successfully verifying a Remove command """
- self._verify([self.applied_commands['remove']])
-
- def test_verify_clear(self):
- """ Test successfully verifying a Clear command """
- self._verify([self.applied_commands['clear']])
-
- def test_verify_set_multi(self):
- """ Test successfully verifying a SetMulti command """
- self._verify([self.applied_commands['setm']])
-
- def test_verify_all(self):
- """ Test successfully verifying multiple commands """
- self._verify(self.applied_commands.values())
-
- @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.install")
- def _install(self, commands, expected, mock_install):
- ptool = self.get_obj()
- mock_install.return_value = True
-
- entry = lxml.etree.Element("Path", name=self.tmpfile,
- type="augeas", lens="Xml")
- entry.extend(commands)
-
- self.assertTrue(ptool.install(entry))
- mock_install.assert_called_with(ptool, entry)
- self.assertXMLEqual(lxml.etree.parse(self.tmpfile).getroot(),
- expected)
-
- def test_install_set_existing(self):
- """ Test setting the value of an existing node """
- expected = copy.deepcopy(test_xdata)
- expected.find("Text").text = "Changed content"
- self._install([lxml.etree.Element("Set", path="Test/Text/#text",
- value="Changed content",
- verified="false")],
- expected)
-
- def test_install_set_new(self):
- """ Test setting the value of an new node """
- expected = copy.deepcopy(test_xdata)
- newtext = lxml.etree.SubElement(expected, "NewText")
- newtext.text = "new content"
- self._install([lxml.etree.Element("Set", path="Test/NewText/#text",
- value="new content",
- verified="false")],
- expected)
-
- def test_install_only_verified(self):
- """ Test that only unverified commands are installed """
- expected = copy.deepcopy(test_xdata)
- newtext = lxml.etree.SubElement(expected, "NewText")
- newtext.text = "new content"
- self._install(
- [lxml.etree.Element("Set", path="Test/NewText/#text",
- value="new content", verified="false"),
- lxml.etree.Element("Set", path="Test/Bogus/#text",
- value="bogus", verified="true")],
- expected)
-
- def test_install_remove(self):
- """ Test removing a node """
- expected = copy.deepcopy(test_xdata)
- expected.remove(expected.find("Attrs"))
- self._install(
- [lxml.etree.Element("Remove",
- path='Test/*[#attribute/foo = "foo"]',
- verified="false")],
- expected)
-
- def test_install_move(self):
- """ Test moving a node """
- expected = copy.deepcopy(test_xdata)
- foo = expected.xpath("//Foo")[0]
- expected.append(foo)
- self._install(
- [lxml.etree.Element("Move", source='Test/Children/Foo',
- destination='Test/Foo',
- verified="false")],
- expected)
-
- def test_install_clear(self):
- """ Test clearing a node """
- # TODO: clearing a node doesn't seem to work with the XML lens
- #
- # % augtool -b
- # augtool> set /augeas/load/Xml/incl[3] "/tmp/test.xml"
- # augtool> load
- # augtool> clear '/files/tmp/test.xml/Test/Text/#text'
- # augtool> save
- # error: Failed to execute command
- # saving failed (run 'print /augeas//error' for details)
- # augtool> print /augeas//error
- #
- # The error isn't useful.
- pass
-
- def test_install_set_multi(self):
- """ Test setting multiple nodes at once """
- expected = copy.deepcopy(test_xdata)
- for thing in expected.xpath("Children[@identical='true']/Thing"):
- thing.text = "same"
- self._install(
- [lxml.etree.Element(
- "SetMulti", value="same",
- base='Test/Children[#attribute/identical = "true"]',
- sub="Thing/#text", verified="false")],
- expected)
-
- def test_install_insert(self):
- """ Test inserting a node """
- expected = copy.deepcopy(test_xdata)
- children = expected.xpath("Children[@identical='true']")[0]
- thing = lxml.etree.Element("Thing")
- thing.text = "three"
- children.append(thing)
- self._install(
- [lxml.etree.Element(
- "Insert",
- path='Test/Children[#attribute/identical = "true"]/Thing[2]',
- label="Thing", where="after", verified="false"),
- lxml.etree.Element(
- "Set",
- path='Test/Children[#attribute/identical = "true"]/Thing[3]/#text',
- value="three", verified="false")],
- expected)
+if can_skip or HAS_AUGEAS:
+ class TestPOSIXAugeas(TestPOSIXTool):
+ test_obj = POSIXAugeas
+
+ applied_commands = dict(
+ insert=lxml.etree.Element(
+ "Insert", label="Thing",
+ path='Test/Children[#attribute/identical = "true"]/Thing'),
+ set=lxml.etree.Element("Set", path="Test/Text/#text",
+ value="content with spaces"),
+ move=lxml.etree.Element(
+ "Move", source="Test/Foo",
+ destination='Test/Children[#attribute/identical = "false"]/Foo'),
+ remove=lxml.etree.Element("Remove", path="Test/Bar"),
+ clear=lxml.etree.Element("Clear", path="Test/Empty/#text"),
+ setm=lxml.etree.Element(
+ "SetMulti", sub="#text", value="same",
+ base='Test/Children[#attribute/multi = "true"]/Thing'))
+
+ @skipUnless(HAS_AUGEAS, "Python Augeas libraries not found")
+ def setUp(self):
+ fd, self.tmpfile = tempfile.mkstemp()
+ os.fdopen(fd, 'w').write(test_data)
+
+ def tearDown(self):
+ tmpfile = getattr(self, "tmpfile", None)
+ if tmpfile and os.path.exists(tmpfile):
+ os.unlink(tmpfile)
+
+ def test_fully_specified(self):
+ ptool = self.get_obj()
+
+ entry = lxml.etree.Element("Path", name="/test", type="augeas")
+ self.assertFalse(ptool.fully_specified(entry))
+
+ lxml.etree.SubElement(entry, "Set", path="/test", value="test")
+ self.assertTrue(ptool.fully_specified(entry))
+
+ def test_install(self):
+ # this is tested adequately by the other tests
+ pass
+
+ def test_verify(self):
+ # this is tested adequately by the other tests
+ pass
+
+ @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.verify")
+ def _verify(self, commands, mock_verify):
+ ptool = self.get_obj()
+ mock_verify.return_value = True
+
+ entry = lxml.etree.Element("Path", name=self.tmpfile,
+ type="augeas", lens="Xml")
+ entry.extend(commands)
+
+ modlist = []
+ self.assertTrue(ptool.verify(entry, modlist))
+ mock_verify.assert_called_with(ptool, entry, modlist)
+ self.assertXMLEqual(lxml.etree.parse(self.tmpfile).getroot(),
+ test_xdata)
+
+ def test_verify_insert(self):
+ """ Test successfully verifying an Insert command """
+ self._verify([self.applied_commands['insert']])
+
+ def test_verify_set(self):
+ """ Test successfully verifying a Set command """
+ self._verify([self.applied_commands['set']])
+
+ def test_verify_move(self):
+ """ Test successfully verifying a Move command """
+ self._verify([self.applied_commands['move']])
+
+ def test_verify_remove(self):
+ """ Test successfully verifying a Remove command """
+ self._verify([self.applied_commands['remove']])
+
+ def test_verify_clear(self):
+ """ Test successfully verifying a Clear command """
+ self._verify([self.applied_commands['clear']])
+
+ def test_verify_set_multi(self):
+ """ Test successfully verifying a SetMulti command """
+ self._verify([self.applied_commands['setm']])
+
+ def test_verify_all(self):
+ """ Test successfully verifying multiple commands """
+ self._verify(self.applied_commands.values())
+
+ @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.install")
+ def _install(self, commands, expected, mock_install, **attrs):
+ ptool = self.get_obj()
+ mock_install.return_value = True
+
+ entry = lxml.etree.Element("Path", name=self.tmpfile,
+ type="augeas", lens="Xml")
+ for key, val in attrs.items():
+ entry.set(key, val)
+ entry.extend(commands)
+
+ self.assertTrue(ptool.install(entry))
+ mock_install.assert_called_with(ptool, entry)
+ self.assertXMLEqual(lxml.etree.parse(self.tmpfile).getroot(),
+ expected)
+
+ def test_install_set_existing(self):
+ """ Test setting the value of an existing node """
+ expected = copy.deepcopy(test_xdata)
+ expected.find("Text").text = "Changed content"
+ self._install([lxml.etree.Element("Set", path="Test/Text/#text",
+ value="Changed content")],
+ expected)
+
+ def test_install_set_new(self):
+ """ Test setting the value of an new node """
+ expected = copy.deepcopy(test_xdata)
+ newtext = lxml.etree.SubElement(expected, "NewText")
+ newtext.text = "new content"
+ self._install([lxml.etree.Element("Set", path="Test/NewText/#text",
+ value="new content")],
+ expected)
+
+ def test_install_remove(self):
+ """ Test removing a node """
+ expected = copy.deepcopy(test_xdata)
+ expected.remove(expected.find("Attrs"))
+ self._install(
+ [lxml.etree.Element("Remove",
+ path='Test/*[#attribute/foo = "foo"]')],
+ expected)
+
+ def test_install_move(self):
+ """ Test moving a node """
+ expected = copy.deepcopy(test_xdata)
+ foo = expected.xpath("//Foo")[0]
+ expected.append(foo)
+ self._install(
+ [lxml.etree.Element("Move", source='Test/Children/Foo',
+ destination='Test/Foo')],
+ expected)
+
+ def test_install_clear(self):
+ """ Test clearing a node """
+ # TODO: clearing a node doesn't seem to work with the XML lens
+ #
+ # % augtool -b
+ # augtool> set /augeas/load/Xml/incl[3] "/tmp/test.xml"
+ # augtool> load
+ # augtool> clear '/files/tmp/test.xml/Test/Text/#text'
+ # augtool> save
+ # error: Failed to execute command
+ # saving failed (run 'print /augeas//error' for details)
+ # augtool> print /augeas//error
+ #
+ # The error isn't useful.
+ pass
+
+ def test_install_set_multi(self):
+ """ Test setting multiple nodes at once """
+ expected = copy.deepcopy(test_xdata)
+ for thing in expected.xpath("Children[@identical='true']/Thing"):
+ thing.text = "same"
+ self._install(
+ [lxml.etree.Element(
+ "SetMulti", value="same",
+ base='Test/Children[#attribute/identical = "true"]',
+ sub="Thing/#text")],
+ expected)
+
+ def test_install_insert(self):
+ """ Test inserting a node """
+ expected = copy.deepcopy(test_xdata)
+ children = expected.xpath("Children[@identical='true']")[0]
+ thing = lxml.etree.Element("Thing")
+ thing.text = "three"
+ children.append(thing)
+ self._install(
+ [lxml.etree.Element(
+ "Insert",
+ path='Test/Children[#attribute/identical = "true"]/Thing[2]',
+ label="Thing", where="after"),
+ lxml.etree.Element(
+ "Set",
+ path='Test/Children[#attribute/identical = "true"]/Thing[3]/#text',
+ value="three")],
+ expected)
+
+ def test_install_initial(self):
+ """ Test creating initial content and then modifying it """
+ os.unlink(self.tmpfile)
+ expected = copy.deepcopy(test_xdata)
+ expected.find("Text").text = "Changed content"
+ initial = lxml.etree.Element("Initial")
+ initial.text = test_data
+ modify = lxml.etree.Element("Set", path="Test/Text/#text",
+ value="Changed content")
+ self._install([initial, modify], expected, current_exists="false")
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py
index 5a752b2ac..ea4ca3f5f 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py
@@ -586,16 +586,16 @@ class TestPOSIXTool(TestTool):
self.assertEqual(6, ptool._norm_acl_perms("rwa"))
self.assertEqual(4, ptool._norm_acl_perms("rr"))
- @patch('os.stat')
- def test__gather_data(self, mock_stat):
+ @patch('os.lstat')
+ def test__gather_data(self, mock_lstat):
ptool = self.get_obj()
path = '/test'
- mock_stat.side_effect = OSError
+ mock_lstat.side_effect = OSError
self.assertFalse(ptool._gather_data(path)[0])
- mock_stat.assert_called_with(path)
+ mock_lstat.assert_called_with(path)
- mock_stat.reset_mock()
- mock_stat.side_effect = None
+ mock_lstat.reset_mock()
+ mock_lstat.side_effect = None
# create a return value
stat_rv = MagicMock()
def stat_getitem(key):
@@ -608,7 +608,7 @@ class TestPOSIXTool(TestTool):
# and ensure that they're stripped
return int('060660', 8)
stat_rv.__getitem__ = Mock(side_effect=stat_getitem)
- mock_stat.return_value = stat_rv
+ mock_lstat.return_value = stat_rv
# disable selinux and acls for this call -- we test them
# separately so that we can skip those tests as appropriate
@@ -620,7 +620,7 @@ class TestPOSIXTool(TestTool):
(stat_rv, '0', '10', '0660', None, None))
Bcfg2.Client.Tools.POSIX.base.HAS_SELINUX, \
Bcfg2.Client.Tools.POSIX.base.HAS_ACLS = states
- mock_stat.assert_called_with(path)
+ mock_lstat.assert_called_with(path)
@skipUnless(HAS_SELINUX, "SELinux not found, skipping")
def test__gather_data_selinux(self):
@@ -628,12 +628,12 @@ class TestPOSIXTool(TestTool):
context = 'system_u:object_r:root_t:s0'
path = '/test'
- @patch('os.stat')
- @patchIf(HAS_SELINUX, "selinux.getfilecon")
- def inner(mock_getfilecon, mock_stat):
- mock_getfilecon.return_value = [len(context) + 1, context]
- mock_stat.return_value = MagicMock()
- mock_stat.return_value.__getitem__.return_value = MagicMock()
+ @patch('os.lstat')
+ @patchIf(HAS_SELINUX, "selinux.lgetfilecon")
+ def inner(mock_lgetfilecon, mock_lstat):
+ mock_lgetfilecon.return_value = [len(context) + 1, context]
+ mock_lstat.return_value = MagicMock()
+ mock_lstat.return_value.__getitem__.return_value = MagicMock()
# disable acls for this call and test them separately
state = (Bcfg2.Client.Tools.POSIX.base.HAS_ACLS,
Bcfg2.Client.Tools.POSIX.base.HAS_SELINUX)
@@ -642,30 +642,40 @@ class TestPOSIXTool(TestTool):
self.assertEqual(ptool._gather_data(path)[4], 'root_t')
Bcfg2.Client.Tools.POSIX.base.HAS_ACLS, \
Bcfg2.Client.Tools.POSIX.base.HAS_SELINUX = state
- mock_getfilecon.assert_called_with(path)
+ mock_lgetfilecon.assert_called_with(path)
inner()
@skipUnless(HAS_ACLS, "ACLS not found, skipping")
- @patch('os.stat')
- def test__gather_data_acls(self, mock_stat):
+ @patch('os.lstat')
+ @patch('stat.S_ISLNK')
+ def test__gather_data_acls(self, mock_S_ISLNK, mock_lstat):
ptool = self.get_obj()
ptool._list_file_acls = Mock()
acls = {("default", posix1e.ACL_USER, "testuser"): "rwx",
("access", posix1e.ACL_GROUP, "testgroup"): "rx"}
ptool._list_file_acls.return_value = acls
path = '/test'
- mock_stat.return_value = MagicMock()
- mock_stat.return_value.__getitem__.return_value = MagicMock()
+ mock_lstat.return_value = MagicMock()
+ mock_lstat.return_value.__getitem__.return_value = MagicMock()
+ mock_S_ISLNK.return_value = False
# disable selinux for this call and test it separately
state = (Bcfg2.Client.Tools.POSIX.base.HAS_ACLS,
Bcfg2.Client.Tools.POSIX.base.HAS_SELINUX)
Bcfg2.Client.Tools.POSIX.base.HAS_ACLS = True
Bcfg2.Client.Tools.POSIX.base.HAS_SELINUX = False
self.assertItemsEqual(ptool._gather_data(path)[5], acls)
+ ptool._list_file_acls.assert_called_with(path)
+
+ # symlinks can't have their own ACLs, so ensure that the
+ # _list_file_acls call is skipped and no ACLs are returned
+ mock_S_ISLNK.return_value = True
+ ptool._list_file_acls.reset_mock()
+ self.assertEqual(ptool._gather_data(path)[5], None)
+ self.assertFalse(ptool._list_file_acls.called)
+
Bcfg2.Client.Tools.POSIX.base.HAS_ACLS, \
Bcfg2.Client.Tools.POSIX.base.HAS_SELINUX = state
- ptool._list_file_acls.assert_called_with(path)
@patchIf(HAS_SELINUX, "selinux.matchpathcon")
def test_verify_metadata(self, mock_matchpathcon):
diff --git a/testsuite/pylintrc.conf b/testsuite/pylintrc.conf
index e13a51d0d..1d3ba8c88 100644
--- a/testsuite/pylintrc.conf
+++ b/testsuite/pylintrc.conf
@@ -99,6 +99,10 @@ evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / stateme
# evaluation report (RP0004).
comment=no
+# Template used to display messages. This is a python new-style format string
+# used to format the massage information. See doc for all details
+msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg}
+
[VARIABLES]
@@ -131,6 +135,9 @@ ignore-docstrings=yes
# Maximum number of characters on a single line.
max-line-length=79
+# Regexp for a line that is allowed to be longer than the limit.
+ignore-long-lines=^\s*(# )?(<?https?://\S+>?|:(func|class):.*)$
+
# Maximum number of lines in a module
max-module-lines=1000
@@ -247,8 +254,10 @@ max-locals=20
# Maximum number of return / yield for function / method body
max-returns=6
-# Maximum number of branch for function / method body
+# Maximum number of branch for function / method body (max-branchs is
+# pylint 0.x, max-branches is 1.0)
max-branchs=18
+max-branches=18
# Maximum number of statements in function / method body
max-statements=75