From f5b4cd33b696ea1da6791320b65e5e9977fb5d3c Mon Sep 17 00:00:00 2001 From: Carl Baldwin Date: Mon, 5 Oct 2015 21:35:37 +0000 Subject: [PATCH] Move update_fip_statuses to Router class I noticed that ri.floating_ips was being accessed from the agent. It didn't seem right. Also, noticed that this set gets passed around too much between methods. It all boils down to saving the previous set and then doing set difference to see which ones went away. This patch set makes it simpler. Partially-Implements: blueprint address-scopes Change-Id: I73424620e196200c70f221871c34e33ccfe73261 --- neutron/agent/l3/agent.py | 16 ---------------- neutron/agent/l3/router_info.py | 20 +++++++++++++++++--- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py index 9948f3b40..2ade79910 100644 --- a/neutron/agent/l3/agent.py +++ b/neutron/agent/l3/agent.py @@ -33,7 +33,6 @@ 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 @@ -369,21 +368,6 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, registry.notify(resources.ROUTER, events.AFTER_DELETE, self, router=ri) - def update_fip_statuses(self, ri, existing_floating_ips, fip_statuses): - # Identify floating IPs which were disabled - 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( - self.context, ri.router_id, fip_statuses) - def router_deleted(self, context, router_id): """Deal with router deletion RPC message.""" LOG.debug('Got router deleted notification for %s', router_id) diff --git a/neutron/agent/l3/router_info.py b/neutron/agent/l3/router_info.py index 30d01122c..038b3d715 100644 --- a/neutron/agent/l3/router_info.py +++ b/neutron/agent/l3/router_info.py @@ -653,7 +653,6 @@ class RouterInfo(object): def process_external(self, agent): fip_statuses = {} - existing_floating_ips = self.floating_ips try: with self.iptables_manager.defer_apply(): ex_gw_port = self.get_ex_gw_port() @@ -676,8 +675,23 @@ class RouterInfo(object): LOG.exception(_LE("Failed to process floating IPs.")) fip_statuses = self.put_fips_in_error_state() finally: - agent.update_fip_statuses( - self, existing_floating_ips, fip_statuses) + self.update_fip_statuses(agent, fip_statuses) + + def update_fip_statuses(self, agent, fip_statuses): + # Identify floating IPs which were disabled + existing_floating_ips = self.floating_ips + self.floating_ips = set(fip_statuses.keys()) + for fip_id in existing_floating_ips - self.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 != 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 + agent.plugin_rpc.update_floatingip_statuses( + agent.context, self.router_id, fip_statuses) @common_utils.exception_logger() def process(self, agent): -- 2.45.2