1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-10 20:26:48 +00:00

feat(instances): a VM's clone form in device cards, with fixes to what it clones

Settings > Clone was a horizontal form with unlabelled checkboxes. The
owner chose this layout from three rendered options: the clone's name
on top, a "Network" card with a new MAC address per NIC, a "Storage"
card with a new volume name per disk, then the optional title and
description and a footer with Clone.

Codex reviewed cloning end to end; these are fixed:

- Every NIC of the clone gets a new random MAC when the form opens.
  Only the first did, so a VM with two NICs gave its clone the second
  NIC's MAC. Guess MAC is offered for the first NIC only: a name's DHCP
  host entry holds one address.
- A VM without a NIC can be cloned: the first NIC's MAC was required.
- The disk name script uses the persistent disks, as the form does; a
  disk added pending the next start kept the source's volume name.
- A running or paused VM is not cloned while a copied disk changes at
  the next start: the backup copies the running disk, so the clone
  would get the old contents under the new definition.
- A derived volume name that does not start with the source's name now
  starts with the clone's name and the disk's device, so a second clone
  or a second disk does not take the same name.
- Guess for the clone name says when the DHCP file has no free name; it
  stopped with a script error.
- The qcow2 metadata preallocation box shows only for a shut-off VM: a
  live clone's backup ignores it.

Other users no longer get hidden MAC and disk inputs or the scripts that
filled them: the server derives those values and ignored the posted ones.
This commit is contained in:
catborise 2026-10-30 13:32:28 +03:00
parent 301b73155d
commit 400ba1614f
8 changed files with 164 additions and 96 deletions

View file

@ -9,7 +9,12 @@ from lxml import etree
from vrtManager import instance as instance_module
from vrtManager import util
from vrtManager.instance import LIVE_CLONE_MIN_LIBVIRT, VIR_DOMAIN_BACKUP_BEGIN_PRESERVE_SHUTDOWN_DOMAIN, wvmInstance
from vrtManager.instance import (
LIVE_CLONE_MIN_LIBVIRT,
PERSISTENT_XML,
VIR_DOMAIN_BACKUP_BEGIN_PRESERVE_SHUTDOWN_DOMAIN,
wvmInstance,
)
GIB = 1024**3
UUID = "abababab-0000-1111-2222-333333333333"
@ -98,6 +103,16 @@ class LiveCloneTargetsTestCase(unittest.TestCase):
def test_a_tpm_is_refused(self):
self.refused(proxy(domain(extra="<tpm model='tpm-crb'/>")), "TPM")
def test_a_disk_the_next_start_changes_is_refused(self):
# the backup copies the running disk: a pending new source, or a disk only the next start has
disk = "<disk type='file' device='disk'><source file='/pool/{}.qcow2'/><target dev='{}'/></disk>"
for persistent in (domain(disk.format("new", "vda")), domain(disk.format("src", "vda") + disk.format("add", "vdb"))):
with self.subTest(persistent):
p = proxy()
p._XMLDesc = lambda flags, xml=persistent: xml if flags == PERSISTENT_XML else domain()
with self.assertRaisesRegex(util.OperationError, "changes at the next start"):
p.live_clone_targets({**FORM, "disk-vdb": "copy-vdb.qcow2"}, 10, 5)
def test_a_running_libvirt_job_is_refused(self):
p = proxy()
p.instance.jobInfo.return_value = [libvirt.VIR_DOMAIN_JOB_UNBOUNDED] + [0] * 11