infiniband: Reject the interface name for the ipoib connection

If the `p_key` is specified, then ipoib (IP over Infiniband) connection
will be created. In this case, the interface name must be unset.

NM only allows the user to set the interface name to a fixed value
based on the interface name of the parent and the value of the `p_key`,
for example, if the interface name of the parent is `ib0` and the
`p_key` is `0x000a`, then the `interface_name` for the ipoib connection
must be `ib0.000a` or unset. But this kind of validation in NM is
pointless because it is not useful at all to have the interface name for
the ipoib connection, NM should has also rejected setting the interface
name for the ipoib connection initially.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
Wen Liang 2022-05-08 20:17:38 -04:00 committed by Fernando Fernández Mancera
parent 6dca796863
commit cb3e23ac5d
2 changed files with 163 additions and 2 deletions

View file

@ -2097,6 +2097,14 @@ class ArgValidator_DictConnection(ArgValidatorDict):
"a infiniband device with 'infiniband.p_key' "
"property also needs 'mac' or 'parent' property",
)
if "interface_name" in result:
raise ValidationError(
name + ".interface_name",
"the 'interface_name' must be unset for the ipoib "
"connection, instead it is {0}".format(
result["interface_name"]
),
)
else:
if "infiniband" in result:
raise ValidationError(
@ -2126,8 +2134,13 @@ class ArgValidator_DictConnection(ArgValidatorDict):
"invalid 'interface_name' '%s'" % (result["interface_name"]),
)
else:
if not result.get("mac") and (
not result.get("match") or not result["match"].get("path")
if (
not result.get("mac")
and (not result.get("match") or not result["match"].get("path"))
and not (
result["type"] == "infiniband"
and result["infiniband"]["p_key"] != -1
)
):
if not Util.ifname_valid(result["name"]):
raise ValidationError(

View file

@ -2347,6 +2347,154 @@ class TestValidator(Python26CompatTestCase):
],
)
def test_infiniband3(self):
self.maxDiff = None
self.do_connections_validate(
[
{
"actions": ["present"],
"autoconnect": True,
"check_iface_exists": True,
"ethtool": ETHTOOL_DEFAULTS,
"ignore_errors": None,
"infiniband": {"p_key": -1, "transport_mode": "datagram"},
"interface_name": "ib0",
"ip": {
"address": [],
"auto_gateway": None,
"auto6": True,
"dhcp4": True,
"dhcp4_send_hostname": None,
"dns": [],
"dns_options": [],
"dns_search": [],
"gateway4": None,
"gateway6": None,
"ipv6_disabled": False,
"route": [],
"route_append_only": False,
"route_metric4": None,
"route_metric6": None,
"routing_rule": [],
"rule_append_only": False,
},
"mac": None,
"match": {},
"controller": None,
"ieee802_1x": None,
"wireless": None,
"mtu": None,
"name": "infiniband.3",
"parent": None,
"persistent_state": "present",
"port_type": None,
"state": None,
"type": "infiniband",
"zone": None,
},
{
"actions": ["present", "up"],
"autoconnect": True,
"check_iface_exists": True,
"ethtool": ETHTOOL_DEFAULTS,
"force_state_change": None,
"ignore_errors": None,
"infiniband": {"p_key": 10, "transport_mode": "datagram"},
"interface_name": None,
"ip": {
"address": [],
"auto_gateway": None,
"auto6": True,
"dhcp4": True,
"dhcp4_send_hostname": None,
"dns": [],
"dns_options": [],
"dns_search": [],
"gateway4": None,
"gateway6": None,
"ipv6_disabled": False,
"route": [],
"route_append_only": False,
"route_metric4": None,
"route_metric6": None,
"routing_rule": [],
"rule_append_only": False,
},
"mac": "11:22:33:44:55:66:77:88:99:00:"
"11:22:33:44:55:66:77:88:99:00",
"match": {},
"controller": None,
"ieee802_1x": None,
"wireless": None,
"mtu": None,
"name": "infiniband.3-10",
"parent": "infiniband.3",
"persistent_state": "present",
"port_type": None,
"state": "up",
"type": "infiniband",
"wait": None,
"zone": None,
},
],
[
{
"name": "infiniband.3",
"interface_name": "ib0",
"type": "infiniband",
},
{
"name": "infiniband.3-10",
"state": "up",
"type": "infiniband",
"parent": "infiniband.3",
"mac": "11:22:33:44:55:66:77:88:99:00:"
"11:22:33:44:55:66:77:88:99:00",
"infiniband_p_key": 10,
},
],
initscripts_dict_expected=[
{
"ifcfg": {
"BOOTPROTO": "dhcp",
"CONNECTED_MODE": "no",
"DEVICE": "ib0",
"IPV6INIT": "yes",
"IPV6_AUTOCONF": "yes",
"NM_CONTROLLED": "no",
"ONBOOT": "yes",
"TYPE": "InfiniBand",
},
"keys": None,
"route": None,
"route6": None,
"rule": None,
"rule6": None,
},
{
"ifcfg": {
"BOOTPROTO": "dhcp",
"CONNECTED_MODE": "no",
"HWADDR": "11:22:33:44:55:66:77:88:99:00:"
"11:22:33:44:55:66:77:88:99:00",
"IPV6INIT": "yes",
"IPV6_AUTOCONF": "yes",
"NM_CONTROLLED": "no",
"ONBOOT": "yes",
"PHYSDEV": "ib0",
"PKEY": "yes",
"PKEY_ID": "10",
"TYPE": "InfiniBand",
},
"keys": None,
"route": None,
"route6": None,
"rule": None,
"rule6": None,
},
],
)
def test_route_metric_prefix(self):
self.maxDiff = None
self.do_connections_validate(