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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from tests.model_registry.constants import DEFAULT_MODEL_CATALOG_CM
from tests.model_registry.model_catalog.constants import DEFAULT_CATALOGS
from tests.model_registry.model_catalog.catalog_config.utils import validate_model_catalog_configmap_data
from tests.model_registry.utils import execute_get_command
from tests.model_registry.model_catalog.utils import assert_source_error_state_message

LOGGER = get_logger(name=__name__)

Expand Down Expand Up @@ -75,105 +75,19 @@ def test_modify_default_catalog_configmap_reconciles(
"non-existent-catalog.yaml: no such file or directory",
id="test_source_error_invalid_path",
),
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
""",
"includedModels cannot be empty for Hugging Face catalog",
id="test_hf_source_no_include_model",
),
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
includedModels:
- abc-random*
""",
'failed to expand model patterns: wildcard pattern "abc-random*" is not supported - '
"Hugging Face requires a specific organization",
id="test_hf_source_invalid_organization",
),
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
includedModels:
- '*'
""",
'failed to expand model patterns: wildcard pattern "*" is not supported - '
"Hugging Face requires a specific organization",
id="test_hf_source_global_wildcard",
),
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
includedModels:
- '*/*'
""",
'failed to expand model patterns: wildcard pattern "*/*" is not supported - '
"Hugging Face requires a specific organization",
id="test_hf_source_global_org_wildcard",
),
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
includedModels:
- 'RedHatAI/'
""",
'failed to expand model patterns: wildcard pattern "RedHatAI/" is not supported - '
"Hugging Face requires a specific organization",
id="test_hf_source_empty_model_name",
),
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
includedModels:
- '*RedHatAI*'
""",
'failed to expand model patterns: wildcard pattern "*RedHatAI*" is not supported - '
"Hugging Face requires a specific organization",
id="test_hf_source_multiple_wildcards",
),
],
indirect=["updated_catalog_config_map_scope_function"],
)
def test_source_error_state(
def test_default_source_error_state(
self: Self,
updated_catalog_config_map_scope_function: ConfigMap,
model_catalog_rest_url: list[str],
model_registry_rest_headers: dict[str, str],
expected_error_message,
expected_error_message: str,
):
results = execute_get_command(
url=f"{model_catalog_rest_url[0]}sources",
headers=model_registry_rest_headers,
)["items"]
# pick the relevant source first by id:
matched_source = [result for result in results if result["id"] == "error_catalog"]
assert matched_source, f"Matched expected source not found: {results}"
assert matched_source[0]["status"] == "error"
assert expected_error_message in matched_source[0]["error"], (
f"Expected error: {expected_error_message} not found in {matched_source[0]['error']}"
assert_source_error_state_message(
model_catalog_rest_url=model_catalog_rest_url,
model_registry_rest_headers=model_registry_rest_headers,
expected_error_message=expected_error_message,
source_id="error_catalog",
)
1 change: 1 addition & 0 deletions tests/model_registry/model_catalog/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def updated_catalog_config_map_scope_function(
wait_for_model_catalog_api(url=model_catalog_rest_url[0], headers=model_registry_rest_headers)
yield catalog_config_map
is_model_catalog_ready(client=admin_client, model_registry_namespace=model_registry_namespace)
wait_for_model_catalog_api(url=model_catalog_rest_url[0], headers=model_registry_rest_headers)


@pytest.fixture(scope="class")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import pytest
from simple_logger.logger import get_logger
from typing import Self

from ocp_resources.config_map import ConfigMap
from tests.model_registry.model_catalog.utils import assert_source_error_state_message

LOGGER = get_logger(name=__name__)

pytestmark = [
pytest.mark.usefixtures(
"updated_dsc_component_state_scope_session",
"model_registry_namespace",
)
]


class TestHuggingFaceNegative:
@pytest.mark.parametrize(
"updated_catalog_config_map_scope_function, expected_error_message",
[
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
""",
"includedModels cannot be empty for Hugging Face catalog",
id="test_hf_source_no_include_model",
),
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
includedModels:
- abc-random*
""",
'failed to expand model patterns: wildcard pattern "abc-random*" is not supported - '
"Hugging Face requires a specific organization",
id="test_hf_source_invalid_organization",
),
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
includedModels:
- '*'
""",
'failed to expand model patterns: wildcard pattern "*" is not supported - '
"Hugging Face requires a specific organization",
id="test_hf_source_global_wildcard",
),
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
includedModels:
- '*/*'
""",
'failed to expand model patterns: wildcard pattern "*/*" is not supported - '
"Hugging Face requires a specific organization",
id="test_hf_source_global_org_wildcard",
),
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
includedModels:
- 'RedHatAI/'
""",
'failed to expand model patterns: wildcard pattern "RedHatAI/" is not supported - '
"Hugging Face requires a specific organization",
id="test_hf_source_empty_model_name",
),
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
includedModels:
- '*RedHatAI*'
""",
'failed to expand model patterns: wildcard pattern "*RedHatAI*" is not supported - '
"Hugging Face requires a specific organization",
id="test_hf_source_multiple_wildcards",
),
pytest.param(
"""
catalogs:
- name: HuggingFace Hub
id: error_catalog
type: hf
enabled: true
properties:
allowedOrganization: "abc-random"
includedModels:
- '*'
""",
"failed to expand model patterns: no models found",
id="test_hf_source_non_existent_allowed_organization",
),
],
indirect=["updated_catalog_config_map_scope_function"],
)
def test_huggingface_source_error_state(
self: Self,
updated_catalog_config_map_scope_function: ConfigMap,
model_catalog_rest_url: list[str],
model_registry_rest_headers: dict[str, str],
expected_error_message: str,
):
assert_source_error_state_message(
model_catalog_rest_url=model_catalog_rest_url,
model_registry_rest_headers=model_registry_rest_headers,
expected_error_message=expected_error_message,
source_id="error_catalog",
)
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 @@ -251,3 +251,22 @@ def get_excluded_model_str(models: list[str]) -> str:
- {model_name}
"""
return excluded_models


def assert_source_error_state_message(
model_catalog_rest_url: list[str],
model_registry_rest_headers: dict[str, str],
expected_error_message: str,
source_id: str,
):
results = execute_get_command(
url=f"{model_catalog_rest_url[0]}sources",
headers=model_registry_rest_headers,
)["items"]
# pick the relevant source first by id:
matched_source = [result for result in results if result["id"] == source_id]
assert matched_source, f"Matched expected source not found: {results}"
assert matched_source[0]["status"] == "error"
assert expected_error_message in matched_source[0]["error"], (
f"Expected error: {expected_error_message} not found in {matched_source[0]['error']}"
)