Skip to content

Commit a0616fb

Browse files
committed
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.
1 parent d98df2d commit a0616fb

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

plugins/modules/nmcli.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,10 @@
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
533537
vxlan_local:
534538
description:
535539
- This is only used with VXLAN - VXLAN local IP address.
@@ -1454,6 +1458,17 @@
14541458
vxlan_local: 192.168.1.2
14551459
vxlan_remote: 192.168.1.5
14561460
1461+
- name: Add VxLan via multicast on a bridge
1462+
community.general.nmcli:
1463+
type: vxlan
1464+
conn_name: vxlan_test2
1465+
vxlan_id: 17
1466+
vxlan_parent: eth1
1467+
vxlan_local: 192.168.1.2
1468+
vxlan_remote: 239.192.0.17
1469+
slave_type: bridge
1470+
master: br0
1471+
14571472
- name: Add gre
14581473
community.general.nmcli:
14591474
type: gre
@@ -1784,6 +1799,7 @@ def __init__(self, module):
17841799
self.ingress = module.params["ingress"]
17851800
self.egress = module.params["egress"]
17861801
self.vxlan_id = module.params["vxlan_id"]
1802+
self.vxlan_parent = module.params["vxlan_parent"]
17871803
self.vxlan_local = module.params["vxlan_local"]
17881804
self.vxlan_remote = module.params["vxlan_remote"]
17891805
self.ip_tunnel_dev = module.params["ip_tunnel_dev"]
@@ -2041,6 +2057,7 @@ def connection_options(self, detect_change=False):
20412057
options.update(
20422058
{
20432059
"vxlan.id": self.vxlan_id,
2060+
"vxlan.parent": self.vxlan_parent,
20442061
"vxlan.local": self.vxlan_local,
20452062
"vxlan.remote": self.vxlan_remote,
20462063
}
@@ -2256,6 +2273,7 @@ def slave_conn_type(self):
22562273
"infiniband",
22572274
"ovs-port",
22582275
"ovs-interface",
2276+
"vxlan",
22592277
)
22602278

22612279
@property
@@ -2825,6 +2843,7 @@ def main():
28252843
egress=dict(type="str"),
28262844
# vxlan specific vars
28272845
vxlan_id=dict(type="int"),
2846+
vxlan_parent=dict(type="str"),
28282847
vxlan_local=dict(type="str"),
28292848
vxlan_remote=dict(type="str"),
28302849
# ip-tunnel specific vars

tests/unit/plugins/modules/test_nmcli.py

Lines changed: 73 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
"""

0 commit comments

Comments
 (0)