|
11 | 11 | from simple_logger.logger import get_logger |
12 | 12 |
|
13 | 13 | import utilities.infra |
14 | | -from utilities.constants import Annotations, KServeDeploymentType, MODELMESH_SERVING |
15 | | -from utilities.exceptions import UnexpectedResourceCountError |
| 14 | +from utilities.constants import Annotations, KServeDeploymentType, MODELMESH_SERVING, Timeout |
| 15 | +from utilities.exceptions import UnexpectedResourceCountError, ResourceValueMismatch |
16 | 16 | from ocp_resources.resource import Resource |
17 | 17 | from timeout_sampler import retry |
18 | 18 |
|
@@ -331,3 +331,27 @@ def generate_random_name(prefix: str = "", length: int = 8) -> str: |
331 | 331 | # random_uuid.hex is 32 characters long. |
332 | 332 | suffix = random_uuid.hex[:length] |
333 | 333 | return f"{prefix}-{suffix}" if prefix else suffix |
| 334 | + |
| 335 | + |
| 336 | +@retry(wait_timeout=Timeout.TIMEOUT_15_SEC, sleep=1) |
| 337 | +def wait_for_container_status(pod: Pod, container_name: str, expected_status: str) -> bool: |
| 338 | + """ |
| 339 | + Wait for a container to be in the expected status. |
| 340 | +
|
| 341 | + Args: |
| 342 | + pod: The pod to wait for |
| 343 | + container_name: The name of the container to wait for |
| 344 | + expected_status: The expected status |
| 345 | +
|
| 346 | + Returns: |
| 347 | + bool: True if the container is in the expected status, False otherwise |
| 348 | +
|
| 349 | + Raises: |
| 350 | + ResourceValueMismatch: If the container is not in the expected status |
| 351 | + """ |
| 352 | + |
| 353 | + for cs in pod.instance.status.get("containerStatuses", []): |
| 354 | + if cs.name == container_name and cs.state.waiting.reason == expected_status: |
| 355 | + LOGGER.info(f"Pod is in the expected status {expected_status}") |
| 356 | + return True |
| 357 | + raise ResourceValueMismatch(f"Pod is not in the expected status {expected_status}") |
0 commit comments