
Now that all preparations are done, actually port the code to use oslo.messaging. This patch does as little as possible. Follow up patches that refactor and cleanup the code and configuration files, will be merged later. The reason for this is to make the patch as slim as possible, to make review process more smooth and concentrated. Details: * neutron/common/rpc.py: - added init() and cleanup() to set global RPC layer state. - added utility functions: get_server(), get_client(), get_notifier() that wrap up oslo.messaging API a bit, enforcing eventlet executor and setting serializer, among other things. - removed PluginRpcDispatcher, instead introduced PluginRpcSerializer to use as a default serializer for API callbacks. * neutron/common/rpc_compat.py: - emulated incubator RPC layer behaviour thru previously introduced stub classes (RpcCallback, RpcProxy, ...) using new oslo.messaging API. - switched to using new oslo.messaging exception types. * neutron/service.py: - expect multiple RPC listeners that are of MessageHandlingServer type, not GreenThread. * neutron/common/config.py: - initialize RPC layer in init() * setup.cfg: - added entry points for old notifier drivers to retain backward compatibility. * neutron/tests/...: - introduced fake_notifier to replace impl_fake. - faked out consume_in_thread() to avoid starting RPC listeners when running unit tests. - used 'fake' transport driver. - made sure neutron.test.* exceptions are caught. - initialize and clean up RPC layer for each test case. * Ported all affected code from using neutron.openstack.common.notifier API to oslo.messaging.Notifier. * rpc.set_defaults() was renamed to rpc.set_transport_defaults() * other changes not worth mentioning here. blueprint oslo-messaging DocImpact Change-Id: I5a91c34df6e300f2dc46217b1b16352fcc3039fc
110 lines
4.5 KiB
Python
110 lines
4.5 KiB
Python
# Copyright (c) 2013 OpenStack Foundation
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
"""
|
|
Unit Tests for ml2 rpc
|
|
"""
|
|
|
|
import mock
|
|
|
|
from neutron.agent import rpc as agent_rpc
|
|
from neutron.common import rpc_compat
|
|
from neutron.common import topics
|
|
from neutron.openstack.common import context
|
|
from neutron.plugins.ml2.drivers import type_tunnel
|
|
from neutron.plugins.ml2 import rpc as plugin_rpc
|
|
from neutron.tests import base
|
|
|
|
|
|
class RpcApiTestCase(base.BaseTestCase):
|
|
|
|
def _test_rpc_api(self, rpcapi, topic, method, rpc_method, **kwargs):
|
|
ctxt = context.RequestContext('fake_user', 'fake_project')
|
|
expected_retval = 'foo' if method == 'call' else None
|
|
expected_msg = rpcapi.make_msg(method, **kwargs)
|
|
if rpc_method == 'cast' and method == 'run_instance':
|
|
kwargs['call'] = False
|
|
|
|
rpc = rpc_compat.RpcProxy
|
|
with mock.patch.object(rpc, rpc_method) as rpc_method_mock:
|
|
rpc_method_mock.return_value = expected_retval
|
|
retval = getattr(rpcapi, method)(ctxt, **kwargs)
|
|
|
|
self.assertEqual(retval, expected_retval)
|
|
expected = [
|
|
mock.call(ctxt, expected_msg, topic=topic)
|
|
]
|
|
rpc_method_mock.assert_has_calls(expected)
|
|
|
|
def test_delete_network(self):
|
|
rpcapi = plugin_rpc.AgentNotifierApi(topics.AGENT)
|
|
self._test_rpc_api(rpcapi,
|
|
topics.get_topic_name(topics.AGENT,
|
|
topics.NETWORK,
|
|
topics.DELETE),
|
|
'network_delete', rpc_method='fanout_cast',
|
|
network_id='fake_request_spec')
|
|
|
|
def test_port_update(self):
|
|
rpcapi = plugin_rpc.AgentNotifierApi(topics.AGENT)
|
|
self._test_rpc_api(rpcapi,
|
|
topics.get_topic_name(topics.AGENT,
|
|
topics.PORT,
|
|
topics.UPDATE),
|
|
'port_update', rpc_method='fanout_cast',
|
|
port='fake_port',
|
|
network_type='fake_network_type',
|
|
segmentation_id='fake_segmentation_id',
|
|
physical_network='fake_physical_network')
|
|
|
|
def test_tunnel_update(self):
|
|
rpcapi = plugin_rpc.AgentNotifierApi(topics.AGENT)
|
|
self._test_rpc_api(rpcapi,
|
|
topics.get_topic_name(topics.AGENT,
|
|
type_tunnel.TUNNEL,
|
|
topics.UPDATE),
|
|
'tunnel_update', rpc_method='fanout_cast',
|
|
tunnel_ip='fake_ip', tunnel_type='gre')
|
|
|
|
def test_device_details(self):
|
|
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
|
|
self._test_rpc_api(rpcapi, topics.PLUGIN,
|
|
'get_device_details', rpc_method='call',
|
|
device='fake_device',
|
|
agent_id='fake_agent_id')
|
|
|
|
def test_update_device_down(self):
|
|
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
|
|
self._test_rpc_api(rpcapi, topics.PLUGIN,
|
|
'update_device_down', rpc_method='call',
|
|
device='fake_device',
|
|
agent_id='fake_agent_id',
|
|
host='fake_host')
|
|
|
|
def test_tunnel_sync(self):
|
|
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
|
|
self._test_rpc_api(rpcapi, topics.PLUGIN,
|
|
'tunnel_sync', rpc_method='call',
|
|
tunnel_ip='fake_tunnel_ip',
|
|
tunnel_type=None)
|
|
|
|
def test_update_device_up(self):
|
|
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
|
|
self._test_rpc_api(rpcapi, topics.PLUGIN,
|
|
'update_device_up', rpc_method='call',
|
|
device='fake_device',
|
|
agent_id='fake_agent_id',
|
|
host='fake_host')
|