Skip to content

Commit 3b46a7b

Browse files
committed
Add post upgrade scenarios for MLMD removal
1 parent 0c45a93 commit 3b46a7b

File tree

5 files changed

+99
-20
lines changed

5 files changed

+99
-20
lines changed

tests/model_registry/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,23 @@ def model_registry_rest_headers(current_client_token: str) -> dict[str, str]:
482482
"accept": "application/json",
483483
"Content-Type": "application/json",
484484
}
485+
486+
487+
@pytest.fixture(scope="class")
488+
def model_registry_deployment_containers(model_registry_namespace: str) -> list[dict[str, Any]]:
489+
return Deployment(
490+
name=MR_INSTANCE_NAME, namespace=model_registry_namespace, ensure_exists=True
491+
).instance.spec.template.spec.containers
492+
493+
494+
@pytest.fixture(scope="class")
495+
def model_registry_pod(admin_client: DynamicClient, model_registry_namespace: str) -> Pod:
496+
mr_pod = list(
497+
Pod.get(
498+
dyn_client=admin_client,
499+
namespace=model_registry_namespace,
500+
label_selector=f"app={MR_INSTANCE_NAME}",
501+
)
502+
)
503+
assert len(mr_pod) == 1
504+
return mr_pod[0]

tests/model_registry/python_client/conftest.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/model_registry/python_client/test_model_registry_creation.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66
from ocp_resources.pod import Pod
77
from ocp_resources.namespace import Namespace
8-
from tests.model_registry.utils import execute_model_registry_get_command
8+
from tests.model_registry.utils import (
9+
execute_model_registry_get_command,
10+
validate_no_grpc_container,
11+
validate_mlmd_removal_in_model_registry_pod_log,
12+
)
913
from utilities.constants import DscComponents
1014
from tests.model_registry.constants import MODEL_NAME, MODEL_DICT
1115
from model_registry import ModelRegistry as ModelRegistryClient
@@ -87,18 +91,29 @@ def test_model_registry_operator_env(
8791
if not namespace_env:
8892
pytest.fail("Missing environment variable REGISTRIES_NAMESPACE")
8993

90-
def test_model_registry_grpc_container_removal(self, model_registry_deployment_containers: dict[str, Any]):
94+
def test_model_registry_grpc_container_removal(self, model_registry_deployment_containers: list[dict[str, Any]]):
9195
"""
9296
RHOAIENG-26239: Test to ensure removal of grpc container from model registry deployment
9397
Steps:
9498
Create metadata database
9599
Deploys model registry using the same
96100
Check model registry deployment for grpc container. It should not be present
97101
"""
102+
validate_no_grpc_container(deployment_containers=model_registry_deployment_containers)
98103

99-
for container in model_registry_deployment_containers:
100-
if "grpc" in container["name"]:
101-
pytest.fail(f"GRPC container found: {container}")
104+
def test_model_registry_pod_log_mlmd_removal(
105+
self, model_registry_deployment_containers: list[dict[str, Any]], model_registry_pod: Pod
106+
):
107+
"""
108+
RHOAIENG-26239: Test to ensure removal of grpc container from model registry deployment
109+
Steps:
110+
Create metadata database
111+
Deploys model registry using the same
112+
Check model registry deployment for grpc container. It should not be present
113+
"""
114+
validate_mlmd_removal_in_model_registry_pod_log(
115+
deployment_containers=model_registry_deployment_containers, pod_object=model_registry_pod
116+
)
102117

103118
@pytest.mark.parametrize(
104119
"endpoint",

tests/model_registry/upgrade/test_model_registry_upgrade.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import pytest
2-
from typing import Self
2+
from typing import Self, Any
3+
4+
from ocp_resources.pod import Pod
35
from tests.model_registry.constants import MODEL_NAME, MODEL_DICT
46
from model_registry.types import RegisteredModel
57
from model_registry import ModelRegistry as ModelRegistryClient
68
from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry
79
from simple_logger.logger import get_logger
810
from tests.model_registry.rest_api.utils import ModelRegistryV1Alpha1
9-
from tests.model_registry.utils import get_and_validate_registered_model
11+
from tests.model_registry.utils import (
12+
get_and_validate_registered_model,
13+
validate_no_grpc_container,
14+
validate_mlmd_removal_in_model_registry_pod_log,
15+
)
1016

1117
LOGGER = get_logger(name=__name__)
1218

@@ -85,3 +91,29 @@ def test_model_registry_instance_status_conversion_post_upgrade(
8591
LOGGER.info(f"Validating MR status {status}")
8692
if not status:
8793
pytest.fail(f"Empty status found for {mr_instance}")
94+
95+
@pytest.mark.post_upgrade
96+
def test_model_registry_grpc_container_removal_post_upgrade(
97+
self, model_registry_deployment_containers: list[dict[str, Any]]
98+
):
99+
"""
100+
RHOAIENG-29161: Test to ensure removal of grpc container from model registry deployment post upgrade
101+
Steps:
102+
Check model registry deployment for grpc container. It should not be present
103+
"""
104+
validate_no_grpc_container(deployment_containers=model_registry_deployment_containers)
105+
106+
@pytest.mark.post_upgrade
107+
def test_model_registry_pod_log_mlmd_removal(
108+
self, model_registry_deployment_containers: list[dict[str, Any]], model_registry_pod: Pod
109+
):
110+
"""
111+
RHOAIENG-29161: Test to ensure removal of grpc container from model registry deployment
112+
Steps:
113+
Create metadata database
114+
Deploys model registry using the same
115+
Check model registry deployment for grpc container. It should not be present
116+
"""
117+
validate_mlmd_removal_in_model_registry_pod_log(
118+
deployment_containers=model_registry_deployment_containers, pod_object=model_registry_pod
119+
)

tests/model_registry/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,28 @@ def execute_model_registry_get_command(url: str, headers: dict[str, str], json_o
362362
raise
363363
else:
364364
return {"raw_output": resp.text}
365+
366+
367+
def validate_no_grpc_container(deployment_containers: list[dict[str, Any]]) -> None:
368+
grpc_container = None
369+
for container in deployment_containers:
370+
if "grpc" in container["name"]:
371+
grpc_container = container
372+
assert not grpc_container, f"GRPC container found: {grpc_container}"
373+
374+
375+
def validate_mlmd_removal_in_model_registry_pod_log(
376+
deployment_containers: list[dict[str, Any]], pod_object: Pod
377+
) -> None:
378+
errors = []
379+
embedmd_message = "EmbedMD service connected"
380+
for container in deployment_containers:
381+
container_name = container["name"]
382+
LOGGER.info(f"Checking {container_name}")
383+
log = pod_object.log(container=container_name)
384+
if "rest" in container_name:
385+
if embedmd_message not in log:
386+
errors.append(f"Missing {embedmd_message} in {container_name} log")
387+
if "MLMD" in log:
388+
errors.append(f"MLMD reference found in {container_name} log")
389+
assert not errors, f"Log validation failed with error(s): {errors}"

0 commit comments

Comments
 (0)