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