-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from usabilla/nginx/logging
Nginx logging
- Loading branch information
Showing
7 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
# | ||
# A simple script to start a Docker container | ||
# and run Testinfra in it | ||
# Original script: https://gist.github.com/renatomefi/bbf44d4e8a2614b1390416c6189fbb8e | ||
# Author: @renatomefi https://github.com/renatomefi | ||
# | ||
|
||
set -eEuo pipefail | ||
|
||
# The first parameter is a Docker tag or image id | ||
declare -r DOCKER_NGINX_TAG="$1" | ||
|
||
declare -r TEST_SUITE="nginx_e2e" | ||
|
||
# Finally, run the tests! | ||
docker run --net="host" --rm -t \ | ||
-v "$(pwd)/test/e2e:/tests" \ | ||
-v "$(pwd)/tmp/test-results:/results" \ | ||
-v /var/run/docker.sock:/var/run/docker.sock:ro \ | ||
renatomefi/docker-testinfra:2 \ | ||
-m "$TEST_SUITE" --junitxml="/results/http-e2e-$DOCKER_NGINX_TAG.xml" \ | ||
--verbose --tag="$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--tag", action="store", help="The docker tag" | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def tag(request): | ||
return request.config.getoption("--tag") | ||
|
||
@pytest.fixture | ||
def container(host, tag): | ||
container = host.check_output('docker run -p 80 -d {}'.format(tag)) | ||
yield container | ||
host.check_output('docker stop {}'.format(container)) | ||
|
||
# Remove afterwads thus the tests still have access to the logs | ||
host.check_output('docker rm -f {}'.format(container)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.nginx_e2e | ||
def test_nginx_sigterm_handling(host, container): | ||
log_level = host.run('docker exec -t {} sh -c "sed -i \'s/error_log .*;/error_log stderr notice;/g\' /etc/nginx/nginx.conf"'.format(container)) | ||
assert log_level.rc is 0 | ||
assert u'stderr notice' in host.check_output('docker exec -t {} cat /etc/nginx/nginx.conf'.format(container)) | ||
|
||
nginx_reload = host.run('docker exec -t {} sh -c "nginx -s reload"'.format(container)) | ||
assert nginx_reload.rc is 0 | ||
|
||
nginx_stop = host.run('docker stop -t 3 {}'.format(container)) | ||
assert nginx_reload.rc is 0 | ||
|
||
logs = host.run('docker logs {}'.format(container)) | ||
|
||
assert u'signal 15 (SIGTERM) received, exiting' in logs.stderr | ||
assert u'exit' in logs.stderr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.nginx_e2e | ||
def test_nginx_logs_to_stdout_and_stderr(host, container): | ||
nginx_port = host.check_output("docker inspect " + container + " --format '{{ (index (index .NetworkSettings.Ports \"80/tcp\") 0).HostPort }}'") | ||
|
||
wget = host.run('wget -O /dev/null -S 127.0.0.1:{}/invalid'.format(nginx_port)) | ||
assert wget.rc is not 0 | ||
|
||
logs = host.run('docker logs {}'.format(container)) | ||
|
||
assert 'GET /invalid' in logs.stdout | ||
assert 'connect() to unix:/var/run/php-fpm.sock failed' in logs.stderr |