From ccdb9c9ae6cae1e3e62e8710349abe98b9c9081d Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Tue, 31 May 2016 11:19:02 +0800 Subject: [PATCH] Show 'deletion_time' for stack-list/stack-show apis We support to get the deleted stacks by filter in stack-list api, support to show the deleted stack by stack-id, so to show the 'deletion_time' info of stacks. Change-Id: I8c55fe7f6a899ca66aa3fef15c93195c03c5aa11 Closes-Bug: #1587214 --- api-ref/source/v1/samples/stacks-list-response.json | 3 ++- api-ref/source/v1/stacks.inc | 1 + heat/engine/api.py | 5 +++++ heat/engine/stack.py | 6 ++++-- heat/tests/test_engine_api_utils.py | 1 + heat/tests/test_engine_service.py | 6 ++++++ heat/tests/test_stack.py | 3 ++- 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/api-ref/source/v1/samples/stacks-list-response.json b/api-ref/source/v1/samples/stacks-list-response.json index 112fcb1303..5cf040f682 100644 --- a/api-ref/source/v1/samples/stacks-list-response.json +++ b/api-ref/source/v1/samples/stacks-list-response.json @@ -17,7 +17,8 @@ "tags": null, "parent": null, "stack_owner": null, - "stack_user_project_id": "71510cbd459a49ac989ca1055de7038b" + "stack_user_project_id": "71510cbd459a49ac989ca1055de7038b", + "deletion_time": null } ] } diff --git a/api-ref/source/v1/stacks.inc b/api-ref/source/v1/stacks.inc index c4bd089b59..c5cdc71997 100644 --- a/api-ref/source/v1/stacks.inc +++ b/api-ref/source/v1/stacks.inc @@ -567,6 +567,7 @@ Response Parameters - tags: tags - creation_time: creation_time - updated_time: updated_time + - deletion_time: deleted_at - stack_status: stack_status - stack_owner: owner_id - stack_user_project_id: stack_user_project_id diff --git a/heat/engine/api.py b/heat/engine/api.py index 125f062aed..a5ef84afde 100644 --- a/heat/engine/api.py +++ b/heat/engine/api.py @@ -212,11 +212,13 @@ def format_stack(stack, preview=False, resolve_outputs=True): """ updated_time = stack.updated_time and stack.updated_time.isoformat() created_time = stack.created_time or timeutils.utcnow() + deleted_time = stack.deleted_time and stack.deleted_time.isoformat() info = { rpc_api.STACK_NAME: stack.name, rpc_api.STACK_ID: dict(stack.identifier()), rpc_api.STACK_CREATION_TIME: created_time.isoformat(), rpc_api.STACK_UPDATED_TIME: updated_time, + rpc_api.STACK_DELETION_TIME: deleted_time, rpc_api.STACK_NOTIFICATION_TOPICS: [], # TODO(therve) Not implemented rpc_api.STACK_PARAMETERS: stack.parameters.map(six.text_type), rpc_api.STACK_DESCRIPTION: stack.t[stack.t.DESCRIPTION], @@ -255,6 +257,8 @@ def format_stack_db_object(stack): """ updated_time = stack.updated_at and stack.updated_at.isoformat() created_time = stack.created_at + deleted_time = stack.deleted_at and stack.deleted_at.isoformat() + tags = None if stack.tags: tags = [t.tag for t in stack.tags] @@ -267,6 +271,7 @@ def format_stack_db_object(stack): rpc_api.STACK_STATUS_DATA: stack.status_reason, rpc_api.STACK_CREATION_TIME: created_time.isoformat(), rpc_api.STACK_UPDATED_TIME: updated_time, + rpc_api.STACK_DELETION_TIME: deleted_time, rpc_api.STACK_OWNER: stack.username, rpc_api.STACK_PARENT: stack.owner_id, rpc_api.STACK_USER_PROJECT_ID: stack.stack_user_project_id, diff --git a/heat/engine/stack.py b/heat/engine/stack.py index e0c7cee5ce..13ff306d90 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -128,7 +128,7 @@ class Stack(collections.Mapping): nested_depth=0, strict_validate=True, convergence=False, current_traversal=None, tags=None, prev_raw_template_id=None, current_deps=None, cache_data=None, resource_validate=True, - service_check_defer=False): + service_check_defer=False, deleted_time=None): """Initialise the Stack. @@ -178,6 +178,7 @@ class Stack(collections.Mapping): self.stack_user_project_id = stack_user_project_id self.created_time = created_time self.updated_time = updated_time + self.deleted_time = deleted_time self.user_creds_id = user_creds_id self.nested_depth = nested_depth self.convergence = convergence @@ -529,7 +530,8 @@ class Stack(collections.Mapping): current_traversal=stack.current_traversal, prev_raw_template_id=stack.prev_raw_template_id, current_deps=stack.current_deps, cache_data=cache_data, - nested_depth=stack.nested_depth) + nested_depth=stack.nested_depth, + deleted_time=stack.deleted_at) def get_kwargs_for_cloning(self, keep_status=False, only_db=False): """Get common kwargs for calling Stack() for cloning. diff --git a/heat/tests/test_engine_api_utils.py b/heat/tests/test_engine_api_utils.py index addfc3d6a0..c25f9f728d 100644 --- a/heat/tests/test_engine_api_utils.py +++ b/heat/tests/test_engine_api_utils.py @@ -346,6 +346,7 @@ class FormatTest(common.HeatTestCase): expected_stack_info = { 'capabilities': [], 'creation_time': '1970-01-01T00:00:00', + 'deletion_time': None, 'description': 'No description', 'disable_rollback': True, 'notification_topics': [], diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 4422539426..c0c75a255e 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -469,6 +469,8 @@ class StackServiceTest(common.HeatTestCase): for s in sl: self.assertIn('creation_time', s) self.assertIn('updated_time', s) + self.assertIn('deletion_time', s) + self.assertIsNone(s['deletion_time']) self.assertIn('stack_identity', s) self.assertIsNotNone(s['stack_identity']) self.assertIn('stack_name', s) @@ -892,6 +894,8 @@ class StackServiceTest(common.HeatTestCase): s = sl[0] self.assertIn('creation_time', s) self.assertIn('updated_time', s) + self.assertIn('deletion_time', s) + self.assertIsNone(s['deletion_time']) self.assertIn('stack_identity', s) self.assertIsNotNone(s['stack_identity']) self.assertIn('stack_name', s) @@ -913,6 +917,8 @@ class StackServiceTest(common.HeatTestCase): s = sl[0] self.assertIn('creation_time', s) self.assertIn('updated_time', s) + self.assertIn('deletion_time', s) + self.assertIsNone(s['deletion_time']) self.assertIn('stack_identity', s) self.assertIsNotNone(s['stack_identity']) self.assertIn('stack_name', s) diff --git a/heat/tests/test_stack.py b/heat/tests/test_stack.py index 66201fb213..2e6b0868c4 100644 --- a/heat/tests/test_stack.py +++ b/heat/tests/test_stack.py @@ -387,7 +387,8 @@ class StackTest(common.HeatTestCase): current_traversal=self.stack.current_traversal, prev_raw_template_id=None, current_deps=None, cache_data=None, - nested_depth=0) + nested_depth=0, + deleted_time=None) self.m.ReplayAll() stack.Stack.load(self.ctx, stack_id=self.stack.id)