]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Rackspace: Don't raise ResourceFailure exceptions
authorZane Bitter <zbitter@redhat.com>
Fri, 2 Aug 2013 16:55:30 +0000 (18:55 +0200)
committerZane Bitter <zbitter@redhat.com>
Fri, 2 Aug 2013 16:55:30 +0000 (18:55 +0200)
ResourceFailure is meant to be a wrapper around other exceptions that's
invoked by top-level resource operations; don't use it as an all-purpose
exception.

Change-Id: Ie15cad32ee31beca9b0f7e9a9473ced9956a2e3b

heat/engine/resources/rackspace/cloud_server.py
heat/tests/test_rackspace_cloud_server.py

index 044a187389f7f19cf50d20891f1adccbef2262a9..b47748bc6221759f95de5bbafa81b9da6d741488 100644 (file)
@@ -234,17 +234,13 @@ zypper --non-interactive in cloud-init python-boto python-pip gcc python-devel
 
     def _get_ip(self, ip_type):
         """Return the IP of the Cloud Server."""
-        def ip_not_found():
-            exc = exception.Error("Could not determine the %s IP of %s." %
-                                  (ip_type, self.properties['image']))
-            raise exception.ResourceFailure(exc)
-
-        if ip_type not in self.server.addresses:
-            ip_not_found()
-        for ip in self.server.addresses[ip_type]:
-            if ip['version'] == 4:
-                return ip['addr']
-        ip_not_found()
+        if ip_type in self.server.addresses:
+            for ip in self.server.addresses[ip_type]:
+                if ip['version'] == 4:
+                    return ip['addr']
+
+        raise exception.Error("Could not determine the %s IP of %s." %
+                              (ip_type, self.properties['image']))
 
     @property
     def public_ip(self):
@@ -256,7 +252,7 @@ zypper --non-interactive in cloud-init python-boto python-pip gcc python-devel
         """Return the private IP of the Cloud Server."""
         try:
             return self._get_ip('private')
-        except exception.ResourceFailure as ex:
+        except exception.Error as ex:
             logger.info(ex.message)
 
     @property
@@ -405,9 +401,8 @@ zypper --non-interactive in cloud-init python-boto python-pip gcc python-devel
                 if server.status == "DELETED":
                     break
                 elif server.status == "ERROR":
-                    exc = exception.Error("Deletion of server %s failed." %
+                    raise exception.Error("Deletion of server %s failed." %
                                           server.name)
-                    raise exception.ResourceFailure(exc)
             except novaexception.NotFound:
                 break
 
index 0f7991f411adc98d2449d352d628032ad5ec5b76..eeef1400865e0db3478a53583a4a35d728d6b48d 100644 (file)
@@ -425,7 +425,7 @@ class RackspaceCloudServerTest(HeatTestCase):
         cs.addresses = {'public': [],
                         'private': []}
         self.mock_get_ip(cs)
-        self.assertRaises(exception.ResourceFailure, cs._get_ip, 'public')
+        self.assertRaises(exception.Error, cs._get_ip, 'public')
 
     def test_private_key(self):
         stack_name = 'test_private_key'