mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 01:16:10 +00:00
fix(instances): a clone's NIC filter keeps no address of its source's
A NIC filter such as clean-traffic can name the VM's own MAC and IP as parameters. A clone kept the source's, so the filter dropped the clone's traffic from its new MAC. A clone's MAC parameter is now its own MAC, and its IP parameter is left out for the filter to learn the clone's address, as clean-traffic does by default; with learning turned off (CTRL_IP_LEARNING none) the filter needs it, and it stays, as an IPV6 parameter does (libvirt learns no IPv6 address). A filter page showed the actions drop, reject, return and continue in English in every language; they are translated now.
This commit is contained in:
parent
b1c6184931
commit
7bbc951082
8 changed files with 199 additions and 117 deletions
|
|
@ -2509,6 +2509,14 @@ class wvmInstance(wvmConnect):
|
|||
if not mac:
|
||||
raise ValueError(f"No MAC address for network interface {num}")
|
||||
net.find("mac").set("address", self.fix_mac(mac))
|
||||
# a filter's parameters of the source's own addresses would block the clone's traffic:
|
||||
# its MAC is the clone's, its IP the one it learns (clean-traffic's default), unless
|
||||
# learning is off; libvirt learns no IPv6 address, so IPV6 stays for the admin to change
|
||||
for parameter in net.xpath("filterref/parameter[@name='MAC']"):
|
||||
parameter.set("value", self.fix_mac(mac))
|
||||
if not net.xpath("filterref/parameter[@name='CTRL_IP_LEARNING'][@value='none']"):
|
||||
for parameter in net.xpath("filterref/parameter[@name='IP']"):
|
||||
parameter.getparent().remove(parameter)
|
||||
|
||||
# the clone's console gets a password of its own: one copied from the source would open both
|
||||
for graphics in tree.findall("devices/graphics[@type='vnc']"):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"""A clone's VNC console gets a password of its own: one copied from its
|
||||
source (a template's, say) would open the source's and every other clone's."""
|
||||
source (a template's, say) would open the source's and every other clone's.
|
||||
Its NIC filters keep no address of the source's."""
|
||||
|
||||
import unittest
|
||||
|
||||
|
|
@ -24,3 +25,26 @@ class CloneConsoleTestCase(unittest.TestCase):
|
|||
|
||||
def test_a_source_without_a_password_gives_a_clone_with_one(self):
|
||||
self.assertEqual(len(clone_graphics("").get("passwd")), 8)
|
||||
|
||||
def test_a_clones_nic_filter_has_its_mac_and_learns_its_ip(self):
|
||||
# the source's MAC and IP in clean-traffic's parameters would drop the clone's traffic
|
||||
p = wvmInstance.__new__(wvmInstance)
|
||||
p.get_instances = lambda: []
|
||||
p._XMLDesc = lambda flags: """<domain><name>tpl</name><uuid>u</uuid><devices>
|
||||
<interface type='network'><mac address='52:54:00:00:00:01'/><source network='default'/>
|
||||
<filterref filter='clean-traffic'><parameter name='MAC' value='52:54:00:00:00:01'/>
|
||||
<parameter name='IP' value='192.0.2.10'/><parameter name='CTRL_IP_LEARNING' value='dhcp'/></filterref>
|
||||
</interface></devices></domain>"""
|
||||
tree, _ = p._clone_definition({"name": "copy", "clone-net-mac-0": "52:54:00:00:00:02"},
|
||||
"abababab-0000-1111-2222-333333333333")
|
||||
parameters = {par.get("name"): par.get("value") for par in tree.findall("devices/interface/filterref/parameter")}
|
||||
self.assertEqual(parameters, {"MAC": "52:54:00:00:00:02", "CTRL_IP_LEARNING": "dhcp"})
|
||||
# without learning, the filter needs its IP: the clone keeps it, as it keeps IPV6
|
||||
p._XMLDesc = lambda flags: """<domain><name>tpl</name><uuid>u</uuid><devices>
|
||||
<interface type='network'><mac address='52:54:00:00:00:01'/><source network='default'/>
|
||||
<filterref filter='clean-traffic'><parameter name='IP' value='192.0.2.10'/>
|
||||
<parameter name='IPV6' value='2001:db8::10'/><parameter name='CTRL_IP_LEARNING' value='none'/></filterref>
|
||||
</interface></devices></domain>"""
|
||||
tree, _ = p._clone_definition({"name": "copy", "clone-net-mac-0": "52:54:00:00:00:02"},
|
||||
"abababab-0000-1111-2222-333333333333")
|
||||
self.assertEqual(tree.xpath("devices/interface/filterref/parameter/@name"), ["IP", "IPV6", "CTRL_IP_LEARNING"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue