Skip to content

Commit 7c78ded

Browse files
committed
fix: address review comments
Signed-off-by: Swati Mukund Bagal <[email protected]>
1 parent 6c41d8e commit 7c78ded

File tree

3 files changed

+27
-53
lines changed

3 files changed

+27
-53
lines changed

tests/model_serving/maas_billing/maas_subscription/conftest.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -49,49 +49,6 @@
4949
CHAT_COMPLETIONS = OpenAIEnpoints.CHAT_COMPLETIONS
5050

5151

52-
# # TEMPORARY: patches maas-controller to pr-498 to fix /v1/models 500 response.
53-
# # Remove once the upstream maas-controller image is fixed (Konflux onboarding complete).
54-
# @pytest.fixture(scope="session")
55-
# def maas_controller_pr498_image(
56-
# admin_client: DynamicClient,
57-
# maas_subscription_controller_enabled_latest: DataScienceCluster,
58-
# ) -> Generator[None, Any, Any]:
59-
# """Patch maas-controller image to pr-498 after MaaS is enabled.
60-
61-
# The maas-controller:latest image has a broken /v1/models endpoint (returns 500).
62-
# This fixture temporarily overrides the image after the operator creates the deployment.
63-
# """
64-
# deployment = Deployment(
65-
# client=admin_client,
66-
# name="maas-controller",
67-
# namespace=MAAS_DB_NAMESPACE,
68-
# )
69-
# deployment.wait_for_condition(condition="Available", status="True", timeout=120)
70-
71-
# with ResourceEditor(
72-
# patches={
73-
# deployment: {
74-
# "metadata": {"annotations": {"opendatahub.io/managed": "false"}},
75-
# "spec": {
76-
# "template": {
77-
# "spec": {
78-
# "containers": [
79-
# {
80-
# "name": "manager",
81-
# "image": "quay.io/opendatahub/maas-controller:pr-498",
82-
# }
83-
# ]
84-
# }
85-
# }
86-
# },
87-
# }
88-
# }
89-
# ):
90-
# deployment.wait_for_condition(condition="Available", status="True", timeout=180)
91-
# LOGGER.info("[TEMPORARY] maas-controller patched to pr-498 image")
92-
# yield
93-
94-
9552
@pytest.fixture(scope="session")
9653
def maas_subscription_controller_enabled_latest(
9754
dsc_resource: DataScienceCluster,

tests/model_serving/maas_billing/maas_subscription/test_api_key_expiration.py

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

66
from tests.model_serving.maas_billing.maas_subscription.utils import (
77
assert_api_key_created_ok,
8+
assert_api_key_get_ok,
89
create_api_key,
910
get_api_key,
11+
revoke_api_key,
1012
)
1113
from utilities.general import generate_random_name
1214
from utilities.opendatahub_logger import get_logger
@@ -44,11 +46,17 @@ def test_create_key_within_expiration_limit(
4446
expires_in=f"{expires_in_hours}h",
4547
raise_on_error=False,
4648
)
47-
assert_api_key_created_ok(create_resp, create_body, required_fields=("key", "expiresAt"))
49+
assert_api_key_created_ok(resp=create_resp, body=create_body, required_fields=("key", "expiresAt"))
4850
LOGGER.info(
4951
f"[expiration] Created key within limit: expires_in={expires_in_hours}h, "
5052
f"expiresAt={create_body.get('expiresAt')}"
5153
)
54+
revoke_api_key(
55+
request_session_http=request_session_http,
56+
base_url=base_url,
57+
key_id=create_body["id"],
58+
ocp_user_token=ocp_token_for_actor,
59+
)
5260

5361
@pytest.mark.tier1
5462
def test_create_key_at_expiration_limit(
@@ -69,11 +77,17 @@ def test_create_key_at_expiration_limit(
6977
expires_in=f"{expires_in_hours}h",
7078
raise_on_error=False,
7179
)
72-
assert_api_key_created_ok(create_resp, create_body, required_fields=("key", "expiresAt"))
80+
assert_api_key_created_ok(resp=create_resp, body=create_body, required_fields=("key", "expiresAt"))
7381
LOGGER.info(
7482
f"[expiration] Created key at limit: expires_in={expires_in_hours}h "
7583
f"({MAAS_API_KEY_MAX_EXPIRATION_DAYS} days)"
7684
)
85+
revoke_api_key(
86+
request_session_http=request_session_http,
87+
base_url=base_url,
88+
key_id=create_body["id"],
89+
ocp_user_token=ocp_token_for_actor,
90+
)
7791

7892
@pytest.mark.tier1
7993
def test_create_key_exceeds_expiration_limit(
@@ -122,10 +136,9 @@ def test_create_key_without_expiration(
122136
key_id=active_api_key_id,
123137
ocp_user_token=ocp_token_for_actor,
124138
)
125-
assert get_resp.status_code == 200, (
126-
f"Expected 200 on GET /v1/api-keys/{active_api_key_id}, got {get_resp.status_code}: {get_resp.text[:200]}"
127-
)
139+
assert_api_key_get_ok(resp=get_resp, body=get_body, key_id=active_api_key_id)
128140
expires_at = get_body.get("expiresAt")
141+
assert expires_at is None, f"Expected no 'expiresAt' for key created without expiration, got: {expires_at!r}"
129142
LOGGER.info(f"[expiration] Key without expiration field: expiresAt={expires_at!r}")
130143

131144
@pytest.mark.tier2
@@ -136,17 +149,14 @@ def test_create_key_with_short_expiration(
136149
ocp_token_for_actor: str,
137150
short_expiration_api_key_id: str,
138151
) -> None:
139-
"""Verify a key created with a 1-hour expiration has a non-null expiresAt value."""
152+
"""Verify a key created with a 1-hour expiration has a non-null expirationDate value."""
140153
get_resp, get_body = get_api_key(
141154
request_session_http=request_session_http,
142155
base_url=base_url,
143156
key_id=short_expiration_api_key_id,
144157
ocp_user_token=ocp_token_for_actor,
145158
)
146-
assert get_resp.status_code == 200, (
147-
f"Expected 200 on GET /v1/api-keys/{short_expiration_api_key_id}, "
148-
f"got {get_resp.status_code}: {get_resp.text[:200]}"
149-
)
159+
assert_api_key_get_ok(resp=get_resp, body=get_body, key_id=short_expiration_api_key_id)
150160
assert get_body.get("expirationDate"), (
151161
f"Expected non-null 'expirationDate' for 1h key, got: {get_body.get('expirationDate')!r}"
152162
)

tests/model_serving/maas_billing/maas_subscription/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,13 @@ def assert_api_key_created_ok(
460460
assert field in body, f"Response must contain '{field}'"
461461

462462

463+
def assert_api_key_get_ok(resp: Response, body: dict[str, Any], key_id: str) -> None:
464+
"""Assert a GET /v1/api-keys/{id} response has status 200."""
465+
assert resp.status_code == 200, (
466+
f"Expected 200 on GET /v1/api-keys/{key_id}, got {resp.status_code}: {resp.text[:200]}"
467+
)
468+
469+
463470
def get_maas_postgres_labels() -> dict[str, str]:
464471
return {
465472
"app": "postgres",

0 commit comments

Comments
 (0)