14 """The Python implementation of the GRPC interoperability test client."""
19 from google
import auth
as google_auth
20 from google.auth
import jwt
as google_auth_jwt
23 from src.proto.grpc.testing
import test_pb2_grpc
29 parser = argparse.ArgumentParser()
30 parser.add_argument(
'--server_host',
33 help=
'the host to which to connect')
34 parser.add_argument(
'--server_port',
37 help=
'the port to which to connect')
38 parser.add_argument(
'--test_case',
39 default=
'large_unary',
41 help=
'the test case to execute')
42 parser.add_argument(
'--use_tls',
44 type=resources.parse_bool,
45 help=
'require a secure connection')
46 parser.add_argument(
'--use_alts',
48 type=resources.parse_bool,
49 help=
'require an ALTS secure connection')
50 parser.add_argument(
'--use_test_ca',
52 type=resources.parse_bool,
53 help=
'replace platform root CAs with ca.pem')
54 parser.add_argument(
'--custom_credentials_type',
55 choices=[
"compute_engine_channel_creds"],
57 help=
'use google default credentials')
58 parser.add_argument(
'--server_host_override',
60 help=
'the server host to which to claim to connect')
61 parser.add_argument(
'--oauth_scope',
63 help=
'scope for OAuth tokens')
64 parser.add_argument(
'--default_service_account',
66 help=
'email address of the default service account')
68 "--grpc_test_use_grpclb_with_child_policy",
71 "If non-empty, set a static service config on channels created by "
72 +
"grpc::CreateTestChannel, that configures the grpclb LB policy " +
73 "with a child policy being the value of this flag (e.g. round_robin "
75 return parser.parse_args()
79 if args.test_case ==
'oauth2_auth_token':
80 google_credentials, unused_project_id = google_auth.default(
81 scopes=[args.oauth_scope])
82 google_credentials.refresh(google_auth.transport.requests.Request())
84 elif args.test_case ==
'compute_engine_creds':
85 google_credentials, unused_project_id = google_auth.default(
86 scopes=[args.oauth_scope])
88 google_auth.transport.grpc.AuthMetadataPlugin(
89 credentials=google_credentials,
90 request=google_auth.transport.requests.Request()))
91 elif args.test_case ==
'jwt_token_creds':
92 google_credentials = google_auth_jwt.OnDemandCredentials.from_service_account_file(
93 os.environ[google_auth.environment_vars.CREDENTIALS])
95 google_auth.transport.grpc.AuthMetadataPlugin(
96 credentials=google_credentials, request=
None))
105 if args.grpc_test_use_grpclb_with_child_policy:
107 "grpc.service_config",
108 '{"loadBalancingConfig": [{"grpclb": {"childPolicy": [{"%s": {}}]}}]}'
109 % args.grpc_test_use_grpclb_with_child_policy),)
110 if args.custom_credentials_type
is not None:
111 if args.custom_credentials_type ==
"compute_engine_channel_creds":
112 assert call_credentials
is None
113 google_credentials, unused_project_id = google_auth.default(
114 scopes=[args.oauth_scope])
116 google_auth.transport.grpc.AuthMetadataPlugin(
117 credentials=google_credentials,
118 request=google_auth.transport.requests.Request()))
122 raise ValueError(
"Unknown credentials type '{}'".
format(
123 args.custom_credentials_type))
126 root_certificates = resources.test_root_certificates()
128 root_certificates =
None
131 if call_credentials
is not None:
133 channel_credentials, call_credentials)
135 if args.server_host_override:
137 'grpc.ssl_target_name_override',
138 args.server_host_override,
143 return channel_credentials, channel_opts
147 target =
'{}:{}'.
format(args.server_host, args.server_port)
149 if args.use_tls
or args.use_alts
or args.custom_credentials_type
is not None:
157 if args.test_case ==
"unimplemented_service":
158 return test_pb2_grpc.UnimplementedServiceStub(channel)
160 return test_pb2_grpc.TestServiceStub(channel)
165 if test_case_arg == test_case.value:
168 raise ValueError(
'No test case "%s"!' % test_case_arg)
176 test_case.test_interoperability(stub, args)
179 if __name__ ==
'__main__':