diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-06-19 14:39:13 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-06-19 14:39:13 -0400 |
commit | a01b57c799d0eb24c4122003c0c295026edc48ba (patch) | |
tree | 960a1760f7cc10092af42224331f323d1008a2fd /src | |
parent | dbc5e0d190ecfb3b047e133294b8d1e6ef451c46 (diff) | |
download | bcfg2-a01b57c799d0eb24c4122003c0c295026edc48ba.tar.gz bcfg2-a01b57c799d0eb24c4122003c0c295026edc48ba.tar.bz2 bcfg2-a01b57c799d0eb24c4122003c0c295026edc48ba.zip |
added ability to disable Properties write-back
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Properties.py | 48 |
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) |