Browse Source

get_conf_options can exclude deprecated opts

Add the ability to exclude deprecated conf options from
Adapter.get_conf_options via a new kwarg, include_deprecated, which (for
backward compatibility) defaults to True.

Closes-Bug: #1706775
Change-Id: I9245d2b983482154959ba05d7d8496a947f1c701
tags/3.1.0^0
Eric Fried 1 year ago
parent
commit
81363eca79
2 changed files with 32 additions and 12 deletions
  1. 20
    12
      keystoneauth1/loading/adapter.py
  2. 12
    0
      keystoneauth1/tests/unit/loading/test_adapter.py

+ 20
- 12
keystoneauth1/loading/adapter.py View File

@@ -32,7 +32,7 @@ class Adapter(base.BaseLoader):
32 32
         return []
33 33
 
34 34
     @staticmethod
35
-    def get_conf_options():
35
+    def get_conf_options(include_deprecated=True):
36 36
         """Get oslo_config options that are needed for a :py:class:`.Adapter`.
37 37
 
38 38
         These may be useful without being registered for config file generation
@@ -63,24 +63,20 @@ class Adapter(base.BaseLoader):
63 63
                                 range with min_version. Mutually exclusive with
64 64
                                 version.
65 65
 
66
+        :param include_deprecated: If True (the default, for backward
67
+                                   compatibility), deprecated options are
68
+                                   included in the result.  If False, they are
69
+                                   excluded.
66 70
         :returns: A list of oslo_config options.
67 71
         """
68 72
         cfg = _utils.get_oslo_config()
69 73
 
70
-        return [cfg.StrOpt('service-type',
74
+        opts = [cfg.StrOpt('service-type',
71 75
                            help='The default service_type for endpoint URL '
72 76
                                 'discovery.'),
73 77
                 cfg.StrOpt('service-name',
74 78
                            help='The default service_name for endpoint URL '
75 79
                                 'discovery.'),
76
-                cfg.StrOpt('interface',
77
-                           help='The default interface for endpoint URL '
78
-                                'discovery.',
79
-                           deprecated_for_removal=True,
80
-                           deprecated_reason='Using valid-interfaces is'
81
-                                             ' preferrable because it is'
82
-                                             ' capable of accepting a list of'
83
-                                             ' possible interfaces.'),
84 80
                 cfg.ListOpt('valid-interfaces',
85 81
                             help='List of interfaces, in order of preference, '
86 82
                                  'for endpoint URL.'),
@@ -108,6 +104,18 @@ class Adapter(base.BaseLoader):
108 104
                                 'range with min_version. Mutually exclusive '
109 105
                                 'with version.'),
110 106
                 ]
107
+        if include_deprecated:
108
+            opts += [
109
+                cfg.StrOpt('interface',
110
+                           help='The default interface for endpoint URL '
111
+                                'discovery.',
112
+                           deprecated_for_removal=True,
113
+                           deprecated_reason='Using valid-interfaces is'
114
+                                             ' preferrable because it is'
115
+                                             ' capable of accepting a list of'
116
+                                             ' possible interfaces.'),
117
+            ]
118
+        return opts
111 119
 
112 120
     def register_conf_options(self, conf, group):
113 121
         """Register the oslo_config options that are needed for an Adapter.
@@ -205,5 +213,5 @@ def load_from_conf_options(*args, **kwargs):
205 213
     return Adapter().load_from_conf_options(*args, **kwargs)
206 214
 
207 215
 
208
-def get_conf_options():
209
-    return Adapter.get_conf_options()
216
+def get_conf_options(*args, **kwargs):
217
+    return Adapter.get_conf_options(*args, **kwargs)

+ 12
- 0
keystoneauth1/tests/unit/loading/test_adapter.py View File

@@ -170,3 +170,15 @@ class ConfLoadingTests(utils.TestCase):
170 170
                           'region-name', 'endpoint-override', 'version',
171 171
                           'min-version', 'max-version'},
172 172
                          {opt.name for opt in opts})
173
+
174
+    def test_get_conf_options_undeprecated(self):
175
+        opts = loading.get_adapter_conf_options(include_deprecated=False)
176
+        for opt in opts:
177
+            if opt.name != 'valid-interfaces':
178
+                self.assertIsInstance(opt, cfg.StrOpt)
179
+            else:
180
+                self.assertIsInstance(opt, cfg.ListOpt)
181
+        self.assertEqual({'service-type', 'service-name', 'valid-interfaces',
182
+                          'region-name', 'endpoint-override', 'version',
183
+                          'min-version', 'max-version'},
184
+                         {opt.name for opt in opts})

Loading…
Cancel
Save