Do not lookup l3-agent for floating IP if host=None, dvr issue

If a floating IP has been associated with a port, but the port
has not been associated with an instance, attempting to lookup
the l3-agent hosting it will cause an AgentNotFoundByTypeHost
exception.  Just skip it and go onto the next one.

Change-Id: If3df9770fa9e2d2eada932ee5f243d3458bf7261
Closes-Bug: #1370795
This commit is contained in:
Brian Haley 2014-09-17 21:48:53 -04:00
parent 48ec1fbfc3
commit 4478eee9e5
2 changed files with 52 additions and 0 deletions

View File

@ -294,6 +294,9 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
floating_ip['host'] = self.get_vm_port_hostid(
context, floating_ip['port_id'])
LOG.debug("Floating IP host: %s", floating_ip['host'])
# if no VM there won't be an agent assigned
if not floating_ip['host']:
continue
fip_agent = self._get_agent_by_type_and_host(
context, l3_const.AGENT_TYPE_L3,
floating_ip['host'])

View File

@ -231,3 +231,52 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
}
mock_fip_clear = self._delete_floatingip_test_setup(floatingip)
self.assertTrue(mock_fip_clear.called)
def _floatingip_on_port_test_setup(self, hostid):
router = {'id': 'foo_router_id', 'distributed': True}
floatingip = {
'id': _uuid(),
'port_id': _uuid(),
'router_id': 'foo_router_id'
}
routers = {
'foo_router_id': router
}
fipagent = {
'id': _uuid()
}
# NOTE: mock.patch is not needed here since self.mixin is created fresh
# for each test. It doesn't work with some methods since the mixin is
# tested in isolation (e.g. _get_agent_by_type_and_host).
self.mixin.get_vm_port_hostid = mock.Mock(return_value=hostid)
self.mixin._get_agent_by_type_and_host = mock.Mock(
return_value=fipagent)
self.mixin.get_fip_sync_interfaces = mock.Mock(
return_value='fip_interface')
self.mixin._process_floating_ips(self.ctx, routers, [floatingip])
return (router, floatingip)
def test_floatingip_on_port_no_host(self):
router, fip = self._floatingip_on_port_test_setup(None)
self.assertTrue(self.mixin.get_vm_port_hostid.called)
self.assertFalse(self.mixin._get_agent_by_type_and_host.called)
self.assertFalse(self.mixin.get_fip_sync_interfaces.called)
self.assertNotIn(l3_const.FLOATINGIP_KEY, router)
self.assertNotIn(l3_const.FLOATINGIP_AGENT_INTF_KEY, router)
def test_floatingip_on_port_with_host(self):
router, fip = self._floatingip_on_port_test_setup(_uuid())
self.assertTrue(self.mixin.get_vm_port_hostid.called)
self.assertTrue(self.mixin._get_agent_by_type_and_host.called)
self.assertTrue(self.mixin.get_fip_sync_interfaces.called)
self.assertIn(l3_const.FLOATINGIP_KEY, router)
self.assertIn(l3_const.FLOATINGIP_AGENT_INTF_KEY, router)
self.assertIn(fip, router[l3_const.FLOATINGIP_KEY])
self.assertIn('fip_interface',
router[l3_const.FLOATINGIP_AGENT_INTF_KEY])