dvr: Don't raise KeyError in _get_floatingips_bound_to_host

We thought _get_floatingips_bound_to_host is not needed but removing the
method caused sending garps for fip that doesn't belong to node during
the full-sync.

This patch just replaces dict lookup with get() method, so fips are
filtered based on presence on the host and if host is not set on fip, it
won't raise a KeyError.

Note: This patch hasn't been merged in master yet because of KeyError happening in grenade job now.

Co-Authored-By: Swaminathan Vasudevan <SVasudevan@suse.com>

Related-bug: #1712412
Related-bug: #1713927

Change-Id: I0fbc772d757fb13b788f9df8d6d7d28d288d054a
This commit is contained in:
Jakub Libosvar 2017-08-31 12:54:47 +02:00 committed by Jakub Libosvar
parent d6f8c44b1f
commit 188f5c29a9
2 changed files with 13 additions and 3 deletions

View File

@ -546,9 +546,8 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
def _get_floatingips_bound_to_host(self, floating_ips):
"""Filter Floating IPs to be hosted on this agent."""
return [i for i in floating_ips
if (i['host'] == self.host or
i.get('dest_host') == self.host)]
return [fip for fip in floating_ips
if self.host in (fip.get('host'), fip.get('dest_host'))]
def process_external(self):
if self.agent_conf.agent_mode != (

View File

@ -1040,6 +1040,17 @@ class TestDvrRouter(framework.L3AgentTestFramework):
self.assertFalse(self._assert_iptables_rules_exist(
router1.iptables_manager, 'nat', expected_rules))
def test_floating_ip_create_does_not_raise_keyerror_on_missing_host(self):
"""Test to check floating ips configure does not raise Keyerror."""
self.agent.conf.agent_mode = 'dvr'
router_info = self.generate_dvr_router_info(
enable_floating_ip=True)
del router_info[lib_constants.FLOATINGIP_KEY][0]['host']
centralized_floatingips = router_info[lib_constants.FLOATINGIP_KEY][0]
self.assertIsNone(centralized_floatingips.get('host'))
# No Keyerror should be raised when calling manage_router
self.manage_router(self.agent, router_info)
def test_dvr_router_snat_namespace_with_interface_remove(self):
"""Test to validate the snat namespace with interface remove.