Skip to content

Commit

Permalink
Merge pull request #2114 from fangge1212/update-disk-driver-cache
Browse files Browse the repository at this point in the history
Add new function update_vm_disk_driver_cache()
  • Loading branch information
chunfuwen authored Aug 28, 2019
2 parents ced0a91 + 84b23a3 commit 635afb4
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions virttest/utils_test/libvirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3276,6 +3276,39 @@ def do_migration(vm_name, uri, extra, auth_pwd, auth_user="root",
return (False, log)


def update_vm_disk_driver_cache(vm_name, driver_cache="none", disk_index=0):
"""
Update disk driver cache of the VM
:param vm_name: vm name
:param driver_cache: new vm disk driver cache mode, default to none if not provided
:param disk_index: vm disk index to be updated, the index of first disk is 0.
"""
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)

try:
# Get the disk to be updated
devices = vmxml.devices
device_index = devices.index(devices.by_device_tag('disk')[disk_index])
disk = devices[device_index]

# Update disk driver cache mode
driver_dict = disk.driver
driver_dict['cache'] = driver_cache
disk.driver = driver_dict
logging.debug("The new vm disk driver cache is %s", disk.driver['cache'])

vmxml.devices = devices

# SYNC VM XML change
logging.debug("The new VM XML:\n%s", vmxml)
vmxml.sync()
return True
except Exception as e:
logging.error("Can't update disk driver cache!! %s", e)
return False


def update_vm_disk_source(vm_name, disk_source_path,
disk_image_name="",
source_type="file"):
Expand Down

0 comments on commit 635afb4

Please sign in to comment.