Merge "Engine changes for API param to show soft-deleted stacks"

This commit is contained in:
Jenkins 2014-05-08 23:13:15 +00:00 committed by Gerrit Code Review
commit 7bb430b47f
5 changed files with 32 additions and 9 deletions

View File

@ -123,9 +123,11 @@ def stack_get_by_name(context, stack_name):
def stack_get_all(context, limit=None, sort_keys=None, marker=None,
sort_dir=None, filters=None, tenant_safe=True):
sort_dir=None, filters=None, tenant_safe=True,
show_deleted=False):
return IMPL.stack_get_all(context, limit, sort_keys,
marker, sort_dir, filters, tenant_safe)
marker, sort_dir, filters, tenant_safe,
show_deleted)
def stack_get_all_by_owner_id(context, owner_id):

View File

@ -349,8 +349,9 @@ def _paginate_query(context, query, model, limit=None, sort_keys=None,
return query
def _query_stack_get_all(context, tenant_safe=True):
query = soft_delete_aware_query(context, models.Stack).\
def _query_stack_get_all(context, tenant_safe=True, show_deleted=False):
query = soft_delete_aware_query(context, models.Stack,
show_deleted=show_deleted).\
filter_by(owner_id=None)
if tenant_safe:
@ -360,8 +361,10 @@ def _query_stack_get_all(context, tenant_safe=True):
def stack_get_all(context, limit=None, sort_keys=None, marker=None,
sort_dir=None, filters=None, tenant_safe=True):
query = _query_stack_get_all(context, tenant_safe)
sort_dir=None, filters=None, tenant_safe=True,
show_deleted=False):
query = _query_stack_get_all(context, tenant_safe,
show_deleted=show_deleted)
return _filter_and_page_query(context, query, limit, sort_keys,
marker, sort_dir, filters).all()

View File

@ -403,7 +403,8 @@ class EngineService(service.Service):
@request_context
def list_stacks(self, cnxt, limit=None, marker=None, sort_keys=None,
sort_dir=None, filters=None, tenant_safe=True):
sort_dir=None, filters=None, tenant_safe=True,
show_deleted=False):
"""
The list_stacks method returns attributes of all stacks. It supports
pagination (``limit`` and ``marker``), sorting (``sort_keys`` and
@ -416,9 +417,9 @@ class EngineService(service.Service):
:param sort_dir: the direction of the sort ('asc' or 'desc')
:param filters: a dict with attribute:value to filter the list
:param tenant_safe: if true, scope the request by the current tenant
:param show_deleted: if true, show soft-deleted stacks
:returns: a list of formatted stacks
"""
def format_stack_details(stacks):
for s in stacks:
try:
@ -432,7 +433,8 @@ class EngineService(service.Service):
yield api.format_stack(stack)
stacks = db_api.stack_get_all(cnxt, limit, sort_keys, marker,
sort_dir, filters, tenant_safe) or []
sort_dir, filters, tenant_safe,
show_deleted) or []
return list(format_stack_details(stacks))
@request_context

View File

@ -1708,6 +1708,7 @@ class StackServiceTest(HeatTestCase):
mock.ANY,
filters,
mock.ANY,
mock.ANY,
)
@mock.patch.object(db_api, 'stack_get_all')
@ -1720,6 +1721,7 @@ class StackServiceTest(HeatTestCase):
mock.ANY,
mock.ANY,
True,
mock.ANY,
)
@mock.patch.object(db_api, 'stack_get_all')
@ -1732,6 +1734,7 @@ class StackServiceTest(HeatTestCase):
mock.ANY,
mock.ANY,
False,
mock.ANY,
)
@mock.patch.object(db_api, 'stack_count_all')

View File

@ -387,6 +387,19 @@ class SqlAlchemyTest(HeatTestCase):
st_db = db_api.stack_get_all(self.ctx)
self.assertEqual(1, len(st_db))
def test_stack_get_all_show_deleted(self):
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
st_db = db_api.stack_get_all(self.ctx)
self.assertEqual(3, len(st_db))
stacks[0].delete()
st_db = db_api.stack_get_all(self.ctx)
self.assertEqual(2, len(st_db))
st_db = db_api.stack_get_all(self.ctx, show_deleted=True)
self.assertEqual(3, len(st_db))
def test_stack_get_all_with_filters(self):
self._setup_test_stack('foo', UUID1)
self._setup_test_stack('bar', UUID2)