Skip to content

Commit e7308b9

Browse files
nmcli: allow VxLan multicast and bridge port
VxLan virtual devices can be added to bridge ports, like any other devices. And when using multicast remote addresses, NetworkManager need to know the parent device as well. Co-authored-by: Felix Fontein <[email protected]>
1 parent d98df2d commit e7308b9

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
minor_changes:
2+
- nmcli module - add vxlan_parent argument required for multicast vxlan_remote addresses
3+
- nmcli module - add vxlan to list of bridgeable devices

plugins/modules/nmcli.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,11 @@
530530
description:
531531
- This is only used with VXLAN - VXLAN destination IP address.
532532
type: str
533+
vxlan_parent:
534+
description:
535+
- This is only used with VXLAN - VXLAN parent device (required when using a multicast remote address).
536+
type: str
537+
version_added: 12.1.0
533538
vxlan_local:
534539
description:
535540
- This is only used with VXLAN - VXLAN local IP address.
@@ -1454,6 +1459,17 @@
14541459
vxlan_local: 192.168.1.2
14551460
vxlan_remote: 192.168.1.5
14561461
1462+
- name: Add VxLan via multicast on a bridge
1463+
community.general.nmcli:
1464+
type: vxlan
1465+
conn_name: vxlan_test2
1466+
vxlan_id: 17
1467+
vxlan_parent: eth1
1468+
vxlan_local: 192.168.1.2
1469+
vxlan_remote: 239.192.0.17
1470+
slave_type: bridge
1471+
master: br0
1472+
14571473
- name: Add gre
14581474
community.general.nmcli:
14591475
type: gre
@@ -1784,6 +1800,7 @@ def __init__(self, module):
17841800
self.ingress = module.params["ingress"]
17851801
self.egress = module.params["egress"]
17861802
self.vxlan_id = module.params["vxlan_id"]
1803+
self.vxlan_parent = module.params["vxlan_parent"]
17871804
self.vxlan_local = module.params["vxlan_local"]
17881805
self.vxlan_remote = module.params["vxlan_remote"]
17891806
self.ip_tunnel_dev = module.params["ip_tunnel_dev"]
@@ -2041,6 +2058,7 @@ def connection_options(self, detect_change=False):
20412058
options.update(
20422059
{
20432060
"vxlan.id": self.vxlan_id,
2061+
"vxlan.parent": self.vxlan_parent,
20442062
"vxlan.local": self.vxlan_local,
20452063
"vxlan.remote": self.vxlan_remote,
20462064
}
@@ -2256,6 +2274,7 @@ def slave_conn_type(self):
22562274
"infiniband",
22572275
"ovs-port",
22582276
"ovs-interface",
2277+
"vxlan",
22592278
)
22602279

22612280
@property
@@ -2825,6 +2844,7 @@ def main():
28252844
egress=dict(type="str"),
28262845
# vxlan specific vars
28272846
vxlan_id=dict(type="int"),
2847+
vxlan_parent=dict(type="str"),
28282848
vxlan_local=dict(type="str"),
28292849
vxlan_remote=dict(type="str"),
28302850
# ip-tunnel specific vars

tests/unit/plugins/modules/test_nmcli.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,34 @@
843843
vxlan.remote: 192.168.225.6
844844
"""
845845

846+
TESTCASE_VXLAN_MULTICAST = [
847+
{
848+
"type": "vxlan",
849+
"conn_name": "vxlan_multicast_test",
850+
"ifname": "vxlan-device",
851+
"vxlan_id": 17,
852+
"vxlan_parent": "eth1",
853+
"vxlan_local": "192.168.1.2",
854+
"vxlan_remote": "239.192.0.17",
855+
"slave_type": "bridge",
856+
"master": "br0",
857+
"state": "present",
858+
"_ansible_check_mode": False,
859+
}
860+
]
861+
862+
TESTCASE_VXLAN_MULTICAST_SHOW_OUTPUT = """\
863+
connection.id: vxlan_multicast_test
864+
connection.interface-name: vxlan-device
865+
connection.autoconnect: yes
866+
connection.slave-type: bridge
867+
connection.master: br0
868+
vxlan.id: 17
869+
vxlan.parent: eth1
870+
vxlan.local: 192.168.1.2
871+
vxlan.remote: 239.192.0.17
872+
"""
873+
846874
TESTCASE_GRE = [
847875
{
848876
"type": "gre",
@@ -2912,6 +2940,51 @@ def test_vxlan_connection_unchanged(mocked_vxlan_connection_unchanged, capfd):
29122940
assert not results["changed"]
29132941

29142942

2943+
@pytest.mark.parametrize("patch_ansible_module", TESTCASE_VXLAN_MULTICAST, indirect=["patch_ansible_module"])
2944+
def test_create_vxlan_multicast(mocked_generic_connection_create, capfd):
2945+
"""
2946+
Test if vxlan with multicast and parent device created
2947+
"""
2948+
with pytest.raises(SystemExit):
2949+
nmcli.main()
2950+
2951+
assert nmcli.Nmcli.execute_command.call_count == 1
2952+
arg_list = nmcli.Nmcli.execute_command.call_args_list
2953+
args, kwargs = arg_list[0]
2954+
2955+
assert args[0][0] == "/usr/bin/nmcli"
2956+
assert args[0][1] == "con"
2957+
assert args[0][2] == "add"
2958+
assert args[0][3] == "type"
2959+
assert args[0][4] == "vxlan"
2960+
assert args[0][5] == "con-name"
2961+
assert args[0][6] == "vxlan_multicast_test"
2962+
2963+
args_text = list(map(to_text, args[0]))
2964+
for param in [
2965+
"connection.interface-name",
2966+
"vxlan-device",
2967+
"vxlan.local",
2968+
"192.168.1.2",
2969+
"vxlan.remote",
2970+
"239.192.0.17",
2971+
"vxlan.id",
2972+
"17",
2973+
"vxlan.parent",
2974+
"eth1",
2975+
"connection.slave-type",
2976+
"bridge",
2977+
"connection.master",
2978+
"br0",
2979+
]:
2980+
assert param in args_text
2981+
2982+
out, err = capfd.readouterr()
2983+
results = json.loads(out)
2984+
assert not results.get("failed")
2985+
assert results["changed"]
2986+
2987+
29152988
@pytest.mark.parametrize("patch_ansible_module", TESTCASE_IPIP, indirect=["patch_ansible_module"])
29162989
def test_create_ipip(mocked_generic_connection_create, capfd):
29172990
"""
@@ -4720,6 +4793,7 @@ def test_bond_connection_unchanged_2(mocked_generic_connection_diff_check, capfd
47204793
egress=dict(type="str"),
47214794
# vxlan specific vars
47224795
vxlan_id=dict(type="int"),
4796+
vxlan_parent=dict(type="str"),
47234797
vxlan_local=dict(type="str"),
47244798
vxlan_remote=dict(type="str"),
47254799
# ip-tunnel specific vars

0 commit comments

Comments
 (0)