Skip to content

Commit d0a0043

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

25 files changed

Lines changed: 431 additions & 726 deletions

tests/model_registry/conftest.py

Lines changed: 64 additions & 256 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(scope="function")
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: 57 additions & 1 deletion
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
@@ -16,9 +18,12 @@
1618
from tests.model_registry.constants import (
1719
MODEL_REGISTRY_DB_SECRET_STR_DATA,
1820
MODEL_REGISTRY_DB_SECRET_ANNOTATIONS,
21+
DB_RESOURCE_NAME,
22+
MR_INSTANCE_NAME,
1923
)
2024
from tests.model_registry.utils import get_model_registry_deployment_template_dict, get_model_registry_db_label_dict
2125
from utilities.constants import MODEL_REGISTRY_CUSTOM_NAMESPACE
26+
from utilities.general import wait_for_pods_by_labels
2227
from utilities.infra import create_ns
2328

2429
DB_RESOURCES_NAME_NEGATIVE = "db-model-registry-negative"
@@ -121,9 +126,60 @@ def model_registry_db_deployment_negative_test(
121126
selector={"matchLabels": {"name": DB_RESOURCES_NAME_NEGATIVE}},
122127
strategy={"type": "Recreate"},
123128
template=get_model_registry_deployment_template_dict(
124-
secret_name=model_registry_db_secret_negative_test.name, resource_name=DB_RESOURCES_NAME_NEGATIVE
129+
secret_name=model_registry_db_secret_negative_test.name,
130+
resource_name=DB_RESOURCES_NAME_NEGATIVE,
131+
db_backend="mysql",
125132
),
126133
wait_for_resource=True,
127134
) as mr_db_deployment:
128135
mr_db_deployment.wait_for_replicas(deployed=True)
129136
yield mr_db_deployment
137+
138+
139+
@pytest.fixture()
140+
def set_mr_db_dirty(model_registry_db_instance_pod: Pod) -> int:
141+
"""Set the model registry database dirty and return the latest migration version"""
142+
output = model_registry_db_instance_pod.execute(
143+
command=[
144+
"mysql",
145+
"-u",
146+
MODEL_REGISTRY_DB_SECRET_STR_DATA["database-user"],
147+
f"-p{MODEL_REGISTRY_DB_SECRET_STR_DATA['database-password']}",
148+
"-e",
149+
"SELECT version FROM schema_migrations ORDER BY version DESC LIMIT 1;",
150+
MODEL_REGISTRY_DB_SECRET_STR_DATA["database-name"],
151+
]
152+
)
153+
latest_migration_version = int(output.strip().split()[1])
154+
model_registry_db_instance_pod.execute(
155+
command=[
156+
"mysql",
157+
"-u",
158+
MODEL_REGISTRY_DB_SECRET_STR_DATA["database-user"],
159+
f"-p{MODEL_REGISTRY_DB_SECRET_STR_DATA['database-password']}",
160+
"-e",
161+
f"UPDATE schema_migrations SET dirty = 1 WHERE version = {latest_migration_version};",
162+
MODEL_REGISTRY_DB_SECRET_STR_DATA["database-name"],
163+
]
164+
)
165+
return latest_migration_version
166+
167+
168+
@pytest.fixture()
169+
def model_registry_db_instance_pod(admin_client: DynamicClient) -> Generator[Pod, Any, Any]:
170+
"""Get the model registry instance pod."""
171+
yield wait_for_pods_by_labels(
172+
admin_client=admin_client,
173+
namespace=py_config["model_registry_namespace"],
174+
label_selector=f"name={DB_RESOURCE_NAME}",
175+
expected_num_pods=1,
176+
)[0]
177+
178+
179+
@pytest.fixture()
180+
def delete_mr_deployment() -> None:
181+
"""Delete the model registry deployment"""
182+
mr_deployment = Deployment(
183+
name=MR_INSTANCE_NAME, namespace=py_config["model_registry_namespace"], ensure_exists=True
184+
)
185+
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: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,10 @@
3030
indirect=True,
3131
)
3232
@pytest.mark.usefixtures(
33-
"updated_dsc_component_state_scope_class",
33+
"updated_dsc_component_state_scope_session",
3434
"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",
35+
"model_registry_metadata_db_resources",
36+
"model_registry_instance",
4037
"registered_model",
4138
)
4239
@pytest.mark.custom_namespace

tests/model_registry/rbac/conftest.py

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
from typing import Generator, List, Dict, Any
88

99
from _pytest.fixtures import FixtureRequest
10-
from pytest_testconfig import py_config
1110
from simple_logger.logger import get_logger
1211

13-
from ocp_resources.data_science_cluster import DataScienceCluster
1412
from ocp_resources.deployment import Deployment
13+
from ocp_resources.infrastructure import Infrastructure
1514
from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry
1615
from ocp_resources.namespace import Namespace
1716
from ocp_resources.oauth import OAuth
@@ -28,11 +27,9 @@
2827
from pyhelper_utils.shell import run_command
2928

3029
from tests.model_registry.rbac.utils import wait_for_oauth_openshift_deployment, create_role_binding
31-
from utilities.constants import DscComponents
3230
from utilities.general import generate_random_name
3331
from tests.model_registry.utils import (
3432
generate_namespace_name,
35-
wait_for_pods_running,
3633
)
3734
from utilities.infra import login_with_user_password
3835
from utilities.user_utils import UserTestSession, create_htpasswd_file, wait_for_user_creation
@@ -425,47 +422,6 @@ def created_role_binding_user(
425422
# =============================================================================
426423
# RESOURCE FIXTURES PARMETRIZED
427424
# =============================================================================
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-
469425
@pytest.fixture(scope="class")
470426
def db_secret_parametrized(request: FixtureRequest, teardown_resources: bool) -> Generator[List[Secret], Any, Any]:
471427
"""Create DB Secret parametrized"""
@@ -556,3 +512,9 @@ def model_registry_instance_parametrized(
556512
f"Created {len(model_registry_instances)} MR instances: {[mr.name for mr in model_registry_instances]}"
557513
)
558514
yield model_registry_instances
515+
516+
517+
@pytest.fixture(scope="session")
518+
def api_server_url(admin_client: DynamicClient) -> str:
519+
infrastructure = Infrastructure(client=admin_client, name="cluster", ensure_exists=True)
520+
return infrastructure.instance.status.apiServerURL

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

Lines changed: 7 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,9 @@
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(
71+
secret_name=resource_name, resource_name=resource_name, db_backend="mysql"
72+
),
7073
"wait_for_resource": True,
7174
}
7275
for resource_name in resource_names
@@ -79,7 +82,7 @@
7982
"label": get_mr_standard_labels(resource_name=f"{MR_INSTANCE_NAME}{index}"),
8083
"grpc": {},
8184
"rest": {},
82-
"mysql": get_mysql_config(base_name=f"{DB_BASE_RESOURCES_NAME}{index}", namespace=ns_name),
85+
"mysql": get_mysql_config(base_name=f"{DB_BASE_RESOURCES_NAME}{index}", namespace=ns_name, db_backend="mysql"),
8386
"wait_for_resource": True,
8487
"oauth_proxy": OAUTH_PROXY_CONFIG_DICT,
8588
}

0 commit comments

Comments
 (0)