From 32700292615b528a9095b99f795a290033d982d5 Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Thu, 31 Aug 2017 12:54:47 +0200 Subject: [PATCH] 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. Co-Authored-By: Swaminathan Vasudevan Related-bug: #1712412 Related-bug: #1713927 Change-Id: I0fbc772d757fb13b788f9df8d6d7d28d288d054a --- neutron/agent/l3/dvr_local_router.py | 5 ++--- neutron/tests/functional/agent/l3/test_dvr_router.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/neutron/agent/l3/dvr_local_router.py b/neutron/agent/l3/dvr_local_router.py index ae46c86dd4d..f1a40126148 100644 --- a/neutron/agent/l3/dvr_local_router.py +++ b/neutron/agent/l3/dvr_local_router.py @@ -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 != ( diff --git a/neutron/tests/functional/agent/l3/test_dvr_router.py b/neutron/tests/functional/agent/l3/test_dvr_router.py index 1e598541d62..3480f4ce5b9 100644 --- a/neutron/tests/functional/agent/l3/test_dvr_router.py +++ b/neutron/tests/functional/agent/l3/test_dvr_router.py @@ -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.