Skip to content

Commit 97fc3d1

Browse files
committed
fix: address review comments
Signed-off-by: lugi0 <lgiorgi@redhat.com>
1 parent 59a6c5a commit 97fc3d1

File tree

3 files changed

+42
-41
lines changed

3 files changed

+42
-41
lines changed

tests/model_registry/model_catalog/conftest.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
REDHAT_AI_CATALOG_ID,
1919
)
2020
from tests.model_registry.model_catalog.utils import get_models_from_catalog_api
21-
from tests.model_registry.constants import CUSTOM_CATALOG_ID1
21+
from tests.model_registry.constants import CUSTOM_CATALOG_ID1, DEFAULT_CUSTOM_MODEL_CATALOG
2222
from tests.model_registry.utils import (
2323
get_rest_headers,
2424
is_model_catalog_ready,
@@ -225,3 +225,27 @@ def models_from_filter_query(
225225
LOGGER.info(f"Filter query '{filter_query}' returned {len(model_names)} models: {', '.join(model_names)}")
226226

227227
return model_names
228+
229+
230+
@pytest.fixture()
231+
def labels_configmap_patch(admin_client: DynamicClient, model_registry_namespace: str) -> dict[str, Any]:
232+
# Get the editable ConfigMap
233+
sources_cm = ConfigMap(name=DEFAULT_CUSTOM_MODEL_CATALOG, client=admin_client, namespace=model_registry_namespace)
234+
235+
# Parse current data and add test label
236+
current_data = yaml.safe_load(sources_cm.instance.data["sources.yaml"])
237+
238+
new_label = {
239+
"name": "test-dynamic",
240+
"displayName": "Dynamic Test Label",
241+
"description": "A label added during test execution",
242+
}
243+
244+
if "labels" not in current_data:
245+
current_data["labels"] = []
246+
current_data["labels"].append(new_label)
247+
248+
patches = {"data": {"sources.yaml": yaml.dump(current_data, default_flow_style=False)}}
249+
250+
with ResourceEditor(patches={sources_cm: patches}):
251+
yield patches
Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import pytest
2-
import yaml
3-
2+
from typing import Any
43
from kubernetes.dynamic import DynamicClient
54
from simple_logger.logger import get_logger
65

7-
from ocp_resources.config_map import ConfigMap
8-
from ocp_resources.resource import ResourceEditor
96

107
from utilities.infra import get_openshift_token
118
from timeout_sampler import TimeoutSampler
@@ -51,45 +48,24 @@ def test_labels_endpoint_configmap_updates(
5148
admin_client: DynamicClient,
5249
model_registry_namespace: str,
5350
model_catalog_rest_url: list[str],
51+
labels_configmap_patch: dict[str, Any],
5452
):
5553
"""
5654
Sanity test: Edit the editable ConfigMap and verify changes are reflected in API.
5755
"""
56+
_ = labels_configmap_patch
5857

59-
# Get the editable ConfigMap
60-
sources_cm = ConfigMap(name="model-catalog-sources", client=admin_client, namespace=model_registry_namespace)
61-
62-
# Parse current data and add test label
63-
current_data = yaml.safe_load(sources_cm.instance.data["sources.yaml"])
64-
65-
new_label = {
66-
"name": "test-dynamic",
67-
"displayName": "Dynamic Test Label",
68-
"description": "A label added during test execution",
69-
}
70-
71-
if "labels" not in current_data:
72-
current_data["labels"] = []
73-
current_data["labels"].append(new_label)
74-
75-
# Update ConfigMap temporarily
76-
patches = {"data": {"sources.yaml": yaml.dump(current_data, default_flow_style=False)}}
77-
78-
with ResourceEditor(patches={sources_cm: patches}):
79-
80-
def _check_updated_labels():
81-
# Get updated expected labels from ConfigMaps
82-
expected_labels = get_labels_from_configmaps(
83-
admin_client=admin_client, namespace=model_registry_namespace
84-
)
58+
def _check_updated_labels():
59+
# Get updated expected labels from ConfigMaps
60+
expected_labels = get_labels_from_configmaps(admin_client=admin_client, namespace=model_registry_namespace)
8561

86-
# Get labels from API
87-
api_labels = get_labels_from_api(
88-
model_catalog_rest_url=model_catalog_rest_url[0], user_token=get_openshift_token()
89-
)
62+
# Get labels from API
63+
api_labels = get_labels_from_api(
64+
model_catalog_rest_url=model_catalog_rest_url[0], user_token=get_openshift_token()
65+
)
9066

91-
# Verify they match (including the new label)
92-
verify_labels_match(expected_labels=expected_labels, api_labels=api_labels)
67+
# Verify they match (including the new label)
68+
verify_labels_match(expected_labels=expected_labels, api_labels=api_labels)
9369

94-
sampler = TimeoutSampler(wait_timeout=60, sleep=5, func=_check_updated_labels)
95-
next(iter(sampler))
70+
sampler = TimeoutSampler(wait_timeout=60, sleep=5, func=_check_updated_labels)
71+
next(iter(sampler))

tests/model_registry/model_catalog/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
CATALOG_CONTAINER,
2323
PERFORMANCE_DATA_DIR,
2424
)
25+
from tests.model_registry.constants import DEFAULT_CUSTOM_MODEL_CATALOG, DEFAULT_MODEL_CATALOG_CM
2526
from tests.model_registry.utils import execute_get_command
2627
from tests.model_registry.utils import get_rest_headers
2728

@@ -1138,13 +1139,13 @@ def get_labels_from_configmaps(admin_client: DynamicClient, namespace: str) -> L
11381139
labels = []
11391140

11401141
# Get labels from default ConfigMap
1141-
default_cm = ConfigMap(name="model-catalog-default-sources", client=admin_client, namespace=namespace)
1142+
default_cm = ConfigMap(name=DEFAULT_MODEL_CATALOG_CM, client=admin_client, namespace=namespace)
11421143
default_data = yaml.safe_load(default_cm.instance.data["sources.yaml"])
11431144
if "labels" in default_data:
11441145
labels.extend(default_data["labels"])
11451146

11461147
# Get labels from sources ConfigMap
1147-
sources_cm = ConfigMap(name="model-catalog-sources", client=admin_client, namespace=namespace)
1148+
sources_cm = ConfigMap(name=DEFAULT_CUSTOM_MODEL_CATALOG, client=admin_client, namespace=namespace)
11481149
sources_data = yaml.safe_load(sources_cm.instance.data["sources.yaml"])
11491150
if "labels" in sources_data:
11501151
labels.extend(sources_data["labels"])

0 commit comments

Comments
 (0)