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
22 from src.proto.grpc.testing import test_pb2_grpc
24 from tests.interop import service
25 from tests.interop import resources
26 from tests.unit import test_common
28 _ONE_DAY_IN_SECONDS = 60 * 60 * 24
30 _LOGGER = logging.getLogger(__name__)
34 parser = argparse.ArgumentParser()
36 '--port', type=int, required=True, help='the port on which to serve')
40 type=resources.parse_bool,
41 help='require a secure connection')
42 args = parser.parse_args()
44 server = test_common.test_server()
45 test_pb2_grpc.add_TestServiceServicer_to_server(service.TestService(),
48 private_key = resources.private_key()
49 certificate_chain = resources.certificate_chain()
50 credentials = grpc.ssl_server_credentials(((private_key,
52 server.add_secure_port('[::]:{}'.format(args.port), credentials)
54 server.add_insecure_port('[::]:{}'.format(args.port))
57 _LOGGER.info('Server serving.')
60 time.sleep(_ONE_DAY_IN_SECONDS)
61 except BaseException as e:
62 _LOGGER.info('Caught exception "%s"; stopping server...', e)
64 _LOGGER.info('Server stopped; exiting.')
67 if __name__ == '__main__':