From: Angus Salkeld Date: Wed, 11 Apr 2012 09:28:31 +0000 (+1000) Subject: Record the reason for any failures X-Git-Tag: 2014.1~2062 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=4539bdeca6e481ae74a2d019af7344850f5e813f;p=openstack-build%2Fheat-build.git Record the reason for any failures Signed-off-by: Angus Salkeld --- diff --git a/heat/common/exception.py b/heat/common/exception.py index d175ec66..45089970 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -164,3 +164,14 @@ class RegionAmbiguity(OpenstackException): message = _("Multiple 'image' service matches for region %(region)s. This " "generally means that a region is required and you have not " "supplied one.") + +class UserParameterMissing(OpenstackException): + message = _("The Parameter (%(key)s) was not provided.") + + +class UserKeyPairMissing(OpenstackException): + message = _("The Key (%(key_name)s) could not be found.") + + +class ImageNotFound(OpenstackException): + message = _("The Image (%(image_name)s) could not be found.") diff --git a/heat/engine/parser.py b/heat/engine/parser.py index aee2549a..c6878632 100644 --- a/heat/engine/parser.py +++ b/heat/engine/parser.py @@ -136,9 +136,10 @@ class Stack: if not failed: try: self.resources[r].create() - except: + except Exception as ex: + logger.error('create: %s' % str(ex)) failed = True - self.resources[r].state_set(self.resources[r].CREATE_FAILED) + self.resources[r].state_set(self.resources[r].CREATE_FAILED, str(ex)) else: self.resources[r].state_set(self.resources[r].CREATE_FAILED) @@ -157,8 +158,9 @@ class Stack: for r in order: try: self.resources[r].delete() - except: - self.resources[r].state_set(self.resources[r].DELETE_FAILED) + except Exception as ex: + logger.error('delete: %s' % str(ex)) + self.resources[r].state_set(self.resources[r].DELETE_FAILED, str(ex)) def delete(self): pool = eventlet.GreenPool() diff --git a/heat/engine/resources.py b/heat/engine/resources.py index 7f5fd3e0..7853716b 100644 --- a/heat/engine/resources.py +++ b/heat/engine/resources.py @@ -21,6 +21,7 @@ import string from novaclient.v1_1 import client +from heat.common import exception from heat.db import api as db_api logger = logging.getLogger('heat.engine.resources') @@ -330,11 +331,11 @@ class Instance(Resource): props = self.t['Properties'] if not props.has_key('KeyName'): - props['KeyName'] = 'default-key-name' + raise exception.UserParameterMissing(key='KeyName') if not props.has_key('InstanceType'): - props['InstanceType'] = 's1.large' + raise exception.UserParameterMissing(key='InstanceType') if not props.has_key('ImageId'): - props['ImageId'] = 'F16-x86_64' + raise exception.UserParameterMissing(key='ImageId') for p in props: if p == 'UserData': @@ -367,17 +368,26 @@ class Instance(Resource): flavor = self.itype_oflavor[self.t['Properties']['InstanceType']] distro_name = self.stack.parameter_get('LinuxDistribution') key_name = self.t['Properties']['KeyName'] - image_name = self.t['Properties']['ImageId'] + keypairs = self.nova().keypairs.list() + key_exists = False + for k in keypairs: + if k.name == key_name: + # cool it exists + key_exists = True + break + if not key_exists: + raise exception.UserKeyPairMissing(key_name=key_name) + + image_name = self.t['Properties']['ImageId'] image_id = None image_list = self.nova().images.list() for o in image_list: if o.name == image_name: image_id = o.id - # TODO(asalkeld) we need to test earlier whether the image_id exists. if image_id is None: - raise + raise exception.ImageNotFound(image_name=image_name) flavor_list = self.nova().flavors.list() for o in flavor_list: