|
1 | 1 | import random |
2 | 2 | from typing import Generator, Any |
| 3 | + |
3 | 4 | from simple_logger.logger import get_logger |
4 | 5 |
|
5 | 6 | import pytest |
|
8 | 9 | from ocp_resources.config_map import ConfigMap |
9 | 10 | from ocp_resources.resource import ResourceEditor |
10 | 11 |
|
11 | | -from ocp_resources.route import Route |
12 | 12 | 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, |
16 | 17 | is_model_catalog_ready, |
17 | 18 | wait_for_model_catalog_api, |
18 | 19 | get_model_str, |
19 | 20 | execute_get_command, |
| 21 | + get_custom_model_catalog_cm_data, |
20 | 22 | ) |
21 | | -from tests.model_registry.utils import get_rest_headers |
22 | 23 | from utilities.infra import get_openshift_token, login_with_user_password, create_inference_token |
23 | 24 | from utilities.user_utils import UserTestSession |
24 | 25 |
|
25 | 26 | LOGGER = get_logger(name=__name__) |
26 | 27 |
|
27 | 28 |
|
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 | | - |
53 | 29 | @pytest.fixture(scope="class") |
54 | 30 | def updated_catalog_config_map( |
| 31 | + pytestconfig: pytest.Config, |
55 | 32 | request: pytest.FixtureRequest, |
56 | 33 | catalog_config_map: ConfigMap, |
57 | 34 | model_registry_namespace: str, |
58 | 35 | admin_client: DynamicClient, |
59 | 36 | model_catalog_rest_url: list[str], |
60 | 37 | model_registry_rest_headers: dict[str, str], |
61 | 38 | ) -> 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 |
68 | 52 | 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) |
72 | 53 |
|
73 | 54 |
|
74 | 55 | @pytest.fixture(scope="class") |
|
0 commit comments