]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move process_ha_router_added/removed from HA agent to router
authorAssaf Muller <amuller@redhat.com>
Tue, 24 Mar 2015 23:45:11 +0000 (19:45 -0400)
committerAssaf Muller <amuller@redhat.com>
Wed, 25 Mar 2015 01:11:42 +0000 (21:11 -0400)
* Move process_ha_router_added/removed from ha.py to
  ha_router.py, rename them initialize and terminate
* Remove _process_ha_router (Spawns/disables keepalived) from
  process_router (Called when adding/updating and deleting
  a router), move its content to process_router for add/update
  and terminate for delete
* Rename ha_router.spawn_keepalived to enable_keepalived
  (Consistent with disable_keepalived and process_manager
  semantics)

Partially-Implements: bp/restructure-l3-agent
Change-Id: I1f21acdae2ae1faa2c78affaa3f1ce9056487104

neutron/agent/l3/agent.py
neutron/agent/l3/ha.py
neutron/agent/l3/ha_router.py

index 2b9197241f360ec95677df39615b1852b548b59b..6797ef2704a3b6f71ee0ae2ed838fe575d6faf11 100644 (file)
@@ -306,7 +306,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
         self.process_router_add(ri)
 
         if ri.is_ha:
-            self.process_ha_router_added(ri)
+            ri.initialize(self.process_monitor, self.enqueue_state_change)
 
     def _router_removed(self, router_id):
         ri = self.router_info.get(router_id)
@@ -319,7 +319,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
             adv_svc.AdvancedService.before_router_removed, ri)
 
         if ri.is_ha:
-            self.process_ha_router_removed(ri)
+            ri.terminate(self.process_monitor)
 
         ri.router['gw_port'] = None
         ri.router[l3_constants.INTERFACE_KEY] = []
@@ -340,13 +340,6 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
         self.plugin_rpc.update_floatingip_statuses(
             self.context, ri.router_id, fip_statuses)
 
-    def _process_ha_router(self, ri):
-        if ri.is_ha:
-            if ri.ha_port:
-                ri.spawn_keepalived()
-            else:
-                ri.disable_keepalived()
-
     @common_utils.exception_logger()
     def process_router(self, ri):
         # TODO(mrsmith) - we shouldn't need to check here
@@ -361,8 +354,9 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
         # Process static routes for router
         ri.routes_updated()
 
-        # Enable or disable keepalived for ha routers
-        self._process_ha_router(ri)
+        # If process_router was called during a create or update
+        if ri.is_ha and ri.ha_port:
+            ri.enable_keepalived()
 
         # Update ex_gw_port and enable_snat on the router info cache
         ri.ex_gw_port = ex_gw_port
index 66a61913f358a522a6ea1a068db20220b32a175d..a51001a65d0aed790ddd1724fe3b0346c40cafdc 100644 (file)
@@ -22,8 +22,7 @@ import webob
 
 from neutron.agent.linux import keepalived
 from neutron.agent.linux import utils as agent_utils
-from neutron.common import constants as l3_constants
-from neutron.i18n import _LE, _LI
+from neutron.i18n import _LI
 from neutron.notifiers import batch_notifier
 
 LOG = logging.getLogger(__name__)
@@ -150,25 +149,3 @@ class AgentMixin(object):
     def _init_ha_conf_path(self):
         ha_full_path = os.path.dirname("/%s/" % self.conf.ha_confs_path)
         agent_utils.ensure_dir(ha_full_path)
-
-    def process_ha_router_added(self, ri):
-        ha_port = ri.router.get(l3_constants.HA_INTERFACE_KEY)
-        if not ha_port:
-            LOG.error(_LE('Unable to process HA router %s without ha port'),
-                      ri.router_id)
-            return
-
-        ri._set_subnet_info(ha_port)
-        ri.ha_port = ha_port
-        ri._init_keepalived_manager(self.process_monitor)
-        ri.ha_network_added(ha_port['network_id'],
-                            ha_port['id'],
-                            ha_port['ip_cidr'],
-                            ha_port['mac_address'])
-
-        ri.update_initial_state(self.enqueue_state_change)
-        ri.spawn_state_change_monitor(self.process_monitor)
-
-    def process_ha_router_removed(self, ri):
-        ri.destroy_state_change_monitor(self.process_monitor)
-        ri.ha_network_removed()
index 3fa9504f3e74d164234a63879458caeaa8a38767..ec241b6dc04c7e6097c0932439314409aae5ecdf 100644 (file)
@@ -83,6 +83,28 @@ class HaRouter(router.RouterInfo):
             LOG.error(_LE('Error while writing HA state for %s'),
                       self.router_id)
 
+    def initialize(self, process_monitor, state_change_callback):
+        ha_port = self.router.get(n_consts.HA_INTERFACE_KEY)
+        if not ha_port:
+            LOG.error(_LE('Unable to process HA router %s without HA port'),
+                      self.router_id)
+            return
+
+        self._set_subnet_info(ha_port)
+        self.ha_port = ha_port
+        self._init_keepalived_manager(process_monitor)
+        self.ha_network_added(ha_port['network_id'],
+                              ha_port['id'],
+                              ha_port['ip_cidr'],
+                              ha_port['mac_address'])
+        self.update_initial_state(state_change_callback)
+        self.spawn_state_change_monitor(process_monitor)
+
+    def terminate(self, process_monitor):
+        self.destroy_state_change_monitor(process_monitor)
+        self.ha_network_removed()
+        self.disable_keepalived()
+
     def _init_keepalived_manager(self, process_monitor):
         self.keepalived_manager = keepalived.KeepalivedManager(
             self.router['id'],
@@ -113,7 +135,7 @@ class HaRouter(router.RouterInfo):
 
         config.add_instance(instance)
 
-    def spawn_keepalived(self):
+    def enable_keepalived(self):
         self.keepalived_manager.spawn()
 
     def disable_keepalived(self):