summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2005-12-01 21:00:12 +0000
committerNarayan Desai <desai@mcs.anl.gov>2005-12-01 21:00:12 +0000
commitf2d1d3c9136bf5b2bee71fa2678281c989bec620 (patch)
tree6e9a133f54ce925142f0946cb3625b73bc828521
parent7b3c34c987805478456acfaaade82f6f69b99d99 (diff)
downloadbcfg2-f2d1d3c9136bf5b2bee71fa2678281c989bec620.tar.gz
bcfg2-f2d1d3c9136bf5b2bee71fa2678281c989bec620.tar.bz2
bcfg2-f2d1d3c9136bf5b2bee71fa2678281c989bec620.zip
Handle fam event processing failures, and fix another case where xml comments cause problems
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1604 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r--src/lib/Server/Core.py36
-rw-r--r--src/lib/Server/Plugin.py6
2 files changed, 21 insertions, 21 deletions
diff --git a/src/lib/Server/Core.py b/src/lib/Server/Core.py
index 4350e580a..979d86f5f 100644
--- a/src/lib/Server/Core.py
+++ b/src/lib/Server/Core.py
@@ -14,6 +14,13 @@ from Bcfg2.Server.Plugin import PluginInitError, PluginExecutionError
from Bcfg2.Server.Metadata import MetadataStore, MetadataConsistencyError
from Bcfg2.Server.Statistics import Statistics
+def log_failure(msg):
+ syslog(LOG_ERR, "Unexpected failure in %s" % (msg))
+ (trace, val, trb) = exc_info()
+ for line in extract_tb(trb):
+ syslog(LOG_ERR, ' File "%s", line %i, in %s\n %s\n'%line)
+ syslog(LOG_ERR, "%s: %s\n"%(trace, val))
+
class CoreInitError(Exception):
'''This error is raised when the core cannot be initialized'''
pass
@@ -50,7 +57,10 @@ class FamFam(object):
reqid = event.requestID
if self.users.has_key(reqid):
#print "dispatching event %s %s to obj %s handle :%s:" % (event.code2str(), event.filename, self.users[reqid], event.requestID)
- self.users[reqid].HandleEvent(event)
+ try:
+ self.users[reqid].HandleEvent(event)
+ except:
+ log_failure("handling event for file %s" % (event.filename))
def Service(self):
'''Handle all fam work'''
@@ -180,12 +190,7 @@ class Core(object):
except PluginInitError:
syslog(LOG_ERR, "Failed to instantiate plugin %s" % (plugin))
except:
- syslog(LOG_ERR, "Unexpected initiantiation failure for plugin %s" % (plugin))
- (trace, val, trb)=exc_info()
- for line in extract_tb(trb):
- syslog(LOG_ERR, ' File "%s", line %i, in %s\n %s\n'%line)
- syslog(LOG_ERR, "%s: %s\n"%(trace, val))
- del trace, val, trb
+ log_failure("Unexpected initiantiation failure for plugin %s" % (plugin))
for plugin in structures:
if self.plugins.has_key(plugin):
@@ -243,7 +248,7 @@ class Core(object):
try:
structures = self.GetStructures(meta)
except:
- self.LogFailure("GetStructures")
+ log_failure("GetStructures")
return Element("error", type='structure error')
for astruct in structures:
@@ -251,28 +256,19 @@ class Core(object):
self.BindStructure(astruct, meta)
config.append(astruct)
except:
- self.LogFailure("BindStructure")
+ log_failure("BindStructure")
syslog(LOG_INFO, "Generated config for %s in %s seconds"%(client, time() - start))
return config
- def LogFailure(self, failure):
- '''Log Failures in unexpected cases'''
- (trace, val, trb) = exc_info()
- syslog(LOG_ERR, "Unexpected failure in %s" % (failure))
- for line in extract_tb(trb):
- syslog(LOG_ERR, ' File "%s", line %i, in %s\n %s\n' % line)
- syslog(LOG_ERR, "%s: %s\n"%(trace, val))
- del trace, val, trb
-
def Service(self):
'''Perform periodic update tasks'''
while self.fam.fm.pending:
try:
self.fam.HandleEvent()
except:
- self.LogFailure("FamEvent")
+ log_failure("FamEvent")
try:
self.stats.WriteBack()
except:
- self.LogFailure("Statistics")
+ log_failure("Statistics")
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py
index 77187bb1d..d7c72a357 100644
--- a/src/lib/Server/Plugin.py
+++ b/src/lib/Server/Plugin.py
@@ -1,7 +1,7 @@
'''This module provides the baseclass for Bcfg2 Server Plugins'''
__revision__ = '$Revision:$'
-from lxml.etree import XML, XMLSyntaxError, _Comment
+from lxml.etree import XML, XMLSyntaxError, _Comment, tostring
from os import stat
from stat import ST_MTIME
from syslog import syslog, LOG_ERR, LOG_INFO
@@ -183,6 +183,10 @@ class ScopedXMLFile(SingleXMLFileBacked):
def StoreRecord(self, metadata, entry):
'''Store scoped record based on metadata'''
+ if isinstance(entry, _Comment):
+ return
+ elif not entry.attrib.has_key('name'):
+ syslog(LOG_ERR, "Got malformed record %s" % (tostring(entry)))
if not self.store.has_key(entry.tag):
self.store[entry.tag] = {}
if not self.store[entry.tag].has_key(entry.attrib['name']):