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:
Russell Bryant 2014-11-26 18:00:24 +00:00
parent 9ad5e286e6
commit 3353102e6d
2 changed files with 69 additions and 59 deletions

View File

@ -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]),
topic='%s.%s' % (l3_agent.topic, l3_agent.host),
version='1.1') version='1.1')
cctxt.cast(context, method, routers=[router_id])
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',

View File

@ -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',
return_value=l3_notifier.client),
mock.patch.object(l3_notifier.client, 'cast'),
self.router(),
) as (
mock_prepare, mock_cast, router1
):
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._add_router_to_l3_agent(hosta_id, self._add_router_to_l3_agent(hosta_id,
router1['router']['id']) router1['router']['id'])
routers = [router1['router']['id']] routers = [router1['router']['id']]
mock_l3.assert_called_with( mock_prepare.assert_called_with(server='hosta')
mock.ANY, mock_cast.assert_called_with(
l3_notifier.make_msg( mock.ANY, 'router_added_to_agent', payload=routers)
'router_added_to_agent',
payload=routers),
topic='l3_agent.hosta')
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,8 +1386,14 @@ 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',
return_value=l3_notifier.client),
mock.patch.object(l3_notifier.client, 'cast'),
self.router(),
) as (
mock_prepare, mock_cast, router1
):
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)
@ -1392,11 +1401,10 @@ class OvsL3AgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
router1['router']['id']) router1['router']['id'])
self._remove_router_from_l3_agent(hosta_id, self._remove_router_from_l3_agent(hosta_id,
router1['router']['id']) router1['router']['id'])
mock_l3.assert_called_with( mock_prepare.assert_called_with(server='hosta')
mock.ANY, l3_notifier.make_msg( mock_cast.assert_called_with(
'router_removed_from_agent', mock.ANY, 'router_removed_from_agent',
payload={'router_id': router1['router']['id']}), payload={'router_id': router1['router']['id']})
topic='l3_agent.hosta')
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})