From 22394d6728564157b36f5d48eb3a0c3c891d95a4 Mon Sep 17 00:00:00 2001 From: Avdhoot Date: Mon, 30 Dec 2024 11:39:03 +0530 Subject: [PATCH 1/4] [WIP] CNV vm snapshot of cloned VM Signed-off-by: Avdhoot --- .../cnv/test_vm_snapshot_cloning_ops.py | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py b/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py index c8e34c93b4b..7d02103edf9 100644 --- a/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py +++ b/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py @@ -130,3 +130,96 @@ def test_vm_snapshot_ops( source_csum == res_csum ), f"Failed: MD5 comparison between source {vm_obj.name} and cloned {res_vm_obj.name} VMs" res_vm_obj.stop() + + @workloads + @pytest.mark.polarion_id("OCS-6288") + def test_vm_snap_of_clone( + self, + project_factory, + snapshot_factory, + snapshot_restore_factory, + multi_cnv_workload, + cnv_workload, + clone_vm_workload, + setup_cnv, + ): + """ + This test performs the VM cloning and IOs created using different volume interfaces(PVC/DV/DVT) + + Test steps: + 1. Create a clone of a VM PVC by following the documented procedure from ODF official docs. + 1.1 Create clone of the pvc associated with VM. + 1.2 Cloned pvc successfully created and listed + 2. Verify the cloned PVc is created. + 3. create vm using cloned pvc. + 4. Verify that the data on VM backed by cloned pvc is same as that in the original VM. + 5. Add additional data to the cloned VM. + 6. Create snapshot of cloned pvc + 7. Vertify snapshot of cloned pvc created successfully + 8. Validate the content of snapshot by restoring it to new pvc + 9. Create VM using restored pvc + 9. Check data conisistency on the new VM + 10. Delete the clone and restored pvc by following the documented procedure from ODF official docs + 1. Delete clone and restored pvc of the pvc associated with VM. + 2. cloned pvc and restored pvc successfully deleted + 11. Repeat the above procedure for all the VMs in the system + 12. Delete all the clones and restored pvc created as part of this test + """ + + proj_obj = project_factory() + file_paths = ["/source_file.txt", "/new_file.txt"] + vm_objs_def, vm_objs_aggr, _, _ = multi_cnv_workload( + namespace=proj_obj.namespace + ) + + vm_list = vm_objs_def + vm_objs_aggr + + for index, vm_obj in enumerate(vm_list): + source_csum = run_dd_io(vm_obj=vm_obj, file_path=file_paths[0], verify=True) + vm_obj.stop() + clone_obj = clone_vm_workload( + vm_obj=vm_obj, + volume_interface=vm_obj.volume_interface, + namespace=( + vm_obj.namespace + if vm_obj.volume_interface == constants.VM_VOLUME_PVC + else None + ), + )[index] + new_csum = cal_md5sum_vm(vm_obj=clone_obj, file_path=file_paths[0]) + assert ( + source_csum == new_csum + ), f"Failed: MD5 comparison between source {vm_obj.name} and cloned {clone_obj.name} VMs" + run_dd_io(vm_obj=clone_obj, file_path=file_paths[1]) + + clone_obj.stop() + + # Taking Snapshot of PVC + cloned_pvc_obj = clone_obj.get_vm_pvc_obj() + snap_obj = snapshot_factory(cloned_pvc_obj) + + # Restore the snapshot + res_snap_obj = snapshot_restore_factory( + snapshot_obj=snap_obj, + storageclass=vm_obj.sc_name, + volume_mode=snap_obj.parent_volume_mode, + access_mode=vm_obj.pvc_access_mode, + status=constants.STATUS_BOUND, + timeout=300, + ) + + # Create new VM using the restored PVC + res_vm_obj = cnv_workload( + source_url=constants.CNV_FEDORA_SOURCE, + storageclass=vm_obj.sc_name, + existing_pvc_obj=res_snap_obj, + namespace=vm_obj.namespace, + )[-1] + + restore_csum = cal_md5sum_vm(vm_obj=res_vm_obj, file_path=file_paths[0]) + assert ( + source_csum == restore_csum + ), f"Failed: MD5 comparison between source {vm_obj.name} and restored {res_vm_obj.name} VMs" + run_dd_io(vm_obj=res_vm_obj, file_path=file_paths[1]) + + res_vm_obj.stop() From 054fc09c21ee1ba07b051a4c4136aadf09bfbbbf Mon Sep 17 00:00:00 2001 From: Avdhoot Date: Mon, 6 Jan 2025 19:10:14 +0530 Subject: [PATCH 2/4] pvc_name is initialized in clone method Signed-off-by: Avdhoot --- ocs_ci/ocs/cnv/virtual_machine.py | 1 + .../workloads/cnv/test_vm_snapshot_cloning_ops.py | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ocs_ci/ocs/cnv/virtual_machine.py b/ocs_ci/ocs/cnv/virtual_machine.py index 0610a009fd9..02603bc8bf9 100644 --- a/ocs_ci/ocs/cnv/virtual_machine.py +++ b/ocs_ci/ocs/cnv/virtual_machine.py @@ -741,6 +741,7 @@ def _clone_vm_pvc(self, vm_data): access_mode=self.pvc_access_mode, volume_mode=constants.VOLUME_MODE_BLOCK, ) + self.pvc_name = self.pvc_obj.name wait_for_resource_state(self.pvc_obj, state=constants.STATUS_BOUND, timeout=300) vm_data["spec"]["template"]["spec"]["volumes"][0]["persistentVolumeClaim"] = { "claimName": self.pvc_obj.name diff --git a/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py b/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py index 7d02103edf9..c712b81a7b6 100644 --- a/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py +++ b/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py @@ -135,13 +135,13 @@ def test_vm_snapshot_ops( @pytest.mark.polarion_id("OCS-6288") def test_vm_snap_of_clone( self, + setup_cnv, project_factory, + multi_cnv_workload, + clone_vm_workload, snapshot_factory, snapshot_restore_factory, - multi_cnv_workload, cnv_workload, - clone_vm_workload, - setup_cnv, ): """ This test performs the VM cloning and IOs created using different volume interfaces(PVC/DV/DVT) @@ -192,10 +192,10 @@ def test_vm_snap_of_clone( ), f"Failed: MD5 comparison between source {vm_obj.name} and cloned {clone_obj.name} VMs" run_dd_io(vm_obj=clone_obj, file_path=file_paths[1]) - clone_obj.stop() - - # Taking Snapshot of PVC cloned_pvc_obj = clone_obj.get_vm_pvc_obj() + # Stopping VM before taking snapshot of the VM PVC + clone_obj.stop() + # Taking Snapshot of cloned PVC snap_obj = snapshot_factory(cloned_pvc_obj) # Restore the snapshot From 56d9b21c75d872bdc7de79ca9a68ea4cface4c0c Mon Sep 17 00:00:00 2001 From: Avdhoot Date: Wed, 22 Jan 2025 16:56:05 +0530 Subject: [PATCH 3/4] Removed indexing Signed-off-by: Avdhoot --- .../workloads/cnv/test_vm_snapshot_cloning_ops.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py b/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py index c712b81a7b6..2c313323e25 100644 --- a/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py +++ b/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py @@ -132,7 +132,7 @@ def test_vm_snapshot_ops( res_vm_obj.stop() @workloads - @pytest.mark.polarion_id("OCS-6288") + @pytest.mark.polarion_id("OCS-6325") def test_vm_snap_of_clone( self, setup_cnv, @@ -185,7 +185,7 @@ def test_vm_snap_of_clone( if vm_obj.volume_interface == constants.VM_VOLUME_PVC else None ), - )[index] + ) new_csum = cal_md5sum_vm(vm_obj=clone_obj, file_path=file_paths[0]) assert ( source_csum == new_csum @@ -214,12 +214,10 @@ def test_vm_snap_of_clone( storageclass=vm_obj.sc_name, existing_pvc_obj=res_snap_obj, namespace=vm_obj.namespace, - )[-1] + ) restore_csum = cal_md5sum_vm(vm_obj=res_vm_obj, file_path=file_paths[0]) assert ( source_csum == restore_csum ), f"Failed: MD5 comparison between source {vm_obj.name} and restored {res_vm_obj.name} VMs" run_dd_io(vm_obj=res_vm_obj, file_path=file_paths[1]) - - res_vm_obj.stop() From 74d4d64c64f07169a74d10ffbed2c83c5f855116 Mon Sep 17 00:00:00 2001 From: Avdhoot Date: Sun, 26 Jan 2025 14:13:50 +0530 Subject: [PATCH 4/4] Removed indexing added vm stop Signed-off-by: Avdhoot --- .../functional/workloads/cnv/test_vm_snapshot_cloning_ops.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py b/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py index 2c313323e25..f8dac240c0a 100644 --- a/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py +++ b/tests/functional/workloads/cnv/test_vm_snapshot_cloning_ops.py @@ -174,7 +174,7 @@ def test_vm_snap_of_clone( vm_list = vm_objs_def + vm_objs_aggr - for index, vm_obj in enumerate(vm_list): + for vm_obj in vm_list: source_csum = run_dd_io(vm_obj=vm_obj, file_path=file_paths[0], verify=True) vm_obj.stop() clone_obj = clone_vm_workload( @@ -221,3 +221,5 @@ def test_vm_snap_of_clone( source_csum == restore_csum ), f"Failed: MD5 comparison between source {vm_obj.name} and restored {res_vm_obj.name} VMs" run_dd_io(vm_obj=res_vm_obj, file_path=file_paths[1]) + + res_vm_obj.stop()