summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keystone/catalog/backends/templated.py8
-rw-r--r--keystone/common/logging.py18
-rw-r--r--keystone/service.py4
3 files changed, 29 insertions, 1 deletions
diff --git a/keystone/catalog/backends/templated.py b/keystone/catalog/backends/templated.py
index de6cf4c6e..e66e949f3 100644
--- a/keystone/catalog/backends/templated.py
+++ b/keystone/catalog/backends/templated.py
@@ -19,6 +19,8 @@ from keystone.common import logging
from keystone.catalog.backends import kvs
+LOG = logging.getLogger('keystone.catalog.backends.templated')
+
CONF = config.CONF
config.register_str('template_file', group='catalog')
@@ -90,7 +92,11 @@ class TemplatedCatalog(kvs.Catalog):
super(TemplatedCatalog, self).__init__()
def _load_templates(self, template_file):
- self.templates = parse_templates(open(template_file))
+ try:
+ self.templates = parse_templates(open(template_file))
+ except IOError:
+ LOG.critical('Unable to open template file %s' % template_file)
+ raise
def get_catalog(self, user_id, tenant_id, metadata=None):
d = dict(CONF.iteritems())
diff --git a/keystone/common/logging.py b/keystone/common/logging.py
index 0d3f46932..77d6a8e1c 100644
--- a/keystone/common/logging.py
+++ b/keystone/common/logging.py
@@ -8,6 +8,7 @@ import functools
import logging
import logging.config
import pprint
+import traceback
from logging.handlers import SysLogHandler
from logging.handlers import WatchedFileHandler
@@ -55,3 +56,20 @@ def log_debug(f):
logging.debug('')
return rv
return wrapper
+
+
+def fail_gracefully(f):
+ """Logs exceptions and aborts."""
+ @functools.wraps(f)
+ def wrapper(*args, **kw):
+ try:
+ return f(*args, **kw)
+ except Exception as e:
+ # tracebacks are kept in the debug log
+ logging.debug(traceback.format_exc(e))
+
+ # exception message is printed to all logs
+ logging.critical(e)
+
+ exit(1)
+ return wrapper
diff --git a/keystone/service.py b/keystone/service.py
index d0d447057..fdc16433a 100644
--- a/keystone/service.py
+++ b/keystone/service.py
@@ -535,24 +535,28 @@ class AdminExtensionsController(ExtensionsController):
}
+@logging.fail_gracefully
def public_app_factory(global_conf, **local_conf):
conf = global_conf.copy()
conf.update(local_conf)
return PublicRouter()
+@logging.fail_gracefully
def admin_app_factory(global_conf, **local_conf):
conf = global_conf.copy()
conf.update(local_conf)
return AdminRouter()
+@logging.fail_gracefully
def public_version_app_factory(global_conf, **local_conf):
conf = global_conf.copy()
conf.update(local_conf)
return PublicVersionRouter()
+@logging.fail_gracefully
def admin_version_app_factory(global_conf, **local_conf):
conf = global_conf.copy()
conf.update(local_conf)