Merge "dvr: Don't raise KeyError in _get_floatingips_bound_to_host"

This commit is contained in:
Jenkins 2017-09-06 03:40:59 +00:00 committed by Gerrit Code Review
commit 765f76ae36
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.