Merge "Eliminate unnecessary indirection in L3 agent"
This commit is contained in:
@@ -620,17 +620,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
|
|||||||
ns_to_ignore = self._get_routers_namespaces(router_ids)
|
ns_to_ignore = self._get_routers_namespaces(router_ids)
|
||||||
|
|
||||||
ns_to_destroy = router_namespaces - ns_to_ignore
|
ns_to_destroy = router_namespaces - ns_to_ignore
|
||||||
self._destroy_stale_router_namespaces(ns_to_destroy)
|
for ns in ns_to_destroy:
|
||||||
|
|
||||||
def _destroy_stale_router_namespaces(self, router_namespaces):
|
|
||||||
"""Destroys the stale router namespaces
|
|
||||||
|
|
||||||
The argumenet router_namespaces is a list of stale router namespaces
|
|
||||||
|
|
||||||
As some stale router namespaces may not be able to be deleted, only
|
|
||||||
one attempt will be made to delete them.
|
|
||||||
"""
|
|
||||||
for ns in router_namespaces:
|
|
||||||
try:
|
try:
|
||||||
self._destroy_namespace(ns)
|
self._destroy_namespace(ns)
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
@@ -1838,18 +1828,11 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
|
|||||||
while True:
|
while True:
|
||||||
pool.spawn_n(self._process_router_update)
|
pool.spawn_n(self._process_router_update)
|
||||||
|
|
||||||
def _router_ids(self):
|
|
||||||
if not self.conf.use_namespaces:
|
|
||||||
return [self.conf.router_id]
|
|
||||||
|
|
||||||
@periodic_task.periodic_task
|
@periodic_task.periodic_task
|
||||||
def periodic_sync_routers_task(self, context):
|
def periodic_sync_routers_task(self, context):
|
||||||
self._sync_routers_task(context)
|
|
||||||
|
|
||||||
def _sync_routers_task(self, context):
|
|
||||||
if self.services_sync:
|
if self.services_sync:
|
||||||
super(L3NATAgent, self).process_services_sync(context)
|
super(L3NATAgent, self).process_services_sync(context)
|
||||||
LOG.debug("Starting _sync_routers_task - fullsync:%s",
|
LOG.debug("Starting periodic_sync_routers_task - fullsync:%s",
|
||||||
self.fullsync)
|
self.fullsync)
|
||||||
if not self.fullsync:
|
if not self.fullsync:
|
||||||
return
|
return
|
||||||
@@ -1862,10 +1845,12 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
|
|||||||
prev_router_ids = set(self.router_info)
|
prev_router_ids = set(self.router_info)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
router_ids = self._router_ids()
|
|
||||||
timestamp = timeutils.utcnow()
|
timestamp = timeutils.utcnow()
|
||||||
routers = self.plugin_rpc.get_routers(
|
if self.conf.use_namespaces:
|
||||||
context, router_ids)
|
routers = self.plugin_rpc.get_routers(context)
|
||||||
|
else:
|
||||||
|
routers = self.plugin_rpc.get_routers(context,
|
||||||
|
[self.conf.router_id])
|
||||||
|
|
||||||
LOG.debug('Processing :%r', routers)
|
LOG.debug('Processing :%r', routers)
|
||||||
for r in routers:
|
for r in routers:
|
||||||
@@ -1875,7 +1860,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
|
|||||||
timestamp=timestamp)
|
timestamp=timestamp)
|
||||||
self._queue.add(update)
|
self._queue.add(update)
|
||||||
self.fullsync = False
|
self.fullsync = False
|
||||||
LOG.debug("_sync_routers_task successfully completed")
|
LOG.debug("periodic_sync_routers_task successfully completed")
|
||||||
except messaging.MessagingException:
|
except messaging.MessagingException:
|
||||||
LOG.exception(_LE("Failed synchronizing routers due to RPC error"))
|
LOG.exception(_LE("Failed synchronizing routers due to RPC error"))
|
||||||
self.fullsync = True
|
self.fullsync = True
|
||||||
|
@@ -418,18 +418,18 @@ class TestBasicRouterOperations(base.BaseTestCase):
|
|||||||
|
|
||||||
return agent, ri, port
|
return agent, ri, port
|
||||||
|
|
||||||
def test__sync_routers_task_raise_exception(self):
|
def test_periodic_sync_routers_task_raise_exception(self):
|
||||||
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
||||||
self.plugin_api.get_routers.side_effect = Exception()
|
self.plugin_api.get_routers.side_effect = Exception()
|
||||||
with mock.patch.object(agent, '_cleanup_namespaces') as f:
|
with mock.patch.object(agent, '_cleanup_namespaces') as f:
|
||||||
agent._sync_routers_task(agent.context)
|
agent.periodic_sync_routers_task(agent.context)
|
||||||
self.assertFalse(f.called)
|
self.assertFalse(f.called)
|
||||||
|
|
||||||
def test__sync_routers_task_call_clean_stale_namespaces(self):
|
def test_periodic_sync_routers_task_call_clean_stale_namespaces(self):
|
||||||
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
||||||
self.plugin_api.get_routers.return_value = []
|
self.plugin_api.get_routers.return_value = []
|
||||||
with mock.patch.object(agent, '_cleanup_namespaces') as f:
|
with mock.patch.object(agent, '_cleanup_namespaces') as f:
|
||||||
agent._sync_routers_task(agent.context)
|
agent.periodic_sync_routers_task(agent.context)
|
||||||
self.assertTrue(f.called)
|
self.assertTrue(f.called)
|
||||||
|
|
||||||
def test_router_info_create(self):
|
def test_router_info_create(self):
|
||||||
@@ -1491,8 +1491,8 @@ vrrp_instance VR_1 {
|
|||||||
# The unexpected exception has been fixed manually
|
# The unexpected exception has been fixed manually
|
||||||
internal_network_added.side_effect = None
|
internal_network_added.side_effect = None
|
||||||
|
|
||||||
# _sync_routers_task finds out that _rpc_loop failed to process the
|
# periodic_sync_routers_task finds out that _rpc_loop failed to
|
||||||
# router last time, it will retry in the next run.
|
# process the router last time, it will retry in the next run.
|
||||||
agent.process_router(ri)
|
agent.process_router(ri)
|
||||||
# We were able to add the port to ri.internal_ports
|
# We were able to add the port to ri.internal_ports
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
@@ -1522,8 +1522,8 @@ vrrp_instance VR_1 {
|
|||||||
# The unexpected exception has been fixed manually
|
# The unexpected exception has been fixed manually
|
||||||
internal_net_removed.side_effect = None
|
internal_net_removed.side_effect = None
|
||||||
|
|
||||||
# _sync_routers_task finds out that _rpc_loop failed to process the
|
# periodic_sync_routers_task finds out that _rpc_loop failed to
|
||||||
# router last time, it will retry in the next run.
|
# process the router last time, it will retry in the next run.
|
||||||
agent.process_router(ri)
|
agent.process_router(ri)
|
||||||
# We were able to remove the port from ri.internal_ports
|
# We were able to remove the port from ri.internal_ports
|
||||||
self.assertNotIn(
|
self.assertNotIn(
|
||||||
@@ -1840,7 +1840,7 @@ vrrp_instance VR_1 {
|
|||||||
|
|
||||||
self.conf.set_override('router_id', '1234')
|
self.conf.set_override('router_id', '1234')
|
||||||
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
||||||
self.assertEqual(['1234'], agent._router_ids())
|
self.assertEqual('1234', agent.conf.router_id)
|
||||||
self.assertFalse(agent._clean_stale_namespaces)
|
self.assertFalse(agent._clean_stale_namespaces)
|
||||||
|
|
||||||
def test_process_router_if_compatible_with_no_ext_net_in_conf(self):
|
def test_process_router_if_compatible_with_no_ext_net_in_conf(self):
|
||||||
|
Reference in New Issue
Block a user