diff options
author | Andrey Kurilin <andr.kurilin@gmail.com> | 2017-12-15 18:24:53 +0200 |
---|---|---|
committer | Stephen Finucane <stephenfin@redhat.com> | 2018-02-09 15:26:08 +0000 |
commit | ca27736810a41080761e604e09c6763aaed07ed7 (patch) | |
tree | 8597094a2cba0c00b842eaa4cac7ebe6027de9a7 | |
parent | beb90ec793dff9e55e67d4ebe80d3f87ec2f0dce (diff) | |
download | python-novaclient-ca27736810a41080761e604e09c6763aaed07ed7.tar.gz |
Remove 2 redundant methods
I suppose that methods get_resource_manager_extra_kwargs and
add_resource_manager_extra_kwargs_hook were designed in those days when
Nova API had extensions.
Nowdays, Nova API has strict schema validation of requests, so no
additional arguments are allowed and these methods look redundant.
The fact that get_resource_manager_extra_kwargs lists of the objects
added by add_resource_manager_extra_kwargs_hook whereas
add_resource_manager_extra_kwargs_hook is not called anywhere
doesn't add chances for leaving these methods in our code.
Compatibility: both methods are designed for CLI and the CLI behaviour
will not change after removing them, so we can do a cleanup without
following standard deprecation cycle.
Change-Id: Id61457c3db8a17e2294dc579b2519873927fec48
-rw-r--r-- | novaclient/tests/unit/test_utils.py | 20 | ||||
-rw-r--r-- | novaclient/utils.py | 37 | ||||
-rw-r--r-- | novaclient/v2/shell.py | 14 | ||||
-rw-r--r-- | releasenotes/notes/get-rid-off-redundant-methods-47e679c13e88f28a.yaml | 10 |
4 files changed, 14 insertions, 67 deletions
diff --git a/novaclient/tests/unit/test_utils.py b/novaclient/tests/unit/test_utils.py index 372e6f00..46ffbc13 100644 --- a/novaclient/tests/unit/test_utils.py +++ b/novaclient/tests/unit/test_utils.py @@ -380,26 +380,6 @@ class ValidationsTestCase(test_utils.TestCase): self.assertIn(key, str(ce)) -class ResourceManagerExtraKwargsHookTestCase(test_utils.TestCase): - def test_get_resource_manager_extra_kwargs_hook_test(self): - do_foo = mock.MagicMock() - - def hook1(args): - return {'kwarg1': 'v_hook1'} - - def hook2(args): - return {'kwarg1': 'v_hook2'} - do_foo.resource_manager_kwargs_hooks = [hook1, hook2] - args = {} - exc = self.assertRaises(exceptions.NoUniqueMatch, - utils.get_resource_manager_extra_kwargs, - do_foo, - args) - except_error = ("Hook 'hook2' is attempting to redefine " - "attributes") - self.assertIn(except_error, six.text_type(exc)) - - class DoActionOnManyTestCase(test_utils.TestCase): def _test_do_action_on_many(self, side_effect, fail): diff --git a/novaclient/utils.py b/novaclient/utils.py index df4464e6..8869f696 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -118,43 +118,6 @@ def service_type(stype): return inner -def add_resource_manager_extra_kwargs_hook(f, hook): - """Add hook to bind CLI arguments to ResourceManager calls. - - The `do_foo` calls in shell.py will receive CLI args and then in turn pass - them through to the ResourceManager. Before passing through the args, the - hooks registered here will be called, giving us a chance to add extra - kwargs (taken from the command-line) to what's passed to the - ResourceManager. - """ - if not hasattr(f, 'resource_manager_kwargs_hooks'): - f.resource_manager_kwargs_hooks = [] - - names = [h.__name__ for h in f.resource_manager_kwargs_hooks] - if hook.__name__ not in names: - f.resource_manager_kwargs_hooks.append(hook) - - -def get_resource_manager_extra_kwargs(f, args, allow_conflicts=False): - """Return extra_kwargs by calling resource manager kwargs hooks.""" - hooks = getattr(f, "resource_manager_kwargs_hooks", []) - extra_kwargs = {} - for hook in hooks: - hook_kwargs = hook(args) - hook_name = hook.__name__ - conflicting_keys = set(hook_kwargs.keys()) & set(extra_kwargs.keys()) - if conflicting_keys and not allow_conflicts: - msg = (_("Hook '%(hook_name)s' is attempting to redefine " - "attributes '%(conflicting_keys)s'") % - {'hook_name': hook_name, - 'conflicting_keys': conflicting_keys}) - raise exceptions.NoUniqueMatch(msg) - - extra_kwargs.update(hook_kwargs) - - return extra_kwargs - - def pretty_choice_list(l): return ', '.join("'%s'" % i for i in l) diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index 7c05d169..5fcff2df 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -877,9 +877,6 @@ def do_boot(cs, args): """Boot a new server.""" boot_args, boot_kwargs = _boot(cs, args) - extra_boot_kwargs = utils.get_resource_manager_extra_kwargs(do_boot, args) - boot_kwargs.update(extra_boot_kwargs) - server = cs.servers.create(*boot_args, **boot_kwargs) if boot_kwargs['reservation_id']: new_server = {'reservation_id': server} @@ -1815,13 +1812,11 @@ def do_rebuild(cs, args): else: _password = None - kwargs = utils.get_resource_manager_extra_kwargs(do_rebuild, args) - kwargs['preserve_ephemeral'] = args.preserve_ephemeral - kwargs['name'] = args.name + kwargs = {'preserve_ephemeral': args.preserve_ephemeral, + 'name': args.name, + 'meta': _meta_parsing(args.meta)} if 'description' in args: kwargs['description'] = args.description - meta = _meta_parsing(args.meta) - kwargs['meta'] = meta # 2.57 deprecates the --file option and adds the --user-data and # --user-data-unset options. @@ -1910,8 +1905,7 @@ def do_resize(cs, args): """Resize a server.""" server = _find_server(cs, args.server) flavor = _find_flavor(cs, args.flavor) - kwargs = utils.get_resource_manager_extra_kwargs(do_resize, args) - server.resize(flavor, **kwargs) + server.resize(flavor) if args.poll: _poll_for_status(cs.servers.get, server.id, 'resizing', ['active', 'verify_resize']) diff --git a/releasenotes/notes/get-rid-off-redundant-methods-47e679c13e88f28a.yaml b/releasenotes/notes/get-rid-off-redundant-methods-47e679c13e88f28a.yaml new file mode 100644 index 00000000..954ae395 --- /dev/null +++ b/releasenotes/notes/get-rid-off-redundant-methods-47e679c13e88f28a.yaml @@ -0,0 +1,10 @@ +--- +deprecations: + - | + ``novaclient.utils.add_resource_manager_extra_kwargs_hook`` and + ``novaclient.utils.get_resource_manager_extra_kwargs`` were designed for + supporting extensions in nova/novaclient. Nowadays, this "extensions" + feature is abandoned and both ``add_resource_manager_extra_kwargs_hook``, + ``add_resource_manager_extra_kwargs_hook`` are not used in novaclient's + code. These methods are not documented, so we are removing them without + standard deprecation cycle. |