Merge "Drop RpcProxy usage from PluginReportStateAPI"
This commit is contained in:
commit
f0233e25a0
@ -54,22 +54,19 @@ def create_consumers(endpoints, prefix, topic_details):
|
|||||||
return connection
|
return connection
|
||||||
|
|
||||||
|
|
||||||
class PluginReportStateAPI(n_rpc.RpcProxy):
|
class PluginReportStateAPI(object):
|
||||||
BASE_RPC_API_VERSION = '1.0'
|
|
||||||
|
|
||||||
def __init__(self, topic):
|
def __init__(self, topic):
|
||||||
super(PluginReportStateAPI, self).__init__(
|
target = messaging.Target(topic=topic, version='1.0')
|
||||||
topic=topic, default_version=self.BASE_RPC_API_VERSION)
|
self.client = n_rpc.get_client(target)
|
||||||
|
|
||||||
def report_state(self, context, agent_state, use_call=False):
|
def report_state(self, context, agent_state, use_call=False):
|
||||||
msg = self.make_msg('report_state',
|
cctxt = self.client.prepare()
|
||||||
agent_state={'agent_state':
|
kwargs = {
|
||||||
agent_state},
|
'agent_state': {'agent_state': agent_state},
|
||||||
time=timeutils.strtime())
|
'time': timeutils.strtime(),
|
||||||
if use_call:
|
}
|
||||||
return self.call(context, msg)
|
method = cctxt.call if use_call else cctxt.cast
|
||||||
else:
|
return method(context, 'report_state', **kwargs)
|
||||||
return self.cast(context, msg)
|
|
||||||
|
|
||||||
|
|
||||||
class PluginApi(n_rpc.RpcProxy):
|
class PluginApi(n_rpc.RpcProxy):
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import mock
|
import mock
|
||||||
from oslo import messaging
|
from oslo import messaging
|
||||||
|
|
||||||
@ -65,32 +66,42 @@ class AgentPluginReportState(base.BaseTestCase):
|
|||||||
topic = 'test'
|
topic = 'test'
|
||||||
reportStateAPI = rpc.PluginReportStateAPI(topic)
|
reportStateAPI = rpc.PluginReportStateAPI(topic)
|
||||||
expected_agent_state = {'agent': 'test'}
|
expected_agent_state = {'agent': 'test'}
|
||||||
with mock.patch.object(reportStateAPI, 'call') as call:
|
with contextlib.nested(
|
||||||
|
mock.patch.object(reportStateAPI.client, 'call'),
|
||||||
|
mock.patch.object(reportStateAPI.client, 'cast'),
|
||||||
|
mock.patch.object(reportStateAPI.client, 'prepare'),
|
||||||
|
) as (
|
||||||
|
mock_call, mock_cast, mock_prepare
|
||||||
|
):
|
||||||
|
mock_prepare.return_value = reportStateAPI.client
|
||||||
ctxt = context.RequestContext('fake_user', 'fake_project')
|
ctxt = context.RequestContext('fake_user', 'fake_project')
|
||||||
reportStateAPI.report_state(ctxt, expected_agent_state,
|
reportStateAPI.report_state(ctxt, expected_agent_state,
|
||||||
use_call=True)
|
use_call=True)
|
||||||
self.assertEqual(call.call_args[0][0], ctxt)
|
self.assertEqual(mock_call.call_args[0][0], ctxt)
|
||||||
self.assertEqual(call.call_args[0][1]['method'],
|
self.assertEqual(mock_call.call_args[0][1], 'report_state')
|
||||||
'report_state')
|
self.assertEqual(mock_call.call_args[1]['agent_state'],
|
||||||
self.assertEqual(call.call_args[0][1]['args']['agent_state'],
|
|
||||||
{'agent_state': expected_agent_state})
|
{'agent_state': expected_agent_state})
|
||||||
self.assertIsInstance(call.call_args[0][1]['args']['time'],
|
self.assertIsInstance(mock_call.call_args[1]['time'], str)
|
||||||
str)
|
|
||||||
|
|
||||||
def test_plugin_report_state_cast(self):
|
def test_plugin_report_state_cast(self):
|
||||||
topic = 'test'
|
topic = 'test'
|
||||||
reportStateAPI = rpc.PluginReportStateAPI(topic)
|
reportStateAPI = rpc.PluginReportStateAPI(topic)
|
||||||
expected_agent_state = {'agent': 'test'}
|
expected_agent_state = {'agent': 'test'}
|
||||||
with mock.patch.object(reportStateAPI, 'cast') as cast:
|
with contextlib.nested(
|
||||||
|
mock.patch.object(reportStateAPI.client, 'call'),
|
||||||
|
mock.patch.object(reportStateAPI.client, 'cast'),
|
||||||
|
mock.patch.object(reportStateAPI.client, 'prepare'),
|
||||||
|
) as (
|
||||||
|
mock_call, mock_cast, mock_prepare
|
||||||
|
):
|
||||||
|
mock_prepare.return_value = reportStateAPI.client
|
||||||
ctxt = context.RequestContext('fake_user', 'fake_project')
|
ctxt = context.RequestContext('fake_user', 'fake_project')
|
||||||
reportStateAPI.report_state(ctxt, expected_agent_state)
|
reportStateAPI.report_state(ctxt, expected_agent_state)
|
||||||
self.assertEqual(cast.call_args[0][0], ctxt)
|
self.assertEqual(mock_cast.call_args[0][0], ctxt)
|
||||||
self.assertEqual(cast.call_args[0][1]['method'],
|
self.assertEqual(mock_cast.call_args[0][1], 'report_state')
|
||||||
'report_state')
|
self.assertEqual(mock_cast.call_args[1]['agent_state'],
|
||||||
self.assertEqual(cast.call_args[0][1]['args']['agent_state'],
|
|
||||||
{'agent_state': expected_agent_state})
|
{'agent_state': expected_agent_state})
|
||||||
self.assertIsInstance(cast.call_args[0][1]['args']['time'],
|
self.assertIsInstance(mock_cast.call_args[1]['time'], str)
|
||||||
str)
|
|
||||||
|
|
||||||
|
|
||||||
class AgentRPCMethods(base.BaseTestCase):
|
class AgentRPCMethods(base.BaseTestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user