From a8ad74b9f08bd4e0f9e44ef34b9828c32b55b391 Mon Sep 17 00:00:00 2001 From: Yaron de Leeuw Date: Thu, 20 Oct 2016 12:20:22 -0400 Subject: [PATCH 1/2] add http-observatory tests Add a locally (docker) deployed http-observatory test. It requires a minimum score of 65, and also prints the test results to stdout. --- .../docker-compose-extra-observatory.yml | 31 ++++++++++++ tests/sls/nginx/httpobs.py | 48 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 tests/sls/nginx/docker-compose-extra-observatory.yml create mode 100644 tests/sls/nginx/httpobs.py diff --git a/tests/sls/nginx/docker-compose-extra-observatory.yml b/tests/sls/nginx/docker-compose-extra-observatory.yml new file mode 100644 index 00000000..714f3f33 --- /dev/null +++ b/tests/sls/nginx/docker-compose-extra-observatory.yml @@ -0,0 +1,31 @@ +version: '2' + +# This file adds a static network configuration to compose. +# That is because we need to know the host's ip, and it can change +# every time you run compose. (see GH: docker/docker#1143). +# +# We also add the hostname to the services that use it, and setup the +# observatory-cli container + +networks: + default: + ipam: + config: + - subnet: 172.101.0.0/16 + ip_range: 172.101.0.0/24 + gateway: 172.101.0.1 + + +services: + scanner: + extra_hosts: + build.servo.org.test: 172.101.0.1 + website: + extra_hosts: + build.servo.org.test: 172.101.0.1 + observatory-cli: + image: jarondl/observatory-cli + links: + - website + environment: + HTTPOBS_API_URL: http://website:57001/api/v1/ diff --git a/tests/sls/nginx/httpobs.py b/tests/sls/nginx/httpobs.py new file mode 100644 index 00000000..a125725a --- /dev/null +++ b/tests/sls/nginx/httpobs.py @@ -0,0 +1,48 @@ +import subprocess +import time +import os.path +from tempfile import TemporaryDirectory + +from tests.util import Failure, Success + +MINSCORE = '65' + + +def run(): + # set up + with TemporaryDirectory() as http_obs: + http_obs_dir = os.path.join(http_obs, 'http-observatory') + # getting the observatory code + subprocess.run(['git', 'clone', '--depth', '1', + 'https://github.com/mozilla/http-observatory.git', + http_obs_dir], check=True) + + docker_compose = [ + 'docker-compose', '-f', + os.path.join(http_obs_dir, 'docker-compose.yml'), + '-f', 'tests/sls/nginx/docker-compose-extra-observatory.yml'] + # getting the observatory up + subprocess.run(docker_compose + ['up', '-d'], check=True) + + # sleep for 5 seconds, to increase the chance everything is really up + print('sleep 5 seconds while composing up') + time.sleep(5) + + # check our site to get the report nicely formatted in stdout + subprocess.run(docker_compose + + ['run', 'observatory-cli', 'build.servo.org.test', + '--format', 'report', '--rescan', + '--attempts', '20'], check=True) + + # check our site a second time with a minimal score + # to decide Fail / Pass + report = subprocess.run(docker_compose + ['run', 'observatory-cli', + 'build.servo.org.test', + '--min-score', MINSCORE], + stderr=subprocess.DEVNULL, + stdout=subprocess.DEVNULL) + if report.returncode == 0: + return Success('Http Observatory score more than %s' % MINSCORE) + else: + return Failure('Http Observatory score less than %s' % MINSCORE, + '') From 01ab242d055cea12f74e64ae05c7c8bff6d8be1e Mon Sep 17 00:00:00 2001 From: Yaron de Leeuw Date: Thu, 20 Oct 2016 12:43:26 -0400 Subject: [PATCH 2/2] STYLE: remove trailing whitespace --- tests/sls/nginx/docker-compose-extra-observatory.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sls/nginx/docker-compose-extra-observatory.yml b/tests/sls/nginx/docker-compose-extra-observatory.yml index 714f3f33..02e5cabe 100644 --- a/tests/sls/nginx/docker-compose-extra-observatory.yml +++ b/tests/sls/nginx/docker-compose-extra-observatory.yml @@ -25,7 +25,7 @@ services: build.servo.org.test: 172.101.0.1 observatory-cli: image: jarondl/observatory-cli - links: + links: - website environment: HTTPOBS_API_URL: http://website:57001/api/v1/