From: Ryan Moats Date: Tue, 25 Aug 2015 10:57:03 +0000 (-0500) Subject: Optimize if statement in dvr_local_router.py X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=b07fb262921c615015c099643c470bf9fe9c7977;p=openstack-build%2Fneutron-build.git Optimize if statement in dvr_local_router.py The if statement for calling create_rtr_2_fip_link and kicking the FW agent includes a check on floating_ips, that has already been performed by the previous if block. Pull this block into the previous block for code clarity. Change-Id: I8661aa3998bda9341f558d0ecbc8e2663cd95aca Signed-off-by: Ryan Moats Co-Authored-By: Brian Haley --- diff --git a/neutron/agent/l3/dvr_local_router.py b/neutron/agent/l3/dvr_local_router.py index c6eb528d9..7819438d2 100644 --- a/neutron/agent/l3/dvr_local_router.py +++ b/neutron/agent/l3/dvr_local_router.py @@ -408,8 +408,8 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase): else: self.fip_ns.create_gateway_port(fip_agent_port) - if self.fip_ns.agent_gateway_port and floating_ips: - if self.dist_fip_count == 0 or is_first: + if (self.fip_ns.agent_gateway_port and + (self.dist_fip_count == 0 or is_first)): self.fip_ns.create_rtr_2_fip_link(self) # kicks the FW Agent to add rules for the IR namespace if diff --git a/neutron/tests/unit/agent/l3/test_agent.py b/neutron/tests/unit/agent/l3/test_agent.py index f13a865c7..e2a5eb6b0 100644 --- a/neutron/tests/unit/agent/l3/test_agent.py +++ b/neutron/tests/unit/agent/l3/test_agent.py @@ -946,6 +946,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): ri.dist_fip_count = 0 ri.fip_ns.subscribe = mock.Mock() ri.fip_ns.agent_router_gateway = mock.Mock() + agent.process_router_add = mock.Mock() with mock.patch.object(ri, 'get_floating_ips') as fips, \ mock.patch.object(ri, 'get_floating_agent_gw_interface' @@ -958,6 +959,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): self.assertEqual(ri.fip_ns.agent_gateway_port, agent_gateway_port[0]) self.assertTrue(ri.rtr_fip_subnet) + self.assertEqual(1, agent.process_router_add.call_count) @mock.patch.object(lla.LinkLocalAllocator, '_write') def test_create_dvr_fip_interfaces_for_restart_l3agent_case(self,