From d0dde5b4a9d7ba4efe608e45f66e27aa98ed6ec3 Mon Sep 17 00:00:00 2001 From: Ian Main Date: Thu, 14 Feb 2013 15:04:30 -0800 Subject: [PATCH] Throw a proper error if the flavor is missing. I ran into a bug which caused a bt when the flavor is missing on the targetted system. This patch makes it throw a proper exception and a useful error message. Fixes: bug #1129388 Change-Id: I545fce32732522053e2a4a113a02883a89045910 Signed-off-by: Ian Main --- heat/common/exception.py | 4 ++++ heat/engine/resources/instance.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/heat/common/exception.py b/heat/common/exception.py index 16b012d0..807df137 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -200,6 +200,10 @@ class UserKeyPairMissing(OpenstackException): message = _("The Key (%(key_name)s) could not be found.") +class FlavorMissing(OpenstackException): + message = _("The Flavor ID (%(flavor_id)s) could not be found.") + + class ImageNotFound(OpenstackException): message = _("The Image (%(image_name)s) could not be found.") diff --git a/heat/engine/resources/instance.py b/heat/engine/resources/instance.py index 1b626bcb..a6965e32 100644 --- a/heat/engine/resources/instance.py +++ b/heat/engine/resources/instance.py @@ -241,10 +241,13 @@ class Instance(resource.Resource): logger.info("Image %s was not found in glance" % image_name) raise exception.ImageNotFound(image_name=image_name) + flavor_id = None flavor_list = self.nova().flavors.list() for o in flavor_list: if o.name == flavor: flavor_id = o.id + if flavor_id is None: + raise exception.FlavorMissing(flavor_id=flavor) tags = {} if self.properties['Tags']: -- 2.45.2