Merge "In InventoryList.find() raise NotFound if invalid resource class"
This commit is contained in:
commit
bc344458e7
@ -544,7 +544,11 @@ class InventoryList(base.ObjectListBase, base.NovaObject):
|
|||||||
string.
|
string.
|
||||||
"""
|
"""
|
||||||
if isinstance(res_class, six.string_types):
|
if isinstance(res_class, six.string_types):
|
||||||
res_class = fields.ResourceClass.index(res_class)
|
try:
|
||||||
|
res_class = fields.ResourceClass.index(res_class)
|
||||||
|
except ValueError:
|
||||||
|
raise exception.NotFound("No such resource class '%s'" %
|
||||||
|
res_class)
|
||||||
|
|
||||||
for inv_rec in self.objects:
|
for inv_rec in self.objects:
|
||||||
if fields.ResourceClass.index(inv_rec.resource_class) == res_class:
|
if fields.ResourceClass.index(inv_rec.resource_class) == res_class:
|
||||||
|
@ -239,6 +239,10 @@ tests:
|
|||||||
GET: /resource_providers/$ENVIRON['RP_UUID']/inventories/IPV4_ADDRESS
|
GET: /resource_providers/$ENVIRON['RP_UUID']/inventories/IPV4_ADDRESS
|
||||||
status: 404
|
status: 404
|
||||||
|
|
||||||
|
- name: get invalid inventory class
|
||||||
|
GET: /resource_providers/$ENVIRON['RP_UUID']/inventories/HOUSE
|
||||||
|
status: 404
|
||||||
|
|
||||||
- name: create another resource provider
|
- name: create another resource provider
|
||||||
POST: /resource_providers
|
POST: /resource_providers
|
||||||
request_headers:
|
request_headers:
|
||||||
|
@ -435,6 +435,12 @@ class TestInventory(test_objects._LocalTest):
|
|||||||
self.assertIsNotNone(found)
|
self.assertIsNotNone(found)
|
||||||
self.assertEqual(24, found.total)
|
self.assertEqual(24, found.total)
|
||||||
|
|
||||||
|
# Use an invalid string...
|
||||||
|
error = self.assertRaises(exception.NotFound,
|
||||||
|
inv_list.find,
|
||||||
|
'HOUSE')
|
||||||
|
self.assertIn('No such resource class', str(error))
|
||||||
|
|
||||||
|
|
||||||
class _TestAllocationNoDB(object):
|
class _TestAllocationNoDB(object):
|
||||||
@mock.patch('nova.objects.Allocation._create_in_db',
|
@mock.patch('nova.objects.Allocation._create_in_db',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user