Merge "Avoid constructing a RouterInfo object to get namespace name"

This commit is contained in:
Jenkins 2014-10-15 03:47:07 +00:00 committed by Gerrit Code Review
commit 3d82ecf603
4 changed files with 29 additions and 25 deletions

View File

@ -244,7 +244,7 @@ class LinkLocalAllocator(object):
class RouterInfo(l3_ha_agent.RouterMixin):
def __init__(self, router_id, root_helper, use_namespaces, router,
use_ipv6=False):
use_ipv6=False, ns_name=None):
self.router_id = router_id
self.ex_gw_port = None
self._snat_enabled = None
@ -257,6 +257,7 @@ 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_name
self.iptables_manager = iptables_manager.IptablesManager(
root_helper=root_helper,
use_ipv6=use_ipv6,
@ -289,10 +290,6 @@ 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:
@ -576,14 +573,6 @@ 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.
@ -619,9 +608,8 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
return set()
def _get_routers_namespaces(self, router_ids):
namespaces = set(self._get_router_info(id, router=None).ns_name
for id in router_ids)
namespaces.update(self.get_snat_ns_name(id) for id in router_ids)
namespaces = set(self.get_ns_name(rid) for rid in router_ids)
namespaces.update(self.get_snat_ns_name(rid) for rid in router_ids)
return namespaces
def _cleanup_namespaces(self, router_namespaces, router_ids):
@ -764,7 +752,14 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
raise Exception(msg)
def _router_added(self, router_id, router):
ri = self._get_router_info(router_id, router)
ns_name = (self.get_ns_name(router_id)
if self.conf.use_namespaces else None)
ri = RouterInfo(router_id=router_id,
root_helper=self.root_helper,
use_namespaces=self.conf.use_namespaces,
router=router,
use_ipv6=self.use_ipv6,
ns_name=ns_name)
self.router_info[router_id] = ri
if self.conf.use_namespaces:
self._create_router_namespace(ri)
@ -1253,6 +1248,9 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
def get_fip_ns_name(self, ext_net_id):
return (FIP_NS_PREFIX + ext_net_id)
def get_ns_name(self, router_id):
return (NS_PREFIX + router_id)
def get_snat_ns_name(self, router_id):
return (SNAT_NS_PREFIX + router_id)

View File

@ -335,8 +335,9 @@ class TestFwaasL3AgentRpcCallback(base.BaseTestCase):
def _prepare_router_data(self, use_namespaces):
router = {'id': str(uuid.uuid4()), 'tenant_id': str(uuid.uuid4())}
ns = "ns-" + router['id']
return l3_agent.RouterInfo(router['id'], self.conf.root_helper,
use_namespaces, router=router)
use_namespaces, router=router, ns_name=ns)
def _get_router_info_list_with_namespace_helper(self,
router_use_namespaces):

View File

@ -93,8 +93,9 @@ class TestVPNAgent(base.BaseTestCase):
def test_get_namespace(self):
router_id = _uuid()
ns = "ns-" + router_id
ri = l3_agent.RouterInfo(router_id, self.conf.root_helper,
self.conf.use_namespaces, {})
self.conf.use_namespaces, {}, ns_name=ns)
self.agent.router_info = {router_id: ri}
namespace = self.agent.get_namespace(router_id)
self.assertTrue(namespace.endswith(router_id))

View File

@ -431,8 +431,9 @@ class TestBasicRouterOperations(base.BaseTestCase):
def test_router_info_create(self):
id = _uuid()
ns = "ns-" + id
ri = l3_agent.RouterInfo(id, self.conf.root_helper,
self.conf.use_namespaces, {})
self.conf.use_namespaces, {}, ns_name=ns)
self.assertTrue(ri.ns_name.endswith(id))
@ -449,8 +450,9 @@ class TestBasicRouterOperations(base.BaseTestCase):
'enable_snat': True,
'routes': [],
'gw_port': ex_gw_port}
ns = "ns-" + id
ri = l3_agent.RouterInfo(id, self.conf.root_helper,
self.conf.use_namespaces, router)
self.conf.use_namespaces, router, ns_name=ns)
self.assertTrue(ri.ns_name.endswith(id))
self.assertEqual(ri.router, router)
@ -520,9 +522,10 @@ class TestBasicRouterOperations(base.BaseTestCase):
self._test_internal_network_action('remove')
def _test_external_gateway_action(self, action, router):
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
self.conf.use_namespaces, router=router)
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
self.conf.use_namespaces, router=router,
ns_name=agent.get_ns_name(router['id']))
# Special setup for dvr routers
if router.get('distributed'):
agent.conf.agent_mode = 'dvr_snat'
@ -590,9 +593,10 @@ class TestBasicRouterOperations(base.BaseTestCase):
def test_external_gateway_updated(self):
router = prepare_router_data(num_internal_ports=2)
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
self.conf.use_namespaces, router=router)
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
self.conf.use_namespaces, router=router,
ns_name=agent.get_ns_name(router['id']))
interface_name, ex_gw_port = self._prepare_ext_gw_test(agent)
fake_fip = {'floatingips': [{'id': _uuid(),