]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Raise suitable exception when stack validation fails
authorZhang Lei (Sneeze) <sneezezhang@cienet.com.cn>
Wed, 26 Jun 2013 05:39:42 +0000 (13:39 +0800)
committerZhang Lei (Sneeze) <sneezezhang@cienet.com.cn>
Wed, 26 Jun 2013 05:41:24 +0000 (13:41 +0800)
fixed Bug#1191009

If nova returns an error looking up images during stack validation, we
return a StackValidationFailed, but we should probably catch
this and return ServerError instead, since this is really an internal
error not a validation failure.

Change-Id: Id509b2fa9f78e197cacfe44bae6c3db37cfd6179

heat/engine/parser.py
heat/engine/resources/instance.py
heat/tests/test_validate.py

index 14b260ae18632f4ebca9e5202db2493ee16b63ca..062e693ebafd92c3b4f28720493030fca972fc7c 100644 (file)
@@ -32,6 +32,7 @@ from heat.engine.clients import Clients
 from heat.db import api as db_api
 
 from heat.openstack.common import log as logging
+from heat.common.exception import ServerError
 from heat.common.exception import StackValidationFailed
 
 logger = logging.getLogger(__name__)
@@ -238,6 +239,9 @@ class Stack(object):
         for res in self:
             try:
                 result = res.validate()
+            except ServerError as ex:
+                logger.exception(ex)
+                raise ex
             except Exception as ex:
                 logger.exception(ex)
                 raise StackValidationFailed(message=str(ex))
index 1d8fbca035ed34dd11fc7b874404feda5928814c..58fb1b59ee57545c47bc9360969904eb37019e03 100644 (file)
@@ -485,7 +485,10 @@ class Instance(resource.Resource):
                             % image_identifier)
                 raise exception.ImageNotFound(image_name=image_identifier)
         else:
-            image_list = self.nova().images.list()
+            try:
+                image_list = self.nova().images.list()
+            except clients.novaclient.exceptions.ClientException as ex:
+                raise exception.ServerError(message=str(ex))
             image_names = dict(
                 (o.id, o.name)
                 for o in image_list if o.name == image_identifier)
index 1cbe1b66c9c5aa69416698d1ba638d8408f4c929..bf6f3c6415e596ef683460e61df5f1b798d6131f 100644 (file)
@@ -14,6 +14,7 @@
 
 from testtools import skipIf
 
+from heat.engine import clients
 from heat.engine import environment
 from heat.tests.v1_1 import fakes
 from heat.common import exception
@@ -430,6 +431,23 @@ test_template_invalid_secgroupids = '''
     }
     '''
 
+test_template_nova_client_exception = '''
+{
+  "AWSTemplateFormatVersion" : "2010-09-09",
+  "Description" : "test.",
+  "Resources" : {
+    "Instance": {
+      "Type": "AWS::EC2::Instance",
+      "DeletionPolicy": "Delete",
+      "Properties": {
+        "ImageId": "image_name",
+        "InstanceType": "m1.large"
+      }
+    }
+  }
+}
+'''
+
 
 class validateTest(HeatTestCase):
     def setUp(self):
@@ -617,3 +635,19 @@ class validateTest(HeatTestCase):
 
         resource = stack.resources['Instance']
         self.assertNotEqual(resource.validate(), None)
+
+    def test_client_exception_from_nova_client(self):
+        t = template_format.parse(test_template_nova_client_exception)
+        template = parser.Template(t)
+        stack = parser.Stack(None, 'test_stack', template)
+
+        self.m.StubOutWithMock(self.fc.images, 'list')
+        self.fc.images.list()\
+            .AndRaise(clients.novaclient.exceptions.ClientException(500))
+        self.m.StubOutWithMock(instances.Instance, 'nova')
+        instances.Instance.nova().AndReturn(self.fc)
+        self.m.ReplayAll()
+
+        self.assertRaises(exception.ServerError,
+                          stack.validate)
+        self.m.VerifyAll()