From 29d25f0915dad93cd7f49eba89557a88c730eb23 Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Thu, 16 Mar 2017 17:52:58 +0800 Subject: [PATCH] Enable boulder tests on Python 3 --- .travis.yml | 28 ++++++++++++++++++++++++---- tests/boulder-integration.sh | 4 ++-- tests/manual-http-auth.sh | 4 +++- tests/run_http_server.py | 11 +++++++++++ 4 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 tests/run_http_server.py diff --git a/.travis.yml b/.travis.yml index 577dcbc40..22bde836e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,13 +78,33 @@ matrix: env: TOXENV=apacheconftest sudo: required - python: "3.3" - env: TOXENV=py33 + env: TOXENV=py33 BOULDER_INTEGRATION=1 + sudo: required + after_failure: + - sudo cat /var/log/mysql/error.log + - ps aux | grep mysql + services: docker - python: "3.4" - env: TOXENV=py34 + env: TOXENV=py34 BOULDER_INTEGRATION=1 + sudo: required + after_failure: + - sudo cat /var/log/mysql/error.log + - ps aux | grep mysql + services: docker - python: "3.5" - env: TOXENV=py35 + env: TOXENV=py35 BOULDER_INTEGRATION=1 + sudo: required + after_failure: + - sudo cat /var/log/mysql/error.log + - ps aux | grep mysql + services: docker - python: "3.6" - env: TOXENV=py36 + env: TOXENV=py36 BOULDER_INTEGRATION=1 + sudo: required + after_failure: + - sudo cat /var/log/mysql/error.log + - ps aux | grep mysql + services: docker - python: "2.7" env: TOXENV=nginxroundtrip diff --git a/tests/boulder-integration.sh b/tests/boulder-integration.sh index 6612b2e67..08c482676 100755 --- a/tests/boulder-integration.sh +++ b/tests/boulder-integration.sh @@ -82,7 +82,7 @@ CheckHooks() { # We start a server listening on the port for the # unrequested challenge to prevent regressions in #3601. -python -m SimpleHTTPServer $http_01_port & +python ./tests/run_http_server.py $http_01_port & python_server_pid=$! common --domains le1.wtf --preferred-challenges tls-sni-01 auth \ @@ -90,7 +90,7 @@ common --domains le1.wtf --preferred-challenges tls-sni-01 auth \ --post-hook 'echo wtf.post >> "$HOOK_TEST"'\ --renew-hook 'echo renew >> "$HOOK_TEST"' kill $python_server_pid -python -m SimpleHTTPServer $tls_sni_01_port & +python ./tests/run_http_server.py $tls_sni_01_port & python_server_pid=$! common --domains le2.wtf --preferred-challenges http-01 run \ --pre-hook 'echo wtf.pre >> "$HOOK_TEST"' \ diff --git a/tests/manual-http-auth.sh b/tests/manual-http-auth.sh index c4730392b..48c33f04b 100755 --- a/tests/manual-http-auth.sh +++ b/tests/manual-http-auth.sh @@ -1,10 +1,12 @@ #!/bin/sh uri_path=".well-known/acme-challenge/$CERTBOT_TOKEN" +# This script should be run from the top level. e.g. ./tests/manual-http-auth.sh +source_dir="$(pwd)" cd $(mktemp -d) mkdir -p $(dirname $uri_path) echo $CERTBOT_VALIDATION > $uri_path -python -m SimpleHTTPServer $http_01_port >/dev/null 2>&1 & +python "$source_dir/tests/run_http_server.py" $http_01_port >/dev/null 2>&1 & server_pid=$! while ! curl "http://localhost:$http_01_port/$uri_path" >/dev/null 2>&1; do sleep 1s diff --git a/tests/run_http_server.py b/tests/run_http_server.py new file mode 100644 index 000000000..fd1163816 --- /dev/null +++ b/tests/run_http_server.py @@ -0,0 +1,11 @@ +import runpy +import sys + +# Run Python's built-in HTTP server +# Usage: python ./tests/run_http_server.py port_num +# NOTE: This script should be compatible with 2.6, 2.7, 3.3+ + +# sys.argv (port number) is passed as-is to the HTTP server module +runpy.run_module( + 'http.server' if sys.version_info[0] == 3 else 'SimpleHTTPServer', + run_name='__main__')