Test progress page started

This commit is contained in:
GeorgianaElena
2020-08-18 23:56:37 +03:00
parent 1ce172ae3e
commit e65749bad1

View File

@@ -1,10 +1,13 @@
""" """
Test running bootstrap script in different circumstances Test running bootstrap script in different circumstances
""" """
import concurrent.futures
import requests
import subprocess import subprocess
from textwrap import dedent from textwrap import dedent
import time
def run_bootstrap(container_name, image): def run_bootstrap(container_name, image, flags=None):
# stop container if it is already running # stop container if it is already running
subprocess.run([ subprocess.run([
'docker', 'rm', '-f', container_name 'docker', 'rm', '-f', container_name
@@ -12,7 +15,7 @@ def run_bootstrap(container_name, image):
# Start a detached Ubuntu 16.04 container # Start a detached Ubuntu 16.04 container
subprocess.check_call([ subprocess.check_call([
'docker', 'run', '--detach', '--name', container_name, image, 'docker', 'run', '--detach', '--publish', '12000:80', '--name', container_name, image,
'/bin/bash', '-c', 'sleep 1000s' '/bin/bash', '-c', 'sleep 1000s'
]) ])
# Install python3 inside the ubuntu container # Install python3 inside the ubuntu container
@@ -20,9 +23,13 @@ def run_bootstrap(container_name, image):
subprocess.check_output([ subprocess.check_output([
'docker', 'exec', container_name, 'apt-get', 'update' 'docker', 'exec', container_name, 'apt-get', 'update'
]) ])
if flags:
pkgs = ['python3', 'systemd', 'git']
else:
pkgs = ['python3']
subprocess.check_output([ subprocess.check_output([
'docker', 'exec', container_name, 'apt-get', 'install', '--yes', 'python3' 'docker', 'exec', container_name, 'apt-get', 'install', '--yes'] + pkgs
]) )
# Copy only the bootstrap script to container, so this is faster # Copy only the bootstrap script to container, so this is faster
subprocess.check_call([ subprocess.check_call([
'docker', 'docker',
@@ -34,7 +41,7 @@ def run_bootstrap(container_name, image):
return subprocess.run([ return subprocess.run([
'docker', 'exec', '-i', container_name, 'docker', 'exec', '-i', container_name,
'python3', '/srv/bootstrap/bootstrap.py' 'python3', '/srv/bootstrap/bootstrap.py'
], check=False, stdout=subprocess.PIPE, encoding='utf-8') ] + flags, check=False, stdout=subprocess.PIPE, encoding='utf-8')
def test_ubuntu_too_old(): def test_ubuntu_too_old():
""" """
@@ -54,3 +61,29 @@ def test_inside_no_systemd_docker():
For local development, see http://tljh.jupyter.org/en/latest/contributing/dev-setup.html For local development, see http://tljh.jupyter.org/en/latest/contributing/dev-setup.html
""").strip() """).strip()
assert output.returncode == 1 assert output.returncode == 1
def verify_progress_page(expected_status_code):
progress_page_status = False
while True:
try:
r = requests.get('http://127.0.0.1:12000/index.html')
status = r.status_code
if status == expected_status_code:
progress_page_status = True
break;
except Exception as e:
time.sleep(5)
continue;
return progress_page_status
def test_progress_page():
with concurrent.futures.ThreadPoolExecutor() as executor:
future = executor.submit(run_bootstrap, 'progress-page', 'ubuntu:18.04', ['--show-progress-page'])
# Check if progress page started
started = verify_progress_page(200)
assert started
return_value = future.result()