]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
engine : suspend support for nested stacks
authorSteven Hardy <shardy@redhat.com>
Fri, 7 Jun 2013 13:19:28 +0000 (14:19 +0100)
committerSteven Hardy <shardy@redhat.com>
Wed, 26 Jun 2013 15:09:54 +0000 (16:09 +0100)
blueprint: stack-suspend-resume
Change-Id: I5d1909065c94d85fb28e4c50475c6ea74baff27c

heat/engine/stack_resource.py
heat/tests/test_nested_stack.py

index 3bc6664eda811f132099306e5c296ee106a8ad46..aef449d6d646dc2cd875c10140789bce402a18ad 100644 (file)
@@ -103,6 +103,25 @@ class StackResource(resource.Resource):
             if stack is not None:
                 stack.delete()
 
+    def handle_suspend(self):
+        stack = self.nested()
+        if stack is None:
+            raise exception.Error(_('Cannot suspend %s, stack not created')
+                                  % self.name)
+
+        suspend_task = scheduler.TaskRunner(self._nested.suspend_task)
+        suspend_task.start(timeout=self._nested.timeout_secs())
+        return suspend_task
+
+    def check_suspend_complete(self, suspend_task):
+        done = suspend_task.step()
+        if done:
+            if self._nested.state != (self._nested.SUSPEND,
+                                      self._nested.COMPLETE):
+                raise exception.Error(self._nested.status_reason)
+
+        return done
+
     def get_output(self, op):
         '''
         Return the specified Output value from the nested stack.
index 5945b2ffcddea35ce6f0f382f435d1b6d80ba067..83174292650f070601d91c9c72823443911ea806 100644 (file)
@@ -18,6 +18,7 @@ from heat.common import exception
 from heat.common import template_format
 from heat.engine import parser
 from heat.engine import resource
+from heat.engine import scheduler
 from heat.common import urlfetch
 from heat.tests.common import HeatTestCase
 from heat.tests import utils
@@ -95,3 +96,17 @@ Outputs:
         self.assertTrue(rsrc.FnGetRefId().startswith(arn_prefix))
 
         self.m.VerifyAll()
+
+    def test_nested_stack_suspend(self):
+        urlfetch.get('https://localhost/the.template').AndReturn(
+            self.nested_template)
+        self.m.ReplayAll()
+
+        stack = self.create_stack(self.test_template)
+        rsrc = stack['the_nested']
+
+        scheduler.TaskRunner(rsrc.suspend)()
+        self.assertEqual(rsrc.state, (rsrc.SUSPEND, rsrc.COMPLETE))
+
+        rsrc.delete()
+        self.m.VerifyAll()