Skip to content

Commit

Permalink
added pvc_clone_factory fixture and better logs
Browse files Browse the repository at this point in the history
Signed-off-by: AYUSH-D-PATNI <[email protected]>
  • Loading branch information
AYUSH-D-PATNI authored and AYUSH-D-PATNI committed Dec 20, 2024
1 parent ec1b49b commit cfb4008
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
31 changes: 15 additions & 16 deletions tests/functional/workloads/cnv/test_vm_pvc_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,25 @@ class TestVmPvcExpansion(E2ETest):

def test_pvc_expansion(self, cnv_workload):
"""
Test PVC expansion for a CNV VM workload
Test PVC expansion for a CNV VM workload.
"""
vm_obj = cnv_workload(
volume_interface=constants.VM_VOLUME_PVC,
source_url=constants.CNV_FEDORA_SOURCE,
)[-1]
vm_pvc_obj = vm_obj.get_vm_pvc_obj()
log.info(vm_pvc_obj.size)
# writing data to the PVC
file_paths = "/source_file.txt"
source_csum = run_dd_io(vm_obj=vm_obj, file_path=file_paths, verify=True)
log.info(source_csum)
# Resize PVC to a random size between 31 and 35 GiB as 30GiB is default
new_size = random.randint(31, 35)
log.info(f"Size of VM PVC before expansion: {vm_pvc_obj.size}")
vm_pvc_obj.resize_pvc(new_size)
log.info(f"Size of VM PVC after expansion: {vm_pvc_obj.size}")
res_csum = cal_md5sum_vm(vm_obj=vm_obj, file_path=file_paths)
log.info(res_csum)
assert source_csum == res_csum and vm_obj.get_vm_pvc_obj().size == new_size, (
f"Failed: Either VM PVC Expansion or MD5 comparison of {vm_obj.name} before and after "
f"PVC expansion"
log.info(f"Initial PVC size: {vm_pvc_obj.size} GiB")
file_path = "/source_file.txt"
source_csum = run_dd_io(vm_obj=vm_obj, file_path=file_path, verify=True)
log.info(f"Checksum before resize: {source_csum}")
new_size = random.randint(vm_pvc_obj.size + 1, vm_pvc_obj.size + 5)
log.info(f"Resizing PVC to {new_size} GiB")
vm_pvc_obj.resize_pvc(new_size, True)
vm_pvc_obj_n = vm_obj.get_vm_pvc_obj()
log.info(f"New PVC size: {vm_pvc_obj_n.size} GiB")
res_csum = cal_md5sum_vm(vm_obj=vm_obj, file_path=file_path)
log.info(f"Checksum after resize: {res_csum}")
assert source_csum == res_csum and vm_pvc_obj_n.size == new_size, (
f"Failed: PVC expansion or MD5 mismatch for VM '{vm_obj.name}'. "
f"Expected size: {new_size} GiB, but got: {vm_pvc_obj.size} GiB."
)
27 changes: 17 additions & 10 deletions tests/functional/workloads/cnv/test_vm_snapshot_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ class TestVMSnapshotClone(E2ETest):
"""

def test_vm_snapshot_clone(
self, cnv_workload, snapshot_factory, snapshot_restore_factory
self,
cnv_workload,
snapshot_factory,
snapshot_restore_factory,
pvc_clone_factory,
):
"""
creates snapshot of a deployed vm and clones it
creates snapshot of a deployed vm, restores the snapshot, and then clones the restored PVC.
"""

# create a VM
Expand All @@ -27,16 +31,16 @@ def test_vm_snapshot_clone(
source_url=constants.CNV_FEDORA_SOURCE,
)[-1]

# put some content onto it
# Write data to the VM
file_paths = ["/source_file.txt", "/new_file.txt"]
source_csum = run_dd_io(vm_obj=vm_obj, file_path=file_paths[0], verify=True)
vm_obj.stop()

# take a snapshot
# Take a snapshot of the VM's PVC
pvc_obj = vm_obj.get_vm_pvc_obj()
snap_obj = snapshot_factory(pvc_obj)

# restoring the snapshot
# Restore the snapshot to a new PVC
res_snap_obj = snapshot_restore_factory(
snapshot_obj=snap_obj,
storageclass=vm_obj.sc_name,
Expand All @@ -46,17 +50,20 @@ def test_vm_snapshot_clone(
status=constants.STATUS_BOUND,
timeout=300,
)
# verify snapshot and data persist
# restore the snapshot to a new PVC
# Clone the restored snapshot PVC to create a new PVC
cloned_pvc_obj = pvc_clone_factory(
pvc_obj=res_snap_obj, clone_name=f"{res_snap_obj.name}-clone"
)
# Create a new VM with the cloned PVC
res_vm_obj = cnv_workload(
volume_interface=constants.VM_VOLUME_PVC,
source_url=constants.CNV_FEDORA_SOURCE,
pvc_obj=res_snap_obj,
pvc_obj=cloned_pvc_obj,
namespace=vm_obj.namespace,
)[1]
# make sure data integrity is present
# Verify data integrity in the cloned VM
run_dd_io(vm_obj=res_vm_obj, file_path=file_paths[1], verify=True)
# getting the md5sum from the clone vm
# Check the MD5 checksum to verify that data persisted after cloning
res_csum = cal_md5sum_vm(vm_obj=res_vm_obj, file_path=file_paths[0])
assert source_csum == res_csum, (
f"Failed: MD5 comparison between source {vm_obj.name} and cloned "
Expand Down

0 comments on commit cfb4008

Please sign in to comment.