From 95fe521a180bce6587974d736d9e71a6c5be3457 Mon Sep 17 00:00:00 2001 From: Sirushti Murugesan Date: Fri, 5 Sep 2014 02:14:41 +0530 Subject: [PATCH] Set the default state of a stack to CREATE_IN_PROGRESS A stacks status is empty when originally entered into the database. This leads to returning empty status responses back if the engine is pre-occupied with other tasks. This patch sets a stack's status to CREATE_IN_PROGRESS by default when the stack object is created. The stack object is only ever created during create and preview and is loaded otherwise from the database in all the other scenarios. Change-Id: Iab0892896b398530423bbe6c6a623376bf86590e Closes-Bug: #1365399 --- heat/engine/api.py | 15 ++++++++++----- heat/engine/stack.py | 4 ++-- heat/tests/test_engine_api_utils.py | 8 +++++--- heat/tests/test_parser.py | 6 +++--- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/heat/engine/api.py b/heat/engine/api.py index ee441aac0..75359b57f 100644 --- a/heat/engine/api.py +++ b/heat/engine/api.py @@ -81,7 +81,7 @@ def format_stack_outputs(stack, outputs): return [format_stack_output(key) for key in outputs] -def format_stack(stack): +def format_stack(stack, preview=False): ''' Return a representation of the given stack that matches the API output expectations. @@ -96,9 +96,6 @@ def format_stack(stack): api.STACK_PARAMETERS: stack.parameters.map(str), api.STACK_DESCRIPTION: stack.t[stack.t.DESCRIPTION], api.STACK_TMPL_DESCRIPTION: stack.t[stack.t.DESCRIPTION], - api.STACK_ACTION: stack.action or '', - api.STACK_STATUS: stack.status or '', - api.STACK_STATUS_DATA: stack.status_reason, api.STACK_CAPABILITIES: [], # TODO Not implemented yet api.STACK_DISABLE_ROLLBACK: stack.disable_rollback, api.STACK_TIMEOUT: stack.timeout_mins, @@ -106,6 +103,14 @@ def format_stack(stack): api.STACK_PARENT: stack.owner_id, } + if not preview: + update_info = { + api.STACK_ACTION: stack.action or '', + api.STACK_STATUS: stack.status or '', + api.STACK_STATUS_DATA: stack.status_reason, + } + info.update(update_info) + # allow users to view the outputs of stacks if (stack.action != stack.DELETE and stack.status != stack.IN_PROGRESS): info[api.STACK_OUTPUTS] = format_stack_outputs(stack, stack.outputs) @@ -167,7 +172,7 @@ def format_stack_preview(stack): return map(format_resource, res) return format_stack_resource(res, with_props=True) - fmt_stack = format_stack(stack) + fmt_stack = format_stack(stack, preview=True) fmt_resources = map(format_resource, stack.preview_resources()) fmt_stack['resources'] = fmt_resources diff --git a/heat/engine/stack.py b/heat/engine/stack.py index edc6bbbc3..3b4537876 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -83,8 +83,8 @@ class Stack(collections.Mapping): self.context = context self.t = tmpl self.name = stack_name - self.action = action - self.status = status + self.action = self.CREATE if action is None else action + self.status = self.IN_PROGRESS if status is None else status self.status_reason = status_reason self.timeout_mins = timeout_mins self.disable_rollback = disable_rollback diff --git a/heat/tests/test_engine_api_utils.py b/heat/tests/test_engine_api_utils.py index 743cf0d22..0f69ccfc6 100644 --- a/heat/tests/test_engine_api_utils.py +++ b/heat/tests/test_engine_api_utils.py @@ -211,6 +211,9 @@ class FormatTest(HeatTestCase): stack = api.format_stack_preview(self.stack) self.assertIsInstance(stack, dict) + self.assertIsNone(stack.get('status')) + self.assertIsNone(stack.get('action')) + self.assertIsNone(stack.get('status_reason')) self.assertEqual('test_stack', stack['stack_name']) self.assertIn('resources', stack) self.assertEqual(['fmt1', ['fmt2', ['fmt3']]], stack['resources']) @@ -230,11 +233,10 @@ class FormatTest(HeatTestCase): 'description': 'No description', 'disable_rollback': True, 'notification_topics': [], - 'outputs': [], - 'stack_action': '', + 'stack_action': 'CREATE', 'stack_name': 'test_stack', 'stack_owner': 'test_username', - 'stack_status': '', + 'stack_status': 'IN_PROGRESS', 'stack_status_reason': '', 'template_description': 'No description', 'timeout_mins': None, diff --git a/heat/tests/test_parser.py b/heat/tests/test_parser.py index de7bcebc6..969d37d1e 100644 --- a/heat/tests/test_parser.py +++ b/heat/tests/test_parser.py @@ -954,7 +954,7 @@ class StackTest(HeatTestCase): def test_state_defaults(self): stack = parser.Stack(self.ctx, 'test_stack', self.tmpl) - self.assertEqual((None, None), stack.state) + self.assertEqual(('CREATE', 'IN_PROGRESS'), stack.state) self.assertEqual('', stack.status_reason) def test_timeout_secs_default(self): @@ -1177,11 +1177,11 @@ class StackTest(HeatTestCase): stack_user_project_id='234') self.stack.store() info = self.stack.prepare_abandon() - self.assertIsNone(info['action']) + self.assertEqual('CREATE', info['action']) self.assertIn('id', info) self.assertEqual('stack_details_test', info['name']) self.assertEqual(json.loads(resources), info['resources']) - self.assertIsNone(info['status']) + self.assertEqual('IN_PROGRESS', info['status']) self.assertEqual(tpl, info['template']) self.assertEqual('123', info['project_id']) self.assertEqual('234', info['stack_user_project_id'])