mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 04:36:48 +00:00
fix(instances): allow editing disks that have no driver format
A disk without driver/@type could not be edited: the empty format was rejected, and edit_disk would have written type=''. An empty format is now accepted and edit_disk leaves the type attribute out.
This commit is contained in:
parent
0f611e6383
commit
479faaa4ca
4 changed files with 36 additions and 5 deletions
|
|
@ -913,12 +913,12 @@ class wvmInstance(wvmConnect):
|
|||
additionals += f"detect_zeroes='{detect_zeroes_mode}' "
|
||||
|
||||
xml_disk = f"<disk type='{old_disk_type}' device='{old_disk_device}'>"
|
||||
# A disk without a driver type keeps having none.
|
||||
type_attr = f"type='{format}' " if format else ""
|
||||
if old_disk_device == "cdrom":
|
||||
xml_disk += f"<driver name='{old_driver_name}' type='{format}'/>"
|
||||
xml_disk += f"<driver name='{old_driver_name}' {type_attr}/>"
|
||||
elif old_disk_device == "disk":
|
||||
xml_disk += (
|
||||
f"<driver name='{old_driver_name}' type='{format}' {additionals}/>"
|
||||
)
|
||||
xml_disk += f"<driver name='{old_driver_name}' {type_attr}{additionals}/>"
|
||||
|
||||
if disk_el.get("type") == "file":
|
||||
xml_disk += f"<source file='{source}'/>"
|
||||
|
|
|
|||
|
|
@ -304,3 +304,22 @@ class TestChangeDiskBus(unittest.TestCase):
|
|||
self.assertEqual(disk.find("source").get("name"), "pool/vm-disk")
|
||||
self.assertEqual(disk.find("source/host").get("name"), "mon1")
|
||||
self.assertEqual(disk.find("auth/secret").get("uuid"), "aaaa")
|
||||
|
||||
def test_edit_disk_without_format_omits_the_driver_type(self):
|
||||
from lxml import etree
|
||||
|
||||
inst = wvmInstance.__new__(wvmInstance)
|
||||
inst.instance = MagicMock()
|
||||
inst._XMLDesc = MagicMock(
|
||||
return_value=(
|
||||
"<domain><devices><disk type='file' device='disk'>"
|
||||
"<driver name='qemu'/><source file='/images/vm.img'/>"
|
||||
"<target dev='vda' bus='virtio'/></disk></devices></domain>"
|
||||
)
|
||||
)
|
||||
inst.edit_disk(
|
||||
"vda", "/images/vm.img", False, False, "virtio", "", "",
|
||||
"default", "default", "default", "default",
|
||||
)
|
||||
disk = etree.fromstring(inst.instance.updateDeviceFlags.call_args[0][0])
|
||||
self.assertIsNone(disk.find("driver").get("type"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue