mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
test(destroy): NVRAM deletion and the base of an overlay
Destroy deletes the NVRAM file only when asked (VIR_DOMAIN_UNDEFINE_NVRAM, otherwise KEEP_NVRAM): a unit test checks the flags, live tests check the file on the host both ways. A VM whose disk is an overlay with a snapshot goes with its own image and the snapshot metadata, and the base image stays, since other images may grow from it.
This commit is contained in:
parent
975b7f0baf
commit
f094982737
2 changed files with 83 additions and 3 deletions
|
|
@ -6,7 +6,7 @@ from django.contrib.auth import get_user_model
|
|||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from instances.models import Instance
|
||||
from libvirt import libvirtError
|
||||
from libvirt import VIR_DOMAIN_UNDEFINE_KEEP_NVRAM, VIR_DOMAIN_UNDEFINE_NVRAM, libvirtError
|
||||
|
||||
|
||||
class DestroyOrderTestCase(TestCase):
|
||||
|
|
@ -19,15 +19,29 @@ class DestroyOrderTestCase(TestCase):
|
|||
compute=compute, name="destroy-vm", uuid="11111111-2222-3333-4444-555555555555"
|
||||
)
|
||||
|
||||
def destroy(self, undefine_error=None):
|
||||
def destroy(self, undefine_error=None, data=None):
|
||||
with patch("instances.models.wvmInstance") as wvm:
|
||||
proxy = wvm.return_value
|
||||
proxy.instance.isActive.return_value = False
|
||||
proxy.split_disk_paths_by_use.return_value = (["/pool/own.qcow2"], ["/pool/shared.qcow2"])
|
||||
proxy.delete.side_effect = undefine_error
|
||||
self.client.post(reverse("instances:destroy", args=[self.instance.id]), {"delete_disk": "1"})
|
||||
self.client.post(reverse("instances:destroy", args=[self.instance.id]), data or {"delete_disk": "1"})
|
||||
return proxy
|
||||
|
||||
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),
|
||||
({}, VIR_DOMAIN_UNDEFINE_KEEP_NVRAM, VIR_DOMAIN_UNDEFINE_NVRAM),
|
||||
):
|
||||
with self.subTest(data=data):
|
||||
Instance.objects.get_or_create(
|
||||
compute=self.instance.compute, name="destroy-vm", uuid="11111111-2222-3333-4444-555555555555"
|
||||
)
|
||||
self.instance = Instance.objects.get(uuid="11111111-2222-3333-4444-555555555555")
|
||||
flags = self.destroy(data=data).delete.call_args[0][0]
|
||||
self.assertTrue(flags & wanted)
|
||||
self.assertFalse(flags & unwanted)
|
||||
|
||||
def test_disks_are_deleted_after_the_undefine(self):
|
||||
proxy = self.destroy()
|
||||
proxy.get_volume_by_path.assert_called_once_with("/pool/own.qcow2")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue