]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Catch "FloatingIpPoolNotFound" in eip.py
authorHui HX Xiang <xianghui@cn.ibm.com>
Mon, 5 Aug 2013 05:30:32 +0000 (22:30 -0700)
committerHui HX Xiang <xianghui@cn.ibm.com>
Thu, 15 Aug 2013 09:10:01 +0000 (02:10 -0700)
This patchset catch the "FloatingIpPoolNotFound" exception in eip
of heat, the floatingippool cannot be configured by heat currently
but it can be assigned by setting 'default_floating_pool' in
nova.conf

Fixes bug #1206865

Change-Id: Idd0fd39f5470904dd351a39f66a57781d9f7c444

heat/engine/resources/eip.py
heat/tests/test_eip.py

index 94a43ef0c1d42a92747719a2215498d86a931349..d6c9e5c9218334d73c4adbdf5c13d0df5b7bb21e 100644 (file)
@@ -16,6 +16,7 @@
 from heat.engine import clients
 from heat.engine import resource
 
+from heat.openstack.common import excutils
 from heat.openstack.common import log as logging
 
 logger = logging.getLogger(__name__)
@@ -48,10 +49,18 @@ class ElasticIp(resource.Resource):
 
     def handle_create(self):
         """Allocate a floating IP for the current tenant."""
-        ips = self.nova().floating_ips.create()
-        logger.info('ElasticIp create %s' % str(ips))
-        self.ipaddress = ips.ip
-        self.resource_id_set(ips.id)
+        try:
+            ips = self.nova().floating_ips.create()
+        except clients.novaclient.exceptions.NotFound:
+            with excutils.save_and_reraise_exception():
+                msg = ("No default floating IP pool configured."
+                       "Set 'default_floating_pool' in nova.conf.")
+                logger.error(msg)
+
+        if ips:
+            logger.info('ElasticIp create %s' % str(ips))
+            self.ipaddress = ips.ip
+            self.resource_id_set(ips.id)
 
         if self.properties['InstanceId']:
             server = self.nova().servers.get(self.properties['InstanceId'])
index 7715877bde8cb7ceacaca461c396eebba5819ae9..d2fa4b9d076d081c83c61eb54d14131ac960eba1 100644 (file)
@@ -16,6 +16,7 @@
 from heat.common import exception
 from heat.common import template_format
 from heat.engine.resources import eip
+from heat.engine import clients
 from heat.engine import resource
 from heat.engine import scheduler
 from heat.tests.common import HeatTestCase
@@ -125,6 +126,24 @@ class EIPTest(HeatTestCase):
 
         self.m.VerifyAll()
 
+    def test_eip_with_exception(self):
+        self.m.StubOutWithMock(self.fc.floating_ips, 'create')
+        eip.ElasticIp.nova().MultipleTimes().AndReturn(self.fc)
+        self.fc.floating_ips.create().AndRaise(
+            clients.novaclient.exceptions.NotFound('fake_falure'))
+        self.m.ReplayAll()
+
+        t = template_format.parse(eip_template)
+        stack = utils.parse_stack(t)
+        resource_name = 'IPAddress'
+        rsrc = eip.ElasticIp(resource_name,
+                             t['Resources'][resource_name],
+                             stack)
+
+        self.assertRaises(clients.novaclient.exceptions.NotFound,
+                          rsrc.handle_create)
+        self.m.VerifyAll()
+
     def test_association(self):
         eip.ElasticIp.nova().AndReturn(self.fc)
         eip.ElasticIpAssociation.nova().AndReturn(self.fc)