network_info cache should be cleared before being rescheduled

If an instance fails to boot due to a non-networking error the instance
then gets rescheduled and launched on another compute node. In these cases
deallocate_for_instance() is called which deletes the network ports
allocated though the info_cache for the instance is never cleared. This patch
adds a call to update_instance_cache_with_nw_info() which causes the cache
to get cleared out. Note: the cache is only cleared if the instance hasn't
been marked for deletion. This is due to how instance_info_cache_update()
is implemented.

Change-Id: If967884c9a6276f5949a7a04b597cedcce12ba09
Closes-bug: #1285158
This commit is contained in:
Aaron Rosen 2014-03-03 22:55:35 -08:00
parent 90d3041850
commit 3538a9cd06
2 changed files with 12 additions and 0 deletions

View File

@ -416,6 +416,13 @@ class API(base.Base):
LOG.exception(_("Failed to delete neutron port %s"),
port)
# NOTE(arosen): This clears out the network_cache only if the instance
# hasn't already been deleted. This is needed when an instance fails to
# launch and is rescheduled onto another compute node. If the instance
# has already been deleted this call does nothing.
update_instance_info_cache(self, context, instance,
network_model.NetworkInfo([]))
def allocate_port_for_instance(self, context, instance, port_id,
network_id=None, requested_ip=None):
"""Allocate a port for the instance."""

View File

@ -960,6 +960,7 @@ class TestNeutronv2(TestNeutronv2Base):
self.instance, requested_networks=requested_networks)
def _deallocate_for_instance(self, number):
api = neutronapi.API()
port_data = number == 1 and self.port_data1 or self.port_data2
self.moxed_client.list_ports(
device_id=self.instance['uuid']).AndReturn(
@ -967,6 +968,10 @@ class TestNeutronv2(TestNeutronv2Base):
for port in reversed(port_data):
self.moxed_client.delete_port(port['id'])
self.mox.StubOutWithMock(api.db, 'instance_info_cache_update')
api.db.instance_info_cache_update(self.context,
self.instance['uuid'],
{'network_info': '[]'})
self.mox.ReplayAll()
api = neutronapi.API()