Skip to content

Commit 08ae480

Browse files
committed
test: add retry logic for RBAC propagation delays
1 parent e47941b commit 08ae480

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

tests/model_registry/model_catalog/test_default_model_catalog.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from ocp_resources.deployment import Deployment
88
from simple_logger.logger import get_logger
99
from typing import Self, Any
10+
from timeout_sampler import TimeoutSampler
11+
from kubernetes.dynamic.exceptions import ResourceNotFoundError
1012

1113
from ocp_resources.pod import Pod
1214
from ocp_resources.config_map import ConfigMap
@@ -170,10 +172,20 @@ def test_model_catalog_default_catalog_sources(
170172
Validate specific user can access default model catalog source
171173
"""
172174
LOGGER.info("Attempting client connection with token")
173-
result = execute_get_command(
174-
url=f"{model_catalog_rest_url[0]}sources",
175-
headers=get_rest_headers(token=user_token_for_api_calls),
176-
)["items"]
175+
176+
url = f"{model_catalog_rest_url[0]}sources"
177+
headers = get_rest_headers(token=user_token_for_api_calls)
178+
179+
# Retry for up to 2 minutes to allow RBAC propagation
180+
# Accept ResourceNotFoundError (401) as a transient error during RBAC propagation
181+
sampler = TimeoutSampler(
182+
wait_timeout=120,
183+
sleep=5,
184+
func=lambda: execute_get_command(url=url, headers=headers)["items"],
185+
exceptions_dict={ResourceNotFoundError: []},
186+
)
187+
188+
result = next(iter(sampler))
177189
assert result
178190
items_to_validate = []
179191
if pytestconfig.option.pre_upgrade or pytestconfig.option.post_upgrade:

tests/model_registry/rbac/test_mr_rbac_sa.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from model_registry import ModelRegistry as ModelRegistryClient
66
from tests.model_registry.rbac.utils import build_mr_client_args
77
from utilities.infra import create_inference_token
8-
from mr_openapi.exceptions import ForbiddenException
8+
from mr_openapi.exceptions import ForbiddenException, UnauthorizedException
99
from ocp_resources.service_account import ServiceAccount
10+
from timeout_sampler import TimeoutSampler
1011

1112
LOGGER = get_logger(name=__name__)
1213

@@ -69,21 +70,29 @@ def test_service_account_access_granted(
6970
LOGGER.info(f"Targeting Model Registry REST endpoint: {model_registry_instance_rest_endpoint[0]}")
7071
LOGGER.info("Applied RBAC Role/Binding via fixtures. Expecting access GRANT.")
7172

72-
# Create a fresh token to bypass OAuth proxy cache from previous test
73+
# Create a fresh token to bypass kube-rbac-proxy cache from previous test
7374
fresh_token = create_inference_token(model_service_account=service_account)
75+
client_args = build_mr_client_args(
76+
rest_endpoint=model_registry_instance_rest_endpoint[0], token=fresh_token, author="rbac-test-granted"
77+
)
78+
LOGGER.debug(f"Attempting client connection with args: {client_args}")
79+
80+
# Retry for up to 2 minutes to allow RBAC propagation
81+
# Accept UnauthorizedException (401) as a transient error during RBAC propagation
82+
sampler = TimeoutSampler(
83+
wait_timeout=120,
84+
sleep=5,
85+
func=lambda: ModelRegistryClient(**client_args),
86+
exceptions_dict={UnauthorizedException: []},
87+
)
7488

7589
try:
76-
client_args = build_mr_client_args(
77-
rest_endpoint=model_registry_instance_rest_endpoint[0], token=fresh_token, author="rbac-test-granted"
78-
)
79-
LOGGER.debug(f"Attempting client connection with args: {client_args}")
80-
mr_client_success = ModelRegistryClient(**client_args)
90+
# Get the first successful result
91+
mr_client_success = next(iter(sampler))
8192
assert mr_client_success is not None, "Client initialization failed after granting permissions"
8293
LOGGER.info("Client instantiated successfully after granting permissions.")
83-
8494
except Exception as e:
85-
# If we get an exception here, it's unexpected, especially 403
86-
LOGGER.error(f"Received unexpected general error after granting access: {e}", exc_info=True)
95+
LOGGER.error(f"Failed to access Model Registry after granting permissions: {e}", exc_info=True)
8796
raise
8897

8998
LOGGER.info("--- RBAC Test Completed Successfully ---")

0 commit comments

Comments
 (0)