Skip to content

Commit cfb4008

Browse files
AYUSH-D-PATNIAYUSH-D-PATNI
AYUSH-D-PATNI
authored and
AYUSH-D-PATNI
committed
added pvc_clone_factory fixture and better logs
Signed-off-by: AYUSH-D-PATNI <[email protected]>
1 parent ec1b49b commit cfb4008

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

tests/functional/workloads/cnv/test_vm_pvc_expansion.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,25 @@ class TestVmPvcExpansion(E2ETest):
1818

1919
def test_pvc_expansion(self, cnv_workload):
2020
"""
21-
Test PVC expansion for a CNV VM workload
21+
Test PVC expansion for a CNV VM workload.
2222
"""
2323
vm_obj = cnv_workload(
2424
volume_interface=constants.VM_VOLUME_PVC,
2525
source_url=constants.CNV_FEDORA_SOURCE,
2626
)[-1]
2727
vm_pvc_obj = vm_obj.get_vm_pvc_obj()
28-
log.info(vm_pvc_obj.size)
29-
# writing data to the PVC
30-
file_paths = "/source_file.txt"
31-
source_csum = run_dd_io(vm_obj=vm_obj, file_path=file_paths, verify=True)
32-
log.info(source_csum)
33-
# Resize PVC to a random size between 31 and 35 GiB as 30GiB is default
34-
new_size = random.randint(31, 35)
35-
log.info(f"Size of VM PVC before expansion: {vm_pvc_obj.size}")
36-
vm_pvc_obj.resize_pvc(new_size)
37-
log.info(f"Size of VM PVC after expansion: {vm_pvc_obj.size}")
38-
res_csum = cal_md5sum_vm(vm_obj=vm_obj, file_path=file_paths)
39-
log.info(res_csum)
40-
assert source_csum == res_csum and vm_obj.get_vm_pvc_obj().size == new_size, (
41-
f"Failed: Either VM PVC Expansion or MD5 comparison of {vm_obj.name} before and after "
42-
f"PVC expansion"
28+
log.info(f"Initial PVC size: {vm_pvc_obj.size} GiB")
29+
file_path = "/source_file.txt"
30+
source_csum = run_dd_io(vm_obj=vm_obj, file_path=file_path, verify=True)
31+
log.info(f"Checksum before resize: {source_csum}")
32+
new_size = random.randint(vm_pvc_obj.size + 1, vm_pvc_obj.size + 5)
33+
log.info(f"Resizing PVC to {new_size} GiB")
34+
vm_pvc_obj.resize_pvc(new_size, True)
35+
vm_pvc_obj_n = vm_obj.get_vm_pvc_obj()
36+
log.info(f"New PVC size: {vm_pvc_obj_n.size} GiB")
37+
res_csum = cal_md5sum_vm(vm_obj=vm_obj, file_path=file_path)
38+
log.info(f"Checksum after resize: {res_csum}")
39+
assert source_csum == res_csum and vm_pvc_obj_n.size == new_size, (
40+
f"Failed: PVC expansion or MD5 mismatch for VM '{vm_obj.name}'. "
41+
f"Expected size: {new_size} GiB, but got: {vm_pvc_obj.size} GiB."
4342
)

tests/functional/workloads/cnv/test_vm_snapshot_clone.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ class TestVMSnapshotClone(E2ETest):
1515
"""
1616

1717
def test_vm_snapshot_clone(
18-
self, cnv_workload, snapshot_factory, snapshot_restore_factory
18+
self,
19+
cnv_workload,
20+
snapshot_factory,
21+
snapshot_restore_factory,
22+
pvc_clone_factory,
1923
):
2024
"""
21-
creates snapshot of a deployed vm and clones it
25+
creates snapshot of a deployed vm, restores the snapshot, and then clones the restored PVC.
2226
"""
2327

2428
# create a VM
@@ -27,16 +31,16 @@ def test_vm_snapshot_clone(
2731
source_url=constants.CNV_FEDORA_SOURCE,
2832
)[-1]
2933

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

35-
# take a snapshot
39+
# Take a snapshot of the VM's PVC
3640
pvc_obj = vm_obj.get_vm_pvc_obj()
3741
snap_obj = snapshot_factory(pvc_obj)
3842

39-
# restoring the snapshot
43+
# Restore the snapshot to a new PVC
4044
res_snap_obj = snapshot_restore_factory(
4145
snapshot_obj=snap_obj,
4246
storageclass=vm_obj.sc_name,
@@ -46,17 +50,20 @@ def test_vm_snapshot_clone(
4650
status=constants.STATUS_BOUND,
4751
timeout=300,
4852
)
49-
# verify snapshot and data persist
50-
# restore the snapshot to a new PVC
53+
# Clone the restored snapshot PVC to create a new PVC
54+
cloned_pvc_obj = pvc_clone_factory(
55+
pvc_obj=res_snap_obj, clone_name=f"{res_snap_obj.name}-clone"
56+
)
57+
# Create a new VM with the cloned PVC
5158
res_vm_obj = cnv_workload(
5259
volume_interface=constants.VM_VOLUME_PVC,
5360
source_url=constants.CNV_FEDORA_SOURCE,
54-
pvc_obj=res_snap_obj,
61+
pvc_obj=cloned_pvc_obj,
5562
namespace=vm_obj.namespace,
5663
)[1]
57-
# make sure data integrity is present
64+
# Verify data integrity in the cloned VM
5865
run_dd_io(vm_obj=res_vm_obj, file_path=file_paths[1], verify=True)
59-
# getting the md5sum from the clone vm
66+
# Check the MD5 checksum to verify that data persisted after cloning
6067
res_csum = cal_md5sum_vm(vm_obj=res_vm_obj, file_path=file_paths[0])
6168
assert source_csum == res_csum, (
6269
f"Failed: MD5 comparison between source {vm_obj.name} and cloned "

0 commit comments

Comments
 (0)