1 # Copyright 2015 gRPC authors.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """The Python implementation of the GRPC interoperability test server."""
17 from concurrent import futures
21 from src.proto.grpc.testing import test_pb2_grpc
23 from tests.interop import service
24 from tests.interop import resources
25 from tests.unit import test_common
28 _LOGGER = logging.getLogger(__name__)
32 parser = argparse.ArgumentParser()
33 parser.add_argument('--port',
36 help='the port on which to serve')
37 parser.add_argument('--use_tls',
39 type=resources.parse_bool,
40 help='require a secure connection')
41 args = parser.parse_args()
43 server = test_common.test_server()
44 test_pb2_grpc.add_TestServiceServicer_to_server(service.TestService(),
47 private_key = resources.private_key()
48 certificate_chain = resources.certificate_chain()
49 credentials = grpc.ssl_server_credentials(
50 ((private_key, certificate_chain),))
51 server.add_secure_port('[::]:{}'.format(args.port), credentials)
53 server.add_insecure_port('[::]:{}'.format(args.port))
56 _LOGGER.info('Server serving.')
57 server.wait_for_termination()
58 _LOGGER.info('Server stopped; exiting.')
61 if __name__ == '__main__':