From 0e1e4b697b96328bf8d8a42e0c4fc8fb074e2a63 Mon Sep 17 00:00:00 2001 From: Hui HX Xiang Date: Sun, 4 Aug 2013 22:30:32 -0700 Subject: [PATCH] Catch "FloatingIpPoolNotFound" in eip.py 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 | 17 +++++++++++++---- heat/tests/test_eip.py | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/heat/engine/resources/eip.py b/heat/engine/resources/eip.py index 94a43ef0..d6c9e5c9 100644 --- a/heat/engine/resources/eip.py +++ b/heat/engine/resources/eip.py @@ -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']) diff --git a/heat/tests/test_eip.py b/heat/tests/test_eip.py index 7715877b..d2fa4b9d 100644 --- a/heat/tests/test_eip.py +++ b/heat/tests/test_eip.py @@ -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) -- 2.45.2