|
9 | 9 |
|
10 | 10 | from ocp_resources.config_map import ConfigMap |
11 | 11 | from ocp_resources.resource import ResourceEditor |
12 | | - |
13 | 12 | from ocp_resources.service_account import ServiceAccount |
14 | 13 | from tests.model_registry.model_catalog.constants import ( |
15 | 14 | SAMPLE_MODEL_NAME3, |
16 | 15 | DEFAULT_CATALOG_FILE, |
17 | 16 | CATALOG_CONTAINER, |
18 | 17 | REDHAT_AI_CATALOG_ID, |
19 | 18 | ) |
20 | | -from tests.model_registry.model_catalog.utils import get_models_from_catalog_api |
| 19 | +from tests.model_registry.model_catalog.utils import get_models_from_catalog_api, get_catalog_url_and_headers |
21 | 20 | from tests.model_registry.constants import ( |
22 | 21 | CUSTOM_CATALOG_ID1, |
23 | 22 | DEFAULT_MODEL_CATALOG_CM, |
|
42 | 41 | def enabled_model_catalog_config_map( |
43 | 42 | admin_client: DynamicClient, |
44 | 43 | model_registry_namespace: str, |
| 44 | + current_client_token: str, |
45 | 45 | ) -> ConfigMap: |
46 | 46 | """ |
47 | 47 | Enable all catalogs in the default model catalog configmap |
@@ -74,7 +74,17 @@ def enabled_model_catalog_config_map( |
74 | 74 | patches = {"data": {"sources.yaml": enabled_sources_yaml}} |
75 | 75 |
|
76 | 76 | with ResourceEditor(patches={user_sources_cm: patches}): |
| 77 | + # Wait for the model catalog pod to be ready |
77 | 78 | is_model_catalog_ready(client=admin_client, model_registry_namespace=model_registry_namespace) |
| 79 | + |
| 80 | + # Get the model catalog URL and headers and wait for the API to be fully ready |
| 81 | + catalog_url, headers = get_catalog_url_and_headers( |
| 82 | + admin_client=admin_client, |
| 83 | + model_registry_namespace=model_registry_namespace, |
| 84 | + token=current_client_token, |
| 85 | + ) |
| 86 | + wait_for_model_catalog_api(url=catalog_url, headers=headers) |
| 87 | + |
78 | 88 | yield user_sources_cm |
79 | 89 |
|
80 | 90 |
|
@@ -145,33 +155,44 @@ def user_token_for_api_calls( |
145 | 155 | api_server_url: str, |
146 | 156 | user_credentials_rbac: dict[str, str], |
147 | 157 | service_account: ServiceAccount, |
| 158 | + model_catalog_rest_url: list[str], |
148 | 159 | ) -> Generator[str, None, None]: |
149 | 160 | param = getattr(request, "param", {}) |
150 | 161 | user = param.get("user_type", "admin") |
151 | 162 | LOGGER.info("User used: %s", user) |
| 163 | + |
| 164 | + token = None |
152 | 165 | if user == "admin": |
153 | 166 | LOGGER.info("Logging in as admin user") |
154 | | - yield get_openshift_token() |
| 167 | + token = get_openshift_token() |
155 | 168 | elif user == "test": |
156 | 169 | if not is_byoidc: |
157 | 170 | login_with_user_password( |
158 | 171 | api_address=api_server_url, |
159 | 172 | user=user_credentials_rbac["username"], |
160 | 173 | password=user_credentials_rbac["password"], |
161 | 174 | ) |
162 | | - yield get_openshift_token() |
163 | | - LOGGER.info(f"Logging in as {original_user}") |
164 | | - login_with_user_password( |
165 | | - api_address=api_server_url, |
166 | | - user=original_user, |
167 | | - ) |
| 175 | + token = get_openshift_token() |
168 | 176 | else: |
169 | | - yield get_mr_user_token(admin_client=admin_client, user_credentials_rbac=user_credentials_rbac) |
| 177 | + token = get_mr_user_token(admin_client=admin_client, user_credentials_rbac=user_credentials_rbac) |
170 | 178 | elif user == "sa_user": |
171 | | - yield create_inference_token(service_account) |
| 179 | + token = create_inference_token(service_account) |
| 180 | + # retries on 401 errors for OAuth/kube-rbac-proxy initialization |
| 181 | + headers = get_rest_headers(token=token) |
| 182 | + wait_for_model_catalog_api(url=model_catalog_rest_url[0], headers=headers) |
172 | 183 | else: |
173 | 184 | raise RuntimeError(f"Unknown user type: {user}") |
174 | 185 |
|
| 186 | + yield token |
| 187 | + |
| 188 | + # Cleanup: log back in as original user if needed |
| 189 | + if user == "test" and not is_byoidc: |
| 190 | + LOGGER.info(f"Logging in as {original_user}") |
| 191 | + login_with_user_password( |
| 192 | + api_address=api_server_url, |
| 193 | + user=original_user, |
| 194 | + ) |
| 195 | + |
175 | 196 |
|
176 | 197 | @pytest.fixture(scope="function") |
177 | 198 | def randomly_picked_model_from_catalog_api_by_source( |
@@ -203,7 +224,6 @@ def randomly_picked_model_from_catalog_api_by_source( |
203 | 224 | headers = model_registry_rest_headers |
204 | 225 | else: |
205 | 226 | headers = get_rest_headers(token=user_token_for_api_calls) |
206 | | - wait_for_model_catalog_api(url=f"{model_catalog_rest_url[0]}", headers=headers) |
207 | 227 |
|
208 | 228 | if not model_name: |
209 | 229 | LOGGER.info(f"Picking random model from catalog: {catalog_id} with header_type: {header_type}") |
|
0 commit comments