mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(instances): an ISO already in a CD-ROM of the VM is not added again
A CD-ROM form sent twice (a double click, a resent request) added a second drive with the same ISO. The form is refused when the ISO is in a CD-ROM of the VM's running or persistent definition; an empty drive may still be added more than once. tr and zh too.
This commit is contained in:
parent
d15842a250
commit
be68009432
6 changed files with 645 additions and 617 deletions
|
|
@ -60,3 +60,16 @@ class DuplicateDeviceTests(TestCase):
|
|||
self.assertEqual(self.post("add_network", form),
|
||||
[f"The VM already has a network device with MAC {MAC.upper()}"])
|
||||
self.proxy.add_network.assert_called_once()
|
||||
|
||||
def test_an_iso_in_a_cdrom_of_the_vm_is_not_added_again(self):
|
||||
iso = "/var/lib/libvirt/isos/alma.iso"
|
||||
self.proxy.get_iso_path.return_value = iso
|
||||
with patch("instances.views.cdrom_bus_choices", return_value=["sata"]):
|
||||
form = {"bus": "sata", "media": "alma.iso"}
|
||||
self.post("add_cdrom", form)
|
||||
self.proxy.attach_disk.assert_called_once()
|
||||
self.proxy.get_media_devices.side_effect = lambda config=False: [{"path": iso, "dev": "sdb"}] if config else []
|
||||
self.assertEqual(self.post("add_cdrom", form), ["alma.iso is already in a CD-ROM of this VM"])
|
||||
# an empty drive may be added more than once
|
||||
self.post("add_cdrom", {"bus": "sata", "media": ""})
|
||||
self.assertEqual(self.proxy.attach_disk.call_count, 2)
|
||||
|
|
|
|||
|
|
@ -1626,6 +1626,11 @@ def add_cdrom(request, pk):
|
|||
if bus == "usb" and not image:
|
||||
messages.error(request, _("A USB CD-ROM needs an ISO image: libvirt has no empty USB drive"))
|
||||
return _back(request, pk, "disks")
|
||||
path = instance.proxy.get_iso_path(image) if image else ""
|
||||
# a form sent twice (a double click) adds the drive once
|
||||
if path and path in {media["path"] for media in instance.media + instance.config_media}:
|
||||
messages.error(request, _("%(image)s is already in a CD-ROM of this VM") % {"image": image})
|
||||
return _back(request, pk, "disks")
|
||||
|
||||
target = utils.get_new_disk_dev(
|
||||
instance.media + instance.config_media, instance.disks + instance.config_disks, bus
|
||||
|
|
@ -1634,7 +1639,7 @@ def add_cdrom(request, pk):
|
|||
with audit_vm(request, instance, f"add CD-ROM {target}" + (f" with {image}" if image else "")):
|
||||
instance.proxy.attach_disk(
|
||||
target,
|
||||
instance.proxy.get_iso_path(image) if image else "",
|
||||
path,
|
||||
disk_device="cdrom",
|
||||
cache_mode="none",
|
||||
target_bus=bus,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue