From fe7879cf63705d7122e202388b2e0ca807e49dcc Mon Sep 17 00:00:00 2001 From: AYUSH-D-PATNI Date: Wed, 18 Dec 2024 12:18:45 +0530 Subject: [PATCH 1/4] added two tests Signed-off-by: AYUSH-D-PATNI --- .../workloads/cnv/test_vm_pvc_expansion.py | 32 +++++++++ .../workloads/cnv/test_vm_snapshot_clone.py | 65 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 tests/functional/workloads/cnv/test_vm_pvc_expansion.py create mode 100644 tests/functional/workloads/cnv/test_vm_snapshot_clone.py diff --git a/tests/functional/workloads/cnv/test_vm_pvc_expansion.py b/tests/functional/workloads/cnv/test_vm_pvc_expansion.py new file mode 100644 index 00000000000..1d29c8b2b02 --- /dev/null +++ b/tests/functional/workloads/cnv/test_vm_pvc_expansion.py @@ -0,0 +1,32 @@ +import logging +import random + +from ocs_ci.framework.pytest_customization.marks import workloads, magenta_squad +from ocs_ci.framework.testlib import E2ETest +from ocs_ci.ocs import constants + +log = logging.getLogger(__name__) + + +@magenta_squad +@workloads +class TestVmPvcExpansion(E2ETest): + """ + Tests for VM PVC Expansion + """ + + def test_pvc_expansion(self, cnv_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) + # Resize PVC to a random size between 31 and 35 GiB + new_size = random.randint(31, 35) + log.info(vm_pvc_obj.size) + vm_pvc_obj.resize_pvc(new_size) + pass diff --git a/tests/functional/workloads/cnv/test_vm_snapshot_clone.py b/tests/functional/workloads/cnv/test_vm_snapshot_clone.py new file mode 100644 index 00000000000..2cd23755afa --- /dev/null +++ b/tests/functional/workloads/cnv/test_vm_snapshot_clone.py @@ -0,0 +1,65 @@ +import logging +from ocs_ci.framework.pytest_customization.marks import workloads, magenta_squad +from ocs_ci.framework.testlib import E2ETest +from ocs_ci.helpers.cnv_helpers import cal_md5sum_vm, run_dd_io +from ocs_ci.ocs import constants + +log = logging.getLogger(__name__) + + +@magenta_squad +@workloads +class TestVMSnapshotClone(E2ETest): + """ + Tests for VM PVC Expansion + """ + + def test_vm_snapshot_clone( + self, cnv_workload, snapshot_factory, snapshot_restore_factory + ): + """ + creates snapshot of a deployed vm and clones it + """ + + # create a VM + vm_obj = cnv_workload( + volume_interface=constants.VM_VOLUME_PVC, + source_url=constants.CNV_FEDORA_SOURCE, + )[-1] + + # put some content onto it + 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 + pvc_obj = vm_obj.get_vm_pvc_obj() + snap_obj = snapshot_factory(pvc_obj) + + # restoring the snapshot + res_snap_obj = snapshot_restore_factory( + snapshot_obj=snap_obj, + storageclass=vm_obj.sc_name, + size=vm_obj.pvc_size, + volume_mode=snap_obj.parent_volume_mode, + access_mode=vm_obj.pvc_access_mode, + status=constants.STATUS_BOUND, + timeout=300, + ) + # verify snapshot and data persist + # restore the snapshot to a new PVC + res_vm_obj = cnv_workload( + volume_interface=constants.VM_VOLUME_PVC, + source_url=constants.CNV_FEDORA_SOURCE, + pvc_obj=res_snap_obj, + namespace=vm_obj.namespace, + )[1] + # make sure data integrity is present + run_dd_io(vm_obj=res_vm_obj, file_path=file_paths[1], verify=True) + # getting the md5sum from the clone vm + 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 " + f"{res_vm_obj.name} VMs" + ) + res_vm_obj.stop() From 5411c6d860956785d7e0e5a0ade66371ad664d56 Mon Sep 17 00:00:00 2001 From: AYUSH-D-PATNI Date: Thu, 19 Dec 2024 14:07:20 +0530 Subject: [PATCH 2/4] improvised test case as per cmts Signed-off-by: AYUSH-D-PATNI --- .../workloads/cnv/test_vm_pvc_expansion.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/functional/workloads/cnv/test_vm_pvc_expansion.py b/tests/functional/workloads/cnv/test_vm_pvc_expansion.py index 1d29c8b2b02..622f165d5d8 100644 --- a/tests/functional/workloads/cnv/test_vm_pvc_expansion.py +++ b/tests/functional/workloads/cnv/test_vm_pvc_expansion.py @@ -4,6 +4,7 @@ from ocs_ci.framework.pytest_customization.marks import workloads, magenta_squad from ocs_ci.framework.testlib import E2ETest from ocs_ci.ocs import constants +from ocs_ci.helpers.cnv_helpers import cal_md5sum_vm, run_dd_io log = logging.getLogger(__name__) @@ -25,8 +26,18 @@ def test_pvc_expansion(self, cnv_workload): )[-1] vm_pvc_obj = vm_obj.get_vm_pvc_obj() log.info(vm_pvc_obj.size) - # Resize PVC to a random size between 31 and 35 GiB + # 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(vm_pvc_obj.size) + log.info(f"Size of VM PVC before expansion: {vm_pvc_obj.size}") vm_pvc_obj.resize_pvc(new_size) - pass + 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: MD5 comparison of {vm_obj.name} before and after " + f"PVC expansion" + ) From 0d645b1f6e8a7bf21e2c3201c915251675e9fa4f Mon Sep 17 00:00:00 2001 From: AYUSH-D-PATNI Date: Thu, 19 Dec 2024 16:04:40 +0530 Subject: [PATCH 3/4] logg Signed-off-by: AYUSH-D-PATNI --- tests/functional/workloads/cnv/test_vm_pvc_expansion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/workloads/cnv/test_vm_pvc_expansion.py b/tests/functional/workloads/cnv/test_vm_pvc_expansion.py index 622f165d5d8..191df9d6ac1 100644 --- a/tests/functional/workloads/cnv/test_vm_pvc_expansion.py +++ b/tests/functional/workloads/cnv/test_vm_pvc_expansion.py @@ -38,6 +38,6 @@ def test_pvc_expansion(self, cnv_workload): 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: MD5 comparison of {vm_obj.name} before and after " + f"Failed: Either VM PVC Expansion or MD5 comparison of {vm_obj.name} before and after " f"PVC expansion" ) From beb069fe91955cf62914d7a3ceba1f9352378b28 Mon Sep 17 00:00:00 2001 From: AYUSH-D-PATNI Date: Fri, 20 Dec 2024 14:02:12 +0530 Subject: [PATCH 4/4] added pvc_clone_factory fixture and better logs Signed-off-by: AYUSH-D-PATNI --- .../workloads/cnv/test_vm_pvc_expansion.py | 31 +++++++++---------- .../workloads/cnv/test_vm_snapshot_clone.py | 27 ++++++++++------ 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/tests/functional/workloads/cnv/test_vm_pvc_expansion.py b/tests/functional/workloads/cnv/test_vm_pvc_expansion.py index 191df9d6ac1..26dd0602538 100644 --- a/tests/functional/workloads/cnv/test_vm_pvc_expansion.py +++ b/tests/functional/workloads/cnv/test_vm_pvc_expansion.py @@ -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." ) diff --git a/tests/functional/workloads/cnv/test_vm_snapshot_clone.py b/tests/functional/workloads/cnv/test_vm_snapshot_clone.py index 2cd23755afa..450c0fa4960 100644 --- a/tests/functional/workloads/cnv/test_vm_snapshot_clone.py +++ b/tests/functional/workloads/cnv/test_vm_snapshot_clone.py @@ -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 @@ -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, @@ -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 "