mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 01:16:10 +00:00
fix(instances): a VM with backup checkpoints is deleted and moved offline
libvirt refuses to undefine a domain that has checkpoints unless asked to drop their metadata. The VM delete job and the shut-off migration's removal of the source definition now pass CHECKPOINTS_METADATA; a backup chain ends with them, and the next backup is full.
This commit is contained in:
parent
272260eec5
commit
5f7555f348
4 changed files with 14 additions and 6 deletions
|
|
@ -14,7 +14,7 @@ from django.template.loader import render_to_string
|
|||
from django.utils.translation import gettext_noop
|
||||
from django.utils.translation import gettext_noop as _
|
||||
from libvirt import (VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE, VIR_DOMAIN_JOB_NONE, VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL,
|
||||
VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_UNDEFINE_KEEP_NVRAM, VIR_DOMAIN_UNDEFINE_MANAGED_SAVE,
|
||||
VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA, VIR_DOMAIN_UNDEFINE_KEEP_NVRAM, VIR_DOMAIN_UNDEFINE_MANAGED_SAVE,
|
||||
VIR_DOMAIN_UNDEFINE_NVRAM, VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, VIR_DOMAIN_XML_INACTIVE,
|
||||
VIR_ERR_NO_DOMAIN, VIR_ERR_NO_STORAGE_VOL, libvirtError)
|
||||
from lxml import etree
|
||||
|
|
@ -1495,7 +1495,8 @@ class DeleteInstance(Kind):
|
|||
if proxy.instance.isActive():
|
||||
proxy.force_shutdown()
|
||||
# snapshot metadata goes with the domain; internal snapshot data stays in kept disk images
|
||||
flags = VIR_DOMAIN_UNDEFINE_MANAGED_SAVE | VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA
|
||||
flags = (VIR_DOMAIN_UNDEFINE_MANAGED_SAVE | VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA
|
||||
| VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA) # backup checkpoints go with the VM
|
||||
flags |= VIR_DOMAIN_UNDEFINE_NVRAM if op.params["delete_nvram"] else VIR_DOMAIN_UNDEFINE_KEEP_NVRAM
|
||||
proxy.delete(flags)
|
||||
return _removed(op)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from instances.jobs import DeleteInstance
|
|||
from instances.models import Instance
|
||||
from instances import utils
|
||||
from instances.utils import paths_used_on_other_computes
|
||||
from libvirt import VIR_DOMAIN_UNDEFINE_KEEP_NVRAM, VIR_DOMAIN_UNDEFINE_NVRAM, VIR_ERR_NO_STORAGE_VOL, libvirtError
|
||||
from libvirt import VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA, VIR_DOMAIN_UNDEFINE_KEEP_NVRAM, VIR_DOMAIN_UNDEFINE_NVRAM, VIR_ERR_NO_STORAGE_VOL, libvirtError
|
||||
from logs.models import Logs
|
||||
from operations.jobs import Context
|
||||
from operations.models import Claim, Operation, acquire
|
||||
|
|
@ -66,6 +66,11 @@ class DestroyOrderTestCase(TransactionTestCase):
|
|||
(f"compute:{self.instance.compute_id}", "exclusive"), (f"instance:{UUID}", "exclusive")})
|
||||
self.assertEqual(self.proxy.mock_calls, [])
|
||||
|
||||
def test_backup_checkpoints_go_with_the_vm(self):
|
||||
# libvirt refuses to undefine a VM that has checkpoints without this flag
|
||||
self.run_job(self.queue())
|
||||
self.assertTrue(self.proxy.delete.call_args[0][0] & VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA)
|
||||
|
||||
def test_the_nvram_goes_only_when_asked(self):
|
||||
for data, wanted, unwanted in (
|
||||
({"delete_nvram": "1"}, VIR_DOMAIN_UNDEFINE_NVRAM, VIR_DOMAIN_UNDEFINE_KEEP_NVRAM),
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ from libvirt import (
|
|||
VIR_DOMAIN_XML_SECURE,
|
||||
VIR_DOMAIN_XML_INACTIVE,
|
||||
VIR_DOMAIN_XML_MIGRATABLE,
|
||||
VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA,
|
||||
VIR_DOMAIN_UNDEFINE_KEEP_NVRAM,
|
||||
VIR_ERR_NO_DOMAIN,
|
||||
VIR_ERR_NO_STORAGE_POOL,
|
||||
|
|
@ -632,8 +633,9 @@ class wvmInstances(wvmConnect):
|
|||
self.delete_nvram(nvram)
|
||||
raise
|
||||
try:
|
||||
# libvirt refuses to undefine a VM with NVRAM without this; the file stays for the cleanup
|
||||
dom.undefineFlags(VIR_DOMAIN_UNDEFINE_KEEP_NVRAM)
|
||||
# libvirt refuses to undefine a VM with NVRAM or backup checkpoints without these; the file stays for
|
||||
# the cleanup, the checkpoints are this host's (the next backup is full)
|
||||
dom.undefineFlags(VIR_DOMAIN_UNDEFINE_KEEP_NVRAM | VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA)
|
||||
try:
|
||||
started = dom.isActive()
|
||||
except libvirtError as error:
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class ShutOffMigrationTestCase(unittest.TestCase):
|
|||
destination(host).moveto(source, "vm", live=False, unsafe=False, offline=True)
|
||||
self.assertEqual(host.defined, ["<domain><name>vm</name></domain>"])
|
||||
self.assertEqual(source.instance.calls, [])
|
||||
self.assertEqual(source.instance.undefined, libvirt.VIR_DOMAIN_UNDEFINE_KEEP_NVRAM)
|
||||
self.assertEqual(source.instance.undefined, libvirt.VIR_DOMAIN_UNDEFINE_KEEP_NVRAM | libvirt.VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA)
|
||||
|
||||
def test_a_tpm_without_local_state_moves(self):
|
||||
xml = "<domain><devices><tpm model='tpm-tis'><backend type='passthrough'/></tpm></devices></domain>"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue