Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
73 changes: 57 additions & 16 deletions tests/model_registry/model_catalog/test_default_model_catalog.py
Original file line number Diff line number Diff line change
@@ -1,46 +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

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"
13 changes: 13 additions & 0 deletions tests/model_registry/model_catalog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,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"
assert default_catalog["id"] == "default_catalog"
assert default_catalog["type"] == "yaml"
assert default_catalog["properties"].get("yamlCatalogPath") == "/default/default-catalog.yaml"