本文整理汇总了Python中oslo_messaging.MessagingTimeout方法的典型用法代码示例。如果您正苦于以下问题:Python oslo_messaging.MessagingTimeout方法的具体用法?Python oslo_messaging.MessagingTimeout怎么用?Python oslo_messaging.MessagingTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_messaging
的用法示例。
在下文中一共展示了oslo_messaging.MessagingTimeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_connection_to_gateway
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def update_connection_to_gateway(self, context, ovsdb_identifier,
ls_dict, locator_list, mac_dict,
port_dict, op_method):
"""RPC to update the connection to gateway."""
self._validate_request_op_method(context, op_method)
cctxt = self.client.prepare()
try:
return cctxt.call(context,
'update_connection_to_gateway',
ovsdb_identifier=ovsdb_identifier,
logical_switch_dict=ls_dict,
locator_dicts=locator_list,
mac_dicts=mac_dict,
port_dicts=port_dict,
op_method=op_method)
except messaging.MessagingTimeout:
message = _("Communication error with the L2 gateway agent")
raise l2gw_exc.OVSDBError(message=message)
except Exception as ex:
message = str(ex)
msg_splits = message.split('\n')
raise l2gw_exc.OVSDBError(message="Error on the OVSDB "
"server: " + msg_splits[0])
示例2: _route
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def _route(self, args, request=None):
"""All requests go through here
We can check the backend status
"""
if not pecan.request.check_backend:
return super(RootRestController, self)._route(args, request)
try:
client = pecan.request.client.prepare(timeout=5)
backend_is_alive = client.call(pecan.request.context, 'is_alive')
if backend_is_alive:
return super(RootRestController, self)._route(args, request)
else:
pecan.abort(503, detail='vitrage-graph is not ready')
except oslo_messaging.MessagingTimeout:
pecan.abort(503, detail='vitrage-graph not available')
示例3: notify
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def notify(engine_id, method, **kwargs):
"""Send notification to health manager service.
Note that the health manager only handles JSON type of parameter passing.
:param engine_id: dispatcher to notify; broadcast if value is None
:param method: remote method to call
"""
timeout = cfg.CONF.engine_life_check_timeout
client = rpc.get_rpc_client(consts.HEALTH_MANAGER_TOPIC, None)
if engine_id:
# Notify specific dispatcher identified by engine_id
call_context = client.prepare(timeout=timeout, server=engine_id)
else:
# Broadcast to all disptachers
call_context = client.prepare(timeout=timeout)
ctx = context.get_admin_context()
try:
call_context.call(ctx, method, **kwargs)
return True
except messaging.MessagingTimeout:
return False
示例4: setUp
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def setUp(self):
super(TimeoutTestCase, self).setUp()
self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
self.messaging_conf.transport_url = 'fake://'
self.messaging_conf.response_timeout = 0
self.useFixture(self.messaging_conf)
self.addCleanup(rpc.cleanup)
rpc.init(CONF)
rpc.TRANSPORT = mock.MagicMock()
rpc.TRANSPORT._send.side_effect = messaging.MessagingTimeout
target = messaging.Target(version='1.0', topic='testing')
self.client = rpc.get_client(target)
self.call_context = mock.Mock()
self.sleep = mock.patch('time.sleep').start()
rpc.TRANSPORT.conf.rpc_response_timeout = 10
rpc.TRANSPORT.conf.rpc_response_max_timeout = 300
示例5: __call__
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def __call__(self, request):
try:
return request.get_response(self.application)
except exceptions.DesignateException as e:
# Handle Designate Exceptions
status = e.error_code if hasattr(e, 'error_code') else 500
# Start building up a response
response = {
'code': status
}
if e.error_type:
response['type'] = e.error_type
if e.error_message:
response['message'] = e.error_message
if e.errors:
response['errors'] = e.errors
return self._handle_exception(request, e, status, response)
except messaging.MessagingTimeout as e:
# Special case for RPC timeout's
response = {
'code': 504,
'type': 'timeout',
}
return self._handle_exception(request, e, 504, response)
except Exception as e:
# Handle all other exception types
return self._handle_exception(request, e)
示例6: test_update_connection_to_gateway_with_error
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def test_update_connection_to_gateway_with_error(self):
cctxt = mock.Mock()
fake_ovsdb_identifier = 'fake_ovsdb_id'
fake_logical_switch = {}
fake_physical_locator_list = []
fake_mac_dicts = [{}]
fake_port_dicts = [{}]
fake_op_method = 'CREATE'
self.plugin_rpc.client.prepare.return_value = cctxt
# Test with a timeout exception
with mock.patch.object(cctxt,
'call',
side_effect=messaging.MessagingTimeout):
self.assertRaises(
l2gw_exc.OVSDBError,
self.plugin_rpc.update_connection_to_gateway,
self.context, fake_ovsdb_identifier, fake_logical_switch,
fake_physical_locator_list, fake_mac_dicts, fake_port_dicts,
fake_op_method)
# Test with a remote exception
with mock.patch.object(cctxt,
'call',
side_effect=Exception):
self.assertRaises(
l2gw_exc.OVSDBError,
self.plugin_rpc.update_connection_to_gateway,
self.context, fake_ovsdb_identifier, fake_logical_switch,
fake_physical_locator_list, fake_mac_dicts, fake_port_dicts,
fake_op_method)
示例7: get
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def get(self):
enforce("get status", pecan.request.headers,
pecan.request.enforcer, {})
try:
client = pecan.request.client.prepare(timeout=5)
backend_is_alive = client.call(pecan.request.context, 'is_alive')
if backend_is_alive:
return {'reason': 'OK'}
else:
pecan.abort(503, detail='vitrage-graph is not ready')
except oslo_messaging.MessagingTimeout:
pecan.abort(503, detail='vitrage-graph is not available')
示例8: test_get_status_not_ok_timeout
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def test_get_status_not_ok_timeout(self):
with mock.patch('pecan.request') as request:
client = mock.Mock()
client.call.side_effect = oslo_messaging.MessagingTimeout()
request.client.prepare.return_value = client
resp = self.get_json('/status/', expect_errors=True)
self.assertEqual(503, resp.status_code)
self.assertIn('vitrage-graph is not available', resp.text)
示例9: call
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def call(self, ctxt, method, **kwargs):
# two methods with the same name in different namespaces should
# be tracked independently
if self._original_context.target.namespace:
scoped_method = '%s.%s' % (self._original_context.target.namespace,
method)
else:
scoped_method = method
# set the timeout from the global method timeout tracker for this
# method
self._original_context.timeout = self._METHOD_TIMEOUTS[scoped_method]
try:
return self._original_context.call(ctxt, method, **kwargs)
except oslo_messaging.MessagingTimeout:
with excutils.save_and_reraise_exception():
wait = random.uniform(
0,
min(self._METHOD_TIMEOUTS[scoped_method],
TRANSPORT.conf.rpc_response_timeout)
)
LOG.error("Timeout in RPC method %(method)s. Waiting for "
"%(wait)s seconds before next attempt. If the "
"server is not down, consider increasing the "
"rpc_response_timeout option as message "
"server(s) may be overloaded and unable to "
"respond quickly enough.",
{'wait': int(round(wait)), 'method': scoped_method})
new_timeout = min(
self._original_context.timeout * 2, self.get_max_timeout())
if new_timeout > self._METHOD_TIMEOUTS[scoped_method]:
LOG.warning("Increasing timeout for %(method)s calls "
"to %(new)s seconds. Restart the client to "
"restore it to the default value.",
{'method': scoped_method, 'new': new_timeout})
self._METHOD_TIMEOUTS[scoped_method] = new_timeout
time.sleep(wait)
示例10: notify
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def notify(method, engine_id=None, **kwargs):
"""Send notification to dispatcher.
Note that dispatcher is an engine internal communication. We are not using
versioned object serialization at this level.
:param method: remote method to call
:param engine_id: dispatcher to notify; None implies broadcast
"""
client = messaging.get_rpc_client(consts.ENGINE_TOPIC, cfg.CONF.host)
if engine_id:
# Notify specific dispatcher identified by engine_id
call_context = client.prepare(server=engine_id)
else:
# Broadcast to all disptachers
call_context = client.prepare(fanout=True)
try:
# We don't use ctext parameter in action progress
# actually. But since RPCClient.call needs this param,
# we use oslo current context here.
call_context.cast(oslo_context.get_current(), method, **kwargs)
return True
except oslo_messaging.MessagingTimeout:
return False
示例11: test_notify_timeout
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def test_notify_timeout(self, mock_rpc):
cfg.CONF.set_override('host', 'HOSTNAME')
mock_rpc.return_value = mock.Mock()
mock_client = mock_rpc.return_value
mock_context = mock_client.prepare.return_value
mock_context.cast.side_effect = oslo_messaging.MessagingTimeout
result = dispatcher.notify('METHOD')
self.assertFalse(result)
mock_rpc.assert_called_once_with(consts.ENGINE_TOPIC, 'HOSTNAME')
mock_client.prepare.assert_called_once_with(fanout=True)
mock_context.cast.assert_called_once_with(mock.ANY, 'METHOD')
示例12: call
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def call(self, ctxt, method, **kwargs):
# two methods with the same name in different namespaces should
# be tracked independently
if self._original_context.target.namespace:
scoped_method = '%s.%s' % (self._original_context.target.namespace,
method)
else:
scoped_method = method
# set the timeout from the global method timeout tracker for this
# method
self._original_context.timeout = self._METHOD_TIMEOUTS[scoped_method]
try:
return self._original_context.call(ctxt, method, **kwargs)
except oslo_messaging.MessagingTimeout:
with excutils.save_and_reraise_exception():
wait = random.uniform(
0,
min(self._METHOD_TIMEOUTS[scoped_method],
TRANSPORT.conf.rpc_response_timeout)
)
LOG.error("Timeout in RPC method %(method)s. Waiting for "
"%(wait)s seconds before next attempt. If the "
"server is not down, consider increasing the "
"rpc_response_timeout option as Neutron "
"server(s) may be overloaded and unable to "
"respond quickly enough.",
{'wait': int(round(wait)), 'method': scoped_method})
new_timeout = min(
self._original_context.timeout * 2, self.get_max_timeout())
if new_timeout > self._METHOD_TIMEOUTS[scoped_method]:
LOG.warning("Increasing timeout for %(method)s calls "
"to %(new)s seconds. Restart the agent to "
"restore it to the default value.",
{'method': scoped_method, 'new': new_timeout})
self._METHOD_TIMEOUTS[scoped_method] = new_timeout
time.sleep(wait)
示例13: test_timeout_unaffected_when_explicitly_set
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def test_timeout_unaffected_when_explicitly_set(self):
rpc.TRANSPORT.conf.rpc_response_timeout = 5
ctx = self.client.prepare(topic='sandwiches', timeout=77)
with testtools.ExpectedException(messaging.MessagingTimeout):
ctx.call(self.call_context, 'create_pb_and_j')
# ensure that the timeout was not increased and the back-off sleep
# wasn't called
self.assertEqual(
5,
rpc._BackingOffContextWrapper._METHOD_TIMEOUTS['create_pb_and_j'])
self.assertFalse(self.sleep.called)
示例14: test_method_timeout_sleep
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def test_method_timeout_sleep(self):
rpc.TRANSPORT.conf.rpc_response_timeout = 2
for i in range(100):
with testtools.ExpectedException(messaging.MessagingTimeout):
self.client.call(self.call_context, 'method_1')
# sleep value should always be between 0 and configured timeout
self.assertGreaterEqual(self.sleep.call_args_list[0][0][0], 0)
self.assertLessEqual(self.sleep.call_args_list[0][0][0], 2)
self.sleep.reset_mock()
示例15: test_method_timeout_increases_on_timeout_exception
# 需要导入模块: import oslo_messaging [as 别名]
# 或者: from oslo_messaging import MessagingTimeout [as 别名]
def test_method_timeout_increases_on_timeout_exception(self):
rpc._BackingOffContextWrapper._METHOD_TIMEOUTS['method_1'] = 1
for i in range(5):
with testtools.ExpectedException(messaging.MessagingTimeout):
self.client.call(self.call_context, 'method_1')
# we only care to check the timeouts sent to the transport
timeouts = [call[1]['timeout']
for call in rpc.TRANSPORT._send.call_args_list]
self.assertEqual([1, 2, 4, 8, 16], timeouts)