Beispiel #1
0
 def setUp(self):
   self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
   test_pb2.add_TestServiceServicer_to_server(
       methods.TestService(), self.server)
   port = self.server.add_insecure_port('[::]:0')
   self.server.start()
   self.stub = test_pb2.TestServiceStub(
       grpc.insecure_channel('localhost:{}'.format(port)))
Beispiel #2
0
 def setUp(self):
     self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
     test_pb2.add_TestServiceServicer_to_server(methods.TestService(),
                                                self.server)
     port = self.server.add_secure_port(
         '[::]:0',
         grpc.ssl_server_credentials([(resources.private_key(),
                                       resources.certificate_chain())]))
     self.server.start()
     self.stub = test_pb2.TestServiceStub(
         grpc.secure_channel(
             'localhost:{}'.format(port),
             grpc.ssl_channel_credentials(
                 resources.test_root_certificates()), ((
                     'grpc.ssl_target_name_override',
                     _SERVER_HOST_OVERRIDE,
                 ), )))
Beispiel #3
0
def _stub(args):
    target = '{}:{}'.format(args.server_host, args.server_port)
    if args.test_case == 'oauth2_auth_token':
        google_credentials = _application_default_credentials()
        scoped_credentials = google_credentials.create_scoped(
            [args.oauth_scope])
        access_token = scoped_credentials.get_access_token().access_token
        call_credentials = grpc.access_token_call_credentials(access_token)
    elif args.test_case == 'compute_engine_creds':
        google_credentials = _application_default_credentials()
        scoped_credentials = google_credentials.create_scoped(
            [args.oauth_scope])
        # TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last
        # remaining use of the Beta API.
        call_credentials = implementations.google_call_credentials(
            scoped_credentials)
    elif args.test_case == 'jwt_token_creds':
        google_credentials = _application_default_credentials()
        # TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last
        # remaining use of the Beta API.
        call_credentials = implementations.google_call_credentials(
            google_credentials)
    else:
        call_credentials = None
    if args.use_tls:
        if args.use_test_ca:
            root_certificates = resources.test_root_certificates()
        else:
            root_certificates = None  # will load default roots.

        channel_credentials = grpc.ssl_channel_credentials(root_certificates)
        if call_credentials is not None:
            channel_credentials = grpc.composite_channel_credentials(
                channel_credentials, call_credentials)

        channel = grpc.secure_channel(target, channel_credentials, ((
            'grpc.ssl_target_name_override',
            args.server_host_override,
        ), ))
    else:
        channel = grpc.insecure_channel(target)
    if args.test_case == "unimplemented_service":
        return test_pb2.UnimplementedServiceStub(channel)
    else:
        return test_pb2.TestServiceStub(channel)
Beispiel #4
0
def _stub(args):
    target = '{}:{}'.format(args.server_host, args.server_port)
    if args.test_case == 'oauth2_auth_token':
        google_credentials, unused_project_id = google_auth.default(
            scopes=[args.oauth_scope])
        google_credentials.refresh(google_auth.transport.requests.Request())
        call_credentials = grpc.access_token_call_credentials(
            google_credentials.token)
    elif args.test_case == 'compute_engine_creds':
        google_credentials, unused_project_id = google_auth.default(
            scopes=[args.oauth_scope])
        call_credentials = grpc.metadata_call_credentials(
            google_auth.transport.grpc.AuthMetadataPlugin(
                credentials=google_credentials,
                request=google_auth.transport.requests.Request()))
    elif args.test_case == 'jwt_token_creds':
        google_credentials = google_auth_jwt.OnDemandCredentials.from_service_account_file(
            os.environ[google_auth.environment_vars.CREDENTIALS])
        call_credentials = grpc.metadata_call_credentials(
            google_auth.transport.grpc.AuthMetadataPlugin(
                credentials=google_credentials, request=None))
    else:
        call_credentials = None
    if args.use_tls:
        if args.use_test_ca:
            root_certificates = resources.test_root_certificates()
        else:
            root_certificates = None  # will load default roots.

        channel_credentials = grpc.ssl_channel_credentials(root_certificates)
        if call_credentials is not None:
            channel_credentials = grpc.composite_channel_credentials(
                channel_credentials, call_credentials)

        channel = grpc.secure_channel(target, channel_credentials, ((
            'grpc.ssl_target_name_override',
            args.server_host_override,
        ), ))
    else:
        channel = grpc.insecure_channel(target)
    if args.test_case == "unimplemented_service":
        return test_pb2.UnimplementedServiceStub(channel)
    else:
        return test_pb2.TestServiceStub(channel)
Beispiel #5
0
def run_test(args):
    test_cases = _parse_weighted_test_cases(args.test_cases)
    test_server_targets = args.server_addresses.split(',')
    # Propagate any client exceptions with a queue
    exception_queue = queue.Queue()
    stop_event = threading.Event()
    hist = histogram.Histogram(1, 1)
    runners = []

    server = grpc.server(futures.ThreadPoolExecutor(max_workers=25))
    metrics_pb2.add_MetricsServiceServicer_to_server(
        metrics_server.MetricsServer(hist), server)
    server.add_insecure_port('[::]:{}'.format(args.metrics_port))
    server.start()

    for test_server_target in test_server_targets:
        for _ in xrange(args.num_channels_per_server):
            channel = grpc.insecure_channel(test_server_target)
            for _ in xrange(args.num_stubs_per_channel):
                stub = test_pb2.TestServiceStub(channel)
                runner = test_runner.TestRunner(stub, test_cases, hist,
                                                exception_queue, stop_event)
                runners.append(runner)

    for runner in runners:
        runner.start()
    try:
        timeout_secs = args.test_duration_secs
        if timeout_secs < 0:
            timeout_secs = None
        raise exception_queue.get(block=True, timeout=timeout_secs)
    except queue.Empty:
        # No exceptions thrown, success
        pass
    finally:
        stop_event.set()
        for runner in runners:
            runner.join()
        runner = None
        server.stop(None)
def _stub(server_host, server_port):
    target = '{}:{}'.format(server_host, server_port)
    channel = grpc.insecure_channel(target)
    grpc.channel_ready_future(channel).result()
    return test_pb2.TestServiceStub(channel)
Beispiel #7
0
def _stub(server_host, server_port):
    target = '{}:{}'.format(server_host, server_port)
    channel = grpc.insecure_channel(target)
    return test_pb2.TestServiceStub(channel)