-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VM hot plugging and unplugging #11149
Open
ayush-patni
wants to merge
20
commits into
red-hat-storage:master
Choose a base branch
from
ayush-patni:hot-plug-unplug
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+205
−46
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a6c9ff6
added two tests
1f06ca0
improvised test case as per cmts
1b5493d
logg
53f19f2
added pvc_clone_factory fixture and better logs
c35ac0f
removed two tcs
98e9d5e
adding test case test_vm_hotplug_unplug.py with updated test_vm_singl…
7efde5b
update in hotplug tc cmt
e6304d0
updated hotplug-unplug tc n verify in vm
75fcd9b
Update cmt in verify_volume
ayush-patni 8b90396
Update cnv_helpers.py
ayush-patni d8edeb3
update as per review cmt
ef235f6
improvised verifyvolume as per comment
acd0f6f
added time in add n rem vol and vm yaml upd
cbbdc56
added timeoutsampler in verifyvolume function
970c971
removed time.sleep from add volume
5e4adf1
updated cnv verify func
1c6ece9
Improvised test case as per persist flag req
c7719ac
added time
846e9d5
removed tests/functional/workloads/cnv/test_vm_single_disk_hot_pluggi…
bc81691
added delete funct for pvc leftover
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
tests/functional/workloads/cnv/test_vm_hotplug_unplug.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,141 @@ | ||||
import logging | ||||
import time | ||||
|
||||
import pytest | ||||
|
||||
from ocs_ci.framework.pytest_customization.marks import magenta_squad, workloads | ||||
from ocs_ci.framework.testlib import E2ETest | ||||
from ocs_ci.helpers.cnv_helpers import cal_md5sum_vm, run_dd_io, verifyvolume | ||||
from ocs_ci.helpers.helpers import create_pvc | ||||
from ocs_ci.ocs import constants | ||||
from ocs_ci.ocs.resources.pvc import delete_pvcs | ||||
|
||||
log = logging.getLogger(__name__) | ||||
|
||||
|
||||
@magenta_squad | ||||
@workloads | ||||
@pytest.mark.polarion_id("OCS-6322") | ||||
class TestVmHotPlugUnplug(E2ETest): | ||||
""" | ||||
Test case for VM hot plugging and unplugging of PVC disks. | ||||
This test ensures that PVC disks can be hotplugged into a running VM | ||||
and that data written to the disk is persisted after reboot. | ||||
""" | ||||
|
||||
def test_vm_hot_plugging_unplugging( | ||||
self, | ||||
# setup_cnv, | ||||
project_factory, | ||||
multi_cnv_workload, | ||||
): | ||||
""" | ||||
Test the hot plugging and unplugging of a PVC into/from a VM. | ||||
|
||||
The test involves: | ||||
1. Hotplugging a disk into a running VM based on PVC. | ||||
2. Verifying the disk is attached to the VM. | ||||
3. Writing data to the disk and rebooting the VM to test persistence. | ||||
4. Hotplugging another disk without the --persist flag and verifying it is detached correctly. | ||||
""" | ||||
|
||||
proj_obj = project_factory() | ||||
file_paths = ["/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 | ||||
log.info(f"Total VMs to process: {len(vm_list)}") | ||||
|
||||
for index, vm_obj in enumerate(vm_list): | ||||
before_disks = vm_obj.run_ssh_cmd( | ||||
command="lsblk -o NAME,SIZE,MOUNTPOINT -P" | ||||
) | ||||
log.info(f"Disks before hotplug:\n{before_disks}") | ||||
|
||||
# Step 2: Create a PVC and hotplug it to the VM with persist flag | ||||
pvc_obj = create_pvc( | ||||
sc_name=vm_obj.sc_name, | ||||
namespace=vm_obj.namespace, | ||||
size="20Gi", | ||||
access_mode=constants.ACCESS_MODE_RWX, | ||||
volume_mode=constants.VOLUME_MODE_BLOCK, | ||||
) | ||||
log.info(f"PVC {pvc_obj.name} created successfully") | ||||
|
||||
# Attach the PVC to the VM (with persist flag enabled) | ||||
vm_obj.addvolume(volume_name=pvc_obj.name, verify=True) | ||||
log.info(f"Hotplugged PVC {pvc_obj.name} to VM {vm_obj.name}") | ||||
time.sleep(30) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of sleep please use Line 695 in 9bf5e75
|
||||
# Step 3: Verify the disk is attached | ||||
after_disks = vm_obj.run_ssh_cmd("lsblk -o NAME,SIZE,MOUNTPOINT -P") | ||||
log.info(f"Disks after hotplug:\n{after_disks}") | ||||
assert ( | ||||
set(after_disks) - set(before_disks) | ||||
) != set(), f"Failed to plug disk {pvc_obj.name} to VM {vm_obj.name}" | ||||
|
||||
# Step 4: Perform I/O on the attached disk to ensure it's working | ||||
log.info(f"Running I/O operation on VM {vm_obj.name}") | ||||
source_csum = run_dd_io(vm_obj=vm_obj, file_path=file_paths[0], verify=True) | ||||
|
||||
# Step 5: Reboot the VM and verify the data is persistent | ||||
log.info(f"Rebooting VM {vm_obj.name}") | ||||
vm_obj.restart(wait=True, verify=True) | ||||
log.info(f"Reboot Success for VM: {vm_obj.name}") | ||||
|
||||
# Verify that the disk is still attached after reboot | ||||
assert verifyvolume( | ||||
vm_obj.name, volume_name=pvc_obj.name, namespace=vm_obj.namespace | ||||
), f"Unable to find volume {pvc_obj.name} mounted on VM: {vm_obj.name}" | ||||
|
||||
# Verify that the data on the disk persisted | ||||
# after reboot (using MD5 checksum) | ||||
new_csum = cal_md5sum_vm(vm_obj=vm_obj, file_path=file_paths[0]) | ||||
assert ( | ||||
source_csum == new_csum | ||||
), f"MD5 mismatch after reboot for VM {vm_obj.name}" | ||||
|
||||
# Step 6: Hotplug another disk to the VM without persist flag | ||||
pvc_obj_wout = create_pvc( | ||||
sc_name=vm_obj.sc_name, | ||||
namespace=vm_obj.namespace, | ||||
size="20Gi", | ||||
access_mode=constants.ACCESS_MODE_RWX, | ||||
volume_mode=constants.VOLUME_MODE_BLOCK, | ||||
) | ||||
log.info(f"PVC {pvc_obj_wout.name} created successfully") | ||||
|
||||
# Attach the new PVC to the VM (without persist flag) | ||||
vm_obj.addvolume(volume_name=pvc_obj_wout.name, persist=False) | ||||
log.info( | ||||
f"Hotplugged PVC {pvc_obj_wout.name} to VM {vm_obj.name} without persist" | ||||
) | ||||
time.sleep(30) | ||||
# Step 7: Verify the new disk was successfully hotplugged | ||||
after_disks_wout_add = vm_obj.run_ssh_cmd( | ||||
"lsblk -o NAME,SIZE,MOUNTPOINT -P" | ||||
) | ||||
log.info( | ||||
f"Disks after hotplug of {pvc_obj_wout.name}:\n{after_disks_wout_add}" | ||||
) | ||||
|
||||
# Step 8: Perform I/O on the new disk | ||||
log.info(f"Running I/O operation on VM {vm_obj.name}") | ||||
run_dd_io(vm_obj=vm_obj, file_path=file_paths[1]) | ||||
|
||||
# Step 9: Unplug the newly hotplugged disk | ||||
vm_obj.removevolume(volume_name=pvc_obj_wout.name, verify=True) | ||||
|
||||
# Step 10: Verify the disk was successfully detached | ||||
after_hotplug_rm_disk_wout = vm_obj.run_ssh_cmd( | ||||
"lsblk -o NAME,SIZE,MOUNTPOINT -P" | ||||
) | ||||
log.info( | ||||
f"Disks after unplugging {pvc_obj_wout.name}:\n{after_hotplug_rm_disk_wout}" | ||||
) | ||||
|
||||
# Ensure the hotplugged disk was removed successfully (check for no change) | ||||
assert set(after_disks) == set( | ||||
after_hotplug_rm_disk_wout | ||||
), f"Failed to unplug disk {pvc_obj_wout.name} from VM {vm_obj.name}" | ||||
delete_pvcs(pvc_objs=[pvc_obj_wout, pvc_obj]) |
37 changes: 0 additions & 37 deletions
37
tests/functional/workloads/cnv/test_vm_single_disk_hot_plugging_unplugging.py
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider making this as common function(s) so it can be used by other tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per today's discussion, we'll be updating addvolume as enhancement
https://github.com/red-hat-storage/ocs-ci/pull/11149/files#r1923196525