Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/model_registry/model_catalog/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@
- uri: https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3/resolve/main/consolidated.safetensors
"""
EXPECTED_CUSTOM_CATALOG_VALUES: dict[str, str] = {"id": CUSTOM_CATALOG_ID, "model_name": SAMPLE_CATALOG_FILE_NAME}
DEFAULT_CATALOG_NAME: str = "Default Catalog"
DEFAULT_CATALOG_ID: str = "default_catalog"
CATALOG_TYPE: str = "yaml"
DEFAULT_CATALOG_FILE: str = "/default/default-catalog.yaml"
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@
indirect=True,
)
@pytest.mark.usefixtures(
"updated_dsc_component_state_scope_session",
"model_registry_namespace",
"model_registry_metadata_db_resources",
"model_registry_instance",
"updated_catalog_config_map",
)
class TestModelCatalogRhec:
class TestModelCatalogCustom:
def test_model_custom_catalog_sources(
self: Self,
updated_catalog_config_map: tuple[ConfigMap, str, str],
Expand Down
74 changes: 57 additions & 17 deletions tests/model_registry/model_catalog/test_default_model_catalog.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,87 @@
import pytest
import yaml
from kubernetes.dynamic import DynamicClient

from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry
from ocp_resources.deployment import Deployment
from simple_logger.logger import get_logger
from typing import Self
from typing import Self, Any

from ocp_resources.pod import Pod
from ocp_resources.config_map import ConfigMap
from tests.model_registry.model_catalog.utils import validate_model_catalog_enabled, execute_get_command
from ocp_resources.route import Route
from ocp_resources.service import Service
from tests.model_registry.model_catalog.utils import (
validate_model_catalog_enabled,
execute_get_command,
validate_model_catalog_resource,
validate_default_catalog,
)

LOGGER = get_logger(name=__name__)


@pytest.mark.usefixtures(
"updated_dsc_component_state_scope_session",
"model_registry_namespace",
"model_registry_metadata_db_resources",
)
class TestModelCatalog:
def test_config_map_not_created(self: Self, catalog_config_map: ConfigMap):
# Check that the default configmaps does not exist, when model registry is not created
assert not catalog_config_map.exists

@pytest.mark.smoke
def test_config_map_exists(self: Self, model_registry_instance: ModelRegistry, catalog_config_map: ConfigMap):
# Check that the default configmaps is created when model registry is enabled.
def test_config_map_exists(self: Self, catalog_config_map: ConfigMap):
# Check that the default configmaps is created when model registry is
# enabled on data science cluster.
assert catalog_config_map.exists, f"{catalog_config_map.name} does not exist"
models = yaml.safe_load(catalog_config_map.instance.data["sources.yaml"])["catalogs"]
assert not models, f"Expected no default models to be present. Actual: {models}"
catalogs = yaml.safe_load(catalog_config_map.instance.data["sources.yaml"])["catalogs"]
assert catalogs
assert len(catalogs) == 1, f"{catalog_config_map.name} should have 1 catalog"
validate_default_catalog(default_catalog=catalogs[0])

def test_operator_pod_enabled_model_catalog(
self: Self, model_registry_instance: ModelRegistry, model_registry_operator_pod: Pod
@pytest.mark.parametrize(
"resource_name",
[
pytest.param(
Deployment,
id="test_model_catalog_deployment_resource",
),
pytest.param(
Route,
id="test_model_catalog_route_resource",
),
pytest.param(
Service,
id="test_model_catalog_service_resource",
),
pytest.param(
Pod,
id="test_model_catalog_pod_resource",
),
],
)
def test_model_catalog_resources_exists(
self: Self, admin_client: DynamicClient, model_registry_namespace: str, resource_name: Any
):
validate_model_catalog_resource(
kind=resource_name, admin_client=admin_client, namespace=model_registry_namespace
)

def test_operator_pod_enabled_model_catalog(self: Self, model_registry_operator_pod: Pod):
assert validate_model_catalog_enabled(pod=model_registry_operator_pod)

def test_model_catalog_no_custom_catalog(
self,
model_registry_instance: ModelRegistry,
model_catalog_rest_url: list[str],
model_registry_rest_headers: dict[str, str],
):
"""
Validate sources api for model catalog
"""
result = execute_get_command(
url=f"{model_catalog_rest_url[0]}sources",
headers=model_registry_rest_headers,
)["items"]
assert not result, f"Expected no custom models to be present. Actual: {result}"
assert result
assert len(result) == 1, f"Expected no custom models to be present. Actual: {result}"

def test_default_config_map_not_present(self: Self, model_registry_namespace: str):
# RHOAIENG-33246: Introduced a new configmap. It should be removed before 2.25 release
# This test is temporary. So not parameterizing it.
cfg_map = ConfigMap(name="default-model-catalog", namespace=model_registry_namespace)
assert not cfg_map.exists, f"{cfg_map.name} should not exist"
19 changes: 19 additions & 0 deletions tests/model_registry/model_catalog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

from class_generator.parsers.explain_parser import ResourceNotFoundError
from ocp_resources.pod import Pod
from tests.model_registry.model_catalog.constants import (
DEFAULT_CATALOG_NAME,
DEFAULT_CATALOG_ID,
CATALOG_TYPE,
DEFAULT_CATALOG_FILE,
)
from tests.model_registry.utils import get_model_catalog_pod

LOGGER = get_logger(name=__name__)
Expand Down Expand Up @@ -61,3 +67,16 @@ def wait_for_model_catalog_update(client: DynamicClient, model_registry_namespac
pods[0].wait_for_status(status=Pod.Status.RUNNING)
return True
return False


def validate_model_catalog_resource(kind: Any, admin_client: DynamicClient, namespace: str) -> None:
resource = list(kind.get(namespace=namespace, label_selector="component=model-catalog", dyn_client=admin_client))
assert resource
assert len(resource) == 1, f"Unexpected number of {kind} resources found: {[res.name for res in resource]}"


def validate_default_catalog(default_catalog) -> None:
assert default_catalog["name"] == DEFAULT_CATALOG_NAME
assert default_catalog["id"] == DEFAULT_CATALOG_ID
assert default_catalog["type"] == CATALOG_TYPE
assert default_catalog["properties"].get("yamlCatalogPath") == DEFAULT_CATALOG_FILE