Browse Source

Merge "Allow fetching oslo.config Opts from plugins"

Jenkins 3 years ago
parent
commit
79104aa0fe
2 changed files with 22 additions and 20 deletions
  1. 12
    2
      keystoneauth1/loading/conf.py
  2. 10
    18
      keystoneauth1/tests/unit/loading/test_conf.py

+ 12
- 2
keystoneauth1/loading/conf.py View File

@@ -42,15 +42,25 @@ def get_common_conf_options():
42 42
     return [_AUTH_TYPE_OPT._to_oslo_opt(), _AUTH_SECTION_OPT._to_oslo_opt()]
43 43
 
44 44
 
45
-def get_plugin_conf_options(name):
45
+def get_plugin_conf_options(plugin):
46 46
     """Get the oslo_config options for a specific plugin.
47 47
 
48 48
     This will be the list of config options that is registered and loaded by
49 49
     the specified plugin.
50 50
 
51
+    :param plugin: The name of the plugin loader or a plugin loader object
52
+    :type plugin: str or keystoneauth1._loading.BaseLoader
53
+
51 54
     :returns: A list of oslo_config options.
52 55
     """
53
-    return [o._to_oslo_opt() for o in base.get_plugin_options(name)]
56
+    try:
57
+        getter = plugin.get_options
58
+    except AttributeError:
59
+        opts = base.get_plugin_options(plugin)
60
+    else:
61
+        opts = getter()
62
+
63
+    return [o._to_oslo_opt() for o in opts]
54 64
 
55 65
 
56 66
 def register_conf_options(conf, group):

+ 10
- 18
keystoneauth1/tests/unit/loading/test_conf.py View File

@@ -24,10 +24,6 @@ from keystoneauth1.loading._plugins.identity import v3
24 24
 from keystoneauth1.tests.unit.loading import utils
25 25
 
26 26
 
27
-def to_oslo_opts(opts):
28
-    return [o._to_oslo_opt() for o in opts]
29
-
30
-
31 27
 class ConfTests(utils.TestCase):
32 28
 
33 29
     def setUp(self):
@@ -53,9 +49,8 @@ class ConfTests(utils.TestCase):
53 49
         loading.register_auth_conf_options(self.conf_fixture.conf,
54 50
                                            group=self.GROUP)
55 51
 
56
-        self.conf_fixture.register_opts(
57
-            to_oslo_opts(v2.Password().get_options()),
58
-            group=section)
52
+        opts = loading.get_auth_plugin_conf_options(v2.Password())
53
+        self.conf_fixture.register_opts(opts, group=section)
59 54
 
60 55
         self.conf_fixture.config(auth_type=self.V2PASS,
61 56
                                  auth_url=auth_url,
@@ -86,8 +81,8 @@ class ConfTests(utils.TestCase):
86 81
         loading.register_auth_conf_options(self.conf_fixture.conf,
87 82
                                            group=self.GROUP)
88 83
 
89
-        self.conf_fixture.register_opts(to_oslo_opts(v3.Token().get_options()),
90
-                                        group=section)
84
+        opts = loading.get_auth_plugin_conf_options(v3.Token())
85
+        self.conf_fixture.register_opts(opts, group=section)
91 86
 
92 87
         self.conf_fixture.config(auth_type=self.V3TOKEN,
93 88
                                  auth_url=auth_url,
@@ -127,9 +122,8 @@ class ConfTests(utils.TestCase):
127 122
         m.return_value = utils.MockManager(utils.MockLoader())
128 123
         driver_name = uuid.uuid4().hex
129 124
 
130
-        self.conf_fixture.register_opts(
131
-            to_oslo_opts(utils.MockLoader().get_options()),
132
-            group=self.GROUP)
125
+        opts = loading.get_auth_plugin_conf_options(utils.MockLoader())
126
+        self.conf_fixture.register_opts(opts, group=self.GROUP)
133 127
         self.conf_fixture.config(auth_type=driver_name,
134 128
                                  group=self.GROUP,
135 129
                                  **self.TEST_VALS)
@@ -144,9 +138,8 @@ class ConfTests(utils.TestCase):
144 138
 
145 139
     @utils.mock_plugin()
146 140
     def test_same_section(self, m):
147
-        self.conf_fixture.register_opts(
148
-            to_oslo_opts(utils.MockLoader().get_options()),
149
-            group=self.GROUP)
141
+        opts = loading.get_auth_plugin_conf_options(utils.MockLoader())
142
+        self.conf_fixture.register_opts(opts, group=self.GROUP)
150 143
 
151 144
         loading.register_auth_conf_options(self.conf_fixture.conf,
152 145
                                            group=self.GROUP)
@@ -166,9 +159,8 @@ class ConfTests(utils.TestCase):
166 159
         loading.register_auth_conf_options(self.conf_fixture.conf,
167 160
                                            group=self.GROUP)
168 161
 
169
-        self.conf_fixture.register_opts(to_oslo_opts(
170
-            utils.MockLoader().get_options()),
171
-            group=section)
162
+        opts = loading.get_auth_plugin_conf_options(utils.MockLoader())
163
+        self.conf_fixture.register_opts(opts, group=section)
172 164
         self.conf_fixture.config(group=section,
173 165
                                  auth_type=uuid.uuid4().hex,
174 166
                                  **self.TEST_VALS)

Loading…
Cancel
Save