diff options
| author | Sean Dague <sdague@linux.vnet.ibm.com> | 2012-10-23 16:39:00 -0400 |
|---|---|---|
| committer | Sean Dague <sdague@linux.vnet.ibm.com> | 2012-10-31 11:55:10 -0400 |
| commit | c8cf6f74001ec3ced16a516c7b10a596b75bc34c (patch) | |
| tree | 3e3a3faf71d18bec3a804e2ba498005c137a2f4a /tests/unit | |
| parent | 9a8c1d7e1a537e6580be2be1630baefc910de1de (diff) | |
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 'tests/unit')
| -rw-r--r-- | tests/unit/test_deprecated.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/unit/test_deprecated.py b/tests/unit/test_deprecated.py new file mode 100644 index 0000000..770a7b9 --- /dev/null +++ b/tests/unit/test_deprecated.py @@ -0,0 +1,53 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# Copyright 2010 OpenStack LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstack.common import cfg +from openstack.common import log as logging +from tests import utils as test_utils + +LOG = logging.getLogger(__name__) + + +class DeprecatedConfigTestCase(test_utils.BaseTestCase): + def setUp(self): + super(DeprecatedConfigTestCase, self).setUp() + self.warnbuffer = "" + self.critbuffer = "" + + def warn_log(msg): + self.warnbuffer = msg + + def critical_log(msg): + self.critbuffer = msg + + self.stubs.Set(LOG, 'warn', warn_log) + self.stubs.Set(LOG, 'critical', critical_log) + + def test_deprecated(self): + LOG.deprecated('test') + self.assertEqual(self.warnbuffer, 'Deprecated Config: test') + + def test_deprecated_fatal(self): + self.config(fatal_deprecations=True) + self.assertRaises(logging.DeprecatedConfig, + LOG.deprecated, "test2") + self.assertEqual(self.critbuffer, 'Deprecated Config: test2') + + def test_deprecated_logs_only_once(self): + LOG.deprecated('only once!') + LOG.deprecated('only once!') + LOG.deprecated('only once!') + self.assertEqual(self.warnbuffer, 'Deprecated Config: only once!') |
