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..02e5cabe --- /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, + '')