Merge "Remove get_external_network_id for router"
This commit is contained in:
commit
1c2e10f859
@ -115,6 +115,7 @@ class L3PluginApi(object):
|
||||
1.10 Added update_all_ha_network_port_statuses
|
||||
1.11 Added get_host_ha_router_count
|
||||
1.12 Added get_networks
|
||||
1.13 Removed get_external_network_id
|
||||
"""
|
||||
|
||||
def __init__(self, topic, host):
|
||||
@ -142,17 +143,6 @@ class L3PluginApi(object):
|
||||
cctxt = self.client.prepare(version='1.9')
|
||||
return cctxt.call(context, 'get_router_ids', host=self.host)
|
||||
|
||||
@utils.timecost
|
||||
def get_external_network_id(self, context):
|
||||
"""Make a remote process call to retrieve the external network id.
|
||||
|
||||
@raise oslo_messaging.RemoteError: with TooManyExternalNetworks as
|
||||
exc_type if there are more than one
|
||||
external network
|
||||
"""
|
||||
cctxt = self.client.prepare()
|
||||
return cctxt.call(context, 'get_external_network_id', host=self.host)
|
||||
|
||||
@utils.timecost
|
||||
def update_floatingip_statuses(self, context, router_id, fip_statuses):
|
||||
"""Call the plugin update floating IPs's operational status."""
|
||||
@ -435,22 +425,6 @@ class L3NATAgent(ha.AgentMixin,
|
||||
LOG.error(msg, self.conf.ipv6_gateway)
|
||||
raise SystemExit(1)
|
||||
|
||||
def _fetch_external_net_id(self, force=False):
|
||||
"""Find UUID of single external network for this agent."""
|
||||
if not force and self.target_ex_net_id:
|
||||
return self.target_ex_net_id
|
||||
|
||||
try:
|
||||
self.target_ex_net_id = self.plugin_rpc.get_external_network_id(
|
||||
self.context)
|
||||
return self.target_ex_net_id
|
||||
except oslo_messaging.RemoteError as e:
|
||||
with excutils.save_and_reraise_exception() as ctx:
|
||||
if e.exc_type == 'TooManyExternalNetworks':
|
||||
# Since there are more than one external network,
|
||||
# we will handle all of them
|
||||
ctx.reraise = False
|
||||
|
||||
def _create_router(self, router_id, router):
|
||||
kwargs = {
|
||||
'agent': self,
|
||||
@ -629,15 +603,6 @@ class L3NATAgent(ha.AgentMixin,
|
||||
if not ex_net_id and not self.conf.handle_internal_only_routers:
|
||||
raise l3_exc.RouterNotCompatibleWithAgent(router_id=router['id'])
|
||||
|
||||
# If target_ex_net_id and ex_net_id are set they must be equal
|
||||
target_ex_net_id = self._fetch_external_net_id()
|
||||
if (target_ex_net_id and ex_net_id and ex_net_id != target_ex_net_id):
|
||||
# Double check that our single external_net_id has not changed
|
||||
# by forcing a check by RPC.
|
||||
if ex_net_id != self._fetch_external_net_id(force=True):
|
||||
raise l3_exc.RouterNotCompatibleWithAgent(
|
||||
router_id=router['id'])
|
||||
|
||||
if router['id'] not in self.router_info:
|
||||
self._process_added_router(router)
|
||||
else:
|
||||
|
@ -225,8 +225,6 @@ class TestDvrRouter(DvrRouterTestFramework, framework.L3AgentTestFramework):
|
||||
self, agent_mode, **dvr_router_kwargs):
|
||||
self.agent.conf.agent_mode = agent_mode
|
||||
router_info = self.generate_dvr_router_info(**dvr_router_kwargs)
|
||||
self.mock_plugin_api.get_external_network_id.return_value = (
|
||||
router_info['_floatingips'][0]['floating_network_id'])
|
||||
router = self.manage_router(self.agent, router_info)
|
||||
fip_ns = router.fip_ns.get_name()
|
||||
return router, fip_ns
|
||||
@ -271,8 +269,6 @@ class TestDvrRouter(DvrRouterTestFramework, framework.L3AgentTestFramework):
|
||||
# Create the router with external net
|
||||
router_info = self.generate_dvr_router_info()
|
||||
external_gw_port = router_info['gw_port']
|
||||
ext_net_id = router_info['_floatingips'][0]['floating_network_id']
|
||||
self.mock_plugin_api.get_external_network_id.return_value = ext_net_id
|
||||
router = self.manage_router(self.agent, router_info)
|
||||
fg_port = router.fip_ns.agent_gateway_port
|
||||
fg_port_name = router.fip_ns.get_ext_device_name(fg_port['id'])
|
||||
@ -325,8 +321,6 @@ class TestDvrRouter(DvrRouterTestFramework, framework.L3AgentTestFramework):
|
||||
# Create the router with external net
|
||||
router_info = self.generate_dvr_router_info()
|
||||
external_gw_port = router_info['gw_port']
|
||||
ext_net_id = router_info['_floatingips'][0]['floating_network_id']
|
||||
self.mock_plugin_api.get_external_network_id.return_value = ext_net_id
|
||||
router = self.manage_router(self.agent, router_info)
|
||||
fg_port = router.fip_ns.agent_gateway_port
|
||||
fg_port_name = router.fip_ns.get_ext_device_name(fg_port['id'])
|
||||
@ -378,7 +372,6 @@ class TestDvrRouter(DvrRouterTestFramework, framework.L3AgentTestFramework):
|
||||
router_info = self.generate_dvr_router_info()
|
||||
external_gw_port = router_info['gw_port']
|
||||
ext_net_id = router_info['_floatingips'][0]['floating_network_id']
|
||||
self.mock_plugin_api.get_external_network_id.return_value = ext_net_id
|
||||
|
||||
# Create the fip namespace up front
|
||||
fip_ns = dvr_fip_ns.FipNamespace(ext_net_id,
|
||||
@ -425,7 +418,6 @@ class TestDvrRouter(DvrRouterTestFramework, framework.L3AgentTestFramework):
|
||||
router_info = self.generate_dvr_router_info(**dvr_router_kwargs)
|
||||
external_gw_port = router_info['gw_port']
|
||||
ext_net_id = router_info['_floatingips'][0]['floating_network_id']
|
||||
self.mock_plugin_api.get_external_network_id.return_value(ext_net_id)
|
||||
|
||||
# Create the fip namespace up front
|
||||
stale_fip_ns = dvr_fip_ns.FipNamespace(ext_net_id,
|
||||
@ -585,11 +577,6 @@ class TestDvrRouter(DvrRouterTestFramework, framework.L3AgentTestFramework):
|
||||
self.mock_plugin_api.get_agent_gateway_port.return_value = (
|
||||
fip_agent_gw_port)
|
||||
|
||||
# We also need to mock the get_external_network_id method to
|
||||
# get the correct fip namespace.
|
||||
self.mock_plugin_api.get_external_network_id.return_value = (
|
||||
router_info['_floatingips'][0]['floating_network_id'])
|
||||
|
||||
# With all that set we can now ask the l3_agent to
|
||||
# manage the router (create it, create namespaces,
|
||||
# attach interfaces, etc...)
|
||||
|
@ -212,8 +212,6 @@ class L3AgentTestCase(framework.L3AgentTestFramework):
|
||||
# Mock the plugin RPC API so a known external network id is returned
|
||||
# when the router updates are processed by the agent
|
||||
external_network_id = framework._uuid()
|
||||
self.mock_plugin_api.get_external_network_id.return_value = (
|
||||
external_network_id)
|
||||
|
||||
# Plug external_gateway_info in the routers that are not going to be
|
||||
# deleted by the agent when it processes the updates. Otherwise,
|
||||
|
@ -25,7 +25,6 @@ import netaddr
|
||||
from neutron_lib.agent import constants as agent_consts
|
||||
from neutron_lib.api.definitions import portbindings
|
||||
from neutron_lib import constants as lib_constants
|
||||
from neutron_lib.exceptions import l3 as l3_exc
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import oslo_messaging
|
||||
@ -2818,27 +2817,6 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
|
||||
self.assertEqual(l3_agent.PRIORITY_RELATED_ROUTER,
|
||||
events_queue[0].priority)
|
||||
|
||||
def test_process_routers_if_compatible_router_not_compatible(self):
|
||||
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
||||
router = {'id': _uuid()}
|
||||
agent.router_info = [router['id']]
|
||||
self.plugin_api.get_routers.return_value = [router]
|
||||
update = resource_processing_queue.ResourceUpdate(
|
||||
router['id'], l3_agent.PRIORITY_RPC, resource=router)
|
||||
|
||||
with mock.patch.object(
|
||||
agent, "_process_router_if_compatible",
|
||||
side_effect=l3_exc.RouterNotCompatibleWithAgent(
|
||||
router_id=router['id'])
|
||||
) as process_router_if_compatible, mock.patch.object(
|
||||
agent, "_safe_router_removed"
|
||||
) as safe_router_removed:
|
||||
self.assertTrue(
|
||||
agent._process_routers_if_compatible([router], update))
|
||||
process_router_if_compatible.assert_called_once_with(
|
||||
router)
|
||||
safe_router_removed.assert_called_once_with(router['id'])
|
||||
|
||||
def test_process_dvr_routers_ha_on_update_when_router_unbound(self):
|
||||
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
||||
agent.conf.agent_mode = 'dvr_snat'
|
||||
@ -2932,50 +2910,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
|
||||
self.assertIn(router['id'], agent.router_info)
|
||||
self.assertFalse(chsfr.called)
|
||||
|
||||
def test_process_router_if_compatible_with_no_ext_net_in_conf(self):
|
||||
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
||||
self.plugin_api.get_external_network_id.return_value = 'aaa'
|
||||
|
||||
router = {'id': _uuid(),
|
||||
'routes': [],
|
||||
'admin_state_up': True,
|
||||
'external_gateway_info': {'network_id': 'aaa'}}
|
||||
|
||||
agent._process_router_if_compatible(router)
|
||||
self.assertIn(router['id'], agent.router_info)
|
||||
self.plugin_api.get_external_network_id.assert_called_with(
|
||||
agent.context)
|
||||
|
||||
def test_process_router_if_compatible_with_cached_ext_net(self):
|
||||
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
||||
self.plugin_api.get_external_network_id.return_value = 'aaa'
|
||||
agent.target_ex_net_id = 'aaa'
|
||||
|
||||
router = {'id': _uuid(),
|
||||
'routes': [],
|
||||
'admin_state_up': True,
|
||||
'external_gateway_info': {'network_id': 'aaa'}}
|
||||
|
||||
agent._process_router_if_compatible(router)
|
||||
self.assertIn(router['id'], agent.router_info)
|
||||
self.assertFalse(self.plugin_api.get_external_network_id.called)
|
||||
|
||||
def test_process_router_if_compatible_with_stale_cached_ext_net(self):
|
||||
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
||||
self.plugin_api.get_external_network_id.return_value = 'aaa'
|
||||
agent.target_ex_net_id = 'bbb'
|
||||
|
||||
router = {'id': _uuid(),
|
||||
'routes': [],
|
||||
'admin_state_up': True,
|
||||
'external_gateway_info': {'network_id': 'aaa'}}
|
||||
|
||||
agent._process_router_if_compatible(router)
|
||||
self.assertIn(router['id'], agent.router_info)
|
||||
self.plugin_api.get_external_network_id.assert_called_with(
|
||||
agent.context)
|
||||
|
||||
def test_process_router_if_compatible_w_no_ext_net_and_2_net_plugin(self):
|
||||
def test_process_router_if_compatible(self):
|
||||
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
||||
|
||||
router = {'id': _uuid(),
|
||||
@ -2983,10 +2918,6 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
|
||||
'admin_state_up': True,
|
||||
'external_gateway_info': {'network_id': 'aaa'}}
|
||||
|
||||
agent.router_info = {}
|
||||
e = oslo_messaging.RemoteError()
|
||||
e.exc_type = 'TooManyExternalNetworks'
|
||||
agent.plugin_rpc.get_external_network_id.side_effect = e
|
||||
agent._process_router_if_compatible(router)
|
||||
self.assertIn(router['id'], agent.router_info)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user