X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ric_robot_suite%2Fric-python-utils%2Fricutils%2FKubernetesEntity.py;h=89441679d87e44bf99cc3a50986e8b329569b28f;hb=e41f46a29c4d635ee3f864e36cfd0ac123bac4ec;hp=7b2535a1e185653e03ddc8137eee1fd9eda1841b;hpb=7bd8a0bd3e84d325d1a5d1df6feb7a259fee2004;p=it%2Ftest.git diff --git a/ric_robot_suite/ric-python-utils/ricutils/KubernetesEntity.py b/ric_robot_suite/ric-python-utils/ricutils/KubernetesEntity.py index 7b2535a..8944167 100644 --- a/ric_robot_suite/ric-python-utils/ricutils/KubernetesEntity.py +++ b/ric_robot_suite/ric-python-utils/ricutils/KubernetesEntity.py @@ -17,6 +17,7 @@ from kubernetes import client, config import string import random import time +import sys # This library provides a massively-simplified interface to the kubernetes # API library to reduce bloat in robot tests. @@ -82,3 +83,19 @@ class KubernetesEntity(object): timeout -= 1 raise TimeoutError('Kubernetes timeout waiting for ' + name + ' to become available') + def RetrievePodsForDeployment(self, name): + # return the pod names associated with a deployment + d = self.Deployment(name) + labels = d.spec.selector.match_labels + pods = self._k8sCore.list_namespaced_pod(self._ns, + label_selector=",".join(map(lambda k: k + "=" + labels[k], + labels))) + return map(lambda i: i.metadata.name, pods.items) + + def RetrieveLogForPod(self, pod, container='', tail=sys.maxsize): + # not really an "entity" thing per se, but. + # kinda want to include timestamps, but i don't have a use case for them. + return self._k8sCore.read_namespaced_pod_log(namespace=self._ns, + name=pod, + container=container, + tail_lines=tail).split('\n')[0:-1]