Merge "Do not raise NotFound for resource_get_all_* queries"

This commit is contained in:
Jenkins 2016-07-15 14:02:29 +00:00 committed by Gerrit Code Review
commit b69704a324
3 changed files with 11 additions and 22 deletions

View File

@ -349,10 +349,6 @@ def resource_get_all_by_stack(context, stack_id, filters=None):
query = db_filters.exact_filter(query, models.Resource, filters)
results = query.all()
if not results:
raise exception.NotFound(_("no resources for stack_id %s were found")
% stack_id)
return dict((res.name, res) for res in results)
@ -365,9 +361,6 @@ def resource_get_all_active_by_stack(context, stack_id):
models.Resource.id.notin_(subquery.as_scalar())
).options(orm.joinedload("data")).all()
if not results:
raise exception.NotFound(_("no active resources for stack_id %s were"
" found") % stack_id)
return dict((res.id, res) for res in results)

View File

@ -344,22 +344,19 @@ class Stack(collections.Mapping):
yield nested_res
def db_active_resources_get(self):
try:
return resource_objects.Resource.get_all_active_by_stack(
self.context, self.id)
except exception.NotFound:
return None
resources = resource_objects.Resource.get_all_active_by_stack(
self.context, self.id)
return resources or None
def db_resource_get(self, name):
if not self.id:
return None
if self._db_resources is None:
try:
_db_resources = resource_objects.Resource.get_all_by_stack(
self.context, self.id)
self._db_resources = _db_resources
except exception.NotFound:
_db_resources = resource_objects.Resource.get_all_by_stack(
self.context, self.id)
if not _db_resources:
return None
self._db_resources = _db_resources
return self._db_resources.get(name)
@property

View File

@ -2055,9 +2055,8 @@ class DBAPIStackTest(common.HeatTestCase):
rt_id = stacks[s].raw_template_id
self.assertRaises(exception.NotFound,
db_api.raw_template_get, ctx, rt_id)
self.assertRaises(exception.NotFound,
db_api.resource_get_all_by_stack,
ctx, stacks[s].id)
self.assertEqual({}, db_api.resource_get_all_by_stack(
ctx, stacks[s].id))
self.assertRaises(exception.NotFound,
db_api.raw_template_files_get,
ctx, tmpl_files[tmpl_idx].files_id)
@ -2252,8 +2251,8 @@ class DBAPIResourceTest(common.HeatTestCase):
self.assertEqual('res1', resources.get('res1').name)
self.assertEqual('res2', resources.get('res2').name)
self.assertRaises(exception.NotFound, db_api.resource_get_all_by_stack,
self.ctx, self.stack2.id)
self.assertEqual({}, db_api.resource_get_all_by_stack(
self.ctx, self.stack2.id))
def test_resource_get_all_active_by_stack(self):
values = [