Skip to content

Commit

Permalink
Update to check running pods are on same node (#2383)
Browse files Browse the repository at this point in the history
* Update to check running pods are on same node

Signed-off-by: Jilju Joy <[email protected]>

* remove unused import

Signed-off-by: Jilju Joy <[email protected]>

* Modify test name to match with the update

Addressed other comments

Signed-off-by: Jilju Joy <[email protected]>
  • Loading branch information
jilju authored Oct 19, 2020
1 parent 709f7e3 commit d6b7b77
Showing 1 changed file with 41 additions and 32 deletions.
73 changes: 41 additions & 32 deletions tests/manage/pv_services/test_verify_rwo_using_dc_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

from ocs_ci.framework.testlib import ManageTest, tier2
from ocs_ci.ocs import constants
from ocs_ci.ocs.exceptions import (
ResourceWrongStatusException, UnexpectedBehaviour
)
from ocs_ci.ocs.exceptions import ResourceWrongStatusException
from ocs_ci.ocs.resources.ocs import OCS
from ocs_ci.ocs.resources import pod
from ocs_ci.ocs.ocp import OCP
Expand Down Expand Up @@ -35,7 +33,7 @@
)
]
)
class TestVerifyRwoUsingReplica2DcPod(ManageTest):
class TestVerifyRwoUsingReplicatedPod(ManageTest):
"""
This test class consists of tests to verify RWO volume is exclusively
mounted.
Expand All @@ -45,14 +43,15 @@ def setup(
self, interface, pvc_factory, service_account_factory, teardown_factory
):
"""
Create dc pod with replica 2
Create dc pod with replica 5
"""
self.replica_count = 5
pvc_obj = pvc_factory(interface=interface, size=3)
sa_obj = service_account_factory(project=pvc_obj.project)
pod1 = create_pod(
interface_type=interface, pvc_name=pvc_obj.name,
namespace=pvc_obj.namespace, sa_name=sa_obj.name,
dc_deployment=True, replica_count=2,
dc_deployment=True, replica_count=self.replica_count,
deploy_pod_status=constants.STATUS_RUNNING
)
self.name = pod1.labels['name']
Expand All @@ -71,49 +70,59 @@ def setup(

def wait_for_pods_and_verify(self):
"""
Wait for both the pods to be created and verify only one pod is running
Wait for 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,
360, 2, func=pod.get_all_pods, namespace=self.namespace,
selector=[self.name], selector_label='name'
):
if len(pods) == 2:
if len(pods) == self.replica_count:
break

pods_iter = cycle(pods)

# Wait for one pod to be in Running state
sampler = TimeoutSampler(180, 2, next(pods_iter).get)
curr_pod = next(pods_iter)
sampler = TimeoutSampler(360, 2, curr_pod.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)
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

# 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."
)
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 test_verify_rwo_using_replica_2_dc_pod(self):
def test_verify_rwo_using_replicated_pod(self):
"""
This test case verifies that RWO volume is exclusively mounted by using
replica 2 dc
replica 5 dc
"""
self.wait_for_pods_and_verify()

Expand Down

0 comments on commit d6b7b77

Please sign in to comment.