diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-15 21:33:41 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-15 21:33:41 +0300 |
commit | 3dd665b514943f69657b593eb51af90b99b1206b (patch) | |
tree | 0eb633e628bb1fe6c639574b1184d43def7c0a73 /contrib/libs/grpc/src/python | |
parent | a68afc731202027f105bc5723ee11788017c29e2 (diff) | |
download | ydb-3dd665b514943f69657b593eb51af90b99b1206b.tar.gz |
intermediate changes
ref:953ca886ec160075b38c0f3614de029b423f0a9e
Diffstat (limited to 'contrib/libs/grpc/src/python')
74 files changed, 1588 insertions, 738 deletions
diff --git a/contrib/libs/grpc/src/python/grpcio/commands.py b/contrib/libs/grpc/src/python/grpcio/commands.py index 8240beb295..f4a3d2bdc0 100644 --- a/contrib/libs/grpc/src/python/grpcio/commands.py +++ b/contrib/libs/grpc/src/python/grpcio/commands.py @@ -24,6 +24,7 @@ import re import shutil import subprocess import sys +import sysconfig import traceback import setuptools @@ -211,21 +212,38 @@ class BuildExt(build_ext.build_ext): } LINK_OPTIONS = {} + def get_ext_filename(self, ext_name): + # since python3.5, python extensions' shared libraries use a suffix that corresponds to the value + # of sysconfig.get_config_var('EXT_SUFFIX') and contains info about the architecture the library targets. + # E.g. on x64 linux the suffix is ".cpython-XYZ-x86_64-linux-gnu.so" + # When crosscompiling python wheels, we need to be able to override this suffix + # so that the resulting file name matches the target architecture and we end up with a well-formed + # wheel. + filename = build_ext.build_ext.get_ext_filename(self, ext_name) + orig_ext_suffix = sysconfig.get_config_var('EXT_SUFFIX') + new_ext_suffix = os.getenv('GRPC_PYTHON_OVERRIDE_EXT_SUFFIX') + if new_ext_suffix and filename.endswith(orig_ext_suffix): + filename = filename[:-len(orig_ext_suffix)] + new_ext_suffix + return filename + def build_extensions(self): def compiler_ok_with_extra_std(): """Test if default compiler is okay with specifying c++ version when invoked in C mode. GCC is okay with this, while clang is not. """ - if platform.system() != 'Windows': + try: + # TODO(lidiz) Remove the generated a.out for success tests. + cc_test = subprocess.Popen(['cc', '-x', 'c', '-std=c++11', '-'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + _, cc_err = cc_test.communicate(input=b'int main(){return 0;}') + return not 'invalid argument' in str(cc_err) + except: + sys.stderr.write('Non-fatal exception:' + + traceback.format_exc() + '\n') return False - # TODO(lidiz) Remove the generated a.out for success tests. - cc_test = subprocess.Popen(['cc', '-x', 'c', '-std=c++11', '-'], - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - _, cc_err = cc_test.communicate(input=b'int main(){return 0;}') - return not 'invalid argument' in str(cc_err) # This special conditioning is here due to difference of compiler # behavior in gcc and clang. The clang doesn't take --stdc++11 diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/__init__.py b/contrib/libs/grpc/src/python/grpcio/grpc/__init__.py index abe87458c4..69803ed161 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/__init__.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/__init__.py @@ -406,8 +406,6 @@ class Call(six.with_metaclass(abc.ABCMeta, RpcContext)): class ClientCallDetails(six.with_metaclass(abc.ABCMeta)): """Describes an RPC to be invoked. - This is an EXPERIMENTAL API. - Attributes: method: The method name of the RPC. timeout: An optional duration of time in seconds to allow for the RPC. @@ -422,10 +420,7 @@ class ClientCallDetails(six.with_metaclass(abc.ABCMeta)): class UnaryUnaryClientInterceptor(six.with_metaclass(abc.ABCMeta)): - """Affords intercepting unary-unary invocations. - - This is an EXPERIMENTAL API. - """ + """Affords intercepting unary-unary invocations.""" @abc.abstractmethod def intercept_unary_unary(self, continuation, client_call_details, request): @@ -459,10 +454,7 @@ class UnaryUnaryClientInterceptor(six.with_metaclass(abc.ABCMeta)): class UnaryStreamClientInterceptor(six.with_metaclass(abc.ABCMeta)): - """Affords intercepting unary-stream invocations. - - This is an EXPERIMENTAL API. - """ + """Affords intercepting unary-stream invocations.""" @abc.abstractmethod def intercept_unary_stream(self, continuation, client_call_details, @@ -489,16 +481,14 @@ class UnaryStreamClientInterceptor(six.with_metaclass(abc.ABCMeta)): An object that is both a Call for the RPC and an iterator of response values. Drawing response values from the returned Call-iterator may raise RpcError indicating termination of - the RPC with non-OK status. + the RPC with non-OK status. This object *should* also fulfill the + Future interface, though it may not. """ raise NotImplementedError() class StreamUnaryClientInterceptor(six.with_metaclass(abc.ABCMeta)): - """Affords intercepting stream-unary invocations. - - This is an EXPERIMENTAL API. - """ + """Affords intercepting stream-unary invocations.""" @abc.abstractmethod def intercept_stream_unary(self, continuation, client_call_details, @@ -532,10 +522,7 @@ class StreamUnaryClientInterceptor(six.with_metaclass(abc.ABCMeta)): class StreamStreamClientInterceptor(six.with_metaclass(abc.ABCMeta)): - """Affords intercepting stream-stream invocations. - - This is an EXPERIMENTAL API. - """ + """Affords intercepting stream-stream invocations.""" @abc.abstractmethod def intercept_stream_stream(self, continuation, client_call_details, @@ -562,7 +549,8 @@ class StreamStreamClientInterceptor(six.with_metaclass(abc.ABCMeta)): An object that is both a Call for the RPC and an iterator of response values. Drawing response values from the returned Call-iterator may raise RpcError indicating termination of - the RPC with non-OK status. + the RPC with non-OK status. This object *should* also fulfill the + Future interface, though it may not. """ raise NotImplementedError() @@ -797,10 +785,10 @@ class UnaryStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): grpc.compression.Gzip. This is an EXPERIMENTAL option. Returns: - An object that is both a Call for the RPC and an iterator of - response values. Drawing response values from the returned - Call-iterator may raise RpcError indicating termination of the - RPC with non-OK status. + An object that is a Call for the RPC, an iterator of response + values, and a Future for the RPC. Drawing response values from the + returned Call-iterator may raise RpcError indicating termination of + the RPC with non-OK status. """ raise NotImplementedError() @@ -936,10 +924,10 @@ class StreamStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): grpc.compression.Gzip. This is an EXPERIMENTAL option. Returns: - An object that is both a Call for the RPC and an iterator of - response values. Drawing response values from the returned - Call-iterator may raise RpcError indicating termination of the - RPC with non-OK status. + An object that is a Call for the RPC, an iterator of response + values, and a Future for the RPC. Drawing response values from the + returned Call-iterator may raise RpcError indicating termination of + the RPC with non-OK status. """ raise NotImplementedError() @@ -1349,10 +1337,7 @@ class ServiceRpcHandler(six.with_metaclass(abc.ABCMeta, GenericRpcHandler)): class ServerInterceptor(six.with_metaclass(abc.ABCMeta)): - """Affords intercepting incoming RPCs on the service-side. - - This is an EXPERIMENTAL API. - """ + """Affords intercepting incoming RPCs on the service-side.""" @abc.abstractmethod def intercept_service(self, continuation, handler_call_details): @@ -1607,6 +1592,21 @@ def ssl_channel_credentials(root_certificates=None, certificate_chain)) +def xds_channel_credentials(fallback_credentials=None): + """Creates a ChannelCredentials for use with xDS. This is an EXPERIMENTAL + API. + + Args: + fallback_credentials: Credentials to use in case it is not possible to + establish a secure connection via xDS. If no fallback_credentials + argument is supplied, a default SSLChannelCredentials is used. + """ + fallback_credentials = ssl_channel_credentials( + ) if fallback_credentials is None else fallback_credentials + return ChannelCredentials( + _cygrpc.XDSChannelCredentials(fallback_credentials._credentials)) + + def metadata_call_credentials(metadata_plugin, name=None): """Construct CallCredentials from an AuthMetadataPlugin. @@ -1706,6 +1706,29 @@ def ssl_server_credentials(private_key_certificate_chain_pairs, ], require_client_auth)) +def xds_server_credentials(fallback_credentials): + """Creates a ServerCredentials for use with xDS. This is an EXPERIMENTAL + API. + + Args: + fallback_credentials: Credentials to use in case it is not possible to + establish a secure connection via xDS. No default value is provided. + """ + return ServerCredentials( + _cygrpc.xds_server_credentials(fallback_credentials._credentials)) + + +def insecure_server_credentials(): + """Creates a credentials object directing the server to use no credentials. + This is an EXPERIMENTAL API. + + This object cannot be used directly in a call to `add_secure_port`. + Instead, it should be used to construct other credentials objects, e.g. + with xds_server_credentials. + """ + return ServerCredentials(_cygrpc.insecure_server_credentials()) + + def ssl_server_certificate_configuration(private_key_certificate_chain_pairs, root_certificates=None): """Creates a ServerCertificateConfiguration for use with a Server. @@ -1951,8 +1974,6 @@ def secure_channel(target, credentials, options=None, compression=None): def intercept_channel(channel, *interceptors): """Intercepts a channel through a set of interceptors. - This is an EXPERIMENTAL API. - Args: channel: A Channel. interceptors: Zero or more objects of type @@ -1981,7 +2002,8 @@ def server(thread_pool, interceptors=None, options=None, maximum_concurrent_rpcs=None, - compression=None): + compression=None, + xds=False): """Creates a Server with which RPCs can be serviced. Args: @@ -2002,6 +2024,8 @@ def server(thread_pool, compression: An element of grpc.compression, e.g. grpc.compression.Gzip. This compression algorithm will be used for the lifetime of the server unless overridden. This is an EXPERIMENTAL option. + xds: If set to true, retrieves server configuration via xDS. This is an + EXPERIMENTAL option. Returns: A Server object. @@ -2011,7 +2035,7 @@ def server(thread_pool, () if handlers is None else handlers, () if interceptors is None else interceptors, () if options is None else options, - maximum_concurrent_rpcs, compression) + maximum_concurrent_rpcs, compression, xds) @contextlib.contextmanager @@ -2103,6 +2127,9 @@ __all__ = ( 'protos', 'services', 'protos_and_services', + 'xds_channel_credentials', + 'xds_server_credentials', + 'insecure_server_credentials', ) ############################### Extension Shims ################################ diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_channel.py b/contrib/libs/grpc/src/python/grpcio/grpc/_channel.py index 11921d7883..b98f3002f4 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_channel.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_channel.py @@ -93,9 +93,16 @@ def _unknown_code_details(unknown_cygrpc_code, details): class _RPCState(object): def __init__(self, due, initial_metadata, trailing_metadata, code, details): + # `condition` guards all members of _RPCState. `notify_all` is called on + # `condition` when the state of the RPC has changed. self.condition = threading.Condition() + # The cygrpc.OperationType objects representing events due from the RPC's - # completion queue. + # completion queue. If an operation is in `due`, it is guaranteed that + # `operate()` has been called on a corresponding operation. But the + # converse is not true. That is, in the case of failed `operate()` + # calls, there may briefly be events in `due` that do not correspond to + # operations submitted to Core. self.due = set(due) self.initial_metadata = initial_metadata self.response = None @@ -103,6 +110,7 @@ class _RPCState(object): self.code = code self.details = details self.debug_error_string = None + # The semantics of grpc.Future.cancel and grpc.Future.cancelled are # slightly wonky, so they have to be tracked separately from the rest of the # result of the RPC. This field tracks whether cancellation was requested @@ -220,18 +228,18 @@ def _consume_request_iterator(request_iterator, state, call, request_serializer, _abort(state, code, details) return else: + state.due.add(cygrpc.OperationType.send_message) operations = (cygrpc.SendMessageOperation( serialized_request, _EMPTY_FLAGS),) operating = call.operate(operations, event_handler) - if operating: - state.due.add(cygrpc.OperationType.send_message) - else: + if not operating: + state.due.remove(cygrpc.OperationType.send_message) return def _done(): return (state.code is not None or - cygrpc.OperationType.send_message not in - state.due) + cygrpc.OperationType.send_message + not in state.due) _common.wait(state.condition.wait, _done, @@ -244,11 +252,13 @@ def _consume_request_iterator(request_iterator, state, call, request_serializer, return with state.condition: if state.code is None: + state.due.add(cygrpc.OperationType.send_close_from_client) operations = ( cygrpc.SendCloseFromClientOperation(_EMPTY_FLAGS),) operating = call.operate(operations, event_handler) - if operating: - state.due.add(cygrpc.OperationType.send_close_from_client) + if not operating: + state.due.remove( + cygrpc.OperationType.send_close_from_client) consumption_thread = cygrpc.ForkManagedThread( target=consume_request_iterator) @@ -609,10 +619,22 @@ class _SingleThreadedRendezvous(_Rendezvous, grpc.Call, grpc.Future): # pylint: def _next(self): with self._state.condition: if self._state.code is None: + # We tentatively add the operation as expected and remove + # it if the enqueue operation fails. This allows us to guarantee that + # if an event has been submitted to the core completion queue, + # it is in `due`. If we waited until after a successful + # enqueue operation then a signal could interrupt this + # thread between the enqueue operation and the addition of the + # operation to `due`. This would cause an exception on the + # channel spin thread when the operation completes and no + # corresponding operation would be present in state.due. + # Note that, since `condition` is held through this block, there is + # no data race on `due`. + self._state.due.add(cygrpc.OperationType.receive_message) operating = self._call.operate( (cygrpc.ReceiveMessageOperation(_EMPTY_FLAGS),), None) - if operating: - self._state.due.add(cygrpc.OperationType.receive_message) + if not operating: + self._state.due.remove(cygrpc.OperationType.receive_message) elif self._state.code is grpc.StatusCode.OK: raise StopIteration() else: @@ -775,21 +797,22 @@ class _MultiThreadedRendezvous(_Rendezvous, grpc.Call, grpc.Future): # pylint: if self._state.code is None: event_handler = _event_handler(self._state, self._response_deserializer) + self._state.due.add(cygrpc.OperationType.receive_message) operating = self._call.operate( (cygrpc.ReceiveMessageOperation(_EMPTY_FLAGS),), event_handler) - if operating: - self._state.due.add(cygrpc.OperationType.receive_message) + if not operating: + self._state.due.remove(cygrpc.OperationType.receive_message) elif self._state.code is grpc.StatusCode.OK: raise StopIteration() else: raise self def _response_ready(): - return ( - self._state.response is not None or - (cygrpc.OperationType.receive_message not in self._state.due - and self._state.code is not None)) + return (self._state.response is not None or + (cygrpc.OperationType.receive_message + not in self._state.due and + self._state.code is not None)) _common.wait(self._state.condition.wait, _response_ready) if self._state.response is not None: @@ -1546,7 +1569,7 @@ class Channel(grpc.Channel): # here (or more likely, call self._close() here). We don't do this today # because many valid use cases today allow the channel to be deleted # immediately after stubs are created. After a sufficient period of time - # has passed for all users to be trusted to hang out to their channels + # has passed for all users to be trusted to freeze out to their channels # for as long as they are in use and to close them after using them, # then deletion of this grpc._channel.Channel instance can be made to # effect closure of the underlying cygrpc.Channel instance. diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi index 10c024e1b3..2c2a3ff3f6 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi @@ -360,7 +360,7 @@ cdef class _AioCall(GrpcCallWrapper): self, self._loop ) - if received_message: + if received_message is not None: return received_message else: return EOF diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pyx.pxi index 86fc91e76a..bc25c2e4ba 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pyx.pxi @@ -130,6 +130,8 @@ async def _receive_message(GrpcCallWrapper grpc_call_wrapper, # # Since they all indicates finish, they are better be merged. _LOGGER.debug('Failed to receive any message from Core') + # NOTE(lidiz) The returned message might be an empty bytes (aka. b''). + # Please explicitly check if it is None or falsey string object! return receive_op.message() diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/grpc_aio.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/grpc_aio.pyx.pxi index 06c92cac58..9aec95520f 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/grpc_aio.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/grpc_aio.pyx.pxi @@ -94,7 +94,7 @@ def _grpc_shutdown_wrapper(_): Define functions are not allowed in "cdef" functions, and Cython complains about a simple lambda with a C function. """ - grpc_shutdown_blocking() + grpc_shutdown() cdef _actual_aio_shutdown(): @@ -106,7 +106,7 @@ cdef _actual_aio_shutdown(): future.add_done_callback(_grpc_shutdown_wrapper) elif _global_aio_state.engine is AsyncIOEngine.POLLER: (<PollerCompletionQueue>_global_aio_state.cq).shutdown() - grpc_shutdown_blocking() + grpc_shutdown() else: raise ValueError('Unsupported engine type [%s]' % _global_aio_state.engine) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pxd.pxi index 46a47bd1ba..4651a6b6f2 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pxd.pxi @@ -67,6 +67,13 @@ cdef enum AioServerStatus: AIO_SERVER_STATUS_STOPPING +cdef class _ConcurrentRpcLimiter: + cdef int _maximum_concurrent_rpcs + cdef int _active_rpcs + cdef object _active_rpcs_condition # asyncio.Condition + cdef object _loop # asyncio.EventLoop + + cdef class AioServer: cdef Server _server cdef list _generic_handlers @@ -79,5 +86,6 @@ cdef class AioServer: cdef object _crash_exception # Exception cdef tuple _interceptors cdef object _thread_pool # concurrent.futures.ThreadPoolExecutor + cdef _ConcurrentRpcLimiter _limiter cdef thread_pool(self) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi index a630ed8811..38c0d71352 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi @@ -252,6 +252,12 @@ cdef class _ServicerContext: else: return {} + def time_remaining(self): + if self._rpc_state.details.deadline.seconds == _GPR_INF_FUTURE.seconds: + return None + else: + return max(_time_from_timespec(self._rpc_state.details.deadline) - time.time(), 0) + cdef class _SyncServicerContext: """Sync servicer context for sync handler compatibility.""" @@ -311,6 +317,9 @@ cdef class _SyncServicerContext: def auth_context(self): return self._context.auth_context() + def time_remaining(self): + return self._context.time_remaining() + async def _run_interceptor(object interceptors, object query_handler, object handler_call_details): @@ -781,6 +790,40 @@ cdef CallbackFailureHandler SERVER_SHUTDOWN_FAILURE_HANDLER = CallbackFailureHan InternalError) +cdef class _ConcurrentRpcLimiter: + + def __cinit__(self, int maximum_concurrent_rpcs, object loop): + if maximum_concurrent_rpcs <= 0: + raise ValueError("maximum_concurrent_rpcs should be a postive integer") + self._maximum_concurrent_rpcs = maximum_concurrent_rpcs + self._active_rpcs = 0 + self._active_rpcs_condition = asyncio.Condition() + self._loop = loop + + async def check_before_request_call(self): + await self._active_rpcs_condition.acquire() + try: + predicate = lambda: self._active_rpcs < self._maximum_concurrent_rpcs + await self._active_rpcs_condition.wait_for(predicate) + self._active_rpcs += 1 + finally: + self._active_rpcs_condition.release() + + async def _decrease_active_rpcs_count_with_lock(self): + await self._active_rpcs_condition.acquire() + try: + self._active_rpcs -= 1 + self._active_rpcs_condition.notify() + finally: + self._active_rpcs_condition.release() + + def _decrease_active_rpcs_count(self, unused_future): + self._loop.create_task(self._decrease_active_rpcs_count_with_lock()) + + def decrease_once_finished(self, object rpc_task): + rpc_task.add_done_callback(self._decrease_active_rpcs_count) + + cdef class AioServer: def __init__(self, loop, thread_pool, generic_handlers, interceptors, @@ -788,7 +831,8 @@ cdef class AioServer: init_grpc_aio() # NOTE(lidiz) Core objects won't be deallocated automatically. # If AioServer.shutdown is not called, those objects will leak. - self._server = Server(options) + # TODO(rbellevi): Support xDS in aio server. + self._server = Server(options, False) grpc_server_register_completion_queue( self._server.c_server, global_completion_queue(), @@ -815,9 +859,9 @@ cdef class AioServer: self._interceptors = () self._thread_pool = thread_pool - - if maximum_concurrent_rpcs: - raise NotImplementedError() + if maximum_concurrent_rpcs is not None: + self._limiter = _ConcurrentRpcLimiter(maximum_concurrent_rpcs, + loop) def add_generic_rpc_handlers(self, object generic_rpc_handlers): self._generic_handlers.extend(generic_rpc_handlers) @@ -860,6 +904,9 @@ cdef class AioServer: if self._status != AIO_SERVER_STATUS_RUNNING: break + if self._limiter is not None: + await self._limiter.check_before_request_call() + # Accepts new request from Core rpc_state = await self._request_call() @@ -874,7 +921,7 @@ cdef class AioServer: self._loop) # Fires off a task that listens on the cancellation from client. - self._loop.create_task( + rpc_task = self._loop.create_task( _schedule_rpc_coro( rpc_coro, rpc_state, @@ -882,8 +929,13 @@ cdef class AioServer: ) ) + if self._limiter is not None: + self._limiter.decrease_once_finished(rpc_task) + def _serving_task_crash_handler(self, object task): """Shutdown the server immediately if unexpectedly exited.""" + if task.cancelled(): + return if task.exception() is None: return if self._status != AIO_SERVER_STATUS_STOPPING: diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi index bdd155bea9..f68e166b17 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi @@ -86,7 +86,7 @@ cdef class Call: with nogil: if self.c_call != NULL: grpc_call_unref(self.c_call) - grpc_shutdown_blocking() + grpc_shutdown() # The object *should* always be valid from Python. Used for debugging. @property diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi index 74c7f6c140..ebffb7b0a2 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi @@ -425,7 +425,7 @@ cdef _close(Channel channel, grpc_status_code code, object details, _destroy_c_completion_queue(state.c_connectivity_completion_queue) grpc_channel_destroy(state.c_channel) state.c_channel = NULL - grpc_shutdown_blocking() + grpc_shutdown() state.condition.notify_all() else: # Another call to close already completed in the past or is currently diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi index a47403ac51..54c55f85f1 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi @@ -115,4 +115,4 @@ cdef class CompletionQueue: self.c_completion_queue, c_deadline, NULL) self._interpret_event(event) grpc_completion_queue_destroy(self.c_completion_queue) - grpc_shutdown_blocking() + grpc_shutdown() diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd.pxi index ddaedb30bd..827f6f17ca 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd.pxi @@ -76,6 +76,13 @@ cdef class CompositeChannelCredentials(ChannelCredentials): cdef grpc_channel_credentials *c(self) except * +cdef class XDSChannelCredentials(ChannelCredentials): + + cdef readonly ChannelCredentials _fallback_credentials + + cdef grpc_channel_credentials *c(self) except * + + cdef class ServerCertificateConfig: cdef grpc_ssl_server_certificate_config *c_cert_config diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi index c75579cc04..e7e59261b4 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi @@ -58,7 +58,7 @@ cdef int _get_metadata(void *state, cdef void _destroy(void *state) except * with gil: cpython.Py_DECREF(<object>state) - grpc_shutdown_blocking() + grpc_shutdown() cdef class MetadataPluginCallCredentials(CallCredentials): @@ -124,7 +124,7 @@ cdef class SSLSessionCacheLRU: def __dealloc__(self): if self._cache != NULL: grpc_ssl_session_cache_destroy(self._cache) - grpc_shutdown_blocking() + grpc_shutdown() cdef class SSLChannelCredentials(ChannelCredentials): @@ -178,6 +178,18 @@ cdef class CompositeChannelCredentials(ChannelCredentials): return c_composition +cdef class XDSChannelCredentials(ChannelCredentials): + + def __cinit__(self, fallback_credentials): + self._fallback_credentials = fallback_credentials + + cdef grpc_channel_credentials *c(self) except *: + cdef grpc_channel_credentials *c_fallback_creds = self._fallback_credentials.c() + cdef grpc_channel_credentials *xds_creds = grpc_xds_credentials_create(c_fallback_creds) + grpc_channel_credentials_release(c_fallback_creds) + return xds_creds + + cdef class ServerCertificateConfig: def __cinit__(self): @@ -190,7 +202,7 @@ cdef class ServerCertificateConfig: def __dealloc__(self): grpc_ssl_server_certificate_config_destroy(self.c_cert_config) gpr_free(self.c_ssl_pem_key_cert_pairs) - grpc_shutdown_blocking() + grpc_shutdown() cdef class ServerCredentials: @@ -206,7 +218,7 @@ cdef class ServerCredentials: def __dealloc__(self): if self.c_credentials != NULL: grpc_server_credentials_release(self.c_credentials) - grpc_shutdown_blocking() + grpc_shutdown() cdef const char* _get_c_pem_root_certs(pem_root_certs): if pem_root_certs is None: @@ -347,11 +359,31 @@ cdef class LocalChannelCredentials(ChannelCredentials): def channel_credentials_local(grpc_local_connect_type local_connect_type): return LocalChannelCredentials(local_connect_type) +cdef class InsecureChannelCredentials(ChannelCredentials): + + cdef grpc_channel_credentials *c(self) except *: + return grpc_insecure_credentials_create() + +def channel_credentials_insecure(): + return InsecureChannelCredentials() + def server_credentials_local(grpc_local_connect_type local_connect_type): cdef ServerCredentials credentials = ServerCredentials() credentials.c_credentials = grpc_local_server_credentials_create(local_connect_type) return credentials +def xds_server_credentials(ServerCredentials fallback_credentials): + cdef ServerCredentials credentials = ServerCredentials() + credentials.c_credentials = grpc_xds_server_credentials_create(fallback_credentials.c_credentials) + # NOTE: We do not need to call grpc_server_credentials_release on the + # fallback credentials here because this will be done by the __dealloc__ + # method of its Cython wrapper. + return credentials + +def insecure_server_credentials(): + cdef ServerCredentials credentials = ServerCredentials() + credentials.c_credentials = grpc_insecure_server_credentials_create() + return credentials cdef class ALTSChannelCredentials(ChannelCredentials): diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi index 54eb7fdffc..0b7c49a037 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi @@ -335,6 +335,7 @@ cdef extern from "grpc/grpc.h": void grpc_dont_init_openssl() nogil void grpc_init() nogil + void grpc_shutdown() nogil void grpc_shutdown_blocking() nogil int grpc_is_initialized() nogil @@ -397,6 +398,23 @@ cdef extern from "grpc/grpc.h": void grpc_server_register_completion_queue(grpc_server *server, grpc_completion_queue *cq, void *reserved) nogil + + ctypedef struct grpc_server_config_fetcher: + pass + + void grpc_server_set_config_fetcher( + grpc_server* server, grpc_server_config_fetcher* config_fetcher) nogil + + ctypedef struct grpc_server_xds_status_notifier: + void (*on_serving_status_change)(void* user_data, const char* uri, + grpc_status_code code, + const char* error_message) + void* user_data; + + grpc_server_config_fetcher* grpc_server_config_fetcher_xds_create( + grpc_server_xds_status_notifier notifier) nogil + + int grpc_server_add_insecure_http2_port( grpc_server *server, const char *addr) nogil void grpc_server_start(grpc_server *server) nogil @@ -514,6 +532,16 @@ cdef extern from "grpc/grpc_security.h": void *reserved) nogil void grpc_channel_credentials_release(grpc_channel_credentials *creds) nogil + grpc_channel_credentials *grpc_xds_credentials_create( + grpc_channel_credentials *fallback_creds) nogil + + grpc_channel_credentials *grpc_insecure_credentials_create() nogil + + grpc_server_credentials *grpc_xds_server_credentials_create( + grpc_server_credentials *fallback_creds) nogil + + grpc_server_credentials *grpc_insecure_server_credentials_create() nogil + grpc_call_credentials *grpc_composite_call_credentials_create( grpc_call_credentials *creds1, grpc_call_credentials *creds2, void *reserved) nogil diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi index 0f693ec691..d857317ead 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi @@ -39,7 +39,7 @@ cdef class SocketWrapper: self.len = 0 def __dealloc__(self): - grpc_shutdown_blocking() + grpc_shutdown() cdef grpc_error* socket_init(grpc_custom_socket* socket, int domain) with gil: sw = SocketWrapper() @@ -267,7 +267,7 @@ cdef class ResolveWrapper: self.c_port = NULL def __dealloc__(self): - grpc_shutdown_blocking() + grpc_shutdown() cdef socket_resolve_async_cython(ResolveWrapper resolve_wrapper): try: @@ -323,7 +323,7 @@ cdef class TimerWrapper: self.timer.stop() def __dealloc__(self): - grpc_shutdown_blocking() + grpc_shutdown() cdef void timer_start(grpc_custom_timer* t) with gil: timer = TimerWrapper(t.timeout_ms / 1000.0) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi index 308d677695..05db7e3df9 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi @@ -137,7 +137,7 @@ cdef class CallDetails: def __dealloc__(self): with nogil: grpc_call_details_destroy(&self.c_details) - grpc_shutdown_blocking() + grpc_shutdown() @property def method(self): diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi index eff95c4f29..ed1dda292d 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi @@ -15,7 +15,7 @@ cdef class Server: - def __cinit__(self, object arguments): + def __cinit__(self, object arguments, bint xds): fork_handlers_and_grpc_init() self.references = [] self.registered_completion_queues = [] @@ -25,6 +25,12 @@ cdef class Server: self.c_server = NULL cdef _ChannelArgs channel_args = _ChannelArgs(arguments) self.c_server = grpc_server_create(channel_args.c_args(), NULL) + cdef grpc_server_xds_status_notifier notifier + notifier.on_serving_status_change = NULL + notifier.user_data = NULL + if xds: + grpc_server_set_config_fetcher(self.c_server, + grpc_server_config_fetcher_xds_create(notifier)) self.references.append(arguments) def request_call( @@ -154,4 +160,4 @@ cdef class Server: def __dealloc__(self): if self.c_server == NULL: - grpc_shutdown_blocking() + grpc_shutdown() diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_grpcio_metadata.py b/contrib/libs/grpc/src/python/grpcio/grpc/_grpcio_metadata.py index f5d0668407..d182b9b768 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_grpcio_metadata.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_grpcio_metadata.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio/grpc/_grpcio_metadata.py.template`!!! -__version__ = """1.33.2""" +__version__ = """1.37.1""" diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_runtime_protos.py b/contrib/libs/grpc/src/python/grpcio/grpc/_runtime_protos.py index 7f555ccd9e..2a3e1d459a 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_runtime_protos.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_runtime_protos.py @@ -15,41 +15,49 @@ import sys _REQUIRED_SYMBOLS = ("_protos", "_services", "_protos_and_services") +_MINIMUM_VERSION = (3, 5, 0) +_UNINSTALLED_TEMPLATE = "Install the grpcio-tools package (1.32.0+) to use the {} function." +_VERSION_ERROR_TEMPLATE = "The {} function is only on available on Python 3.X interpreters." -def _uninstalled_protos(*args, **kwargs): - raise NotImplementedError( - "Install the grpcio-tools package (1.32.0+) to use the protos function." - ) +def _has_runtime_proto_symbols(mod): + return all(hasattr(mod, sym) for sym in _REQUIRED_SYMBOLS) -def _uninstalled_services(*args, **kwargs): - raise NotImplementedError( - "Install the grpcio-tools package (1.32.0+) to use the services function." - ) - -def _uninstalled_protos_and_services(*args, **kwargs): - raise NotImplementedError( - "Install the grpcio-tools package (1.32.0+) to use the protos_and_services function." - ) - - -def _interpreter_version_protos(*args, **kwargs): - raise NotImplementedError( - "The protos function is only on available on Python 3.X interpreters.") +def _is_grpc_tools_importable(): + try: + import grpc_tools # pylint: disable=unused-import + return True + except ImportError as e: + # NOTE: It's possible that we're encountering a transitive ImportError, so + # we check for that and re-raise if so. + if "grpc_tools" not in e.args[0]: + raise + return False -def _interpreter_version_services(*args, **kwargs): - raise NotImplementedError( - "The services function is only on available on Python 3.X interpreters." - ) +def _call_with_lazy_import(fn_name, protobuf_path): + """Calls one of the three functions, lazily importing grpc_tools. + Args: + fn_name: The name of the function to import from grpc_tools.protoc. + protobuf_path: The path to import. -def _interpreter_version_protos_and_services(*args, **kwargs): - raise NotImplementedError( - "The protos_and_services function is only on available on Python 3.X interpreters." - ) + Returns: + The appropriate module object. + """ + if sys.version_info < _MINIMUM_VERSION: + raise NotImplementedError(_VERSION_ERROR_TEMPLATE.format(fn_name)) + else: + if not _is_grpc_tools_importable(): + raise NotImplementedError(_UNINSTALLED_TEMPLATE.format(fn_name)) + import grpc_tools.protoc + if _has_runtime_proto_symbols(grpc_tools.protoc): + fn = getattr(grpc_tools.protoc, '_' + fn_name) + return fn(protobuf_path) + else: + raise NotImplementedError(_UNINSTALLED_TEMPLATE.format(fn_name)) def protos(protobuf_path): # pylint: disable=unused-argument @@ -85,6 +93,7 @@ def protos(protobuf_path): # pylint: disable=unused-argument A module object corresponding to the message code for the indicated .proto file. Equivalent to a generated _pb2.py file. """ + return _call_with_lazy_import("protos", protobuf_path) def services(protobuf_path): # pylint: disable=unused-argument @@ -121,6 +130,7 @@ def services(protobuf_path): # pylint: disable=unused-argument A module object corresponding to the stub/service code for the indicated .proto file. Equivalent to a generated _pb2_grpc.py file. """ + return _call_with_lazy_import("services", protobuf_path) def protos_and_services(protobuf_path): # pylint: disable=unused-argument @@ -142,30 +152,4 @@ def protos_and_services(protobuf_path): # pylint: disable=unused-argument Returns: A 2-tuple of module objects corresponding to (protos(path), services(path)). """ - - -if sys.version_info < (3, 5, 0): - protos = _interpreter_version_protos - services = _interpreter_version_services - protos_and_services = _interpreter_version_protos_and_services -else: - try: - import grpc_tools # pylint: disable=unused-import - except ImportError as e: - # NOTE: It's possible that we're encountering a transitive ImportError, so - # we check for that and re-raise if so. - if "grpc_tools" not in e.args[0]: - raise - protos = _uninstalled_protos - services = _uninstalled_services - protos_and_services = _uninstalled_protos_and_services - else: - import grpc_tools.protoc # pylint: disable=unused-import - if all(hasattr(grpc_tools.protoc, sym) for sym in _REQUIRED_SYMBOLS): - from grpc_tools.protoc import _protos as protos # pylint: disable=unused-import - from grpc_tools.protoc import _services as services # pylint: disable=unused-import - from grpc_tools.protoc import _protos_and_services as protos_and_services # pylint: disable=unused-import - else: - protos = _uninstalled_protos - services = _uninstalled_services - protos_and_services = _uninstalled_protos_and_services + return _call_with_lazy_import("protos_and_services", protobuf_path) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_server.py b/contrib/libs/grpc/src/python/grpcio/grpc/_server.py index 48ff743995..069ffa7982 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_server.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_server.py @@ -945,9 +945,9 @@ class _Server(grpc.Server): # pylint: disable=too-many-arguments def __init__(self, thread_pool, generic_handlers, interceptors, options, - maximum_concurrent_rpcs, compression): + maximum_concurrent_rpcs, compression, xds): completion_queue = cygrpc.CompletionQueue() - server = cygrpc.Server(_augment_options(options, compression)) + server = cygrpc.Server(_augment_options(options, compression), xds) server.register_completion_queue(completion_queue) self._state = _ServerState(completion_queue, server, generic_handlers, _interceptor.service_pipeline(interceptors), @@ -989,7 +989,7 @@ class _Server(grpc.Server): def create_server(thread_pool, generic_rpc_handlers, interceptors, options, - maximum_concurrent_rpcs, compression): + maximum_concurrent_rpcs, compression, xds): _validate_generic_rpc_handlers(generic_rpc_handlers) return _Server(thread_pool, generic_rpc_handlers, interceptors, options, - maximum_concurrent_rpcs, compression) + maximum_concurrent_rpcs, compression, xds) diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/_simple_stubs.py b/contrib/libs/grpc/src/python/grpcio/grpc/_simple_stubs.py index baa7ae5dbe..3dd44c705e 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/_simple_stubs.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/_simple_stubs.py @@ -28,8 +28,8 @@ RequestType = TypeVar('RequestType') ResponseType = TypeVar('ResponseType') OptionsType = Sequence[Tuple[str, str]] -CacheKey = Tuple[str, OptionsType, Optional[grpc.ChannelCredentials], Optional[ - grpc.Compression]] +CacheKey = Tuple[str, OptionsType, Optional[grpc.ChannelCredentials], + Optional[grpc.Compression]] _LOGGER = logging.getLogger(__name__) @@ -60,20 +60,13 @@ else: def _create_channel(target: str, options: Sequence[Tuple[str, str]], channel_credentials: Optional[grpc.ChannelCredentials], compression: Optional[grpc.Compression]) -> grpc.Channel: - if channel_credentials is grpc.experimental.insecure_channel_credentials(): - _LOGGER.debug(f"Creating insecure channel with options '{options}' " + - f"and compression '{compression}'") - return grpc.insecure_channel(target, - options=options, - compression=compression) - else: - _LOGGER.debug( - f"Creating secure channel with credentials '{channel_credentials}', " - + f"options '{options}' and compression '{compression}'") - return grpc.secure_channel(target, - credentials=channel_credentials, - options=options, - compression=compression) + _LOGGER.debug( + f"Creating secure channel with credentials '{channel_credentials}', " + + f"options '{options}' and compression '{compression}'") + return grpc.secure_channel(target, + credentials=channel_credentials, + options=options, + compression=compression) class ChannelCache: @@ -174,19 +167,19 @@ class ChannelCache: @experimental_api def unary_unary( - request: RequestType, - target: str, - method: str, - request_serializer: Optional[Callable[[Any], bytes]] = None, - response_deserializer: Optional[Callable[[bytes], Any]] = None, - options: Sequence[Tuple[AnyStr, AnyStr]] = (), - channel_credentials: Optional[grpc.ChannelCredentials] = None, - insecure: bool = False, - call_credentials: Optional[grpc.CallCredentials] = None, - compression: Optional[grpc.Compression] = None, - wait_for_ready: Optional[bool] = None, - timeout: Optional[float] = _DEFAULT_TIMEOUT, - metadata: Optional[Sequence[Tuple[str, Union[str, bytes]]]] = None + request: RequestType, + target: str, + method: str, + request_serializer: Optional[Callable[[Any], bytes]] = None, + response_deserializer: Optional[Callable[[bytes], Any]] = None, + options: Sequence[Tuple[AnyStr, AnyStr]] = (), + channel_credentials: Optional[grpc.ChannelCredentials] = None, + insecure: bool = False, + call_credentials: Optional[grpc.CallCredentials] = None, + compression: Optional[grpc.Compression] = None, + wait_for_ready: Optional[bool] = None, + timeout: Optional[float] = _DEFAULT_TIMEOUT, + metadata: Optional[Sequence[Tuple[str, Union[str, bytes]]]] = None ) -> ResponseType: """Invokes a unary-unary RPC without an explicitly specified channel. @@ -255,19 +248,19 @@ def unary_unary( @experimental_api def unary_stream( - request: RequestType, - target: str, - method: str, - request_serializer: Optional[Callable[[Any], bytes]] = None, - response_deserializer: Optional[Callable[[bytes], Any]] = None, - options: Sequence[Tuple[AnyStr, AnyStr]] = (), - channel_credentials: Optional[grpc.ChannelCredentials] = None, - insecure: bool = False, - call_credentials: Optional[grpc.CallCredentials] = None, - compression: Optional[grpc.Compression] = None, - wait_for_ready: Optional[bool] = None, - timeout: Optional[float] = _DEFAULT_TIMEOUT, - metadata: Optional[Sequence[Tuple[str, Union[str, bytes]]]] = None + request: RequestType, + target: str, + method: str, + request_serializer: Optional[Callable[[Any], bytes]] = None, + response_deserializer: Optional[Callable[[bytes], Any]] = None, + options: Sequence[Tuple[AnyStr, AnyStr]] = (), + channel_credentials: Optional[grpc.ChannelCredentials] = None, + insecure: bool = False, + call_credentials: Optional[grpc.CallCredentials] = None, + compression: Optional[grpc.Compression] = None, + wait_for_ready: Optional[bool] = None, + timeout: Optional[float] = _DEFAULT_TIMEOUT, + metadata: Optional[Sequence[Tuple[str, Union[str, bytes]]]] = None ) -> Iterator[ResponseType]: """Invokes a unary-stream RPC without an explicitly specified channel. @@ -335,19 +328,19 @@ def unary_stream( @experimental_api def stream_unary( - request_iterator: Iterator[RequestType], - target: str, - method: str, - request_serializer: Optional[Callable[[Any], bytes]] = None, - response_deserializer: Optional[Callable[[bytes], Any]] = None, - options: Sequence[Tuple[AnyStr, AnyStr]] = (), - channel_credentials: Optional[grpc.ChannelCredentials] = None, - insecure: bool = False, - call_credentials: Optional[grpc.CallCredentials] = None, - compression: Optional[grpc.Compression] = None, - wait_for_ready: Optional[bool] = None, - timeout: Optional[float] = _DEFAULT_TIMEOUT, - metadata: Optional[Sequence[Tuple[str, Union[str, bytes]]]] = None + request_iterator: Iterator[RequestType], + target: str, + method: str, + request_serializer: Optional[Callable[[Any], bytes]] = None, + response_deserializer: Optional[Callable[[bytes], Any]] = None, + options: Sequence[Tuple[AnyStr, AnyStr]] = (), + channel_credentials: Optional[grpc.ChannelCredentials] = None, + insecure: bool = False, + call_credentials: Optional[grpc.CallCredentials] = None, + compression: Optional[grpc.Compression] = None, + wait_for_ready: Optional[bool] = None, + timeout: Optional[float] = _DEFAULT_TIMEOUT, + metadata: Optional[Sequence[Tuple[str, Union[str, bytes]]]] = None ) -> ResponseType: """Invokes a stream-unary RPC without an explicitly specified channel. @@ -415,19 +408,19 @@ def stream_unary( @experimental_api def stream_stream( - request_iterator: Iterator[RequestType], - target: str, - method: str, - request_serializer: Optional[Callable[[Any], bytes]] = None, - response_deserializer: Optional[Callable[[bytes], Any]] = None, - options: Sequence[Tuple[AnyStr, AnyStr]] = (), - channel_credentials: Optional[grpc.ChannelCredentials] = None, - insecure: bool = False, - call_credentials: Optional[grpc.CallCredentials] = None, - compression: Optional[grpc.Compression] = None, - wait_for_ready: Optional[bool] = None, - timeout: Optional[float] = _DEFAULT_TIMEOUT, - metadata: Optional[Sequence[Tuple[str, Union[str, bytes]]]] = None + request_iterator: Iterator[RequestType], + target: str, + method: str, + request_serializer: Optional[Callable[[Any], bytes]] = None, + response_deserializer: Optional[Callable[[bytes], Any]] = None, + options: Sequence[Tuple[AnyStr, AnyStr]] = (), + channel_credentials: Optional[grpc.ChannelCredentials] = None, + insecure: bool = False, + call_credentials: Optional[grpc.CallCredentials] = None, + compression: Optional[grpc.Compression] = None, + wait_for_ready: Optional[bool] = None, + timeout: Optional[float] = _DEFAULT_TIMEOUT, + metadata: Optional[Sequence[Tuple[str, Union[str, bytes]]]] = None ) -> Iterator[ResponseType]: """Invokes a stream-stream RPC without an explicitly specified channel. diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/aio/_base_channel.py b/contrib/libs/grpc/src/python/grpcio/grpc/aio/_base_channel.py index 4b4ea1355b..b9a47efb41 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/aio/_base_channel.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/aio/_base_channel.py @@ -28,15 +28,16 @@ class UnaryUnaryMultiCallable(abc.ABC): """Enables asynchronous invocation of a unary-call RPC.""" @abc.abstractmethod - def __call__(self, - request: Any, - *, - timeout: Optional[float] = None, - metadata: Optional[Metadata] = None, - credentials: Optional[grpc.CallCredentials] = None, - wait_for_ready: Optional[bool] = None, - compression: Optional[grpc.Compression] = None - ) -> _base_call.UnaryUnaryCall: + def __call__( + self, + request: Any, + *, + timeout: Optional[float] = None, + metadata: Optional[Metadata] = None, + credentials: Optional[grpc.CallCredentials] = None, + wait_for_ready: Optional[bool] = None, + compression: Optional[grpc.Compression] = None + ) -> _base_call.UnaryUnaryCall: """Asynchronously invokes the underlying RPC. Args: @@ -66,15 +67,16 @@ class UnaryStreamMultiCallable(abc.ABC): """Enables asynchronous invocation of a server-streaming RPC.""" @abc.abstractmethod - def __call__(self, - request: Any, - *, - timeout: Optional[float] = None, - metadata: Optional[Metadata] = None, - credentials: Optional[grpc.CallCredentials] = None, - wait_for_ready: Optional[bool] = None, - compression: Optional[grpc.Compression] = None - ) -> _base_call.UnaryStreamCall: + def __call__( + self, + request: Any, + *, + timeout: Optional[float] = None, + metadata: Optional[Metadata] = None, + credentials: Optional[grpc.CallCredentials] = None, + wait_for_ready: Optional[bool] = None, + compression: Optional[grpc.Compression] = None + ) -> _base_call.UnaryStreamCall: """Asynchronously invokes the underlying RPC. Args: @@ -104,14 +106,15 @@ class StreamUnaryMultiCallable(abc.ABC): """Enables asynchronous invocation of a client-streaming RPC.""" @abc.abstractmethod - def __call__(self, - request_iterator: Optional[RequestIterableType] = None, - timeout: Optional[float] = None, - metadata: Optional[Metadata] = None, - credentials: Optional[grpc.CallCredentials] = None, - wait_for_ready: Optional[bool] = None, - compression: Optional[grpc.Compression] = None - ) -> _base_call.StreamUnaryCall: + def __call__( + self, + request_iterator: Optional[RequestIterableType] = None, + timeout: Optional[float] = None, + metadata: Optional[Metadata] = None, + credentials: Optional[grpc.CallCredentials] = None, + wait_for_ready: Optional[bool] = None, + compression: Optional[grpc.Compression] = None + ) -> _base_call.StreamUnaryCall: """Asynchronously invokes the underlying RPC. Args: @@ -142,14 +145,15 @@ class StreamStreamMultiCallable(abc.ABC): """Enables asynchronous invocation of a bidirectional-streaming RPC.""" @abc.abstractmethod - def __call__(self, - request_iterator: Optional[RequestIterableType] = None, - timeout: Optional[float] = None, - metadata: Optional[Metadata] = None, - credentials: Optional[grpc.CallCredentials] = None, - wait_for_ready: Optional[bool] = None, - compression: Optional[grpc.Compression] = None - ) -> _base_call.StreamStreamCall: + def __call__( + self, + request_iterator: Optional[RequestIterableType] = None, + timeout: Optional[float] = None, + metadata: Optional[Metadata] = None, + credentials: Optional[grpc.CallCredentials] = None, + wait_for_ready: Optional[bool] = None, + compression: Optional[grpc.Compression] = None + ) -> _base_call.StreamStreamCall: """Asynchronously invokes the underlying RPC. Args: @@ -234,8 +238,8 @@ class Channel(abc.ABC): @abc.abstractmethod async def wait_for_state_change( - self, - last_observed_state: grpc.ChannelConnectivity, + self, + last_observed_state: grpc.ChannelConnectivity, ) -> None: """Waits for a change in connectivity state. @@ -264,10 +268,10 @@ class Channel(abc.ABC): @abc.abstractmethod def unary_unary( - self, - method: str, - request_serializer: Optional[SerializingFunction] = None, - response_deserializer: Optional[DeserializingFunction] = None + self, + method: str, + request_serializer: Optional[SerializingFunction] = None, + response_deserializer: Optional[DeserializingFunction] = None ) -> UnaryUnaryMultiCallable: """Creates a UnaryUnaryMultiCallable for a unary-unary method. @@ -285,10 +289,10 @@ class Channel(abc.ABC): @abc.abstractmethod def unary_stream( - self, - method: str, - request_serializer: Optional[SerializingFunction] = None, - response_deserializer: Optional[DeserializingFunction] = None + self, + method: str, + request_serializer: Optional[SerializingFunction] = None, + response_deserializer: Optional[DeserializingFunction] = None ) -> UnaryStreamMultiCallable: """Creates a UnaryStreamMultiCallable for a unary-stream method. @@ -306,10 +310,10 @@ class Channel(abc.ABC): @abc.abstractmethod def stream_unary( - self, - method: str, - request_serializer: Optional[SerializingFunction] = None, - response_deserializer: Optional[DeserializingFunction] = None + self, + method: str, + request_serializer: Optional[SerializingFunction] = None, + response_deserializer: Optional[DeserializingFunction] = None ) -> StreamUnaryMultiCallable: """Creates a StreamUnaryMultiCallable for a stream-unary method. @@ -327,10 +331,10 @@ class Channel(abc.ABC): @abc.abstractmethod def stream_stream( - self, - method: str, - request_serializer: Optional[SerializingFunction] = None, - response_deserializer: Optional[DeserializingFunction] = None + self, + method: str, + request_serializer: Optional[SerializingFunction] = None, + response_deserializer: Optional[DeserializingFunction] = None ) -> StreamStreamMultiCallable: """Creates a StreamStreamMultiCallable for a stream-stream method. diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/aio/_base_server.py b/contrib/libs/grpc/src/python/grpcio/grpc/aio/_base_server.py index 926c865171..7cbedf9b60 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/aio/_base_server.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/aio/_base_server.py @@ -169,8 +169,11 @@ class ServicerContext(Generic[RequestType, ResponseType], abc.ABC): """ @abc.abstractmethod - async def abort(self, code: grpc.StatusCode, details: str, - trailing_metadata: Metadata) -> None: + async def abort( + self, + code: grpc.StatusCode, + details: str = '', + trailing_metadata: Metadata = tuple()) -> None: """Raises an exception to terminate the RPC with a non-OK status. The code and details passed as arguments will supercede any existing @@ -292,3 +295,12 @@ class ServicerContext(Generic[RequestType, ResponseType], abc.ABC): Returns: A map of strings to an iterable of bytes for each auth property. """ + + def time_remaining(self) -> float: + """Describes the length of allowed time remaining for the RPC. + + Returns: + A nonnegative float indicating the length of allowed time in seconds + remaining for the RPC to complete before it is considered to have + timed out, or None if no deadline was specified for the RPC. + """ diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/aio/_call.py b/contrib/libs/grpc/src/python/grpcio/grpc/aio/_call.py index ba229f35c3..def89b4df0 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/aio/_call.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/aio/_call.py @@ -393,9 +393,8 @@ class _StreamRequestMixin(Call): def _metadata_sent_observer(self): self._metadata_sent.set() - async def _consume_request_iterator(self, - request_iterator: RequestIterableType - ) -> None: + async def _consume_request_iterator( + self, request_iterator: RequestIterableType) -> None: try: if inspect.isasyncgen(request_iterator) or hasattr( request_iterator, '__aiter__'): diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/aio/_channel.py b/contrib/libs/grpc/src/python/grpcio/grpc/aio/_channel.py index 3af3467706..99f256e0b9 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/aio/_channel.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/aio/_channel.py @@ -73,13 +73,13 @@ class _BaseMultiCallable: # pylint: disable=too-many-arguments def __init__( - self, - channel: cygrpc.AioChannel, - method: bytes, - request_serializer: SerializingFunction, - response_deserializer: DeserializingFunction, - interceptors: Optional[Sequence[ClientInterceptor]], - loop: asyncio.AbstractEventLoop, + self, + channel: cygrpc.AioChannel, + method: bytes, + request_serializer: SerializingFunction, + response_deserializer: DeserializingFunction, + interceptors: Optional[Sequence[ClientInterceptor]], + loop: asyncio.AbstractEventLoop, ) -> None: self._loop = loop self._channel = channel @@ -89,9 +89,9 @@ class _BaseMultiCallable: self._interceptors = interceptors @staticmethod - def _init_metadata(metadata: Optional[Metadata] = None, - compression: Optional[grpc.Compression] = None - ) -> Metadata: + def _init_metadata( + metadata: Optional[Metadata] = None, + compression: Optional[grpc.Compression] = None) -> Metadata: """Based on the provided values for <metadata> or <compression> initialise the final metadata, as it should be used for the current call. """ @@ -105,15 +105,16 @@ class _BaseMultiCallable: class UnaryUnaryMultiCallable(_BaseMultiCallable, _base_channel.UnaryUnaryMultiCallable): - def __call__(self, - request: Any, - *, - timeout: Optional[float] = None, - metadata: Optional[Metadata] = None, - credentials: Optional[grpc.CallCredentials] = None, - wait_for_ready: Optional[bool] = None, - compression: Optional[grpc.Compression] = None - ) -> _base_call.UnaryUnaryCall: + def __call__( + self, + request: Any, + *, + timeout: Optional[float] = None, + metadata: Optional[Metadata] = None, + credentials: Optional[grpc.CallCredentials] = None, + wait_for_ready: Optional[bool] = None, + compression: Optional[grpc.Compression] = None + ) -> _base_call.UnaryUnaryCall: metadata = self._init_metadata(metadata, compression) if not self._interceptors: @@ -135,15 +136,16 @@ class UnaryUnaryMultiCallable(_BaseMultiCallable, class UnaryStreamMultiCallable(_BaseMultiCallable, _base_channel.UnaryStreamMultiCallable): - def __call__(self, - request: Any, - *, - timeout: Optional[float] = None, - metadata: Optional[Metadata] = None, - credentials: Optional[grpc.CallCredentials] = None, - wait_for_ready: Optional[bool] = None, - compression: Optional[grpc.Compression] = None - ) -> _base_call.UnaryStreamCall: + def __call__( + self, + request: Any, + *, + timeout: Optional[float] = None, + metadata: Optional[Metadata] = None, + credentials: Optional[grpc.CallCredentials] = None, + wait_for_ready: Optional[bool] = None, + compression: Optional[grpc.Compression] = None + ) -> _base_call.UnaryStreamCall: metadata = self._init_metadata(metadata, compression) deadline = _timeout_to_deadline(timeout) @@ -166,14 +168,15 @@ class UnaryStreamMultiCallable(_BaseMultiCallable, class StreamUnaryMultiCallable(_BaseMultiCallable, _base_channel.StreamUnaryMultiCallable): - def __call__(self, - request_iterator: Optional[RequestIterableType] = None, - timeout: Optional[float] = None, - metadata: Optional[Metadata] = None, - credentials: Optional[grpc.CallCredentials] = None, - wait_for_ready: Optional[bool] = None, - compression: Optional[grpc.Compression] = None - ) -> _base_call.StreamUnaryCall: + def __call__( + self, + request_iterator: Optional[RequestIterableType] = None, + timeout: Optional[float] = None, + metadata: Optional[Metadata] = None, + credentials: Optional[grpc.CallCredentials] = None, + wait_for_ready: Optional[bool] = None, + compression: Optional[grpc.Compression] = None + ) -> _base_call.StreamUnaryCall: metadata = self._init_metadata(metadata, compression) deadline = _timeout_to_deadline(timeout) @@ -196,14 +199,15 @@ class StreamUnaryMultiCallable(_BaseMultiCallable, class StreamStreamMultiCallable(_BaseMultiCallable, _base_channel.StreamStreamMultiCallable): - def __call__(self, - request_iterator: Optional[RequestIterableType] = None, - timeout: Optional[float] = None, - metadata: Optional[Metadata] = None, - credentials: Optional[grpc.CallCredentials] = None, - wait_for_ready: Optional[bool] = None, - compression: Optional[grpc.Compression] = None - ) -> _base_call.StreamStreamCall: + def __call__( + self, + request_iterator: Optional[RequestIterableType] = None, + timeout: Optional[float] = None, + metadata: Optional[Metadata] = None, + credentials: Optional[grpc.CallCredentials] = None, + wait_for_ready: Optional[bool] = None, + compression: Optional[grpc.Compression] = None + ) -> _base_call.StreamStreamCall: metadata = self._init_metadata(metadata, compression) deadline = _timeout_to_deadline(timeout) @@ -361,8 +365,8 @@ class Channel(_base_channel.Channel): return _common.CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY[result] async def wait_for_state_change( - self, - last_observed_state: grpc.ChannelConnectivity, + self, + last_observed_state: grpc.ChannelConnectivity, ) -> None: assert await self._channel.watch_connectivity_state( last_observed_state.value[0], None) @@ -374,10 +378,10 @@ class Channel(_base_channel.Channel): state = self.get_state(try_to_connect=True) def unary_unary( - self, - method: str, - request_serializer: Optional[SerializingFunction] = None, - response_deserializer: Optional[DeserializingFunction] = None + self, + method: str, + request_serializer: Optional[SerializingFunction] = None, + response_deserializer: Optional[DeserializingFunction] = None ) -> UnaryUnaryMultiCallable: return UnaryUnaryMultiCallable(self._channel, _common.encode(method), request_serializer, @@ -386,10 +390,10 @@ class Channel(_base_channel.Channel): self._loop) def unary_stream( - self, - method: str, - request_serializer: Optional[SerializingFunction] = None, - response_deserializer: Optional[DeserializingFunction] = None + self, + method: str, + request_serializer: Optional[SerializingFunction] = None, + response_deserializer: Optional[DeserializingFunction] = None ) -> UnaryStreamMultiCallable: return UnaryStreamMultiCallable(self._channel, _common.encode(method), request_serializer, @@ -398,10 +402,10 @@ class Channel(_base_channel.Channel): self._loop) def stream_unary( - self, - method: str, - request_serializer: Optional[SerializingFunction] = None, - response_deserializer: Optional[DeserializingFunction] = None + self, + method: str, + request_serializer: Optional[SerializingFunction] = None, + response_deserializer: Optional[DeserializingFunction] = None ) -> StreamUnaryMultiCallable: return StreamUnaryMultiCallable(self._channel, _common.encode(method), request_serializer, @@ -410,10 +414,10 @@ class Channel(_base_channel.Channel): self._loop) def stream_stream( - self, - method: str, - request_serializer: Optional[SerializingFunction] = None, - response_deserializer: Optional[DeserializingFunction] = None + self, + method: str, + request_serializer: Optional[SerializingFunction] = None, + response_deserializer: Optional[DeserializingFunction] = None ) -> StreamStreamMultiCallable: return StreamStreamMultiCallable(self._channel, _common.encode(method), request_serializer, diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/aio/_interceptor.py b/contrib/libs/grpc/src/python/grpcio/grpc/aio/_interceptor.py index 80e9625c55..f62685c127 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/aio/_interceptor.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/aio/_interceptor.py @@ -42,8 +42,8 @@ class ServerInterceptor(metaclass=ABCMeta): @abstractmethod async def intercept_service( - self, continuation: Callable[[grpc.HandlerCallDetails], Awaitable[ - grpc.RpcMethodHandler]], + self, continuation: Callable[[grpc.HandlerCallDetails], + Awaitable[grpc.RpcMethodHandler]], handler_call_details: grpc.HandlerCallDetails ) -> grpc.RpcMethodHandler: """Intercepts incoming RPCs before handing them over to a handler. @@ -167,11 +167,11 @@ class StreamUnaryClientInterceptor(ClientInterceptor, metaclass=ABCMeta): @abstractmethod async def intercept_stream_unary( - self, - continuation: Callable[[ClientCallDetails, RequestType], - UnaryStreamCall], - client_call_details: ClientCallDetails, - request_iterator: RequestIterableType, + self, + continuation: Callable[[ClientCallDetails, RequestType], + UnaryStreamCall], + client_call_details: ClientCallDetails, + request_iterator: RequestIterableType, ) -> StreamUnaryCall: """Intercepts a stream-unary invocation asynchronously. @@ -208,11 +208,11 @@ class StreamStreamClientInterceptor(ClientInterceptor, metaclass=ABCMeta): @abstractmethod async def intercept_stream_stream( - self, - continuation: Callable[[ClientCallDetails, RequestType], - UnaryStreamCall], - client_call_details: ClientCallDetails, - request_iterator: RequestIterableType, + self, + continuation: Callable[[ClientCallDetails, RequestType], + UnaryStreamCall], + client_call_details: ClientCallDetails, + request_iterator: RequestIterableType, ) -> Union[ResponseIterableType, StreamStreamCall]: """Intercepts a stream-stream invocation asynchronously. @@ -280,9 +280,8 @@ class InterceptedCall: def __del__(self): self.cancel() - def _fire_or_add_pending_done_callbacks(self, - interceptors_task: asyncio.Task - ) -> None: + def _fire_or_add_pending_done_callbacks( + self, interceptors_task: asyncio.Task) -> None: if not self._pending_add_done_callbacks: return @@ -442,8 +441,8 @@ class _InterceptedStreamResponseMixin: # consumed a logging warning is emmited by Asyncio. self._response_aiter = None - async def _wait_for_interceptor_task_response_iterator(self - ) -> ResponseType: + async def _wait_for_interceptor_task_response_iterator( + self) -> ResponseType: call = await self._interceptors_task async for response in call: yield response @@ -572,14 +571,14 @@ class InterceptedUnaryUnaryCall(_InterceptedUnaryResponseMixin, InterceptedCall, super().__init__(interceptors_task) # pylint: disable=too-many-arguments - async def _invoke(self, interceptors: Sequence[UnaryUnaryClientInterceptor], - method: bytes, timeout: Optional[float], - metadata: Optional[Metadata], - credentials: Optional[grpc.CallCredentials], - wait_for_ready: Optional[bool], request: RequestType, - request_serializer: SerializingFunction, - response_deserializer: DeserializingFunction - ) -> UnaryUnaryCall: + async def _invoke( + self, interceptors: Sequence[UnaryUnaryClientInterceptor], + method: bytes, timeout: Optional[float], + metadata: Optional[Metadata], + credentials: Optional[grpc.CallCredentials], + wait_for_ready: Optional[bool], request: RequestType, + request_serializer: SerializingFunction, + response_deserializer: DeserializingFunction) -> UnaryUnaryCall: """Run the RPC call wrapped in interceptors""" async def _run_interceptor( @@ -646,20 +645,20 @@ class InterceptedUnaryStreamCall(_InterceptedStreamResponseMixin, super().__init__(interceptors_task) # pylint: disable=too-many-arguments - async def _invoke(self, interceptors: Sequence[UnaryUnaryClientInterceptor], - method: bytes, timeout: Optional[float], - metadata: Optional[Metadata], - credentials: Optional[grpc.CallCredentials], - wait_for_ready: Optional[bool], request: RequestType, - request_serializer: SerializingFunction, - response_deserializer: DeserializingFunction - ) -> UnaryStreamCall: + async def _invoke( + self, interceptors: Sequence[UnaryUnaryClientInterceptor], + method: bytes, timeout: Optional[float], + metadata: Optional[Metadata], + credentials: Optional[grpc.CallCredentials], + wait_for_ready: Optional[bool], request: RequestType, + request_serializer: SerializingFunction, + response_deserializer: DeserializingFunction) -> UnaryStreamCall: """Run the RPC call wrapped in interceptors""" async def _run_interceptor( - interceptors: Iterator[UnaryStreamClientInterceptor], - client_call_details: ClientCallDetails, - request: RequestType, + interceptors: Iterator[UnaryStreamClientInterceptor], + client_call_details: ClientCallDetails, + request: RequestType, ) -> _base_call.UnaryUnaryCall: interceptor = next(interceptors, None) @@ -741,9 +740,9 @@ class InterceptedStreamUnaryCall(_InterceptedUnaryResponseMixin, """Run the RPC call wrapped in interceptors""" async def _run_interceptor( - interceptors: Iterator[UnaryUnaryClientInterceptor], - client_call_details: ClientCallDetails, - request_iterator: RequestIterableType + interceptors: Iterator[UnaryUnaryClientInterceptor], + client_call_details: ClientCallDetails, + request_iterator: RequestIterableType ) -> _base_call.StreamUnaryCall: interceptor = next(interceptors, None) @@ -814,9 +813,9 @@ class InterceptedStreamStreamCall(_InterceptedStreamResponseMixin, """Run the RPC call wrapped in interceptors""" async def _run_interceptor( - interceptors: Iterator[StreamStreamClientInterceptor], - client_call_details: ClientCallDetails, - request_iterator: RequestIterableType + interceptors: Iterator[StreamStreamClientInterceptor], + client_call_details: ClientCallDetails, + request_iterator: RequestIterableType ) -> _base_call.StreamStreamCall: interceptor = next(interceptors, None) @@ -908,8 +907,8 @@ class _StreamCallResponseIterator: _call: Union[_base_call.UnaryStreamCall, _base_call.StreamStreamCall] _response_iterator: AsyncIterable[ResponseType] - def __init__(self, call: Union[_base_call.UnaryStreamCall, _base_call. - StreamStreamCall], + def __init__(self, call: Union[_base_call.UnaryStreamCall, + _base_call.StreamStreamCall], response_iterator: AsyncIterable[ResponseType]) -> None: self._response_iterator = response_iterator self._call = call diff --git a/contrib/libs/grpc/src/python/grpcio/grpc/experimental/__init__.py b/contrib/libs/grpc/src/python/grpcio/grpc/experimental/__init__.py index a4e2660fb4..c820bc9db3 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc/experimental/__init__.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc/experimental/__init__.py @@ -22,6 +22,7 @@ import sys import warnings import grpc +from grpc._cython import cygrpc as _cygrpc _EXPERIMENTAL_APIS_USED = set() @@ -41,19 +42,16 @@ class UsageError(Exception): """Raised by the gRPC library to indicate usage not allowed by the API.""" -_insecure_channel_credentials_sentinel = object() +# It's important that there be a single insecure credentials object so that its +# hash is deterministic and can be used for indexing in the simple stubs cache. _insecure_channel_credentials = grpc.ChannelCredentials( - _insecure_channel_credentials_sentinel) + _cygrpc.channel_credentials_insecure()) def insecure_channel_credentials(): """Creates a ChannelCredentials for use with an insecure channel. THIS IS AN EXPERIMENTAL API. - - This is not for use with secure_channel function. Intead, this should be - used with grpc.unary_unary, grpc.unary_stream, grpc.stream_unary, or - grpc.stream_stream. """ return _insecure_channel_credentials diff --git a/contrib/libs/grpc/src/python/grpcio/grpc_core_dependencies.py b/contrib/libs/grpc/src/python/grpcio/grpc_core_dependencies.py index 67f985e1f4..f3d11423ef 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc_core_dependencies.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc_core_dependencies.py @@ -24,6 +24,7 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', 'src/core/ext/filters/client_channel/config_selector.cc', + 'src/core/ext/filters/client_channel/dynamic_filters.cc', 'src/core/ext/filters/client_channel/global_subchannel_pool.cc', 'src/core/ext/filters/client_channel/health/health_check_client.cc', 'src/core/ext/filters/client_channel/http_connect_handshaker.cc', @@ -39,34 +40,33 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc', 'src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc', 'src/core/ext/filters/client_channel/lb_policy/priority/priority.cc', + 'src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc', 'src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc', 'src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/cds.cc', - 'src/core/ext/filters/client_channel/lb_policy/xds/eds.cc', - 'src/core/ext/filters/client_channel/lb_policy/xds/eds_drop.cc', + 'src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc', 'src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc', + 'src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc', 'src/core/ext/filters/client_channel/lb_policy_registry.cc', 'src/core/ext/filters/client_channel/local_subchannel_pool.cc', 'src/core/ext/filters/client_channel/proxy_mapper_registry.cc', 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc', - 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc', - 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc', 'src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc', 'src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc', 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc', + 'src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc', 'src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc', 'src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/resolver_result_parsing.cc', - 'src/core/ext/filters/client_channel/resolving_lb_policy.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', 'src/core/ext/filters/client_channel/server_address.cc', 'src/core/ext/filters/client_channel/service_config.cc', @@ -76,6 +76,8 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/subchannel_pool_interface.cc', 'src/core/ext/filters/client_idle/client_idle_filter.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', + 'src/core/ext/filters/fault_injection/fault_injection_filter.cc', + 'src/core/ext/filters/fault_injection/service_config_parser.cc', 'src/core/ext/filters/http/client/http_client_filter.cc', 'src/core/ext/filters/http/client_authority_filter.cc', 'src/core/ext/filters/http/http_filters_plugin.cc', @@ -121,9 +123,11 @@ CORE_SOURCE_FILES = [ 'src/core/ext/transport/chttp2/transport/writing.cc', 'src/core/ext/transport/inproc/inproc_plugin.cc', 'src/core/ext/transport/inproc/inproc_transport.cc', + 'src/core/ext/upb-generated/envoy/admin/v3/config_dump.upb.c', 'src/core/ext/upb-generated/envoy/annotations/deprecation.upb.c', 'src/core/ext/upb-generated/envoy/annotations/resource.upb.c', 'src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c', + 'src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.c', 'src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c', 'src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c', 'src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.c', @@ -148,11 +152,17 @@ CORE_SOURCE_FILES = [ 'src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c', 'src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c', 'src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c', + 'src/core/ext/upb-generated/envoy/config/metrics/v3/stats.upb.c', + 'src/core/ext/upb-generated/envoy/config/overload/v3/overload.upb.c', 'src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c', 'src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c', 'src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c', 'src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c', 'src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c', + 'src/core/ext/upb-generated/envoy/extensions/clusters/aggregate/v3/cluster.upb.c', + 'src/core/ext/upb-generated/envoy/extensions/filters/common/fault/v3/fault.upb.c', + 'src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.c', + 'src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.c', 'src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c', 'src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.c', 'src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c', @@ -166,11 +176,14 @@ CORE_SOURCE_FILES = [ 'src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c', 'src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.c', 'src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.c', + 'src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.c', 'src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c', + 'src/core/ext/upb-generated/envoy/type/matcher/v3/node.upb.c', 'src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c', 'src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c', 'src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c', 'src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c', + 'src/core/ext/upb-generated/envoy/type/matcher/v3/struct.upb.c', 'src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c', 'src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c', 'src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c', @@ -200,20 +213,116 @@ CORE_SOURCE_FILES = [ 'src/core/ext/upb-generated/udpa/annotations/sensitive.upb.c', 'src/core/ext/upb-generated/udpa/annotations/status.upb.c', 'src/core/ext/upb-generated/udpa/annotations/versioning.upb.c', - 'src/core/ext/upb-generated/udpa/core/v1/authority.upb.c', - 'src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.c', - 'src/core/ext/upb-generated/udpa/core/v1/context_params.upb.c', - 'src/core/ext/upb-generated/udpa/core/v1/resource.upb.c', - 'src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.c', - 'src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.c', 'src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c', + 'src/core/ext/upb-generated/udpa/type/v1/typed_struct.upb.c', 'src/core/ext/upb-generated/validate/validate.upb.c', + 'src/core/ext/upb-generated/xds/core/v3/authority.upb.c', + 'src/core/ext/upb-generated/xds/core/v3/collection_entry.upb.c', + 'src/core/ext/upb-generated/xds/core/v3/context_params.upb.c', + 'src/core/ext/upb-generated/xds/core/v3/resource.upb.c', + 'src/core/ext/upb-generated/xds/core/v3/resource_locator.upb.c', + 'src/core/ext/upb-generated/xds/core/v3/resource_name.upb.c', + 'src/core/ext/upbdefs-generated/envoy/admin/v3/config_dump.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/annotations/resource.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/cluster/v3/circuit_breaker.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/cluster/v3/filter.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/address.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/backoff.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/event_service_config.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/http_uri.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/proxy_protocol.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/socket_option.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/load_report.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/listener/v3/api_listener.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/metrics/v3/stats.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/overload/v3/overload.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/route/v3/scoped_route.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/config/trace/v3/http_tracer.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/extensions/filters/common/fault/v3/fault.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/extensions/filters/http/fault/v3/fault.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/extensions/filters/http/router/v3/router.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/service/cluster/v3/cds.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/service/discovery/v3/ads.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/service/endpoint/v3/eds.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/service/listener/v3/lds.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/service/load_stats/v3/lrs.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/service/route/v3/rds.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/service/route/v3/srds.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/matcher/v3/metadata.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/matcher/v3/node.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/matcher/v3/number.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/matcher/v3/path.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/matcher/v3/string.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/matcher/v3/struct.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/matcher/v3/value.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/metadata/v3/metadata.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/tracing/v3/custom_tag.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/v3/http.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/v3/percent.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/v3/range.upbdefs.c', + 'src/core/ext/upbdefs-generated/envoy/type/v3/semantic_version.upbdefs.c', + 'src/core/ext/upbdefs-generated/google/api/annotations.upbdefs.c', + 'src/core/ext/upbdefs-generated/google/api/http.upbdefs.c', + 'src/core/ext/upbdefs-generated/google/protobuf/any.upbdefs.c', + 'src/core/ext/upbdefs-generated/google/protobuf/descriptor.upbdefs.c', + 'src/core/ext/upbdefs-generated/google/protobuf/duration.upbdefs.c', + 'src/core/ext/upbdefs-generated/google/protobuf/empty.upbdefs.c', + 'src/core/ext/upbdefs-generated/google/protobuf/struct.upbdefs.c', + 'src/core/ext/upbdefs-generated/google/protobuf/timestamp.upbdefs.c', + 'src/core/ext/upbdefs-generated/google/protobuf/wrappers.upbdefs.c', + 'src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.c', + 'src/core/ext/upbdefs-generated/udpa/annotations/migrate.upbdefs.c', + 'src/core/ext/upbdefs-generated/udpa/annotations/security.upbdefs.c', + 'src/core/ext/upbdefs-generated/udpa/annotations/sensitive.upbdefs.c', + 'src/core/ext/upbdefs-generated/udpa/annotations/status.upbdefs.c', + 'src/core/ext/upbdefs-generated/udpa/annotations/versioning.upbdefs.c', + 'src/core/ext/upbdefs-generated/udpa/type/v1/typed_struct.upbdefs.c', + 'src/core/ext/upbdefs-generated/validate/validate.upbdefs.c', + 'src/core/ext/upbdefs-generated/xds/core/v3/authority.upbdefs.c', + 'src/core/ext/upbdefs-generated/xds/core/v3/collection_entry.upbdefs.c', + 'src/core/ext/upbdefs-generated/xds/core/v3/context_params.upbdefs.c', + 'src/core/ext/upbdefs-generated/xds/core/v3/resource.upbdefs.c', + 'src/core/ext/upbdefs-generated/xds/core/v3/resource_locator.upbdefs.c', + 'src/core/ext/upbdefs-generated/xds/core/v3/resource_name.upbdefs.c', 'src/core/ext/xds/certificate_provider_registry.cc', - 'src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc', + 'src/core/ext/xds/certificate_provider_store.cc', + 'src/core/ext/xds/file_watcher_certificate_provider_factory.cc', 'src/core/ext/xds/xds_api.cc', 'src/core/ext/xds/xds_bootstrap.cc', + 'src/core/ext/xds/xds_certificate_provider.cc', 'src/core/ext/xds/xds_client.cc', 'src/core/ext/xds/xds_client_stats.cc', + 'src/core/ext/xds/xds_http_fault_filter.cc', + 'src/core/ext/xds/xds_http_filters.cc', + 'src/core/ext/xds/xds_server_config_fetcher.cc', 'src/core/lib/avl/avl.cc', 'src/core/lib/backoff/backoff.cc', 'src/core/lib/channel/channel_args.cc', @@ -269,12 +378,16 @@ CORE_SOURCE_FILES = [ 'src/core/lib/gpr/tmpfile_windows.cc', 'src/core/lib/gpr/wrap_memcpy.cc', 'src/core/lib/gprpp/arena.cc', + 'src/core/lib/gprpp/examine_stack.cc', 'src/core/lib/gprpp/fork.cc', 'src/core/lib/gprpp/global_config_env.cc', 'src/core/lib/gprpp/host_port.cc', 'src/core/lib/gprpp/mpscq.cc', + 'src/core/lib/gprpp/stat_posix.cc', + 'src/core/lib/gprpp/stat_windows.cc', 'src/core/lib/gprpp/thd_posix.cc', 'src/core/lib/gprpp/thd_windows.cc', + 'src/core/lib/gprpp/time_util.cc', 'src/core/lib/http/format_request.cc', 'src/core/lib/http/httpcli.cc', 'src/core/lib/http/httpcli_security_connector.cc', @@ -378,10 +491,9 @@ CORE_SOURCE_FILES = [ 'src/core/lib/json/json_reader.cc', 'src/core/lib/json/json_util.cc', 'src/core/lib/json/json_writer.cc', + 'src/core/lib/matchers/matchers.cc', 'src/core/lib/profiling/basic_timers.cc', 'src/core/lib/profiling/stap_timers.cc', - 'src/core/lib/security/authorization/authorization_engine.cc', - 'src/core/lib/security/authorization/evaluate_args.cc', 'src/core/lib/security/context/security_context.cc', 'src/core/lib/security/credentials/alts/alts_credentials.cc', 'src/core/lib/security/credentials/alts/check_gcp_environment.cc', @@ -394,10 +506,16 @@ CORE_SOURCE_FILES = [ 'src/core/lib/security/credentials/composite/composite_credentials.cc', 'src/core/lib/security/credentials/credentials.cc', 'src/core/lib/security/credentials/credentials_metadata.cc', + 'src/core/lib/security/credentials/external/aws_external_account_credentials.cc', + 'src/core/lib/security/credentials/external/aws_request_signer.cc', + 'src/core/lib/security/credentials/external/external_account_credentials.cc', + 'src/core/lib/security/credentials/external/file_external_account_credentials.cc', + 'src/core/lib/security/credentials/external/url_external_account_credentials.cc', 'src/core/lib/security/credentials/fake/fake_credentials.cc', 'src/core/lib/security/credentials/google_default/credentials_generic.cc', 'src/core/lib/security/credentials/google_default/google_default_credentials.cc', 'src/core/lib/security/credentials/iam/iam_credentials.cc', + 'src/core/lib/security/credentials/insecure/insecure_credentials.cc', 'src/core/lib/security/credentials/jwt/json_token.cc', 'src/core/lib/security/credentials/jwt/jwt_credentials.cc', 'src/core/lib/security/credentials/jwt/jwt_verifier.cc', @@ -406,11 +524,14 @@ CORE_SOURCE_FILES = [ 'src/core/lib/security/credentials/plugin/plugin_credentials.cc', 'src/core/lib/security/credentials/ssl/ssl_credentials.cc', 'src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc', + 'src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc', 'src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc', 'src/core/lib/security/credentials/tls/tls_credentials.cc', + 'src/core/lib/security/credentials/tls/tls_utils.cc', 'src/core/lib/security/credentials/xds/xds_credentials.cc', 'src/core/lib/security/security_connector/alts/alts_security_connector.cc', 'src/core/lib/security/security_connector/fake/fake_security_connector.cc', + 'src/core/lib/security/security_connector/insecure/insecure_security_connector.cc', 'src/core/lib/security/security_connector/load_system_roots_fallback.cc', 'src/core/lib/security/security_connector/load_system_roots_linux.cc', 'src/core/lib/security/security_connector/local/local_security_connector.cc', @@ -494,7 +615,6 @@ CORE_SOURCE_FILES = [ 'src/core/tsi/ssl_transport_security.cc', 'src/core/tsi/transport_security.cc', 'src/core/tsi/transport_security_grpc.cc', - 'third_party/abseil-cpp/y_absl/base/dynamic_annotations.cc', 'third_party/abseil-cpp/y_absl/base/internal/cycleclock.cc', 'third_party/abseil-cpp/y_absl/base/internal/exponential_biased.cc', 'third_party/abseil-cpp/y_absl/base/internal/low_level_alloc.cc', @@ -520,6 +640,7 @@ CORE_SOURCE_FILES = [ 'third_party/abseil-cpp/y_absl/numeric/int128.cc', 'third_party/abseil-cpp/y_absl/status/status.cc', 'third_party/abseil-cpp/y_absl/status/status_payload_printer.cc', + 'third_party/abseil-cpp/y_absl/status/statusor.cc', 'third_party/abseil-cpp/y_absl/strings/ascii.cc', 'third_party/abseil-cpp/y_absl/strings/charconv.cc', 'third_party/abseil-cpp/y_absl/strings/cord.cc', @@ -613,6 +734,7 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl-with-bazel/src/crypto/bio/printf.c', 'third_party/boringssl-with-bazel/src/crypto/bio/socket.c', 'third_party/boringssl-with-bazel/src/crypto/bio/socket_helper.c', + 'third_party/boringssl-with-bazel/src/crypto/blake2/blake2.c', 'third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c', 'third_party/boringssl-with-bazel/src/crypto/bn_extra/convert.c', 'third_party/boringssl-with-bazel/src/crypto/buf/buf.c', @@ -637,6 +759,7 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl-with-bazel/src/crypto/conf/conf.c', 'third_party/boringssl-with-bazel/src/crypto/cpu-aarch64-fuchsia.c', 'third_party/boringssl-with-bazel/src/crypto/cpu-aarch64-linux.c', + 'third_party/boringssl-with-bazel/src/crypto/cpu-aarch64-win.c', 'third_party/boringssl-with-bazel/src/crypto/cpu-arm-linux.c', 'third_party/boringssl-with-bazel/src/crypto/cpu-arm.c', 'third_party/boringssl-with-bazel/src/crypto/cpu-intel.c', @@ -644,10 +767,8 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl-with-bazel/src/crypto/crypto.c', 'third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519.c', 'third_party/boringssl-with-bazel/src/crypto/curve25519/spake25519.c', - 'third_party/boringssl-with-bazel/src/crypto/dh/check.c', - 'third_party/boringssl-with-bazel/src/crypto/dh/dh.c', - 'third_party/boringssl-with-bazel/src/crypto/dh/dh_asn1.c', - 'third_party/boringssl-with-bazel/src/crypto/dh/params.c', + 'third_party/boringssl-with-bazel/src/crypto/dh_extra/dh_asn1.c', + 'third_party/boringssl-with-bazel/src/crypto/dh_extra/params.c', 'third_party/boringssl-with-bazel/src/crypto/digest_extra/digest_extra.c', 'third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c', 'third_party/boringssl-with-bazel/src/crypto/dsa/dsa_asn1.c', @@ -706,6 +827,7 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl-with-bazel/src/crypto/rand_extra/deterministic.c', 'third_party/boringssl-with-bazel/src/crypto/rand_extra/forkunsafe.c', 'third_party/boringssl-with-bazel/src/crypto/rand_extra/fuchsia.c', + 'third_party/boringssl-with-bazel/src/crypto/rand_extra/passive.c', 'third_party/boringssl-with-bazel/src/crypto/rand_extra/rand_extra.c', 'third_party/boringssl-with-bazel/src/crypto/rand_extra/windows.c', 'third_party/boringssl-with-bazel/src/crypto/rc4/rc4.c', @@ -721,6 +843,7 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl-with-bazel/src/crypto/thread_win.c', 'third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c', 'third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c', + 'third_party/boringssl-with-bazel/src/crypto/trust_token/voprf.c', 'third_party/boringssl-with-bazel/src/crypto/x509/a_digest.c', 'third_party/boringssl-with-bazel/src/crypto/x509/a_sign.c', 'third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c', @@ -911,10 +1034,13 @@ CORE_SOURCE_FILES = [ 'third_party/re2/util/rune.cc', 'third_party/re2/util/strutil.cc', 'third_party/upb/upb/decode.c', + 'third_party/upb/upb/decode_fast.c', + 'third_party/upb/upb/def.c', 'third_party/upb/upb/encode.c', 'third_party/upb/upb/msg.c', - 'third_party/upb/upb/port.c', + 'third_party/upb/upb/reflection.c', 'third_party/upb/upb/table.c', + 'third_party/upb/upb/text_encode.c', 'third_party/upb/upb/upb.c', 'third_party/zlib/adler32.c', 'third_party/zlib/compress.c', @@ -946,62 +1072,51 @@ ASM_SOURCE_FILES = { 'third_party/boringssl-with-bazel/ios-aarch64/crypto/fipsmodule/vpaes-armv8.S', 'third_party/boringssl-with-bazel/ios-aarch64/crypto/test/trampoline-armv8.S', ], - 'crypto_mac_x86_64': [ - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/chacha/chacha-x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/cipher_extra/aes128gcmsiv-x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/cipher_extra/chacha20_poly1305_x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/aesni-gcm-x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/aesni-x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/ghash-ssse3-x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/ghash-x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/md5-x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/p256-x86_64-asm.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/p256_beeu-x86_64-asm.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/rdrand-x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/rsaz-avx2.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/sha1-x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/sha256-x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/sha512-x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/vpaes-x86_64.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/x86_64-mont.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/x86_64-mont5.S', - 'third_party/boringssl-with-bazel/mac-x86_64/crypto/test/trampoline-x86_64.S', + 'crypto_ios_arm': [ + 'third_party/boringssl-with-bazel/ios-arm/crypto/chacha/chacha-armv4.S', + 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/aesv8-armx32.S', + 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/armv4-mont.S', + 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/bsaes-armv7.S', + 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/ghash-armv4.S', + 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/ghashv8-armx32.S', + 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/sha1-armv4-large.S', + 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/sha256-armv4.S', + 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/sha512-armv4.S', + 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/vpaes-armv7.S', + 'third_party/boringssl-with-bazel/ios-arm/crypto/test/trampoline-armv4.S', ], - 'crypto_win_x86': [ - 'third_party/boringssl-with-bazel/win-x86/crypto/chacha/chacha-x86.asm', - 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/aesni-x86.asm', - 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/bn-586.asm', - 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/co-586.asm', - 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/ghash-ssse3-x86.asm', - 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/ghash-x86.asm', - 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/md5-586.asm', - 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/sha1-586.asm', - 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/sha256-586.asm', - 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/sha512-586.asm', - 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/vpaes-x86.asm', - 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/x86-mont.asm', - 'third_party/boringssl-with-bazel/win-x86/crypto/test/trampoline-x86.asm', + 'crypto_linux_aarch64': [ + 'third_party/boringssl-with-bazel/linux-aarch64/crypto/chacha/chacha-armv8.S', + 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/aesv8-armx64.S', + 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/armv8-mont.S', + 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/ghash-neon-armv8.S', + 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/ghashv8-armx64.S', + 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/sha1-armv8.S', + 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/sha256-armv8.S', + 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/sha512-armv8.S', + 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/vpaes-armv8.S', + 'third_party/boringssl-with-bazel/linux-aarch64/crypto/test/trampoline-armv8.S', + ], + 'crypto_linux_arm': [ + 'third_party/boringssl-with-bazel/linux-arm/crypto/chacha/chacha-armv4.S', + 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/aesv8-armx32.S', + 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/armv4-mont.S', + 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/bsaes-armv7.S', + 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/ghash-armv4.S', + 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/ghashv8-armx32.S', + 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/sha1-armv4-large.S', + 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/sha256-armv4.S', + 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/sha512-armv4.S', + 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/vpaes-armv7.S', + 'third_party/boringssl-with-bazel/linux-arm/crypto/test/trampoline-armv4.S', + 'third_party/boringssl-with-bazel/src/crypto/curve25519/asm/x25519-asm-arm.S', + 'third_party/boringssl-with-bazel/src/crypto/poly1305/poly1305_arm_asm.S', ], 'crypto_linux_ppc64le': [ 'third_party/boringssl-with-bazel/linux-ppc64le/crypto/fipsmodule/aesp8-ppc.S', 'third_party/boringssl-with-bazel/linux-ppc64le/crypto/fipsmodule/ghashp8-ppc.S', 'third_party/boringssl-with-bazel/linux-ppc64le/crypto/test/trampoline-ppc.S', ], - 'crypto_mac_x86': [ - 'third_party/boringssl-with-bazel/mac-x86/crypto/chacha/chacha-x86.S', - 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/aesni-x86.S', - 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/bn-586.S', - 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/co-586.S', - 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/ghash-ssse3-x86.S', - 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/ghash-x86.S', - 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/md5-586.S', - 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/sha1-586.S', - 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/sha256-586.S', - 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/sha512-586.S', - 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/vpaes-x86.S', - 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/x86-mont.S', - 'third_party/boringssl-with-bazel/mac-x86/crypto/test/trampoline-x86.S', - ], 'crypto_linux_x86': [ 'third_party/boringssl-with-bazel/linux-x86/crypto/chacha/chacha-x86.S', 'third_party/boringssl-with-bazel/linux-x86/crypto/fipsmodule/aesni-x86.S', @@ -1017,19 +1132,6 @@ ASM_SOURCE_FILES = { 'third_party/boringssl-with-bazel/linux-x86/crypto/fipsmodule/x86-mont.S', 'third_party/boringssl-with-bazel/linux-x86/crypto/test/trampoline-x86.S', ], - 'crypto_ios_arm': [ - 'third_party/boringssl-with-bazel/ios-arm/crypto/chacha/chacha-armv4.S', - 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/aesv8-armx32.S', - 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/armv4-mont.S', - 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/bsaes-armv7.S', - 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/ghash-armv4.S', - 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/ghashv8-armx32.S', - 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/sha1-armv4-large.S', - 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/sha256-armv4.S', - 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/sha512-armv4.S', - 'third_party/boringssl-with-bazel/ios-arm/crypto/fipsmodule/vpaes-armv7.S', - 'third_party/boringssl-with-bazel/ios-arm/crypto/test/trampoline-armv4.S', - ], 'crypto_linux_x86_64': [ 'third_party/boringssl-with-bazel/linux-x86_64/crypto/chacha/chacha-x86_64.S', 'third_party/boringssl-with-bazel/linux-x86_64/crypto/cipher_extra/aes128gcmsiv-x86_64.S', @@ -1052,6 +1154,69 @@ ASM_SOURCE_FILES = { 'third_party/boringssl-with-bazel/linux-x86_64/crypto/test/trampoline-x86_64.S', 'third_party/boringssl-with-bazel/src/crypto/hrss/asm/poly_rq_mul.S', ], + 'crypto_mac_x86': [ + 'third_party/boringssl-with-bazel/mac-x86/crypto/chacha/chacha-x86.S', + 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/aesni-x86.S', + 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/bn-586.S', + 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/co-586.S', + 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/ghash-ssse3-x86.S', + 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/ghash-x86.S', + 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/md5-586.S', + 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/sha1-586.S', + 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/sha256-586.S', + 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/sha512-586.S', + 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/vpaes-x86.S', + 'third_party/boringssl-with-bazel/mac-x86/crypto/fipsmodule/x86-mont.S', + 'third_party/boringssl-with-bazel/mac-x86/crypto/test/trampoline-x86.S', + ], + 'crypto_mac_x86_64': [ + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/chacha/chacha-x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/cipher_extra/aes128gcmsiv-x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/cipher_extra/chacha20_poly1305_x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/aesni-gcm-x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/aesni-x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/ghash-ssse3-x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/ghash-x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/md5-x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/p256-x86_64-asm.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/p256_beeu-x86_64-asm.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/rdrand-x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/rsaz-avx2.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/sha1-x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/sha256-x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/sha512-x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/vpaes-x86_64.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/x86_64-mont.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/fipsmodule/x86_64-mont5.S', + 'third_party/boringssl-with-bazel/mac-x86_64/crypto/test/trampoline-x86_64.S', + ], + 'crypto_win_aarch64': [ + 'third_party/boringssl-with-bazel/win-aarch64/crypto/chacha/chacha-armv8.S', + 'third_party/boringssl-with-bazel/win-aarch64/crypto/fipsmodule/aesv8-armx64.S', + 'third_party/boringssl-with-bazel/win-aarch64/crypto/fipsmodule/armv8-mont.S', + 'third_party/boringssl-with-bazel/win-aarch64/crypto/fipsmodule/ghash-neon-armv8.S', + 'third_party/boringssl-with-bazel/win-aarch64/crypto/fipsmodule/ghashv8-armx64.S', + 'third_party/boringssl-with-bazel/win-aarch64/crypto/fipsmodule/sha1-armv8.S', + 'third_party/boringssl-with-bazel/win-aarch64/crypto/fipsmodule/sha256-armv8.S', + 'third_party/boringssl-with-bazel/win-aarch64/crypto/fipsmodule/sha512-armv8.S', + 'third_party/boringssl-with-bazel/win-aarch64/crypto/fipsmodule/vpaes-armv8.S', + 'third_party/boringssl-with-bazel/win-aarch64/crypto/test/trampoline-armv8.S', + ], + 'crypto_win_x86': [ + 'third_party/boringssl-with-bazel/win-x86/crypto/chacha/chacha-x86.asm', + 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/aesni-x86.asm', + 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/bn-586.asm', + 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/co-586.asm', + 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/ghash-ssse3-x86.asm', + 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/ghash-x86.asm', + 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/md5-586.asm', + 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/sha1-586.asm', + 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/sha256-586.asm', + 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/sha512-586.asm', + 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/vpaes-x86.asm', + 'third_party/boringssl-with-bazel/win-x86/crypto/fipsmodule/x86-mont.asm', + 'third_party/boringssl-with-bazel/win-x86/crypto/test/trampoline-x86.asm', + ], 'crypto_win_x86_64': [ 'third_party/boringssl-with-bazel/win-x86_64/crypto/chacha/chacha-x86_64.asm', 'third_party/boringssl-with-bazel/win-x86_64/crypto/cipher_extra/aes128gcmsiv-x86_64.asm', @@ -1073,31 +1238,4 @@ ASM_SOURCE_FILES = { 'third_party/boringssl-with-bazel/win-x86_64/crypto/fipsmodule/x86_64-mont5.asm', 'third_party/boringssl-with-bazel/win-x86_64/crypto/test/trampoline-x86_64.asm', ], - 'crypto_linux_aarch64': [ - 'third_party/boringssl-with-bazel/linux-aarch64/crypto/chacha/chacha-armv8.S', - 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/aesv8-armx64.S', - 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/armv8-mont.S', - 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/ghash-neon-armv8.S', - 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/ghashv8-armx64.S', - 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/sha1-armv8.S', - 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/sha256-armv8.S', - 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/sha512-armv8.S', - 'third_party/boringssl-with-bazel/linux-aarch64/crypto/fipsmodule/vpaes-armv8.S', - 'third_party/boringssl-with-bazel/linux-aarch64/crypto/test/trampoline-armv8.S', - ], - 'crypto_linux_arm': [ - 'third_party/boringssl-with-bazel/linux-arm/crypto/chacha/chacha-armv4.S', - 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/aesv8-armx32.S', - 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/armv4-mont.S', - 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/bsaes-armv7.S', - 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/ghash-armv4.S', - 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/ghashv8-armx32.S', - 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/sha1-armv4-large.S', - 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/sha256-armv4.S', - 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/sha512-armv4.S', - 'third_party/boringssl-with-bazel/linux-arm/crypto/fipsmodule/vpaes-armv7.S', - 'third_party/boringssl-with-bazel/linux-arm/crypto/test/trampoline-armv4.S', - 'third_party/boringssl-with-bazel/src/crypto/curve25519/asm/x25519-asm-arm.S', - 'third_party/boringssl-with-bazel/src/crypto/poly1305/poly1305_arm_asm.S', - ], } diff --git a/contrib/libs/grpc/src/python/grpcio/grpc_version.py b/contrib/libs/grpc/src/python/grpcio/grpc_version.py index 9237f14e2f..ece1ae87a5 100644 --- a/contrib/libs/grpc/src/python/grpcio/grpc_version.py +++ b/contrib/libs/grpc/src/python/grpcio/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio/grpc_version.py.template`!!! -VERSION = '1.33.2' +VERSION = '1.37.1' diff --git a/contrib/libs/grpc/src/python/grpcio_channelz/grpc_channelz/v1/_async.py b/contrib/libs/grpc/src/python/grpcio_channelz/grpc_channelz/v1/_async.py index 50911b0fd9..3f0d93fdc3 100644 --- a/contrib/libs/grpc/src/python/grpcio_channelz/grpc_channelz/v1/_async.py +++ b/contrib/libs/grpc/src/python/grpcio_channelz/grpc_channelz/v1/_async.py @@ -24,43 +24,46 @@ class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer): """AsyncIO servicer for handling RPCs for service statuses.""" @staticmethod - async def GetTopChannels(request: _channelz_pb2.GetTopChannelsRequest, - context: aio.ServicerContext - ) -> _channelz_pb2.GetTopChannelsResponse: + async def GetTopChannels( + request: _channelz_pb2.GetTopChannelsRequest, + context: aio.ServicerContext + ) -> _channelz_pb2.GetTopChannelsResponse: return _SyncChannelzServicer.GetTopChannels(request, context) @staticmethod - async def GetServers(request: _channelz_pb2.GetServersRequest, - context: aio.ServicerContext - ) -> _channelz_pb2.GetServersResponse: + async def GetServers( + request: _channelz_pb2.GetServersRequest, + context: aio.ServicerContext) -> _channelz_pb2.GetServersResponse: return _SyncChannelzServicer.GetServers(request, context) @staticmethod - async def GetServer(request: _channelz_pb2.GetServerRequest, - context: aio.ServicerContext - ) -> _channelz_pb2.GetServerResponse: + async def GetServer( + request: _channelz_pb2.GetServerRequest, + context: aio.ServicerContext) -> _channelz_pb2.GetServerResponse: return _SyncChannelzServicer.GetServer(request, context) @staticmethod - async def GetServerSockets(request: _channelz_pb2.GetServerSocketsRequest, - context: aio.ServicerContext - ) -> _channelz_pb2.GetServerSocketsResponse: + async def GetServerSockets( + request: _channelz_pb2.GetServerSocketsRequest, + context: aio.ServicerContext + ) -> _channelz_pb2.GetServerSocketsResponse: return _SyncChannelzServicer.GetServerSockets(request, context) @staticmethod - async def GetChannel(request: _channelz_pb2.GetChannelRequest, - context: aio.ServicerContext - ) -> _channelz_pb2.GetChannelResponse: + async def GetChannel( + request: _channelz_pb2.GetChannelRequest, + context: aio.ServicerContext) -> _channelz_pb2.GetChannelResponse: return _SyncChannelzServicer.GetChannel(request, context) @staticmethod - async def GetSubchannel(request: _channelz_pb2.GetSubchannelRequest, - context: aio.ServicerContext - ) -> _channelz_pb2.GetSubchannelResponse: + async def GetSubchannel( + request: _channelz_pb2.GetSubchannelRequest, + context: aio.ServicerContext + ) -> _channelz_pb2.GetSubchannelResponse: return _SyncChannelzServicer.GetSubchannel(request, context) @staticmethod - async def GetSocket(request: _channelz_pb2.GetSocketRequest, - context: aio.ServicerContext - ) -> _channelz_pb2.GetSocketResponse: + async def GetSocket( + request: _channelz_pb2.GetSocketRequest, + context: aio.ServicerContext) -> _channelz_pb2.GetSocketResponse: return _SyncChannelzServicer.GetSocket(request, context) diff --git a/contrib/libs/grpc/src/python/grpcio_channelz/grpc_version.py b/contrib/libs/grpc/src/python/grpcio_channelz/grpc_version.py index 52cb1a9d3b..197b529922 100644 --- a/contrib/libs/grpc/src/python/grpcio_channelz/grpc_version.py +++ b/contrib/libs/grpc/src/python/grpcio_channelz/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_channelz/grpc_version.py.template`!!! -VERSION = '1.33.2' +VERSION = '1.37.1' diff --git a/contrib/libs/grpc/src/python/grpcio_health_checking/grpc_health/v1/_async.py b/contrib/libs/grpc/src/python/grpcio_health_checking/grpc_health/v1/_async.py index 752531f517..de9712a7c5 100644 --- a/contrib/libs/grpc/src/python/grpcio_health_checking/grpc_health/v1/_async.py +++ b/contrib/libs/grpc/src/python/grpcio_health_checking/grpc_health/v1/_async.py @@ -71,9 +71,9 @@ class HealthServicer(_health_pb2_grpc.HealthServicer): if request.service in self._server_watchers: del self._server_watchers[request.service] - async def _set(self, service: str, - status: _health_pb2.HealthCheckResponse.ServingStatus - ) -> None: + async def _set( + self, service: str, + status: _health_pb2.HealthCheckResponse.ServingStatus) -> None: if service in self._server_watchers: condition = self._server_watchers.get(service) async with condition: @@ -82,9 +82,9 @@ class HealthServicer(_health_pb2_grpc.HealthServicer): else: self._server_status[service] = status - async def set(self, service: str, - status: _health_pb2.HealthCheckResponse.ServingStatus - ) -> None: + async def set( + self, service: str, + status: _health_pb2.HealthCheckResponse.ServingStatus) -> None: """Sets the status of a service. Args: diff --git a/contrib/libs/grpc/src/python/grpcio_health_checking/grpc_version.py b/contrib/libs/grpc/src/python/grpcio_health_checking/grpc_version.py index f676be1068..3e60e12ef8 100644 --- a/contrib/libs/grpc/src/python/grpcio_health_checking/grpc_version.py +++ b/contrib/libs/grpc/src/python/grpcio_health_checking/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_health_checking/grpc_version.py.template`!!! -VERSION = '1.33.2' +VERSION = '1.37.1' diff --git a/contrib/libs/grpc/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py b/contrib/libs/grpc/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py index fb567fc09f..bdd9b23289 100644 --- a/contrib/libs/grpc/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py +++ b/contrib/libs/grpc/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py @@ -25,8 +25,8 @@ class ReflectionServicer(BaseReflectionServicer): """Servicer handling RPCs for service statuses.""" async def ServerReflectionInfo( - self, request_iterator: AsyncIterable[ - _reflection_pb2.ServerReflectionRequest], unused_context + self, request_iterator: AsyncIterable[ + _reflection_pb2.ServerReflectionRequest], unused_context ) -> AsyncIterable[_reflection_pb2.ServerReflectionResponse]: async for request in request_iterator: if request.HasField('file_by_filename'): diff --git a/contrib/libs/grpc/src/python/grpcio_reflection/grpc_version.py b/contrib/libs/grpc/src/python/grpcio_reflection/grpc_version.py index 676511118a..7b3e707985 100644 --- a/contrib/libs/grpc/src/python/grpcio_reflection/grpc_version.py +++ b/contrib/libs/grpc/src/python/grpcio_reflection/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_reflection/grpc_version.py.template`!!! -VERSION = '1.33.2' +VERSION = '1.37.1' diff --git a/contrib/libs/grpc/src/python/grpcio_status/grpc_version.py b/contrib/libs/grpc/src/python/grpcio_status/grpc_version.py index 2b6ec9c659..95a2a872e8 100644 --- a/contrib/libs/grpc/src/python/grpcio_status/grpc_version.py +++ b/contrib/libs/grpc/src/python/grpcio_status/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_status/grpc_version.py.template`!!! -VERSION = '1.33.2' +VERSION = '1.37.1' diff --git a/contrib/libs/grpc/src/python/grpcio_testing/grpc_version.py b/contrib/libs/grpc/src/python/grpcio_testing/grpc_version.py index c042934ba3..899dae7730 100644 --- a/contrib/libs/grpc/src/python/grpcio_testing/grpc_version.py +++ b/contrib/libs/grpc/src/python/grpcio_testing/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_testing/grpc_version.py.template`!!! -VERSION = '1.33.2' +VERSION = '1.37.1' diff --git a/contrib/libs/grpc/src/python/grpcio_tests/.yandex_meta/licenses.list.txt b/contrib/libs/grpc/src/python/grpcio_tests/.yandex_meta/licenses.list.txt index e0080a7b1f..a9192e37f1 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/.yandex_meta/licenses.list.txt +++ b/contrib/libs/grpc/src/python/grpcio_tests/.yandex_meta/licenses.list.txt @@ -61,6 +61,10 @@ ====================COPYRIGHT==================== +# Copyright 2021 The gRPC authors. + + +====================COPYRIGHT==================== // Copyright 2018 The gRPC Authors @@ -70,3 +74,7 @@ ====================COPYRIGHT==================== // Copyright 2020 The gRPC Authors + + +====================COPYRIGHT==================== +// Copyright 2021 The gRPC Authors diff --git a/contrib/libs/grpc/src/python/grpcio_tests/grpc_version.py b/contrib/libs/grpc/src/python/grpcio_tests/grpc_version.py index 219b336a42..69d40de2a5 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/grpc_version.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_tests/grpc_version.py.template`!!! -VERSION = '1.33.2' +VERSION = '1.37.1' diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/_runner.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/_runner.py index 39da0399b0..92546fca49 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/_runner.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/_runner.py @@ -80,7 +80,7 @@ class CaptureFile(object): value (str): What to write to the original file. """ if six.PY3 and not isinstance(value, six.binary_type): - value = bytes(value, 'ascii') + value = value.encode('ascii') if self._saved_fd is None: os.write(self._redirect_fd, value) else: diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py index 784307ae00..a500897029 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py @@ -350,6 +350,15 @@ class ChannelzServicerTest(unittest.TestCase): self.assertEqual(gsc_resp.subchannel.data.calls_succeeded, gs_resp.socket.data.messages_received) + if gs_resp.socket.remote.HasField("tcpip_address"): + address = gs_resp.socket.remote.tcpip_address.ip_address + self.assertTrue( + len(address) == 4 or len(address) == 16, address) + if gs_resp.socket.local.HasField("tcpip_address"): + address = gs_resp.socket.local.tcpip_address.ip_address + self.assertTrue( + len(address) == 4 or len(address) == 16, address) + def test_streaming_rpc(self): self._pairs = _generate_channel_server_pairs(1) # In C++, the argument for _send_successful_stream_stream is message length. @@ -413,6 +422,7 @@ class ChannelzServicerTest(unittest.TestCase): gs_resp = self._channelz_stub.GetSocket( channelz_pb2.GetSocketRequest( socket_id=gss_resp.server[0].listen_socket[0].socket_id)) + # If the RPC call failed, it will raise a grpc.RpcError # So, if there is no exception raised, considered pass diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/fork/_fork_interop_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/fork/_fork_interop_test.py index e2eff257fa..a6fd5f8624 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/fork/_fork_interop_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/fork/_fork_interop_test.py @@ -16,13 +16,14 @@ import six import subprocess import sys +import tempfile import threading import unittest from grpc._cython import cygrpc from tests.fork import methods # New instance of multiprocessing.Process using fork without exec can and will -# hang if the Python process has any other threads running. This includes the +# freeze if the Python process has any other threads running. This includes the # additional thread spawned by our _runner.py class. So in order to test our # compatibility with multiprocessing, we first fork+exec a new process to ensure # we don't have any conflicting background threads. @@ -69,15 +70,23 @@ class ForkInteropTest(unittest.TestCase): while True: time.sleep(1) """ + streams = tuple(tempfile.TemporaryFile() for _ in range(2)) self._server_process = subprocess.Popen( [sys.executable, '-c', start_server_script], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stdout=streams[0], + stderr=streams[1]) timer = threading.Timer(_SUBPROCESS_TIMEOUT_S, self._server_process.kill) try: timer.start() - self._port = int(self._server_process.stdout.readline()) + while True: + streams[0].seek(0) + s = streams[0].readline() + if not s: + continue + else: + self._port = int(s) + break except ValueError: raise Exception('Failed to get port from server') finally: @@ -125,26 +134,22 @@ class ForkInteropTest(unittest.TestCase): def _verifyTestCase(self, test_case): script = _CLIENT_FORK_SCRIPT_TEMPLATE % (test_case.name, self._port) + streams = tuple(tempfile.TemporaryFile() for _ in range(2)) process = subprocess.Popen([sys.executable, '-c', script], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stdout=streams[0], + stderr=streams[1]) timer = threading.Timer(_SUBPROCESS_TIMEOUT_S, process.kill) - try: - timer.start() - try: - out, err = process.communicate(timeout=_SUBPROCESS_TIMEOUT_S) - except TypeError: - # The timeout parameter was added in Python 3.3. - out, err = process.communicate() - except subprocess.TimeoutExpired: - process.kill() - raise RuntimeError('Process failed to terminate') - finally: - timer.cancel() + timer.start() + process.wait() + timer.cancel() + outputs = [] + for stream in streams: + stream.seek(0) + outputs.append(stream.read()) self.assertEqual( 0, process.returncode, - 'process failed with exit code %d (stdout: %s, stderr: %s)' % - (process.returncode, out, err)) + 'process failed with exit code %d (stdout: "%s", stderr: "%s")' % + (process.returncode, outputs[0], outputs[1])) if __name__ == '__main__': diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/fork/methods.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/fork/methods.py index 2123c69916..3ccebcf651 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/fork/methods.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/fork/methods.py @@ -142,7 +142,8 @@ class _ChildProcess(object): self._process.exitcode) try: exception = self._exceptions.get(block=False) - raise ValueError('Child process failed: %s' % exception) + raise ValueError('Child process failed: "%s": "%s"' % + (repr(exception), exception)) except queue.Empty: pass diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/benchmark_client.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/benchmark_client.py index 17835e7c0d..29cd35efb1 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/benchmark_client.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/benchmark_client.py @@ -34,6 +34,8 @@ class GenericStub(object): def __init__(self, channel): self.UnaryCall = channel.unary_unary( '/grpc.testing.BenchmarkService/UnaryCall') + self.StreamingFromServer = channel.unary_stream( + '/grpc.testing.BenchmarkService/StreamingFromServer') self.StreamingCall = channel.stream_stream( '/grpc.testing.BenchmarkService/StreamingCall') @@ -200,3 +202,43 @@ class StreamingSyncBenchmarkClient(BenchmarkClient): stream.stop() self._pool.shutdown(wait=True) self._stub = None + + +class ServerStreamingSyncBenchmarkClient(BenchmarkClient): + + def __init__(self, server, config, hist): + super(ServerStreamingSyncBenchmarkClient, + self).__init__(server, config, hist) + if config.outstanding_rpcs_per_channel == 1: + self._pool = None + else: + self._pool = futures.ThreadPoolExecutor( + max_workers=config.outstanding_rpcs_per_channel) + self._rpcs = [] + self._sender = None + + def send_request(self): + if self._pool is None: + self._sender = threading.Thread( + target=self._one_stream_streaming_rpc, daemon=True) + self._sender.start() + else: + self._pool.submit(self._one_stream_streaming_rpc) + + def _one_stream_streaming_rpc(self): + response_stream = self._stub.StreamingFromServer( + self._request, _TIMEOUT) + self._rpcs.append(response_stream) + start_time = time.time() + for _ in response_stream: + self._handle_response(self, time.time() - start_time) + start_time = time.time() + + def stop(self): + for call in self._rpcs: + call.cancel() + if self._sender is not None: + self._sender.join() + if self._pool is not None: + self._pool.shutdown(wait=False) + self._stub = None diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/client_runner.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/client_runner.py index c5d299f646..a03174472c 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/client_runner.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/client_runner.py @@ -67,12 +67,15 @@ class OpenLoopClientRunner(ClientRunner): class ClosedLoopClientRunner(ClientRunner): - def __init__(self, client, request_count): + def __init__(self, client, request_count, no_ping_pong): super(ClosedLoopClientRunner, self).__init__(client) self._is_running = False self._request_count = request_count - # Send a new request on each response for closed loop - self._client.add_response_callback(self._send_request) + # For server-streaming RPC, don't spawn new RPC after each responses. + # This yield at most ~17% for single RPC scenarios. + if not no_ping_pong: + # Send a new request on each response for closed loop + self._client.add_response_callback(self._send_request) def start(self): self._is_running = True @@ -85,6 +88,6 @@ class ClosedLoopClientRunner(ClientRunner): self._client.stop() self._client = None - def _send_request(self, client, response_time): + def _send_request(self, client, unused_response_time): if self._is_running: client.send_request() diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/qps_worker.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/qps_worker.py index a7e692821a..de8eefbd7f 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/qps_worker.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/qps_worker.py @@ -14,6 +14,7 @@ """The entry point for the qps worker.""" import argparse +import logging import time import grpc @@ -23,24 +24,33 @@ from tests.qps import worker_server from tests.unit import test_common -def run_worker_server(port): +def run_worker_server(driver_port, server_port): server = test_common.test_server() - servicer = worker_server.WorkerServer() + servicer = worker_server.WorkerServer(server_port) worker_service_pb2_grpc.add_WorkerServiceServicer_to_server( servicer, server) - server.add_insecure_port('[::]:{}'.format(port)) + server.add_insecure_port('[::]:{}'.format(driver_port)) server.start() servicer.wait_for_quit() server.stop(0) if __name__ == '__main__': + logging.basicConfig(level=logging.DEBUG) parser = argparse.ArgumentParser( description='gRPC Python performance testing worker') - parser.add_argument('--driver_port', - type=int, - dest='port', - help='The port the worker should listen on') + parser.add_argument( + '--driver_port', + type=int, + dest='driver_port', + help='The port for the worker to expose for driver communication') + parser.add_argument( + '--server_port', + type=int, + default=None, + dest='server_port', + help='The port for the server if not specified by server config message' + ) args = parser.parse_args() - run_worker_server(args.port) + run_worker_server(args.driver_port, args.server_port) diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/worker_server.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/worker_server.py index 65b081e5d1..327b8e3b4c 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/worker_server.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/qps/worker_server.py @@ -35,8 +35,9 @@ from tests.unit import test_common class WorkerServer(worker_service_pb2_grpc.WorkerServiceServicer): """Python Worker Server implementation.""" - def __init__(self): + def __init__(self, server_port=None): self._quit_event = threading.Event() + self._server_port = server_port def RunServer(self, request_iterator, context): config = next(request_iterator).setup #pylint: disable=stop-iteration-return @@ -91,13 +92,18 @@ class WorkerServer(worker_service_pb2_grpc.WorkerServiceServicer): raise Exception('Unsupported server type {}'.format( config.server_type)) + if self._server_port is not None and config.port == 0: + server_port = self._server_port + else: + server_port = config.port + if config.HasField('security_params'): # Use SSL server_creds = grpc.ssl_server_credentials( ((resources.private_key(), resources.certificate_chain()),)) - port = server.add_secure_port('[::]:{}'.format(config.port), + port = server.add_secure_port('[::]:{}'.format(server_port), server_creds) else: - port = server.add_insecure_port('[::]:{}'.format(config.port)) + port = server.add_insecure_port('[::]:{}'.format(server_port)) return (server, port) @@ -142,6 +148,7 @@ class WorkerServer(worker_service_pb2_grpc.WorkerServiceServicer): return control_pb2.ClientStatus(stats=stats) def _create_client_runner(self, server, config, qps_data): + no_ping_pong = False if config.client_type == control_pb2.SYNC_CLIENT: if config.rpc_type == control_pb2.UNARY: client = benchmark_client.UnarySyncBenchmarkClient( @@ -149,6 +156,10 @@ class WorkerServer(worker_service_pb2_grpc.WorkerServiceServicer): elif config.rpc_type == control_pb2.STREAMING: client = benchmark_client.StreamingSyncBenchmarkClient( server, config, qps_data) + elif config.rpc_type == control_pb2.STREAMING_FROM_SERVER: + no_ping_pong = True + client = benchmark_client.ServerStreamingSyncBenchmarkClient( + server, config, qps_data) elif config.client_type == control_pb2.ASYNC_CLIENT: if config.rpc_type == control_pb2.UNARY: client = benchmark_client.UnaryAsyncBenchmarkClient( @@ -163,7 +174,7 @@ class WorkerServer(worker_service_pb2_grpc.WorkerServiceServicer): load_factor = float(config.client_channels) if config.load_params.WhichOneof('load') == 'closed_loop': runner = client_runner.ClosedLoopClientRunner( - client, config.outstanding_rpcs_per_channel) + client, config.outstanding_rpcs_per_channel, no_ping_pong) else: # Open loop Poisson alpha = config.load_params.poisson.offered_load / load_factor diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_api_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_api_test.py index a459ee6e19..e98632d0d2 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_api_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_api_test.py @@ -87,6 +87,9 @@ class AllTest(unittest.TestCase): 'protos', 'services', 'protos_and_services', + 'xds_channel_credentials', + 'xds_server_credentials', + 'insecure_server_credentials', ) six.assertCountEqual(self, expected_grpc_code_elements, diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_cancel_many_calls_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_cancel_many_calls_test.py index b279f3d07c..c84dff614a 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_cancel_many_calls_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_cancel_many_calls_test.py @@ -144,12 +144,10 @@ class CancelManyCallsTest(unittest.TestCase): test_constants.THREAD_CONCURRENCY) server_completion_queue = cygrpc.CompletionQueue() - server = cygrpc.Server([ - ( - b'grpc.so_reuseport', - 0, - ), - ]) + server = cygrpc.Server([( + b'grpc.so_reuseport', + 0, + )], False) server.register_completion_queue(server_completion_queue) port = server.add_http2_port(b'[::]:0') server.start() diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_common.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_common.py index d8210f36f8..42ec655fee 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_common.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_common.py @@ -96,7 +96,7 @@ class RpcTest(object): def setUp(self): self.server_completion_queue = cygrpc.CompletionQueue() - self.server = cygrpc.Server([(b'grpc.so_reuseport', 0)]) + self.server = cygrpc.Server([(b'grpc.so_reuseport', 0)], False) self.server.register_completion_queue(self.server_completion_queue) port = self.server.add_http2_port(b'[::]:0') self.server.start() diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_read_some_but_not_all_responses_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_read_some_but_not_all_responses_test.py index 8a903bfaf9..4aad924427 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_read_some_but_not_all_responses_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_read_some_but_not_all_responses_test.py @@ -115,7 +115,7 @@ class ReadSomeButNotAllResponsesTest(unittest.TestCase): server = cygrpc.Server([( b'grpc.so_reuseport', 0, - )]) + )], False) server.register_completion_queue(server_completion_queue) port = server.add_http2_port(b'[::]:0') server.start() diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_server_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_server_test.py index bbd25457b3..60b068243c 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_server_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/_server_test.py @@ -25,7 +25,7 @@ class Test(unittest.TestCase): def test_lonely_server(self): server_call_completion_queue = cygrpc.CompletionQueue() server_shutdown_completion_queue = cygrpc.CompletionQueue() - server = cygrpc.Server(None) + server = cygrpc.Server(None, False) server.register_completion_queue(server_call_completion_queue) server.register_completion_queue(server_shutdown_completion_queue) port = server.add_http2_port(b'[::]:0') diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py index 1182f83a42..30cd5078ff 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py @@ -42,12 +42,10 @@ class TypeSmokeTest(unittest.TestCase): del completion_queue def testServerUpDown(self): - server = cygrpc.Server(set([ - ( - b'grpc.so_reuseport', - 0, - ), - ])) + server = cygrpc.Server(set([( + b'grpc.so_reuseport', + 0, + )]), False) del server def testChannelUpDown(self): @@ -59,12 +57,10 @@ class TypeSmokeTest(unittest.TestCase): b'test plugin name!') def testServerStartNoExplicitShutdown(self): - server = cygrpc.Server([ - ( - b'grpc.so_reuseport', - 0, - ), - ]) + server = cygrpc.Server([( + b'grpc.so_reuseport', + 0, + )], False) completion_queue = cygrpc.CompletionQueue() server.register_completion_queue(completion_queue) port = server.add_http2_port(b'[::]:0') @@ -79,7 +75,7 @@ class TypeSmokeTest(unittest.TestCase): b'grpc.so_reuseport', 0, ), - ]) + ], False) server.add_http2_port(b'[::]:0') server.register_completion_queue(completion_queue) server.start() @@ -97,12 +93,10 @@ class ServerClientMixin(object): def setUpMixin(self, server_credentials, client_credentials, host_override): self.server_completion_queue = cygrpc.CompletionQueue() - self.server = cygrpc.Server([ - ( - b'grpc.so_reuseport', - 0, - ), - ]) + self.server = cygrpc.Server([( + b'grpc.so_reuseport', + 0, + )], False) self.server.register_completion_queue(self.server_completion_queue) if server_credentials: self.port = self.server.add_http2_port(b'[::]:0', diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_dynamic_stubs_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_dynamic_stubs_test.py index d2d8ce9f60..5d4819dd17 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_dynamic_stubs_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_dynamic_stubs_test.py @@ -21,6 +21,8 @@ import os import sys import unittest +_DATA_DIR = os.path.join("tests", "unit", "data") + @contextlib.contextmanager def _grpc_tools_unimportable(): @@ -53,6 +55,18 @@ def _collect_errors(fn): return _wrapped +def _python3_check(fn): + + @functools.wraps(fn) + def _wrapped(): + if sys.version_info[0] == 3: + fn() + else: + _assert_unimplemented("Python 3") + + return _wrapped + + def _run_in_subprocess(test_case): sys.path.insert( 0, os.path.join(os.path.realpath(os.path.dirname(__file__)), "..")) @@ -80,24 +94,30 @@ def _assert_unimplemented(msg_substr): @_collect_errors +@_python3_check def _test_sunny_day(): - if sys.version_info[0] == 3: - import grpc - protos, services = grpc.protos_and_services( - os.path.join("tests", "unit", "data", "foo", "bar.proto")) - assert protos.BarMessage is not None - assert services.BarStub is not None - else: - _assert_unimplemented("Python 3") + import grpc + protos, services = grpc.protos_and_services( + os.path.join(_DATA_DIR, "foo", "bar.proto")) + assert protos.BarMessage is not None + assert services.BarStub is not None + + +@_collect_errors +@_python3_check +def _test_well_known_types(): + import grpc + protos, services = grpc.protos_and_services( + os.path.join(_DATA_DIR, "foo", "bar_with_wkt.proto")) + assert protos.BarMessage is not None + assert services.BarStub is not None @_collect_errors +@_python3_check def _test_grpc_tools_unimportable(): with _grpc_tools_unimportable(): - if sys.version_info[0] == 3: - _assert_unimplemented("grpcio-tools") - else: - _assert_unimplemented("Python 3") + _assert_unimplemented("grpcio-tools") # NOTE(rbellevi): multiprocessing.Process fails to pickle function objects @@ -110,6 +130,10 @@ class DynamicStubTest(unittest.TestCase): def test_sunny_day(self): _run_in_subprocess(_test_sunny_day) + @unittest.skip('grpcio-tools package required') + def test_well_known_types(self): + _run_in_subprocess(_test_well_known_types) + def test_grpc_tools_unimportable(self): _run_in_subprocess(_test_grpc_tools_unimportable) diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_exit_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_exit_test.py index 4cf5ab63bd..190b289fa9 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_exit_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_exit_test.py @@ -14,7 +14,7 @@ """Tests clean exit of server/client on Python Interpreter exit/sigint. The tests in this module spawn a subprocess for each test case, the -test is considered successful if it doesn't hang/timeout. +test is considered successful if it doesn't freeze/timeout. """ import atexit diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_metadata_flags_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_metadata_flags_test.py index e2b36b1c70..0dafc9e982 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_metadata_flags_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_metadata_flags_test.py @@ -100,8 +100,8 @@ class _GenericHandler(grpc.GenericRpcHandler): return None -def create_dummy_channel(): - """Creating dummy channels is a workaround for retries""" +def create_phony_channel(): + """Creating phony channels is a workaround for retries""" host, port, sock = get_socket(sock_options=(socket.SO_REUSEADDR,)) sock.close() return grpc.insecure_channel('{}:{}'.format(host, port)) @@ -188,12 +188,12 @@ class MetadataFlagsTest(unittest.TestCase): def test_call_wait_for_ready_default(self): for perform_call in _ALL_CALL_CASES: - with create_dummy_channel() as channel: + with create_phony_channel() as channel: self.check_connection_does_failfast(perform_call, channel) def test_call_wait_for_ready_disabled(self): for perform_call in _ALL_CALL_CASES: - with create_dummy_channel() as channel: + with create_phony_channel() as channel: self.check_connection_does_failfast(perform_call, channel, wait_for_ready=False) diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_server_shutdown_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_server_shutdown_test.py index c1dc7585f8..1d203f63b3 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_server_shutdown_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_server_shutdown_test.py @@ -14,7 +14,7 @@ """Tests clean shutdown of server on various interpreter exit conditions. The tests in this module spawn a subprocess for each test case, the -test is considered successful if it doesn't hang/timeout. +test is considered successful if it doesn't freeze/timeout. """ import atexit diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_signal_client.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_signal_client.py index 0be1270749..5cc68831f7 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_signal_client.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_signal_client.py @@ -82,7 +82,7 @@ def main_unary_with_exception(server_target): sys.stderr.write("Running signal handler.\n") sys.stderr.flush() - # This call should not hang. + # This call should not freeze. channel.close() @@ -97,7 +97,7 @@ def main_streaming_with_exception(server_target): sys.stderr.write("Running signal handler.\n") sys.stderr.flush() - # This call should not hang. + # This call should not freeze. channel.close() diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_xds_credentials_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_xds_credentials_test.py new file mode 100644 index 0000000000..91d30c68ad --- /dev/null +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/_xds_credentials_test.py @@ -0,0 +1,103 @@ +# Copyright 2021 The gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Tests xDS server and channel credentials.""" + +import unittest + +import logging +from concurrent import futures +import contextlib + +import grpc +import grpc.experimental +from tests.unit import test_common +from tests.unit import resources + + +class _GenericHandler(grpc.GenericRpcHandler): + + def service(self, handler_call_details): + return grpc.unary_unary_rpc_method_handler( + lambda request, unused_context: request) + + +@contextlib.contextmanager +def xds_channel_server_without_xds(server_fallback_creds): + server = grpc.server(futures.ThreadPoolExecutor()) + server.add_generic_rpc_handlers((_GenericHandler(),)) + server_server_fallback_creds = grpc.ssl_server_credentials( + ((resources.private_key(), resources.certificate_chain()),)) + server_creds = grpc.xds_server_credentials(server_fallback_creds) + port = server.add_secure_port("localhost:0", server_creds) + server.start() + try: + yield "localhost:{}".format(port) + finally: + server.stop(None) + + +class XdsCredentialsTest(unittest.TestCase): + + def test_xds_creds_fallback_ssl(self): + # Since there is no xDS server, the fallback credentials will be used. + # In this case, SSL credentials. + server_fallback_creds = grpc.ssl_server_credentials( + ((resources.private_key(), resources.certificate_chain()),)) + with xds_channel_server_without_xds( + server_fallback_creds) as server_address: + override_options = (("grpc.ssl_target_name_override", + "foo.test.google.fr"),) + channel_fallback_creds = grpc.ssl_channel_credentials( + root_certificates=resources.test_root_certificates(), + private_key=resources.private_key(), + certificate_chain=resources.certificate_chain()) + channel_creds = grpc.xds_channel_credentials(channel_fallback_creds) + with grpc.secure_channel(server_address, + channel_creds, + options=override_options) as channel: + request = b"abc" + response = channel.unary_unary("/test/method")( + request, wait_for_ready=True) + self.assertEqual(response, request) + + def test_xds_creds_fallback_insecure(self): + # Since there is no xDS server, the fallback credentials will be used. + # In this case, insecure. + server_fallback_creds = grpc.insecure_server_credentials() + with xds_channel_server_without_xds( + server_fallback_creds) as server_address: + channel_fallback_creds = grpc.experimental.insecure_channel_credentials( + ) + channel_creds = grpc.xds_channel_credentials(channel_fallback_creds) + with grpc.secure_channel(server_address, channel_creds) as channel: + request = b"abc" + response = channel.unary_unary("/test/method")( + request, wait_for_ready=True) + self.assertEqual(response, request) + + def test_start_xds_server(self): + server = grpc.server(futures.ThreadPoolExecutor(), xds=True) + server.add_generic_rpc_handlers((_GenericHandler(),)) + server_fallback_creds = grpc.insecure_server_credentials() + server_creds = grpc.xds_server_credentials(server_fallback_creds) + port = server.add_secure_port("localhost:0", server_creds) + server.start() + server.stop(None) + # No exceptions thrown. A more comprehensive suite of tests will be + # provided by the interop tests. + + +if __name__ == "__main__": + logging.basicConfig() + unittest.main() diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/framework/common/test_control.py b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/framework/common/test_control.py index 6a422825cc..999cb5f229 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/framework/common/test_control.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests/unit/framework/common/test_control.py @@ -34,7 +34,7 @@ class Control(six.with_metaclass(abc.ABCMeta)): Systems under test passed a Control should call its control() method frequently during execution. The control() method may block, raise an exception, or do nothing, all according to the enclosing test's desire for - the system under test to simulate hanging, failing, or functioning. + the system under test to simulate freezing, failing, or functioning. """ @abc.abstractmethod diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/benchmark/benchmark_client.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/benchmark/benchmark_client.py index 51a046c20c..1f925ba3cd 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/benchmark/benchmark_client.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/benchmark/benchmark_client.py @@ -33,6 +33,8 @@ class GenericStub(object): def __init__(self, channel: aio.Channel): self.UnaryCall = channel.unary_unary( '/grpc.testing.BenchmarkService/UnaryCall') + self.StreamingFromServer = channel.unary_stream( + '/grpc.testing.BenchmarkService/StreamingFromServer') self.StreamingCall = channel.stream_stream( '/grpc.testing.BenchmarkService/StreamingCall') @@ -153,3 +155,32 @@ class StreamingAsyncBenchmarkClient(BenchmarkClient): self._running = False await self._stopped.wait() await super().stop() + + +class ServerStreamingAsyncBenchmarkClient(BenchmarkClient): + + def __init__(self, address: str, config: control_pb2.ClientConfig, + hist: histogram.Histogram): + super().__init__(address, config, hist) + self._running = None + self._stopped = asyncio.Event() + + async def _one_server_streaming_call(self): + call = self._stub.StreamingFromServer(self._request) + while self._running: + start_time = time.time() + await call.read() + self._record_query_time(time.time() - start_time) + + async def run(self): + await super().run() + self._running = True + senders = ( + self._one_server_streaming_call() for _ in range(self._concurrency)) + await asyncio.gather(*senders) + self._stopped.set() + + async def stop(self): + self._running = False + await self._stopped.wait() + await super().stop() diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/benchmark/worker_servicer.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/benchmark/worker_servicer.py index 4f80095cd2..1893bb9f19 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/benchmark/worker_servicer.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/benchmark/worker_servicer.py @@ -105,9 +105,9 @@ def _create_server(config: control_pb2.ServerConfig) -> Tuple[aio.Server, int]: return server, port -def _get_client_status(start_time: float, end_time: float, - qps_data: histogram.Histogram - ) -> control_pb2.ClientStatus: +def _get_client_status( + start_time: float, end_time: float, + qps_data: histogram.Histogram) -> control_pb2.ClientStatus: """Creates ClientStatus proto message.""" latencies = qps_data.get_data() end_time = time.monotonic() @@ -120,9 +120,9 @@ def _get_client_status(start_time: float, end_time: float, return control_pb2.ClientStatus(stats=stats) -def _create_client(server: str, config: control_pb2.ClientConfig, - qps_data: histogram.Histogram - ) -> benchmark_client.BenchmarkClient: +def _create_client( + server: str, config: control_pb2.ClientConfig, + qps_data: histogram.Histogram) -> benchmark_client.BenchmarkClient: """Creates a client object according to the ClientConfig.""" if config.load_params.WhichOneof('load') != 'closed_loop': raise NotImplementedError( @@ -133,6 +133,8 @@ def _create_client(server: str, config: control_pb2.ClientConfig, client_type = benchmark_client.UnaryAsyncBenchmarkClient elif config.rpc_type == control_pb2.STREAMING: client_type = benchmark_client.StreamingAsyncBenchmarkClient + elif config.rpc_type == control_pb2.STREAMING_FROM_SERVER: + client_type = benchmark_client.ServerStreamingAsyncBenchmarkClient else: raise NotImplementedError( f'Unsupported rpc_type [{config.rpc_type}]') @@ -213,8 +215,8 @@ class WorkerServicer(worker_service_pb2_grpc.WorkerServiceServicer): await self._run_single_server(config, request_iterator, context) else: # If server_processes > 1, offload to other processes. - sub_workers = await asyncio.gather(*( - _create_sub_worker() for _ in range(config.server_processes))) + sub_workers = await asyncio.gather( + *[_create_sub_worker() for _ in range(config.server_processes)]) calls = [worker.stub.RunServer() for worker in sub_workers] @@ -306,8 +308,8 @@ class WorkerServicer(worker_service_pb2_grpc.WorkerServiceServicer): await self._run_single_client(config, request_iterator, context) else: # If client_processes > 1, offload the work to other processes. - sub_workers = await asyncio.gather(*( - _create_sub_worker() for _ in range(config.client_processes))) + sub_workers = await asyncio.gather( + *[_create_sub_worker() for _ in range(config.client_processes)]) calls = [worker.stub.RunClient() for worker in sub_workers] diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/interop/methods.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/interop/methods.py index aa39976981..24681aa698 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/interop/methods.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/interop/methods.py @@ -60,10 +60,10 @@ async def _validate_status_code_and_details(call: aio.Call, await _expect_status_details(call, expected_details) -def _validate_payload_type_and_length( - response: Union[messages_pb2.SimpleResponse, messages_pb2. - StreamingOutputCallResponse], expected_type: Any, - expected_length: int) -> None: +def _validate_payload_type_and_length(response: Union[ + messages_pb2.SimpleResponse, messages_pb2.StreamingOutputCallResponse], + expected_type: Any, + expected_length: int) -> None: if response.payload.type is not expected_type: raise ValueError('expected payload type %s, got %s' % (expected_type, type(response.payload.type))) @@ -73,8 +73,8 @@ def _validate_payload_type_and_length( async def _large_unary_common_behavior( - stub: test_pb2_grpc.TestServiceStub, fill_username: bool, - fill_oauth_scope: bool, call_credentials: Optional[grpc.CallCredentials] + stub: test_pb2_grpc.TestServiceStub, fill_username: bool, + fill_oauth_scope: bool, call_credentials: Optional[grpc.CallCredentials] ) -> messages_pb2.SimpleResponse: size = 314159 request = messages_pb2.SimpleRequest( @@ -436,10 +436,10 @@ _TEST_CASE_IMPLEMENTATION_MAPPING = { } -async def test_interoperability(case: TestCase, - stub: test_pb2_grpc.TestServiceStub, - args: Optional[argparse.Namespace] = None - ) -> None: +async def test_interoperability( + case: TestCase, + stub: test_pb2_grpc.TestServiceStub, + args: Optional[argparse.Namespace] = None) -> None: method = _TEST_CASE_IMPLEMENTATION_MAPPING.get(case) if method is None: raise NotImplementedError(f'Test case "{case}" not implemented!') diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/_common.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/_common.py index 016280a152..11513a722c 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/_common.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/_common.py @@ -21,6 +21,8 @@ from grpc.aio._metadata import Metadata from tests.unit.framework.common import test_constants +ADHOC_METHOD = '/test/AdHoc' + def seen_metadata(expected: Metadata, actual: Metadata): return not bool(set(tuple(expected)) - set(tuple(actual))) @@ -97,3 +99,20 @@ class CountingResponseIterator: def __aiter__(self): return self._forward_responses() + + +class AdhocGenericHandler(grpc.GenericRpcHandler): + """A generic handler to plugin testing server methods on the fly.""" + _handler: grpc.RpcMethodHandler + + def __init__(self): + self._handler = None + + def set_adhoc_handler(self, handler: grpc.RpcMethodHandler): + self._handler = handler + + def service(self, handler_call_details): + if handler_call_details.method == ADHOC_METHOD: + return self._handler + else: + return None diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/_test_server.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/_test_server.py index 5e5081a38d..ee137dedb6 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/_test_server.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/_test_server.py @@ -67,10 +67,13 @@ class TestServiceServicer(test_pb2_grpc.TestServiceServicer): await asyncio.sleep( datetime.timedelta(microseconds=response_parameters. interval_us).total_seconds()) - yield messages_pb2.StreamingOutputCallResponse( - payload=messages_pb2.Payload(type=request.response_type, - body=b'\x00' * - response_parameters.size)) + if response_parameters.size != 0: + yield messages_pb2.StreamingOutputCallResponse( + payload=messages_pb2.Payload(type=request.response_type, + body=b'\x00' * + response_parameters.size)) + else: + yield messages_pb2.StreamingOutputCallResponse() # Next methods are extra ones that are registred programatically # when the sever is instantiated. They are not being provided by @@ -96,10 +99,13 @@ class TestServiceServicer(test_pb2_grpc.TestServiceServicer): await asyncio.sleep( datetime.timedelta(microseconds=response_parameters. interval_us).total_seconds()) - yield messages_pb2.StreamingOutputCallResponse( - payload=messages_pb2.Payload(type=request.payload.type, - body=b'\x00' * - response_parameters.size)) + if response_parameters.size != 0: + yield messages_pb2.StreamingOutputCallResponse( + payload=messages_pb2.Payload(type=request.payload.type, + body=b'\x00' * + response_parameters.size)) + else: + yield messages_pb2.StreamingOutputCallResponse() def _create_extra_generic_handler(servicer: TestServiceServicer): diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/abort_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/abort_test.py index 828b6884df..487c8c972e 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/abort_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/abort_test.py @@ -33,7 +33,7 @@ _RESPONSE = b'\x01\x01\x01' _NUM_STREAM_RESPONSES = 5 _ABORT_CODE = grpc.StatusCode.RESOURCE_EXHAUSTED -_ABORT_DETAILS = 'Dummy error details' +_ABORT_DETAILS = 'Phony error details' class _GenericHandler(grpc.GenericRpcHandler): diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/call_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/call_test.py index 1961226fa6..c7d99a20c4 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/call_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/call_test.py @@ -472,6 +472,24 @@ class TestUnaryStreamCall(_MulticallableTestMixin, AioTestBase): self.assertEqual(grpc.StatusCode.OK, await call.code()) + async def test_empty_responses(self): + # Prepares the request + request = messages_pb2.StreamingOutputCallRequest() + for _ in range(_NUM_STREAM_RESPONSES): + request.response_parameters.append( + messages_pb2.ResponseParameters()) + + # Invokes the actual RPC + call = self._stub.StreamingOutputCall(request) + + for _ in range(_NUM_STREAM_RESPONSES): + response = await call.read() + self.assertIs(type(response), + messages_pb2.StreamingOutputCallResponse) + self.assertEqual(b'', response.SerializeToString()) + + self.assertEqual(grpc.StatusCode.OK, await call.code()) + class TestStreamUnaryCall(_MulticallableTestMixin, AioTestBase): @@ -624,6 +642,10 @@ class TestStreamUnaryCall(_MulticallableTestMixin, AioTestBase): _STREAM_OUTPUT_REQUEST_ONE_RESPONSE = messages_pb2.StreamingOutputCallRequest() _STREAM_OUTPUT_REQUEST_ONE_RESPONSE.response_parameters.append( messages_pb2.ResponseParameters(size=_RESPONSE_PAYLOAD_SIZE)) +_STREAM_OUTPUT_REQUEST_ONE_EMPTY_RESPONSE = messages_pb2.StreamingOutputCallRequest( +) +_STREAM_OUTPUT_REQUEST_ONE_EMPTY_RESPONSE.response_parameters.append( + messages_pb2.ResponseParameters()) class TestStreamStreamCall(_MulticallableTestMixin, AioTestBase): @@ -808,6 +830,15 @@ class TestStreamStreamCall(_MulticallableTestMixin, AioTestBase): self.assertEqual(await call.code(), grpc.StatusCode.OK) + async def test_empty_ping_pong(self): + call = self._stub.FullDuplexCall() + for _ in range(_NUM_STREAM_RESPONSES): + await call.write(_STREAM_OUTPUT_REQUEST_ONE_EMPTY_RESPONSE) + response = await call.read() + self.assertEqual(b'', response.SerializeToString()) + await call.done_writing() + self.assertEqual(await call.code(), grpc.StatusCode.OK) + if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/compatibility_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/compatibility_test.py index 0bb3a3acc8..e1f0f4d584 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/compatibility_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/compatibility_test.py @@ -35,29 +35,12 @@ _NUM_STREAM_RESPONSES = 5 _REQUEST_PAYLOAD_SIZE = 7 _RESPONSE_PAYLOAD_SIZE = 42 _REQUEST = b'\x03\x07' -_ADHOC_METHOD = '/test/AdHoc' def _unique_options() -> Sequence[Tuple[str, float]]: return (('iv', random.random()),) -class _AdhocGenericHandler(grpc.GenericRpcHandler): - _handler: grpc.RpcMethodHandler - - def __init__(self): - self._handler = None - - def set_adhoc_handler(self, handler: grpc.RpcMethodHandler): - self._handler = handler - - def service(self, handler_call_details): - if handler_call_details.method == _ADHOC_METHOD: - return self._handler - else: - return None - - @unittest.skipIf( os.environ.get('GRPC_ASYNCIO_ENGINE', '').lower() == 'custom_io_manager', 'Compatible mode needs POLLER completion queue.') @@ -70,7 +53,7 @@ class TestCompatibility(AioTestBase): test_pb2_grpc.add_TestServiceServicer_to_server(TestServiceServicer(), self._async_server) - self._adhoc_handlers = _AdhocGenericHandler() + self._adhoc_handlers = _common.AdhocGenericHandler() self._async_server.add_generic_rpc_handlers((self._adhoc_handlers,)) port = self._async_server.add_insecure_port('[::]:0') @@ -240,8 +223,8 @@ class TestCompatibility(AioTestBase): return request self._adhoc_handlers.set_adhoc_handler(echo_unary_unary) - response = await self._async_channel.unary_unary(_ADHOC_METHOD)(_REQUEST - ) + response = await self._async_channel.unary_unary(_common.ADHOC_METHOD + )(_REQUEST) self.assertEqual(_REQUEST, response) async def test_sync_unary_unary_metadata(self): @@ -253,7 +236,7 @@ class TestCompatibility(AioTestBase): return request self._adhoc_handlers.set_adhoc_handler(metadata_unary_unary) - call = self._async_channel.unary_unary(_ADHOC_METHOD)(_REQUEST) + call = self._async_channel.unary_unary(_common.ADHOC_METHOD)(_REQUEST) self.assertTrue( _common.seen_metadata(aio.Metadata(*metadata), await call.initial_metadata())) @@ -266,7 +249,8 @@ class TestCompatibility(AioTestBase): self._adhoc_handlers.set_adhoc_handler(abort_unary_unary) with self.assertRaises(aio.AioRpcError) as exception_context: - await self._async_channel.unary_unary(_ADHOC_METHOD)(_REQUEST) + await self._async_channel.unary_unary(_common.ADHOC_METHOD + )(_REQUEST) self.assertEqual(grpc.StatusCode.INTERNAL, exception_context.exception.code()) @@ -278,7 +262,8 @@ class TestCompatibility(AioTestBase): self._adhoc_handlers.set_adhoc_handler(set_code_unary_unary) with self.assertRaises(aio.AioRpcError) as exception_context: - await self._async_channel.unary_unary(_ADHOC_METHOD)(_REQUEST) + await self._async_channel.unary_unary(_common.ADHOC_METHOD + )(_REQUEST) self.assertEqual(grpc.StatusCode.INTERNAL, exception_context.exception.code()) @@ -290,7 +275,7 @@ class TestCompatibility(AioTestBase): yield request self._adhoc_handlers.set_adhoc_handler(echo_unary_stream) - call = self._async_channel.unary_stream(_ADHOC_METHOD)(_REQUEST) + call = self._async_channel.unary_stream(_common.ADHOC_METHOD)(_REQUEST) async for response in call: self.assertEqual(_REQUEST, response) @@ -303,7 +288,7 @@ class TestCompatibility(AioTestBase): raise RuntimeError('Test') self._adhoc_handlers.set_adhoc_handler(error_unary_stream) - call = self._async_channel.unary_stream(_ADHOC_METHOD)(_REQUEST) + call = self._async_channel.unary_stream(_common.ADHOC_METHOD)(_REQUEST) with self.assertRaises(aio.AioRpcError) as exception_context: async for response in call: self.assertEqual(_REQUEST, response) @@ -320,8 +305,8 @@ class TestCompatibility(AioTestBase): self._adhoc_handlers.set_adhoc_handler(echo_stream_unary) request_iterator = iter([_REQUEST] * _NUM_STREAM_RESPONSES) - response = await self._async_channel.stream_unary(_ADHOC_METHOD)( - request_iterator) + response = await self._async_channel.stream_unary(_common.ADHOC_METHOD + )(request_iterator) self.assertEqual(_REQUEST, response) async def test_sync_stream_unary_error(self): @@ -335,8 +320,8 @@ class TestCompatibility(AioTestBase): self._adhoc_handlers.set_adhoc_handler(echo_stream_unary) request_iterator = iter([_REQUEST] * _NUM_STREAM_RESPONSES) with self.assertRaises(aio.AioRpcError) as exception_context: - response = await self._async_channel.stream_unary(_ADHOC_METHOD)( - request_iterator) + response = await self._async_channel.stream_unary( + _common.ADHOC_METHOD)(request_iterator) self.assertEqual(grpc.StatusCode.UNKNOWN, exception_context.exception.code()) @@ -350,8 +335,8 @@ class TestCompatibility(AioTestBase): self._adhoc_handlers.set_adhoc_handler(echo_stream_stream) request_iterator = iter([_REQUEST] * _NUM_STREAM_RESPONSES) - call = self._async_channel.stream_stream(_ADHOC_METHOD)( - request_iterator) + call = self._async_channel.stream_stream( + _common.ADHOC_METHOD)(request_iterator) async for response in call: self.assertEqual(_REQUEST, response) @@ -366,8 +351,8 @@ class TestCompatibility(AioTestBase): self._adhoc_handlers.set_adhoc_handler(echo_stream_stream) request_iterator = iter([_REQUEST] * _NUM_STREAM_RESPONSES) - call = self._async_channel.stream_stream(_ADHOC_METHOD)( - request_iterator) + call = self._async_channel.stream_stream( + _common.ADHOC_METHOD)(request_iterator) with self.assertRaises(aio.AioRpcError) as exception_context: async for response in call: self.assertEqual(_REQUEST, response) diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/init_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/init_test.py index b9183a22c7..b7889b9942 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/init_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/init_test.py @@ -19,12 +19,12 @@ class TestInit(unittest.TestCase): def test_grpc(self): import grpc # pylint: disable=wrong-import-position - channel = grpc.aio.insecure_channel('dummy') + channel = grpc.aio.insecure_channel('phony') self.assertIsInstance(channel, grpc.aio.Channel) def test_grpc_dot_aio(self): import grpc.aio # pylint: disable=wrong-import-position - channel = grpc.aio.insecure_channel('dummy') + channel = grpc.aio.insecure_channel('phony') self.assertIsInstance(channel, grpc.aio.Channel) diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/server_interceptor_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/server_interceptor_test.py index d891ecdb77..8eb846201a 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/server_interceptor_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/server_interceptor_test.py @@ -38,8 +38,8 @@ class _LoggingInterceptor(aio.ServerInterceptor): self.record = record async def intercept_service( - self, continuation: Callable[[grpc.HandlerCallDetails], Awaitable[ - grpc.RpcMethodHandler]], + self, continuation: Callable[[grpc.HandlerCallDetails], + Awaitable[grpc.RpcMethodHandler]], handler_call_details: grpc.HandlerCallDetails ) -> grpc.RpcMethodHandler: self.record.append(self.tag + ':intercept_service') @@ -48,28 +48,29 @@ class _LoggingInterceptor(aio.ServerInterceptor): class _GenericInterceptor(aio.ServerInterceptor): - def __init__(self, fn: Callable[[ - Callable[[grpc.HandlerCallDetails], Awaitable[grpc. - RpcMethodHandler]], - grpc.HandlerCallDetails - ], Any]) -> None: + def __init__( + self, fn: Callable[[ + Callable[[grpc.HandlerCallDetails], + Awaitable[grpc.RpcMethodHandler]], grpc.HandlerCallDetails + ], Any] + ) -> None: self._fn = fn async def intercept_service( - self, continuation: Callable[[grpc.HandlerCallDetails], Awaitable[ - grpc.RpcMethodHandler]], + self, continuation: Callable[[grpc.HandlerCallDetails], + Awaitable[grpc.RpcMethodHandler]], handler_call_details: grpc.HandlerCallDetails ) -> grpc.RpcMethodHandler: return await self._fn(continuation, handler_call_details) -def _filter_server_interceptor(condition: Callable, - interceptor: aio.ServerInterceptor - ) -> aio.ServerInterceptor: +def _filter_server_interceptor( + condition: Callable, + interceptor: aio.ServerInterceptor) -> aio.ServerInterceptor: async def intercept_service( - continuation: Callable[[grpc.HandlerCallDetails], Awaitable[ - grpc.RpcMethodHandler]], + continuation: Callable[[grpc.HandlerCallDetails], + Awaitable[grpc.RpcMethodHandler]], handler_call_details: grpc.HandlerCallDetails ) -> grpc.RpcMethodHandler: if condition(handler_call_details): @@ -87,8 +88,8 @@ class _CacheInterceptor(aio.ServerInterceptor): self.cache_store = cache_store or {} async def intercept_service( - self, continuation: Callable[[grpc.HandlerCallDetails], Awaitable[ - grpc.RpcMethodHandler]], + self, continuation: Callable[[grpc.HandlerCallDetails], + Awaitable[grpc.RpcMethodHandler]], handler_call_details: grpc.HandlerCallDetails ) -> grpc.RpcMethodHandler: # Get the actual handler @@ -100,13 +101,14 @@ class _CacheInterceptor(aio.ServerInterceptor): return handler def wrapper(behavior: Callable[ - [messages_pb2.SimpleRequest, aio. - ServicerContext], messages_pb2.SimpleResponse]): + [messages_pb2.SimpleRequest, aio.ServicerContext], + messages_pb2.SimpleResponse]): @functools.wraps(behavior) - async def wrapper(request: messages_pb2.SimpleRequest, - context: aio.ServicerContext - ) -> messages_pb2.SimpleResponse: + async def wrapper( + request: messages_pb2.SimpleRequest, + context: aio.ServicerContext + ) -> messages_pb2.SimpleResponse: if request.response_size not in self.cache_store: self.cache_store[request.response_size] = await behavior( request, context) @@ -118,7 +120,7 @@ class _CacheInterceptor(aio.ServerInterceptor): async def _create_server_stub_pair( - *interceptors: aio.ServerInterceptor + *interceptors: aio.ServerInterceptor ) -> Tuple[aio.Server, test_pb2_grpc.TestServiceStub]: """Creates a server-stub pair with given interceptors. diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/server_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/server_test.py index 61d1edd523..8ba3ce1901 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/server_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/server_test.py @@ -47,6 +47,7 @@ _REQUEST = b'\x00\x00\x00' _RESPONSE = b'\x01\x01\x01' _NUM_STREAM_REQUESTS = 3 _NUM_STREAM_RESPONSES = 5 +_MAXIMUM_CONCURRENT_RPCS = 5 class _GenericHandler(grpc.GenericRpcHandler): @@ -189,7 +190,8 @@ class _GenericHandler(grpc.GenericRpcHandler): context.set_code(grpc.StatusCode.INTERNAL) def service(self, handler_details): - self._called.set_result(None) + if not self._called.done(): + self._called.set_result(None) return self._routing_table.get(handler_details.method) async def wait_for_call(self): @@ -480,6 +482,30 @@ class TestServer(AioTestBase): with self.assertRaises(RuntimeError): server.add_secure_port(bind_address, server_credentials) + async def test_maximum_concurrent_rpcs(self): + # Build the server with concurrent rpc argument + server = aio.server(maximum_concurrent_rpcs=_MAXIMUM_CONCURRENT_RPCS) + port = server.add_insecure_port('localhost:0') + bind_address = "localhost:%d" % port + server.add_generic_rpc_handlers((_GenericHandler(),)) + await server.start() + # Build the channel + channel = aio.insecure_channel(bind_address) + # Deplete the concurrent quota with 3 times of max RPCs + rpcs = [] + for _ in range(3 * _MAXIMUM_CONCURRENT_RPCS): + rpcs.append(channel.unary_unary(_BLOCK_BRIEFLY)(_REQUEST)) + task = self.loop.create_task( + asyncio.wait(rpcs, return_when=asyncio.FIRST_EXCEPTION)) + # Each batch took test_constants.SHORT_TIMEOUT /2 + start_time = time.time() + await task + elapsed_time = time.time() - start_time + self.assertGreater(elapsed_time, test_constants.SHORT_TIMEOUT * 3 / 2) + # Clean-up + await channel.close() + await server.stop(0) + if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/server_time_remaining_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/server_time_remaining_test.py new file mode 100644 index 0000000000..0de87b532f --- /dev/null +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/server_time_remaining_test.py @@ -0,0 +1,70 @@ +# Copyright 2021 The gRPC Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Test the time_remaining() method of async ServicerContext.""" + +import asyncio +import logging +import unittest +import datetime + +import grpc +from grpc import aio + +from tests_aio.unit._common import ADHOC_METHOD, AdhocGenericHandler +from tests_aio.unit._test_base import AioTestBase + +_REQUEST = b'\x09\x05' +_REQUEST_TIMEOUT_S = datetime.timedelta(seconds=5).total_seconds() + + +class TestServerTimeRemaining(AioTestBase): + + async def setUp(self): + # Create async server + self._server = aio.server(options=(('grpc.so_reuseport', 0),)) + self._adhoc_handlers = AdhocGenericHandler() + self._server.add_generic_rpc_handlers((self._adhoc_handlers,)) + port = self._server.add_insecure_port('[::]:0') + address = 'localhost:%d' % port + await self._server.start() + # Create async channel + self._channel = aio.insecure_channel(address) + + async def tearDown(self): + await self._channel.close() + await self._server.stop(None) + + async def test_servicer_context_time_remaining(self): + seen_time_remaining = [] + + @grpc.unary_unary_rpc_method_handler + def log_time_remaining(request: bytes, + context: grpc.ServicerContext) -> bytes: + seen_time_remaining.append(context.time_remaining()) + return b"" + + # Check if the deadline propagates properly + self._adhoc_handlers.set_adhoc_handler(log_time_remaining) + await self._channel.unary_unary(ADHOC_METHOD)( + _REQUEST, timeout=_REQUEST_TIMEOUT_S) + self.assertGreater(seen_time_remaining[0], _REQUEST_TIMEOUT_S / 2) + # Check if there is no timeout, the time_remaining will be None + self._adhoc_handlers.set_adhoc_handler(log_time_remaining) + await self._channel.unary_unary(ADHOC_METHOD)(_REQUEST) + self.assertIsNone(seen_time_remaining[1]) + + +if __name__ == '__main__': + logging.basicConfig(level=logging.DEBUG) + unittest.main(verbosity=2) diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/wait_for_connection_test.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/wait_for_connection_test.py index cb6f798529..4fbe074740 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/wait_for_connection_test.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_aio/unit/wait_for_connection_test.py @@ -42,11 +42,11 @@ class TestWaitForConnection(AioTestBase): async def setUp(self): address, self._server = await start_test_server() self._channel = aio.insecure_channel(address) - self._dummy_channel = aio.insecure_channel(UNREACHABLE_TARGET) + self._phony_channel = aio.insecure_channel(UNREACHABLE_TARGET) self._stub = test_pb2_grpc.TestServiceStub(self._channel) async def tearDown(self): - await self._dummy_channel.close() + await self._phony_channel.close() await self._channel.close() await self._server.stop(None) @@ -122,7 +122,7 @@ class TestWaitForConnection(AioTestBase): self.assertEqual(grpc.StatusCode.OK, await call.code()) async def test_unary_unary_error(self): - call = self._dummy_channel.unary_unary(_TEST_METHOD)(_REQUEST) + call = self._phony_channel.unary_unary(_TEST_METHOD)(_REQUEST) with self.assertRaises(aio.AioRpcError) as exception_context: await call.wait_for_connection() @@ -130,7 +130,7 @@ class TestWaitForConnection(AioTestBase): self.assertEqual(grpc.StatusCode.UNAVAILABLE, rpc_error.code()) async def test_unary_stream_error(self): - call = self._dummy_channel.unary_stream(_TEST_METHOD)(_REQUEST) + call = self._phony_channel.unary_stream(_TEST_METHOD)(_REQUEST) with self.assertRaises(aio.AioRpcError) as exception_context: await call.wait_for_connection() @@ -138,7 +138,7 @@ class TestWaitForConnection(AioTestBase): self.assertEqual(grpc.StatusCode.UNAVAILABLE, rpc_error.code()) async def test_stream_unary_error(self): - call = self._dummy_channel.stream_unary(_TEST_METHOD)() + call = self._phony_channel.stream_unary(_TEST_METHOD)() with self.assertRaises(aio.AioRpcError) as exception_context: await call.wait_for_connection() @@ -146,7 +146,7 @@ class TestWaitForConnection(AioTestBase): self.assertEqual(grpc.StatusCode.UNAVAILABLE, rpc_error.code()) async def test_stream_stream_error(self): - call = self._dummy_channel.stream_stream(_TEST_METHOD)() + call = self._phony_channel.stream_stream(_TEST_METHOD)() with self.assertRaises(aio.AioRpcError) as exception_context: await call.wait_for_connection() diff --git a/contrib/libs/grpc/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_client.py b/contrib/libs/grpc/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_client.py index 21277a98cf..fa953e5ac0 100644 --- a/contrib/libs/grpc/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_client.py +++ b/contrib/libs/grpc/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_client.py @@ -13,6 +13,8 @@ # limitations under the License. import argparse +import collections +import datetime import logging import signal import threading @@ -42,8 +44,22 @@ _SUPPORTED_METHODS = ( "EmptyCall", ) +_METHOD_CAMEL_TO_CAPS_SNAKE = { + "UnaryCall": "UNARY_CALL", + "EmptyCall": "EMPTY_CALL", +} + +_METHOD_STR_TO_ENUM = { + "UnaryCall": messages_pb2.ClientConfigureRequest.UNARY_CALL, + "EmptyCall": messages_pb2.ClientConfigureRequest.EMPTY_CALL, +} + +_METHOD_ENUM_TO_STR = {v: k for k, v in _METHOD_STR_TO_ENUM.items()} + PerMethodMetadataType = Mapping[str, Sequence[Tuple[str, str]]] +_CONFIG_CHANGE_TIMEOUT = datetime.timedelta(milliseconds=500) + class _StatsWatcher: _start: int @@ -77,8 +93,8 @@ class _StatsWatcher: self._rpcs_needed -= 1 self._condition.notify() - def await_rpc_stats_response(self, timeout_sec: int - ) -> messages_pb2.LoadBalancerStatsResponse: + def await_rpc_stats_response( + self, timeout_sec: int) -> messages_pb2.LoadBalancerStatsResponse: """Blocks until a full response has been collected.""" with self._condition: self._condition.wait_for(lambda: not self._rpcs_needed, @@ -98,9 +114,16 @@ _stop_event = threading.Event() _global_rpc_id: int = 0 _watchers: Set[_StatsWatcher] = set() _global_server = None +_global_rpcs_started: Mapping[str, int] = collections.defaultdict(int) +_global_rpcs_succeeded: Mapping[str, int] = collections.defaultdict(int) +_global_rpcs_failed: Mapping[str, int] = collections.defaultdict(int) + +# Mapping[method, Mapping[status_code, count]] +_global_rpc_statuses: Mapping[str, Mapping[int, int]] = collections.defaultdict( + lambda: collections.defaultdict(int)) -def _handle_sigint(sig, frame): +def _handle_sigint(sig, frame) -> None: _stop_event.set() _global_server.stop(None) @@ -111,9 +134,10 @@ class _LoadBalancerStatsServicer(test_pb2_grpc.LoadBalancerStatsServiceServicer def __init__(self): super(_LoadBalancerStatsServicer).__init__() - def GetClientStats(self, request: messages_pb2.LoadBalancerStatsRequest, - context: grpc.ServicerContext - ) -> messages_pb2.LoadBalancerStatsResponse: + def GetClientStats( + self, request: messages_pb2.LoadBalancerStatsRequest, + context: grpc.ServicerContext + ) -> messages_pb2.LoadBalancerStatsResponse: logger.info("Received stats request.") start = None end = None @@ -126,15 +150,37 @@ class _LoadBalancerStatsServicer(test_pb2_grpc.LoadBalancerStatsServiceServicer response = watcher.await_rpc_stats_response(request.timeout_sec) with _global_lock: _watchers.remove(watcher) - logger.info("Returning stats response: {}".format(response)) + logger.info("Returning stats response: %s", response) + return response + + def GetClientAccumulatedStats( + self, request: messages_pb2.LoadBalancerAccumulatedStatsRequest, + context: grpc.ServicerContext + ) -> messages_pb2.LoadBalancerAccumulatedStatsResponse: + logger.info("Received cumulative stats request.") + response = messages_pb2.LoadBalancerAccumulatedStatsResponse() + with _global_lock: + for method in _SUPPORTED_METHODS: + caps_method = _METHOD_CAMEL_TO_CAPS_SNAKE[method] + response.num_rpcs_started_by_method[ + caps_method] = _global_rpcs_started[method] + response.num_rpcs_succeeded_by_method[ + caps_method] = _global_rpcs_succeeded[method] + response.num_rpcs_failed_by_method[ + caps_method] = _global_rpcs_failed[method] + response.stats_per_method[ + caps_method].rpcs_started = _global_rpcs_started[method] + for code, count in _global_rpc_statuses[method].items(): + response.stats_per_method[caps_method].result[code] = count + logger.info("Returning cumulative stats response.") return response def _start_rpc(method: str, metadata: Sequence[Tuple[str, str]], request_id: int, stub: test_pb2_grpc.TestServiceStub, - timeout: float, - futures: Mapping[int, Tuple[grpc.Future, str]]) -> None: - logger.info(f"Sending {method} request to backend: {request_id}") + timeout: float, futures: Mapping[int, Tuple[grpc.Future, + str]]) -> None: + logger.debug(f"Sending {method} request to backend: {request_id}") if method == "UnaryCall": future = stub.UnaryCall.future(messages_pb2.SimpleRequest(), metadata=metadata, @@ -152,7 +198,10 @@ def _on_rpc_done(rpc_id: int, future: grpc.Future, method: str, print_response: bool) -> None: exception = future.exception() hostname = "" + _global_rpc_statuses[method][future.code().value[0]] += 1 if exception is not None: + with _global_lock: + _global_rpcs_failed[method] += 1 if exception.code() == grpc.StatusCode.DEADLINE_EXCEEDED: logger.error(f"RPC {rpc_id} timed out") else: @@ -166,11 +215,17 @@ def _on_rpc_done(rpc_id: int, future: grpc.Future, method: str, break else: hostname = response.hostname + if future.code() == grpc.StatusCode.OK: + with _global_lock: + _global_rpcs_succeeded[method] += 1 + else: + with _global_lock: + _global_rpcs_failed[method] += 1 if print_response: if future.code() == grpc.StatusCode.OK: - logger.info("Successful response.") + logger.debug("Successful response.") else: - logger.info(f"RPC failed: {call}") + logger.debug(f"RPC failed: {call}") with _global_lock: for watcher in _watchers: watcher.on_rpc_complete(rpc_id, hostname, method) @@ -194,24 +249,55 @@ def _cancel_all_rpcs(futures: Mapping[int, Tuple[grpc.Future, str]]) -> None: future.cancel() -def _run_single_channel(method: str, metadata: Sequence[Tuple[str, str]], - qps: int, server: str, rpc_timeout_sec: int, - print_response: bool): +class _ChannelConfiguration: + """Configuration for a single client channel. + + Instances of this class are meant to be dealt with as PODs. That is, + data member should be accessed directly. This class is not thread-safe. + When accessing any of its members, the lock member should be held. + """ + + def __init__(self, method: str, metadata: Sequence[Tuple[str, + str]], qps: int, + server: str, rpc_timeout_sec: int, print_response: bool): + # condition is signalled when a change is made to the config. + self.condition = threading.Condition() + + self.method = method + self.metadata = metadata + self.qps = qps + self.server = server + self.rpc_timeout_sec = rpc_timeout_sec + self.print_response = print_response + + +def _run_single_channel(config: _ChannelConfiguration) -> None: global _global_rpc_id # pylint: disable=global-statement - duration_per_query = 1.0 / float(qps) + with config.condition: + server = config.server with grpc.insecure_channel(server) as channel: stub = test_pb2_grpc.TestServiceStub(channel) futures: Dict[int, Tuple[grpc.Future, str]] = {} while not _stop_event.is_set(): + with config.condition: + if config.qps == 0: + config.condition.wait( + timeout=_CONFIG_CHANGE_TIMEOUT.total_seconds()) + continue + else: + duration_per_query = 1.0 / float(config.qps) request_id = None with _global_lock: request_id = _global_rpc_id _global_rpc_id += 1 + _global_rpcs_started[config.method] += 1 start = time.time() end = start + duration_per_query - _start_rpc(method, metadata, request_id, stub, - float(rpc_timeout_sec), futures) - _remove_completed_rpcs(futures, print_response) + with config.condition: + _start_rpc(config.method, config.metadata, request_id, stub, + float(config.rpc_timeout_sec), futures) + with config.condition: + _remove_completed_rpcs(futures, config.print_response) logger.debug(f"Currently {len(futures)} in-flight RPCs") now = time.time() while now < end: @@ -220,30 +306,64 @@ def _run_single_channel(method: str, metadata: Sequence[Tuple[str, str]], _cancel_all_rpcs(futures) +class _XdsUpdateClientConfigureServicer( + test_pb2_grpc.XdsUpdateClientConfigureServiceServicer): + + def __init__(self, per_method_configs: Mapping[str, _ChannelConfiguration], + qps: int): + super(_XdsUpdateClientConfigureServicer).__init__() + self._per_method_configs = per_method_configs + self._qps = qps + + def Configure( + self, request: messages_pb2.ClientConfigureRequest, + context: grpc.ServicerContext + ) -> messages_pb2.ClientConfigureResponse: + logger.info("Received Configure RPC: %s", request) + method_strs = (_METHOD_ENUM_TO_STR[t] for t in request.types) + for method in _SUPPORTED_METHODS: + method_enum = _METHOD_STR_TO_ENUM[method] + channel_config = self._per_method_configs[method] + if method in method_strs: + qps = self._qps + metadata = ((md.key, md.value) + for md in request.metadata + if md.type == method_enum) + # For backward compatibility, do not change timeout when we + # receive a default value timeout. + if request.timeout_sec == 0: + timeout_sec = channel_config.rpc_timeout_sec + else: + timeout_sec = request.timeout_sec + else: + qps = 0 + metadata = () + # Leave timeout unchanged for backward compatibility. + timeout_sec = channel_config.rpc_timeout_sec + with channel_config.condition: + channel_config.qps = qps + channel_config.metadata = list(metadata) + channel_config.rpc_timeout_sec = timeout_sec + channel_config.condition.notify_all() + return messages_pb2.ClientConfigureResponse() + + class _MethodHandle: """An object grouping together threads driving RPCs for a method.""" _channel_threads: List[threading.Thread] - def __init__(self, method: str, metadata: Sequence[Tuple[str, str]], - num_channels: int, qps: int, server: str, rpc_timeout_sec: int, - print_response: bool): + def __init__(self, num_channels: int, + channel_config: _ChannelConfiguration): """Creates and starts a group of threads running the indicated method.""" self._channel_threads = [] for i in range(num_channels): thread = threading.Thread(target=_run_single_channel, - args=( - method, - metadata, - qps, - server, - rpc_timeout_sec, - print_response, - )) + args=(channel_config,)) thread.start() self._channel_threads.append(thread) - def stop(self): + def stop(self) -> None: """Joins all threads referenced by the handle.""" for channel_thread in self._channel_threads: channel_thread.join() @@ -254,15 +374,24 @@ def _run(args: argparse.Namespace, methods: Sequence[str], logger.info("Starting python xDS Interop Client.") global _global_server # pylint: disable=global-statement method_handles = [] - for method in methods: - method_handles.append( - _MethodHandle(method, per_method_metadata.get(method, []), - args.num_channels, args.qps, args.server, - args.rpc_timeout_sec, args.print_response)) + channel_configs = {} + for method in _SUPPORTED_METHODS: + if method in methods: + qps = args.qps + else: + qps = 0 + channel_config = _ChannelConfiguration( + method, per_method_metadata.get(method, []), qps, args.server, + args.rpc_timeout_sec, args.print_response) + channel_configs[method] = channel_config + method_handles.append(_MethodHandle(args.num_channels, channel_config)) _global_server = grpc.server(futures.ThreadPoolExecutor()) _global_server.add_insecure_port(f"0.0.0.0:{args.stats_port}") test_pb2_grpc.add_LoadBalancerStatsServiceServicer_to_server( _LoadBalancerStatsServicer(), _global_server) + test_pb2_grpc.add_XdsUpdateClientConfigureServiceServicer_to_server( + _XdsUpdateClientConfigureServicer(channel_configs, args.qps), + _global_server) _global_server.start() _global_server.wait_for_termination() for method_handle in method_handles: |