From 80b4ca09bf4a815efd0726b96e3d032f76e1366d Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 22 Aug 2012 16:54:49 -0400 Subject: do not require a priority attribute on InfoXML files at all --- src/lib/Bcfg2/Server/Plugin.py | 9 +++++---- src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py | 2 +- src/lib/Bcfg2/Server/Plugins/SSLCA.py | 3 +-- testsuite/Testlib/TestServer/TestPlugin.py | 23 +++++++++++++---------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/lib/Bcfg2/Server/Plugin.py b/src/lib/Bcfg2/Server/Plugin.py index 97892c42d..f858c7b44 100644 --- a/src/lib/Bcfg2/Server/Plugin.py +++ b/src/lib/Bcfg2/Server/Plugin.py @@ -852,14 +852,14 @@ class XMLSrc(XMLFileBacked): """XMLSrc files contain a LNode hierarchy that returns matching entries.""" __node__ = INode __cacheobj__ = dict + __priority_required__ = True - def __init__(self, filename, fam=None, should_monitor=False, noprio=False): + def __init__(self, filename, fam=None, should_monitor=False): XMLFileBacked.__init__(self, filename, fam, should_monitor) self.items = {} self.cache = None self.pnode = None self.priority = -1 - self.noprio = noprio def HandleEvent(self, _=None): """Read file upon update.""" @@ -881,7 +881,7 @@ class XMLSrc(XMLFileBacked): try: self.priority = int(xdata.get('priority')) except (ValueError, TypeError): - if not self.noprio: + if self.__priority_required__: msg = "Got bogus priority %s for file %s" % \ (xdata.get('priority'), self.name) logger.error(msg) @@ -906,6 +906,7 @@ class XMLSrc(XMLFileBacked): class InfoXML(XMLSrc): __node__ = InfoNode + __priority_required__ = False class XMLDirectoryBacked(DirectoryBacked): @@ -1173,7 +1174,7 @@ class EntrySet(Debuggable): fpath = os.path.join(self.path, event.filename) if event.filename == 'info.xml': if not self.infoxml: - self.infoxml = InfoXML(fpath, True) + self.infoxml = InfoXML(fpath) self.infoxml.HandleEvent(event) elif event.filename in [':info', 'info']: for line in open(fpath).readlines(): diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py index 92cf45824..956ebfe17 100644 --- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py +++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py @@ -9,7 +9,7 @@ class CfgInfoXML(CfgInfo): def __init__(self, path): CfgInfo.__init__(self, path) - self.infoxml = Bcfg2.Server.Plugin.InfoXML(path, noprio=True) + self.infoxml = Bcfg2.Server.Plugin.InfoXML(path) def bind_info_to_entry(self, entry, metadata): mdata = dict() diff --git a/src/lib/Bcfg2/Server/Plugins/SSLCA.py b/src/lib/Bcfg2/Server/Plugins/SSLCA.py index d207c45a2..9d1c51a08 100644 --- a/src/lib/Bcfg2/Server/Plugins/SSLCA.py +++ b/src/lib/Bcfg2/Server/Plugins/SSLCA.py @@ -77,8 +77,7 @@ class SSLCA(Bcfg2.Server.Plugin.GroupSpool): self.CAs[ca] = dict(cp.items('sslca_' + ca)) self.Entries['Path'][ident] = self.get_cert elif event.filename.endswith("info.xml"): - self.infoxml[ident] = Bcfg2.Server.Plugin.InfoXML(epath, - noprio=True) + self.infoxml[ident] = Bcfg2.Server.Plugin.InfoXML(epath) self.infoxml[ident].HandleEvent(event) if action == 'deleted': if ident in self.Entries['Path']: diff --git a/testsuite/Testlib/TestServer/TestPlugin.py b/testsuite/Testlib/TestServer/TestPlugin.py index f970fcdb1..14e37f36b 100644 --- a/testsuite/Testlib/TestServer/TestPlugin.py +++ b/testsuite/Testlib/TestServer/TestPlugin.py @@ -1379,16 +1379,20 @@ class TestXMLSrc(TestXMLFileBacked): xsrc.__node__ = Mock() mock_open.return_value.read.return_value = tostring(xdata) - self.assertRaises(PluginExecutionError, - xsrc.HandleEvent, Mock()) + if xsrc.__priority_required__: + # test with no priority at all + self.assertRaises(PluginExecutionError, + xsrc.HandleEvent, Mock()) - xdata.set("priority", "cow") - mock_open.return_value.read.return_value = tostring(xdata) - self.assertRaises(PluginExecutionError, - xsrc.HandleEvent, Mock()) + # test with bogus priority + xdata.set("priority", "cow") + mock_open.return_value.read.return_value = tostring(xdata) + self.assertRaises(PluginExecutionError, + xsrc.HandleEvent, Mock()) - xdata.set("priority", "10") - mock_open.return_value.read.return_value = tostring(xdata) + # assign a priority to use in future tests + xdata.set("priority", "10") + mock_open.return_value.read.return_value = tostring(xdata) mock_open.reset_mock() xsrc = self.get_obj("/test/foo.xml") @@ -1946,8 +1950,7 @@ class TestEntrySet(TestDebuggable): event = Mock() event.filename = "info.xml" eset.update_metadata(event) - mock_InfoXML.assert_called_with(os.path.join(eset.path, "info.xml"), - True) + mock_InfoXML.assert_called_with(os.path.join(eset.path, "info.xml")) mock_InfoXML.return_value.HandleEvent.assert_called_with(event) self.assertEqual(eset.infoxml, mock_InfoXML.return_value) -- cgit v1.2.3-1-g7c22