mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-01 00:16:04 +00:00
fix(vrtManager): a VM's new disk in an NFS or filesystem pool keeps its format
A new VM's disk and a disk added to a VM were built by a copy of the volume XML of the Storage page that kept the format in dir pools only: in an fs or netfs pool a qcow2 disk became a raw one allocated whole, and a qcow disk got qcow2's compat and lazy_refcounts, which libvirt refuses. Both now use the Storage page's builder, where every pool of files keeps the format and the other pools make a raw volume without metadata preallocation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
8f09812b7d
commit
f952d4e0d0
4 changed files with 58 additions and 43 deletions
41
vrtManager/tests/test_volume_xml.py
Normal file
41
vrtManager/tests/test_volume_xml.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
"""A new volume: a pool of files (dir, fs, netfs) keeps the asked format,
|
||||
the others make it raw; only qcow2 takes qcow2's options."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test import SimpleTestCase
|
||||
from lxml import etree
|
||||
from vrtManager.create import wvmCreate
|
||||
|
||||
|
||||
class NewVolumeTests(SimpleTestCase):
|
||||
def created(self, pool_type, fmt, metadata=True):
|
||||
"""The volume XML and flags a new VM disk of format fmt gets in a pool of pool_type."""
|
||||
with patch("vrtManager.connection.connection_manager.get_connection") as get:
|
||||
pool = get.return_value.storagePoolLookupByName.return_value
|
||||
pool.XMLDesc.return_value = f"<pool type='{pool_type}'/>"
|
||||
wvmCreate("host", "login", "pw", 1).create_volume("pool1", "vm", 1, fmt, metadata)
|
||||
xml, flags = pool.createXML.call_args.args
|
||||
return etree.fromstring(xml), flags
|
||||
|
||||
def test_a_file_pool_keeps_the_format(self):
|
||||
for pool_type in ("dir", "fs", "netfs"):
|
||||
with self.subTest(pool_type):
|
||||
volume, flags = self.created(pool_type, "qcow2")
|
||||
self.assertEqual((volume.findtext("name"), volume.find("target/format").get("type")), ("vm.qcow2", "qcow2"))
|
||||
self.assertEqual((volume.findtext("allocation"), flags), ("0", True))
|
||||
self.assertIsNotNone(volume.find("target/features/lazy_refcounts"))
|
||||
|
||||
def test_other_pools_make_a_whole_raw_volume(self):
|
||||
for pool_type in ("logical", "rbd", "disk"):
|
||||
with self.subTest(pool_type):
|
||||
volume, flags = self.created(pool_type, "qcow2")
|
||||
self.assertEqual((volume.findtext("name"), volume.find("target/format").get("type")), ("vm", "raw"))
|
||||
self.assertEqual((volume.findtext("allocation"), flags), (str(1 << 30), False))
|
||||
self.assertIsNone(volume.find("target/compat"))
|
||||
|
||||
def test_only_qcow2_takes_its_options(self):
|
||||
volume, _flags = self.created("dir", "qcow")
|
||||
self.assertEqual(volume.findtext("name"), "vm.qcow")
|
||||
self.assertIsNone(volume.find("target/compat"))
|
||||
self.assertIsNone(volume.find("target/features"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue