Raise on NodeManager get when invalid identifier provided
When calling the NodeManager get method with resource_id equal to [], {}, (), None, "" or False the client returns a bad data structure. In order to be consistent with the API and the CLI the resource_id is now validated before calling the API and raises ValidationError in case of invalid value. Change-Id: Idb2b424ab17e79da948595fb74df3ef9d81732c0 Closes-Bug: #1652142
This commit is contained in:
parent
e512550ab7
commit
b227a39912
@ -72,8 +72,14 @@ class Manager(object):
|
||||
|
||||
:param resource_id: Identifier of the resource.
|
||||
:param fields: List of specific fields to be returned.
|
||||
:raises exc.ValidationError: For invalid resource_id arg value.
|
||||
"""
|
||||
|
||||
if not resource_id:
|
||||
raise exc.ValidationError(
|
||||
"The identifier argument is invalid. "
|
||||
"Value provided: {!r}".format(resource_id))
|
||||
|
||||
if fields is not None:
|
||||
resource_id = '%s?fields=' % resource_id
|
||||
resource_id += ','.join(fields)
|
||||
|
@ -133,6 +133,12 @@ class ManagerTestCase(testtools.TestCase):
|
||||
self.assertEqual(resource_id, resource.uuid)
|
||||
self.assertEqual(TESTABLE_RESOURCE['attribute1'], resource.attribute1)
|
||||
|
||||
def test__get_invalid_resource_id_raises(self):
|
||||
resource_ids = [[], {}, False, '', 0, None, ()]
|
||||
for resource_id in resource_ids:
|
||||
self.assertRaises(exc.ValidationError, self.manager._get,
|
||||
resource_id=resource_id)
|
||||
|
||||
def test__get_as_dict(self):
|
||||
resource_id = TESTABLE_RESOURCE['uuid']
|
||||
resource = self.manager._get_as_dict(resource_id)
|
||||
|
Loading…
Reference in New Issue
Block a user