Browse Source

Merge "Fix plugin loading tests"

Jenkins 3 years ago
parent
commit
34368ade9b

+ 1
- 1
keystoneauth1/loading/_plugins/identity/v3.py View File

@@ -62,7 +62,7 @@ class Token(BaseV3Loader):
62 62
 
63 63
     @property
64 64
     def plugin_class(self):
65
-        return identity.Token
65
+        return identity.V3Token
66 66
 
67 67
     def get_options(self):
68 68
         options = super(Token, self).get_options()

+ 1
- 0
keystoneauth1/loading/base.py View File

@@ -59,6 +59,7 @@ def get_plugin_loader(name):
59 59
     """
60 60
     try:
61 61
         mgr = stevedore.DriverManager(namespace=PLUGIN_NAMESPACE,
62
+                                      invoke_on_load=True,
62 63
                                       name=name)
63 64
     except RuntimeError:
64 65
         raise exceptions.NoMatchingPlugin(name)

+ 1
- 1
keystoneauth1/loading/cli.py View File

@@ -48,7 +48,7 @@ def register_argparse_arguments(parser, argv, default=None):
48 48
     if not options.os_auth_plugin:
49 49
         return None
50 50
 
51
-    if isinstance(options.os_auth_plugin, type):
51
+    if isinstance(options.os_auth_plugin, base.BaseLoader):
52 52
         msg = 'Default Authentication options'
53 53
         plugin = options.os_auth_plugin
54 54
     else:

+ 13
- 1
keystoneauth1/loading/opts.py View File

@@ -71,6 +71,18 @@ class Opt(object):
71 71
                        deprecated_opts=deprecated_opts,
72 72
                        metavar=self.metavar)
73 73
 
74
+    def __eq__(self, other):
75
+        return (type(self) == type(other) and
76
+                self.name == other.name and
77
+                self.type == other.type and
78
+                self.help == other.help and
79
+                self.secret == other.secret and
80
+                self.required == other.required and
81
+                self.dest == other.dest and
82
+                self.deprecated == other.deprecated and
83
+                self.default == other.default and
84
+                self.metavar == other.metavar)
85
+
74 86
     @property
75 87
     def _all_opts(self):
76 88
         return itertools.chain([self], self.deprecated)
@@ -83,7 +95,7 @@ class Opt(object):
83 95
     def argparse_default(self):
84 96
         # select the first ENV that is not false-y or return None
85 97
         for o in self._all_opts:
86
-            v = os.environ.get('OS_%s' % self.name.replace('-', '_').upper())
98
+            v = os.environ.get('OS_%s' % o.name.replace('-', '_').upper())
87 99
             if v:
88 100
                 return v
89 101
 

+ 8
- 3
keystoneauth1/tests/unit/auth/utils.py View File

@@ -20,6 +20,7 @@ from keystoneauth1 import access
20 20
 from keystoneauth1 import exceptions
21 21
 from keystoneauth1 import fixture
22 22
 from keystoneauth1 import loading
23
+from keystoneauth1.loading import base
23 24
 from keystoneauth1 import plugin
24 25
 from keystoneauth1 import session
25 26
 from keystoneauth1.tests.unit import utils
@@ -42,8 +43,12 @@ class MockPlugin(plugin.BaseAuthPlugin):
42 43
 
43 44
 class BoolType(object):
44 45
 
46
+    def __eq__(self, other):
47
+        # hack around oslo.config type comparison
48
+        return type(self) == type(other)
49
+
45 50
     def __call__(self, value):
46
-        return value.lower() in ('1', 'true', 't', 'yes', 'y')
51
+        return str(value).lower() in ('1', 'true', 't', 'yes', 'y')
47 52
 
48 53
 
49 54
 class MockLoader(loading.BaseLoader):
@@ -76,8 +81,8 @@ class MockManager(object):
76 81
 def mock_plugin(f):
77 82
     @functools.wraps(f)
78 83
     def inner(*args, **kwargs):
79
-        with mock.patch.object(loading, 'get_plugin_loader') as m:
80
-            m.return_value = MockPlugin
84
+        with mock.patch.object(base, 'get_plugin_loader') as m:
85
+            m.return_value = MockLoader()
81 86
             args = list(args) + [m]
82 87
             return f(*args, **kwargs)
83 88
 

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


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

@@ -16,12 +16,12 @@ import uuid
16 16
 import fixtures
17 17
 import mock
18 18
 
19
-from keystoneauth1 import base
20 19
 from keystoneauth1 import loading
20
+from keystoneauth1 import plugin
21 21
 from keystoneauth1.tests.unit.auth import utils
22 22
 
23 23
 
24
-class TesterPlugin(base.BaseAuthPlugin):
24
+class TesterPlugin(plugin.BaseAuthPlugin):
25 25
 
26 26
     def get_token(self, *args, **kwargs):
27 27
         return None
@@ -71,7 +71,7 @@ class CliTests(utils.TestCase):
71 71
         name = uuid.uuid4().hex
72 72
         argv = ['--os-auth-plugin', name]
73 73
         ret = loading.register_argparse_arguments(self.p, argv)
74
-        self.assertIs(utils.MockPlugin, ret)
74
+        self.assertIsInstance(ret, utils.MockLoader)
75 75
 
76 76
         for n in ('--os-a-int', '--os-a-bool', '--os-a-float'):
77 77
             self.assertIn(n, self.p.format_usage())
@@ -87,7 +87,7 @@ class CliTests(utils.TestCase):
87 87
                 '--os-a-bool', str(self.a_bool)]
88 88
 
89 89
         klass = loading.register_argparse_arguments(self.p, argv)
90
-        self.assertIs(utils.MockPlugin, klass)
90
+        self.assertIsInstance(klass, utils.MockLoader)
91 91
 
92 92
         opts = self.p.parse_args(argv)
93 93
         self.assertEqual(name, opts.os_auth_plugin)
@@ -107,7 +107,7 @@ class CliTests(utils.TestCase):
107 107
                 '--os-a-float', str(self.a_float)]
108 108
 
109 109
         klass = loading.register_argparse_arguments(self.p, argv)
110
-        self.assertIs(utils.MockPlugin, klass)
110
+        self.assertIsInstance(klass, utils.MockLoader)
111 111
 
112 112
         opts = self.p.parse_args(argv)
113 113
         self.assertEqual(name, opts.os_auth_plugin)
@@ -121,7 +121,7 @@ class CliTests(utils.TestCase):
121 121
     def test_with_default_string_value(self, m):
122 122
         name = uuid.uuid4().hex
123 123
         klass = loading.register_argparse_arguments(self.p, [], default=name)
124
-        self.assertIs(utils.MockPlugin, klass)
124
+        self.assertIsInstance(klass, utils.MockLoader)
125 125
         m.assert_called_once_with(name)
126 126
 
127 127
     @utils.mock_plugin
@@ -132,29 +132,29 @@ class CliTests(utils.TestCase):
132 132
         klass = loading.register_argparse_arguments(self.p,
133 133
                                                     argv,
134 134
                                                     default=default)
135
-        self.assertIs(utils.MockPlugin, klass)
135
+        self.assertIsInstance(klass, utils.MockLoader)
136 136
         m.assert_called_once_with(name)
137 137
 
138 138
     @utils.mock_plugin
139 139
     def test_with_default_type_value(self, m):
140 140
         klass = loading.register_argparse_arguments(self.p,
141 141
                                                     [],
142
-                                                    default=utils.MockPlugin)
143
-        self.assertIs(utils.MockPlugin, klass)
142
+                                                    default=utils.MockLoader())
143
+        self.assertIsInstance(klass, utils.MockLoader)
144 144
         self.assertEqual(0, m.call_count)
145 145
 
146 146
     @utils.mock_plugin
147 147
     def test_overrides_default_type_value(self, m):
148 148
         # using this test plugin would fail if called because there
149 149
         # is no get_options() function
150
-        class TestPlugin(object):
150
+        class TestLoader(object):
151 151
             pass
152 152
         name = uuid.uuid4().hex
153 153
         argv = ['--os-auth-plugin', name]
154 154
         klass = loading.register_argparse_arguments(self.p,
155 155
                                                     argv,
156
-                                                    default=TestPlugin)
157
-        self.assertIs(utils.MockPlugin, klass)
156
+                                                    default=TestLoader)
157
+        self.assertIsInstance(klass, utils.MockLoader)
158 158
         m.assert_called_once_with(name)
159 159
 
160 160
     @utils.mock_plugin

+ 22
- 12
keystoneauth1/tests/unit/loading/test_conf.py View File

@@ -23,6 +23,10 @@ from keystoneauth1.loading._plugins.identity import v3
23 23
 from keystoneauth1.tests.unit.auth import utils
24 24
 
25 25
 
26
+def to_oslo_opts(opts):
27
+    return [o._to_oslo_opt() for o in opts]
28
+
29
+
26 30
 class ConfTests(utils.TestCase):
27 31
 
28 32
     def setUp(self):
@@ -45,8 +49,9 @@ class ConfTests(utils.TestCase):
45 49
         self.conf_fixture.config(auth_section=section, group=self.GROUP)
46 50
         loading.register_conf_options(self.conf_fixture.conf, group=self.GROUP)
47 51
 
48
-        self.conf_fixture.register_opts(v2.Password.get_options(),
49
-                                        group=section)
52
+        self.conf_fixture.register_opts(
53
+            to_oslo_opts(v2.Password().get_options()),
54
+            group=section)
50 55
 
51 56
         self.conf_fixture.config(auth_plugin=self.V2PASS,
52 57
                                  username=username,
@@ -72,7 +77,7 @@ class ConfTests(utils.TestCase):
72 77
         self.conf_fixture.config(auth_section=section, group=self.GROUP)
73 78
         loading.register_conf_options(self.conf_fixture.conf, group=self.GROUP)
74 79
 
75
-        self.conf_fixture.register_opts(v3.Token().get_options(),
80
+        self.conf_fixture.register_opts(to_oslo_opts(v3.Token().get_options()),
76 81
                                         group=section)
77 82
 
78 83
         self.conf_fixture.config(auth_plugin=self.V3TOKEN,
@@ -107,11 +112,12 @@ class ConfTests(utils.TestCase):
107 112
 
108 113
     @mock.patch('stevedore.DriverManager')
109 114
     def test_other_params(self, m):
110
-        m.return_value = utils.MockManager(utils.MockPlugin)
115
+        m.return_value = utils.MockManager(utils.MockLoader())
111 116
         driver_name = uuid.uuid4().hex
112 117
 
113
-        self.conf_fixture.register_opts(utils.MockPlugin.get_options(),
114
-                                        group=self.GROUP)
118
+        self.conf_fixture.register_opts(
119
+            to_oslo_opts(utils.MockLoader().get_options()),
120
+            group=self.GROUP)
115 121
         self.conf_fixture.config(auth_plugin=driver_name,
116 122
                                  group=self.GROUP,
117 123
                                  **self.TEST_VALS)
@@ -120,12 +126,15 @@ class ConfTests(utils.TestCase):
120 126
         self.assertTestVals(a)
121 127
 
122 128
         m.assert_called_once_with(namespace=loading.PLUGIN_NAMESPACE,
123
-                                  name=driver_name)
129
+                                  name=driver_name,
130
+                                  invoke_on_load=True)
124 131
 
125 132
     @utils.mock_plugin
126 133
     def test_same_section(self, m):
127
-        self.conf_fixture.register_opts(utils.MockPlugin.get_options(),
128
-                                        group=self.GROUP)
134
+        self.conf_fixture.register_opts(
135
+            to_oslo_opts(utils.MockLoader().get_options()),
136
+            group=self.GROUP)
137
+
129 138
         loading.register_conf_options(self.conf_fixture.conf, group=self.GROUP)
130 139
         self.conf_fixture.config(auth_plugin=uuid.uuid4().hex,
131 140
                                  group=self.GROUP,
@@ -141,8 +150,9 @@ class ConfTests(utils.TestCase):
141 150
         self.conf_fixture.config(auth_section=section, group=self.GROUP)
142 151
         loading.register_conf_options(self.conf_fixture.conf, group=self.GROUP)
143 152
 
144
-        self.conf_fixture.register_opts(utils.MockPlugin.get_options(),
145
-                                        group=section)
153
+        self.conf_fixture.register_opts(to_oslo_opts(
154
+            utils.MockLoader().get_options()),
155
+            group=section)
146 156
         self.conf_fixture.config(group=section,
147 157
                                  auth_plugin=uuid.uuid4().hex,
148 158
                                  **self.TEST_VALS)
@@ -168,6 +178,6 @@ class ConfTests(utils.TestCase):
168 178
 
169 179
     def test_get_named(self):
170 180
         loaded_opts = loading.get_plugin_options('v2password')
171
-        plugin_opts = v2.Password.get_options()
181
+        plugin_opts = v2.Password().get_options()
172 182
 
173 183
         self.assertEqual(plugin_opts, loaded_opts)

Loading…
Cancel
Save