Skip to content

Commit 69e096a

Browse files
committed
Add tests for grpc removal
1 parent db3b5e2 commit 69e096a

File tree

6 files changed

+101
-39
lines changed

6 files changed

+101
-39
lines changed

tests/model_registry/conftest.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
ISTIO_CONFIG_DICT,
3232
)
3333
from tests.model_registry.rest_api.utils import ModelRegistryV1Alpha1
34-
from utilities.constants import Labels
34+
from utilities.constants import Labels, Protocols
3535
from tests.model_registry.utils import (
3636
get_endpoint_from_mr_service,
3737
get_mr_service_by_label,
3838
get_model_registry_deployment_template_dict,
3939
get_model_registry_db_label_dict,
4040
wait_for_pods_running,
4141
)
42-
from utilities.constants import Protocols, DscComponents
42+
from utilities.constants import DscComponents
4343
from model_registry import ModelRegistry as ModelRegistryClient
4444
from semver import Version
4545
from utilities.general import wait_for_pods_by_labels
@@ -467,3 +467,18 @@ def is_model_registry_oauth(request: FixtureRequest) -> bool:
467467
def api_server_url(admin_client: DynamicClient) -> str:
468468
infrastructure = Infrastructure(client=admin_client, name="cluster", ensure_exists=True)
469469
return infrastructure.instance.status.apiServerURL
470+
471+
472+
@pytest.fixture(scope="class")
473+
def model_registry_rest_url(model_registry_instance_rest_endpoint: str) -> str:
474+
# address and port need to be split in the client instantiation
475+
return f"{Protocols.HTTPS}://{model_registry_instance_rest_endpoint}"
476+
477+
478+
@pytest.fixture(scope="class")
479+
def model_registry_rest_headers(current_client_token: str) -> dict[str, str]:
480+
return {
481+
"Authorization": f"Bearer {current_client_token}",
482+
"accept": "application/json",
483+
"Content-Type": "application/json",
484+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import Any
2+
3+
import pytest
4+
5+
from ocp_resources.deployment import Deployment
6+
from tests.model_registry.constants import MR_INSTANCE_NAME
7+
8+
9+
@pytest.fixture(scope="class")
10+
def model_registry_deployment_containers(model_registry_namespace: str) -> dict[str, Any]:
11+
return Deployment(
12+
name=MR_INSTANCE_NAME, namespace=model_registry_namespace, ensure_exists=True
13+
).instance.spec.template.spec.containers

tests/model_registry/python_client/test_model_registry_creation.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import pytest
2-
from typing import Self
2+
from typing import Self, Any
33
from simple_logger.logger import get_logger
44
from pytest_testconfig import config as py_config
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
89
from utilities.constants import DscComponents
910
from tests.model_registry.constants import MODEL_NAME, MODEL_DICT
1011
from model_registry import ModelRegistry as ModelRegistryClient
@@ -86,7 +87,41 @@ def test_model_registry_operator_env(
8687
if not namespace_env:
8788
pytest.fail("Missing environment variable REGISTRIES_NAMESPACE")
8889

89-
# TODO: Edit a registered model
90-
# TODO: Add additional versions for a model
91-
# TODO: List all available models
92-
# TODO: List all versions of a model
90+
def test_model_registry_grpc_container_removal(self, model_registry_deployment_containers: dict[str, Any]):
91+
"""
92+
RHOAIENG-26239: Test to ensure removal of grpc container from model registry deployment
93+
Steps:
94+
Create metadata database
95+
Deploys model registry using the same
96+
Check model registry deployment for grpc container. It should not be present
97+
"""
98+
99+
for container in model_registry_deployment_containers:
100+
if "grpc" in container["name"]:
101+
pytest.fail(f"GRPC container found: {container}")
102+
103+
@pytest.mark.parametrize(
104+
"endpoint",
105+
[
106+
pytest.param(
107+
"oauth/healthz",
108+
),
109+
pytest.param(
110+
"readyz/isDirty",
111+
),
112+
],
113+
)
114+
def test_model_registry_endpoint_response(
115+
self, model_registry_rest_url: str, model_registry_rest_headers: dict[str, str], endpoint: str
116+
):
117+
"""
118+
RHOAIENG-26239: Test to ensure model registry endpoints are responsive
119+
Steps:
120+
Create metadata database
121+
Deploys model registry using the same
122+
Ensure endpoint is responsive via get call
123+
"""
124+
output = execute_model_registry_get_command(
125+
url=f"{model_registry_rest_url}/{endpoint}", headers=model_registry_rest_headers, json_output=False
126+
)
127+
assert output["raw_output"].lower() == "OK".lower()

tests/model_registry/rest_api/conftest.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from kubernetes.dynamic import DynamicClient
44
import pytest
55
import copy
6+
67
from tests.model_registry.rest_api.constants import MODEL_REGISTRY_BASE_URI, MODEL_REGISTER_DATA
78
from tests.model_registry.rest_api.utils import (
89
register_model_rest_api,
910
execute_model_registry_patch_command,
1011
)
11-
from utilities.constants import Protocols
1212
from utilities.general import generate_random_name
1313
from ocp_resources.deployment import Deployment
1414
from tests.model_registry.utils import (
@@ -40,21 +40,6 @@
4040
LOGGER = get_logger(name=__name__)
4141

4242

43-
@pytest.fixture(scope="class")
44-
def model_registry_rest_url(model_registry_instance_rest_endpoint: str) -> str:
45-
# address and port need to be split in the client instantiation
46-
return f"{Protocols.HTTPS}://{model_registry_instance_rest_endpoint}"
47-
48-
49-
@pytest.fixture(scope="class")
50-
def model_registry_rest_headers(current_client_token: str) -> dict[str, str]:
51-
return {
52-
"Authorization": f"Bearer {current_client_token}",
53-
"accept": "application/json",
54-
"Content-Type": "application/json",
55-
}
56-
57-
5843
@pytest.fixture(scope="class")
5944
def registered_model_rest_api(
6045
request: pytest.FixtureRequest, model_registry_rest_url: str, model_registry_rest_headers: dict[str, str]

tests/model_registry/rest_api/utils.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from simple_logger.logger import get_logger
77
from tests.model_registry.exceptions import (
88
ModelRegistryResourceNotCreated,
9-
ModelRegistryResourceNotFoundError,
109
ModelRegistryResourceNotUpdated,
1110
)
1211
from tests.model_registry.rest_api.constants import MODEL_REGISTRY_BASE_URI
@@ -52,21 +51,6 @@ def execute_model_registry_post_command(
5251
raise
5352

5453

55-
def execute_model_registry_get_command(url: str, headers: dict[str, str]) -> dict[Any, Any]: # skip-unused-code
56-
resp = requests.get(url=url, headers=headers, verify=False)
57-
LOGGER.info(f"url: {url}, status code: {resp.status_code}, rep: {resp.text}")
58-
if resp.status_code not in [200, 201]:
59-
raise ModelRegistryResourceNotFoundError(
60-
f"Failed to get ModelRegistry resource: {url}, {resp.status_code}: {resp.text}"
61-
)
62-
63-
try:
64-
return json.loads(resp.text)
65-
except json.JSONDecodeError:
66-
LOGGER.error(f"Unable to parse {resp.text}")
67-
raise
68-
69-
7054
def register_model_rest_api(
7155
model_registry_rest_url: str,
7256
model_registry_rest_headers: dict[str, str],

tests/model_registry/utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import json
12
from typing import Any, List
23

4+
import requests
35
from kubernetes.dynamic import DynamicClient
46
from ocp_resources.pod import Pod
57
from ocp_resources.service import Service
@@ -9,6 +11,7 @@
911
from timeout_sampler import TimeoutExpiredError, TimeoutSampler
1012
from kubernetes.dynamic.exceptions import NotFoundError
1113
from tests.model_registry.constants import MR_DB_IMAGE_DIGEST
14+
from tests.model_registry.exceptions import ModelRegistryResourceNotFoundError
1215
from utilities.exceptions import ProtocolNotSupportedError, TooManyServicesError
1316
from utilities.constants import Protocols, Annotations
1417
from model_registry import ModelRegistry as ModelRegistryClient
@@ -332,3 +335,30 @@ def get_and_validate_registered_model(
332335
if getattr(model, attr) != expected
333336
]
334337
return errors
338+
339+
340+
def execute_model_registry_get_command(url: str, headers: dict[str, str], json_output: bool = True) -> dict[Any, Any]:
341+
"""
342+
Executes model registry get commands against model registry rest end point
343+
344+
Args:
345+
url (str): Model registry endpoint for rest calls
346+
headers (dict[str, str]): HTTP headers for get calls
347+
json_output(bool): Whether to output JSON response
348+
349+
Returns: json output or dict of raw output.
350+
"""
351+
resp = requests.get(url=url, headers=headers, verify=False)
352+
LOGGER.info(f"url: {url}, status code: {resp.status_code}, rep: {resp.text}")
353+
if resp.status_code not in [200, 201]:
354+
raise ModelRegistryResourceNotFoundError(
355+
f"Failed to get ModelRegistry resource: {url}, {resp.status_code}: {resp.text}"
356+
)
357+
if json_output:
358+
try:
359+
return json.loads(resp.text)
360+
except json.JSONDecodeError:
361+
LOGGER.error(f"Unable to parse {resp.text}")
362+
raise
363+
else:
364+
return {"raw_output": resp.text}

0 commit comments

Comments
 (0)