Пример #1
0
  def __init__(self, server, config, hist):
    # Create the stub
    host, port = server.split(':')
    port = int(port)
    if config.HasField('security_params'):
      creds = implementations.ssl_channel_credentials(
          resources.test_root_certificates())
      channel = test_utilities.not_really_secure_channel(
          host, port, creds, config.security_params.server_host_override)
    else:
      channel = implementations.insecure_channel(host, port)

    if config.payload_config.WhichOneof('payload') == 'simple_params':
      self._generic = False
      self._stub = services_pb2.beta_create_BenchmarkService_stub(channel)
      payload = messages_pb2.Payload(
          body='\0' * config.payload_config.simple_params.req_size)
      self._request = messages_pb2.SimpleRequest(
          payload=payload,
          response_size=config.payload_config.simple_params.resp_size)
    else:
      self._generic = True
      self._stub = implementations.generic_stub(channel)
      self._request = '\0' * config.payload_config.bytebuf_params.req_size

    self._hist = hist
    self._response_callbacks = []
Пример #2
0
  def __init__(self, server, config, hist):
    # Create the stub
    if config.HasField('security_params'):
      creds = grpc.ssl_channel_credentials(resources.test_root_certificates())
      channel = test_common.test_secure_channel(
        server, creds, config.security_params.server_host_override)
    else:
      channel = grpc.insecure_channel(server)

    connected_event = threading.Event()
    def wait_for_ready(connectivity):
      if connectivity == grpc.ChannelConnectivity.READY:
        connected_event.set()
    channel.subscribe(wait_for_ready, try_to_connect=True)
    connected_event.wait()

    if config.payload_config.WhichOneof('payload') == 'simple_params':
      self._generic = False
      self._stub = services_pb2.BenchmarkServiceStub(channel)
      payload = messages_pb2.Payload(
          body='\0' * config.payload_config.simple_params.req_size)
      self._request = messages_pb2.SimpleRequest(
          payload=payload,
          response_size=config.payload_config.simple_params.resp_size)
    else:
      self._generic = True
      self._stub = GenericStub(channel)
      self._request = '\0' * config.payload_config.bytebuf_params.req_size

    self._hist = hist
    self._response_callbacks = []
Пример #3
0
    def setUp(self):
        self._servicer = _Servicer()
        self._method_implementations = {
            (_GROUP, _UNARY_UNARY):
            utilities.unary_unary_inline(self._servicer.unary_unary),
            (_GROUP, _UNARY_STREAM):
            utilities.unary_stream_inline(self._servicer.unary_stream),
            (_GROUP, _STREAM_UNARY):
            utilities.stream_unary_inline(self._servicer.stream_unary),
            (_GROUP, _STREAM_STREAM):
            utilities.stream_stream_inline(self._servicer.stream_stream),
        }

        self._cardinalities = {
            _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY,
            _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM,
            _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY,
            _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM,
        }

        self._server_options = implementations.server_options(
            thread_pool_size=test_constants.POOL_SIZE)
        self._server_credentials = implementations.ssl_server_credentials([
            (
                resources.private_key(),
                resources.certificate_chain(),
            ),
        ])
        self._channel_credentials = implementations.ssl_channel_credentials(
            resources.test_root_certificates())
        self._stub_options = implementations.stub_options(
            thread_pool_size=test_constants.POOL_SIZE)
Пример #4
0
    def __init__(self, server, config, hist):
        # Create the stub
        if config.HasField('security_params'):
            creds = grpc.ssl_channel_credentials(
                resources.test_root_certificates())
            channel = test_common.test_secure_channel(
                server, creds, config.security_params.server_host_override)
        else:
            channel = grpc.insecure_channel(server)

        # waits for the channel to be ready before we start sending messages
        grpc.channel_ready_future(channel).result()

        if config.payload_config.WhichOneof('payload') == 'simple_params':
            self._generic = False
            self._stub = benchmark_service_pb2_grpc.BenchmarkServiceStub(
                channel)
            payload = messages_pb2.Payload(
                body=bytes(b'\0' *
                           config.payload_config.simple_params.req_size))
            self._request = messages_pb2.SimpleRequest(
                payload=payload,
                response_size=config.payload_config.simple_params.resp_size)
        else:
            self._generic = True
            self._stub = GenericStub(channel)
            self._request = bytes(b'\0' *
                                  config.payload_config.bytebuf_params.req_size)

        self._hist = hist
        self._response_callbacks = []
Пример #5
0
 def setUp(self):
   server_credentials = cygrpc.server_credentials_ssl(
       None, [cygrpc.SslPemKeyCertPair(resources.private_key(),
                                       resources.certificate_chain())], False)
   client_credentials = cygrpc.channel_credentials_ssl(
       resources.test_root_certificates(), None)
   self.setUpMixin(server_credentials, client_credentials, _SSL_HOST_OVERRIDE)
Пример #6
0
  def setUp(self):
    self._servicer = _Servicer()
    self._method_implementations = {
        (_GROUP, _UNARY_UNARY):
            utilities.unary_unary_inline(self._servicer.unary_unary),
        (_GROUP, _UNARY_STREAM):
            utilities.unary_stream_inline(self._servicer.unary_stream),
        (_GROUP, _STREAM_UNARY):
            utilities.stream_unary_inline(self._servicer.stream_unary),
        (_GROUP, _STREAM_STREAM):
            utilities.stream_stream_inline(self._servicer.stream_stream),
    }

    self._cardinalities = {
        _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY,
        _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM,
        _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY,
        _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM,
    }

    self._server_options = implementations.server_options(
        thread_pool_size=test_constants.POOL_SIZE)
    self._server_credentials = implementations.ssl_server_credentials(
        [(resources.private_key(), resources.certificate_chain(),),])
    self._client_credentials = implementations.ssl_client_credentials(
        resources.test_root_certificates(), None, None)
    self._stub_options = implementations.stub_options(
        thread_pool_size=test_constants.POOL_SIZE)
Пример #7
0
  def instantiate(
      self, methods, method_implementations, multi_method_implementation):
    serialization_behaviors = _serialization_behaviors_from_test_methods(
        methods)
    # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest.
    service = next(iter(methods))[0]
    # TODO(nathaniel): Add a "cardinalities_by_group" attribute to
    # _digest.TestServiceDigest.
    cardinalities = {
        method: method_object.cardinality()
        for (group, method), method_object in methods.iteritems()}

    server_options = implementations.server_options(
        request_deserializers=serialization_behaviors.request_deserializers,
        response_serializers=serialization_behaviors.response_serializers,
        thread_pool_size=test_constants.POOL_SIZE)
    server = implementations.server(
        method_implementations, options=server_options)
    server_credentials = implementations.ssl_server_credentials(
        [(resources.private_key(), resources.certificate_chain(),),])
    port = server.add_secure_port('[::]:0', server_credentials)
    server.start()
    channel_credentials = implementations.ssl_channel_credentials(
        resources.test_root_certificates(), None, None)
    channel = test_utilities.not_really_secure_channel(
        'localhost', port, channel_credentials, _SERVER_HOST_OVERRIDE)
    stub_options = implementations.stub_options(
        request_serializers=serialization_behaviors.request_serializers,
        response_deserializers=serialization_behaviors.response_deserializers,
        thread_pool_size=test_constants.POOL_SIZE)
    generic_stub = implementations.generic_stub(channel, options=stub_options)
    dynamic_stub = implementations.dynamic_stub(
        channel, service, cardinalities, options=stub_options)
    return generic_stub, {service: dynamic_stub}, server
Пример #8
0
    def __init__(self, server, config, hist):
        # Create the stub
        host, port = server.split(':')
        port = int(port)
        if config.HasField('security_params'):
            creds = implementations.ssl_channel_credentials(
                resources.test_root_certificates())
            channel = test_utilities.not_really_secure_channel(
                host, port, creds, config.security_params.server_host_override)
        else:
            channel = implementations.insecure_channel(host, port)

        if config.payload_config.WhichOneof('payload') == 'simple_params':
            self._generic = False
            self._stub = services_pb2.beta_create_BenchmarkService_stub(
                channel)
            payload = messages_pb2.Payload(
                body='\0' * config.payload_config.simple_params.req_size)
            self._request = messages_pb2.SimpleRequest(
                payload=payload,
                response_size=config.payload_config.simple_params.resp_size)
        else:
            self._generic = True
            self._stub = implementations.generic_stub(channel)
            self._request = '\0' * config.payload_config.bytebuf_params.req_size

        self._hist = hist
        self._response_callbacks = []
Пример #9
0
  def instantiate(
      self, methods, method_implementations, multi_method_implementation):
    serialization_behaviors = _serialization_behaviors_from_test_methods(
        methods)
    # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest.
    service = next(iter(methods))[0]
    # TODO(nathaniel): Add a "cardinalities_by_group" attribute to
    # _digest.TestServiceDigest.
    cardinalities = {
        method: method_object.cardinality()
        for (group, method), method_object in six.iteritems(methods)}

    server_options = implementations.server_options(
        request_deserializers=serialization_behaviors.request_deserializers,
        response_serializers=serialization_behaviors.response_serializers,
        thread_pool_size=test_constants.POOL_SIZE)
    server = implementations.server(
        method_implementations, options=server_options)
    server_credentials = implementations.ssl_server_credentials(
        [(resources.private_key(), resources.certificate_chain(),),])
    port = server.add_secure_port('[::]:0', server_credentials)
    server.start()
    channel_credentials = implementations.ssl_channel_credentials(
        resources.test_root_certificates())
    channel = test_utilities.not_really_secure_channel(
        'localhost', port, channel_credentials, _SERVER_HOST_OVERRIDE)
    stub_options = implementations.stub_options(
        request_serializers=serialization_behaviors.request_serializers,
        response_deserializers=serialization_behaviors.response_deserializers,
        thread_pool_size=test_constants.POOL_SIZE)
    generic_stub = implementations.generic_stub(channel, options=stub_options)
    dynamic_stub = implementations.dynamic_stub(
        channel, service, cardinalities, options=stub_options)
    return generic_stub, {service: dynamic_stub}, server
Пример #10
0
    def __init__(self, server, config, hist):
        # Create the stub
        if config.HasField('security_params'):
            creds = grpc.ssl_channel_credentials(
                resources.test_root_certificates())
            channel = test_common.test_secure_channel(
                server, creds, config.security_params.server_host_override)
        else:
            channel = grpc.insecure_channel(server)

        # waits for the channel to be ready before we start sending messages
        grpc.channel_ready_future(channel).result()

        if config.payload_config.WhichOneof('payload') == 'simple_params':
            self._generic = False
            self._stub = services_pb2.BenchmarkServiceStub(channel)
            payload = messages_pb2.Payload(
                body='\0' * config.payload_config.simple_params.req_size)
            self._request = messages_pb2.SimpleRequest(
                payload=payload,
                response_size=config.payload_config.simple_params.resp_size)
        else:
            self._generic = True
            self._stub = GenericStub(channel)
            self._request = '\0' * config.payload_config.bytebuf_params.req_size

        self._hist = hist
        self._response_callbacks = []
Пример #11
0
    async def setUp(self):
        server_credentials = grpc.ssl_server_credentials([
            (resources.private_key(), resources.certificate_chain())
        ])
        channel_credentials = grpc.ssl_channel_credentials(
            resources.test_root_certificates())

        self._server_address, self._server = await start_test_server(
            secure=True, server_credentials=server_credentials)
        channel_options = ((
            'grpc.ssl_target_name_override',
            _SERVER_HOST_OVERRIDE,
        ), )
        self._channel = aio.secure_channel(self._server_address,
                                           channel_credentials,
                                           channel_options)
        self._stub = test_pb2_grpc.TestServiceStub(self._channel)
Пример #12
0
    def setUp(self):
        self._servicer = _Servicer()
        method_implementations = {
            (_GROUP, _UNARY_UNARY):
            utilities.unary_unary_inline(self._servicer.unary_unary),
            (_GROUP, _UNARY_STREAM):
            utilities.unary_stream_inline(self._servicer.unary_stream),
            (_GROUP, _STREAM_UNARY):
            utilities.stream_unary_inline(self._servicer.stream_unary),
            (_GROUP, _STREAM_STREAM):
            utilities.stream_stream_inline(self._servicer.stream_stream),
        }

        cardinalities = {
            _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY,
            _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM,
            _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY,
            _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM,
        }

        server_options = implementations.server_options(
            thread_pool_size=test_constants.POOL_SIZE)
        self._server = implementations.server(method_implementations,
                                              options=server_options)
        server_credentials = implementations.ssl_server_credentials([
            (
                resources.private_key(),
                resources.certificate_chain(),
            ),
        ])
        port = self._server.add_secure_port('[::]:0', server_credentials)
        self._server.start()
        self._channel_credentials = implementations.ssl_channel_credentials(
            resources.test_root_certificates())
        self._call_credentials = implementations.metadata_call_credentials(
            _metadata_plugin)
        channel = test_utilities.not_really_secure_channel(
            'localhost', port, self._channel_credentials,
            _SERVER_HOST_OVERRIDE)
        stub_options = implementations.stub_options(
            thread_pool_size=test_constants.POOL_SIZE)
        self._dynamic_stub = implementations.dynamic_stub(channel,
                                                          _GROUP,
                                                          cardinalities,
                                                          options=stub_options)
Пример #13
0
 def setUp(self):
   server_credentials = cygrpc.server_credentials_ssl(
       None, [cygrpc.SslPemKeyCertPair(resources.private_key(),
                                       resources.certificate_chain())], False)
   channel_credentials = cygrpc.channel_credentials_ssl(
       resources.test_root_certificates(), None)
   self.server_completion_queue = cygrpc.CompletionQueue()
   self.server = cygrpc.Server()
   self.server.register_completion_queue(self.server_completion_queue)
   self.port = self.server.add_http2_port('[::]:0', server_credentials)
   self.server.start()
   self.client_completion_queue = cygrpc.CompletionQueue()
   client_channel_arguments = cygrpc.ChannelArgs([
       cygrpc.ChannelArg(cygrpc.ChannelArgKey.ssl_target_name_override,
                         _SSL_HOST_OVERRIDE)])
   self.client_channel = cygrpc.Channel(
       'localhost:{}'.format(self.port), client_channel_arguments,
       channel_credentials)
Пример #14
0
    def __init__(self, address: str, config: control_pb2.ClientConfig,
                 hist: histogram.Histogram):
        # Disables underlying reuse of subchannels
        unique_option = (('iv', random.random()),)

        # Parses the channel argument from config
        channel_args = tuple(
            (arg.name, arg.str_value) if arg.HasField('str_value') else (
                arg.name, int(arg.int_value)) for arg in config.channel_args)

        # Creates the channel
        if config.HasField('security_params'):
            channel_credentials = grpc.ssl_channel_credentials(
                resources.test_root_certificates(),)
            server_host_override_option = ((
                'grpc.ssl_target_name_override',
                config.security_params.server_host_override,
            ),)
            self._channel = aio.secure_channel(
                address, channel_credentials,
                unique_option + channel_args + server_host_override_option)
        else:
            self._channel = aio.insecure_channel(address,
                                                 options=unique_option +
                                                 channel_args)

        # Creates the stub
        if config.payload_config.WhichOneof('payload') == 'simple_params':
            self._generic = False
            self._stub = benchmark_service_pb2_grpc.BenchmarkServiceStub(
                self._channel)
            payload = messages_pb2.Payload(
                body=b'\0' * config.payload_config.simple_params.req_size)
            self._request = messages_pb2.SimpleRequest(
                payload=payload,
                response_size=config.payload_config.simple_params.resp_size)
        else:
            self._generic = True
            self._stub = GenericStub(self._channel)
            self._request = b'\0' * config.payload_config.bytebuf_params.req_size

        self._hist = hist
        self._response_callbacks = []
        self._concurrency = config.outstanding_rpcs_per_channel
Пример #15
0
 def test_default_ssl(self):
     _private_key = resources.private_key()
     _certificate_chain = resources.certificate_chain()
     _server_certs = ((_private_key, _certificate_chain), )
     _server_host_override = 'foo.test.google.fr'
     _test_root_certificates = resources.test_root_certificates()
     _property_options = ((
         'grpc.ssl_target_name_override',
         _server_host_override,
     ), )
     cert_dir = os.path.join(os.path.dirname(resources.__file__),
                             "credentials")
     cert_file = os.path.join(cert_dir, "ca.pem")
     with _env("GRPC_DEFAULT_SSL_ROOTS_FILE_PATH", cert_file):
         server_creds = grpc.ssl_server_credentials(_server_certs)
         with _server(server_creds) as port:
             target = f'localhost:{port}'
             response = grpc.experimental.unary_unary(
                 _REQUEST, target, _UNARY_UNARY, options=_property_options)
Пример #16
0
    def setUp(self):
        self._servicer = _Servicer()
        method_implementations = {
            (_GROUP, _UNARY_UNARY):
            utilities.unary_unary_inline(self._servicer.unary_unary),
            (_GROUP, _UNARY_STREAM):
            utilities.unary_stream_inline(self._servicer.unary_stream),
            (_GROUP, _STREAM_UNARY):
            utilities.stream_unary_inline(self._servicer.stream_unary),
            (_GROUP, _STREAM_STREAM):
            utilities.stream_stream_inline(self._servicer.stream_stream),
        }

        cardinalities = {
            _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY,
            _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM,
            _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY,
            _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM,
        }

        server_options = implementations.server_options(
            thread_pool_size=test_constants.POOL_SIZE)
        self._server = implementations.server(
            method_implementations, options=server_options)
        server_credentials = implementations.ssl_server_credentials([
            (
                resources.private_key(),
                resources.certificate_chain(),
            ),
        ])
        port = self._server.add_secure_port('[::]:0', server_credentials)
        self._server.start()
        self._channel_credentials = implementations.ssl_channel_credentials(
            resources.test_root_certificates())
        self._call_credentials = implementations.metadata_call_credentials(
            _metadata_plugin)
        channel = test_utilities.not_really_secure_channel(
            'localhost', port, self._channel_credentials, _SERVER_HOST_OVERRIDE)
        stub_options = implementations.stub_options(
            thread_pool_size=test_constants.POOL_SIZE)
        self._dynamic_stub = implementations.dynamic_stub(
            channel, _GROUP, cardinalities, options=stub_options)
Пример #17
0
 def setUp(self):
     server_credentials = cygrpc.server_credentials_ssl(
         None, [
             cygrpc.SslPemKeyCertPair(resources.private_key(),
                                      resources.certificate_chain())
         ], False)
     channel_credentials = cygrpc.channel_credentials_ssl(
         resources.test_root_certificates(), None)
     self.server_completion_queue = cygrpc.CompletionQueue()
     self.server = cygrpc.Server()
     self.server.register_completion_queue(self.server_completion_queue)
     self.port = self.server.add_http2_port('[::]:0', server_credentials)
     self.server.start()
     self.client_completion_queue = cygrpc.CompletionQueue()
     client_channel_arguments = cygrpc.ChannelArgs([
         cygrpc.ChannelArg(cygrpc.ChannelArgKey.ssl_target_name_override,
                           _SSL_HOST_OVERRIDE)
     ])
     self.client_channel = cygrpc.Channel('localhost:{}'.format(self.port),
                                          client_channel_arguments,
                                          channel_credentials)
Пример #18
0
 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)
Пример #19
0
_UNARY_UNARY = '/test/UnaryUnary'

_SERVER_HOST_OVERRIDE = 'foo.test.google.fr'
_CLIENT_IDS = (
    b'*.test.google.fr',
    b'waterzooi.test.google.be',
    b'*.test.youtube.com',
    b'192.168.1.3',
)
_ID = 'id'
_ID_KEY = 'id_key'
_AUTH_CTX = 'auth_ctx'

_PRIVATE_KEY = resources.private_key()
_CERTIFICATE_CHAIN = resources.certificate_chain()
_TEST_ROOT_CERTIFICATES = resources.test_root_certificates()
_SERVER_CERTS = ((_PRIVATE_KEY, _CERTIFICATE_CHAIN), )
_PROPERTY_OPTIONS = ((
    'grpc.ssl_target_name_override',
    _SERVER_HOST_OVERRIDE,
), )


def handle_unary_unary(request, servicer_context):
    return pickle.dumps({
        _ID: servicer_context.peer_identities(),
        _ID_KEY: servicer_context.peer_identity_key(),
        _AUTH_CTX: servicer_context.auth_context()
    })

Пример #20
0
 def test_application_provided_root_certificates(self):
     channel_credentials = implementations.ssl_channel_credentials(
         resources.test_root_certificates())
     self.assertIsInstance(channel_credentials,
                           implementations.ChannelCredentials)
Пример #21
0
 def test_application_provided_root_certificates(self):
     channel_credentials = implementations.ssl_channel_credentials(
         resources.test_root_certificates())
     self.assertIsInstance(channel_credentials,
                           implementations.ChannelCredentials)
Пример #22
0
_UNARY_UNARY = '/test/UnaryUnary'

_SERVER_HOST_OVERRIDE = 'foo.test.google.fr'
_CLIENT_IDS = (
    b'*.test.google.fr',
    b'waterzooi.test.google.be',
    b'*.test.youtube.com',
    b'192.168.1.3',
)
_ID = 'id'
_ID_KEY = 'id_key'
_AUTH_CTX = 'auth_ctx'

_PRIVATE_KEY = resources.private_key()
_CERTIFICATE_CHAIN = resources.certificate_chain()
_TEST_ROOT_CERTIFICATES = resources.test_root_certificates()
_SERVER_CERTS = ((_PRIVATE_KEY, _CERTIFICATE_CHAIN),)
_PROPERTY_OPTIONS = ((
    'grpc.ssl_target_name_override',
    _SERVER_HOST_OVERRIDE,
),)


def handle_unary_unary(request, servicer_context):
    return pickle.dumps({
        _ID: servicer_context.peer_identities(),
        _ID_KEY: servicer_context.peer_identity_key(),
        _AUTH_CTX: servicer_context.auth_context()
    })