Browse Source

Merge "Move warnings to their own module"

Zuul 5 months ago
parent
commit
fb12d340e8

+ 9
- 24
oslo_db/exception.py View File

@@ -43,10 +43,12 @@ with `try/except` statement. This is required for consistent handling of
43 43
 database errors.
44 44
 """
45 45
 
46
+from debtcollector import moves
47
+from oslo_utils.excutils import CausedByException
46 48
 import six
47 49
 
48 50
 from oslo_db._i18n import _
49
-from oslo_utils.excutils import CausedByException
51
+from oslo_db import warning
50 52
 
51 53
 
52 54
 class DBError(CausedByException):
@@ -299,27 +301,10 @@ class CantStartEngineError(Exception):
299 301
     """Error raised when the enginefacade cannot start up correctly."""
300 302
 
301 303
 
302
-class NotSupportedWarning(Warning):
303
-    """Warn that an argument or call that was passed is not supported.
304
-
305
-    This subclasses Warning so that it can be filtered as a distinct
306
-    category.
307
-
308
-    .. seealso::
309
-
310
-        https://docs.python.org/2/library/warnings.html
311
-
312
-    """
304
+moves.moved_class(warning.NotSupportedWarning,
305
+                  'NotSupportedWarning',
306
+                  __name__, version='Stein')
313 307
 
314
-
315
-class OsloDBDeprecationWarning(DeprecationWarning):
316
-    """Issued per usage of a deprecated API.
317
-
318
-    This subclasses DeprecationWarning so that it can be filtered as a distinct
319
-    category.
320
-
321
-    .. seealso::
322
-
323
-        https://docs.python.org/2/library/warnings.html
324
-
325
-    """
308
+moves.moved_class(warning.OsloDBDeprecationWarning,
309
+                  'OsloDBDeprecationWarning',
310
+                  __name__, version='Stein')

+ 3
- 3
oslo_db/sqlalchemy/enginefacade.py View File

@@ -10,7 +10,6 @@
10 10
 #    License for the specific language governing permissions and limitations
11 11
 #    under the License.
12 12
 
13
-
14 13
 import contextlib
15 14
 import functools
16 15
 import operator
@@ -28,6 +27,7 @@ from oslo_db import options
28 27
 from oslo_db.sqlalchemy import engines
29 28
 from oslo_db.sqlalchemy import orm
30 29
 from oslo_db.sqlalchemy import utils
30
+from oslo_db import warning
31 31
 
32 32
 
33 33
 class _symbol(object):
@@ -343,7 +343,7 @@ class _TransactionFactory(object):
343 343
             warnings.warn(
344 344
                 "Configuration option(s) %r not supported" %
345 345
                 sorted(not_supported),
346
-                exception.NotSupportedWarning
346
+                warning.NotSupportedWarning
347 347
             )
348 348
 
349 349
     def get_legacy_facade(self):
@@ -1272,7 +1272,7 @@ class LegacyEngineFacade(object):
1272 1272
         warnings.warn(
1273 1273
             "EngineFacade is deprecated; please use "
1274 1274
             "oslo_db.sqlalchemy.enginefacade",
1275
-            exception.OsloDBDeprecationWarning,
1275
+            warning.OsloDBDeprecationWarning,
1276 1276
             stacklevel=2)
1277 1277
         if _factory:
1278 1278
             self._factory = _factory

+ 2
- 1
oslo_db/tests/sqlalchemy/test_enginefacade.py View File

@@ -37,6 +37,7 @@ from oslo_db.sqlalchemy import enginefacade
37 37
 from oslo_db.sqlalchemy import engines as oslo_engines
38 38
 from oslo_db.sqlalchemy import orm
39 39
 from oslo_db.tests.sqlalchemy import base as test_base
40
+from oslo_db import warning
40 41
 
41 42
 
42 43
 enginefacade.transaction_context_provider(oslo_context.RequestContext)
@@ -2208,7 +2209,7 @@ class ConfigOptionsTest(oslo_test_base.BaseTestCase):
2208 2209
 
2209 2210
         self.assertEqual(1, len(w))
2210 2211
         self.assertTrue(
2211
-            issubclass(w[-1].category, exception.NotSupportedWarning))
2212
+            issubclass(w[-1].category, warning.NotSupportedWarning))
2212 2213
         self.assertEqual(
2213 2214
             "Configuration option(s) ['fake1', 'wrong2'] not supported",
2214 2215
             str(w[-1].message)

+ 41
- 0
oslo_db/warning.py View File

@@ -0,0 +1,41 @@
1
+# Copyright 2018 Red Hat, Inc.
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
7
+#      http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+"""Custom warnings."""
16
+
17
+
18
+class NotSupportedWarning(Warning):
19
+    """Warn that an argument or call that was passed is not supported.
20
+
21
+    This subclasses Warning so that it can be filtered as a distinct
22
+    category.
23
+
24
+    .. seealso::
25
+
26
+        https://docs.python.org/2/library/warnings.html
27
+
28
+    """
29
+
30
+
31
+class OsloDBDeprecationWarning(DeprecationWarning):
32
+    """Issued per usage of a deprecated API.
33
+
34
+    This subclasses DeprecationWarning so that it can be filtered as a distinct
35
+    category.
36
+
37
+    .. seealso::
38
+
39
+        https://docs.python.org/2/library/warnings.html
40
+
41
+    """

Loading…
Cancel
Save