diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-12-10 20:58:55 -0500 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-12-11 10:51:54 -0500 |
commit | 94ba31279869d7052ba001e38927f9eecd0a636f (patch) | |
tree | d54894a50fbe4850996a3aa5fb254d6956cb92af /testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX | |
parent | 13fbef668878239dc5116f899a0c9791df81081e (diff) | |
download | bcfg2-94ba31279869d7052ba001e38927f9eecd0a636f.tar.gz bcfg2-94ba31279869d7052ba001e38927f9eecd0a636f.tar.bz2 bcfg2-94ba31279869d7052ba001e38927f9eecd0a636f.zip |
Augeas improvements:
* Added ability to specify initial content for a file that doesn't
exist, to avoid a messy situation where you'd have to probe for file
existence and either use a Path type="file" or Path type="augeas"
depending, and run Bcfg2 twice.
* All commands in an Augeas path are run if *any* of them fail to
verify. Previously, only commands that hadn't been run would be
installed, but that had issues, particularly with the Clear command,
which could pass verification but then be required during the
installation phase anyway.
* Miscellaneous bug fixes.
Diffstat (limited to 'testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX')
-rw-r--r-- | testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py index 9b25499fe..b8534f5a8 100644 --- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py +++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py @@ -74,7 +74,7 @@ if can_skip or HAS_AUGEAS: def tearDown(self): tmpfile = getattr(self, "tmpfile", None) - if tmpfile: + if tmpfile and os.path.exists(tmpfile): os.unlink(tmpfile) def test_fully_specified(self): @@ -83,7 +83,7 @@ if can_skip or HAS_AUGEAS: entry = lxml.etree.Element("Path", name="/test", type="augeas") self.assertFalse(ptool.fully_specified(entry)) - entry.text = "text" + lxml.etree.SubElement(entry, "Set", path="/test", value="test") self.assertTrue(ptool.fully_specified(entry)) def test_install(self): @@ -138,12 +138,14 @@ if can_skip or HAS_AUGEAS: self._verify(self.applied_commands.values()) @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.install") - def _install(self, commands, expected, mock_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)) @@ -156,8 +158,7 @@ if can_skip or HAS_AUGEAS: 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")], + value="Changed content")], expected) def test_install_set_new(self): @@ -166,30 +167,16 @@ if can_skip or HAS_AUGEAS: 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")], + value="new content")], 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")], + path='Test/*[#attribute/foo = "foo"]')], expected) def test_install_move(self): @@ -199,8 +186,7 @@ if can_skip or HAS_AUGEAS: expected.append(foo) self._install( [lxml.etree.Element("Move", source='Test/Children/Foo', - destination='Test/Foo', - verified="false")], + destination='Test/Foo')], expected) def test_install_clear(self): @@ -228,7 +214,7 @@ if can_skip or HAS_AUGEAS: [lxml.etree.Element( "SetMulti", value="same", base='Test/Children[#attribute/identical = "true"]', - sub="Thing/#text", verified="false")], + sub="Thing/#text")], expected) def test_install_insert(self): @@ -242,9 +228,20 @@ if can_skip or HAS_AUGEAS: [lxml.etree.Element( "Insert", path='Test/Children[#attribute/identical = "true"]/Thing[2]', - label="Thing", where="after", verified="false"), + label="Thing", where="after"), lxml.etree.Element( "Set", path='Test/Children[#attribute/identical = "true"]/Thing[3]/#text', - value="three", verified="false")], + 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") |