Skip to content

Commit 5d24e78

Browse files
committed
ModelCatalog: update default tests to reflect expected behavior
1 parent 4b221f1 commit 5d24e78

File tree

4 files changed

+60
-23
lines changed

4 files changed

+60
-23
lines changed

tests/model_registry/model_catalog/conftest.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,3 @@ def updated_catalog_config_map(
5454
wait_for_model_catalog_api(url=model_catalog_rest_url[0], headers=model_registry_rest_headers)
5555
yield catalog_config_map
5656
is_model_catalog_ready(client=admin_client, model_registry_namespace=model_registry_namespace)
57-
58-
59-
@pytest.fixture(scope="class")
60-
def expected_catalog_values(request: pytest.FixtureRequest) -> dict[str, str]:
61-
return request.param

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: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,78 @@
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 validate_model_catalog_enabled, execute_get_command, \
14+
validate_model_catalog_resource, validate_default_catalog
1115

1216
LOGGER = get_logger(name=__name__)
1317

1418

1519
@pytest.mark.usefixtures(
1620
"updated_dsc_component_state_scope_session",
1721
"model_registry_namespace",
18-
"model_registry_metadata_db_resources",
1922
)
2023
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
2424

25-
def test_config_map_exists(self: Self, model_registry_instance: ModelRegistry, catalog_config_map: ConfigMap):
26-
# Check that the default configmaps is created when model registry is enabled.
25+
def test_config_map_exists(self: Self, catalog_config_map: ConfigMap):
26+
# Check that the default configmaps is created when model registry is
27+
# enabled on data science cluster.
2728
assert catalog_config_map.exists, f"{catalog_config_map.name} does not exist"
28-
models = yaml.safe_load(catalog_config_map.instance.data["sources.yaml"])["catalogs"]
29-
assert not models, f"Expected no default models to be present. Actual: {models}"
29+
catalogs = yaml.safe_load(catalog_config_map.instance.data["sources.yaml"])["catalogs"]
30+
assert catalogs
31+
assert len(catalogs) == 1, f"{catalog_config_map.name} should have 1 catalog"
32+
validate_default_catalog(default_catalog=catalogs[0])
33+
34+
@pytest.mark.parametrize(
35+
"resource_name",
36+
[
37+
pytest.param(
38+
Deployment,
39+
id="test_model_catalog_deployment_resource",
40+
),
41+
pytest.param(
42+
Route,
43+
id="test_model_catalog_route_resource",
44+
),
45+
pytest.param(
46+
Service,
47+
id="test_model_catalog_service_resource",
48+
),
49+
pytest.param(
50+
Pod,
51+
id="test_model_catalog_pod_resource",
52+
),
53+
],
54+
)
55+
def test_model_catalog_resources_exists(self: Self, admin_client: DynamicClient, model_registry_namespace: str,
56+
resource_name: Any):
57+
validate_model_catalog_resource(kind=resource_name, admin_client=admin_client,
58+
namespace=model_registry_namespace)
3059

3160
def test_operator_pod_enabled_model_catalog(
32-
self: Self, model_registry_instance: ModelRegistry, model_registry_operator_pod: Pod
61+
self: Self, model_registry_operator_pod: Pod
3362
):
3463
assert validate_model_catalog_enabled(pod=model_registry_operator_pod)
3564

3665
def test_model_catalog_no_custom_catalog(
3766
self,
38-
model_registry_instance: ModelRegistry,
3967
model_catalog_rest_url: list[str],
4068
model_registry_rest_headers: dict[str, str],
4169
):
70+
"""
71+
Validate sources api for model catalog
72+
"""
4273
result = execute_get_command(
4374
url=f"{model_catalog_rest_url[0]}sources",
4475
headers=model_registry_rest_headers,
4576
)["items"]
46-
assert not result, f"Expected no custom models to be present. Actual: {result}"
77+
assert result
78+
assert len(result) == 1, f"Expected no custom models to be present. Actual: {result}"

tests/model_registry/model_catalog/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,16 @@ def wait_for_model_catalog_update(client: DynamicClient, model_registry_namespac
6161
pods[0].wait_for_status(status=Pod.Status.RUNNING)
6262
return True
6363
return False
64+
65+
def validate_model_catalog_resource(kind: Any, admin_client: DynamicClient, namespace: str) -> None:
66+
resource = list(kind.get(
67+
namespace=namespace, label_selector="component=model-catalog", dyn_client=admin_client
68+
))
69+
assert resource
70+
assert len(resource) == 1, f"Unexpected number of {kind} resources found: {[res.name for res in resource]}"
71+
72+
def validate_default_catalog(default_catalog) -> None:
73+
assert default_catalog["name"] == 'Default Catalog'
74+
assert default_catalog['id'] == 'default_catalog'
75+
assert default_catalog['type'] == 'yaml'
76+
assert default_catalog['properties'].get("yamlCatalogPath") == '/default-catalog.yaml'

0 commit comments

Comments
 (0)