Skip to content

Commit 01f773c

Browse files
committed
Test mod_wsgi in Evergreen
1 parent 3d9e2ea commit 01f773c

7 files changed

Lines changed: 175 additions & 18 deletions

File tree

.evergreen/config.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,15 @@ functions:
327327
${PREPARE_SHELL}
328328
sh ${DRIVERS_TOOLS}/.evergreen/stop-orchestration.sh
329329
330+
"run mod_wsgi tests":
331+
- command: shell.exec
332+
type: test
333+
params:
334+
working_dir: "src"
335+
script: |
336+
${PREPARE_SHELL}
337+
PYTHON_BINARY=${PYTHON_BINARY} MOD_WSGI_VERSION=${MOD_WSGI_VERSION} PROJECT_DIRECTORY=${PROJECT_DIRECTORY} sh ${PROJECT_DIRECTORY}/.evergreen/run-mod-wsgi-tests.sh
338+
330339
"run tests":
331340
- command: shell.exec
332341
type: test
@@ -622,6 +631,24 @@ tasks:
622631
TOPOLOGY: "server"
623632
- func: "run enterprise auth tests"
624633

634+
- name: "mod-wsgi-standalone"
635+
tags: ["mod_wsgi"]
636+
commands:
637+
- func: "bootstrap mongo-orchestration"
638+
vars:
639+
VERSION: "latest"
640+
TOPOLOGY: "server"
641+
- func: "run mod_wsgi tests"
642+
643+
- name: "mod-wsgi-replica-set"
644+
tags: ["mod_wsgi"]
645+
commands:
646+
- func: "bootstrap mongo-orchestration"
647+
vars:
648+
VERSION: "latest"
649+
TOPOLOGY: "replica_set"
650+
- func: "run mod_wsgi tests"
651+
625652
# }}}
626653

627654

@@ -842,6 +869,21 @@ axes:
842869
display_name: "Jython 2.7"
843870
variables:
844871
PYTHON_BINARY: "/opt/python/jython2.7/bin/jython"
872+
- id: mod-wsgi-version
873+
display_name: "mod_wsgi version"
874+
values:
875+
- id: "2.8"
876+
display_name: "mod_wsgi 2.8"
877+
variables:
878+
MOD_WSGI_VERSION: "2.8"
879+
- id: "3.5"
880+
display_name: "mod_wsgi 3.5"
881+
variables:
882+
MOD_WSGI_VERSION: "3.5"
883+
- id: "4.5.15"
884+
display_name: "mod_wsgi 4.5.15"
885+
variables:
886+
MOD_WSGI_VERSION: "4.5.15"
845887
- id: c-extensions
846888
display_name: "C Extensions"
847889
values:
@@ -1068,6 +1110,16 @@ buildvariants:
10681110
tasks:
10691111
- name: "test-enterprise-auth"
10701112

1113+
- matrix_name: "tests-mod-wsgi"
1114+
matrix_spec: {"python-version": ["2.4", "2.6", "2.7"], "mod-wsgi-version": "*"}
1115+
exclude_spec:
1116+
python-version: ["2.4"]
1117+
mod-wsgi-version: ["3.5", "4.5.15"]
1118+
display_name: "${mod-wsgi-version} ${python-version}"
1119+
run_on: ubuntu1204-test
1120+
tasks:
1121+
- ".mod_wsgi"
1122+
10711123
# Platform notes
10721124
# i386 builds of OpenSSL or Cyrus SASL are not available
10731125
# Ubuntu14.04 only supports 2.6+ with SSL

.evergreen/run-mod-wsgi-tests.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
set -o xtrace
3+
set -o errexit
4+
5+
APACHE=$(command -v apache2 || command -v /usr/lib/apache2/mpm-prefork/apache2) || true
6+
if [ -z "$APACHE" ]; then
7+
echo "Could not find apache2 binary"
8+
exit 1
9+
fi
10+
11+
PYTHON_VERSION=$(${PYTHON_BINARY} -c "import sys; sys.stdout.write('.'.join(str(val) for val in sys.version_info[:2]))")
12+
13+
if [ $MOD_WSGI_VERSION = "2.8" ] && [ $PYTHON_VERSION = "2.7" ]; then
14+
# mod_wsgi 2.8 segfaults when built against the toolchain Python 2.7. Build
15+
# against the system Python 2.7 instead.
16+
git clone https://github.com/GrahamDumpleton/mod_wsgi.git
17+
cd mod_wsgi
18+
git checkout tags/2.8
19+
./configure
20+
make
21+
export MOD_WSGI_SO=$(pwd)/.libs/mod_wsgi.so
22+
cd ..
23+
else
24+
export MOD_WSGI_SO=/opt/python/mod_wsgi/python_version/$PYTHON_VERSION/mod_wsgi_version/$MOD_WSGI_VERSION/mod_wsgi.so
25+
export PYTHONHOME=/opt/python/$PYTHON_VERSION
26+
fi
27+
28+
cd ..
29+
$APACHE -k start -f ${PROJECT_DIRECTORY}/test/mod_wsgi_test/apache22ubuntu1204.conf
30+
trap "$APACHE -k stop -f ${PROJECT_DIRECTORY}/test/mod_wsgi_test/apache22ubuntu1204.conf" EXIT HUP
31+
32+
set +e
33+
wget -t 1 -T 10 -O - "http://localhost:8080${PROJECT_DIRECTORY}"
34+
STATUS=$?
35+
set -e
36+
37+
# Debug
38+
cat error_log
39+
40+
if [ $STATUS != 0 ]; then
41+
exit $STATUS
42+
fi
43+
44+
${PYTHON_BINARY} ${PROJECT_DIRECTORY}/test/mod_wsgi_test/test_client.py -n 25000 -t 100 parallel http://localhost:8080${PROJECT_DIRECTORY}
45+
46+
${PYTHON_BINARY} ${PROJECT_DIRECTORY}/test/mod_wsgi_test/test_client.py -n 25000 serial http://localhost:8080${PROJECT_DIRECTORY}
47+

test/mod_wsgi_test/README.rst

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,12 @@ Compile Python
2727
We need a Python interpreter built as a shared library. Download the
2828
source tarball for each Python version tested, untar it, and run::
2929

30-
./configure --prefix=/some/directory --enable-shared
30+
./configure --prefix=/some/directory --enable-shared LDFLAGS="-Wl,--rpath=/some/directory/lib"
3131
make
3232
make install
3333

34-
This results in an executable named "python" and a shared
35-
library named something like "libpython2.7.so.1.0".
36-
It may be necessary to add /some/directory/lib to your system's
37-
LD_LIBRARY_PATH, or to make a symlink from your system's default library
38-
directory to the shared library. For example, on Ubuntu::
39-
40-
ln -s /some/directory/lib/libpython2.7.so.1.0 /usr/lib64/
34+
This results in an executable named "python" or "python3" and a shared
35+
library named something like "libpython2.7.so.1.0" or "libpython3.3m.so.1.0".
4136

4237
Compile mod_wsgi
4338
................
@@ -50,7 +45,7 @@ RedHat-like Linux::
5045
wget https://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
5146
tar xzf mod_wsgi-3.4.tar.gz
5247
cd mod_wsgi-3.4
53-
./configure --with-python=/some/directory/python
48+
./configure --with-python=/some/directory/bin/python LDFLAGS="-Wl,--rpath=/some/directory/lib"
5449
make
5550
make install
5651

@@ -66,8 +61,12 @@ listening on port 27017.
6661
Configure Apache
6762
................
6863

69-
Copy the appropriate version of ``mod_wsgi.so`` into Apache's modules
70-
directory. Start Apache with the ``mod_wsgi_test.conf`` in this directory.
64+
Set a MOD_WSGI_SO environment variable so our ``mod_wsgi_test.conf``
65+
can find and load mod_wsgi.so::
66+
67+
export MOD_WSGI_SO=/path/to/mod_wsgi.so
68+
69+
Start Apache with one of the config files in this directory.
7170

7271
Run the test
7372
------------
@@ -90,7 +89,7 @@ The ``test_client.py`` script merely makes HTTP requests to Apache. Its
9089
exit code is non-zero if any of its requests fails, for example with an
9190
HTTP 500.
9291

93-
The core of the test is in the WSGI script, ``mod_wsgi_test.wsgi`.
92+
The core of the test is in the WSGI script, ``mod_wsgi_test.wsgi``.
9493
This script inserts some documents into MongoDB at startup, then queries
9594
documents for each HTTP request.
9695

@@ -100,7 +99,6 @@ the test will fail when PyMongo exhausts its file descriptors.
10099
Automation
101100
----------
102101

103-
At MongoDB, Inc. we use a Jenkins job that tests each combination in the
104-
matrix. The job copies the appropriate version of ``mod_wsgi.so`` into
105-
place, sets up Apache, starts a single server or replica set,
106-
and runs ``test_client.py`` with the proper arguments.
102+
At MongoDB, Inc. we use a continuous integration job that tests each
103+
combination in the matrix. The job starts up Apache, starts a single server
104+
or replica set, and runs ``test_client.py`` with the proper arguments.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This is a minimal httpd.conf file written for Apache 2.2 on Amazon Linux
2+
3+
# The modules directory is here by default.
4+
# ServerRoot "/etc/httpd"
5+
DocumentRoot ${PWD}
6+
PidFile ${PWD}/apache2.pid
7+
8+
# Bind to localhost only, don't require sudo.
9+
Listen 127.0.0.1:8080
10+
11+
# Required modules.
12+
LoadModule authz_host_module modules/mod_authz_host.so
13+
# Needed so we can set a custom log location.
14+
LoadModule log_config_module modules/mod_log_config.so
15+
16+
ErrorLog ${PWD}/error_log
17+
CustomLog ${PWD}/access_log combined
18+
19+
<Directory "/">
20+
AllowOverride None
21+
Order Deny,Allow
22+
Deny from All
23+
</Directory>
24+
25+
<Directory ${PWD}>
26+
AllowOverride None
27+
Order Allow,Deny
28+
Allow from All
29+
</Directory>
30+
31+
Include ${PROJECT_DIRECTORY}/test/mod_wsgi_test/mod_wsgi_test.conf
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This is a minimal httpd.conf file written for Apache 2.2 on Ubuntu 12.04
2+
3+
# The modules directory is here on Ubuntu.
4+
ServerRoot "/usr/lib/apache2"
5+
DocumentRoot ${PWD}
6+
PidFile ${PWD}/apache2.pid
7+
8+
# Bind to localhost only, don't require sudo.
9+
Listen 127.0.0.1:8080
10+
11+
# Required modules.
12+
LoadModule authz_host_module modules/mod_authz_host.so
13+
14+
ErrorLog ${PWD}/error_log
15+
CustomLog ${PWD}/access_log combined
16+
17+
<Directory "/">
18+
AllowOverride None
19+
Order Deny,Allow
20+
Deny from All
21+
</Directory>
22+
23+
<Directory ${PWD}>
24+
AllowOverride None
25+
Order Allow,Deny
26+
Allow from All
27+
</Directory>
28+
29+
Include ${PROJECT_DIRECTORY}/test/mod_wsgi_test/mod_wsgi_test.conf

test/mod_wsgi_test/mod_wsgi_test.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# Minimal test of PyMongo in a WSGI application, see bug PYTHON-353
1616

17-
LoadModule wsgi_module modules/mod_wsgi.so
17+
LoadModule wsgi_module ${MOD_WSGI_SO}
1818

1919
# Avoid permissions issues
2020
WSGISocketPrefix /tmp/

test/mod_wsgi_test/mod_wsgi_test.wsgi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ except:
5555
def application(environ, start_response):
5656
results = list(collection.find().batch_size(10))
5757
assert len(results) == ndocs
58-
output = 'python %s, mod_wsgi %s, pymongo %s' % (
58+
output = ' python %s, mod_wsgi %s, pymongo %s ' % (
5959
sys.version, mod_wsgi_version, pymongo.version)
6060
response_headers = [('Content-Length', str(len(output)))]
6161
start_response('200 OK', response_headers)

0 commit comments

Comments
 (0)