summaryrefslogtreecommitdiffstats
path: root/openstack
diff options
context:
space:
mode:
authorSean Dague <sdague@linux.vnet.ibm.com>2012-10-23 16:39:00 -0400
committerSean Dague <sdague@linux.vnet.ibm.com>2012-10-31 11:55:10 -0400
commitc8cf6f74001ec3ced16a516c7b10a596b75bc34c (patch)
tree3e3a3faf71d18bec3a804e2ba498005c137a2f4a /openstack
parent9a8c1d7e1a537e6580be2be1630baefc910de1de (diff)
downloadoslo-c8cf6f74001ec3ced16a516c7b10a596b75bc34c.tar.gz
oslo-c8cf6f74001ec3ced16a516c7b10a596b75bc34c.tar.xz
oslo-c8cf6f74001ec3ced16a516c7b10a596b75bc34c.zip
move nova.common.deprecated to openstack-common
Fixes bug #1070511 nova has a common deprecation path which lets you turn deprecation warnings into fatal errors via config. Make this a function of the openstack common log to make it available to other projects in a standard way. Include exception directly in logging module. Update exception to work correctly now that it's not based off of nova's exception class. Change-Id: I699e776c99c429e60dfb5cd6c0cdbb661bae0ce8
Diffstat (limited to 'openstack')
-rw-r--r--openstack/common/log.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/openstack/common/log.py b/openstack/common/log.py
index 783ff2d..6cb3dfc 100644
--- a/openstack/common/log.py
+++ b/openstack/common/log.py
@@ -76,6 +76,9 @@ log_opts = [
cfg.BoolOpt('publish_errors',
default=False,
help='publish error events'),
+ cfg.BoolOpt('fatal_deprecations',
+ default=False,
+ help='make deprecations fatal'),
# NOTE(mikal): there are two options here because sometimes we are handed
# a full instance (and could include more information), and other times we
@@ -170,6 +173,14 @@ class ContextAdapter(logging.LoggerAdapter):
def audit(self, msg, *args, **kwargs):
self.log(logging.AUDIT, msg, *args, **kwargs)
+ def deprecated(self, msg, *args, **kwargs):
+ stdmsg = _("Deprecated Config: %s") % msg
+ if CONF.fatal_deprecations:
+ self.critical(stdmsg, *args, **kwargs)
+ raise DeprecatedConfig(msg=stdmsg)
+ else:
+ self.warn(stdmsg, *args, **kwargs)
+
def process(self, msg, kwargs):
if 'extra' not in kwargs:
kwargs['extra'] = {}
@@ -450,3 +461,10 @@ class ColorHandler(logging.StreamHandler):
def format(self, record):
record.color = self.LEVEL_COLORS[record.levelno]
return logging.StreamHandler.format(self, record)
+
+
+class DeprecatedConfig(Exception):
+ message = _("Fatal call to deprecated config: %(msg)s")
+
+ def __init__(self, msg):
+ super(Exception, self).__init__(self.message % dict(msg=msg))