]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Optimize if statement in dvr_local_router.py
authorRyan Moats <rmoats@us.ibm.com>
Tue, 25 Aug 2015 10:57:03 +0000 (05:57 -0500)
committerRyan Moats <rmoats@us.ibm.com>
Thu, 17 Sep 2015 16:55:56 +0000 (11:55 -0500)
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 <rmoats@us.ibm.com>
Co-Authored-By: Brian Haley <brian.haley@hpe.com>
neutron/agent/l3/dvr_local_router.py
neutron/tests/unit/agent/l3/test_agent.py

index c6eb528d9f12444e56fe8f25e31d3927a4a9b270..7819438d28f03dfc946668083e74880213d6b9d1 100644 (file)
@@ -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
index f13a865c7320e4b88e6abeb5d9104fbb55e4b83b..e2a5eb6b079f05716c369d76cca21791879daae8 100644 (file)
@@ -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,