From 636c70c3c990d0405c7e05a428d78908dc8b4317 Mon Sep 17 00:00:00 2001 From: Asbjørn Sannes Date: Wed, 19 Oct 2011 22:36:03 +0200 Subject: Fix deletion of instances without fixed ips. Catch exception when there are no fixed ips for an instance when deallocating it. When trying to delete failed builds I got the following traces: (nova.rpc): TRACE: Traceback (most recent call last): (nova.rpc): TRACE: File "/usr/lib64/python2.7/site-packages/nova/rpc/impl_kombu.py", line 620, in _process_data (nova.rpc): TRACE: rval = node_func(context=ctxt, **node_args) (nova.rpc): TRACE: File "/usr/lib64/python2.7/site-packages/nova/network/manager.py", line 252, in deallocate_for_instance (nova.rpc): TRACE: fixed_ips = self.db.fixed_ip_get_by_instance(context, instance_id) (nova.rpc): TRACE: File "/usr/lib64/python2.7/site-packages/nova/db/api.py", line 392, in fixed_ip_get_by_instance (nova.rpc): TRACE: return IMPL.fixed_ip_get_by_instance(context, instance_id) (nova.rpc): TRACE: File "/usr/lib64/python2.7/site-packages/nova/db/sqlalchemy/api.py", line 120, in wrapper (nova.rpc): TRACE: return f(*args, **kwargs) (nova.rpc): TRACE: File "/usr/lib64/python2.7/site-packages/nova/db/sqlalchemy/api.py", line 877, in fixed_ip_get_by_instance (nova.rpc): TRACE: raise exception.FixedIpNotFoundForInstance(instance_id=instance_id) (nova.rpc): TRACE: FixedIpNotFoundForInstance: Instance 37 has zero fixed ips. Which this commit fixes. Added myself to Authors as requested. Change-Id: I87a1764c16328c6a4bfa5a0bfab1ea4800cbb355 --- Authors | 1 + nova/network/manager.py | 5 ++++- nova/tests/test_network.py | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Authors b/Authors index 47aa6aed1..fab2ef03a 100644 --- a/Authors +++ b/Authors @@ -12,6 +12,7 @@ Anthony Young Antony Messerli Armando Migliaccio Arvind Somya +Asbjørn Sannes Ben McGraw Bilal Akhtar Brad Hall diff --git a/nova/network/manager.py b/nova/network/manager.py index f1070f960..ea6bdb5d4 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -250,7 +250,10 @@ class FloatingIP(object): LOG.debug(_("floating IP deallocation for instance |%s|"), instance_id, context=context) - fixed_ips = self.db.fixed_ip_get_by_instance(context, instance_id) + try: + fixed_ips = self.db.fixed_ip_get_by_instance(context, instance_id) + except exception.FixedIpNotFoundForInstance: + fixed_ips = [] # add to kwargs so we can pass to super to save a db lookup there kwargs['fixed_ips'] = fixed_ips for fixed_ip in fixed_ips: diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index e3d27e091..17e79f39a 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -972,3 +972,30 @@ class CommonNetworkTestCase(test.TestCase): self.assertTrue(res) self.assertEqual(len(res), 1) self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id']) + + +class TestFloatingIPManager(network_manager.FloatingIP, + network_manager.NetworkManager): + """Dummy manager that implements FloatingIP""" + + +class FloatingIPTestCase(test.TestCase): + """Tests nova.network.manager.FloatingIP""" + def setUp(self): + super(FloatingIPTestCase, self).setUp() + self.network = TestFloatingIPManager() + self.network.db = db + self.project_id = 'testproject' + self.context = context.RequestContext('testuser', self.project_id, + is_admin=False) + + def test_double_deallocation(self): + instance_ref = db.api.instance_create(self.context, + {"project_id": self.project_id}) + # Run it twice to make it fault if it does not handle + # instances without fixed networks + # If this fails in either, it does not handle having no addresses + self.network.deallocate_for_instance(self.context, + instance_id=instance_ref['id']) + self.network.deallocate_for_instance(self.context, + instance_id=instance_ref['id']) -- cgit