Skip to content

Commit f4f6dd4

Browse files
dbasunagYgnas
authored andcommitted
ModelCatalog: update default tests to reflect expected behavior (opendatahub-io#578)
* ModelCatalog: update default tests to reflect expected behavior * review comments
1 parent 57172dd commit f4f6dd4

File tree

4 files changed

+81
-21
lines changed

4 files changed

+81
-21
lines changed

tests/model_registry/model_catalog/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@
3838
- uri: https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3/resolve/main/consolidated.safetensors
3939
"""
4040
EXPECTED_CUSTOM_CATALOG_VALUES: dict[str, str] = {"id": CUSTOM_CATALOG_ID, "model_name": SAMPLE_CATALOG_FILE_NAME}
41+
DEFAULT_CATALOG_NAME: str = "Default Catalog"
42+
DEFAULT_CATALOG_ID: str = "default_catalog"
43+
CATALOG_TYPE: str = "yaml"
44+
DEFAULT_CATALOG_FILE: str = "/default/default-catalog.yaml"

tests/model_registry/model_catalog/test_custom_model_catalog.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@
2828
indirect=True,
2929
)
3030
@pytest.mark.usefixtures(
31-
"updated_dsc_component_state_scope_session",
3231
"model_registry_namespace",
33-
"model_registry_metadata_db_resources",
34-
"model_registry_instance",
3532
"updated_catalog_config_map",
3633
)
37-
class TestModelCatalogRhec:
34+
class TestModelCatalogCustom:
3835
def test_model_custom_catalog_sources(
3936
self: Self,
4037
updated_catalog_config_map: tuple[ConfigMap, str, str],
Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,87 @@
11
import pytest
22
import yaml
3+
from kubernetes.dynamic import DynamicClient
34

4-
from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry
5+
from ocp_resources.deployment import Deployment
56
from simple_logger.logger import get_logger
6-
from typing import Self
7+
from typing import Self, Any
78

89
from ocp_resources.pod import Pod
910
from ocp_resources.config_map import ConfigMap
10-
from tests.model_registry.model_catalog.utils import validate_model_catalog_enabled, execute_get_command
11+
from ocp_resources.route import Route
12+
from ocp_resources.service import Service
13+
from tests.model_registry.model_catalog.utils import (
14+
validate_model_catalog_enabled,
15+
execute_get_command,
16+
validate_model_catalog_resource,
17+
validate_default_catalog,
18+
)
1119

1220
LOGGER = get_logger(name=__name__)
1321

1422

1523
@pytest.mark.usefixtures(
1624
"updated_dsc_component_state_scope_session",
1725
"model_registry_namespace",
18-
"model_registry_metadata_db_resources",
1926
)
2027
class TestModelCatalog:
21-
def test_config_map_not_created(self: Self, catalog_config_map: ConfigMap):
22-
# Check that the default configmaps does not exist, when model registry is not created
23-
assert not catalog_config_map.exists
24-
25-
@pytest.mark.smoke
26-
def test_config_map_exists(self: Self, model_registry_instance: ModelRegistry, catalog_config_map: ConfigMap):
27-
# Check that the default configmaps is created when model registry is enabled.
28+
def test_config_map_exists(self: Self, catalog_config_map: ConfigMap):
29+
# Check that the default configmaps is created when model registry is
30+
# enabled on data science cluster.
2831
assert catalog_config_map.exists, f"{catalog_config_map.name} does not exist"
29-
models = yaml.safe_load(catalog_config_map.instance.data["sources.yaml"])["catalogs"]
30-
assert not models, f"Expected no default models to be present. Actual: {models}"
32+
catalogs = yaml.safe_load(catalog_config_map.instance.data["sources.yaml"])["catalogs"]
33+
assert catalogs
34+
assert len(catalogs) == 1, f"{catalog_config_map.name} should have 1 catalog"
35+
validate_default_catalog(default_catalog=catalogs[0])
3136

32-
def test_operator_pod_enabled_model_catalog(
33-
self: Self, model_registry_instance: ModelRegistry, model_registry_operator_pod: Pod
37+
@pytest.mark.parametrize(
38+
"resource_name",
39+
[
40+
pytest.param(
41+
Deployment,
42+
id="test_model_catalog_deployment_resource",
43+
),
44+
pytest.param(
45+
Route,
46+
id="test_model_catalog_route_resource",
47+
),
48+
pytest.param(
49+
Service,
50+
id="test_model_catalog_service_resource",
51+
),
52+
pytest.param(
53+
Pod,
54+
id="test_model_catalog_pod_resource",
55+
),
56+
],
57+
)
58+
def test_model_catalog_resources_exists(
59+
self: Self, admin_client: DynamicClient, model_registry_namespace: str, resource_name: Any
3460
):
61+
validate_model_catalog_resource(
62+
kind=resource_name, admin_client=admin_client, namespace=model_registry_namespace
63+
)
64+
65+
def test_operator_pod_enabled_model_catalog(self: Self, model_registry_operator_pod: Pod):
3566
assert validate_model_catalog_enabled(pod=model_registry_operator_pod)
3667

3768
def test_model_catalog_no_custom_catalog(
3869
self,
39-
model_registry_instance: ModelRegistry,
4070
model_catalog_rest_url: list[str],
4171
model_registry_rest_headers: dict[str, str],
4272
):
73+
"""
74+
Validate sources api for model catalog
75+
"""
4376
result = execute_get_command(
4477
url=f"{model_catalog_rest_url[0]}sources",
4578
headers=model_registry_rest_headers,
4679
)["items"]
47-
assert not result, f"Expected no custom models to be present. Actual: {result}"
80+
assert result
81+
assert len(result) == 1, f"Expected no custom models to be present. Actual: {result}"
82+
83+
def test_default_config_map_not_present(self: Self, model_registry_namespace: str):
84+
# RHOAIENG-33246: Introduced a new configmap. It should be removed before 2.25 release
85+
# This test is temporary. So not parameterizing it.
86+
cfg_map = ConfigMap(name="default-model-catalog", namespace=model_registry_namespace)
87+
assert not cfg_map.exists, f"{cfg_map.name} should not exist"

tests/model_registry/model_catalog/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
from class_generator.parsers.explain_parser import ResourceNotFoundError
1111
from ocp_resources.pod import Pod
12+
from tests.model_registry.model_catalog.constants import (
13+
DEFAULT_CATALOG_NAME,
14+
DEFAULT_CATALOG_ID,
15+
CATALOG_TYPE,
16+
DEFAULT_CATALOG_FILE,
17+
)
1218
from tests.model_registry.utils import get_model_catalog_pod
1319

1420
LOGGER = get_logger(name=__name__)
@@ -61,3 +67,16 @@ def wait_for_model_catalog_update(client: DynamicClient, model_registry_namespac
6167
pods[0].wait_for_status(status=Pod.Status.RUNNING)
6268
return True
6369
return False
70+
71+
72+
def validate_model_catalog_resource(kind: Any, admin_client: DynamicClient, namespace: str) -> None:
73+
resource = list(kind.get(namespace=namespace, label_selector="component=model-catalog", dyn_client=admin_client))
74+
assert resource
75+
assert len(resource) == 1, f"Unexpected number of {kind} resources found: {[res.name for res in resource]}"
76+
77+
78+
def validate_default_catalog(default_catalog) -> None:
79+
assert default_catalog["name"] == DEFAULT_CATALOG_NAME
80+
assert default_catalog["id"] == DEFAULT_CATALOG_ID
81+
assert default_catalog["type"] == CATALOG_TYPE
82+
assert default_catalog["properties"].get("yamlCatalogPath") == DEFAULT_CATALOG_FILE

0 commit comments

Comments
 (0)