DELETE_COMPLETE = 'DELETE_COMPLETE'
def __init__(self, context, stack_name, template, parameters=None,
- stack_id=None):
+ stack_id=None, state=None, state_description=''):
'''
Initialise from a context, name, Template object and (optionally)
Parameters object. The database ID may also be initialised, if the
self.context = context
self.t = template
self.name = stack_name
+ self.state = state
+ self.state_description = state_description
if parameters is None:
parameters = Parameters(stack_name, template)
template = Template.load(context, s.raw_template_id)
params = Parameters(s.name, template, s.parameters)
- stack = cls(context, s.name, template, params, stack_id)
+ stack = cls(context, s.name, template, params,
+ stack_id, s.status, s.status_reason)
return stack
if self.id is None:
new_creds = db_api.user_creds_create(self.context.to_dict())
- s = {'name': self.name,
- 'raw_template_id': self.t.store(),
- 'parameters': self.parameters.user_parameters(),
- 'owner_id': owner and owner.id,
- 'user_creds_id': new_creds.id,
- 'username': self.context.username}
+ s = {
+ 'name': self.name,
+ 'raw_template_id': self.t.store(),
+ 'parameters': self.parameters.user_parameters(),
+ 'owner_id': owner and owner.id,
+ 'user_creds_id': new_creds.id,
+ 'username': self.context.username,
+ 'status': self.state,
+ 'status_reason': self.state_description,
+ }
new_s = db_api.stack_create(self.context, s)
self.id = new_s.id
def state_set(self, new_status, reason):
'''Update the stack state in the database'''
+ self.state = new_status
+ self.state_description = reason
+
if self.id is None:
return
if resource:
self.instance_id = resource.nova_instance
self.state = resource.state
+ self.state_description = resource.state_description
self.id = resource.id
else:
self.instance_id = None
self.state = None
+ self.state_description = ''
self.id = None
self._nova = {}
self._keystone = None
def state_set(self, new_state, reason="state changed"):
self.state, old_state = new_state, self.state
+ self.state_description = reason
if self.id is not None:
try:
self.assertEqual(params2['Defaulted'], 'foobar')
+@attr(tag=['unit', 'parser', 'stack'])
+@attr(speed='fast')
+class StackTest(unittest.TestCase):
+ def test_state_defaults(self):
+ stack = parser.Stack(None, 'test_stack', parser.Template({}))
+ self.assertEqual(stack.state, None)
+ self.assertEqual(stack.state_description, '')
+
+ def test_state(self):
+ stack = parser.Stack(None, 'test_stack', parser.Template({}),
+ state='foo')
+ self.assertEqual(stack.state, 'foo')
+ stack.state_set('bar', '')
+ self.assertEqual(stack.state, 'bar')
+
+ def test_state_description(self):
+ stack = parser.Stack(None, 'test_stack', parser.Template({}),
+ state_description='quux')
+ self.assertEqual(stack.state_description, 'quux')
+ stack.state_set('blarg', 'wibble')
+ self.assertEqual(stack.state_description, 'wibble')
+
+
# allows testing of the test directly, shown below
if __name__ == '__main__':
sys.argv.append(__file__)
--- /dev/null
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+
+import nose
+import unittest
+from nose.plugins.attrib import attr
+import mox
+
+import json
+from heat.engine import parser
+from heat.engine import resources
+
+
+@attr(tag=['unit', 'parser', 'stack'])
+@attr(speed='fast')
+class ResourceTest(unittest.TestCase):
+ def setUp(self):
+ self.stack = parser.Stack(None, 'test_stack', parser.Template({}))
+
+ def test_state_defaults(self):
+ tmpl = {'Type': 'Foo'}
+ res = resources.GenericResource('test_resource', tmpl, self.stack)
+ self.assertEqual(res.state, None)
+ self.assertEqual(res.state_description, '')
+
+ def test_state(self):
+ tmpl = {'Type': 'Foo'}
+ res = resources.GenericResource('test_resource', tmpl, self.stack)
+ res.state_set('bar')
+ self.assertEqual(res.state, 'bar')
+
+ def test_state_description(self):
+ tmpl = {'Type': 'Foo'}
+ res = resources.GenericResource('test_resource', tmpl, self.stack)
+ res.state_set('blarg', 'wibble')
+ self.assertEqual(res.state_description, 'wibble')
+
+
+# allows testing of the test directly, shown below
+if __name__ == '__main__':
+ sys.argv.append(__file__)
+ nose.main()