Skip to content

Commit 8897f6a

Browse files
authored
minor changes to the tests to ensure we can test default and custom together (#663)
1 parent 640b72c commit 8897f6a

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

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,
@@ -95,18 +98,16 @@ def validate_default_catalog(default_catalog) -> None:
9598

9699
def get_catalog_str(ids: list[str]) -> str:
97100
catalog_str: str = ""
98-
for id in ids:
101+
for index, id in enumerate(ids):
99102
catalog_str += f"""
100-
- name: Sample Catalog
103+
- name: Sample Catalog {index}
101104
id: {id}
102105
type: yaml
103106
enabled: true
104107
properties:
105108
yamlCatalogPath: {id.replace("_", "-")}.yaml
106109
"""
107-
return f"""catalogs:
108-
{catalog_str}
109-
"""
110+
return catalog_str
110111

111112

112113
def get_sample_yaml_str(models: list[str]) -> str:
@@ -122,6 +123,7 @@ def get_sample_yaml_str(models: list[str]) -> str:
122123

123124

124125
def get_model_str(model: str) -> str:
126+
current_time = int(time.time() * 1000)
125127
return f"""
126128
- name: {model}
127129
description: test description.
@@ -134,6 +136,8 @@ def get_model_str(model: str) -> str:
134136
libraryName: transformers
135137
artifacts:
136138
- uri: https://huggingface.co/{model}/resolve/main/consolidated.safetensors
139+
createTimeSinceEpoch: \"{str(current_time - 10000)}\"
140+
lastUpdateTimeSinceEpoch: \"{str(current_time)}\"
137141
"""
138142

139143

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

0 commit comments

Comments
 (0)