summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-02-13 11:28:26 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-02-13 11:28:26 -0500
commit7241066deea16a9ebba718d7ecd157891e23cf33 (patch)
tree73f3bc0cae620b40903aef8971fd09c229e1f465
parentbd44478c06f65b7cb2a7f87ab8de862033dd80dc (diff)
downloadbcfg2-7241066deea16a9ebba718d7ecd157891e23cf33.tar.gz
bcfg2-7241066deea16a9ebba718d7ecd157891e23cf33.tar.bz2
bcfg2-7241066deea16a9ebba718d7ecd157891e23cf33.zip
Defaults: change to GoalValidator to apply defaults after structures are bound (#1136)
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Defaults.py29
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py17
2 files changed, 17 insertions, 29 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Defaults.py b/src/lib/Bcfg2/Server/Plugins/Defaults.py
index f4d86a64f..04c14aa96 100644
--- a/src/lib/Bcfg2/Server/Plugins/Defaults.py
+++ b/src/lib/Bcfg2/Server/Plugins/Defaults.py
@@ -5,7 +5,7 @@ import Bcfg2.Server.Plugins.Rules
class Defaults(Bcfg2.Server.Plugins.Rules.Rules,
- Bcfg2.Server.Plugin.StructureValidator):
+ Bcfg2.Server.Plugin.GoalValidator):
"""Set default attributes on bound entries"""
__author__ = 'bcfg-dev@mcs.anl.gov'
@@ -22,27 +22,18 @@ class Defaults(Bcfg2.Server.Plugins.Rules.Rules,
def HandleEvent(self, event):
Bcfg2.Server.Plugin.XMLDirectoryBacked.HandleEvent(self, event)
- def validate_structures(self, metadata, structures):
+ def validate_goals(self, metadata, config):
""" Apply defaults """
- for struct in structures:
+ for struct in config.getchildren():
for entry in struct.getchildren():
- if entry.tag.startswith("Bound"):
- is_bound = True
- entry.tag = entry.tag[5:]
- else:
- is_bound = False
try:
- try:
- self.BindEntry(entry, metadata)
- except Bcfg2.Server.Plugin.PluginExecutionError:
- # either no matching defaults (which is okay),
- # or multiple matching defaults (which is not
- # okay, but is logged). either way, we don't
- # care about the error.
- pass
- finally:
- if is_bound:
- entry.tag = "Bound" + entry.tag
+ self.BindEntry(entry, metadata)
+ except Bcfg2.Server.Plugin.PluginExecutionError:
+ # either no matching defaults (which is okay),
+ # or multiple matching defaults (which is not
+ # okay, but is logged). either way, we don't
+ # care about the error.
+ pass
@property
def _regex_enabled(self):
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py
index 9ed0c3803..7be3d8e84 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestDefaults.py
@@ -15,10 +15,10 @@ while path != "/":
path = os.path.dirname(path)
from common import *
from TestRules import TestRules
-from Testinterfaces import TestStructureValidator
+from Testinterfaces import TestGoalValidator
-class TestDefaults(TestRules, TestStructureValidator):
+class TestDefaults(TestRules, TestGoalValidator):
test_obj = Defaults
def get_obj(self, *args, **kwargs):
@@ -35,25 +35,22 @@ class TestDefaults(TestRules, TestStructureValidator):
d.HandleEvent(evt)
mock_HandleEvent.assert_called_with(d, evt)
- def test_validate_structures(self):
+ def test_validate_goals(self):
d = self.get_obj()
d.BindEntry = Mock()
metadata = Mock()
entries = []
- b1 = lxml.etree.Element("Bundle")
+ config = lxml.etree.Element("Configuration")
+ b1 = lxml.etree.SubElement(config, "Bundle")
entries.append(lxml.etree.SubElement(b1, "Path", name="/foo"))
entries.append(lxml.etree.SubElement(b1, "Path", name="/bar"))
- b2 = lxml.etree.Element("Bundle")
- bound = lxml.etree.SubElement(b2, "BoundPath", name="/baz")
- entries.append(bound)
+ b2 = lxml.etree.SubElement(config, "Bundle")
entries.append(lxml.etree.SubElement(b2, "Package", name="quux"))
- d.validate_structures(metadata, [b1, b2])
+ d.validate_goals(metadata, config)
self.assertItemsEqual(d.BindEntry.call_args_list,
[call(e, metadata) for e in entries])
- # ensure that BoundEntries stay bound
- self.assertTrue(bound.tag == "BoundPath")
def test__matches_regex_disabled(self):
""" cannot disable regex in Defaults plugin """