Fix for passing dict for get_* methods
We are not accepting dicts for the name_or_id parameter, only objects. Change-Id: I31f0f127f71f10a2f11f89e10ac8911816786963
This commit is contained in:
parent
de9bc53b1b
commit
7460ad36d8
@ -207,7 +207,9 @@ def _get_entity(cloud, resource, name_or_id, filters, **kwargs):
|
||||
get_<>_by_id or search_<resource>s methods(Example: network)
|
||||
or a callable to invoke.
|
||||
:param string name_or_id:
|
||||
The name or ID of the entity being filtered or a dict
|
||||
The name or ID of the entity being filtered or an object or dict.
|
||||
If this is an object/dict with an 'id' attr/key, we return it and
|
||||
bypass resource lookup.
|
||||
:param filters:
|
||||
A dictionary of meta data to use for further filtering.
|
||||
OR
|
||||
@ -221,7 +223,8 @@ def _get_entity(cloud, resource, name_or_id, filters, **kwargs):
|
||||
# an additional call, it's simple enough to test to see if we got an
|
||||
# object and just short-circuit return it.
|
||||
|
||||
if hasattr(name_or_id, 'id'):
|
||||
if (hasattr(name_or_id, 'id') or
|
||||
(isinstance(name_or_id, dict) and 'id' in name_or_id)):
|
||||
return name_or_id
|
||||
|
||||
# If a uuid is passed short-circuit it calling the
|
||||
|
@ -326,6 +326,11 @@ class TestUtils(base.TestCase):
|
||||
self.cloud.use_direct_get = True
|
||||
self.assertEqual(obj, _utils._get_entity(self.cloud, '', obj, {}))
|
||||
|
||||
def test_get_entity_pass_dict(self):
|
||||
d = dict(id=uuid4().hex)
|
||||
self.cloud.use_direct_get = True
|
||||
self.assertEqual(d, _utils._get_entity(self.cloud, '', d, {}))
|
||||
|
||||
def test_get_entity_no_use_direct_get(self):
|
||||
# test we are defaulting to the search_<resource> methods
|
||||
# if the use_direct_get flag is set to False(default).
|
||||
|
Loading…
Reference in New Issue
Block a user