Move process_ha_router_added/removed from HA agent to router

* 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
This commit is contained in:
Assaf Muller 2015-03-24 19:45:11 -04:00
parent 97372fe6ff
commit 79fcf57b37
3 changed files with 29 additions and 36 deletions

View 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

View 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()

View 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):