summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Bcfg2')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Properties.py48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Properties.py b/src/lib/Bcfg2/Server/Plugins/Properties.py
index 8d3e049d4..6d1c21328 100644
--- a/src/lib/Bcfg2/Server/Plugins/Properties.py
+++ b/src/lib/Bcfg2/Server/Plugins/Properties.py
@@ -32,18 +32,27 @@ class PropertyFile(Bcfg2.Server.Plugin.StructFile):
def write(self):
""" Write the data in this data structure back to the property
file """
- if self.validate_data():
- try:
- open(self.name,
- "wb").write(lxml.etree.tostring(self.xdata,
- pretty_print=True))
- return True
- except IOError:
- err = sys.exc_info()[1]
- logger.error("Failed to write %s: %s" % (self.name, err))
- return False
- else:
- return False
+ if not SETUP.cfp.getboolean("properties", "writes_enabled",
+ default=True):
+ msg = "Properties files write-back is disabled in the configuration"
+ logger.error(msg)
+ raise Bcfg2.Server.Plugin.PluginExecutionError(msg)
+ try:
+ self.validate_data()
+ except Bcfg2.Server.Plugin.PluginExecutionError:
+ msg = "Cannot write %s: %s" % (self.name, sys.exc_info()[1])
+ logger.error(msg)
+ raise Bcfg2.Server.Plugin.PluginExecutionError(msg)
+
+ try:
+ open(self.name, "wb").write(lxml.etree.tostring(self.xdata,
+ pretty_print=True))
+ return True
+ except IOError:
+ err = sys.exc_info()[1]
+ msg = "Failed to write %s: %s" % (self.name, err)
+ logger.error(msg)
+ raise Bcfg2.Server.Plugin.PluginExecutionError(msg)
def validate_data(self):
""" ensure that the data in this object validates against the
@@ -53,16 +62,14 @@ class PropertyFile(Bcfg2.Server.Plugin.StructFile):
try:
schema = lxml.etree.XMLSchema(file=schemafile)
except:
- logger.error("Failed to process schema for %s" % self.name)
- return False
+ err = sys.exc_info()[1]
+ raise Bcfg2.Server.Plugin.PluginExecutionError("Failed to process schema for %s: %s" % (self.name, err))
else:
# no schema exists
return True
if not schema.validate(self.xdata):
- logger.error("Data for %s fails to validate; run bcfg2-lint for "
- "more details" % self.name)
- return False
+ raise Bcfg2.Server.Plugin.PluginExecutionError("Data for %s fails to validate; run bcfg2-lint for more details" % self.name)
else:
return True
@@ -129,11 +136,12 @@ class Properties(Bcfg2.Server.Plugin.Plugin,
SETUP = core.setup
def get_additional_data(self, metadata):
- autowatch = self.core.setup.cfp.getboolean("properties", "automatch")
+ autowatch = self.core.setup.cfp.getboolean("properties", "automatch",
+ default=False)
rv = dict()
for fname, pfile in self.store.entries.items():
- if autowatch or pfile.xdata.get("automatch",
- "false").lower() == "true":
+ if (autowatch or
+ pfile.xdata.get("automatch", "false").lower() == "true"):
rv[fname] = pfile.XMLMatch(metadata)
else:
rv[fname] = copy.copy(pfile)