Skip to content

Commit 092df55

Browse files
authored
Add OSSM rest api test for regression check (#367)
updates! c1618fe
1 parent 3421741 commit 092df55

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

tests/model_registry/conftest.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
MODEL_REGISTRY_DB_SECRET_ANNOTATIONS,
3535
OAUTH_PROXY_CONFIG_DICT,
3636
MODEL_REGISTRY_STANDARD_LABELS,
37+
ISTIO_CONFIG_DICT,
3738
)
3839
from utilities.constants import Labels
3940
from tests.model_registry.utils import (
@@ -150,9 +151,16 @@ def model_registry_db_deployment(
150151

151152
@pytest.fixture(scope="class")
152153
def model_registry_instance(
153-
model_registry_namespace: str,
154-
model_registry_mysql_config: dict[str, Any],
154+
model_registry_namespace: str, model_registry_mysql_config: dict[str, Any], is_model_registry_oauth: bool
155155
) -> Generator[ModelRegistry, Any, Any]:
156+
istio_config = None
157+
oauth_config = None
158+
if is_model_registry_oauth:
159+
LOGGER.warning("Requested Ouath Proxy configuration:")
160+
oauth_config = OAUTH_PROXY_CONFIG_DICT
161+
else:
162+
LOGGER.warning("Requested OSSM configuration:")
163+
istio_config = ISTIO_CONFIG_DICT
156164
"""Creates a model registry instance with oauth proxy configuration."""
157165
oauth_config = OAUTH_PROXY_CONFIG_DICT
158166
with ModelRegistry(
@@ -161,7 +169,7 @@ def model_registry_instance(
161169
label=MODEL_REGISTRY_STANDARD_LABELS,
162170
grpc={},
163171
rest={},
164-
istio=None,
172+
istio=istio_config,
165173
oauth_proxy=oauth_config,
166174
mysql=model_registry_mysql_config,
167175
wait_for_resource=True,
@@ -374,7 +382,7 @@ def model_registry_instance_pod(admin_client: DynamicClient) -> Generator[Pod, A
374382

375383
@pytest.fixture(scope="class")
376384
def is_model_registry_oauth(request: FixtureRequest) -> bool:
377-
return getattr(request, "param", {}).get("use_oauth_proxy", False)
385+
return getattr(request, "param", {}).get("use_oauth_proxy", True)
378386

379387

380388
@pytest.fixture(scope="session")

tests/model_registry/rest_api/test_model_registry_rest_api.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from typing import Self, Any
22
import pytest
33
from pytest_testconfig import config as py_config
4-
4+
from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry
55
from tests.model_registry.rest_api.constants import MODEL_REGISTER, MODEL_ARTIFACT, MODEL_VERSION, MODEL_REGISTER_DATA
6-
from tests.model_registry.rest_api.utils import validate_resource_attributes
6+
from tests.model_registry.rest_api.utils import validate_resource_attributes, ModelRegistryV1Alpha1
77
from utilities.constants import DscComponents
88
from simple_logger.logger import get_logger
99

@@ -25,7 +25,7 @@
2525

2626

2727
@pytest.mark.parametrize(
28-
"updated_dsc_component_state_scope_class, registered_model_rest_api",
28+
"updated_dsc_component_state_scope_class, is_model_registry_oauth, registered_model_rest_api",
2929
[
3030
pytest.param(
3131
{
@@ -36,12 +36,27 @@
3636
},
3737
},
3838
},
39+
{"use_oauth_proxy": False},
40+
MODEL_REGISTER_DATA,
41+
),
42+
pytest.param(
43+
{
44+
"component_patch": {
45+
DscComponents.MODELREGISTRY: {
46+
"managementState": DscComponents.ManagementState.MANAGED,
47+
"registriesNamespace": py_config["model_registry_namespace"],
48+
},
49+
},
50+
},
51+
{},
3952
MODEL_REGISTER_DATA,
4053
),
4154
],
4255
indirect=True,
4356
)
44-
@pytest.mark.usefixtures("updated_dsc_component_state_scope_class", "registered_model_rest_api")
57+
@pytest.mark.usefixtures(
58+
"updated_dsc_component_state_scope_class", "is_model_registry_oauth", "registered_model_rest_api"
59+
)
4560
class TestModelRegistryCreationRest:
4661
"""
4762
Tests the creation of a model registry. If the component is set to 'Removed' it will be switched to 'Managed'
@@ -80,6 +95,27 @@ def test_validate_model_registry_resource(
8095
resource_name=data_key,
8196
)
8297

98+
def test_model_registry_validate_api_version(self: Self, model_registry_instance):
99+
api_version = model_registry_instance.instance.apiVersion
100+
LOGGER.info(f"Validating apiversion {api_version} for model registry")
101+
expected_version = f"{ModelRegistry.ApiGroup.MODELREGISTRY_OPENDATAHUB_IO}/{ModelRegistry.ApiVersion.V1BETA1}"
102+
assert api_version == expected_version
103+
104+
def test_model_registry_validate_oauthproxy_enabled(self: Self, model_registry_instance):
105+
model_registry_instance_spec = model_registry_instance.instance.spec
106+
LOGGER.info(f"Validating that MR is using oauth proxy {model_registry_instance_spec}")
107+
assert not model_registry_instance_spec.istio
108+
assert model_registry_instance_spec.oauthProxy.serviceRoute == "enabled"
109+
110+
def test_model_registry_validate_mr_status_v1alpha1(self: Self, model_registry_instance):
111+
mr_instance = ModelRegistryV1Alpha1(
112+
name=model_registry_instance.name, namespace=model_registry_instance.namespace, ensure_exists=True
113+
).instance
114+
status = mr_instance.status.to_dict()
115+
LOGGER.info(f"Validating MR status {status}")
116+
if not status:
117+
pytest.fail(f"Empty status found for {mr_instance}")
118+
83119
@pytest.mark.parametrize(
84120
"updated_model_registry_resource, expected_param",
85121
[

tests/model_registry/rest_api/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from tests.model_registry.rest_api.constants import MODEL_REGISTRY_BASE_URI
1313
from pyhelper_utils.shell import run_command
1414
from utilities.exceptions import ResourceValueMismatch
15+
from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry
16+
1517

1618
LOGGER = get_logger(name=__name__)
1719

@@ -262,3 +264,7 @@ def sign_db_server_cert_with_ca_with_openssl(
262264
],
263265
check=True,
264266
)
267+
268+
269+
class ModelRegistryV1Alpha1(ModelRegistry):
270+
api_version = f"{ModelRegistry.ApiGroup.MODELREGISTRY_OPENDATAHUB_IO}/{ModelRegistry.ApiVersion.V1ALPHA1}"

0 commit comments

Comments
 (0)