Skip to content

Commit ae6982c

Browse files
committed
refactor the collect_pod_information function to be re-used in different component tests
Signed-off-by: Kamesh Akella <kakella@redhat.com>
1 parent 62ab79d commit ae6982c

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

tests/model_registry/async_job/utils.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from timeout_sampler import TimeoutExpiredError
1111

1212
from utilities.must_gather_collector import get_base_dir, get_must_gather_collector_dir
13+
from utilities.general import collect_pod_information
1314

1415
LOGGER = get_logger(name=__name__)
1516

@@ -136,22 +137,3 @@ def upload_test_model_to_minio_from_image(
136137
LOGGER.info(
137138
f"Test model file uploaded successfully to s3://{MinIo.Buckets.MODELMESH_EXAMPLE_MODELS}/{object_key}"
138139
)
139-
140-
141-
def collect_pod_information(pod: Pod) -> None:
142-
try:
143-
base_dir_name = get_must_gather_collector_dir() or get_base_dir()
144-
LOGGER.info(f"Collecting pod information for {pod.name}: {base_dir_name}")
145-
os.makedirs(base_dir_name, exist_ok=True)
146-
yaml_file_path = os.path.join(base_dir_name, f"{pod.name}.yaml")
147-
with open(yaml_file_path, "w") as fd:
148-
fd.write(pod.instance.to_str())
149-
# get all the containers of the pod:
150-
151-
containers = [container["name"] for container in pod.instance.status.containerStatuses]
152-
for container in containers:
153-
file_path = os.path.join(base_dir_name, f"{pod.name}_{container}.log")
154-
with open(file_path, "w") as fd:
155-
fd.write(pod.log(**{"container": container}))
156-
except Exception:
157-
LOGGER.warning(f"For pod: {pod.name} information gathering failed.")

tests/workbenches/conftest.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from utilities import constants
1818
from utilities.constants import INTERNAL_IMAGE_REGISTRY_PATH
1919
from utilities.infra import check_internal_image_registry_available
20+
from utilities.general import collect_pod_information
2021

2122
LOGGER = get_logger(name=__name__)
2223

@@ -67,16 +68,21 @@ def notebook_image(
6768
if not custom_image:
6869
raise ValueError("custom_image cannot be empty or whitespace")
6970

70-
# Validation Logic (Moved from default_notebook)
71+
# Validation Logic: Only digest references are accepted
7172
_ERR_INVALID_CUSTOM_IMAGE = (
72-
"custom_image must be a valid OCI image reference with either a tag (:tag) or digest (@sha256:digest), "
73-
"e.g., 'quay.io/org/image:tag' or 'quay.io/org/image@sha256:digest', "
73+
"custom_image must be a valid OCI image reference with a digest (@sha256:digest), "
74+
"e.g., 'quay.io/org/image@sha256:abc123...', "
7475
"got: '{custom_image}'"
7576
)
76-
has_digest = "@sha256:" in custom_image
77-
has_tag = ":" in custom_image and custom_image.rfind(":") > custom_image.rfind("/")
78-
79-
if not (has_digest or has_tag):
77+
# Check for valid digest: @sha256: must be followed by non-empty content
78+
digest_marker = "@sha256:"
79+
has_valid_digest = False
80+
if digest_marker in custom_image:
81+
digest_index = custom_image.rfind(digest_marker)
82+
digest_end = digest_index + len(digest_marker)
83+
has_valid_digest = digest_end < len(custom_image)
84+
85+
if not has_valid_digest:
8086
raise ValueError(_ERR_INVALID_CUSTOM_IMAGE.format(custom_image=custom_image))
8187

8288
LOGGER.info(f"Using custom workbench image: {custom_image}")
@@ -261,6 +267,8 @@ def notebook_pod(
261267
)
262268
except (TimeoutError, RuntimeError) as e:
263269
if notebook_pod.exists:
270+
# Collect pod information for debugging purposes
271+
collect_pod_information(notebook_pod)
264272
pod_status = notebook_pod.instance.status
265273
pod_phase = pod_status.phase
266274
error_details = get_pod_failure_details(notebook_pod)

utilities/general.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
from typing import List, Tuple, Any
44
import uuid
5+
import os
56

67
from kubernetes.dynamic import DynamicClient
78
from kubernetes.dynamic.exceptions import ResourceNotFoundError, NotFoundError
@@ -13,6 +14,7 @@
1314
import utilities.infra
1415
from utilities.constants import Annotations, KServeDeploymentType, MODELMESH_SERVING
1516
from utilities.exceptions import UnexpectedResourceCountError, ResourceValueMismatch
17+
from utilities.must_gather_collector import get_base_dir, get_must_gather_collector_dir
1618
from ocp_resources.resource import Resource
1719
from timeout_sampler import retry
1820
from timeout_sampler import TimeoutExpiredError, TimeoutSampler
@@ -467,3 +469,22 @@ def wait_for_pods_running(
467469
)
468470
raise
469471
return None
472+
473+
474+
def collect_pod_information(pod: Pod) -> None:
475+
try:
476+
base_dir_name = get_must_gather_collector_dir() or get_base_dir()
477+
LOGGER.info(f"Collecting pod information for {pod.name}: {base_dir_name}")
478+
os.makedirs(base_dir_name, exist_ok=True)
479+
yaml_file_path = os.path.join(base_dir_name, f"{pod.name}.yaml")
480+
with open(yaml_file_path, "w") as fd:
481+
fd.write(pod.instance.to_str())
482+
# get all the containers of the pod:
483+
484+
containers = [container["name"] for container in pod.instance.status.containerStatuses]
485+
for container in containers:
486+
file_path = os.path.join(base_dir_name, f"{pod.name}_{container}.log")
487+
with open(file_path, "w") as fd:
488+
fd.write(pod.log(**{"container": container}))
489+
except Exception:
490+
LOGGER.warning(f"For pod: {pod.name} information gathering failed.")

0 commit comments

Comments
 (0)