Merge "Drop RpcProxy usage from FWaaS code"
This commit is contained in:
commit
49fee853ad
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
from oslo.config import cfg
|
||||
from oslo import messaging
|
||||
|
||||
from neutron.common import rpc as n_rpc
|
||||
from neutron.openstack.common import log as logging
|
||||
@ -33,28 +34,25 @@ FWaaSOpts = [
|
||||
cfg.CONF.register_opts(FWaaSOpts, 'fwaas')
|
||||
|
||||
|
||||
class FWaaSPluginApiMixin(n_rpc.RpcProxy):
|
||||
class FWaaSPluginApiMixin(object):
|
||||
"""Agent side of the FWaaS agent to FWaaS Plugin RPC API."""
|
||||
|
||||
RPC_API_VERSION = '1.0'
|
||||
|
||||
def __init__(self, topic, host):
|
||||
super(FWaaSPluginApiMixin,
|
||||
self).__init__(topic=topic,
|
||||
default_version=self.RPC_API_VERSION)
|
||||
self.host = host
|
||||
target = messaging.Target(topic=topic, version='1.0')
|
||||
self.client = n_rpc.get_client(target)
|
||||
|
||||
def set_firewall_status(self, context, firewall_id, status):
|
||||
"""Make a RPC to set the status of a firewall."""
|
||||
return self.call(context,
|
||||
self.make_msg('set_firewall_status', host=self.host,
|
||||
firewall_id=firewall_id, status=status))
|
||||
cctxt = self.client.prepare()
|
||||
return cctxt.call(context, 'set_firewall_status', host=self.host,
|
||||
firewall_id=firewall_id, status=status)
|
||||
|
||||
def firewall_deleted(self, context, firewall_id):
|
||||
"""Make a RPC to indicate that the firewall resources are deleted."""
|
||||
return self.call(context,
|
||||
self.make_msg('firewall_deleted', host=self.host,
|
||||
firewall_id=firewall_id))
|
||||
cctxt = self.client.prepare()
|
||||
return cctxt.call(context, 'firewall_deleted', host=self.host,
|
||||
firewall_id=firewall_id)
|
||||
|
||||
|
||||
class FWaaSAgentRpcCallbackMixin(object):
|
||||
|
@ -97,35 +97,28 @@ class FirewallCallbacks(object):
|
||||
return fw_tenant_list
|
||||
|
||||
|
||||
class FirewallAgentApi(n_rpc.RpcProxy):
|
||||
class FirewallAgentApi(object):
|
||||
"""Plugin side of plugin to agent RPC API."""
|
||||
|
||||
API_VERSION = '1.0'
|
||||
|
||||
def __init__(self, topic, host):
|
||||
super(FirewallAgentApi, self).__init__(topic, self.API_VERSION)
|
||||
self.host = host
|
||||
target = messaging.Target(topic=topic, version='1.0')
|
||||
self.client = n_rpc.get_client(target)
|
||||
|
||||
def create_firewall(self, context, firewall):
|
||||
return self.fanout_cast(
|
||||
context,
|
||||
self.make_msg('create_firewall', firewall=firewall,
|
||||
host=self.host)
|
||||
)
|
||||
cctxt = self.client.prepare(fanout=True)
|
||||
cctxt.cast(context, 'create_firewall', firewall=firewall,
|
||||
host=self.host)
|
||||
|
||||
def update_firewall(self, context, firewall):
|
||||
return self.fanout_cast(
|
||||
context,
|
||||
self.make_msg('update_firewall', firewall=firewall,
|
||||
host=self.host)
|
||||
)
|
||||
cctxt = self.client.prepare(fanout=True)
|
||||
cctxt.cast(context, 'update_firewall', firewall=firewall,
|
||||
host=self.host)
|
||||
|
||||
def delete_firewall(self, context, firewall):
|
||||
return self.fanout_cast(
|
||||
context,
|
||||
self.make_msg('delete_firewall', firewall=firewall,
|
||||
host=self.host)
|
||||
)
|
||||
cctxt = self.client.prepare(fanout=True)
|
||||
cctxt.cast(context, 'delete_firewall', firewall=firewall,
|
||||
host=self.host)
|
||||
|
||||
|
||||
class FirewallCountExceeded(n_exception.Conflict):
|
||||
|
@ -52,46 +52,26 @@ class TestFWaaSAgentApi(base.BaseTestCase):
|
||||
def test_init(self):
|
||||
self.assertEqual(self.api.host, 'host')
|
||||
|
||||
def test_set_firewall_status(self):
|
||||
def _test_firewall_method(self, method_name, **kwargs):
|
||||
with contextlib.nested(
|
||||
mock.patch.object(self.api, 'make_msg'),
|
||||
mock.patch.object(self.api, 'call')
|
||||
) as (mock_make_msg, mock_call):
|
||||
mock.patch.object(self.api.client, 'call'),
|
||||
mock.patch.object(self.api.client, 'prepare'),
|
||||
) as (
|
||||
rpc_mock, prepare_mock
|
||||
):
|
||||
prepare_mock.return_value = self.api.client
|
||||
getattr(self.api, method_name)(mock.sentinel.context, 'test',
|
||||
**kwargs)
|
||||
|
||||
self.assertEqual(
|
||||
self.api.set_firewall_status(
|
||||
mock.sentinel.context,
|
||||
'firewall_id',
|
||||
'status'),
|
||||
mock_call.return_value)
|
||||
prepare_args = {}
|
||||
prepare_mock.assert_called_once_with(**prepare_args)
|
||||
|
||||
mock_make_msg.assert_called_once_with(
|
||||
'set_firewall_status',
|
||||
host='host',
|
||||
firewall_id='firewall_id',
|
||||
status='status')
|
||||
rpc_mock.assert_called_once_with(mock.sentinel.context, method_name,
|
||||
firewall_id='test', host='host',
|
||||
**kwargs)
|
||||
|
||||
mock_call.assert_called_once_with(
|
||||
mock.sentinel.context,
|
||||
mock_make_msg.return_value)
|
||||
def test_set_firewall_status(self):
|
||||
self._test_firewall_method('set_firewall_status', status='fake_status')
|
||||
|
||||
def test_firewall_deleted(self):
|
||||
with contextlib.nested(
|
||||
mock.patch.object(self.api, 'make_msg'),
|
||||
mock.patch.object(self.api, 'call')
|
||||
) as (mock_make_msg, mock_call):
|
||||
|
||||
self.assertEqual(
|
||||
self.api.firewall_deleted(
|
||||
mock.sentinel.context,
|
||||
'firewall_id'),
|
||||
mock_call.return_value)
|
||||
|
||||
mock_make_msg.assert_called_once_with(
|
||||
'firewall_deleted',
|
||||
host='host',
|
||||
firewall_id='firewall_id')
|
||||
|
||||
mock_call.assert_called_once_with(
|
||||
mock.sentinel.context,
|
||||
mock_make_msg.return_value)
|
||||
self._test_firewall_method('firewall_deleted')
|
||||
|
@ -171,27 +171,26 @@ class TestFirewallAgentApi(base.BaseTestCase):
|
||||
super(TestFirewallAgentApi, self).setUp()
|
||||
|
||||
self.api = fwaas_plugin.FirewallAgentApi('topic', 'host')
|
||||
self.mock_fanoutcast = mock.patch.object(self.api,
|
||||
'fanout_cast').start()
|
||||
self.mock_msg = mock.patch.object(self.api, 'make_msg').start()
|
||||
|
||||
def test_init(self):
|
||||
self.assertEqual(self.api.topic, 'topic')
|
||||
self.assertEqual(self.api.client.target.topic, 'topic')
|
||||
self.assertEqual(self.api.host, 'host')
|
||||
|
||||
def _call_test_helper(self, method_name):
|
||||
rv = getattr(self.api, method_name)(mock.sentinel.context, 'test')
|
||||
self.assertEqual(rv, self.mock_fanoutcast.return_value)
|
||||
self.mock_fanoutcast.assert_called_once_with(
|
||||
mock.sentinel.context,
|
||||
self.mock_msg.return_value
|
||||
)
|
||||
with contextlib.nested(
|
||||
mock.patch.object(self.api.client, 'cast'),
|
||||
mock.patch.object(self.api.client, 'prepare'),
|
||||
) as (
|
||||
rpc_mock, prepare_mock
|
||||
):
|
||||
prepare_mock.return_value = self.api.client
|
||||
getattr(self.api, method_name)(mock.sentinel.context, 'test')
|
||||
|
||||
self.mock_msg.assert_called_once_with(
|
||||
method_name,
|
||||
firewall='test',
|
||||
host='host'
|
||||
)
|
||||
prepare_args = {'fanout': True}
|
||||
prepare_mock.assert_called_once_with(**prepare_args)
|
||||
|
||||
rpc_mock.assert_called_once_with(mock.sentinel.context, method_name,
|
||||
firewall='test', host='host')
|
||||
|
||||
def test_create_firewall(self):
|
||||
self._call_test_helper('create_firewall')
|
||||
|
Loading…
Reference in New Issue
Block a user