Python oslo_messaging.MessagingTimeout() Examples
The following are 19
code examples of oslo_messaging.MessagingTimeout().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
oslo_messaging
, or try the search function
.
Example #1
Source File: agent_api.py From networking-l2gw with Apache License 2.0 | 6 votes |
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])
Example #2
Source File: rest.py From vitrage with Apache License 2.0 | 6 votes |
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')
Example #3
Source File: health_manager.py From senlin with Apache License 2.0 | 6 votes |
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
Example #4
Source File: test_rpc.py From neutron-lib with Apache License 2.0 | 6 votes |
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
Example #5
Source File: test_rpc.py From neutron-lib with Apache License 2.0 | 5 votes |
def test_method_timeout_increases_with_prepare(self): rpc._BackingOffContextWrapper._METHOD_TIMEOUTS['method_1'] = 1 ctx = self.client.prepare(version='1.4') with testtools.ExpectedException(messaging.MessagingTimeout): ctx.call(self.call_context, 'method_1') with testtools.ExpectedException(messaging.MessagingTimeout): ctx.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], timeouts)
Example #6
Source File: middleware.py From designate with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: test_rpc.py From neutron-lib with Apache License 2.0 | 5 votes |
def test_timeouts_for_namespaces_tracked_independently(self): rpc._BackingOffContextWrapper._METHOD_TIMEOUTS['ns1.method'] = 1 rpc._BackingOffContextWrapper._METHOD_TIMEOUTS['ns2.method'] = 1 for ns in ('ns1', 'ns2'): self.client.target.namespace = ns for i in range(4): with testtools.ExpectedException(messaging.MessagingTimeout): self.client.call(self.call_context, 'method') timeouts = [call[1]['timeout'] for call in rpc.TRANSPORT._send.call_args_list] self.assertEqual([1, 2, 4, 8, 1, 2, 4, 8], timeouts)
Example #8
Source File: test_rpc.py From neutron-lib with Apache License 2.0 | 5 votes |
def test_timeouts_for_methods_tracked_independently(self): rpc._BackingOffContextWrapper._METHOD_TIMEOUTS['method_1'] = 1 rpc._BackingOffContextWrapper._METHOD_TIMEOUTS['method_2'] = 1 for method in ('method_1', 'method_1', 'method_2', 'method_1', 'method_2'): with testtools.ExpectedException(messaging.MessagingTimeout): self.client.call(self.call_context, method) timeouts = [call[1]['timeout'] for call in rpc.TRANSPORT._send.call_args_list] self.assertEqual([1, 2, 1, 4, 2], timeouts)
Example #9
Source File: test_rpc.py From neutron-lib with Apache License 2.0 | 5 votes |
def test_timeout_unchanged_on_other_exception(self): rpc._BackingOffContextWrapper._METHOD_TIMEOUTS['method_1'] = 1 rpc.TRANSPORT._send.side_effect = ValueError with testtools.ExpectedException(ValueError): self.client.call(self.call_context, 'method_1') rpc.TRANSPORT._send.side_effect = messaging.MessagingTimeout with testtools.ExpectedException(messaging.MessagingTimeout): self.client.call(self.call_context, 'method_1') timeouts = [call[1]['timeout'] for call in rpc.TRANSPORT._send.call_args_list] self.assertEqual([1, 1], timeouts)
Example #10
Source File: test_rpc.py From neutron-lib with Apache License 2.0 | 5 votes |
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)
Example #11
Source File: test_rpc.py From neutron-lib with Apache License 2.0 | 5 votes |
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()
Example #12
Source File: test_rpc.py From neutron-lib with Apache License 2.0 | 5 votes |
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)
Example #13
Source File: rpc.py From neutron-lib with Apache License 2.0 | 5 votes |
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)
Example #14
Source File: test_service.py From senlin with Apache License 2.0 | 5 votes |
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')
Example #15
Source File: dispatcher.py From senlin with Apache License 2.0 | 5 votes |
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
Example #16
Source File: rpc.py From tacker with Apache License 2.0 | 5 votes |
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)
Example #17
Source File: test_status.py From vitrage with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: status.py From vitrage with Apache License 2.0 | 5 votes |
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')
Example #19
Source File: test_agent_api.py From networking-l2gw with Apache License 2.0 | 5 votes |
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)