]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Tidy up create timeout code
authorZane Bitter <zbitter@redhat.com>
Tue, 26 Jun 2012 09:36:10 +0000 (11:36 +0200)
committerZane Bitter <zbitter@redhat.com>
Thu, 28 Jun 2012 16:02:08 +0000 (18:02 +0200)
- Change the parameter name to 'TimeoutInMinutes' to match CloudFormation
- Don't hack parameters into the template, just pass them as parameters

Change-Id: If938b51a0fcb36bb76efeea3527ee7f8eaae9f81
Signed-off-by: Zane Bitter <zbitter@redhat.com>
bin/heat
heat/api/v1/stacks.py
heat/cloudformations.py
heat/engine/manager.py
heat/engine/parser.py

index 10376864794a5c525972d0e7d4f7541e524b74b8..48e8c19b50d657897749eacdba6bfa8922d45096 100755 (executable)
--- a/bin/heat
+++ b/bin/heat
@@ -176,7 +176,7 @@ def stack_create(options, arguments):
             parameters['Parameters.member.%d.ParameterValue' % count] = v
             count = count + 1
 
-    parameters['Timeout'] = options.timeout
+    parameters['TimeoutInMinutes'] = options.timeout
 
     if options.template_file:
         parameters['TemplateBody'] = open(options.template_file).read()
index f0c4342f0197b28cd6231565d4f97355a63ca23d..eed301b7cd45e7b0f713f295b05e3675698304e8 100644 (file)
@@ -152,9 +152,6 @@ class StackController(object):
         except ValueError:
             msg = _("The Template must be a JSON document.")
             return webob.exc.HTTPBadRequest(explanation=msg)
-        stack['StackName'] = req.params['StackName']
-        if 'Timeout' in req.params:
-            stack['Timeout'] = req.params['Timeout']
 
         try:
             res = rpc.call(con, 'engine',
index 5ad1fb3a994d9ddae9aa1613f0a9efda885ac69c..648770d687d5a82468115c438e8648cf01b3d55d 100644 (file)
@@ -16,6 +16,6 @@
 SUPPORTED_PARAMS = ('StackName', 'TemplateBody', 'TemplateUrl',
                     'NotificationARNs', 'Parameters', 'Version',
                     'SignatureVersion', 'Timestamp', 'AWSAccessKeyId',
-                    'Signature', 'KeyStoneCreds', 'Timeout',
+                    'Signature', 'KeyStoneCreds', 'TimeoutInMinutes',
                     'LogicalResourceId', 'PhysicalResourceId', 'NextToken',
 )
index 11b98973bc664fd849bd0a2d8fad1cac405d8412..94e82585ad21c58bdb3c1b25e1a77b6506d33f5b 100644 (file)
@@ -63,6 +63,18 @@ def _extract_user_params(params):
     return dict(get_param_pairs())
 
 
+def _extract_args(params):
+    kwargs = {}
+    try:
+        timeout_mins = int(params.get('TimeoutInMinutes', 0))
+    except ValueError:
+        logger.exception('create timeout conversion')
+    else:
+        if timeout > 0:
+            kwargs['timeout_in_minutes'] = timeout_mins
+    return kwargs
+
+
 class EngineManager(manager.Manager):
     """
     Manages the running instances from creation to destruction.
@@ -129,9 +141,8 @@ class EngineManager(manager.Manager):
             mem['LastUpdatedTimestamp'] = heat_utils.strtime(s.updated_at)
             mem['NotificationARNs'] = 'TODO'
             mem['Parameters'] = ps.t['Parameters']
-            mem['TimeoutInMinutes'] = ps.t.get('Timeout', '60')
             mem['Description'] = ps.t.get('Description',
-                                                  'No description')
+                                          'No description')
             mem['StackStatus'] = s.status
             mem['StackStatusReason'] = s.status_reason
 
@@ -201,7 +212,8 @@ class EngineManager(manager.Manager):
         new_pt = db_api.parsed_template_create(None, pt)
 
         stack.parsed_template_id = new_pt.id
-        greenpool.spawn_n(stack.create)
+
+        greenpool.spawn_n(stack.create, **_extract_args(params))
 
         return {'StackId': "/".join([new_s.name, str(new_s.id)])}
 
index 5373266a713bb6fbd9a3c825af22de83968c780e..8e77735e415c3fccc94b0996b97472e36ebc946f 100644 (file)
@@ -191,28 +191,20 @@ class Stack(object):
         stack.update_and_save({'status': new_status,
                                'status_reason': reason})
 
-    def _timeout(self):
-        '''Return the stack creation timeout in seconds'''
-        if 'Timeout' in self.t:
-            try:
-                # Timeout is in minutes
-                return int(self.t['Timeout']) * 60
-            except ValueError:
-                logger.exception('create timeout conversion')
-
-        # Default to 1 hour
-        return 60 * 60
-
-    def create(self):
+    def create(self, timeout_in_minutes=60):
         '''
         Create the stack and all of the resources.
+
+        Creation will fail if it exceeds the specified timeout. The default is
+        60 minutes.
         '''
         self.state_set(self.IN_PROGRESS, 'Stack creation started')
 
         stack_status = self.CREATE_COMPLETE
         reason = 'Stack successfully created'
+        res = None
 
-        with eventlet.Timeout(self._timeout()) as tmo:
+        with eventlet.Timeout(timeout_in_minutes * 60) as tmo:
             try:
                 for res in self:
                     if stack_status != self.CREATE_FAILED:
@@ -231,10 +223,10 @@ class Stack(object):
                         res.state_set(res.CREATE_FAILED,
                                       'Stack creation aborted')
 
-            except eventlet.Timeout, t:
+            except eventlet.Timeout as t:
                 if t is tmo:
                     stack_status = self.CREATE_FAILED
-                    reason = 'Timed out waiting for %s' % (res.name)
+                    reason = 'Timed out waiting for %s' % str(res)
                 else:
                     # not my timeout
                     raise