Skip to content

Commit e2ba93c

Browse files
committed
Use exitStack to support multiple resource creations
updates! 72351d8
1 parent 76ce3db commit e2ba93c

17 files changed

+490
-235
lines changed

tests/model_registry/conftest.py

Lines changed: 128 additions & 154 deletions
Large diffs are not rendered by default.

tests/model_registry/constants.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any
22
from ocp_resources.resource import Resource
3-
from utilities.constants import ModelFormat, Annotations
3+
from utilities.constants import ModelFormat
44

55

66
class ModelRegistryEndpoints:
@@ -25,7 +25,8 @@ class ModelRegistryEndpoints:
2525
"str_key": "str_value",
2626
},
2727
}
28-
MR_INSTANCE_NAME: str = "model-registry"
28+
MR_INSTANCE_BASE_NAME: str = "model-registry"
29+
MR_INSTANCE_NAME: str = f"{MR_INSTANCE_BASE_NAME}0"
2930
SECURE_MR_NAME: str = "secure-db-mr"
3031
ISTIO_CONFIG_DICT: dict[str, Any] = {
3132
"gateway": {"grpc": {"tls": {}}, "rest": {"tls": {}}},
@@ -35,7 +36,8 @@ class ModelRegistryEndpoints:
3536
"routePort": 443,
3637
"serviceRoute": "enabled",
3738
}
38-
DB_RESOURCES_NAME: str = "db-model-registry"
39+
DB_BASE_RESOURCES_NAME: str = "db-model-registry"
40+
DB_RESOURCE_NAME: str = f"{DB_BASE_RESOURCES_NAME}0"
3941
MR_DB_IMAGE_DIGEST: str = (
4042
"public.ecr.aws/docker/library/mysql@sha256:9de9d54fecee6253130e65154b930978b1fcc336bcc86dfd06e89b72a2588ebe"
4143
)
@@ -53,10 +55,3 @@ class ModelRegistryEndpoints:
5355
CA_CONFIGMAP_NAME = "odh-trusted-ca-bundle"
5456
CA_MOUNT_PATH = "/etc/pki/ca-trust/extracted/pem"
5557
CA_FILE_PATH = f"{CA_MOUNT_PATH}/ca-bundle.crt"
56-
57-
MODEL_REGISTRY_STANDARD_LABELS = {
58-
Annotations.KubernetesIo.NAME: MR_INSTANCE_NAME,
59-
Annotations.KubernetesIo.INSTANCE: MR_INSTANCE_NAME,
60-
Annotations.KubernetesIo.PART_OF: MR_OPERATOR_NAME,
61-
Annotations.KubernetesIo.CREATED_BY: MR_OPERATOR_NAME,
62-
}

tests/model_registry/image_validation/test_verify_rhoai_images.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from typing import Self, Set
2+
from typing import Self, Set, Any
33
from simple_logger.logger import get_logger
44
from kubernetes.dynamic import DynamicClient
55
from pytest_testconfig import config as py_config
@@ -8,7 +8,6 @@
88
from utilities.general import (
99
validate_container_images,
1010
)
11-
from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry
1211
from ocp_resources.pod import Pod
1312

1413
LOGGER = get_logger(name=__name__)
@@ -43,7 +42,7 @@ class TestModelRegistryImages:
4342
def test_verify_model_registry_images(
4443
self: Self,
4544
admin_client: DynamicClient,
46-
model_registry_instance: ModelRegistry,
45+
model_registry_instance: list[Any],
4746
model_registry_operator_pod: Pod,
4847
model_registry_instance_pod: Pod,
4948
related_images_refs: Set[str],

tests/model_registry/negative_tests/test_db_migration.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
2-
from typing import Self
2+
from typing import Self, Any
33
from simple_logger.logger import get_logger
4-
from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry
54
from pytest_testconfig import config as py_config
65
from ocp_resources.pod import Pod
76
from utilities.constants import DscComponents
@@ -32,7 +31,7 @@ class TestDBMigration:
3231
def test_db_migration_negative(
3332
self: Self,
3433
admin_client: DynamicClient,
35-
model_registry_instance: ModelRegistry,
34+
model_registry_instance: list[Any],
3635
model_registry_db_instance_pod: Pod,
3736
set_mr_db_dirty: int,
3837
delete_mr_deployment: None,

tests/model_registry/negative_tests/test_model_registry_creation_negative.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from utilities.constants import DscComponents, Annotations
1212
from tests.model_registry.constants import (
1313
MR_OPERATOR_NAME,
14-
MR_INSTANCE_NAME,
14+
MR_INSTANCE_BASE_NAME,
1515
ISTIO_CONFIG_DICT,
16-
DB_RESOURCES_NAME,
16+
DB_BASE_RESOURCES_NAME,
1717
)
1818
from kubernetes.dynamic.exceptions import ForbiddenError
1919

@@ -65,7 +65,7 @@ def test_registering_model_negative(
6565
"host": f"{model_registry_db_deployment_negative_test.name}."
6666
f"{model_registry_db_deployment_negative_test.namespace}.svc.cluster.local",
6767
"database": model_registry_db_secret_negative_test.string_data["database-name"],
68-
"passwordSecret": {"key": "database-password", "name": DB_RESOURCES_NAME},
68+
"passwordSecret": {"key": "database-password", "name": DB_BASE_RESOURCES_NAME},
6969
"port": 3306,
7070
"skipDBCreation": False,
7171
"username": model_registry_db_secret_negative_test.string_data["database-user"],
@@ -75,11 +75,11 @@ def test_registering_model_negative(
7575
match=f"namespace must be {expected_namespace}",
7676
):
7777
with ModelRegistry(
78-
name=MR_INSTANCE_NAME,
78+
name=MR_INSTANCE_BASE_NAME,
7979
namespace=model_registry_namespace_for_negative_tests.name,
8080
label={
81-
Annotations.KubernetesIo.NAME: MR_INSTANCE_NAME,
82-
Annotations.KubernetesIo.INSTANCE: MR_INSTANCE_NAME,
81+
Annotations.KubernetesIo.NAME: MR_INSTANCE_BASE_NAME,
82+
Annotations.KubernetesIo.INSTANCE: MR_INSTANCE_BASE_NAME,
8383
Annotations.KubernetesIo.PART_OF: MR_OPERATOR_NAME,
8484
Annotations.KubernetesIo.CREATED_BY: MR_OPERATOR_NAME,
8585
},

tests/model_registry/python_client/test_model_registry_creation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ class TestModelRegistryCreation:
5454
@pytest.mark.smoke
5555
def test_registering_model(
5656
self: Self,
57-
model_registry_client: ModelRegistryClient,
57+
model_registry_client: list[ModelRegistryClient],
5858
registered_model: RegisteredModel,
5959
):
60-
model = model_registry_client.get_registered_model(name=MODEL_NAME)
60+
model = model_registry_client[0].get_registered_model(name=MODEL_NAME)
6161
expected_attrs = {
6262
"id": registered_model.id,
6363
"name": registered_model.name,
@@ -112,7 +112,7 @@ def test_model_registry_grpc_container_removal(self, model_registry_deployment_c
112112
],
113113
)
114114
def test_model_registry_endpoint_response(
115-
self, model_registry_rest_url: str, model_registry_rest_headers: dict[str, str], endpoint: str
115+
self, model_registry_rest_url: list[str], model_registry_rest_headers: dict[str, str], endpoint: str
116116
):
117117
"""
118118
RHOAIENG-26239: Test to ensure model registry endpoints are responsive
@@ -122,6 +122,6 @@ def test_model_registry_endpoint_response(
122122
Ensure endpoint is responsive via get call
123123
"""
124124
output = execute_model_registry_get_command(
125-
url=f"{model_registry_rest_url}/{endpoint}", headers=model_registry_rest_headers, json_output=False
125+
url=f"{model_registry_rest_url[0]}/{endpoint}", headers=model_registry_rest_headers, json_output=False
126126
)
127127
assert output["raw_output"].lower() == "OK".lower()

tests/model_registry/rbac/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from tests.model_registry.rbac.group_utils import create_group
2626
from tests.model_registry.constants import MR_INSTANCE_NAME
2727

28-
2928
LOGGER = get_logger(name=__name__)
3029
DEFAULT_TOKEN_DURATION = "10m"
3130

tests/model_registry/rbac/test_mr_rbac.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@
4242
],
4343
indirect=True,
4444
)
45-
@pytest.mark.usefixtures("updated_dsc_component_state_scope_class")
45+
@pytest.mark.usefixtures("updated_dsc_component_state_scope_class", "model_registry_instance")
4646
class TestUserPermission:
4747
@pytest.mark.sanity
4848
def test_user_permission_non_admin_user(
4949
self: Self,
5050
test_idp_user,
51-
model_registry_instance_rest_endpoint: str,
51+
model_registry_instance_rest_endpoint: list[str],
5252
login_as_test_user: None,
5353
):
5454
"""
5555
This test verifies that non-admin users cannot access the Model Registry (403 Forbidden)
5656
"""
5757
client_args = build_mr_client_args(
58-
rest_endpoint=model_registry_instance_rest_endpoint, token=get_openshift_token()
58+
rest_endpoint=model_registry_instance_rest_endpoint[0], token=get_openshift_token()
5959
)
6060
with pytest.raises(ForbiddenException) as exc_info:
6161
ModelRegistryClient(**client_args)
@@ -65,7 +65,7 @@ def test_user_permission_non_admin_user(
6565
@pytest.mark.sanity
6666
def test_user_added_to_group(
6767
self: Self,
68-
model_registry_instance_rest_endpoint: str,
68+
model_registry_instance_rest_endpoint: list[str],
6969
test_idp_user: UserTestSession,
7070
model_registry_group_with_user: Group,
7171
login_as_test_user: Generator[UserTestSession, None, None],
@@ -79,7 +79,7 @@ def test_user_added_to_group(
7979
wait_timeout=240,
8080
sleep=5,
8181
func=assert_positive_mr_registry,
82-
model_registry_instance_rest_endpoint=model_registry_instance_rest_endpoint,
82+
model_registry_instance_rest_endpoint=model_registry_instance_rest_endpoint[0],
8383
token=get_openshift_token(),
8484
)
8585
for _ in sampler:
@@ -90,7 +90,7 @@ def test_user_added_to_group(
9090
def test_create_group(
9191
self: Self,
9292
test_idp_user: UserTestSession,
93-
model_registry_instance_rest_endpoint: str,
93+
model_registry_instance_rest_endpoint: list[str],
9494
created_role_binding_group: RoleBinding,
9595
login_as_test_user: None,
9696
):
@@ -103,14 +103,14 @@ def test_create_group(
103103
3. Users in the group can access the Model Registry
104104
"""
105105
assert_positive_mr_registry(
106-
model_registry_instance_rest_endpoint=model_registry_instance_rest_endpoint,
106+
model_registry_instance_rest_endpoint=model_registry_instance_rest_endpoint[0],
107107
)
108108

109109
@pytest.mark.sanity
110110
def test_add_single_user_role_binding(
111111
self: Self,
112112
test_idp_user: UserTestSession,
113-
model_registry_instance_rest_endpoint: str,
113+
model_registry_instance_rest_endpoint: list[str],
114114
created_role_binding_user: RoleBinding,
115115
login_as_test_user: None,
116116
):
@@ -122,5 +122,5 @@ def test_add_single_user_role_binding(
122122
2. The user can access the Model Registry after being granted access
123123
"""
124124
assert_positive_mr_registry(
125-
model_registry_instance_rest_endpoint=model_registry_instance_rest_endpoint,
125+
model_registry_instance_rest_endpoint=model_registry_instance_rest_endpoint[0],
126126
)

tests/model_registry/rbac/test_mr_rbac_sa.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ class TestModelRegistryRBAC:
3838
def test_service_account_access_denied(
3939
self: Self,
4040
sa_token: str,
41-
model_registry_instance_rest_endpoint: str,
41+
model_registry_instance_rest_endpoint: list[str],
4242
):
4343
"""
4444
Verifies SA access is DENIED (403 Forbidden) by default via REST.
4545
Does NOT use mr_access_role or mr_access_role_binding fixtures.
4646
"""
4747
LOGGER.info("--- Starting RBAC Test: Access Denied ---")
48-
LOGGER.info(f"Targeting Model Registry REST endpoint: {model_registry_instance_rest_endpoint}")
48+
LOGGER.info(f"Targeting Model Registry REST endpoint: {model_registry_instance_rest_endpoint[0]}")
4949
LOGGER.info("Expecting initial access DENIAL (403 Forbidden)")
5050

5151
client_args = build_mr_client_args(
52-
rest_endpoint=model_registry_instance_rest_endpoint, token=sa_token, author="rbac-test-denied"
52+
rest_endpoint=model_registry_instance_rest_endpoint[0], token=sa_token, author="rbac-test-denied"
5353
)
5454
LOGGER.debug(f"Attempting client connection with args: {client_args}")
5555

@@ -69,7 +69,7 @@ def test_service_account_access_denied(
6969
def test_service_account_access_granted(
7070
self: Self,
7171
sa_token: str,
72-
model_registry_instance_rest_endpoint: str,
72+
model_registry_instance_rest_endpoint: list[str],
7373
):
7474
"""
7575
Verifies SA access is GRANTED via REST after applying Role and RoleBinding fixtures.
@@ -80,7 +80,7 @@ def test_service_account_access_granted(
8080

8181
try:
8282
client_args = build_mr_client_args(
83-
rest_endpoint=model_registry_instance_rest_endpoint, token=sa_token, author="rbac-test-granted"
83+
rest_endpoint=model_registry_instance_rest_endpoint[0], token=sa_token, author="rbac-test-granted"
8484
)
8585
LOGGER.debug(f"Attempting client connection with args: {client_args}")
8686
mr_client_success = ModelRegistryClient(**client_args)

0 commit comments

Comments
 (0)