diff options
| author | Zuul <zuul@review.openstack.org> | 2018-01-17 04:16:08 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2018-01-17 04:16:08 +0000 |
| commit | 0cbdfd5fcd8c5961036ff65732e758f563ae8465 (patch) | |
| tree | 657c1945a9f6bc56696cf21c29bfacd49ae92e82 /troveclient | |
| parent | 0552a0bec1632fc63cdbbefe52d9382c02b59003 (diff) | |
| parent | c346c7be7138edf4437ace2c7efdeb320d814332 (diff) | |
| download | python-troveclient-0cbdfd5fcd8c5961036ff65732e758f563ae8465.tar.gz | |
Merge "Fix show instance with integer name NotFound"
Diffstat (limited to 'troveclient')
| -rw-r--r-- | troveclient/tests/test_base.py | 4 | ||||
| -rw-r--r-- | troveclient/utils.py | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/troveclient/tests/test_base.py b/troveclient/tests/test_base.py index e3e8970..bc409c2 100644 --- a/troveclient/tests/test_base.py +++ b/troveclient/tests/test_base.py @@ -375,6 +375,10 @@ class FindResourceTestCase(testtools.TestCase): output = utils.find_resource(self.manager, 'entity_three') self.assertEqual(self.manager.get('4242'), output) + def test_find_by_int_name(self): + output = utils.find_resource(self.manager, 9876) + self.assertEqual(self.manager.get('5678'), output) + class ResourceTest(testtools.TestCase): def setUp(self): diff --git a/troveclient/utils.py b/troveclient/utils.py index f4db742..28096a7 100644 --- a/troveclient/utils.py +++ b/troveclient/utils.py @@ -214,10 +214,12 @@ def find_resource(manager, name_or_id): """Helper for the _find_* methods.""" # first try to get entity as integer id - # if the 'id' starts with '0' don't treat it as an int - if isinstance(name_or_id, int) or ( - name_or_id.isdigit() and not name_or_id.startswith('0')): - name_or_id = int(name_or_id) + # When the 'name_or_id' is int, covert it to string. + # Reason is that manager cannot find instance when name_or_id + # is integer and instance name is digital. + # Related to bug/1740015. + if isinstance(name_or_id, int): + name_or_id = six.text_type(name_or_id) elif sys.version_info <= (3, 0): name_or_id = encodeutils.safe_decode(name_or_id) |
