mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Check progress page up with curl
This commit is contained in:
@@ -110,7 +110,6 @@ commands:
|
|||||||
- run:
|
- run:
|
||||||
name: Run bootstrap checks
|
name: Run bootstrap checks
|
||||||
command: |
|
command: |
|
||||||
python3 -m pip install requests
|
|
||||||
py.test integration-tests/test_bootstrap.py -s
|
py.test integration-tests/test_bootstrap.py -s
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,36 +3,17 @@ Test running bootstrap script in different circumstances
|
|||||||
"""
|
"""
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import os
|
import os
|
||||||
import requests
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
def start_container(container_name, image, show_progress_page):
|
|
||||||
run_flags = [
|
|
||||||
"--detach",
|
|
||||||
"--name",
|
|
||||||
container_name,
|
|
||||||
image,
|
|
||||||
"/bin/bash",
|
|
||||||
"-c",
|
|
||||||
"sleep 1000s",
|
|
||||||
]
|
|
||||||
if show_progress_page:
|
|
||||||
# Use port-forwarding to be able to access the progress page when it starts
|
|
||||||
run_flags = ["--publish", "12000:80"] + run_flags
|
|
||||||
|
|
||||||
# Start a detached container
|
|
||||||
subprocess.check_call(["docker", "run"] + run_flags)
|
|
||||||
|
|
||||||
|
|
||||||
def install_pkgs(container_name, show_progress_page):
|
def install_pkgs(container_name, show_progress_page):
|
||||||
# Install python3 inside the ubuntu container
|
# Install python3 inside the ubuntu container
|
||||||
# There is no trusted Ubuntu+Python3 container we can use
|
# There is no trusted Ubuntu+Python3 container we can use
|
||||||
pkgs = ["python3"]
|
pkgs = ["python3"]
|
||||||
if show_progress_page:
|
if show_progress_page:
|
||||||
pkgs += ["systemd", "git"]
|
pkgs += ["systemd", "git", "curl"]
|
||||||
# Create the sudoers dir, so that the installer succesfully gets to the
|
# Create the sudoers dir, so that the installer succesfully gets to the
|
||||||
# point of starting jupyterhub and stopping the progress page server.
|
# point of starting jupyterhub and stopping the progress page server.
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
@@ -63,7 +44,21 @@ def run_bootstrap(container_name, image, show_progress_page=False):
|
|||||||
# stop container if it is already running
|
# stop container if it is already running
|
||||||
subprocess.run(["docker", "rm", "-f", container_name])
|
subprocess.run(["docker", "rm", "-f", container_name])
|
||||||
|
|
||||||
start_container(container_name, image, show_progress_page)
|
# Start a detached container
|
||||||
|
subprocess.check_call(
|
||||||
|
[
|
||||||
|
"docker",
|
||||||
|
"run",
|
||||||
|
"--detach",
|
||||||
|
"--name",
|
||||||
|
container_name,
|
||||||
|
image,
|
||||||
|
"/bin/bash",
|
||||||
|
"-c",
|
||||||
|
"sleep 1000s",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
install_pkgs(container_name, show_progress_page)
|
install_pkgs(container_name, show_progress_page)
|
||||||
|
|
||||||
bootstrap_script = get_bootstrap_script_location(container_name, show_progress_page)
|
bootstrap_script = get_bootstrap_script_location(container_name, show_progress_page)
|
||||||
@@ -115,12 +110,20 @@ def verify_progress_page(expected_status_code, timeout):
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
while not progress_page_status and (time.time() - start < timeout):
|
while not progress_page_status and (time.time() - start < timeout):
|
||||||
try:
|
try:
|
||||||
resp = requests.get("http://127.0.0.1:12000/index.html")
|
resp = subprocess.check_output(
|
||||||
if resp.status_code == expected_status_code:
|
[
|
||||||
|
"docker",
|
||||||
|
"exec",
|
||||||
|
"progress-page",
|
||||||
|
"curl",
|
||||||
|
"-i",
|
||||||
|
"http://localhost/index.html",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
if b"HTTP/1.0 200 OK" in resp:
|
||||||
progress_page_status = True
|
progress_page_status = True
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user