Fix logic for "nova flavor-show 0#"
For perviously logic, if flavor id is start with "0Number", int(name_or_id) will convert it to "Number". If flavor id "Number" exist in DB, it will show up for query with "0Number". This fix enter flavor search logic at the beginning. Also add one more UT for this function. Change-Id: Ic48ff4275978404064c0c6fce6f98181660aa84a Fixes: bug 1268456
This commit is contained in:
parent
8e9c038f15
commit
27de89af5f
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):
|
||||
|
@ -250,7 +250,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):
|
||||
@ -266,13 +273,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