summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Dague <sdague@linux.vnet.ibm.com>2012-06-13 10:56:39 -0400
committerSean Dague <sdague@linux.vnet.ibm.com>2012-06-18 09:14:07 -0400
commitadc66644c4d1a4c6e5cd6a26394cf8b48620d99e (patch)
tree766f7e24d47524ff70e3a07cee805b453a4ac0bf
parentfb9abcc83935b01746aeba0db4c431fe72b921fc (diff)
downloadnova-adc66644c4d1a4c6e5cd6a26394cf8b48620d99e.tar.gz
nova-adc66644c4d1a4c6e5cd6a26394cf8b48620d99e.tar.xz
nova-adc66644c4d1a4c6e5cd6a26394cf8b48620d99e.zip
added deprecated.warn helper method
provide a convenience method for indicating in code that a config option the operateor will have to deal with exists in their environment. Change-Id: I17b0c120d54b1db75c6bb29d107e4a15a5202e76
-rw-r--r--nova/common/deprecated.py42
-rw-r--r--nova/exception.py4
-rw-r--r--nova/tests/test_deprecated.py40
-rw-r--r--nova/virt/connection.py4
4 files changed, 89 insertions, 1 deletions
diff --git a/nova/common/deprecated.py b/nova/common/deprecated.py
new file mode 100644
index 000000000..a442c1506
--- /dev/null
+++ b/nova/common/deprecated.py
@@ -0,0 +1,42 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright (c) 2012 IBM
+#
+# 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 nova import exception
+from nova import flags
+from nova import log as logging
+from nova.openstack.common import cfg
+
+LOG = logging.getLogger(__name__)
+
+deprecate_opts = [
+ cfg.BoolOpt('fatal_deprecations',
+ default=False,
+ help='make deprecations fatal')
+ ]
+FLAGS = flags.FLAGS
+FLAGS.register_opts(deprecate_opts)
+
+
+def warn(msg=""):
+ """
+ Warn of a deprecated config option that an operator has specified.
+ This should be added in the code where we've made a change in how
+ 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)
+ if FLAGS.fatal_deprecations:
+ raise exception.DeprecatedConfig(msg=msg)
diff --git a/nova/exception.py b/nova/exception.py
index 2c43d36f4..df21f0273 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -175,6 +175,10 @@ class DBError(NovaException):
super(DBError, self).__init__(str(inner_exception))
+class DeprecatedConfig(NovaException):
+ message = _("Fatal call to deprecated config %(msg)")
+
+
class DecryptionFailure(NovaException):
message = _("Failed to decrypt text")
diff --git a/nova/tests/test_deprecated.py b/nova/tests/test_deprecated.py
new file mode 100644
index 000000000..e65baa53e
--- /dev/null
+++ b/nova/tests/test_deprecated.py
@@ -0,0 +1,40 @@
+# 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 nova.common import deprecated
+from nova import exception
+from nova import test
+
+
+class DeprecatedConfigTestCase(test.TestCase):
+ def setUp(self):
+ super(DeprecatedConfigTestCase, self).setUp()
+ self.logbuffer = ""
+
+ def local_log(msg):
+ self.logbuffer = msg
+
+ self.stubs.Set(deprecated.LOG, 'warn', local_log)
+
+ def test_deprecated(self):
+ deprecated.warn('test')
+ self.assertEqual(self.logbuffer, 'Deprecated Config: test')
+
+ def test_deprecated_fatal(self):
+ self.flags(fatal_deprecations=True)
+ self.assertRaises(exception.DeprecatedConfig,
+ deprecated.warn, "test2")
+ self.assertEqual(self.logbuffer, 'Deprecated Config: test2')
diff --git a/nova/virt/connection.py b/nova/virt/connection.py
index c792ff966..0c7c3bd0a 100644
--- a/nova/virt/connection.py
+++ b/nova/virt/connection.py
@@ -21,6 +21,7 @@
import sys
+from nova.common import deprecated
from nova import exception
from nova import flags
from nova import log as logging
@@ -66,7 +67,8 @@ def get_connection(read_only=False):
* baremetal
"""
- LOG.warning(_('Specifying virt driver via connection_type is deprecated'))
+ deprecated.warn(_('Specifying virt driver via connection_type is '
+ 'deprecated. Use compute_driver=classname instead.'))
driver_name = known_drivers.get(FLAGS.connection_type)