mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-10 19:42:58 +00:00
Better warnings
This commit is contained in:
@@ -23,9 +23,7 @@ def test_cli_args(container: TrackedContainer, http_client: requests.Session) ->
|
|||||||
logs = running_container.logs().decode("utf-8")
|
logs = running_container.logs().decode("utf-8")
|
||||||
LOGGER.debug(logs)
|
LOGGER.debug(logs)
|
||||||
assert "ERROR" not in logs
|
assert "ERROR" not in logs
|
||||||
warnings = [
|
warnings = TrackedContainer.get_warnings(logs)
|
||||||
warning for warning in logs.split("\n") if warning.startswith("WARNING")
|
|
||||||
]
|
|
||||||
assert not warnings
|
assert not warnings
|
||||||
assert "login_submit" not in resp.text
|
assert "login_submit" not in resp.text
|
||||||
|
|
||||||
@@ -48,9 +46,7 @@ def test_unsigned_ssl(
|
|||||||
assert "login_submit" in resp.text
|
assert "login_submit" in resp.text
|
||||||
logs = running_container.logs().decode("utf-8")
|
logs = running_container.logs().decode("utf-8")
|
||||||
assert "ERROR" not in logs
|
assert "ERROR" not in logs
|
||||||
warnings = [
|
warnings = TrackedContainer.get_warnings(logs)
|
||||||
warning for warning in logs.split("\n") if warning.startswith("WARNING")
|
|
||||||
]
|
|
||||||
assert not warnings
|
assert not warnings
|
||||||
|
|
||||||
|
|
||||||
@@ -218,9 +214,7 @@ def test_group_add(container: TrackedContainer) -> None:
|
|||||||
group_add=["users"], # Ensures write access to /home/jovyan
|
group_add=["users"], # Ensures write access to /home/jovyan
|
||||||
command=["start.sh", "id"],
|
command=["start.sh", "id"],
|
||||||
)
|
)
|
||||||
warnings = [
|
warnings = TrackedContainer.get_warnings(logs)
|
||||||
warning for warning in logs.split("\n") if warning.startswith("WARNING")
|
|
||||||
]
|
|
||||||
assert len(warnings) == 1
|
assert len(warnings) == 1
|
||||||
assert "Try setting gid=0" in warnings[0]
|
assert "Try setting gid=0" in warnings[0]
|
||||||
assert "uid=1010 gid=1010 groups=1010,100(users)" in logs
|
assert "uid=1010 gid=1010 groups=1010,100(users)" in logs
|
||||||
@@ -239,9 +233,7 @@ def test_set_uid(container: TrackedContainer) -> None:
|
|||||||
command=["start.sh", "id"],
|
command=["start.sh", "id"],
|
||||||
)
|
)
|
||||||
assert "uid=1010(jovyan) gid=0(root)" in logs
|
assert "uid=1010(jovyan) gid=0(root)" in logs
|
||||||
warnings = [
|
warnings = TrackedContainer.get_warnings(logs)
|
||||||
warning for warning in logs.split("\n") if warning.startswith("WARNING")
|
|
||||||
]
|
|
||||||
assert len(warnings) == 1
|
assert len(warnings) == 1
|
||||||
assert "--group-add=users" in warnings[0]
|
assert "--group-add=users" in warnings[0]
|
||||||
|
|
||||||
@@ -257,9 +249,7 @@ def test_set_uid_and_nb_user(container: TrackedContainer) -> None:
|
|||||||
command=["start.sh", "id"],
|
command=["start.sh", "id"],
|
||||||
)
|
)
|
||||||
assert "uid=1010(kitten) gid=0(root)" in logs
|
assert "uid=1010(kitten) gid=0(root)" in logs
|
||||||
warnings = [
|
warnings = TrackedContainer.get_warnings(logs)
|
||||||
warning for warning in logs.split("\n") if warning.startswith("WARNING")
|
|
||||||
]
|
|
||||||
assert len(warnings) == 1
|
assert len(warnings) == 1
|
||||||
assert "user is kitten but home is /home/jovyan" in warnings[0]
|
assert "user is kitten but home is /home/jovyan" in warnings[0]
|
||||||
|
|
||||||
|
@@ -5,7 +5,6 @@ import logging
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
import re
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from conftest import TrackedContainer
|
from conftest import TrackedContainer
|
||||||
@@ -65,10 +64,8 @@ def test_start_notebook(
|
|||||||
assert "ERROR" not in logs, "ERROR(s) found in logs"
|
assert "ERROR" not in logs, "ERROR(s) found in logs"
|
||||||
for exp_warning in expected_warnings:
|
for exp_warning in expected_warnings:
|
||||||
assert exp_warning in logs, f"Expected warning {exp_warning} not found in logs"
|
assert exp_warning in logs, f"Expected warning {exp_warning} not found in logs"
|
||||||
warnings = re.findall(r"^WARNING", logs, flags=re.MULTILINE)
|
warnings = TrackedContainer.get_warnings(logs)
|
||||||
assert len(expected_warnings) == len(
|
assert len(expected_warnings) == len(warnings)
|
||||||
warnings
|
|
||||||
), "Not found the number of expected warnings in logs"
|
|
||||||
# checking if the server is listening
|
# checking if the server is listening
|
||||||
if expected_start:
|
if expected_start:
|
||||||
resp = http_client.get("http://localhost:8888")
|
resp = http_client.get("http://localhost:8888")
|
||||||
|
@@ -107,6 +107,12 @@ class TrackedContainer:
|
|||||||
assert rv == 0 or rv["StatusCode"] == 0
|
assert rv == 0 or rv["StatusCode"] == 0
|
||||||
return logs
|
return logs
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_warnings(logs: str) -> list[str]:
|
||||||
|
return [
|
||||||
|
warning for warning in logs.split("\n") if warning.startswith("WARNING")
|
||||||
|
]
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
"""Kills and removes the tracked docker container."""
|
"""Kills and removes the tracked docker container."""
|
||||||
if self.container:
|
if self.container:
|
||||||
|
Reference in New Issue
Block a user