Merge "In InventoryList.find() raise NotFound if invalid resource class"

This commit is contained in:
Jenkins 2016-08-29 13:30:37 +00:00 committed by Gerrit Code Review
commit bc344458e7
3 changed files with 15 additions and 1 deletions

View File

@ -544,7 +544,11 @@ class InventoryList(base.ObjectListBase, base.NovaObject):
string.
"""
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:
if fields.ResourceClass.index(inv_rec.resource_class) == res_class:

View File

@ -239,6 +239,10 @@ tests:
GET: /resource_providers/$ENVIRON['RP_UUID']/inventories/IPV4_ADDRESS
status: 404
- name: get invalid inventory class
GET: /resource_providers/$ENVIRON['RP_UUID']/inventories/HOUSE
status: 404
- name: create another resource provider
POST: /resource_providers
request_headers:

View File

@ -435,6 +435,12 @@ class TestInventory(test_objects._LocalTest):
self.assertIsNotNone(found)
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):
@mock.patch('nova.objects.Allocation._create_in_db',