mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(vrtManager): a new VM's disk path, network and filter names are XML text
create_instance put an existing volume's path and the network and filter names into the domain XML unescaped, so a quote or ampersand, which libvirt allows in them, broke the VM's XML. They are escaped as attach_disk does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
0ac078b9cc
commit
2dfc393f05
2 changed files with 24 additions and 3 deletions
|
|
@ -227,7 +227,7 @@ class wvmCreate(wvmConnect):
|
|||
else:
|
||||
xml += f"""<disk type='file' device='{volume["device"]}'>"""
|
||||
xml += f""" <driver name='qemu' type='{volume["type"]}' {disk_opts}/>"""
|
||||
xml += f""" <source file='{volume["path"]}'/>"""
|
||||
xml += f""" <source file='{util.xml_escape(volume["path"])}'/>"""
|
||||
|
||||
if volume.get("bus") in dom_caps["disk_bus"]:
|
||||
dev_prefix = util.vol_dev_type(volume.get("bus"))
|
||||
|
|
@ -255,9 +255,9 @@ class wvmCreate(wvmConnect):
|
|||
xml += """<interface type='network'>"""
|
||||
if idx < len(macs):
|
||||
xml += f"""<mac address='{macs[idx].strip()}'/>"""
|
||||
xml += f"""<source network='{net}'/>"""
|
||||
xml += f"""<source network='{util.xml_escape(net)}'/>"""
|
||||
if nwfilter:
|
||||
xml += f"""<filterref filter='{nwfilter}'/>"""
|
||||
xml += f"""<filterref filter='{util.xml_escape(nwfilter)}'/>"""
|
||||
if virtio:
|
||||
xml += f"""<model type='{net_model}'/>"""
|
||||
xml += """</interface>"""
|
||||
|
|
|
|||
|
|
@ -181,3 +181,24 @@ class NewVmPortsTests(SimpleTestCase):
|
|||
|
||||
def test_a_pc_vm_has_none_its_pci_bus_has_slots(self):
|
||||
self.assertEqual(defined_controllers("pc-i440fx-rhel7.6.0"), [])
|
||||
|
||||
|
||||
class NewVmTextTests(SimpleTestCase):
|
||||
def test_a_path_a_network_and_a_filter_are_text(self):
|
||||
odd = "a'b\"c<d>&e"
|
||||
conn = wvmCreate.__new__(wvmCreate)
|
||||
conn.wvm = MagicMock()
|
||||
conn.get_storage_by_vol_path = MagicMock()
|
||||
conn.get_storage_by_vol_path.return_value.XMLDesc.return_value = "<pool type='dir'/>"
|
||||
volume = {"path": f"/srv/{odd}/vm.qcow2", "type": "qcow2", "device": "disk", "bus": "virtio", "cache_mode": None,
|
||||
"io_mode": None, "discard_mode": None, "detect_zeroes_mode": None}
|
||||
with patch.object(wvmCreate, "get_capabilities", return_value={"features": []}), \
|
||||
patch.object(wvmCreate, "get_dom_capabilities", return_value=PORTS_DOM_CAPS):
|
||||
conn.create_instance(name="vm-1", memory=512, vcpu=1, vcpu_mode="host-model",
|
||||
uuid="00000000-0000-4000-8000-0000000000c2", arch="x86_64", machine="pc",
|
||||
firmware="BIOS", volumes=[volume], networks=odd, nwfilter=odd, virtio=True,
|
||||
listener_addr="0.0.0.0", add_cdrom="None", add_input="None")
|
||||
devices = etree.fromstring(conn.wvm.defineXML.call_args.args[0]).find("devices")
|
||||
self.assertEqual(devices.find("disk/source").get("file"), f"/srv/{odd}/vm.qcow2")
|
||||
self.assertEqual(devices.find("interface/source").get("network"), odd)
|
||||
self.assertEqual(devices.find("interface/filterref").get("filter"), odd)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue