|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING |
| 4 | + |
| 5 | +import requests |
| 6 | + |
| 7 | +import allure |
| 8 | +import pytest |
| 9 | + |
| 10 | +from tests.containers import docker_utils |
| 11 | +from tests.containers.workbenches.workbench_image_test import WorkbenchContainer, skip_if_not_workbench_image |
| 12 | + |
| 13 | +if TYPE_CHECKING: |
| 14 | + import docker.models.images |
| 15 | + |
| 16 | + |
| 17 | +class TestJupyterLabImage: |
| 18 | + """Tests for JupyterLab Workbench images in this repository.""" |
| 19 | + |
| 20 | + APP_ROOT_HOME = "/opt/app-root/src" |
| 21 | + |
| 22 | + @allure.issue("RHOAIENG-11156") |
| 23 | + @allure.description("Check that the HTML for the spinner is contained in the initial page.") |
| 24 | + def test_spinner_html_loaded(self, image: str) -> None: |
| 25 | + skip_if_not_jupyterlab_image(image) |
| 26 | + |
| 27 | + container = WorkbenchContainer(image=image, user=4321, group_add=[0]) |
| 28 | + # if no env is specified, the image will run |
| 29 | + # > 4321 3334 3319 0 10:36 pts/0 00:00:01 /mnt/rosetta /opt/app-root/bin/python3.11 /opt/app-root/bin/jupyter-lab |
| 30 | + # > --ServerApp.root_dir=/opt/app-root/src --ServerApp.ip= --ServerApp.allow_origin=* --ServerApp.open_browser=False |
| 31 | + # which does not let us open a notebook and get a spinner, we need to disable auth at a minimum |
| 32 | + |
| 33 | + # These NOTEBOOK_ARGS are what ODH Dashboard uses, |
| 34 | + # and we also have them in the Kustomize test files for Makefile tests |
| 35 | + container.with_env("NOTEBOOK_ARGS", "\n".join([ |
| 36 | + "--ServerApp.port=8888", |
| 37 | + "--ServerApp.token=''", |
| 38 | + "--ServerApp.password=''", |
| 39 | + "--ServerApp.base_url=/notebook/opendatahub/jovyan", |
| 40 | + "--ServerApp.quit_button=False", |
| 41 | + """--ServerApp.tornado_settings={"user":"jovyan","hub_host":"https://opendatahub.io","hub_prefix":"/notebookController/jovyan"}"""])) |
| 42 | + try: |
| 43 | + # we changed base_url, and wait_for_readiness=True would attempt connections to / |
| 44 | + container.start(wait_for_readiness=False) |
| 45 | + container._connect(base_url="/notebook/opendatahub/jovyan") |
| 46 | + |
| 47 | + host_ip = container.get_container_host_ip() |
| 48 | + host_port = container.get_exposed_port(container.port) |
| 49 | + response = requests.get(f"http://{host_ip}:{host_port}/notebook/opendatahub/jovyan") |
| 50 | + assert response.status_code == 200 |
| 51 | + assert "text/html" in response.headers["content-type"] |
| 52 | + assert 'class="pf-v6-c-spinner"' in response.text |
| 53 | + finally: |
| 54 | + docker_utils.NotebookContainer(container).stop(timeout=0) |
| 55 | + |
| 56 | + |
| 57 | +def skip_if_not_jupyterlab_image(image: str) -> docker.models.images.Image: |
| 58 | + image_metadata = skip_if_not_workbench_image(image) |
| 59 | + if "-jupyter-" not in image_metadata.labels['name']: |
| 60 | + pytest.skip( |
| 61 | + f"Image {image} does not have '-jupyter-' in {image_metadata.labels['name']=}'") |
| 62 | + |
| 63 | + return image_metadata |
0 commit comments