Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions tests/workbenches/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
from ocp_resources.route import Route
from ocp_resources.notebook import Notebook
from ocp_resources.cluster_operator import ClusterOperator


from utilities.constants import Labels
from utilities.constants import Labels, Timeout
from utilities import constants
from utilities.constants import INTERNAL_IMAGE_REGISTRY_PATH

Expand All @@ -36,17 +37,38 @@ def users_persistent_volume_claim(
yield pvc


@pytest.fixture(scope="function")
def internal_image_registry(
admin_client: DynamicClient,
) -> Generator[ClusterOperator | None, None, None]:
try:
image_registry = ClusterOperator(
client=admin_client,
name="image-registry",
ensure_exists=True,
)
image_registry.wait_for_condition(
condition=ClusterOperator.Condition.AVAILABLE,
status=ClusterOperator.Condition.Status.TRUE,
timeout=Timeout.TIMEOUT_30SEC,
)
yield image_registry
except ResourceNotFoundError:
yield None


@pytest.fixture(scope="function")
def minimal_image() -> Generator[str, None, None]:
"""Provides a full image name of a minimal workbench image"""
image_name = "jupyter-minimal-notebook" if py_config.get("distribution") == "upstream" else "s2i-minimal-notebook"
yield f"{INTERNAL_IMAGE_REGISTRY_PATH}/{py_config['applications_namespace']}/{image_name}:{'2024.2'}"
yield f"{image_name}:{'2024.2'}"


@pytest.fixture(scope="function")
def default_notebook(
request: pytest.FixtureRequest,
admin_client: DynamicClient,
internal_image_registry: ClusterOperator | None,
minimal_image: str,
) -> Generator[Notebook, None, None]:
"""Returns a new Notebook CR for a given namespace, name, and image"""
Expand All @@ -62,6 +84,13 @@ def default_notebook(
# Set the correct username
username = get_username(dyn_client=admin_client)

# Set the image path based on internal image registry status
minimal_image_path = (
f"{INTERNAL_IMAGE_REGISTRY_PATH}/{py_config['applications_namespace']}/{minimal_image}"
if internal_image_registry
else ":" + minimal_image.rsplit(":", maxsplit=1)[1]
)

probe_config = {
"failureThreshold": 3,
"httpGet": {
Expand All @@ -83,6 +112,7 @@ def default_notebook(
"notebooks.opendatahub.io/inject-oauth": "true",
"opendatahub.io/accelerator-name": "",
"opendatahub.io/service-mesh": "false",
"notebooks.opendatahub.io/last-image-selection": minimal_image,
},
"labels": {
Labels.Openshift.APP: name,
Expand Down Expand Up @@ -114,9 +144,9 @@ def default_notebook(
" "
f'--ServerApp.tornado_settings={{"user":"{username}","hub_host":"https://{route.host}","hub_prefix":"/projects/{namespace}"}}', # noqa: E501 line too long
},
{"name": "JUPYTER_IMAGE", "value": minimal_image},
{"name": "JUPYTER_IMAGE", "value": minimal_image_path},
],
"image": minimal_image,
"image": minimal_image_path,
"imagePullPolicy": "Always",
"livenessProbe": probe_config,
"name": name,
Expand Down