Changeset: dc95a5526107 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dc95a5526107 Modified Files: clients/examples/python/sqlsample.py clients/python2/monetdb/mapi.py clients/python2/monetdb/sql/connections.py clients/python2/test/runtests.py clients/python3/monetdb/mapi.py clients/python3/monetdb/sql/connections.py clients/python3/test/runtests.py sql/benchmarks/tpch/fileleak/Tests/delete_all.SQL.py sql/benchmarks/tpch/fileleak/Tests/leaks.SQL.py sql/test/BugTracker/Tests/python_escape.SF-1916844.SQL.py sql/test/concurrent/Tests/crash_on_concurrent_use.SF-1411926.SQL.py sql/test/concurrent/Tests/simple_select.SQL.py sql/test/mapi/Tests/python2_dbapi.SQL.bat sql/test/mapi/Tests/python2_dbapi.SQL.sh sql/test/mapi/Tests/python3_dbapi.SQL.bat sql/test/mapi/Tests/python3_dbapi.SQL.sh testing/Mtest.py.in Branch: default Log Message:
Like mclient, in Python you can specify UNIX socket directory in hostname. If the hostname starts with a / (slash) and unix_socket is not specified, use the hostname as the directory in which the UNIX domain socket can be found. If neither hostname nor unix_socket is specified, use a UNIX domain socket if the default file (/tmp/.s.monetdb.PORT) actually exists, otherwise connect to localhost/PORT. Mtest.py now sets MAPIHOST in the environment to the host name that is also used by mclient. This, so that the Python tests can find the host name. This makes that the Python tests work once again. diffs (232 lines): diff --git a/clients/examples/python/sqlsample.py b/clients/examples/python/sqlsample.py --- a/clients/examples/python/sqlsample.py +++ b/clients/examples/python/sqlsample.py @@ -20,7 +20,7 @@ import monetdb.sql import sys -dbh = monetdb.sql.Connection(port=int(sys.argv[1]),database=sys.argv[2],autocommit=True) +dbh = monetdb.sql.Connection(port=int(sys.argv[1]),database=sys.argv[2],hostname=sys.argv[3],autocommit=True) cursor = dbh.cursor(); cursor.execute('select 1;') diff --git a/clients/python2/monetdb/mapi.py b/clients/python2/monetdb/mapi.py --- a/clients/python2/monetdb/mapi.py +++ b/clients/python2/monetdb/mapi.py @@ -23,6 +23,7 @@ import socket import logging import struct import hashlib +import os from cStringIO import StringIO @@ -77,6 +78,14 @@ class Connection(object): unix_socket is used if hostname is not defined. """ + if hostname and hostname[:1] == '/' and not unix_socket: + unix_socket = '%s/.s.monetdb.%d' % (hostname, port) + hostname = None + if not unix_socket and os.path.exists("/tmp/.s.monetdb.%i" % port): + unix_socket = "/tmp/.s.monetdb.%i" % port + elif not hostname: + hostname = 'localhost' + self.hostname = hostname self.port = port self.username = username diff --git a/clients/python2/monetdb/sql/connections.py b/clients/python2/monetdb/sql/connections.py --- a/clients/python2/monetdb/sql/connections.py +++ b/clients/python2/monetdb/sql/connections.py @@ -44,8 +44,6 @@ class Connection(object): autocommit -- enable/disable auto commit (default: False) """ - if not unix_socket: - unix_socket = "/tmp/.s.monetdb.%i" % port # The DB API spec is not specific about this if host: diff --git a/clients/python2/test/runtests.py b/clients/python2/test/runtests.py --- a/clients/python2/test/runtests.py +++ b/clients/python2/test/runtests.py @@ -45,7 +45,7 @@ TSTDB = os.environ.get('TSTDB', 'demo') TSTHOSTNAME = os.environ.get('TSTHOSTNAME', 'localhost') TSTUSERNAME = os.environ.get('TSTUSERNAME', 'monetdb') TSTPASSWORD = os.environ.get('TSTPASSWORD', 'monetdb') -#TSTHOSTNAME = None # set to none if test a socket +#TSTHOSTNAME = os.environ.get('MAPIHOST') # set to this if testing a socket if os.environ.get("TSTDEBUG", "no") == "yes": diff --git a/clients/python3/monetdb/mapi.py b/clients/python3/monetdb/mapi.py --- a/clients/python3/monetdb/mapi.py +++ b/clients/python3/monetdb/mapi.py @@ -23,6 +23,7 @@ import socket import logging import struct import hashlib +import os from io import BytesIO @@ -78,6 +79,14 @@ class Connection(object): unix_socket is used if hostname is not defined. """ + if hostname and hostname[:1] == '/' and not unix_socket: + unix_socket = '%s/.s.monetdb.%d' % (hostname, port) + hostname = None + if not unix_socket and os.path.exists("/tmp/.s.monetdb.%i" % port): + unix_socket = "/tmp/.s.monetdb.%i" % port + elif not hostname: + hostname = 'localhost' + self.hostname = hostname self.port = port self.username = username diff --git a/clients/python3/monetdb/sql/connections.py b/clients/python3/monetdb/sql/connections.py --- a/clients/python3/monetdb/sql/connections.py +++ b/clients/python3/monetdb/sql/connections.py @@ -44,8 +44,6 @@ class Connection(object): autocommit -- enable/disable auto commit (default: False) """ - if not unix_socket: - unix_socket = "/tmp/.s.monetdb.%i" % port # The DB API spec is not specific about this if host: diff --git a/clients/python3/test/runtests.py b/clients/python3/test/runtests.py --- a/clients/python3/test/runtests.py +++ b/clients/python3/test/runtests.py @@ -45,7 +45,7 @@ TSTDB = os.environ.get('TSTDB', 'demo') TSTHOSTNAME = os.environ.get('TSTHOSTNAME', 'localhost') TSTUSERNAME = os.environ.get('TSTUSERNAME', 'monetdb') TSTPASSWORD = os.environ.get('TSTPASSWORD', 'monetdb') -TSTHOSTNAME = None # set to none if test a socket +TSTHOSTNAME = os.environ.get('MAPIHOST') # set to this if testing a socket if os.environ.get("TSTDEBUG", "no") == "yes": diff --git a/sql/benchmarks/tpch/fileleak/Tests/delete_all.SQL.py b/sql/benchmarks/tpch/fileleak/Tests/delete_all.SQL.py --- a/sql/benchmarks/tpch/fileleak/Tests/delete_all.SQL.py +++ b/sql/benchmarks/tpch/fileleak/Tests/delete_all.SQL.py @@ -5,8 +5,9 @@ import os, sys, time port = int(os.environ['MAPIPORT']) db = os.environ['TSTDB'] +host = os.environ['MAPIHOST'] -dbh = monetdb.sql.Connection(port=port,database=db,autocommit=True) +dbh = monetdb.sql.Connection(hostname=host,port=port,database=db,autocommit=True) cursor = dbh.cursor(); diff --git a/sql/benchmarks/tpch/fileleak/Tests/leaks.SQL.py b/sql/benchmarks/tpch/fileleak/Tests/leaks.SQL.py --- a/sql/benchmarks/tpch/fileleak/Tests/leaks.SQL.py +++ b/sql/benchmarks/tpch/fileleak/Tests/leaks.SQL.py @@ -5,8 +5,9 @@ import os, sys, time port = int(os.environ['MAPIPORT']) db = os.environ['TSTDB'] +host = os.environ['MAPIHOST'] -dbh = monetdb.sql.Connection(port=port,database=db,autocommit=True) +dbh = monetdb.sql.Connection(port=port,database=db,hostname=host,autocommit=True) cursor = dbh.cursor(); diff --git a/sql/test/BugTracker/Tests/python_escape.SF-1916844.SQL.py b/sql/test/BugTracker/Tests/python_escape.SF-1916844.SQL.py --- a/sql/test/BugTracker/Tests/python_escape.SF-1916844.SQL.py +++ b/sql/test/BugTracker/Tests/python_escape.SF-1916844.SQL.py @@ -2,7 +2,8 @@ import monetdb.sql import os dbh = monetdb.sql.Connection(database = os.environ['TSTDB'], - port = int(os.environ['MAPIPORT'])) + port = int(os.environ['MAPIPORT']), + hostname = os.environ['MAPIHOST']) cursor = dbh.cursor() diff --git a/sql/test/concurrent/Tests/crash_on_concurrent_use.SF-1411926.SQL.py b/sql/test/concurrent/Tests/crash_on_concurrent_use.SF-1411926.SQL.py --- a/sql/test/concurrent/Tests/crash_on_concurrent_use.SF-1411926.SQL.py +++ b/sql/test/concurrent/Tests/crash_on_concurrent_use.SF-1411926.SQL.py @@ -22,7 +22,7 @@ class Client(threading.Thread): def __init__(self, client): threading.Thread.__init__ (self) self.client = client - self.dbh = monetdb.sql.Connection(port=int(os.getenv('MAPIPORT')),database=os.getenv('TSTDB')) + self.dbh = monetdb.sql.Connection(port=int(os.getenv('MAPIPORT')),hostname=os.getenv('MAPIHOST'),database=os.getenv('TSTDB')) def run(self): cursor = self.dbh.cursor(); diff --git a/sql/test/concurrent/Tests/simple_select.SQL.py b/sql/test/concurrent/Tests/simple_select.SQL.py --- a/sql/test/concurrent/Tests/simple_select.SQL.py +++ b/sql/test/concurrent/Tests/simple_select.SQL.py @@ -7,7 +7,7 @@ class Client(threading.Thread): def __init__(self, client): threading.Thread.__init__ (self) self.client = client - self.dbh = monetdb.sql.Connection(port=int(os.getenv('MAPIPORT')),database=os.getenv('TSTDB')) + self.dbh = monetdb.sql.Connection(port=int(os.getenv('MAPIPORT')),hostname=os.getenv('MAPIHOST'),database=os.getenv('TSTDB')) def run(self): cursor = self.dbh.cursor(); diff --git a/sql/test/mapi/Tests/python2_dbapi.SQL.bat b/sql/test/mapi/Tests/python2_dbapi.SQL.bat --- a/sql/test/mapi/Tests/python2_dbapi.SQL.bat +++ b/sql/test/mapi/Tests/python2_dbapi.SQL.bat @@ -10,4 +10,4 @@ rem ignore PYTHONPATH from Mtest, it is rem Python that runs Mtest (currently always Python 2) set PYTHONPATH=%PYTHON2PATH% -%PYTHON2% "%testpath%/sqlsample.py" %MAPIPORT% %TSTDB% +%PYTHON2% "%testpath%/sqlsample.py" %MAPIPORT% %TSTDB% %MAPIHOST% diff --git a/sql/test/mapi/Tests/python2_dbapi.SQL.sh b/sql/test/mapi/Tests/python2_dbapi.SQL.sh --- a/sql/test/mapi/Tests/python2_dbapi.SQL.sh +++ b/sql/test/mapi/Tests/python2_dbapi.SQL.sh @@ -8,4 +8,4 @@ testpath="$TSTSRCBASE/clients/examples/p PYTHONPATH=${PYTHON2PATH} export PYTHONPATH -Mlog -x "${PYTHON2} ${testpath}/sqlsample.py $MAPIPORT $TSTDB" +Mlog -x "${PYTHON2} ${testpath}/sqlsample.py $MAPIPORT $TSTDB $MAPIHOST" diff --git a/sql/test/mapi/Tests/python3_dbapi.SQL.bat b/sql/test/mapi/Tests/python3_dbapi.SQL.bat --- a/sql/test/mapi/Tests/python3_dbapi.SQL.bat +++ b/sql/test/mapi/Tests/python3_dbapi.SQL.bat @@ -10,4 +10,4 @@ rem ignore PYTHONPATH from Mtest, it is rem Python that runs Mtest (currently always Python 2) set PYTHONPATH=%PYTHON3PATH% -%PYTHON3% "%testpath%/sqlsample.py" %MAPIPORT% %TSTDB% +%PYTHON3% "%testpath%/sqlsample.py" %MAPIPORT% %TSTDB% %MAPIHOST% diff --git a/sql/test/mapi/Tests/python3_dbapi.SQL.sh b/sql/test/mapi/Tests/python3_dbapi.SQL.sh --- a/sql/test/mapi/Tests/python3_dbapi.SQL.sh +++ b/sql/test/mapi/Tests/python3_dbapi.SQL.sh @@ -8,4 +8,4 @@ testpath="$TSTSRCBASE/clients/examples/p PYTHONPATH=${PYTHON3PATH} export PYTHONPATH -Mlog -x "${PYTHON3} ${testpath}/sqlsample.py $MAPIPORT $TSTDB" +Mlog -x "${PYTHON3} ${testpath}/sqlsample.py $MAPIPORT $TSTDB $MAPIHOST" diff --git a/testing/Mtest.py.in b/testing/Mtest.py.in --- a/testing/Mtest.py.in +++ b/testing/Mtest.py.in @@ -3171,6 +3171,7 @@ os.environ['HOST'] = HOST # check the host port actually works _, HOST = randomPort(30000,39999) os.environ['HOST'] = HOST +os.environ['MAPIHOST'] = HOST if os.name == "nt": SYST = "Windows" @@ -3752,6 +3753,7 @@ def main(argv) : SOCK = "--set mapi_usock=%s/.s.monetdb.%s" % \ (sockdir, env['MAPIPORT']) HOST = sockdir + os.environ['MAPIHOST'] = HOST except: SOCK = "" else: _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list