def wait_for_pods_and_verify(self): """ Wait for the pods to be created and verify only one pod is running """ # Wait for pods for pods in TimeoutSampler( 360, 2, func=pod.get_all_pods, namespace=self.namespace, selector=[self.name], selector_label="name", ): if len(pods) == self.replica_count: break pods_iter = cycle(pods) # Wait for one pod to be in Running state curr_pod = next(pods_iter) sampler = TimeoutSampler(360, 2, curr_pod.get) for pod_info in sampler: if pod_info["status"]["phase"] == constants.STATUS_RUNNING: self.running_pod = curr_pod log.info(f"Pod {curr_pod.name} reached state Running.") break curr_pod = next(pods_iter) sampler.func = curr_pod.get pods.remove(self.running_pod) pod_running_node = self.running_pod.get()["spec"]["nodeName"] # Verify the other pods are not coming up Running for pod_obj in pods: try: wait_for_resource_state(resource=pod_obj, state=constants.STATUS_RUNNING, timeout=10) assert pod_obj.get()["spec"]["nodeName"] == pod_running_node, ( f"Unexpected: Pod {pod_obj.name} is in Running state. " f"RWO PVC is mounted on pods which are on different nodes." ) log.info(f"Expected: Pod {pod_obj.name} is Running. " f"Pods which are running are on the same node " f"{pod_running_node}") except ResourceWrongStatusException: log.info(f"Verified: Pod {pod_obj.name} is not in " f"running state.")
def wait_for_pods_and_verify(self): """ Wait for both the pods to be created and verify only one pod is running """ # Wait for pods for pods in TimeoutSampler(180, 2, func=pod.get_all_pods, namespace=self.namespace, selector=[self.name], selector_label='name'): if len(pods) == 2: break pods_iter = cycle(pods) # Wait for one pod to be in Running state sampler = TimeoutSampler(180, 2, next(pods_iter).get) for pod_info in sampler: sampler.func = next(pods_iter).get if pod_info['status']['phase'] == constants.STATUS_RUNNING: self.running_pod = next(pods_iter) break # Verify the other pod is not coming up Running try: self.pod_not_running = next(pods_iter) wait_for_resource_state(resource=self.pod_not_running, state=constants.STATUS_RUNNING, timeout=10) # ResourceWrongStatusException exception should be raised in # wait_for_resource_state. If not, raise UnexpectedBehaviour. raise UnexpectedBehaviour( f"Unexpected: Pod {self.pod_not_running.name} is in " f"Running state") except ResourceWrongStatusException: log.info(f"Verified: Only one pod {self.running_pod.name} is in " f"running state.")