THRIFT-3118: add http (for non-ssl and for ssl) to the python cross tests
diff --git a/test/py/TestClient.py b/test/py/TestClient.py
index 1ab8e78..edab610 100755
--- a/test/py/TestClient.py
+++ b/test/py/TestClient.py
@@ -32,8 +32,18 @@
class AbstractTest(unittest.TestCase):
def setUp(self):
- if options.http_path:
- self.transport = THttpClient.THttpClient(options.host, port=options.port, path=options.http_path)
+ if options.trans == 'http':
+ uri = '{0}://{1}:{2}{3}'.format(('https' if options.ssl else 'http'),
+ options.host,
+ options.port,
+ (options.http_path if options.http_path else '/'))
+ if options.ssl:
+ __cafile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "CA.pem")
+ __certfile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "client.crt")
+ __keyfile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "client.key")
+ self.transport = THttpClient.THttpClient(uri, cafile=__cafile, cert_file=__certfile, key_file=__keyfile)
+ else:
+ self.transport = THttpClient.THttpClient(uri)
else:
if options.ssl:
from thrift.transport import TSSLSocket
@@ -325,9 +335,9 @@
dest="verbose", const=0,
help="minimal output")
parser.add_option('--protocol', dest="proto", type="string",
- help="protocol to use, one of: accel, binary, compact, json")
+ help="protocol to use, one of: accel, accelc, binary, compact, json")
parser.add_option('--transport', dest="trans", type="string",
- help="transport to use, one of: buffered, framed")
+ help="transport to use, one of: buffered, framed, http")
parser.set_defaults(framed=False, http_path=None, verbose=1, host='localhost', port=9090, proto='binary')
options, args = parser.parse_args()
@@ -335,6 +345,9 @@
sys.path.insert(0, os.path.join(SCRIPT_DIR, options.genpydir))
sys.path.insert(0, local_libpath())
+ if options.http_path:
+ options.trans = 'http'
+
from ThriftTest import ThriftTest
from ThriftTest.ttypes import Xtruct, Xtruct2, Numberz, Xception, Xception2
from thrift.Thrift import TException
diff --git a/test/py/TestServer.py b/test/py/TestServer.py
index 04ad62a..4dc4c07 100755
--- a/test/py/TestServer.py
+++ b/test/py/TestServer.py
@@ -21,6 +21,7 @@
from __future__ import division
import logging
import os
+import signal
import sys
import time
from optparse import OptionParser
@@ -180,11 +181,11 @@
def main(options):
# set up the protocol factory form the --protocol option
prot_factories = {
- 'binary': TBinaryProtocol.TBinaryProtocolFactory,
'accel': TBinaryProtocol.TBinaryProtocolAcceleratedFactory,
- 'compact': TCompactProtocol.TCompactProtocolFactory,
'accelc': TCompactProtocol.TCompactProtocolAcceleratedFactory,
- 'json': TJSONProtocol.TJSONProtocolFactory,
+ 'binary': TBinaryProtocol.TBinaryProtocolFactory,
+ 'compact': TCompactProtocol.TCompactProtocolFactory,
+ 'json': TJSONProtocol.TJSONProtocolFactory
}
pfactory_cls = prot_factories.get(options.proto, None)
if pfactory_cls is None:
@@ -201,14 +202,23 @@
if len(args) > 1:
raise AssertionError('Only one server type may be specified, not multiple types.')
server_type = args[0]
+ if options.trans == 'http':
+ server_type = 'THttpServer'
# Set up the handler and processor objects
handler = TestHandler()
processor = ThriftTest.Processor(handler)
+ global server
+
# Handle THttpServer as a special case
if server_type == 'THttpServer':
- server = THttpServer.THttpServer(processor, ('', options.port), pfactory)
+ if options.ssl:
+ __certfile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "server.crt")
+ __keyfile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "server.key")
+ server = THttpServer.THttpServer(processor, ('', options.port), pfactory, cert_file=__certfile, key_file=__keyfile)
+ else:
+ server = THttpServer.THttpServer(processor, ('', options.port), pfactory)
server.serve()
sys.exit(0)
@@ -268,7 +278,15 @@
server.serve()
+def exit_gracefully(signum, frame):
+ print("SIGINT received\n")
+ server.shutdown() # doesn't work properly, yet
+ sys.exit(0)
+
+
if __name__ == '__main__':
+ signal.signal(signal.SIGINT, exit_gracefully)
+
parser = OptionParser()
parser.add_option('--libpydir', type='string', dest='libpydir',
help='include this directory to sys.path for locating library code')
@@ -288,12 +306,12 @@
dest="verbose", const=0,
help="minimal output")
parser.add_option('--protocol', dest="proto", type="string",
- help="protocol to use, one of: accel, binary, compact, json")
+ help="protocol to use, one of: accel, accelc, binary, compact, json")
parser.add_option('--transport', dest="trans", type="string",
- help="transport to use, one of: buffered, framed")
+ help="transport to use, one of: buffered, framed, http")
parser.add_option('--container-limit', dest='container_limit', type='int', default=None)
parser.add_option('--string-limit', dest='string_limit', type='int', default=None)
- parser.set_defaults(port=9090, verbose=1, proto='binary')
+ parser.set_defaults(port=9090, verbose=1, proto='binary', transport='buffered')
options, args = parser.parse_args()
# Print TServer log to stdout so that the test-runner can redirect it to log files