'Runs a test against RPC API method.
:param method: Name of RPC API method.
:param rpc_method: Expected RPC message type (cast or call).
:param server: Expected hostname.
:param fanout: True if expected call/cast should be fanout.
:param version: Expected autocalculated RPC API version.
:param expected_method: Expected RPC method name.
:param expected_kwargs_diff: Map of expected changes between keyword
arguments passed into the method and sent
over RPC.
:param retval: Value returned by RPC call/cast.
:param expected_retval: Expected RPC API response (if different than
retval).
:param kwargs: Parameters passed into the RPC API method.'

def _test_rpc_api(self, method, rpc_method, server=None, fanout=False, version=None, expected_method=None, expected_kwargs_diff=None, retval=None, expected_retval=None, **kwargs):

    rpcapi = self.rpcapi()
    expected_kwargs_diff = (expected_kwargs_diff or {})
    version = (version or self.base_version)
    topic = None
    if (server is not None):
        backend = utils.extract_host(server)
        server = utils.extract_host(server, 'host')
        topic = ('cinder-volume.%s' % backend)
    if (expected_method is None):
        expected_method = method
    if (expected_retval is None):
        expected_retval = retval
    target = {'server': server, 'fanout': fanout, 'version': version, 'topic': topic}
    expected_msg = copy.deepcopy(kwargs)
    expected_msg.update(expected_kwargs_diff)
    def _fake_prepare_method(*args, **kwds):
        for kwd in kwds:
            self.assertEqual(target[kwd], kwds[kwd])
        return rpcapi.client
    def _fake_rpc_method(*args, **kwargs):
        self.assertEqual((self.context, expected_method), args)
        for (kwarg, value) in kwargs.items():
            if isinstance(value, objects_base.CinderObject):
                self._assertEqualObjects(expected_msg[kwarg], value)
            else:
                self.assertEqual(expected_msg[kwarg], value)
        if retval:
            return retval
    with mock.patch.object(rpcapi.client, 'prepare', side_effect=_fake_prepare_method):
        with mock.patch.object(rpcapi.client, rpc_method, side_effect=_fake_rpc_method):
            real_retval = getattr(rpcapi, method)(self.context, **kwargs)
            self.assertEqual(expected_retval, real_retval)
