summaryrefslogtreecommitdiffstats
path: root/testsuite/Testsrc/Testlib/TestClient
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/Testsrc/Testlib/TestClient')
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py400
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py13
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py43
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py29
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py28
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py70
6 files changed, 290 insertions, 293 deletions
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
index 9b25499fe..74ca617af 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
@@ -48,203 +48,203 @@ test_data = """<Test>
test_xdata = lxml.etree.XML(test_data)
-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:
- 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)
+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)
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py
index 8f933e08f..31e297888 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py
@@ -55,8 +55,8 @@ class TestPOSIXFile(TestPOSIXTool):
def test_get_data(self):
orig_entry = lxml.etree.Element("Path", name="/test", type="file")
- ptool = self.get_obj(setup=dict(encoding="ascii", ppath='/',
- max_copies=5))
+ Bcfg2.Options.setup.encoding = "ascii"
+ ptool = self.get_obj()
entry = copy.deepcopy(orig_entry)
entry.text = b64encode("test")
@@ -91,8 +91,7 @@ class TestPOSIXFile(TestPOSIXTool):
@patch("Bcfg2.Client.Tools.POSIX.base.POSIXTool.verify")
def test_verify(self, mock_verify, mock_open):
entry = lxml.etree.Element("Path", name="/test", type="file")
- ptool = self.get_obj(setup=dict(interactive=False, ppath='/',
- max_copies=5))
+ ptool = self.get_obj()
ptool._exists = Mock()
ptool._get_data = Mock()
ptool._get_diffs = Mock()
@@ -223,8 +222,8 @@ class TestPOSIXFile(TestPOSIXTool):
group='root')
orig_entry.text = "test"
ondisk = "test2"
- ptool = self.get_obj(setup=dict(encoding="utf-8", ppath='/',
- max_copies=5))
+ Bcfg2.Options.setup.encoding = "utf-8"
+ ptool = self.get_obj()
ptool._get_data = Mock()
ptool._diff = Mock()
ptool._is_string = Mock()
@@ -312,7 +311,7 @@ class TestPOSIXFile(TestPOSIXTool):
# non-sensitive, interactive with unicode data
entry = reset()
entry.text = u("tëst")
- encoded = entry.text.encode(ptool.setup['encoding'])
+ encoded = entry.text.encode(Bcfg2.Options.setup.encoding)
ptool._diff.return_value = ["-test2", "+tëst"]
ptool._get_data.return_value = (encoded, False)
ptool._get_diffs(entry, interactive=True)
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py
index f01082e86..adc2032b7 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py
@@ -49,7 +49,6 @@ class TestPOSIX(TestTool):
mock_canVerify.assert_called_with(posix, entry)
# next, test fully_specified failure
- posix.logger.error.reset_mock()
mock_canVerify.reset_mock()
mock_canVerify.return_value = True
mock_fully_spec = Mock()
@@ -59,17 +58,14 @@ class TestPOSIX(TestTool):
self.assertFalse(posix.canVerify(entry))
mock_canVerify.assert_called_with(posix, entry)
mock_fully_spec.assert_called_with(entry)
- self.assertTrue(posix.logger.error.called)
# finally, test success
- posix.logger.error.reset_mock()
mock_canVerify.reset_mock()
mock_fully_spec.reset_mock()
mock_fully_spec.return_value = True
self.assertTrue(posix.canVerify(entry))
mock_canVerify.assert_called_with(posix, entry)
mock_fully_spec.assert_called_with(entry)
- self.assertFalse(posix.logger.error.called)
@patch("Bcfg2.Client.Tools.Tool.canInstall")
def test_canInstall(self, mock_canInstall):
@@ -82,7 +78,6 @@ class TestPOSIX(TestTool):
mock_canInstall.assert_called_with(posix, entry)
# next, test fully_specified failure
- posix.logger.error.reset_mock()
mock_canInstall.reset_mock()
mock_canInstall.return_value = True
mock_fully_spec = Mock()
@@ -92,17 +87,14 @@ class TestPOSIX(TestTool):
self.assertFalse(posix.canInstall(entry))
mock_canInstall.assert_called_with(posix, entry)
mock_fully_spec.assert_called_with(entry)
- self.assertTrue(posix.logger.error.called)
# finally, test success
- posix.logger.error.reset_mock()
mock_canInstall.reset_mock()
mock_fully_spec.reset_mock()
mock_fully_spec.return_value = True
self.assertTrue(posix.canInstall(entry))
mock_canInstall.assert_called_with(posix, entry)
mock_fully_spec.assert_called_with(entry)
- self.assertFalse(posix.logger.error.called)
def test_InstallPath(self):
posix = self.get_obj()
@@ -127,15 +119,17 @@ class TestPOSIX(TestTool):
mock_verify.reset_mock()
mock_verify.return_value = False
- posix.setup.__getitem__.return_value = True
+ Bcfg2.Options.setup.interactive = True
self.assertFalse(posix.VerifyPath(entry, modlist))
self.assertIsNotNone(entry.get('qtext'))
@patch('os.remove')
def test_prune_old_backups(self, mock_remove):
entry = lxml.etree.Element("Path", name="/etc/foo", type="file")
- setup = dict(ppath='/', max_copies=5, paranoid=True)
- posix = self.get_obj(setup=setup)
+ Bcfg2.Options.setup.paranoid_path = '/'
+ Bcfg2.Options.setup.paranoid_copies = 5
+ Bcfg2.Options.setup.paranoid = True
+ posix = self.get_obj()
remove = ["_etc_foo_2012-07-20T04:13:22.364989",
"_etc_foo_2012-07-31T04:13:23.894958",
@@ -152,9 +146,8 @@ class TestPOSIX(TestTool):
def inner(mock_listdir):
mock_listdir.side_effect = OSError
posix._prune_old_backups(entry)
- self.assertTrue(posix.logger.error.called)
self.assertFalse(mock_remove.called)
- mock_listdir.assert_called_with(setup['ppath'])
+ mock_listdir.assert_called_with(Bcfg2.Options.setup.paranoid_path)
mock_listdir.reset_mock()
mock_remove.reset_mock()
@@ -162,23 +155,23 @@ class TestPOSIX(TestTool):
mock_listdir.return_value = keep + remove
posix._prune_old_backups(entry)
- mock_listdir.assert_called_with(setup['ppath'])
+ mock_listdir.assert_called_with(Bcfg2.Options.setup.paranoid_path)
self.assertItemsEqual(mock_remove.call_args_list,
- [call(os.path.join(setup['ppath'], p))
+ [call(os.path.join(Bcfg2.Options.setup.paranoid_path,
+ p))
for p in remove])
mock_listdir.reset_mock()
mock_remove.reset_mock()
mock_remove.side_effect = OSError
- posix.logger.error.reset_mock()
# test to ensure that we call os.remove() for all files that
# need to be removed even if we get an error
posix._prune_old_backups(entry)
- mock_listdir.assert_called_with(setup['ppath'])
+ mock_listdir.assert_called_with(Bcfg2.Options.setup.paranoid_path)
self.assertItemsEqual(mock_remove.call_args_list,
- [call(os.path.join(setup['ppath'], p))
+ [call(os.path.join(Bcfg2.Options.setup.paranoid_path,
+ p))
for p in remove])
- self.assertTrue(posix.logger.error.called)
inner()
@@ -186,8 +179,10 @@ class TestPOSIX(TestTool):
@patch("os.path.isdir")
def test_paranoid_backup(self, mock_isdir, mock_copy):
entry = lxml.etree.Element("Path", name="/etc/foo", type="file")
- setup = dict(ppath='/', max_copies=5, paranoid=False)
- posix = self.get_obj(setup=setup)
+ Bcfg2.Options.setup.paranoid_path = '/'
+ Bcfg2.Options.setup.paranoid_copies = 5
+ Bcfg2.Options.setup.paranoid = False
+ posix = self.get_obj()
posix._prune_old_backups = Mock()
# paranoid false globally
@@ -196,9 +191,7 @@ class TestPOSIX(TestTool):
self.assertFalse(mock_copy.called)
# paranoid false on the entry
- setup['paranoid'] = True
- posix = self.get_obj(setup=setup)
- posix._prune_old_backups = Mock()
+ Bcfg2.Options.setup.paranoid = True
def reset():
mock_isdir.reset_mock()
@@ -238,6 +231,6 @@ class TestPOSIX(TestTool):
# just test it good enough
self.assertEqual(mock_copy.call_args[0][0],
entry.get("name"))
- bkupnam = os.path.join(setup['ppath'],
+ bkupnam = os.path.join(Bcfg2.Options.setup.paranoid_path,
entry.get('name').replace('/', '_')) + '_'
self.assertEqual(bkupnam, mock_copy.call_args[0][1][:len(bkupnam)])
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py
index d2f383f42..5a752b2ac 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py
@@ -197,7 +197,8 @@ class TestPOSIXTool(TestTool):
@patch("os.chown")
@patch("os.chmod")
@patch("os.utime")
- def test_set_perms(self, mock_utime, mock_chmod, mock_chown):
+ @patch("os.geteuid")
+ def test_set_perms(self, mock_geteuid, mock_utime, mock_chmod, mock_chown):
ptool = self.get_obj()
ptool._norm_entry_uid = Mock()
ptool._norm_entry_gid = Mock()
@@ -211,7 +212,12 @@ class TestPOSIXTool(TestTool):
mock_chmod.reset_mock()
mock_chown.reset_mock()
mock_utime.reset_mock()
+ mock_geteuid.reset_mock()
+ # pretend to run as root
+ mock_geteuid.return_value = 0
+
+ # test symlink -- no owner, group, permissions
entry = lxml.etree.Element("Path", name="/etc/foo", to="/etc/bar",
type="symlink")
ptool._set_acls.return_value = True
@@ -220,12 +226,12 @@ class TestPOSIXTool(TestTool):
ptool._set_secontext.assert_called_with(entry, path=entry.get("name"))
ptool._set_acls.assert_called_with(entry, path=entry.get("name"))
+ # test file with owner, group, permissions
+ reset()
entry = lxml.etree.Element("Path", name="/etc/foo", owner="owner",
group="group", mode="644", type="file")
ptool._norm_entry_uid.return_value = 10
ptool._norm_entry_gid.return_value = 100
-
- reset()
self.assertTrue(ptool._set_perms(entry))
ptool._norm_entry_uid.assert_called_with(entry)
ptool._norm_entry_gid.assert_called_with(entry)
@@ -236,6 +242,23 @@ class TestPOSIXTool(TestTool):
ptool._set_secontext.assert_called_with(entry, path=entry.get("name"))
ptool._set_acls.assert_called_with(entry, path=entry.get("name"))
+ # test file with owner, group, permissions, run as non-root
+ mock_geteuid.return_value = 1000
+ reset()
+ entry = lxml.etree.Element("Path", name="/etc/foo", owner="owner",
+ group="group", mode="644", type="file")
+ 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)
+ mock_chmod.assert_called_with(entry.get("name"),
+ int(entry.get("mode"), 8))
+ self.assertFalse(mock_utime.called)
+ ptool._set_secontext.assert_called_with(entry, path=entry.get("name"))
+ ptool._set_acls.assert_called_with(entry, path=entry.get("name"))
+ mock_geteuid.return_value = 0
+
+ # test with mtime
reset()
mtime = 1344459042
entry.set("mtime", str(mtime))
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
index c207900f1..9647413b6 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
@@ -24,18 +24,16 @@ from TestTools.Test_init import TestTool
class TestPOSIXUsers(TestTool):
test_obj = POSIXUsers
- def get_obj(self, logger=None, setup=None, config=None):
- if setup is None:
- setup = MagicMock()
- def getitem(key):
- if key == 'encoding':
- return 'UTF-8'
- else:
- return []
-
- setup.__getitem__.side_effect = getitem
+ def setUp(self):
+ TestTool.setUp(self)
+ set_setup_default('uid_whitelist')
+ set_setup_default('uid_blacklist')
+ set_setup_default('gid_whitelist')
+ set_setup_default('gid_blacklist')
+ set_setup_default('encoding', 'UTF-8')
- return TestTool.get_obj(self, logger, setup, config)
+ def get_obj(self, config=None):
+ return TestTool.get_obj(self, config)
@patch("pwd.getpwall")
@patch("grp.getgrall")
@@ -141,10 +139,9 @@ class TestPOSIXUsers(TestTool):
users.set_defaults['POSIXUser'] = Mock()
users.set_defaults['POSIXUser'].side_effect = lambda e: e
- states = dict()
- self.assertEqual(users.Inventory(states),
+ self.assertEqual(users.Inventory(),
mock_Inventory.return_value)
- mock_Inventory.assert_called_with(users, states, config.getchildren())
+ mock_Inventory.assert_called_with(users, config.getchildren())
lxml.etree.SubElement(orig_bundle, "POSIXGroup", name="test")
self.assertXMLEqual(orig_bundle, bundle)
@@ -306,9 +303,8 @@ class TestPOSIXUsers(TestTool):
entries = [lxml.etree.Element("POSIXUser", name="test"),
lxml.etree.Element("POSIXGroup", name="test"),
lxml.etree.Element("POSIXUser", name="test2")]
- states = dict()
- users.Install(entries, states)
+ states = users.Install(entries)
self.assertItemsEqual(entries, states.keys())
for state in states.values():
self.assertEqual(state, users._install.return_value)
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py
index 390b92608..0c059b5f3 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py
@@ -21,24 +21,17 @@ from common import *
class TestTool(Bcfg2TestCase):
test_obj = Tool
- def get_obj(self, logger=None, setup=None, config=None):
+ def setUp(self):
+ set_setup_default('command_timeout')
+ set_setup_default('interactive', False)
+
+ def get_obj(self, config=None):
if config is None:
config = lxml.etree.Element("Configuration")
- if not logger:
- def print_msg(msg):
- print(msg)
- logger = Mock()
- logger.error = Mock(side_effect=print_msg)
- logger.warning = Mock(side_effect=print_msg)
- logger.info = Mock(side_effect=print_msg)
- logger.debug = Mock(side_effect=print_msg)
- if not setup:
- setup = MagicMock()
- if 'command_timeout' not in setup:
- setup['command_timeout'] = None
+
execs = self.test_obj.__execs__
self.test_obj.__execs__ = []
- rv = self.test_obj(logger, setup, config)
+ rv = self.test_obj(config)
self.test_obj.__execs__ = execs
return rv
@@ -48,10 +41,12 @@ class TestTool(Bcfg2TestCase):
@patch("%s.%s._analyze_config" % (self.test_obj.__module__,
self.test_obj.__name__))
def inner(mock_analyze_config, mock_check_execs):
- t = self.get_obj()
+ self.get_obj()
mock_analyze_config.assert_called_with()
mock_check_execs.assert_called_with()
+ inner()
+
def test__analyze_config(self):
t = self.get_obj()
t.getSupportedEntries = Mock()
@@ -166,14 +161,12 @@ class TestTool(Bcfg2TestCase):
self.assertItemsEqual(states, expected_states)
self.assertEqual(t.extra, t.FindExtra.return_value)
- actual_states = dict()
- t.Inventory(actual_states, structures=[bundle1, bundle2])
+ actual_states = t.Inventory(structures=[bundle1, bundle2])
perform_assertions(actual_states)
reset()
- actual_states = dict()
t.config = config
- t.Inventory(actual_states)
+ actual_states = t.Inventory()
perform_assertions(actual_states)
def test_Install(self):
@@ -199,9 +192,8 @@ class TestTool(Bcfg2TestCase):
expected_states.update(dict([(e, t.InstallService.return_value)
for e in entries if e.tag == "Service"]))
- actual_states = dict()
t.modified = []
- t.Install(entries, actual_states)
+ actual_states = t.Install(entries)
self.assertItemsEqual(t.InstallPath.call_args_list,
[call(e) for e in entries if e.tag == "Path"])
self.assertItemsEqual(t.InstallPackage.call_args_list,
@@ -385,8 +377,7 @@ class TestPkgTool(TestTool):
# test single-pass install success
reset()
pt.cmd.run.return_value = True
- states = dict([(p, False) for p in packages])
- pt.Install(packages, states)
+ states = pt.Install(packages)
pt._get_package_command.assert_called_with(packages)
pt.cmd.run.assert_called_with([p.get("name") for p in packages])
self.assertItemsEqual(states,
@@ -406,8 +397,7 @@ class TestPkgTool(TestTool):
pt.VerifyPackage.side_effect = lambda p, m: p.get("name") == "bar"
pt.cmd.run.side_effect = run
- states = dict([(p, False) for p in packages])
- pt.Install(packages, states)
+ states = pt.Install(packages)
pt._get_package_command.assert_any_call(packages)
for pkg in packages:
pt.VerifyPackage.assert_any_call(pkg, [])
@@ -551,15 +541,15 @@ class TestSvcTool(TestTool):
@patch("Bcfg2.Client.prompt")
def test_BundleUpdated(self, mock_prompt):
- st = self.get_obj(setup=dict(interactive=False,
- servicemode='default'))
+ Bcfg2.Options.setup.service_mode = 'default'
+ Bcfg2.Options.setup.interactive = False
+ st = self.get_obj()
st.handlesEntry = Mock()
st.handlesEntry.side_effect = lambda e: e.tag == "Service"
st.stop_service = Mock()
- st.stop_service.return_value = 0
+ st.stop_service.return_value = True
st.restart_service = Mock()
- st.restart_service.side_effect = lambda e: \
- int(e.get("name") != "failed")
+ st.restart_service.side_effect = lambda e: e.get("name") != "failed"
def reset():
st.handlesEntry.reset_mock()
@@ -593,8 +583,7 @@ class TestSvcTool(TestTool):
# test in non-interactive mode
reset()
- states = dict()
- st.BundleUpdated(bundle, states)
+ states = st.BundleUpdated(bundle)
self.assertItemsEqual(st.handlesEntry.call_args_list,
[call(e) for e in entries])
st.stop_service.assert_called_with(stop)
@@ -606,9 +595,8 @@ class TestSvcTool(TestTool):
# test in interactive mode
reset()
mock_prompt.side_effect = lambda p: "interactive2" not in p
- st.setup['interactive'] = True
- states = dict()
- st.BundleUpdated(bundle, states)
+ Bcfg2.Options.setup.interactive = True
+ states = st.BundleUpdated(bundle)
self.assertItemsEqual(st.handlesEntry.call_args_list,
[call(e) for e in entries])
st.stop_service.assert_called_with(stop)
@@ -620,10 +608,9 @@ class TestSvcTool(TestTool):
# test in build mode
reset()
- st.setup['interactive'] = False
- st.setup['servicemode'] = 'build'
- states = dict()
- st.BundleUpdated(bundle, states)
+ Bcfg2.Options.setup.interactive = False
+ Bcfg2.Options.setup.service_mode = 'build'
+ states = st.BundleUpdated(bundle)
self.assertItemsEqual(st.handlesEntry.call_args_list,
[call(e) for e in entries])
self.assertItemsEqual(st.stop_service.call_args_list,
@@ -639,10 +626,9 @@ class TestSvcTool(TestTool):
services = install + [lxml.etree.Element("Service", type="test",
name="bar", install="false")]
st = self.get_obj()
- states = Mock()
- self.assertEqual(st.Install(services, states),
+ self.assertEqual(st.Install(services),
mock_Install.return_value)
- mock_Install.assert_called_with(st, install, states)
+ mock_Install.assert_called_with(st, install)
def test_InstallService(self):
st = self.get_obj()