Skip to content

Commit 4d40abb

Browse files
authored
Merge branch 'main' into cluster_h
2 parents 0fcf098 + 8897f6a commit 4d40abb

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

tests/model_registry/model_catalog/conftest.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import random
22
from typing import Generator, Any
3+
4+
import yaml
35
from simple_logger.logger import get_logger
46

57
import pytest
@@ -17,6 +19,7 @@
1719
wait_for_model_catalog_api,
1820
get_model_str,
1921
execute_get_command,
22+
get_default_model_catalog_yaml,
2023
)
2124
from tests.model_registry.utils import get_rest_headers
2225
from utilities.infra import get_openshift_token, login_with_user_password, create_inference_token
@@ -59,7 +62,15 @@ def updated_catalog_config_map(
5962
model_catalog_rest_url: list[str],
6063
model_registry_rest_headers: dict[str, str],
6164
) -> Generator[ConfigMap, None, None]:
62-
patches = {"data": {"sources.yaml": request.param["sources_yaml"]}}
65+
defaults = yaml.dump(
66+
get_default_model_catalog_yaml(config_map=catalog_config_map),
67+
default_flow_style=False,
68+
)
69+
catalog_str = f"""catalogs:
70+
{defaults}
71+
{request.param["sources_yaml"]}
72+
"""
73+
patches = {"data": {"sources.yaml": catalog_str}}
6374
if "sample_yaml" in request.param:
6475
for key in request.param["sample_yaml"]:
6576
patches["data"][key] = request.param["sample_yaml"][key]

tests/model_registry/model_catalog/test_custom_model_catalog.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
SAMPLE_MODEL_NAME2,
77
MULTIPLE_CUSTOM_CATALOG_VALUES,
88
SAMPLE_MODEL_NAME3,
9+
DEFAULT_CATALOG_ID,
910
)
1011
from ocp_resources.config_map import ConfigMap
1112
import pytest
@@ -67,10 +68,11 @@ def test_model_custom_catalog_list_sources(
6768
url=url,
6869
headers=model_registry_rest_headers,
6970
)["items"]
70-
71-
assert len(results) == len(expected_catalog_values)
71+
# since we expect one default catalog
72+
assert len(results) == len(expected_catalog_values) + 1
7273
ids_from_query = [result_entry["id"] for result_entry in results]
7374
ids_expected = [expected_entry["id"] for expected_entry in expected_catalog_values]
75+
ids_expected.append(DEFAULT_CATALOG_ID)
7476
assert sorted(ids_from_query) == sorted(ids_expected), f"Expected: {expected_catalog_values}. Actual: {results}"
7577

7678
def test_model_custom_catalog_get_models_by_source(

tests/model_registry/model_catalog/utils.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import json
22
from typing import Any
3+
import time
4+
import yaml
35

46
from kubernetes.dynamic import DynamicClient
57
from simple_logger.logger import get_logger
68

79
import requests
810
from timeout_sampler import retry
911

12+
from ocp_resources.config_map import ConfigMap
1013
from ocp_resources.pod import Pod
1114
from tests.model_registry.model_catalog.constants import (
1215
DEFAULT_CATALOG_NAME,
@@ -96,18 +99,16 @@ def validate_default_catalog(default_catalog) -> None:
9699

97100
def get_catalog_str(ids: list[str]) -> str:
98101
catalog_str: str = ""
99-
for id in ids:
102+
for index, id in enumerate(ids):
100103
catalog_str += f"""
101-
- name: Sample Catalog
104+
- name: Sample Catalog {index}
102105
id: {id}
103106
type: yaml
104107
enabled: true
105108
properties:
106109
yamlCatalogPath: {id.replace("_", "-")}.yaml
107110
"""
108-
return f"""catalogs:
109-
{catalog_str}
110-
"""
111+
return catalog_str
111112

112113

113114
def get_sample_yaml_str(models: list[str]) -> str:
@@ -123,6 +124,7 @@ def get_sample_yaml_str(models: list[str]) -> str:
123124

124125

125126
def get_model_str(model: str) -> str:
127+
current_time = int(time.time() * 1000)
126128
return f"""
127129
- name: {model}
128130
description: test description.
@@ -135,6 +137,8 @@ def get_model_str(model: str) -> str:
135137
libraryName: transformers
136138
artifacts:
137139
- uri: https://huggingface.co/{model}/resolve/main/consolidated.safetensors
140+
createTimeSinceEpoch: \"{str(current_time - 10000)}\"
141+
lastUpdateTimeSinceEpoch: \"{str(current_time)}\"
138142
"""
139143

140144

@@ -149,3 +153,7 @@ def get_validate_default_model_catalog_source(token: str, model_catalog_url: str
149153
assert result[0]["id"] == DEFAULT_CATALOG_ID
150154
assert result[0]["name"] == DEFAULT_CATALOG_NAME
151155
assert str(result[0]["enabled"]) == "True", result[0]["enabled"]
156+
157+
158+
def get_default_model_catalog_yaml(config_map: ConfigMap) -> str:
159+
return yaml.safe_load(config_map.instance.data["sources.yaml"])["catalogs"]

0 commit comments

Comments
 (0)