Skip to content

Commit fc6872f

Browse files
committed
Add custom catalog upgrade scenarios
1 parent f5797cd commit fc6872f

File tree

13 files changed

+347
-178
lines changed

13 files changed

+347
-178
lines changed

conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,17 @@ def _add_upgrade_test(_item: Item, _upgrade_deployment_modes: list[str]) -> bool
247247
# Add support to be able to reuse tests in both upgrade and fresh install scenarios
248248
if "install" in item.keywords:
249249
non_upgrade_tests.append(item)
250-
250+
if "post_upgrade" in item.keywords:
251+
post_upgrade_tests.append(item)
251252
elif "post_upgrade" in item.keywords and _add_upgrade_test(
252253
_item=item, _upgrade_deployment_modes=upgrade_deployment_modes
253254
):
254255
post_upgrade_tests.append(item)
255256
# Add support to be able to reuse tests in both upgrade and fresh install scenarios
256257
if "install" in item.keywords:
257258
non_upgrade_tests.append(item)
259+
if "pre_upgrade" in item.keywords:
260+
pre_upgrade_tests.append(item)
258261
else:
259262
non_upgrade_tests.append(item)
260263

tests/model_registry/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from ocp_resources.infrastructure import Infrastructure
1414
from ocp_resources.oauth import OAuth
1515
from ocp_resources.pod import Pod
16+
from ocp_resources.route import Route
1617
from ocp_resources.secret import Secret
1718
from ocp_resources.namespace import Namespace
1819
from ocp_resources.service import Service
@@ -43,6 +44,7 @@
4344
DB_RESOURCE_NAME,
4445
MR_INSTANCE_NAME,
4546
MODEL_REGISTRY_POD_FILTER,
47+
DEFAULT_MODEL_CATALOG,
4648
)
4749
from utilities.constants import Labels, Protocols
4850
from tests.model_registry.utils import (
@@ -590,3 +592,28 @@ def user_credentials_rbac() -> dict[str, str]:
590592
"idp_name": f"test-htpasswd-idp-{random_str}",
591593
"secret_name": f"test-htpasswd-secret-{random_str}",
592594
}
595+
596+
597+
@pytest.fixture(scope="class")
598+
def model_catalog_rest_url(model_registry_namespace: str, model_catalog_routes: list[Route]) -> list[str]:
599+
assert model_catalog_routes, f"Model catalog routes does not exist in {model_registry_namespace}"
600+
route_urls = [
601+
f"https://{route.instance.spec.host}:443/api/model_catalog/v1alpha1/" for route in model_catalog_routes
602+
]
603+
assert route_urls, (
604+
"Model catalog routes information could not be found from "
605+
f"routes:{[route.name for route in model_catalog_routes]}"
606+
)
607+
return route_urls
608+
609+
610+
@pytest.fixture(scope="class")
611+
def catalog_config_map(admin_client: DynamicClient, model_registry_namespace: str) -> ConfigMap:
612+
return ConfigMap(name=DEFAULT_MODEL_CATALOG, client=admin_client, namespace=model_registry_namespace)
613+
614+
615+
@pytest.fixture(scope="class")
616+
def model_catalog_routes(admin_client: DynamicClient, model_registry_namespace: str) -> list[Route]:
617+
return list(
618+
Route.get(namespace=model_registry_namespace, label_selector="component=model-catalog", dyn_client=admin_client)
619+
)

tests/model_registry/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,5 @@ class ModelRegistryEndpoints:
6565
}
6666
MODEL_REGISTRY_POD_FILTER: str = "component=model-registry"
6767
DEFAULT_MODEL_CATALOG: str = "model-catalog-sources"
68+
CUSTOM_CATALOG_ID1: str = "sample_custom_catalog1"
69+
SAMPLE_MODEL_NAME1 = "mistralai/Mistral-7B-Instruct-v0.3"

tests/model_registry/model_catalog/conftest.py

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import random
22
from typing import Generator, Any
3+
34
from simple_logger.logger import get_logger
45

56
import pytest
@@ -8,67 +9,47 @@
89
from ocp_resources.config_map import ConfigMap
910
from ocp_resources.resource import ResourceEditor
1011

11-
from ocp_resources.route import Route
1212
from ocp_resources.service_account import ServiceAccount
13-
from tests.model_registry.constants import DEFAULT_MODEL_CATALOG
14-
from tests.model_registry.model_catalog.constants import SAMPLE_MODEL_NAME3, CUSTOM_CATALOG_ID1, DEFAULT_CATALOG_ID
15-
from tests.model_registry.model_catalog.utils import (
13+
from tests.model_registry.constants import CUSTOM_CATALOG_ID1
14+
from tests.model_registry.model_catalog.constants import SAMPLE_MODEL_NAME3, DEFAULT_CATALOG_ID
15+
from tests.model_registry.utils import (
16+
get_rest_headers,
1617
is_model_catalog_ready,
1718
wait_for_model_catalog_api,
1819
get_model_str,
1920
execute_get_command,
21+
get_custom_model_catalog_cm_data,
2022
)
21-
from tests.model_registry.utils import get_rest_headers
2223
from utilities.infra import get_openshift_token, login_with_user_password, create_inference_token
2324
from utilities.user_utils import UserTestSession
2425

2526
LOGGER = get_logger(name=__name__)
2627

2728

28-
@pytest.fixture(scope="class")
29-
def catalog_config_map(admin_client: DynamicClient, model_registry_namespace: str) -> ConfigMap:
30-
return ConfigMap(name=DEFAULT_MODEL_CATALOG, client=admin_client, namespace=model_registry_namespace)
31-
32-
33-
@pytest.fixture(scope="class")
34-
def model_catalog_routes(admin_client: DynamicClient, model_registry_namespace: str) -> list[Route]:
35-
return list(
36-
Route.get(namespace=model_registry_namespace, label_selector="component=model-catalog", dyn_client=admin_client)
37-
)
38-
39-
40-
@pytest.fixture(scope="class")
41-
def model_catalog_rest_url(model_registry_namespace: str, model_catalog_routes: list[Route]) -> list[str]:
42-
assert model_catalog_routes, f"Model catalog routes does not exist in {model_registry_namespace}"
43-
route_urls = [
44-
f"https://{route.instance.spec.host}:443/api/model_catalog/v1alpha1/" for route in model_catalog_routes
45-
]
46-
assert route_urls, (
47-
"Model catalog routes information could not be found from "
48-
f"routes:{[route.name for route in model_catalog_routes]}"
49-
)
50-
return route_urls
51-
52-
5329
@pytest.fixture(scope="class")
5430
def updated_catalog_config_map(
31+
pytestconfig: pytest.Config,
5532
request: pytest.FixtureRequest,
5633
catalog_config_map: ConfigMap,
5734
model_registry_namespace: str,
5835
admin_client: DynamicClient,
5936
model_catalog_rest_url: list[str],
6037
model_registry_rest_headers: dict[str, str],
6138
) -> Generator[ConfigMap, None, None]:
62-
patches = {"data": {"sources.yaml": request.param["sources_yaml"]}}
63-
if "sample_yaml" in request.param:
64-
for key in request.param["sample_yaml"]:
65-
patches["data"][key] = request.param["sample_yaml"][key]
66-
67-
with ResourceEditor(patches={catalog_config_map: patches}):
39+
if pytestconfig.option.post_upgrade or pytestconfig.option.pre_upgrade:
40+
yield
41+
else:
42+
with ResourceEditor(
43+
patches={
44+
catalog_config_map: get_custom_model_catalog_cm_data(
45+
catalog_config_map=catalog_config_map, param=request.param
46+
)
47+
}
48+
):
49+
is_model_catalog_ready(client=admin_client, model_registry_namespace=model_registry_namespace)
50+
wait_for_model_catalog_api(url=model_catalog_rest_url[0], headers=model_registry_rest_headers)
51+
yield catalog_config_map
6852
is_model_catalog_ready(client=admin_client, model_registry_namespace=model_registry_namespace)
69-
wait_for_model_catalog_api(url=model_catalog_rest_url[0], headers=model_registry_rest_headers)
70-
yield catalog_config_map
71-
is_model_catalog_ready(client=admin_client, model_registry_namespace=model_registry_namespace)
7253

7354

7455
@pytest.fixture(scope="class")

tests/model_registry/model_catalog/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
CUSTOM_CATALOG_ID1: str = "sample_custom_catalog1"
1+
from tests.model_registry.constants import CUSTOM_CATALOG_ID1, SAMPLE_MODEL_NAME1
2+
23
CUSTOM_CATALOG_ID2: str = "sample_custom_catalog2"
3-
SAMPLE_MODEL_NAME1 = "mistralai/Mistral-7B-Instruct-v0.3"
44

55
SAMPLE_MODEL_NAME2 = "mistralai/Devstral-Small-2505"
66
EXPECTED_CUSTOM_CATALOG_VALUES: list[dict[str, str]] = [{"id": CUSTOM_CATALOG_ID1, "model_name": SAMPLE_MODEL_NAME1}]

tests/model_registry/model_catalog/test_custom_model_catalog.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
from tests.model_registry.model_catalog.constants import (
22
EXPECTED_CUSTOM_CATALOG_VALUES,
3-
CUSTOM_CATALOG_ID1,
4-
SAMPLE_MODEL_NAME1,
53
CUSTOM_CATALOG_ID2,
64
SAMPLE_MODEL_NAME2,
75
MULTIPLE_CUSTOM_CATALOG_VALUES,
86
SAMPLE_MODEL_NAME3,
97
)
8+
from tests.model_registry.constants import CUSTOM_CATALOG_ID1, SAMPLE_MODEL_NAME1
109
from ocp_resources.config_map import ConfigMap
1110
import pytest
1211
from simple_logger.logger import get_logger
1312
from typing import Self
1413

15-
from tests.model_registry.model_catalog.utils import (
16-
execute_get_command,
14+
from kubernetes.dynamic.exceptions import ResourceNotFoundError
15+
from tests.model_registry.utils import (
1716
get_catalog_str,
1817
get_sample_yaml_str,
19-
ResourceNotFoundError,
18+
execute_get_command,
19+
validate_model_catalog_sources,
2020
)
2121

2222
LOGGER = get_logger(name=__name__)
@@ -32,6 +32,7 @@
3232
},
3333
EXPECTED_CUSTOM_CATALOG_VALUES,
3434
id="test_file_test_catalog",
35+
marks=(pytest.mark.pre_upgrade, pytest.mark.post_upgrade),
3536
),
3637
pytest.param(
3738
{
@@ -62,16 +63,11 @@ def test_model_custom_catalog_list_sources(
6263
"""
6364
Validate sources api for model catalog
6465
"""
65-
url = f"{model_catalog_rest_url[0]}sources"
66-
results = execute_get_command(
67-
url=url,
68-
headers=model_registry_rest_headers,
69-
)["items"]
70-
71-
assert len(results) == len(expected_catalog_values)
72-
ids_from_query = [result_entry["id"] for result_entry in results]
73-
ids_expected = [expected_entry["id"] for expected_entry in expected_catalog_values]
74-
assert sorted(ids_from_query) == sorted(ids_expected), f"Expected: {expected_catalog_values}. Actual: {results}"
66+
validate_model_catalog_sources(
67+
model_catalog_sources_url=f"{model_catalog_rest_url[0]}sources",
68+
rest_headers=model_registry_rest_headers,
69+
expected_catalog_values=expected_catalog_values,
70+
)
7571

7672
def test_model_custom_catalog_get_models_by_source(
7773
self: Self,

tests/model_registry/model_catalog/test_default_model_catalog.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
from tests.model_registry.model_catalog.constants import DEFAULT_CATALOG_ID
1414
from tests.model_registry.model_catalog.utils import (
1515
validate_model_catalog_enabled,
16-
execute_get_command,
1716
validate_model_catalog_resource,
1817
validate_default_catalog,
1918
get_validate_default_model_catalog_source,
2019
)
21-
from tests.model_registry.utils import get_rest_headers
20+
from tests.model_registry.utils import get_rest_headers, execute_get_command
2221
from utilities.user_utils import UserTestSession
2322

2423
LOGGER = get_logger(name=__name__)
@@ -32,15 +31,19 @@
3231

3332
@pytest.mark.skip_must_gather
3433
class TestModelCatalogGeneral:
34+
@pytest.mark.pre_upgrade
3535
@pytest.mark.post_upgrade
3636
@pytest.mark.install
37-
def test_config_map_exists(self: Self, catalog_config_map: ConfigMap):
37+
def test_config_map_exists(self: Self, catalog_config_map: ConfigMap, pytestconfig: pytest.Config) -> None:
3838
# Check that the default configmaps is created when model registry is
3939
# enabled on data science cluster.
40+
expected_num_catalog = 1
41+
if pytestconfig.option.pre_upgrade or pytestconfig.option.post_upgrade:
42+
expected_num_catalog = 2
4043
assert catalog_config_map.exists, f"{catalog_config_map.name} does not exist"
4144
catalogs = yaml.safe_load(catalog_config_map.instance.data["sources.yaml"])["catalogs"]
4245
assert catalogs
43-
assert len(catalogs) == 1, f"{catalog_config_map.name} should have 1 catalog"
46+
assert len(catalogs) == expected_num_catalog, f"{catalog_config_map.name} should have 1 catalog"
4447
validate_default_catalog(default_catalog=catalogs[0])
4548

4649
@pytest.mark.parametrize(
@@ -65,6 +68,7 @@ def test_config_map_exists(self: Self, catalog_config_map: ConfigMap):
6568
],
6669
)
6770
@pytest.mark.post_upgrade
71+
@pytest.mark.pre_upgrade
6872
@pytest.mark.install
6973
def test_model_catalog_resources_exists(
7074
self: Self, admin_client: DynamicClient, model_registry_namespace: str, resource_name: Any
@@ -77,12 +81,14 @@ def test_operator_pod_enabled_model_catalog(self: Self, model_registry_operator_
7781
assert validate_model_catalog_enabled(pod=model_registry_operator_pod)
7882

7983

84+
@pytest.mark.install
8085
@pytest.mark.parametrize(
8186
"user_token_for_api_calls,",
8287
[
8388
pytest.param(
8489
{},
8590
id="test_model_catalog_source_admin_user",
91+
marks=(pytest.mark.pre_upgrade, pytest.mark.post_upgrade),
8692
),
8793
pytest.param(
8894
{"user_type": "test"},
@@ -98,16 +104,28 @@ def test_operator_pod_enabled_model_catalog(self: Self, model_registry_operator_
98104
class TestModelCatalogDefault:
99105
def test_model_catalog_default_catalog_sources(
100106
self,
107+
pytestconfig: pytest.Config,
101108
test_idp_user: UserTestSession,
102109
model_catalog_rest_url: list[str],
103110
user_token_for_api_calls: str,
104111
):
105112
"""
106113
Validate specific user can access default model catalog source
107114
"""
108-
get_validate_default_model_catalog_source(
109-
token=user_token_for_api_calls, model_catalog_url=f"{model_catalog_rest_url[0]}sources"
110-
)
115+
LOGGER.info("Attempting client connection with token")
116+
result = execute_get_command(
117+
url=f"{model_catalog_rest_url[0]}sources",
118+
headers=get_rest_headers(token=user_token_for_api_calls),
119+
)["items"]
120+
assert result
121+
items_to_validate = []
122+
if pytestconfig.option.pre_upgrade or pytestconfig.option.post_upgrade:
123+
for catalog in result:
124+
if catalog["id"] == DEFAULT_CATALOG_ID:
125+
items_to_validate.append(catalog)
126+
else:
127+
items_to_validate = result
128+
get_validate_default_model_catalog_source(catalogs=items_to_validate)
111129

112130
def test_model_default_catalog_get_models_by_source(
113131
self: Self,

0 commit comments

Comments
 (0)