diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-08-06 13:38:57 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-08-06 13:38:57 +0000 |
| commit | 51002f0d0f85f077bbbfed1d151df59240775ff8 (patch) | |
| tree | 9c0fdc57a3cd6933983959a8b400c28046ff60ab | |
| parent | 9142e11580e901875617400c62e9f18aeb7d3b21 (diff) | |
| parent | c3047b988fd7e937bf822a8a54115b4cab452380 (diff) | |
| download | nova-51002f0d0f85f077bbbfed1d151df59240775ff8.tar.gz nova-51002f0d0f85f077bbbfed1d151df59240775ff8.tar.xz nova-51002f0d0f85f077bbbfed1d151df59240775ff8.zip | |
Merge "Only log deprecated config warnings once."
| -rw-r--r-- | nova/common/deprecated.py | 15 | ||||
| -rw-r--r-- | nova/tests/test_deprecated.py | 6 |
2 files changed, 20 insertions, 1 deletions
diff --git a/nova/common/deprecated.py b/nova/common/deprecated.py index feef86d98..6b1c587e8 100644 --- a/nova/common/deprecated.py +++ b/nova/common/deprecated.py @@ -14,6 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. +import warnings + from nova import exception from nova import flags from nova.openstack.common import cfg @@ -30,6 +32,17 @@ FLAGS = flags.FLAGS FLAGS.register_opts(deprecate_opts) +def _showwarning(message, category, filename, lineno, file=None, line=None): + """ + Redirect warnings into logging. + """ + LOG.warn(str(message)) + + +# Install our warnings handler +warnings.showwarning = _showwarning + + def warn(msg=""): """ Warn of a deprecated config option that an operator has specified. @@ -37,6 +50,6 @@ def warn(msg=""): we use some operator changeable parameter to indicate that it will go away in a future version of OpenStack. """ - LOG.warn(_("Deprecated Config: %s") % msg) + warnings.warn(_("Deprecated Config: %s") % msg) if FLAGS.fatal_deprecations: raise exception.DeprecatedConfig(msg=msg) diff --git a/nova/tests/test_deprecated.py b/nova/tests/test_deprecated.py index e65baa53e..ebc6fed93 100644 --- a/nova/tests/test_deprecated.py +++ b/nova/tests/test_deprecated.py @@ -38,3 +38,9 @@ class DeprecatedConfigTestCase(test.TestCase): self.assertRaises(exception.DeprecatedConfig, deprecated.warn, "test2") self.assertEqual(self.logbuffer, 'Deprecated Config: test2') + + def test_deprecated_logs_only_once(self): + deprecated.warn('only once!') + deprecated.warn('only once!') + deprecated.warn('only once!') + self.assertEqual(self.logbuffer, 'Deprecated Config: only once!') |
