Пример #1
0
 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)
Пример #2
0
def _configure_test_server(server: grpc.Server, port: int, secure_mode: bool,
                           server_id: str) -> None:
    test_pb2_grpc.add_TestServiceServicer_to_server(
        TestService(server_id, socket.gethostname()), server)
    listen_address = f"{_LISTEN_HOST}:{port}"
    if not secure_mode:
        server.add_insecure_port(listen_address)
    else:
        logger.info("Running with xDS Server credentials")
        server_fallback_creds = grpc.insecure_server_credentials()
        server_creds = grpc.xds_server_credentials(server_fallback_creds)
        server.add_secure_port(listen_address, server_creds)
Пример #3
0
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)
Пример #4
0
def _configure_greeter_server(server: grpc.Server, port: int,
                              secure_mode: bool, hostname) -> None:
    # Add the application servicer to the server.
    helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(hostname),
                                                      server)
    listen_address = f"{_LISTEN_HOST}:{port}"
    if not secure_mode:
        server.add_insecure_port(listen_address)
    else:
        # Use xDS credentials.
        logger.info("Running with xDS Server credentials")

        # Fall back to insecure credentials.
        server_fallback_creds = grpc.insecure_server_credentials()
        server_creds = grpc.xds_server_credentials(server_fallback_creds)
        server.add_secure_port(listen_address, server_creds)