def _stub(args): if args.oauth_scope: if args.test_case == "oauth2_auth_token": # TODO(jtattermusch): This testcase sets the auth metadata key-value # manually, which also means that the user would need to do the same # thing every time he/she would like to use and out of band oauth token. # The transformer function that produces the metadata key-value from # the access token should be provided by gRPC auth library. access_token = _oauth_access_token(args) metadata_transformer = lambda x: [("authorization", "Bearer %s" % access_token)] else: metadata_transformer = lambda x: [("authorization", "Bearer %s" % _oauth_access_token(args))] else: metadata_transformer = lambda x: [] if args.use_tls: if args.use_test_ca: root_certificates = resources.test_root_certificates() else: root_certificates = None # will load default roots. channel = test_utilities.not_really_secure_channel( args.server_host, args.server_port, implementations.ssl_channel_credentials(root_certificates), args.server_host_override, ) stub = test_pb2.beta_create_TestService_stub(channel, metadata_transformer=metadata_transformer) else: channel = implementations.insecure_channel(args.server_host, args.server_port) stub = test_pb2.beta_create_TestService_stub(channel) return stub
def _stub(args): if args.test_case == 'oauth2_auth_token': creds = oauth2client_client.GoogleCredentials.get_application_default() scoped_creds = creds.create_scoped([args.oauth_scope]) access_token = scoped_creds.get_access_token().access_token call_creds = implementations.access_token_call_credentials( access_token) elif args.test_case == 'compute_engine_creds': creds = oauth2client_client.GoogleCredentials.get_application_default() scoped_creds = creds.create_scoped([args.oauth_scope]) call_creds = implementations.google_call_credentials(scoped_creds) else: call_creds = 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_creds = implementations.ssl_channel_credentials( root_certificates) if call_creds is not None: channel_creds = implementations.composite_channel_credentials( channel_creds, call_creds) channel = test_utilities.not_really_secure_channel( args.server_host, args.server_port, channel_creds, args.server_host_override) stub = test_pb2.beta_create_TestService_stub(channel) else: channel = implementations.insecure_channel(args.server_host, args.server_port) stub = test_pb2.beta_create_TestService_stub(channel) return stub
def _stub(args): if args.test_case == 'oauth2_auth_token': creds = oauth2client_client.GoogleCredentials.get_application_default() scoped_creds = creds.create_scoped([args.oauth_scope]) access_token = scoped_creds.get_access_token().access_token call_creds = implementations.access_token_call_credentials(access_token) elif args.test_case == 'compute_engine_creds': creds = oauth2client_client.GoogleCredentials.get_application_default() scoped_creds = creds.create_scoped([args.oauth_scope]) call_creds = implementations.google_call_credentials(scoped_creds) elif args.test_case == 'jwt_token_creds': creds = oauth2client_client.GoogleCredentials.get_application_default() call_creds = implementations.google_call_credentials(creds) else: call_creds = 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_creds = implementations.ssl_channel_credentials(root_certificates) if call_creds is not None: channel_creds = implementations.composite_channel_credentials( channel_creds, call_creds) channel = test_utilities.not_really_secure_channel( args.server_host, args.server_port, channel_creds, args.server_host_override) stub = test_pb2.beta_create_TestService_stub(channel) else: channel = implementations.insecure_channel( args.server_host, args.server_port) stub = test_pb2.beta_create_TestService_stub(channel) return stub
def _stub(args): if args.oauth_scope: if args.test_case == 'oauth2_auth_token': # TODO(jtattermusch): This testcase sets the auth metadata key-value # manually, which also means that the user would need to do the same # thing every time he/she would like to use and out of band oauth token. # The transformer function that produces the metadata key-value from # the access token should be provided by gRPC auth library. access_token = _oauth_access_token(args) metadata_transformer = lambda x: [('authorization', 'Bearer %s' % access_token)] else: metadata_transformer = lambda x: [('authorization', 'Bearer %s' % _oauth_access_token(args))] else: metadata_transformer = lambda x: [] if args.use_tls: if args.use_test_ca: root_certificates = resources.test_root_certificates() else: root_certificates = None # will load default roots. channel = test_utilities.not_really_secure_channel( args.server_host, args.server_port, implementations.ssl_channel_credentials(root_certificates), args.server_host_override) stub = test_pb2.beta_create_TestService_stub( channel, metadata_transformer=metadata_transformer) else: channel = implementations.insecure_channel(args.server_host, args.server_port) stub = test_pb2.beta_create_TestService_stub(channel) return stub
def setUp(self): self.server = test_pb2.beta_create_TestService_server( methods.TestService()) port = self.server.add_insecure_port('[::]:0') self.server.start() self.stub = test_pb2.beta_create_TestService_stub( implementations.insecure_channel('localhost', port))
def setUp(self): self.server = test_pb2.beta_create_TestService_server(methods.TestService()) port = self.server.add_secure_port( '[::]:0', implementations.ssl_server_credentials( [(resources.private_key(), resources.certificate_chain())])) self.server.start() self.stub = test_pb2.beta_create_TestService_stub( test_utilities.not_really_secure_channel( 'localhost', port, implementations.ssl_channel_credentials( resources.test_root_certificates()), _SERVER_HOST_OVERRIDE))
def setUp(self): self.server = test_pb2.beta_create_TestService_server(methods.TestService()) port = self.server.add_secure_port( '[::]:0', implementations.ssl_server_credentials( [(resources.private_key(), resources.certificate_chain())])) self.server.start() self.stub = test_pb2.beta_create_TestService_stub( test_utilities.not_really_secure_channel( '[::]', port, implementations.ssl_channel_credentials( resources.test_root_certificates()), _SERVER_HOST_OVERRIDE))
def run_test(args): test_cases = _parse_weighted_test_cases(args.test_cases) test_servers = 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 = metrics_pb2.beta_create_MetricsService_server( metrics_server.MetricsServer(hist)) server.add_insecure_port('[::]:{}'.format(args.metrics_port)) server.start() for test_server in test_servers: host, port = test_server.split(':', 1) for _ in xrange(args.num_channels_per_server): channel = implementations.insecure_channel(host, int(port)) for _ in xrange(args.num_stubs_per_channel): stub = test_pb2.beta_create_TestService_stub(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(0)
def setUp(self): self.server = test_pb2.beta_create_TestService_server(methods.TestService()) port = self.server.add_insecure_port('[::]:0') self.server.start() self.stub = test_pb2.beta_create_TestService_stub( implementations.insecure_channel('[::]', port))