Skip to content

Commit 456033d

Browse files
authored
Revert "Remove defaults from custom configmaps (#699)"
This reverts commit 56f4250.
1 parent 89c0fc2 commit 456033d

File tree

7 files changed

+71
-83
lines changed

7 files changed

+71
-83
lines changed

tests/model_registry/constants.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,4 @@ class ModelRegistryEndpoints:
6464
"mysql": 3306,
6565
}
6666
MODEL_REGISTRY_POD_FILTER: str = "component=model-registry"
67-
DEFAULT_CUSTOM_MODEL_CATALOG: str = "model-catalog-sources"
68-
DEFAULT_MODEL_CATALOG_CFG: str = "model-catalog-default-sources"
67+
DEFAULT_MODEL_CATALOG: str = "model-catalog-sources"

tests/model_registry/model_catalog/conftest.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@
1212

1313
from ocp_resources.route import Route
1414
from ocp_resources.service_account import ServiceAccount
15-
from tests.model_registry.constants import DEFAULT_CUSTOM_MODEL_CATALOG
15+
from tests.model_registry.constants import DEFAULT_MODEL_CATALOG
1616
from tests.model_registry.model_catalog.constants import (
1717
SAMPLE_MODEL_NAME3,
1818
CUSTOM_CATALOG_ID1,
19+
DEFAULT_CATALOG_ID,
1920
DEFAULT_CATALOG_FILE,
2021
CATALOG_CONTAINER,
21-
REDHAT_AI_CATALOG_ID,
2222
)
2323
from tests.model_registry.model_catalog.utils import (
2424
is_model_catalog_ready,
2525
wait_for_model_catalog_api,
2626
get_model_str,
2727
execute_get_command,
2828
get_model_catalog_pod,
29+
get_default_model_catalog_yaml,
2930
)
3031
from tests.model_registry.utils import get_rest_headers
3132
from utilities.infra import get_openshift_token, login_with_user_password, create_inference_token
@@ -37,7 +38,7 @@
3738

3839
@pytest.fixture(scope="class")
3940
def catalog_config_map(admin_client: DynamicClient, model_registry_namespace: str) -> ConfigMap:
40-
return ConfigMap(name=DEFAULT_CUSTOM_MODEL_CATALOG, client=admin_client, namespace=model_registry_namespace)
41+
return ConfigMap(name=DEFAULT_MODEL_CATALOG, client=admin_client, namespace=model_registry_namespace)
4142

4243

4344
@pytest.fixture(scope="class")
@@ -79,7 +80,15 @@ def updated_catalog_config_map(
7980
model_catalog_rest_url: list[str],
8081
model_registry_rest_headers: dict[str, str],
8182
) -> Generator[ConfigMap, None, None]:
82-
patches = {"data": {"sources.yaml": request.param["sources_yaml"]}}
83+
defaults = yaml.dump(
84+
get_default_model_catalog_yaml(config_map=catalog_config_map),
85+
default_flow_style=False,
86+
)
87+
catalog_str = f"""catalogs:
88+
{defaults}
89+
{request.param["sources_yaml"]}
90+
"""
91+
patches = {"data": {"sources.yaml": catalog_str}}
8392
if "sample_yaml" in request.param:
8493
for key in request.param["sample_yaml"]:
8594
patches["data"][key] = request.param["sample_yaml"][key]
@@ -150,7 +159,7 @@ def user_token_for_api_calls(
150159
def randomly_picked_model_from_default_catalog(
151160
model_catalog_rest_url: list[str], user_token_for_api_calls: str
152161
) -> dict[Any, Any]:
153-
url = f"{model_catalog_rest_url[0]}models?source={REDHAT_AI_CATALOG_ID}&pageSize=100"
162+
url = f"{model_catalog_rest_url[0]}models?source={DEFAULT_CATALOG_ID}&pageSize=100"
154163
result = execute_get_command(
155164
url=url,
156165
headers=get_rest_headers(token=user_token_for_api_calls),
@@ -172,7 +181,7 @@ def default_catalog_api_response(
172181
) -> dict[Any, Any]:
173182
"""Fetch all models from default catalog API (used for data validation tests)"""
174183
return execute_get_command(
175-
url=f"{model_catalog_rest_url[0]}models?source={REDHAT_AI_CATALOG_ID}&pageSize=100",
184+
url=f"{model_catalog_rest_url[0]}models?source={DEFAULT_CATALOG_ID}&pageSize=100",
176185
headers=model_registry_rest_headers,
177186
)
178187

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any
2-
31
CUSTOM_CATALOG_ID1: str = "sample_custom_catalog1"
42
CUSTOM_CATALOG_ID2: str = "sample_custom_catalog2"
53
SAMPLE_MODEL_NAME1 = "mistralai/Mistral-7B-Instruct-v0.3"
@@ -10,20 +8,9 @@
108
{"id": CUSTOM_CATALOG_ID1, "model_name": SAMPLE_MODEL_NAME1},
119
{"id": CUSTOM_CATALOG_ID2, "model_name": SAMPLE_MODEL_NAME2},
1210
]
13-
11+
DEFAULT_CATALOG_NAME: str = "Default Catalog"
12+
DEFAULT_CATALOG_ID: str = "default_catalog"
13+
CATALOG_TYPE: str = "yaml"
14+
DEFAULT_CATALOG_FILE: str = "/shared-data/default-catalog.yaml"
1415
SAMPLE_MODEL_NAME3 = "mistralai/Ministral-8B-Instruct-2410"
1516
CATALOG_CONTAINER: str = "catalog"
16-
DEFAULT_CATALOGS: dict[str, Any] = {
17-
"redhat_ai_models": {
18-
"name": "Red Hat AI models",
19-
"type": "yaml",
20-
"properties": {"yamlCatalogPath": "/shared-data/models-catalog.yaml"},
21-
},
22-
"redhat_ai_validated_models": {
23-
"name": "Red Hat AI validated models",
24-
"type": "yaml",
25-
"properties": {"yamlCatalogPath": "/shared-data/validated-models-catalog.yaml"},
26-
},
27-
}
28-
REDHAT_AI_CATALOG_ID: str = next(iter(DEFAULT_CATALOGS))
29-
DEFAULT_CATALOG_FILE: str = DEFAULT_CATALOGS[REDHAT_AI_CATALOG_ID]["properties"]["yamlCatalogPath"]

tests/model_registry/model_catalog/test_custom_model_catalog.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
SAMPLE_MODEL_NAME2,
77
MULTIPLE_CUSTOM_CATALOG_VALUES,
88
SAMPLE_MODEL_NAME3,
9+
DEFAULT_CATALOG_ID,
910
)
1011
from ocp_resources.config_map import ConfigMap
1112
import pytest
@@ -67,11 +68,12 @@ def test_model_custom_catalog_list_sources(
6768
url=url,
6869
headers=model_registry_rest_headers,
6970
)["items"]
71+
# since we expect one default catalog
72+
assert len(results) == len(expected_catalog_values) + 1
7073
ids_from_query = [result_entry["id"] for result_entry in results]
7174
ids_expected = [expected_entry["id"] for expected_entry in expected_catalog_values]
72-
assert set(ids_expected).issubset(set(ids_from_query)), (
73-
f"Expected model catalogs: {expected_catalog_values}. Actual model catalogs: {results}"
74-
)
75+
ids_expected.append(DEFAULT_CATALOG_ID)
76+
assert sorted(ids_from_query) == sorted(ids_expected), f"Expected: {expected_catalog_values}. Actual: {results}"
7577

7678
def test_model_custom_catalog_get_models_by_source(
7779
self: Self,

tests/model_registry/model_catalog/test_default_model_catalog.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
from ocp_resources.config_map import ConfigMap
1212
from ocp_resources.route import Route
1313
from ocp_resources.service import Service
14-
from tests.model_registry.constants import DEFAULT_CUSTOM_MODEL_CATALOG, DEFAULT_MODEL_CATALOG_CFG
15-
from tests.model_registry.model_catalog.constants import REDHAT_AI_CATALOG_ID, CATALOG_CONTAINER
14+
from tests.model_registry.model_catalog.constants import DEFAULT_CATALOG_ID, CATALOG_CONTAINER
1615
from tests.model_registry.model_catalog.utils import (
1716
validate_model_catalog_enabled,
1817
execute_get_command,
@@ -37,30 +36,26 @@
3736
@pytest.mark.skip_must_gather
3837
class TestModelCatalogGeneral:
3938
@pytest.mark.parametrize(
40-
"model_catalog_config_map, expected_catalogs",
39+
"model_catalog_config_map",
4140
[
4241
pytest.param(
43-
{"configmap_name": DEFAULT_CUSTOM_MODEL_CATALOG},
44-
0,
42+
{"configmap_name": "model-catalog-sources"},
4543
id="test_model_catalog_sources_configmap",
4644
),
4745
pytest.param(
48-
{"configmap_name": DEFAULT_MODEL_CATALOG_CFG},
49-
2,
46+
{"configmap_name": "model-catalog-default-sources"},
5047
id="test_model_catalog_default_sources_configmap",
5148
),
5249
],
5350
indirect=["model_catalog_config_map"],
5451
)
55-
def test_config_map_exists(self: Self, model_catalog_config_map: ConfigMap, expected_catalogs: int):
52+
def test_config_map_exists(self: Self, model_catalog_config_map: ConfigMap):
5653
# Check that model catalog configmaps is created when model registry is
5754
# enabled on data science cluster.
5855
catalogs = yaml.safe_load(model_catalog_config_map.instance.data["sources.yaml"])["catalogs"]
59-
assert len(catalogs) == expected_catalogs, (
60-
f"{model_catalog_config_map.name} should have {expected_catalogs} catalog"
61-
)
62-
if expected_catalogs:
63-
validate_default_catalog(catalogs=catalogs)
56+
assert catalogs
57+
assert len(catalogs) == 1, f"{model_catalog_config_map.name} should have 1 catalog"
58+
validate_default_catalog(default_catalog=catalogs[0])
6459

6560
@pytest.mark.parametrize(
6661
"resource_name, expected_resource_count",
@@ -175,7 +170,7 @@ def test_model_default_catalog_get_model_by_name(
175170
"""
176171
model_name = randomly_picked_model_from_default_catalog["name"]
177172
result = execute_get_command(
178-
url=f"{model_catalog_rest_url[0]}sources/{REDHAT_AI_CATALOG_ID}/models/{model_name}",
173+
url=f"{model_catalog_rest_url[0]}sources/{DEFAULT_CATALOG_ID}/models/{model_name}",
179174
headers=get_rest_headers(token=user_token_for_api_calls),
180175
)
181176
differences = list(diff(randomly_picked_model_from_default_catalog, result))
@@ -192,7 +187,7 @@ def test_model_default_catalog_get_model_artifact(
192187
"""
193188
model_name = randomly_picked_model_from_default_catalog["name"]
194189
result = execute_get_command(
195-
url=f"{model_catalog_rest_url[0]}sources/{REDHAT_AI_CATALOG_ID}/models/{model_name}/artifacts",
190+
url=f"{model_catalog_rest_url[0]}sources/{DEFAULT_CATALOG_ID}/models/{model_name}/artifacts",
196191
headers=get_rest_headers(token=user_token_for_api_calls),
197192
)["items"]
198193
assert result, f"No artifacts found for {model_name}"
@@ -290,25 +285,24 @@ def test_model_default_catalog_random_artifact(
290285
LOGGER.info(f"Required artifact fields from OpenAPI schema: {required_artifact_fields}")
291286

292287
random_model = random.choice(seq=default_model_catalog_yaml_content.get("models", []))
293-
model_name = random_model["name"]
294-
LOGGER.info(f"Random model: {model_name}")
288+
LOGGER.info(f"Random model: {random_model['name']}")
295289

296290
api_model_artifacts = execute_get_command(
297-
url=f"{model_catalog_rest_url[0]}sources/{REDHAT_AI_CATALOG_ID}/models/{model_name}/artifacts",
291+
url=f"{model_catalog_rest_url[0]}sources/{DEFAULT_CATALOG_ID}/models/{random_model['name']}/artifacts",
298292
headers=model_registry_rest_headers,
299293
)["items"]
300294

301295
yaml_artifacts = random_model.get("artifacts", [])
302-
assert api_model_artifacts, f"No artifacts found in API for {model_name}"
303-
assert yaml_artifacts, f"No artifacts found in YAML for {model_name}"
296+
assert api_model_artifacts, f"No artifacts found in API for {random_model['name']}"
297+
assert yaml_artifacts, f"No artifacts found in YAML for {random_model['name']}"
304298

305299
# Validate all required fields are present in both YAML and API artifact
306300
# FAILS artifactType is not in YAML nor in API until https://issues.redhat.com/browse/RHOAIENG-35569 is fixed
307301
for field in required_artifact_fields:
308302
for artifact in yaml_artifacts:
309-
assert field in artifact, f"YAML artifact for {model_name} missing REQUIRED field: {field}"
303+
assert field in artifact, f"YAML artifact for {random_model['name']} missing REQUIRED field: {field}"
310304
for artifact in api_model_artifacts:
311-
assert field in artifact, f"API artifact for {model_name} missing REQUIRED field: {field}"
305+
assert field in artifact, f"API artifact for {random_model['name']} missing REQUIRED field: {field}"
312306

313307
# Filter artifacts to only include schema-defined fields for comparison
314308
yaml_artifacts_filtered = [
@@ -319,5 +313,5 @@ def test_model_default_catalog_random_artifact(
319313
]
320314

321315
differences = list(diff(yaml_artifacts_filtered, api_artifacts_filtered))
322-
assert not differences, f"Artifacts mismatch for {model_name}: {differences}"
316+
assert not differences, f"Artifacts mismatch for {random_model['name']}: {differences}"
323317
LOGGER.info("Artifacts match")

tests/model_registry/model_catalog/utils.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import json
22
from typing import Any
33
import time
4+
import yaml
45

56
from kubernetes.dynamic import DynamicClient
67
from simple_logger.logger import get_logger
78

89
import requests
910
from timeout_sampler import retry
1011

12+
from ocp_resources.config_map import ConfigMap
1113
from ocp_resources.pod import Pod
1214
from tests.model_registry.model_catalog.constants import (
13-
DEFAULT_CATALOGS,
15+
DEFAULT_CATALOG_NAME,
16+
DEFAULT_CATALOG_ID,
17+
CATALOG_TYPE,
18+
DEFAULT_CATALOG_FILE,
1419
)
1520
from tests.model_registry.utils import get_model_catalog_pod, get_rest_headers
1621
from utilities.general import wait_for_pods_running
@@ -90,16 +95,11 @@ def validate_model_catalog_resource(
9095
)
9196

9297

93-
def validate_default_catalog(catalogs: list[dict[Any, Any]]) -> None:
94-
errors = ""
95-
for catalog in catalogs:
96-
expected_catalog = DEFAULT_CATALOGS.get(catalog["id"])
97-
assert expected_catalog, f"Unexpected catalog: {catalog}"
98-
for field in ["type", "name", "properties"]:
99-
if catalog[field] != expected_catalog[field]:
100-
errors += f"For {catalog['id']} expected {field}={expected_catalog[field]}, but got {catalog[field]}"
101-
102-
assert not errors, errors
98+
def validate_default_catalog(default_catalog) -> None:
99+
assert default_catalog["name"] == DEFAULT_CATALOG_NAME
100+
assert default_catalog["id"] == DEFAULT_CATALOG_ID
101+
assert default_catalog["type"] == CATALOG_TYPE
102+
assert default_catalog["properties"].get("yamlCatalogPath") == DEFAULT_CATALOG_FILE
103103

104104

105105
def get_catalog_str(ids: list[str]) -> str:
@@ -113,9 +113,7 @@ def get_catalog_str(ids: list[str]) -> str:
113113
properties:
114114
yamlCatalogPath: {id.replace("_", "-")}.yaml
115115
"""
116-
return f"""catalogs:
117-
{catalog_str}
118-
"""
116+
return catalog_str
119117

120118

121119
def get_sample_yaml_str(models: list[str]) -> str:
@@ -156,11 +154,14 @@ def get_validate_default_model_catalog_source(token: str, model_catalog_url: str
156154
headers=get_rest_headers(token=token),
157155
)["items"]
158156
assert result
159-
assert len(result) == 2, f"Expected no custom models to be present. Actual: {result}"
160-
ids_actual = [entry["id"] for entry in result]
161-
assert sorted(ids_actual) == sorted(DEFAULT_CATALOGS.keys()), (
162-
f"Actual default catalog entries: {ids_actual},Expected: {DEFAULT_CATALOGS.keys()}"
163-
)
157+
assert len(result) == 1, f"Expected no custom models to be present. Actual: {result}"
158+
assert result[0]["id"] == DEFAULT_CATALOG_ID
159+
assert result[0]["name"] == DEFAULT_CATALOG_NAME
160+
assert str(result[0]["enabled"]) == "True", result[0]["enabled"]
161+
162+
163+
def get_default_model_catalog_yaml(config_map: ConfigMap) -> str:
164+
return yaml.safe_load(config_map.instance.data["sources.yaml"])["catalogs"]
164165

165166

166167
def extract_schema_fields(openapi_schema: dict[Any, Any], schema_name: str) -> tuple[set[str], set[str]]:

tests/model_registry/rest_api/test_multiple_mr.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry
77
from ocp_resources.pod import Pod
88

9-
from tests.model_registry.constants import (
10-
MR_INSTANCE_BASE_NAME,
11-
NUM_RESOURCES,
12-
DEFAULT_CUSTOM_MODEL_CATALOG,
13-
DEFAULT_MODEL_CATALOG_CFG,
14-
)
9+
from tests.model_registry.constants import MR_INSTANCE_BASE_NAME, NUM_RESOURCES, DEFAULT_MODEL_CATALOG
1510
from tests.model_registry.rest_api.utils import (
1611
validate_resource_attributes,
1712
get_register_model_data,
@@ -55,25 +50,26 @@ def test_validate_one_model_catalog_configmap(
5550
self: Self, admin_client: DynamicClient, model_registry_namespace: str
5651
):
5752
"""
58-
Validate that when multiple MR exists on a cluster, only two model catalog configmaps are created
53+
Validate that when multiple MR exists on a cluster, only one model catalog configmap is created
5954
"""
6055
config_map_names: list[str] = []
61-
expected_number_config_maps: int = 2
56+
expected_number_config_maps: int = 1
6257
for config_map in list(ConfigMap.get(namespace=model_registry_namespace, dyn_client=admin_client)):
63-
if config_map.name.startswith(tuple([DEFAULT_CUSTOM_MODEL_CATALOG, DEFAULT_MODEL_CATALOG_CFG])):
58+
if config_map.name.startswith(DEFAULT_MODEL_CATALOG):
6459
config_map_names.append(config_map.name)
6560
assert len(config_map_names) == expected_number_config_maps, (
66-
f"Expected {expected_number_config_maps} model catalog sources, found: {config_map_names}"
61+
f"Expected {expected_number_config_maps} modelcatalog sources, found: {config_map_names}"
6762
)
6863

69-
def test_validate_model_catalog_pods(self: Self, admin_client: DynamicClient, model_registry_namespace: str):
64+
# FAILS until https://github.com/opendatahub-io/model-registry-operator/pull/298/ is merged downstream
65+
def test_validate_one_model_catalog_pod(self: Self, admin_client: DynamicClient, model_registry_namespace: str):
7066
"""
71-
Validate that even when multiple MR exists on a cluster, only two model catalog pods are created
67+
Validate that even when multiple MR exists on a cluster, only one model catalog pod is created
7268
"""
7369
catalog_pods: list[Pod] = get_model_catalog_pod(
7470
client=admin_client, model_registry_namespace=model_registry_namespace
7571
)
76-
expected_number_pods: int = 2
72+
expected_number_pods: int = 1
7773

7874
assert len(catalog_pods) == expected_number_pods, (
7975
f"Expected {expected_number_pods} model catalog pods, found: {[pod.name for pod in catalog_pods]}"

0 commit comments

Comments
 (0)