Merge "Fix using a variable which is not defined"
This commit is contained in:
commit
a8c184362b
novaclient
@ -301,3 +301,23 @@ class ValidationsTestCase(test_utils.TestCase):
|
||||
self.fail("Invalid key passed validation: %s" % key)
|
||||
except exceptions.CommandError as ce:
|
||||
self.assertTrue(key in 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))
|
||||
|
@ -57,13 +57,14 @@ def get_resource_manager_extra_kwargs(f, args, allow_conflicts=False):
|
||||
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:
|
||||
raise Exception(_("Hook '%(hook_name)s' is attempting to redefine"
|
||||
" attributes '%(conflicting_keys)s'") %
|
||||
{'hook_name': hook_name,
|
||||
'conflicting_keys': conflicting_keys})
|
||||
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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user