Skip to content

Commit fb938b8

Browse files
authored
Merge branch 'main' into fix_ns
2 parents fe65e6c + 6a1f7e2 commit fb938b8

File tree

5 files changed

+79
-50
lines changed

5 files changed

+79
-50
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ARG TESTS_DIR=$HOME/opendatahub-tests/
66
ENV UV_PYTHON=python3.12
77
ENV UV_COMPILE_BYTECODE=1
88
ENV UV_NO_SYNC=1
9-
ENV UV_CACHE_DIR=${TESTS_DIR}/.cache
9+
ENV UV_NO_CACHE=1
1010

1111
ENV BIN_DIR="$HOME_DIR/.local/bin"
1212
ENV PATH="$PATH:$BIN_DIR"

tests/workbenches/conftest.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
1414
from ocp_resources.route import Route
1515
from ocp_resources.notebook import Notebook
16+
from ocp_resources.cluster_operator import ClusterOperator
1617

1718

18-
from utilities.constants import Labels
19+
from utilities.constants import Labels, Timeout
1920
from utilities import constants
2021
from utilities.constants import INTERNAL_IMAGE_REGISTRY_PATH
2122

@@ -36,17 +37,38 @@ def users_persistent_volume_claim(
3637
yield pvc
3738

3839

40+
@pytest.fixture(scope="function")
41+
def internal_image_registry(
42+
admin_client: DynamicClient,
43+
) -> Generator[ClusterOperator | None, None, None]:
44+
try:
45+
image_registry = ClusterOperator(
46+
client=admin_client,
47+
name="image-registry",
48+
ensure_exists=True,
49+
)
50+
image_registry.wait_for_condition(
51+
condition=ClusterOperator.Condition.AVAILABLE,
52+
status=ClusterOperator.Condition.Status.TRUE,
53+
timeout=Timeout.TIMEOUT_30SEC,
54+
)
55+
yield image_registry
56+
except ResourceNotFoundError:
57+
yield None
58+
59+
3960
@pytest.fixture(scope="function")
4061
def minimal_image() -> Generator[str, None, None]:
4162
"""Provides a full image name of a minimal workbench image"""
4263
image_name = "jupyter-minimal-notebook" if py_config.get("distribution") == "upstream" else "s2i-minimal-notebook"
43-
yield f"{INTERNAL_IMAGE_REGISTRY_PATH}/{py_config['applications_namespace']}/{image_name}:{'2024.2'}"
64+
yield f"{image_name}:{'2024.2'}"
4465

4566

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

87+
# Set the image path based on internal image registry status
88+
minimal_image_path = (
89+
f"{INTERNAL_IMAGE_REGISTRY_PATH}/{py_config['applications_namespace']}/{minimal_image}"
90+
if internal_image_registry
91+
else ":" + minimal_image.rsplit(":", maxsplit=1)[1]
92+
)
93+
6594
probe_config = {
6695
"failureThreshold": 3,
6796
"httpGet": {
@@ -83,6 +112,7 @@ def default_notebook(
83112
"notebooks.opendatahub.io/inject-oauth": "true",
84113
"opendatahub.io/accelerator-name": "",
85114
"opendatahub.io/service-mesh": "false",
115+
"notebooks.opendatahub.io/last-image-selection": minimal_image,
86116
},
87117
"labels": {
88118
Labels.Openshift.APP: name,
@@ -114,9 +144,9 @@ def default_notebook(
114144
" "
115145
f'--ServerApp.tornado_settings={{"user":"{username}","hub_host":"https://{route.host}","hub_prefix":"/projects/{namespace}"}}', # noqa: E501 line too long
116146
},
117-
{"name": "JUPYTER_IMAGE", "value": minimal_image},
147+
{"name": "JUPYTER_IMAGE", "value": minimal_image_path},
118148
],
119-
"image": minimal_image,
149+
"image": minimal_image_path,
120150
"imagePullPolicy": "Always",
121151
"livenessProbe": probe_config,
122152
"name": name,
Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import pytest
22

3-
from timeout_sampler import TimeoutExpiredError
3+
from kubernetes.dynamic.client import DynamicClient
44

55
from ocp_resources.pod import Pod
6+
from ocp_resources.namespace import Namespace
7+
from ocp_resources.notebook import Notebook
8+
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
69

710

811
class TestNotebook:
12+
@pytest.mark.smoke
913
@pytest.mark.parametrize(
1014
"unprivileged_model_namespace,users_persistent_volume_claim,default_notebook",
1115
[
@@ -25,25 +29,18 @@ class TestNotebook:
2529
)
2630
def test_create_simple_notebook(
2731
self,
28-
unprivileged_client,
29-
unprivileged_model_namespace,
30-
users_persistent_volume_claim,
31-
default_notebook,
32+
unprivileged_client: DynamicClient,
33+
unprivileged_model_namespace: Namespace,
34+
users_persistent_volume_claim: PersistentVolumeClaim,
35+
default_notebook: Notebook,
3236
):
3337
"""
3438
Create a simple Notebook CR with all necessary resources and see if the Notebook Operator creates it properly
3539
"""
36-
pods = Pod.get(
37-
dyn_client=unprivileged_client,
38-
namespace=unprivileged_model_namespace.name,
39-
label_selector=f"app={unprivileged_model_namespace.name}",
40+
notebook_pod = Pod(
41+
client=unprivileged_client,
42+
namespace=default_notebook.namespace,
43+
name=f"{default_notebook.name}-0",
4044
)
41-
assert pods, "The expected notebook pods were not found"
42-
43-
failed_pods = []
44-
for pod in pods:
45-
try:
46-
pod.wait_for_condition(condition=pod.Condition.READY, status=pod.Condition.Status.TRUE)
47-
except TimeoutExpiredError:
48-
failed_pods.append(pod)
49-
assert not failed_pods, f"The following pods failed to get READY when starting the notebook: {failed_pods}"
45+
notebook_pod.wait()
46+
notebook_pod.wait_for_condition(condition=Pod.Condition.READY, status=Pod.Condition.Status.TRUE)

utilities/infra.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,11 @@ def is_managed_cluster(client: DynamicClient) -> bool:
368368

369369
platform_statuses = infra.instance.status.platformStatus
370370

371-
for entries in platform_statuses.values():
372-
if isinstance(entries, kubernetes.dynamic.resource.ResourceField):
373-
if tags := entries.resourceTags:
374-
return next(b["value"] == "true" for b in tags if b["key"] == "red-hat-managed")
371+
for entry in platform_statuses.values():
372+
if isinstance(entry, kubernetes.dynamic.resource.ResourceField):
373+
if tags := entry.resourceTags:
374+
LOGGER.info(f"Infrastructure {infra.name} resource tags: {tags}")
375+
return any([tag["value"] == "true" for tag in tags if tag["key"] == "red-hat-managed"])
375376

376377
return False
377378

uv.lock

Lines changed: 24 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)