L3 Agent should generate ns_name in a single place

Currently the l3 agent has 2 places where it allows generating ns_name
of specific router_ids (ie. qrouter-<router_id>): in the RouterInfo's
constructor, and in _cleanup_namespaces. This patch proposes a
unification of this creation code with a property which lives in
RouterInfo's namespace. A simpler fix was also made for snat_ns_name.

This patch also offers a single way to initialize a new RouterInfo.

Related-bug: #1374946
Related-bug: #1374947
Change-Id: Ia028236b73a22ff534acee00b46c86b134dc987e
This commit is contained in:
John Schwarz 2014-09-23 14:41:54 +03:00
parent 205162f580
commit 467bd9476d
1 changed files with 17 additions and 7 deletions

View File

@ -254,7 +254,6 @@ class RouterInfo(l3_ha_agent.RouterMixin):
self.use_namespaces = use_namespaces
# Invoke the setter for establishing initial SNAT action
self.router = router
self.ns_name = NS_PREFIX + router_id if use_namespaces else None
self.iptables_manager = iptables_manager.IptablesManager(
root_helper=root_helper,
use_ipv6=use_ipv6,
@ -287,6 +286,10 @@ class RouterInfo(l3_ha_agent.RouterMixin):
# Gateway port was removed, remove rules
self._snat_action = 'remove_rules'
@property
def ns_name(self):
return NS_PREFIX + self.router_id if self.use_namespaces else None
def perform_snat_action(self, snat_callback, *args):
# Process SNAT rules for attached subnets
if self._snat_action:
@ -554,6 +557,14 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
self.target_ex_net_id = None
self.use_ipv6 = ipv6_utils.is_enabled()
def _get_router_info(self, router_id, router):
return RouterInfo(
router_id=router_id,
root_helper=self.root_helper,
use_namespaces=self.conf.use_namespaces,
router=router,
use_ipv6=self.use_ipv6)
def _check_config_params(self):
"""Check items in configuration files.
@ -591,13 +602,14 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
def _cleanup_namespaces(self, router_namespaces, router_ids):
"""Destroy stale router namespaces on host when L3 agent restarts
This routine is called when self._clean_stale_namespaces is True.
This routine is called when self._clean_stale_namespaces is True.
The argument router_namespaces is the list of all routers namespaces
The argument router_ids is the list of ids for known routers.
"""
ns_to_ignore = set(NS_PREFIX + id for id in router_ids)
ns_to_ignore.update(SNAT_NS_PREFIX + id for id in router_ids)
ns_to_ignore = set(self._get_router_info(id, router=None).ns_name
for id in router_ids)
ns_to_ignore.update(self.get_snat_ns_name(id) for id in router_ids)
ns_to_destroy = router_namespaces - ns_to_ignore
self._destroy_stale_router_namespaces(ns_to_destroy)
@ -727,9 +739,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
raise Exception(msg)
def _router_added(self, router_id, router):
ri = RouterInfo(router_id, self.root_helper,
self.conf.use_namespaces, router,
use_ipv6=self.use_ipv6)
ri = self._get_router_info(router_id, router)
self.router_info[router_id] = ri
if self.conf.use_namespaces:
self._create_router_namespace(ri)