Skip to content

Commit

Permalink
Adding a new test case for reclaim space job and cronjob on rwop pvc (#…
Browse files Browse the repository at this point in the history
…10096)

* adding new test case for reclaim space job and cronjob on rwop pvc
* adding rwop reclaim space as a separate file and only for rbd

Signed-off-by: Yulia Persky <ypersky@redhat.com>
  • Loading branch information
ypersky1980 authored Jul 16, 2024
1 parent e685557 commit 06a6627
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
64 changes: 64 additions & 0 deletions ocs_ci/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5057,3 +5057,67 @@ def upgrade_multus_holder_design():
delete_csi_holder_pods()
delete_csi_holder_daemonsets()
verify_csi_holder_pods_do_not_exist()


def wait_for_reclaim_space_cronjob(reclaim_space_cron_job, schedule):
"""
Wait for reclaim space cronjbo
Args:
reclaim_space_cron_job (obj): The reclaim space cron job
schedule (str): Reclaim space cron job schedule
Raises:
UnexpectedBehaviour: In case reclaim space cron job doesn't reach the desired state
"""

try:
for reclaim_space_cron_job_yaml in TimeoutSampler(
timeout=120, sleep=5, func=reclaim_space_cron_job.get
):
result = reclaim_space_cron_job_yaml["spec"]["schedule"]
if result == f"@{schedule}":
logger.info(
f"ReclaimSpaceCronJob {reclaim_space_cron_job.name} succeeded"
)
break
else:
logger.info(
f"Waiting for the @{schedule} result of the ReclaimSpaceCronJob {reclaim_space_cron_job.name}. "
f"Present value of result is {result}"
)
except TimeoutExpiredError:
raise UnexpectedBehaviour(
f"ReclaimSpaceJob {reclaim_space_cron_job.name} is not successful. "
f"Yaml output: {reclaim_space_cron_job.get()}"
)


def wait_for_reclaim_space_job(reclaim_space_job):
"""
Wait for reclaim space cronjbo
Args:
reclaim_space_job (obj): The reclaim space job
Raises:
UnexpectedBehaviour: In case reclaim space job doesn't reach the Succeeded state
"""

try:
for reclaim_space_job_yaml in TimeoutSampler(
timeout=120, sleep=5, func=reclaim_space_job.get
):
result = reclaim_space_job_yaml.get("status", {}).get("result")
if result == "Succeeded":
logger.info(f"ReclaimSpaceJob {reclaim_space_job.name} succeeded")
break
else:
logger.info(
f"Waiting for the Succeeded result of the ReclaimSpaceJob {reclaim_space_job.name}. "
f"Present value of result is {result}"
)
except TimeoutExpiredError:
raise UnexpectedBehaviour(
f"ReclaimSpaceJob {reclaim_space_job.name} is not successful. Yaml output: {reclaim_space_job.get()}"
)
2 changes: 1 addition & 1 deletion tests/functional/pv/pv_services/test_rwop_pvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@skipif_ocs_version("<4.15")
class TestRwopPvc(ManageTest):
"""
Tests ReadWriteOncePod RBD PVC
Tests ReadWriteOncePod PVC
"""

@pytest.fixture(autouse=True)
Expand Down
40 changes: 40 additions & 0 deletions tests/functional/pv/pv_services/test_rwop_pvc_reclaim_space.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import logging

from ocs_ci.ocs import constants
from ocs_ci.framework.pytest_customization.marks import green_squad
from ocs_ci.framework.testlib import (
ManageTest,
tier2,
skipif_ocs_version,
)
from ocs_ci.helpers import helpers

log = logging.getLogger(__name__)


@green_squad
@tier2
@skipif_ocs_version("<4.15")
class TestRwopPvcReclaimSpace(ManageTest):
"""
Tests Reclaim Space on ReadWriteOncePod RBD PVC
"""

def test_rwop_pvc_reclaim_space(self, pvc_factory):
"""
Test to verify creation of reclaim space job and reclaim space cron job on RWOP pvc
"""

pvc_obj = pvc_factory(
interface=constants.CEPHBLOCKPOOL,
access_mode=constants.ACCESS_MODE_RWOP,
size=10,
)

schedule = "weekly"
reclaim_space_job = pvc_obj.create_reclaim_space_cronjob(schedule)
helpers.wait_for_reclaim_space_cronjob(reclaim_space_job, schedule)

reclaim_space_job = pvc_obj.create_reclaim_space_job()

helpers.wait_for_reclaim_space_job(reclaim_space_job)

0 comments on commit 06a6627

Please sign in to comment.