1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(vmbackups): full audit: backup volumes attached, ended creates, refusals

- A backup's volume is no longer attached to a VM as an existing volume:
  the VM would write into the backup, and the backup's deletion (by hand
  or retention) would remove the VM's disk.
- A backup whose create job ended without it (uncertain, then resolved)
  stayed "creating" for good and could not be deleted. Only a backup whose
  job still runs is being made; the others show as failed and are deleted.
- A VM with an NVDIMM or virtio-pmem device is refused: the host file
  behind it is not copied, and its restore would use the original's file.
- A block device's or network NVRAM is refused by its path, instead of a
  ready backup without the firmware state.
- A VM owner's restore pages link back to the VM's Backups tab, not to the
  superusers' backup list.
This commit is contained in:
catborise 2026-11-18 14:30:51 +03:00
parent e1611efd53
commit 8e0a84a3bd
17 changed files with 375 additions and 305 deletions

View file

@ -69,6 +69,9 @@ class wvmBackup(wvmInstance):
raise OperationError(gettext_noop("%(vm)s has TPM state; shut it down to back it up"), vm=name)
if tree.find("devices/filesystem") is not None:
raise OperationError(gettext_noop("%(vm)s shares a host directory (filesystem); it cannot be backed up"), vm=name)
if tree.xpath("devices/memory[@model='nvdimm' or @model='virtio-pmem']"):
raise OperationError(gettext_noop("%(vm)s has a persistent memory device (a host file); it cannot be backed up"),
vm=name)
if tree.xpath("os/kernel|os/initrd|os/dtb"):
raise OperationError(gettext_noop("%(vm)s boots a kernel file of the host; it cannot be backed up"), vm=name)
if tree.xpath("devices/hostdev|devices/interface[@type='hostdev']"):
@ -115,7 +118,9 @@ class wvmBackup(wvmInstance):
raise OperationError(gettext_noop("Disks %(devs)s change at the next start; back the VM up after it restarts"),
devs=", ".join(changed))
nvram = tree.xpath("string(os/nvram/source/@file)") or (tree.findtext("os/nvram") or "").strip() or None
# a block device's or network NVRAM is named too: it is refused below
nvram = (tree.xpath("string(os/nvram/source/@file|os/nvram/source/@dev|os/nvram/source/@name)")
or (tree.findtext("os/nvram") or "").strip() or None)
if nvram and os.path.dirname(nvram) != NVRAM_DIR:
raise OperationError(gettext_noop("The NVRAM file %(path)s is not in libvirt's NVRAM directory %(dir)s and cannot be copied"),
path=nvram, dir=NVRAM_DIR)

View file

@ -104,6 +104,15 @@ class BackupPlanTestCase(unittest.TestCase):
def test_an_nvram_outside_libvirts_directory_is_refused(self):
self.refused(proxy(domain(os_extra="<nvram>/srv/vm1_VARS.fd</nvram>")), "/srv/vm1_VARS.fd")
def test_an_nvram_that_is_no_file_is_refused(self):
self.refused(proxy(domain(os_extra="<nvram type='block'><source dev='/dev/sdc'/></nvram>")), "/dev/sdc")
self.refused(proxy(domain(os_extra="<nvram type='network'><source protocol='iscsi' name='iqn.2013-07.com.example:iscsi-nopool/0'/></nvram>")),
"iqn.2013-07.com.example:iscsi-nopool/0")
def test_a_memory_dimm_is_backed_up(self):
self.assertEqual(len(proxy(domain(QCOW + "<memory model='dimm'><target><size unit='KiB'>524288</size></target></memory>"))
.backup_plan()["disks"]), 1)
def test_refusals_name_the_reason_and_the_device(self):
cases = {
"encrypted": (
@ -124,6 +133,10 @@ class BackupPlanTestCase(unittest.TestCase):
("vda", "vmdk"),
),
"filesystem": (QCOW + "<filesystem type='mount'><source dir='/srv'/><target dir='t'/></filesystem>", ("host directory",)),
"nvdimm": (QCOW + "<memory model='nvdimm'><source><path>/srv/nvdimm</path></source></memory>",
("persistent memory",)),
"virtio-pmem": (QCOW + "<memory model='virtio-pmem' access='shared'><source><path>/srv/pmem</path>"
"</source></memory>", ("persistent memory",)),
"host device": (QCOW + "<hostdev mode='subsystem' type='pci'/>", ("host device",)),
"host device NIC": (QCOW + "<interface type='hostdev'><mac address='52:54:00:00:00:09'/></interface>",
("host device",)),