Drop RpcProxy usage from DhcpAgentNotifyAPI

Remove usage of the RpcProxy compatibility class from the
DhcpAgentNotifyAPI class.  The equivalent oslo.messaging APIs are now
used instead.

Part of blueprint drop-rpc-compat.

Change-Id: Ib658a0d67da1af3b009bc6df9a7c8ec08c04897b
This commit is contained in:
Russell Bryant 2014-12-02 16:18:58 +00:00
parent 947f151307
commit 679b29f58e
2 changed files with 22 additions and 36 deletions

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo import messaging
from neutron.common import constants
from neutron.common import rpc as n_rpc
from neutron.common import topics
@ -25,9 +27,8 @@ from neutron.openstack.common import log as logging
LOG = logging.getLogger(__name__)
class DhcpAgentNotifyAPI(n_rpc.RpcProxy):
class DhcpAgentNotifyAPI(object):
"""API for plugin to notify DHCP agent."""
BASE_RPC_API_VERSION = '1.0'
# It seems dhcp agent does not support bulk operation
VALID_RESOURCES = ['network', 'subnet', 'port']
VALID_METHOD_NAMES = ['network.create.end',
@ -41,9 +42,9 @@ class DhcpAgentNotifyAPI(n_rpc.RpcProxy):
'port.delete.end']
def __init__(self, topic=topics.DHCP_AGENT, plugin=None):
super(DhcpAgentNotifyAPI, self).__init__(
topic=topic, default_version=self.BASE_RPC_API_VERSION)
self._plugin = plugin
target = messaging.Target(topic=topic, version='1.0')
self.client = n_rpc.get_client(target)
@property
def plugin(self):
@ -134,17 +135,13 @@ class DhcpAgentNotifyAPI(n_rpc.RpcProxy):
def _cast_message(self, context, method, payload, host,
topic=topics.DHCP_AGENT):
"""Cast the payload to the dhcp agent running on the host."""
self.cast(
context, self.make_msg(method,
payload=payload),
topic='%s.%s' % (topic, host))
cctxt = self.client.prepare(topic=topic, server=host)
cctxt.cast(context, method, payload=payload)
def _fanout_message(self, context, method, payload):
"""Fanout the payload to all dhcp agents."""
self.fanout_cast(
context, self.make_msg(method,
payload=payload),
topic=topics.DHCP_AGENT)
cctxt = self.client.prepare(fanout=True)
cctxt.cast(context, method, payload=payload)
def network_removed_from_agent(self, context, network_id, host):
self._cast_message(context, 'network_delete_end',

View File

@ -1163,11 +1163,10 @@ class OvsDhcpAgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
for resource, attrs in attributes.RESOURCE_ATTRIBUTE_MAP.iteritems():
self.saved_attr_map[resource] = attrs.copy()
super(OvsDhcpAgentNotifierTestCase, self).setUp(self.plugin_str)
# the notifier is used to get access to make_msg() method only
self.dhcp_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
self.dhcp_notifier_cast = mock.patch(
'neutron.api.rpc.agentnotifiers.dhcp_rpc_agent_api.'
'DhcpAgentNotifyAPI.cast').start()
'DhcpAgentNotifyAPI._cast_message').start()
ext_mgr = extensions.PluginAwareExtensionManager.get_instance()
self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr)
self.adminContext = context.get_admin_context()
@ -1193,11 +1192,8 @@ class OvsDhcpAgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
self._add_network_to_dhcp_agent(hosta_id,
network_id)
self.dhcp_notifier_cast.assert_called_with(
mock.ANY,
self.dhcp_notifier.make_msg(
'network_create_end',
payload={'network': {'id': network_id}}),
topic='dhcp_agent.' + DHCP_HOSTA)
mock.ANY, 'network_create_end',
{'network': {'id': network_id}}, DHCP_HOSTA)
notifications = fake_notifier.NOTIFICATIONS
expected_event_type = 'dhcp_agent.network.add'
self._assert_notify(notifications, expected_event_type)
@ -1214,11 +1210,8 @@ class OvsDhcpAgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
self._remove_network_from_dhcp_agent(hosta_id,
network_id)
self.dhcp_notifier_cast.assert_called_with(
mock.ANY,
self.dhcp_notifier.make_msg(
'network_delete_end',
payload={'network_id': network_id}),
topic='dhcp_agent.' + DHCP_HOSTA)
mock.ANY, 'network_delete_end',
{'network_id': network_id}, DHCP_HOSTA)
notifications = fake_notifier.NOTIFICATIONS
expected_event_type = 'dhcp_agent.network.remove'
self._assert_notify(notifications, expected_event_type)
@ -1230,10 +1223,8 @@ class OvsDhcpAgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
self._disable_agent(hosta_id, admin_state_up=False)
self.dhcp_notifier_cast.assert_called_with(
mock.ANY, self.dhcp_notifier.make_msg(
'agent_updated',
payload={'admin_state_up': False}),
topic='dhcp_agent.' + DHCP_HOSTA)
mock.ANY, 'agent_updated',
{'admin_state_up': False}, DHCP_HOSTA)
def _network_port_create(
self, hosts, gateway=attributes.ATTR_NOT_SPECIFIED, owner=None):
@ -1262,16 +1253,14 @@ class OvsDhcpAgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
expected_calls = [
mock.call(
mock.ANY,
self.dhcp_notifier.make_msg(
'network_create_end',
payload={'network': {'id': net['network']['id']}}),
topic='dhcp_agent.' + host),
'network_create_end',
{'network': {'id': net['network']['id']}},
host),
mock.call(
mock.ANY,
self.dhcp_notifier.make_msg(
'port_create_end',
payload={'port': port['port']}),
topic='dhcp_agent.' + host)]
'port_create_end',
{'port': port['port']},
host, 'dhcp_agent')]
host_calls[host] = expected_calls
return host_calls