Merge "Fix logic for "nova flavor-show 0#""
This commit is contained in:
commit
daa33c56c9
novaclient
@ -42,9 +42,15 @@ class FakeManager(base.ManagerWithFind):
|
||||
resources = [
|
||||
FakeResource('1234', {'name': 'entity_one'}),
|
||||
FakeResource(UUID, {'name': 'entity_two'}),
|
||||
FakeResource('5678', {'name': '9876'})
|
||||
FakeResource('5678', {'name': '9876'}),
|
||||
FakeResource('01234', {'name': 'entity_three'})
|
||||
]
|
||||
|
||||
is_alphanum_id_allowed = None
|
||||
|
||||
def __init__(self, alphanum_id_allowed=False):
|
||||
self.is_alphanum_id_allowed = alphanum_id_allowed
|
||||
|
||||
def get(self, resource_id):
|
||||
for resource in self.resources:
|
||||
if resource.id == str(resource_id):
|
||||
@ -117,6 +123,11 @@ class FindResourceTestCase(test_utils.TestCase):
|
||||
output = utils.find_resource(display_manager, 'entity_three')
|
||||
self.assertEqual(output, display_manager.get('4242'))
|
||||
|
||||
def test_find_in_alphanum_allowd_manager_by_str_id_(self):
|
||||
alphanum_manager = FakeManager(True)
|
||||
output = utils.find_resource(alphanum_manager, '01234')
|
||||
self.assertEqual(output, alphanum_manager.get('01234'))
|
||||
|
||||
|
||||
class _FakeResult(object):
|
||||
def __init__(self, name, value):
|
||||
|
@ -254,7 +254,14 @@ def print_dict(d, dict_property="Property", dict_value="Value", wrap=0):
|
||||
|
||||
def find_resource(manager, name_or_id, **find_args):
|
||||
"""Helper for the _find_* methods."""
|
||||
# first try to get entity as integer id
|
||||
# for str id which is not uuid (for Flavor search currently)
|
||||
if getattr(manager, 'is_alphanum_id_allowed', False):
|
||||
try:
|
||||
return manager.get(name_or_id)
|
||||
except exceptions.NotFound:
|
||||
pass
|
||||
|
||||
# try to get entity as integer id
|
||||
try:
|
||||
return manager.get(int(name_or_id))
|
||||
except (TypeError, ValueError, exceptions.NotFound):
|
||||
@ -270,13 +277,6 @@ def find_resource(manager, name_or_id, **find_args):
|
||||
except (TypeError, ValueError, exceptions.NotFound):
|
||||
pass
|
||||
|
||||
# for str id which is not uuid (for Flavor search currently)
|
||||
if getattr(manager, 'is_alphanum_id_allowed', False):
|
||||
try:
|
||||
return manager.get(name_or_id)
|
||||
except exceptions.NotFound:
|
||||
pass
|
||||
|
||||
try:
|
||||
try:
|
||||
return manager.find(human_id=name_or_id, **find_args)
|
||||
|
Loading…
x
Reference in New Issue
Block a user