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
This commit is contained in:
Sirushti Murugesan 2014-09-05 02:14:41 +05:30
parent 12b3bd4360
commit 95fe521a18
4 changed files with 20 additions and 13 deletions

View File

@ -81,7 +81,7 @@ def format_stack_outputs(stack, outputs):
return [format_stack_output(key) for key in 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 Return a representation of the given stack that matches the API output
expectations. expectations.
@ -96,9 +96,6 @@ def format_stack(stack):
api.STACK_PARAMETERS: stack.parameters.map(str), api.STACK_PARAMETERS: stack.parameters.map(str),
api.STACK_DESCRIPTION: stack.t[stack.t.DESCRIPTION], api.STACK_DESCRIPTION: stack.t[stack.t.DESCRIPTION],
api.STACK_TMPL_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_CAPABILITIES: [], # TODO Not implemented yet
api.STACK_DISABLE_ROLLBACK: stack.disable_rollback, api.STACK_DISABLE_ROLLBACK: stack.disable_rollback,
api.STACK_TIMEOUT: stack.timeout_mins, api.STACK_TIMEOUT: stack.timeout_mins,
@ -106,6 +103,14 @@ def format_stack(stack):
api.STACK_PARENT: stack.owner_id, 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 # allow users to view the outputs of stacks
if (stack.action != stack.DELETE and stack.status != stack.IN_PROGRESS): if (stack.action != stack.DELETE and stack.status != stack.IN_PROGRESS):
info[api.STACK_OUTPUTS] = format_stack_outputs(stack, stack.outputs) 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 map(format_resource, res)
return format_stack_resource(res, with_props=True) 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_resources = map(format_resource, stack.preview_resources())
fmt_stack['resources'] = fmt_resources fmt_stack['resources'] = fmt_resources

View File

@ -83,8 +83,8 @@ class Stack(collections.Mapping):
self.context = context self.context = context
self.t = tmpl self.t = tmpl
self.name = stack_name self.name = stack_name
self.action = action self.action = self.CREATE if action is None else action
self.status = status self.status = self.IN_PROGRESS if status is None else status
self.status_reason = status_reason self.status_reason = status_reason
self.timeout_mins = timeout_mins self.timeout_mins = timeout_mins
self.disable_rollback = disable_rollback self.disable_rollback = disable_rollback

View File

@ -211,6 +211,9 @@ class FormatTest(HeatTestCase):
stack = api.format_stack_preview(self.stack) stack = api.format_stack_preview(self.stack)
self.assertIsInstance(stack, dict) 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.assertEqual('test_stack', stack['stack_name'])
self.assertIn('resources', stack) self.assertIn('resources', stack)
self.assertEqual(['fmt1', ['fmt2', ['fmt3']]], stack['resources']) self.assertEqual(['fmt1', ['fmt2', ['fmt3']]], stack['resources'])
@ -230,11 +233,10 @@ class FormatTest(HeatTestCase):
'description': 'No description', 'description': 'No description',
'disable_rollback': True, 'disable_rollback': True,
'notification_topics': [], 'notification_topics': [],
'outputs': [], 'stack_action': 'CREATE',
'stack_action': '',
'stack_name': 'test_stack', 'stack_name': 'test_stack',
'stack_owner': 'test_username', 'stack_owner': 'test_username',
'stack_status': '', 'stack_status': 'IN_PROGRESS',
'stack_status_reason': '', 'stack_status_reason': '',
'template_description': 'No description', 'template_description': 'No description',
'timeout_mins': None, 'timeout_mins': None,

View File

@ -954,7 +954,7 @@ class StackTest(HeatTestCase):
def test_state_defaults(self): def test_state_defaults(self):
stack = parser.Stack(self.ctx, 'test_stack', self.tmpl) 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) self.assertEqual('', stack.status_reason)
def test_timeout_secs_default(self): def test_timeout_secs_default(self):
@ -1177,11 +1177,11 @@ class StackTest(HeatTestCase):
stack_user_project_id='234') stack_user_project_id='234')
self.stack.store() self.stack.store()
info = self.stack.prepare_abandon() info = self.stack.prepare_abandon()
self.assertIsNone(info['action']) self.assertEqual('CREATE', info['action'])
self.assertIn('id', info) self.assertIn('id', info)
self.assertEqual('stack_details_test', info['name']) self.assertEqual('stack_details_test', info['name'])
self.assertEqual(json.loads(resources), info['resources']) self.assertEqual(json.loads(resources), info['resources'])
self.assertIsNone(info['status']) self.assertEqual('IN_PROGRESS', info['status'])
self.assertEqual(tpl, info['template']) self.assertEqual(tpl, info['template'])
self.assertEqual('123', info['project_id']) self.assertEqual('123', info['project_id'])
self.assertEqual('234', info['stack_user_project_id']) self.assertEqual('234', info['stack_user_project_id'])