Skip to content

Commit

Permalink
Add method to retrieve detailed pod information for improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kooomix committed Jan 1, 2025
1 parent 1a23406 commit 9c7b093
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests_scripts/kubernetes/base_k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,14 @@ def get_nodes(self):
def get_all_pods(self):
return self.kubernetes_obj.client_CoreV1Api.list_pod_for_all_namespaces()

def get_all_pods_printable_details(self):
pods = self.get_all_pods()
message = ""
for pod in pods.items:
message += "Pod name: {0}, namespace: {1}, status: {2}\n".format(pod.metadata.name, pod.metadata.namespace,
pod.status.phase)
return message

def get_pods(self, namespace: str = None, name: str = None, include_terminating: bool = True, wlid: str = None):
"""
:return: list of running pods
Expand Down Expand Up @@ -777,12 +785,8 @@ def verify_running_pods(self, namespace: str, replicas: int = None, name: str =
running_pods = self.get_ready_pods(namespace=namespace, name=name)
if comp_operator(len(running_pods), replicas): # and len(running_pods) == len(total_pods):
Logger.logger.info(f"all pods are running after {delta_t} seconds")
all_pods = self.get_all_pods()
Logger.logger.info("cluster states:")
# Print the pod details
for pod in all_pods.items:
Logger.logger.info(f"Namespace: {pod.metadata.namespace}, Name: {pod.metadata.name}, Status: {pod.status.phase}")

all_pods_message = self.get_all_pods_printable_details()
Logger.logger.info(f"cluster states:\n{all_pods_message}")
return
delta_t = (datetime.now() - start).total_seconds()
time.sleep(10)
Expand All @@ -792,12 +796,8 @@ def verify_running_pods(self, namespace: str, replicas: int = None, name: str =
format(timeout,
KubectlWrapper.convert_workload_to_dict(non_running_pods, f_json=True, indent=2)))

all_pods = self.get_all_pods()
Logger.logger.info("cluster states:")
# Print the pod details
for pod in all_pods.items:
Logger.logger.info(f"Namespace: {pod.metadata.namespace}, Name: {pod.metadata.name}, Status: {pod.status.phase}")

all_pods_message = self.get_all_pods_printable_details()
Logger.logger.info(f"cluster states:\n{all_pods_message}")
raise Exception("wrong number of pods are running after {} seconds. expected: {}, running: {}, pods:{}"
.format(delta_t, replicas, len(running_pods), running_pods)) # , len(total_pods)))

Expand Down

0 comments on commit 9c7b093

Please sign in to comment.