From 63ee213c1b17b6e1fb526451d3c5736bd51eab86 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 1 Feb 2013 09:36:39 -0500 Subject: get VCS revision in a more resilient way --- src/lib/Bcfg2/Server/Core.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/lib/Bcfg2/Server/Core.py') diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index 37da4a4b6..81bfebbb5 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -336,9 +336,23 @@ class BaseCore(object): self.fam.handle_event_set(self.lock) except: continue - # VCS plugin periodic updates - for plugin in self.plugins_by_type(Bcfg2.Server.Plugin.Version): - self.revision = plugin.get_revision() + self._update_vcs_revision() + + @track_statistics() + def _update_vcs_revision(self): + """ Update the revision of the current configuration on-disk + from the VCS plugin """ + for plugin in self.plugins_by_type(Bcfg2.Server.Plugin.Version): + try: + newrev = plugin.get_revision() + if newrev != self.revision: + self.logger.debug("Updated to revision %s" % newrev) + self.revision = newrev + break + except: + self.logger.warning("Error getting revision from %s: %s" % + (plugin.name, sys.exc_info()[1])) + self.revision = '-1' def init_plugin(self, plugin): """ Import and instantiate a single plugin. The plugin is @@ -364,8 +378,8 @@ class BaseCore(object): try: plug = getattr(mod, plugin.split('.')[-1]) except AttributeError: - self.logger.error("Failed to load plugin %s (AttributeError)" % - plugin) + self.logger.error("Failed to load plugin %s: %s" % + (plugin, sys.exc_info()[1])) return # Blacklist conflicting plugins cplugs = [conflict for conflict in plug.conflicts -- cgit v1.2.3-1-g7c22 From 55807333ccb7d80c4e2f074c2a1a10f554e57289 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 8 Feb 2013 08:12:19 -0500 Subject: Core: deduplicated some error handling code --- src/lib/Bcfg2/Server/Core.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/lib/Bcfg2/Server/Core.py') diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index 81bfebbb5..782aafbf1 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -552,18 +552,16 @@ class BaseCore(object): continue try: self.Bind(entry, metadata) - except PluginExecutionError: - exc = sys.exc_info()[1] - if 'failure' not in entry.attrib: - entry.set('failure', 'bind error: %s' % exc) - self.logger.error("Failed to bind entry %s:%s: %s" % - (entry.tag, entry.get('name'), exc)) - except Exception: + except: exc = sys.exc_info()[1] if 'failure' not in entry.attrib: entry.set('failure', 'bind error: %s' % exc) - self.logger.error("Unexpected failure in BindStructure: %s %s" - % (entry.tag, entry.get('name')), exc_info=1) + if isinstance(exc, PluginExecutionError): + msg = "Failed to bind entry" + else: + msg = "Unexpected failure binding entry" + self.logger.error("%s %s:%s: %s" % + (msg, entry.tag, entry.get('name'), exc)) def Bind(self, entry, metadata): """ Bind a single entry using the appropriate generator. -- cgit v1.2.3-1-g7c22