disk: lookup volumes in disk.set_backend_for_existing_path

Seems like it should be doing this.
Make use of that helper in cloner afterwards

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-09-04 13:07:02 -04:00
parent 8f60e4af47
commit 9c1453a253
3 changed files with 22 additions and 2 deletions

View File

@ -1587,6 +1587,23 @@ class XMLParseTest(unittest.TestCase):
with self.assertRaises(ValueError):
disk.validate()
# Ensure set_backend_for_existing_path resolves a path
# to its existing storage volume
xml = ("<disk type='file' device='disk'>"
"<source file='/dev/default-pool/default-vol'/>"
"</disk>")
conn = utils.URIs.open_testdriver_cached()
disk = virtinst.DeviceDisk(conn, parsexml=xml)
disk.set_backend_for_existing_path()
assert disk.get_vol_object()
# Verify set_backend_for_existing_path doesn't error
# for a variety of disks
dom = conn.lookupByName("test-many-devices")
guest = virtinst.Guest(conn, parsexml=dom.XMLDesc(0))
for disk in guest.devices.disk:
disk.set_backend_for_existing_path()
def testGuestXMLDeviceMatch(self):
"""
Test Guest.find_device and Device.compare_device

View File

@ -194,8 +194,7 @@ class _CloneDiskInfo:
def check_clonable(self):
try:
# This forces DeviceDisk to resolve the storage backend
self.disk.path = self.disk.path
self.disk.set_backend_for_existing_path()
if self.disk.wants_storage_creation():
raise ValueError(
_("Disk path '%s' does not exist.") % self.disk.path)

View File

@ -675,6 +675,10 @@ class DeviceDisk(Device):
if vol_object is None and path is None:
path = self._get_xmlpath()
if path and not vol_object and not parent_pool:
(vol_object, parent_pool) = diskbackend.manage_path(
self.conn, path)
self._change_backend(path, vol_object, parent_pool)
def set_local_disk_to_clone(self, disk, sparse):