]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Don't update floating IP status if no change
authorKevin Benton <blak111@gmail.com>
Fri, 17 Apr 2015 11:03:38 +0000 (04:03 -0700)
committerKevin Benton <kevinbenton@buttewifi.com>
Tue, 2 Jun 2015 22:30:36 +0000 (22:30 +0000)
The floating IP status was going through all of the
status update code every time the L3 agent sent in
an update, even if the status didn't change.

This patch skips sending updates to the server if the
agent doesn't change the status.

Change-Id: Ic3736bed3dc3e4ccb91f4acfabbf033949e09ce0
Partial-Bug: #1445412
(cherry picked from commit c44506bfd60b2dd6036e113464f1ea682cfaeb6c)

neutron/agent/l3/agent.py
neutron/agent/l3/router_info.py
neutron/tests/unit/agent/l3/test_agent.py
neutron/tests/unit/agent/l3/test_router_info.py

index cfdf404acc90aa9a1974f1905239223660ff297d..b74d07ed2ac0462a83bd209b1d079744110fa7a4 100644 (file)
@@ -29,6 +29,7 @@ from neutron.agent.l3 import ha_router
 from neutron.agent.l3 import legacy_router
 from neutron.agent.l3 import namespace_manager
 from neutron.agent.l3 import namespaces
+from neutron.agent.l3 import router_info as rinf
 from neutron.agent.l3 import router_processing_queue as queue
 from neutron.agent.linux import external_process
 from neutron.agent.linux import ip_lib
@@ -337,6 +338,11 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
         ri.floating_ips = set(fip_statuses.keys())
         for fip_id in existing_floating_ips - ri.floating_ips:
             fip_statuses[fip_id] = l3_constants.FLOATINGIP_STATUS_DOWN
+        # filter out statuses that didn't change
+        fip_statuses = {f: stat for f, stat in fip_statuses.items()
+                        if stat != rinf.FLOATINGIP_STATUS_NOCHANGE}
+        if not fip_statuses:
+            return
         LOG.debug('Sending floating ip statuses: %s', fip_statuses)
         # Update floating IP status on the neutron server
         self.plugin_rpc.update_floatingip_statuses(
index b9b54b6107dd692f085207711ce665bd0181bb9b..fe521022528f584a6f1c2c044fb961b453cf0013 100644 (file)
@@ -30,6 +30,7 @@ INTERNAL_DEV_PREFIX = namespaces.INTERNAL_DEV_PREFIX
 EXTERNAL_DEV_PREFIX = namespaces.EXTERNAL_DEV_PREFIX
 
 EXTERNAL_INGRESS_MARK_MASK = '0xffffffff'
+FLOATINGIP_STATUS_NOCHANGE = object()
 
 
 class RouterInfo(object):
@@ -247,6 +248,10 @@ class RouterInfo(object):
                           {'id': fip['id'],
                            'status': fip_statuses.get(fip['id'])})
 
+                # mark the status as not changed. we can't remove it because
+                # that's how the caller determines that it was removed
+                if fip_statuses[fip['id']] == fip['status']:
+                    fip_statuses[fip['id']] = FLOATINGIP_STATUS_NOCHANGE
         fips_to_remove = (
             ip_cidr for ip_cidr in existing_cidrs - new_cidrs
             if common_utils.is_cidr_host(ip_cidr))
index a5016f815f916908ab1a4e179b795600acd953eb..ecbf58f34035ffefcfe245eadc1e59d0b66981b7 100644 (file)
@@ -229,6 +229,7 @@ def prepare_router_data(ip_version=4, enable_snat=None, num_internal_ports=1,
         router[l3_constants.FLOATINGIP_KEY] = [{
             'id': _uuid(),
             'port_id': _uuid(),
+            'status': 'DOWN',
             'floating_ip_address': '19.4.4.2',
             'fixed_ip_address': '10.0.0.1'}]
 
@@ -1218,6 +1219,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
             {'id': _uuid(),
              'floating_ip_address': '15.1.2.3',
              'fixed_ip_address': '192.168.0.1',
+             'status': 'DOWN',
              'floating_network_id': _uuid(),
              'port_id': _uuid(),
              'host': HOSTNAME}]}
@@ -1634,6 +1636,27 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
             self.assertNotIn(
                 router[l3_constants.INTERFACE_KEY][0], ri.internal_ports)
 
+    def test_process_router_floatingip_nochange(self):
+        agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
+        with mock.patch.object(
+            agent.plugin_rpc, 'update_floatingip_statuses'
+        ) as mock_update_fip_status:
+            router = prepare_router_data(num_internal_ports=1)
+            fip1 = {'id': _uuid(), 'floating_ip_address': '8.8.8.8',
+                    'fixed_ip_address': '7.7.7.7', 'status': 'ACTIVE',
+                    'port_id': router[l3_constants.INTERFACE_KEY][0]['id']}
+            fip2 = copy.copy(fip1)
+            fip2.update({'id': _uuid(), 'status': 'DOWN'})
+            router[l3_constants.FLOATINGIP_KEY] = [fip1, fip2]
+
+            ri = legacy_router.LegacyRouter(router['id'], router,
+                                            **self.ri_kwargs)
+            ri.external_gateway_added = mock.Mock()
+            ri.process(agent)
+            # make sure only the one that went from DOWN->ACTIVE was sent
+            mock_update_fip_status.assert_called_once_with(
+                mock.ANY, ri.router_id, {fip2['id']: 'ACTIVE'})
+
     def test_process_router_floatingip_disabled(self):
         agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
         with mock.patch.object(
@@ -1645,6 +1668,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
                 {'id': fip_id,
                  'floating_ip_address': '8.8.8.8',
                  'fixed_ip_address': '7.7.7.7',
+                 'status': 'DOWN',
                  'port_id': router[l3_constants.INTERFACE_KEY][0]['id']}]
 
             ri = legacy_router.LegacyRouter(router['id'],
index 04aa55748c3e494b3d3973055a39d8f829fa1dfd..5e60aa12c8fe54d9869079c7e699393d338eee95 100644 (file)
@@ -283,7 +283,8 @@ class TestFloatingIpWithMockDevice(BasicRouterTestCaseFramework):
         fip = {
             'id': fip_id, 'port_id': _uuid(),
             'floating_ip_address': '15.1.2.3',
-            'fixed_ip_address': '192.168.0.2'
+            'fixed_ip_address': '192.168.0.2',
+            'status': 'DOWN'
         }
         ri = self._create_router()
         ri.add_floating_ip = mock.Mock(