Drop RpcProxy usage from L3AgentNotifyAPI
Remove RpcProxy usage from the L3AgentNotifyAPI. The equivalent oslo.messaging APIs are now used instead. Part of blueprint drop-rpc-compat. Change-Id: Ice8e2592d7b254134bbee215b93ca77075ab4fe8
This commit is contained in:
parent
9ad5e286e6
commit
3353102e6d
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
from oslo import messaging
|
||||||
|
|
||||||
from neutron.common import constants
|
from neutron.common import constants
|
||||||
from neutron.common import rpc as n_rpc
|
from neutron.common import rpc as n_rpc
|
||||||
from neutron.common import topics
|
from neutron.common import topics
|
||||||
@ -28,23 +30,20 @@ from neutron.plugins.common import constants as service_constants
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class L3AgentNotifyAPI(n_rpc.RpcProxy):
|
class L3AgentNotifyAPI(object):
|
||||||
"""API for plugin to notify L3 agent."""
|
"""API for plugin to notify L3 agent."""
|
||||||
BASE_RPC_API_VERSION = '1.0'
|
|
||||||
|
|
||||||
def __init__(self, topic=topics.L3_AGENT):
|
def __init__(self, topic=topics.L3_AGENT):
|
||||||
super(L3AgentNotifyAPI, self).__init__(
|
target = messaging.Target(topic=topic, version='1.0')
|
||||||
topic=topic, default_version=self.BASE_RPC_API_VERSION)
|
self.client = n_rpc.get_client(target)
|
||||||
|
|
||||||
def _notification_host(self, context, method, payload, host):
|
def _notification_host(self, context, method, payload, host):
|
||||||
"""Notify the agent that is hosting the router."""
|
"""Notify the agent that is hosting the router."""
|
||||||
LOG.debug('Nofity agent at %(host)s the message '
|
LOG.debug('Nofity agent at %(host)s the message '
|
||||||
'%(method)s', {'host': host,
|
'%(method)s', {'host': host,
|
||||||
'method': method})
|
'method': method})
|
||||||
self.cast(
|
cctxt = self.client.prepare(server=host)
|
||||||
context, self.make_msg(method,
|
cctxt.cast(context, method, payload=payload)
|
||||||
payload=payload),
|
|
||||||
topic='%s.%s' % (topics.L3_AGENT, host))
|
|
||||||
|
|
||||||
def _agent_notification(self, context, method, router_ids, operation,
|
def _agent_notification(self, context, method, router_ids, operation,
|
||||||
shuffle_agents):
|
shuffle_agents):
|
||||||
@ -65,11 +64,10 @@ class L3AgentNotifyAPI(n_rpc.RpcProxy):
|
|||||||
{'topic': l3_agent.topic,
|
{'topic': l3_agent.topic,
|
||||||
'host': l3_agent.host,
|
'host': l3_agent.host,
|
||||||
'method': method})
|
'method': method})
|
||||||
self.cast(
|
cctxt = self.client.prepare(topic=l3_agent.topic,
|
||||||
context, self.make_msg(method,
|
server=l3_agent.host,
|
||||||
routers=[router_id]),
|
version='1.1')
|
||||||
topic='%s.%s' % (l3_agent.topic, l3_agent.host),
|
cctxt.cast(context, method, routers=[router_id])
|
||||||
version='1.1')
|
|
||||||
|
|
||||||
def _agent_notification_arp(self, context, method, router_id,
|
def _agent_notification_arp(self, context, method, router_id,
|
||||||
operation, data):
|
operation, data):
|
||||||
@ -88,14 +86,15 @@ class L3AgentNotifyAPI(n_rpc.RpcProxy):
|
|||||||
# TODO(murali): replace cast with fanout to avoid performance
|
# TODO(murali): replace cast with fanout to avoid performance
|
||||||
# issues at greater scale.
|
# issues at greater scale.
|
||||||
for l3_agent in l3_agents:
|
for l3_agent in l3_agents:
|
||||||
topic = '%s.%s' % (l3_agent.topic, l3_agent.host)
|
log_topic = '%s.%s' % (l3_agent.topic, l3_agent.host)
|
||||||
LOG.debug('Casting message %(method)s with topic %(topic)s',
|
LOG.debug('Casting message %(method)s with topic %(topic)s',
|
||||||
{'topic': topic, 'method': method})
|
{'topic': log_topic, 'method': method})
|
||||||
dvr_arptable = {'router_id': router_id,
|
dvr_arptable = {'router_id': router_id,
|
||||||
'arp_table': data}
|
'arp_table': data}
|
||||||
self.cast(context,
|
cctxt = self.client.prepare(topic=l3_agent.topic,
|
||||||
self.make_msg(method, payload=dvr_arptable),
|
server=l3_agent.host,
|
||||||
topic=topic, version='1.2')
|
version='1.2')
|
||||||
|
cctxt.cast(context, method, payload=dvr_arptable)
|
||||||
|
|
||||||
def _notification(self, context, method, router_ids, operation,
|
def _notification(self, context, method, router_ids, operation,
|
||||||
shuffle_agents):
|
shuffle_agents):
|
||||||
@ -114,10 +113,8 @@ class L3AgentNotifyAPI(n_rpc.RpcProxy):
|
|||||||
self._agent_notification(
|
self._agent_notification(
|
||||||
context, method, router_ids, operation, shuffle_agents)
|
context, method, router_ids, operation, shuffle_agents)
|
||||||
else:
|
else:
|
||||||
self.fanout_cast(
|
cctxt = self.client.prepare(fanout=True)
|
||||||
context, self.make_msg(method,
|
cctxt.cast(context, method, routers=router_ids)
|
||||||
routers=router_ids),
|
|
||||||
topic=topics.L3_AGENT)
|
|
||||||
|
|
||||||
def _notification_fanout(self, context, method, router_id):
|
def _notification_fanout(self, context, method, router_id):
|
||||||
"""Fanout the deleted router to all L3 agents."""
|
"""Fanout the deleted router to all L3 agents."""
|
||||||
@ -126,10 +123,8 @@ class L3AgentNotifyAPI(n_rpc.RpcProxy):
|
|||||||
{'topic': topics.L3_AGENT,
|
{'topic': topics.L3_AGENT,
|
||||||
'method': method,
|
'method': method,
|
||||||
'router_id': router_id})
|
'router_id': router_id})
|
||||||
self.fanout_cast(
|
cctxt = self.client.prepare(fanout=True)
|
||||||
context, self.make_msg(method,
|
cctxt.cast(context, method, router_id=router_id)
|
||||||
router_id=router_id),
|
|
||||||
topic=topics.L3_AGENT)
|
|
||||||
|
|
||||||
def agent_updated(self, context, admin_state_up, host):
|
def agent_updated(self, context, admin_state_up, host):
|
||||||
self._notification_host(context, 'agent_updated',
|
self._notification_host(context, 'agent_updated',
|
||||||
|
@ -1361,20 +1361,23 @@ class OvsL3AgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
|
|||||||
l3_plugin = (manager.NeutronManager.get_service_plugins()
|
l3_plugin = (manager.NeutronManager.get_service_plugins()
|
||||||
[service_constants.L3_ROUTER_NAT])
|
[service_constants.L3_ROUTER_NAT])
|
||||||
l3_notifier = l3_plugin.agent_notifiers[constants.AGENT_TYPE_L3]
|
l3_notifier = l3_plugin.agent_notifiers[constants.AGENT_TYPE_L3]
|
||||||
with mock.patch.object(l3_notifier, 'cast') as mock_l3:
|
with contextlib.nested(
|
||||||
with self.router() as router1:
|
mock.patch.object(l3_notifier.client, 'prepare',
|
||||||
self._register_agent_states()
|
return_value=l3_notifier.client),
|
||||||
hosta_id = self._get_agent_id(constants.AGENT_TYPE_L3,
|
mock.patch.object(l3_notifier.client, 'cast'),
|
||||||
L3_HOSTA)
|
self.router(),
|
||||||
self._add_router_to_l3_agent(hosta_id,
|
) as (
|
||||||
router1['router']['id'])
|
mock_prepare, mock_cast, router1
|
||||||
routers = [router1['router']['id']]
|
):
|
||||||
mock_l3.assert_called_with(
|
self._register_agent_states()
|
||||||
mock.ANY,
|
hosta_id = self._get_agent_id(constants.AGENT_TYPE_L3,
|
||||||
l3_notifier.make_msg(
|
L3_HOSTA)
|
||||||
'router_added_to_agent',
|
self._add_router_to_l3_agent(hosta_id,
|
||||||
payload=routers),
|
router1['router']['id'])
|
||||||
topic='l3_agent.hosta')
|
routers = [router1['router']['id']]
|
||||||
|
mock_prepare.assert_called_with(server='hosta')
|
||||||
|
mock_cast.assert_called_with(
|
||||||
|
mock.ANY, 'router_added_to_agent', payload=routers)
|
||||||
notifications = fake_notifier.NOTIFICATIONS
|
notifications = fake_notifier.NOTIFICATIONS
|
||||||
expected_event_type = 'l3_agent.router.add'
|
expected_event_type = 'l3_agent.router.add'
|
||||||
self._assert_notify(notifications, expected_event_type)
|
self._assert_notify(notifications, expected_event_type)
|
||||||
@ -1383,20 +1386,25 @@ class OvsL3AgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
|
|||||||
l3_plugin = (manager.NeutronManager.get_service_plugins()
|
l3_plugin = (manager.NeutronManager.get_service_plugins()
|
||||||
[service_constants.L3_ROUTER_NAT])
|
[service_constants.L3_ROUTER_NAT])
|
||||||
l3_notifier = l3_plugin.agent_notifiers[constants.AGENT_TYPE_L3]
|
l3_notifier = l3_plugin.agent_notifiers[constants.AGENT_TYPE_L3]
|
||||||
with mock.patch.object(l3_notifier, 'cast') as mock_l3:
|
with contextlib.nested(
|
||||||
with self.router() as router1:
|
mock.patch.object(l3_notifier.client, 'prepare',
|
||||||
self._register_agent_states()
|
return_value=l3_notifier.client),
|
||||||
hosta_id = self._get_agent_id(constants.AGENT_TYPE_L3,
|
mock.patch.object(l3_notifier.client, 'cast'),
|
||||||
L3_HOSTA)
|
self.router(),
|
||||||
self._add_router_to_l3_agent(hosta_id,
|
) as (
|
||||||
router1['router']['id'])
|
mock_prepare, mock_cast, router1
|
||||||
self._remove_router_from_l3_agent(hosta_id,
|
):
|
||||||
router1['router']['id'])
|
self._register_agent_states()
|
||||||
mock_l3.assert_called_with(
|
hosta_id = self._get_agent_id(constants.AGENT_TYPE_L3,
|
||||||
mock.ANY, l3_notifier.make_msg(
|
L3_HOSTA)
|
||||||
'router_removed_from_agent',
|
self._add_router_to_l3_agent(hosta_id,
|
||||||
payload={'router_id': router1['router']['id']}),
|
router1['router']['id'])
|
||||||
topic='l3_agent.hosta')
|
self._remove_router_from_l3_agent(hosta_id,
|
||||||
|
router1['router']['id'])
|
||||||
|
mock_prepare.assert_called_with(server='hosta')
|
||||||
|
mock_cast.assert_called_with(
|
||||||
|
mock.ANY, 'router_removed_from_agent',
|
||||||
|
payload={'router_id': router1['router']['id']})
|
||||||
notifications = fake_notifier.NOTIFICATIONS
|
notifications = fake_notifier.NOTIFICATIONS
|
||||||
expected_event_type = 'l3_agent.router.remove'
|
expected_event_type = 'l3_agent.router.remove'
|
||||||
self._assert_notify(notifications, expected_event_type)
|
self._assert_notify(notifications, expected_event_type)
|
||||||
@ -1405,12 +1413,19 @@ class OvsL3AgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
|
|||||||
l3_plugin = (manager.NeutronManager.get_service_plugins()
|
l3_plugin = (manager.NeutronManager.get_service_plugins()
|
||||||
[service_constants.L3_ROUTER_NAT])
|
[service_constants.L3_ROUTER_NAT])
|
||||||
l3_notifier = l3_plugin.agent_notifiers[constants.AGENT_TYPE_L3]
|
l3_notifier = l3_plugin.agent_notifiers[constants.AGENT_TYPE_L3]
|
||||||
with mock.patch.object(l3_notifier, 'cast') as mock_l3:
|
with contextlib.nested(
|
||||||
|
mock.patch.object(l3_notifier.client, 'prepare',
|
||||||
|
return_value=l3_notifier.client),
|
||||||
|
mock.patch.object(l3_notifier.client, 'cast'),
|
||||||
|
) as (
|
||||||
|
mock_prepare, mock_cast
|
||||||
|
):
|
||||||
self._register_agent_states()
|
self._register_agent_states()
|
||||||
hosta_id = self._get_agent_id(constants.AGENT_TYPE_L3,
|
hosta_id = self._get_agent_id(constants.AGENT_TYPE_L3,
|
||||||
L3_HOSTA)
|
L3_HOSTA)
|
||||||
self._disable_agent(hosta_id, admin_state_up=False)
|
self._disable_agent(hosta_id, admin_state_up=False)
|
||||||
mock_l3.assert_called_with(
|
|
||||||
mock.ANY, l3_notifier.make_msg(
|
mock_prepare.assert_called_with(server='hosta')
|
||||||
'agent_updated', payload={'admin_state_up': False}),
|
|
||||||
topic='l3_agent.hosta')
|
mock_cast.assert_called_with(
|
||||||
|
mock.ANY, 'agent_updated', payload={'admin_state_up': False})
|
||||||
|
Loading…
Reference in New Issue
Block a user