Skip to content

Commit 7012826

Browse files
committed
parameterize mariadb tests
1 parent 02b6927 commit 7012826

25 files changed

Lines changed: 402 additions & 722 deletions

tests/model_registry/conftest.py

Lines changed: 52 additions & 257 deletions
Large diffs are not rendered by default.

tests/model_registry/constants.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,12 @@ class ModelRegistryEndpoints:
5454
CA_FILE_PATH = f"{CA_MOUNT_PATH}/ca-bundle.crt"
5555
NUM_RESOURCES = {"num_resources": 3}
5656
NUM_MR_INSTANCES: int = 2
57+
MARIADB_MY_CNF = (
58+
"[mysqld]\nbind-address=0.0.0.0\ndefault_storage_engine=InnoDB\n"
59+
"binlog_format=row\ninnodb_autoinc_lock_mode=2\ninnodb_buffer_pool_size=1024M"
60+
"\nmax_allowed_packet=256M\n"
61+
)
62+
PORT_MAP = {
63+
"mariadb": 3306,
64+
"mysql": 3306,
65+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import Generator, Any
2+
3+
import pytest
4+
from kubernetes.dynamic import DynamicClient
5+
from pytest_testconfig import config as py_config
6+
7+
from ocp_resources.pod import Pod
8+
from tests.model_registry.constants import MR_INSTANCE_NAME
9+
from utilities.general import wait_for_pods_by_labels
10+
11+
12+
@pytest.fixture()
13+
def model_registry_instance_pod(admin_client: DynamicClient) -> Generator[Pod, Any, Any]:
14+
"""Get the model registry instance pod."""
15+
yield wait_for_pods_by_labels(
16+
admin_client=admin_client,
17+
namespace=py_config["model_registry_namespace"],
18+
label_selector=f"app={MR_INSTANCE_NAME}",
19+
expected_num_pods=1,
20+
)[0]

tests/model_registry/image_validation/test_verify_rhoai_images.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212

1313

1414
@pytest.mark.usefixtures(
15-
"updated_dsc_component_state_scope_class",
16-
"mysql_metadata_resources",
17-
"model_registry_instance_mysql",
15+
"updated_dsc_component_state_scope_session",
16+
"model_registry_namespace",
17+
"model_registry_metadata_db_resources",
18+
"model_registry_instance",
1819
)
1920
@pytest.mark.downstream_only
2021
class TestModelRegistryImages:

tests/model_registry/negative_tests/conftest.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
from typing import Generator, Any
33

44
from _pytest.config import Config
5+
from pytest_testconfig import config as py_config
56

67
from ocp_resources.data_science_cluster import DataScienceCluster
8+
from ocp_resources.pod import Pod
79
from ocp_resources.secret import Secret
810
from ocp_resources.namespace import Namespace
911
from ocp_resources.service import Service
@@ -15,10 +17,11 @@
1517

1618
from tests.model_registry.constants import (
1719
MODEL_REGISTRY_DB_SECRET_STR_DATA,
18-
MODEL_REGISTRY_DB_SECRET_ANNOTATIONS,
20+
MODEL_REGISTRY_DB_SECRET_ANNOTATIONS, DB_RESOURCE_NAME, MR_INSTANCE_NAME,
1921
)
2022
from tests.model_registry.utils import get_model_registry_deployment_template_dict, get_model_registry_db_label_dict
2123
from utilities.constants import MODEL_REGISTRY_CUSTOM_NAMESPACE
24+
from utilities.general import wait_for_pods_by_labels
2225
from utilities.infra import create_ns
2326

2427
DB_RESOURCES_NAME_NEGATIVE = "db-model-registry-negative"
@@ -121,9 +124,58 @@ def model_registry_db_deployment_negative_test(
121124
selector={"matchLabels": {"name": DB_RESOURCES_NAME_NEGATIVE}},
122125
strategy={"type": "Recreate"},
123126
template=get_model_registry_deployment_template_dict(
124-
secret_name=model_registry_db_secret_negative_test.name, resource_name=DB_RESOURCES_NAME_NEGATIVE
127+
secret_name=model_registry_db_secret_negative_test.name, resource_name=DB_RESOURCES_NAME_NEGATIVE, db_backend="mysql"
125128
),
126129
wait_for_resource=True,
127130
) as mr_db_deployment:
128131
mr_db_deployment.wait_for_replicas(deployed=True)
129132
yield mr_db_deployment
133+
134+
135+
@pytest.fixture()
136+
def set_mr_db_dirty(model_registry_db_instance_pod: Pod) -> int:
137+
"""Set the model registry database dirty and return the latest migration version"""
138+
output = model_registry_db_instance_pod.execute(
139+
command=[
140+
"mysql",
141+
"-u",
142+
MODEL_REGISTRY_DB_SECRET_STR_DATA["database-user"],
143+
f"-p{MODEL_REGISTRY_DB_SECRET_STR_DATA['database-password']}",
144+
"-e",
145+
"SELECT version FROM schema_migrations ORDER BY version DESC LIMIT 1;",
146+
MODEL_REGISTRY_DB_SECRET_STR_DATA["database-name"],
147+
]
148+
)
149+
latest_migration_version = int(output.strip().split()[1])
150+
model_registry_db_instance_pod.execute(
151+
command=[
152+
"mysql",
153+
"-u",
154+
MODEL_REGISTRY_DB_SECRET_STR_DATA["database-user"],
155+
f"-p{MODEL_REGISTRY_DB_SECRET_STR_DATA['database-password']}",
156+
"-e",
157+
f"UPDATE schema_migrations SET dirty = 1 WHERE version = {latest_migration_version};",
158+
MODEL_REGISTRY_DB_SECRET_STR_DATA["database-name"],
159+
]
160+
)
161+
return latest_migration_version
162+
163+
164+
@pytest.fixture()
165+
def model_registry_db_instance_pod(admin_client: DynamicClient) -> Generator[Pod, Any, Any]:
166+
"""Get the model registry instance pod."""
167+
yield wait_for_pods_by_labels(
168+
admin_client=admin_client,
169+
namespace=py_config["model_registry_namespace"],
170+
label_selector=f"name={DB_RESOURCE_NAME}",
171+
expected_num_pods=1,
172+
)[0]
173+
174+
175+
@pytest.fixture()
176+
def delete_mr_deployment() -> None:
177+
"""Delete the model registry deployment"""
178+
mr_deployment = Deployment(
179+
name=MR_INSTANCE_NAME, namespace=py_config["model_registry_namespace"], ensure_exists=True
180+
)
181+
mr_deployment.delete(wait=True)

tests/model_registry/negative_tests/test_db_migration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
@pytest.mark.usefixtures(
16-
"updated_dsc_component_state_scope_class", "mysql_metadata_resources", "model_registry_instance_mysql"
16+
"updated_dsc_component_state_scope_session", "model_registry_metadata_db_resources", "model_registry_instance"
1717
)
1818
class TestDBMigration:
1919
def test_db_migration_negative(

tests/model_registry/negative_tests/test_model_registry_creation_negative.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
@pytest.mark.usefixtures(
2424
"model_registry_namespace_for_negative_tests",
25-
"updated_dsc_component_state_scope_class",
25+
"updated_dsc_component_state_scope_session",
2626
"model_registry_db_secret_negative_test",
2727
"model_registry_db_deployment_negative_test",
2828
)
@@ -32,7 +32,7 @@ def test_registering_model_negative(
3232
self: Self,
3333
current_client_token: str,
3434
model_registry_namespace_for_negative_tests: Namespace,
35-
updated_dsc_component_state_scope_class: DataScienceCluster,
35+
updated_dsc_component_state_scope_session: DataScienceCluster,
3636
model_registry_db_secret_negative_test: Secret,
3737
model_registry_db_deployment_negative_test: Deployment,
3838
):

tests/model_registry/python_client/test_model_registry_creation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@
3030
indirect=True,
3131
)
3232
@pytest.mark.usefixtures(
33-
"updated_dsc_component_state_scope_class",
33+
"updated_dsc_component_state_scope_session",
34+
"updated_dsc_component_state_scope_session",
3435
"model_registry_namespace",
35-
"model_registry_db_secret",
36-
"model_registry_db_pvc",
37-
"model_registry_db_service",
38-
"model_registry_db_deployment",
39-
"model_registry_instance_mysql",
36+
"model_registry_metadata_db_resources",
37+
"model_registry_instance",
4038
"registered_model",
4139
)
4240
@pytest.mark.custom_namespace

tests/model_registry/rbac/conftest.py

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from ocp_resources.data_science_cluster import DataScienceCluster
1414
from ocp_resources.deployment import Deployment
15+
from ocp_resources.infrastructure import Infrastructure
1516
from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry
1617
from ocp_resources.namespace import Namespace
1718
from ocp_resources.oauth import OAuth
@@ -425,47 +426,6 @@ def created_role_binding_user(
425426
# =============================================================================
426427
# RESOURCE FIXTURES PARMETRIZED
427428
# =============================================================================
428-
@pytest.fixture(scope="class")
429-
def updated_dsc_component_state_parametrized(
430-
request: FixtureRequest,
431-
admin_client: DynamicClient,
432-
dsc_resource: DataScienceCluster,
433-
teardown_resources: bool,
434-
) -> Generator[DataScienceCluster, Any, Any]:
435-
"""Configure DSC to use parametrized Model Registry namespace"""
436-
if not teardown_resources:
437-
yield dsc_resource
438-
439-
# Get the namespace name from the parameter if provided, otherwise use the default namespace
440-
namespace_name = request.param.get("ns_name", py_config["model_registry_namespace"])
441-
442-
# Set the new namespace and manage
443-
component_patch = {
444-
DscComponents.MODELREGISTRY: {
445-
"managementState": DscComponents.ManagementState.MANAGED,
446-
"registriesNamespace": namespace_name,
447-
},
448-
}
449-
450-
with ResourceEditor(patches={dsc_resource: {"spec": {"components": component_patch}}}):
451-
dsc_resource.wait_for_condition(
452-
condition=DscComponents.COMPONENT_MAPPING[DscComponents.MODELREGISTRY], status="True"
453-
)
454-
namespace = Namespace(name=namespace_name, wait_for_resource=True)
455-
namespace.wait_for_status(status=Namespace.Status.ACTIVE)
456-
wait_for_pods_running(
457-
admin_client=admin_client,
458-
namespace_name=py_config["applications_namespace"],
459-
number_of_consecutive_checks=6,
460-
)
461-
yield dsc_resource
462-
463-
# Clean up the dynamic namespace
464-
namespace = Namespace(name=namespace_name, ensure_exists=True)
465-
if namespace:
466-
namespace.delete(wait=True)
467-
468-
469429
@pytest.fixture(scope="class")
470430
def db_secret_parametrized(request: FixtureRequest, teardown_resources: bool) -> Generator[List[Secret], Any, Any]:
471431
"""Create DB Secret parametrized"""
@@ -556,3 +516,9 @@ def model_registry_instance_parametrized(
556516
f"Created {len(model_registry_instances)} MR instances: {[mr.name for mr in model_registry_instances]}"
557517
)
558518
yield model_registry_instances
519+
520+
521+
@pytest.fixture(scope="session")
522+
def api_server_url(admin_client: DynamicClient) -> str:
523+
infrastructure = Infrastructure(client=admin_client, name="cluster", ensure_exists=True)
524+
return infrastructure.instance.status.apiServerURL

tests/model_registry/multiple_instance_utils.py renamed to tests/model_registry/rbac/multiple_instance_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import pytest
2+
from pytest_testconfig import config as py_config
3+
24
from tests.model_registry.constants import (
35
MODEL_REGISTRY_DB_SECRET_STR_DATA,
46
MR_INSTANCE_NAME,
@@ -13,9 +15,8 @@
1315
get_mr_standard_labels,
1416
get_mysql_config,
1517
)
16-
from utilities.general import generate_random_name
1718

18-
ns_name = generate_random_name(prefix=MR_INSTANCE_NAME, length=2)
19+
ns_name = py_config["model_registry_namespace"]
1920
ns_params = {"ns_name": ns_name}
2021

2122
resource_names = [f"{DB_BASE_RESOURCES_NAME}{index}" for index in range(0, NUM_MR_INSTANCES)]
@@ -66,7 +67,7 @@
6667
"label": get_model_registry_db_label_dict(db_resource_name=resource_name),
6768
"selector": {"matchLabels": {"name": resource_name}},
6869
"strategy": {"type": "Recreate"},
69-
"template": get_model_registry_deployment_template_dict(secret_name=resource_name, resource_name=resource_name),
70+
"template": get_model_registry_deployment_template_dict(secret_name=resource_name, resource_name=resource_name, db_backend="mysql"),
7071
"wait_for_resource": True,
7172
}
7273
for resource_name in resource_names
@@ -79,7 +80,7 @@
7980
"label": get_mr_standard_labels(resource_name=f"{MR_INSTANCE_NAME}{index}"),
8081
"grpc": {},
8182
"rest": {},
82-
"mysql": get_mysql_config(base_name=f"{DB_BASE_RESOURCES_NAME}{index}", namespace=ns_name),
83+
"mysql": get_mysql_config(base_name=f"{DB_BASE_RESOURCES_NAME}{index}", namespace=ns_name, db_backend="mysql"),
8384
"wait_for_resource": True,
8485
"oauth_proxy": OAUTH_PROXY_CONFIG_DICT,
8586
}

0 commit comments

Comments
 (0)