
This patch removes the usage of the RpcProxy compatibility class from the neutron.agent.rpc.PluginApi class. The equivalent use of oslo.messaging APIs have been put in place instead. This simple conversion had a pretty wide impact on unit tests, as well. The security groups API was converted in this patch as well. It was necessary because the security group class is used as a mixin, so it must be implemented the same way. Unfortunately, the way this is used as a mix-in is not consistent, so for now it's only conditionally converted. Finally, some other miscellaneous plugin specific interfaces were converted as well. Again, these were methods mixed-in for certain plugins. Note that there's one very minor functional difference in this patch. The previous code set the base version to be '1.1'. The right pattern is for this to be set to '1.0'. This version is the default version specified by the client, telling the server that it must implement at least this version to satisfy the request. The default should be '1.0' and methods that require higher than that should specify it. From looking at other parts of the code, '1.0' vs '1.1' is not actually important, as '1.1' was actually the addition of some security group methods defined elsewhere. The correction is more about establishing the right pattern to follow. Change-Id: I391c01e79943ef179d815ea602253720925ccce1
197 lines
8.0 KiB
Python
197 lines
8.0 KiB
Python
# Copyright 2013 Mellanox Technologies, Ltd
|
|
#
|
|
# 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 Mellanox RPC (major reuse of linuxbridge rpc unit tests)
|
|
"""
|
|
|
|
import contextlib
|
|
import mock
|
|
|
|
import fixtures
|
|
from oslo.config import cfg
|
|
|
|
from neutron.agent import rpc as agent_rpc
|
|
from neutron.common import topics
|
|
from neutron.openstack.common import context
|
|
from neutron.plugins.mlnx import agent_notify_api
|
|
from neutron.tests import base
|
|
|
|
|
|
class rpcApiTestCase(base.BaseTestCase):
|
|
|
|
def _test_mlnx_api_legacy(self, rpcapi, topic, method, rpc_method,
|
|
expected_msg=None, **kwargs):
|
|
# NOTE(russellb) This method can be removed once the AgentNotifierApi
|
|
# has been converted to no longer use the RpcProxy class.
|
|
ctxt = context.RequestContext('fake_user', 'fake_project')
|
|
expected_retval = 'foo' if rpc_method == 'call' else None
|
|
expected_kwargs = {}
|
|
if topic:
|
|
expected_kwargs['topic'] = topic
|
|
if 'version' in kwargs:
|
|
expected_kwargs['version'] = kwargs.pop('version')
|
|
if not expected_msg:
|
|
expected_msg = rpcapi.make_msg(method, **kwargs)
|
|
|
|
self.fake_args = None
|
|
self.fake_kwargs = None
|
|
|
|
def _fake_rpc_method(*args, **kwargs):
|
|
self.fake_args = args
|
|
self.fake_kwargs = kwargs
|
|
if expected_retval:
|
|
return expected_retval
|
|
|
|
self.useFixture(fixtures.MonkeyPatch(
|
|
'neutron.common.rpc.RpcProxy.' + rpc_method,
|
|
_fake_rpc_method))
|
|
|
|
retval = getattr(rpcapi, method)(ctxt, **kwargs)
|
|
|
|
self.assertEqual(expected_retval, retval)
|
|
expected_args = [ctxt, expected_msg]
|
|
|
|
# skip the first argument which is 'self'
|
|
for arg, expected_arg in zip(self.fake_args[1:], expected_args):
|
|
self.assertEqual(expected_arg, arg)
|
|
self.assertEqual(expected_kwargs, self.fake_kwargs)
|
|
|
|
def _test_mlnx_api(self, rpcapi, topic, method, rpc_method, **kwargs):
|
|
ctxt = context.RequestContext('fake_user', 'fake_project')
|
|
expected_retval = 'foo' if rpc_method == 'call' else None
|
|
expected_version = kwargs.pop('version', None)
|
|
|
|
with contextlib.nested(
|
|
mock.patch.object(rpcapi.client, rpc_method),
|
|
mock.patch.object(rpcapi.client, 'prepare'),
|
|
) as (
|
|
rpc_mock, prepare_mock
|
|
):
|
|
prepare_mock.return_value = rpcapi.client
|
|
rpc_mock.return_value = expected_retval
|
|
retval = getattr(rpcapi, method)(ctxt, **kwargs)
|
|
|
|
prepare_args = {}
|
|
if expected_version:
|
|
prepare_args['version'] = expected_version
|
|
prepare_mock.assert_called_once_with(**prepare_args)
|
|
|
|
self.assertEqual(retval, expected_retval)
|
|
rpc_mock.assert_called_once_with(ctxt, method, **kwargs)
|
|
|
|
def test_delete_network(self):
|
|
rpcapi = agent_notify_api.AgentNotifierApi(topics.AGENT)
|
|
self._test_mlnx_api_legacy(
|
|
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):
|
|
cfg.CONF.set_override('rpc_support_old_agents', False, 'AGENT')
|
|
rpcapi = agent_notify_api.AgentNotifierApi(topics.AGENT)
|
|
expected_msg = rpcapi.make_msg('port_update',
|
|
port='fake_port',
|
|
network_type='vlan',
|
|
physical_network='fake_net',
|
|
segmentation_id='fake_vlan_id')
|
|
self._test_mlnx_api_legacy(
|
|
rpcapi,
|
|
topics.get_topic_name(topics.AGENT,
|
|
topics.PORT,
|
|
topics.UPDATE),
|
|
'port_update', rpc_method='fanout_cast',
|
|
expected_msg=expected_msg,
|
|
port='fake_port',
|
|
network_type='vlan',
|
|
physical_network='fake_net',
|
|
vlan_id='fake_vlan_id')
|
|
|
|
def test_port_update_ib(self):
|
|
cfg.CONF.set_override('rpc_support_old_agents', False, 'AGENT')
|
|
rpcapi = agent_notify_api.AgentNotifierApi(topics.AGENT)
|
|
expected_msg = rpcapi.make_msg('port_update',
|
|
port='fake_port',
|
|
network_type='ib',
|
|
physical_network='fake_net',
|
|
segmentation_id='fake_vlan_id')
|
|
self._test_mlnx_api_legacy(
|
|
rpcapi,
|
|
topics.get_topic_name(topics.AGENT,
|
|
topics.PORT,
|
|
topics.UPDATE),
|
|
'port_update', rpc_method='fanout_cast',
|
|
expected_msg=expected_msg,
|
|
port='fake_port',
|
|
network_type='ib',
|
|
physical_network='fake_net',
|
|
vlan_id='fake_vlan_id')
|
|
|
|
def test_port_update_old_agent(self):
|
|
cfg.CONF.set_override('rpc_support_old_agents', True, 'AGENT')
|
|
rpcapi = agent_notify_api.AgentNotifierApi(topics.AGENT)
|
|
expected_msg = rpcapi.make_msg('port_update',
|
|
port='fake_port',
|
|
network_type='vlan',
|
|
physical_network='fake_net',
|
|
segmentation_id='fake_vlan_id',
|
|
vlan_id='fake_vlan_id')
|
|
self._test_mlnx_api_legacy(
|
|
rpcapi,
|
|
topics.get_topic_name(topics.AGENT,
|
|
topics.PORT,
|
|
topics.UPDATE),
|
|
'port_update', rpc_method='fanout_cast',
|
|
expected_msg=expected_msg,
|
|
port='fake_port',
|
|
network_type='vlan',
|
|
physical_network='fake_net',
|
|
vlan_id='fake_vlan_id')
|
|
|
|
def test_device_details(self):
|
|
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
|
|
self._test_mlnx_api(rpcapi, None,
|
|
'get_device_details', rpc_method='call',
|
|
device='fake_device',
|
|
agent_id='fake_agent_id',
|
|
host='fake_host')
|
|
|
|
def test_devices_details_list(self):
|
|
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
|
|
self._test_mlnx_api(rpcapi, None,
|
|
'get_devices_details_list', rpc_method='call',
|
|
devices=['fake_device1', 'fake_device1'],
|
|
agent_id='fake_agent_id', host='fake_host',
|
|
version='1.3')
|
|
|
|
def test_update_device_down(self):
|
|
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
|
|
self._test_mlnx_api(rpcapi, None,
|
|
'update_device_down', rpc_method='call',
|
|
device='fake_device',
|
|
agent_id='fake_agent_id',
|
|
host='fake_host')
|
|
|
|
def test_update_device_up(self):
|
|
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
|
|
self._test_mlnx_api(rpcapi, None,
|
|
'update_device_up', rpc_method='call',
|
|
device='fake_device',
|
|
agent_id='fake_agent_id',
|
|
host='fake_host')
|