Merge "Remove 2 redundant methods"

This commit is contained in:
Zuul 2018-02-09 19:07:51 +00:00 committed by Gerrit Code Review
commit 1bdf8c65d9
4 changed files with 14 additions and 67 deletions

View File

@ -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):

View File

@ -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)

View File

@ -878,9 +878,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}
@ -1816,13 +1813,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.
@ -1911,8 +1906,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'])

View File

@ -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.