mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
fix(interfaces): an interface a VM or a network uses is not deleted
A stopped bridge was deleted while a shut-off VM's network card or a libvirt network named it; that VM or network then did not start. Deleting an interface is now refused while any definition of a VM, running or not, or a network names it, with their names. A new bridge was offered a device a VM's macvtap card or a network forwarding to it used; bridging it cut that VM off. Such devices are no longer offered. A NAT or routed network's outgoing device counts as used too.
This commit is contained in:
parent
edc165cfc4
commit
de249ebad7
7 changed files with 97 additions and 27 deletions
Binary file not shown.
|
|
@ -11,7 +11,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-11-12 12:50+0000\n"
|
||||
"POT-Creation-Date: 2026-11-12 12:53+0000\n"
|
||||
"PO-Revision-Date: 2020-11-04 12:00+0000\n"
|
||||
"Last-Translator: catborise <muhammetalisag@gmail.com>, 2020\n"
|
||||
"Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n"
|
||||
|
|
@ -9789,7 +9789,7 @@ msgstr ""
|
|||
"%(err)s; değişikliğin geri alınması da başarısız oldu, sunucunun "
|
||||
"yapılandırması değişmiş olabilir: %(rollback_err)s"
|
||||
|
||||
#: vrtManager/interface.py:260
|
||||
#: vrtManager/interface.py:263
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Interface %(iface)s is in use by the running VMs %(vms)s; shut them down or "
|
||||
|
|
@ -9798,12 +9798,28 @@ msgstr ""
|
|||
"%(iface)s arayüzünü çalışan %(vms)s VM'leri kullanıyor; önce onları kapatın "
|
||||
"veya ağ kartlarını başka yere taşıyın"
|
||||
|
||||
#: vrtManager/interface.py:275
|
||||
#: vrtManager/interface.py:281 vrtManager/virtsecrets.py:118
|
||||
#, python-format
|
||||
msgid "VMs %(names)s"
|
||||
msgstr "%(names)s sanal makineleri"
|
||||
|
||||
#: vrtManager/interface.py:283
|
||||
#, python-format
|
||||
msgid "networks %(names)s"
|
||||
msgstr "%(names)s ağları"
|
||||
|
||||
#: vrtManager/interface.py:285
|
||||
#, python-format
|
||||
msgid "Interface %(iface)s is used by %(named)s; remove it from them first"
|
||||
msgstr ""
|
||||
"%(iface)s arayüzü %(named)s tarafından kullanılıyor; önce onlardan kaldırın"
|
||||
|
||||
#: vrtManager/interface.py:296
|
||||
#, python-format
|
||||
msgid "Stop interface %(iface)s before deleting it"
|
||||
msgstr "%(iface)s arabirimini silmeden önce durdurun"
|
||||
|
||||
#: vrtManager/interface.py:279
|
||||
#: vrtManager/interface.py:301
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Bridge %(iface)s has addresses and several members: give the addresses to one"
|
||||
|
|
@ -10251,11 +10267,6 @@ msgstr ""
|
|||
msgid "Type the secret's value"
|
||||
msgstr "Parolanın değerini yazın"
|
||||
|
||||
#: vrtManager/virtsecrets.py:118
|
||||
#, python-format
|
||||
msgid "VMs %(names)s"
|
||||
msgstr "%(names)s sanal makineleri"
|
||||
|
||||
#: vrtManager/virtsecrets.py:120
|
||||
#, python-format
|
||||
msgid "pools %(names)s"
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-11-12 12:50+0000\n"
|
||||
"POT-Creation-Date: 2026-11-12 12:53+0000\n"
|
||||
"PO-Revision-Date: \n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
|
|
@ -9217,19 +9217,34 @@ msgid ""
|
|||
"changed: %(rollback_err)s"
|
||||
msgstr "%(err)s;回滚更改也失败了,主机的配置可能已被更改:%(rollback_err)s"
|
||||
|
||||
#: vrtManager/interface.py:260
|
||||
#: vrtManager/interface.py:263
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Interface %(iface)s is in use by the running VMs %(vms)s; shut them down or "
|
||||
"move their network cards first"
|
||||
msgstr "接口 %(iface)s 正被运行中的虚拟机 %(vms)s 使用;请先关闭它们或移走其网卡"
|
||||
|
||||
#: vrtManager/interface.py:275
|
||||
#: vrtManager/interface.py:281 vrtManager/virtsecrets.py:118
|
||||
#, python-format
|
||||
msgid "VMs %(names)s"
|
||||
msgstr "虚拟机 %(names)s"
|
||||
|
||||
#: vrtManager/interface.py:283
|
||||
#, python-format
|
||||
msgid "networks %(names)s"
|
||||
msgstr "网络 %(names)s"
|
||||
|
||||
#: vrtManager/interface.py:285
|
||||
#, python-format
|
||||
msgid "Interface %(iface)s is used by %(named)s; remove it from them first"
|
||||
msgstr "接口 %(iface)s 正被 %(named)s 使用;请先从中移除它"
|
||||
|
||||
#: vrtManager/interface.py:296
|
||||
#, python-format
|
||||
msgid "Stop interface %(iface)s before deleting it"
|
||||
msgstr "删除接口 %(iface)s 前请先停止它"
|
||||
|
||||
#: vrtManager/interface.py:279
|
||||
#: vrtManager/interface.py:301
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Bridge %(iface)s has addresses and several members: give the addresses to one"
|
||||
|
|
@ -9648,11 +9663,6 @@ msgstr "Ceph 密钥是 base64 文本,即 `ceph auth get-key` 输出的内容"
|
|||
msgid "Type the secret's value"
|
||||
msgstr "请输入机密的值"
|
||||
|
||||
#: vrtManager/virtsecrets.py:118
|
||||
#, python-format
|
||||
msgid "VMs %(names)s"
|
||||
msgstr "虚拟机 %(names)s"
|
||||
|
||||
#: vrtManager/virtsecrets.py:120
|
||||
#, python-format
|
||||
msgid "pools %(names)s"
|
||||
|
|
|
|||
|
|
@ -80,13 +80,14 @@ def interface_info(iface, tree):
|
|||
|
||||
|
||||
def networks_by_device(conn):
|
||||
"""The host's libvirt networks by the devices they use: their bridge, or
|
||||
every interface or physical function they forward to. One listing, one
|
||||
"""The host's libvirt networks by the devices they use: their bridge, the
|
||||
device NAT or routing goes out by, or every interface or physical
|
||||
function they forward to. One listing, one
|
||||
XML read per network."""
|
||||
by_device = {}
|
||||
for net in conn.listAllNetworks(0):
|
||||
tree = ElementTree.fromstring(net.XMLDesc(0))
|
||||
devices = {attribute(tree, "bridge", "name")}
|
||||
devices = {attribute(tree, "bridge", "name"), attribute(tree, "forward", "dev")}
|
||||
for forward in tree.findall("forward/interface") + tree.findall("forward/pf"):
|
||||
devices.add(forward.get("dev"))
|
||||
devices.discard(None)
|
||||
|
|
@ -109,15 +110,18 @@ class wvmInterfaces(wvmConnect):
|
|||
def get_member_candidates(self, netdevs):
|
||||
"""The devices of netdevs a new bridge can take: not the loopback, a
|
||||
bridge, bond or VLAN of the host nor a device in one as configured, at
|
||||
any depth (a bridge's bond's devices), not the bridge of a libvirt
|
||||
network and not a VM's tap (libvirt names them vnetN and macvtapN)."""
|
||||
any depth (a bridge's bond's devices), not a device a libvirt network
|
||||
or a VM's macvtap card uses and not a VM's tap (libvirt names them
|
||||
vnetN and macvtapN)."""
|
||||
taken = {"lo"}
|
||||
for iface in self.wvm.listAllInterfaces(0):
|
||||
tree = ElementTree.fromstring(iface.XMLDesc(VIR_INTERFACE_XML_INACTIVE))
|
||||
if tree.get("type") in ("bridge", "bond", "vlan"):
|
||||
taken.update(element.get("name") for element in tree.iter("interface"))
|
||||
for net in self.wvm.listAllNetworks(0):
|
||||
taken.add(util.get_xml_path(net.XMLDesc(0), "/network/bridge/@name"))
|
||||
taken.update(networks_by_device(self.wvm))
|
||||
for _name, trees in self.domain_trees():
|
||||
for tree in trees:
|
||||
taken.update(tree.xpath("devices/interface[@type='direct']/source/@dev"))
|
||||
return [dev for dev in netdevs if dev not in taken and not dev.startswith(("vnet", "macvtap"))]
|
||||
|
||||
def define_iface(self, xml, flag=0):
|
||||
|
|
@ -264,6 +268,24 @@ class wvmInterface(wvmConnect):
|
|||
def start_iface(self):
|
||||
self.iface.create()
|
||||
|
||||
def check_unused(self):
|
||||
"""Refused while a VM's network card (in any of its definitions, the
|
||||
VM running or not) or a libvirt network names the interface: that VM
|
||||
or network would no longer start."""
|
||||
name = self.iface.name()
|
||||
networks = networks_by_device(self.wvm).get(name, [])
|
||||
vms = self.domains_using(lambda tree: any(
|
||||
name in (source.get("bridge"), source.get("dev")) or source.get("network") in networks
|
||||
for source in tree.xpath("devices/interface/source")))
|
||||
named = []
|
||||
if vms:
|
||||
named.append(util.message(gettext_noop("VMs %(names)s"), names=", ".join(vms)))
|
||||
if networks:
|
||||
named.append(util.message(gettext_noop("networks %(names)s"), names=", ".join(networks)))
|
||||
if named:
|
||||
raise util.OperationError(gettext_noop("Interface %(iface)s is used by %(named)s; remove it from them first"),
|
||||
iface=name, named=named)
|
||||
|
||||
def delete_iface(self):
|
||||
"""Undefine the interface, stopped first. netcf removes a bridge's
|
||||
members with it, so each member is defined again on its own, as virsh
|
||||
|
|
@ -273,6 +295,7 @@ class wvmInterface(wvmConnect):
|
|||
All of it is one change of the host's configuration."""
|
||||
if self.iface.isActive():
|
||||
raise util.OperationError(gettext_noop("Stop interface %(iface)s before deleting it"), iface=self.iface.name())
|
||||
self.check_unused()
|
||||
tree = ElementTree.fromstring(self.iface.XMLDesc(VIR_INTERFACE_XML_INACTIVE))
|
||||
members = tree.findall("bridge/interface")
|
||||
if len(members) > 1 and tree.findall("protocol"):
|
||||
|
|
|
|||
|
|
@ -64,6 +64,22 @@ class DeleteInterfaceTestCase(SimpleTestCase):
|
|||
conn.delete_iface()
|
||||
conn.iface.undefine.assert_not_called()
|
||||
|
||||
def test_an_interface_a_vm_or_a_network_names_is_refused(self):
|
||||
# the VM is shut off: its saved definition names the bridge, and it would not start
|
||||
vm = MagicMock(**{"name.return_value": "web-1", "isPersistent.return_value": True,
|
||||
"XMLDesc.return_value": "<domain><devices><interface type='bridge'><source bridge='br1'/>"
|
||||
"</interface></devices></domain>"})
|
||||
lab = MagicMock(**{"name.return_value": "lab",
|
||||
"XMLDesc.return_value": "<network><forward mode='bridge'/><bridge name='br1'/></network>"})
|
||||
for domains, networks, why in (([vm], [], "used by VMs web-1;"), ([], [lab], "used by networks lab;"),
|
||||
([vm], [lab], "used by VMs web-1; networks lab;")):
|
||||
conn = interface("<interface type='bridge' name='br1'><bridge/></interface>")
|
||||
conn.wvm.listAllDomains.return_value = domains
|
||||
conn.wvm.listAllNetworks.return_value = networks
|
||||
with self.subTest(why), self.assertRaisesRegex(OperationError, why):
|
||||
conn.delete_iface()
|
||||
conn.iface.undefine.assert_not_called()
|
||||
|
||||
def test_a_member_libvirt_refuses_rolls_the_whole_change_back(self):
|
||||
conn = interface(f"<interface type='bridge' name='br1'><bridge>{BOND}</bridge></interface>")
|
||||
conn.wvm.interfaceDefineXML.side_effect = libvirt.libvirtError("netcf: cannot write")
|
||||
|
|
|
|||
|
|
@ -63,6 +63,16 @@ class ReadTests(SimpleTestCase):
|
|||
for listed in conn.wvm.listAllInterfaces.return_value:
|
||||
listed.XMLDesc.assert_called_with(libvirt.VIR_INTERFACE_XML_INACTIVE)
|
||||
|
||||
def test_a_device_a_vm_or_a_network_uses_is_taken(self):
|
||||
# a VM's macvtap card, running or not, and a network forwarding to it would be cut off
|
||||
conn = self.interfaces(networks=["<network><forward mode='bridge'><interface dev='eno6'/></forward></network>"])
|
||||
conn.wvm.listAllNetworks.return_value[0].name.return_value = "direct"
|
||||
conn.wvm.listAllDomains.return_value = [MagicMock(**{
|
||||
"name.return_value": "web-1", "isPersistent.return_value": False,
|
||||
"XMLDesc.return_value": "<domain><devices><interface type='direct'><source dev='eno5' mode='bridge'/>"
|
||||
"</interface></devices></domain>"})]
|
||||
self.assertEqual(conn.get_member_candidates(["eno5", "eno6", "eno7"]), ["eno7"])
|
||||
|
||||
def test_a_device_in_a_bond_of_a_bridge_is_taken(self):
|
||||
nested = ("<interface type='bridge' name='br1'><mac address='52:54:00:aa:01:05'/><bridge><interface type='bond' name='bond0'><bond>"
|
||||
"<interface type='ethernet' name='eno3'/><interface type='ethernet' name='eno4'/></bond></interface>"
|
||||
|
|
@ -97,12 +107,12 @@ class BridgeUseTests(SimpleTestCase):
|
|||
from vrtManager.interface import networks_by_device
|
||||
|
||||
nets = [MagicMock(**{"name.return_value": name, "XMLDesc.return_value": xml}) for name, xml in (
|
||||
("default", "<network><bridge name='virbr0'/></network>"),
|
||||
("default", "<network><forward mode='nat' dev='eth3'/><bridge name='virbr0'/></network>"),
|
||||
("lan", "<network><forward mode='bridge'/><bridge name='br0'/></network>"),
|
||||
("direct", "<network><forward mode='bridge'><interface dev='eth0'/><interface dev='eth1'/></forward></network>"),
|
||||
("sriov", "<network><forward mode='hostdev'><pf dev='eth2'/></forward></network>"))]
|
||||
self.assertEqual(networks_by_device(MagicMock(**{"listAllNetworks.return_value": nets})),
|
||||
{"virbr0": ["default"], "br0": ["lan"], "eth0": ["direct"], "eth1": ["direct"], "eth2": ["sriov"]})
|
||||
{"virbr0": ["default"], "eth3": ["default"], "br0": ["lan"], "eth0": ["direct"], "eth1": ["direct"], "eth2": ["sriov"]})
|
||||
doms = [MagicMock(**{"name.return_value": name, "XMLDesc.return_value": xml}) for name, xml in (
|
||||
("web", "<domain><devices><interface type='bridge'><mac address='52:54:00:00:00:01'/><source bridge='br0'/>"
|
||||
"<target dev='vnet3'/></interface></devices></domain>"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue