def wait_for_pod_restart(namespace, name, timeout): while timeout > 0: r = k8sclient.get_pod_info(namespace, name) if r.status.container_statuses[0].restart_count > 0: return time.sleep(1) timeout -= 1 assert False, "Fail to wait for pod %s to restart" % name
def wait_for_pod_state(name, timeout): while timeout > 0: r = k8sclient.get_pod_info(namespace, name) if r.status.phase == "Running": print name, "is running." return True time.sleep(1) timeout -= 1 print "Fail to wait for pod %s Running" % name, r.status.phase return False
def wait_for_pod_state(namespace, name, timeout, expect_status): while timeout > 0: r = k8sclient.get_pod_info(namespace, name) if r.status.phase == expect_status: break time.sleep(1) timeout -= 1 if (timeout % 1800) == 0: print ">>>>>>>", timeout k8sclient.print_pod_stats(namespace) assert timeout > 0, "Fail to wait expect status %s, current %s" % ( expect_status, r.status.phase) return timeout
def check_cross(node1, node2): name_prefix1 = "-".join(node1.split(".")) + uid pod1 = name_prefix1 + "-pod-2" name_prefix2 = "-".join(node2.split(".")) + uid service2 = "service-2-" + name_prefix2 pod2 = name_prefix2 + "-pod-2" pod2_ip = k8sclient.get_pod_info(namespace, pod2).status.pod_ip ok = True ok &= check_service(pod1, service2) ok &= check_service(pod1, pod2_ip) ok &= check_ping(pod1, node2) ok &= check_ping(pod1, node1) return ok
def check_local(node): name_prefix = "-".join(node.split(".")) + uid pod1 = name_prefix + "-pod-1" pod2 = name_prefix + "-pod-2" pod2_ip = k8sclient.get_pod_info(namespace, pod2).status.pod_ip service1 = "service-1-" + name_prefix service2 = "service-2-" + name_prefix ok = True ok &= check_service(pod1, service1) ok &= check_service(pod1, service2) ok &= check_service(pod1, pod2_ip) ok &= check_service(pod1, global_service) return ok
def get_pod_restart_count(namespace, name): r = k8sclient.get_pod_info(namespace, name) return r.status.container_statuses[0].restart_count