From e8cdb2bc58b2f39bf619c02a049e56906b4a88a9 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Mon, 16 May 2022 06:24:53 -0400 Subject: [PATCH] infiniband: Change the default value of `p_key` into `None` The current default `p_key` value is `-1`, which is only useful for the recognizability with NetworkManager API. NetworkManager chooses the `-1` as the default pkey value only because the connection should be created on the physical infiniband interface by default and the positive pkey value would make the connection created on the virtual infiniband partition. But NetworkManager should also have represented the default value as not specifying the pkey property initially. Therefore, change the default value of `p_key` into `None`. Signed-off-by: Wen Liang --- library/network_connections.py | 6 +++--- module_utils/network_lsr/argument_validator.py | 18 +++++++++++++----- tests/unit/test_network_connections.py | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/library/network_connections.py b/library/network_connections.py index 5102173..6c11c17 100644 --- a/library/network_connections.py +++ b/library/network_connections.py @@ -348,7 +348,7 @@ class IfcfgUtil: if (connection["infiniband"]["transport_mode"] == "connected") else "no" ) - if connection["infiniband"]["p_key"] != -1: + if connection["infiniband"]["p_key"] is not None: ifcfg["PKEY"] = "yes" ifcfg["PKEY_ID"] = str(connection["infiniband"]["p_key"]) if connection["parent"]: @@ -846,7 +846,7 @@ class NMUtil: NM.SETTING_INFINIBAND_TRANSPORT_MODE, connection["infiniband"]["transport_mode"], ) - if connection["infiniband"]["p_key"] != -1: + if connection["infiniband"]["p_key"] is not None: s_infiniband.set_property( NM.SETTING_INFINIBAND_P_KEY, connection["infiniband"]["p_key"] ) @@ -2012,7 +2012,7 @@ class Cmd(object): "interface exists" % (connection["interface_name"]), ) elif connection["type"] == "infiniband": - if connection["infiniband"]["p_key"] == -1: + if connection["infiniband"]["p_key"] is None: self.log_fatal( idx, "profile specifies interface_name '%s' but no such " diff --git a/module_utils/network_lsr/argument_validator.py b/module_utils/network_lsr/argument_validator.py index bb5fa0c..5e4e2e9 100644 --- a/module_utils/network_lsr/argument_validator.py +++ b/module_utils/network_lsr/argument_validator.py @@ -1561,13 +1561,15 @@ class ArgValidator_DictInfiniband(ArgValidatorDict): ArgValidatorStr( "transport_mode", enum_values=["datagram", "connected"] ), - ArgValidatorNum("p_key", val_min=-1, val_max=0xFFFF, default_value=-1), + ArgValidatorNum( + "p_key", val_min=-1, val_max=0xFFFF, default_value=None + ), ], default_value=ArgValidator.MISSING, ) def get_default_infiniband(self): - return {"transport_mode": "datagram", "p_key": -1} + return {"transport_mode": "datagram", "p_key": None} class ArgValidator_DictVlan(ArgValidatorDict): @@ -2090,7 +2092,13 @@ class ArgValidator_DictConnection(ArgValidatorDict): ) if result["infiniband"]["transport_mode"] is None: result["infiniband"]["transport_mode"] = "datagram" - if result["infiniband"]["p_key"] != -1: + # For the compatibility with NetworkManager API and the initial + # infiniband support in the role (the user may get used to set the + # `p_key` into `-1` to make the connection created on the physical + # infiniband interface), normalize the `p_key` setting as follows + if result["infiniband"]["p_key"] == -1: + result["infiniband"]["p_key"] = None + if result["infiniband"]["p_key"] is not None: if ( result["infiniband"]["p_key"] == 0x0000 or result["infiniband"]["p_key"] == 0x8000 @@ -2148,7 +2156,7 @@ class ArgValidator_DictConnection(ArgValidatorDict): and (not result.get("match") or not result["match"].get("path")) and not ( result["type"] == "infiniband" - and result["infiniband"]["p_key"] != -1 + and result["infiniband"]["p_key"] is not None ) ): if not Util.ifname_valid(result["name"]): @@ -2370,7 +2378,7 @@ class ArgValidator_ListConnections(ArgValidatorList): ) or ( (connection["type"] == "infiniband") - and (connection["infiniband"]["p_key"] != -1) + and (connection["infiniband"]["p_key"] is not None) ) ): try: diff --git a/tests/unit/test_network_connections.py b/tests/unit/test_network_connections.py index 85deabd..161d209 100644 --- a/tests/unit/test_network_connections.py +++ b/tests/unit/test_network_connections.py @@ -2199,7 +2199,7 @@ class TestValidator(Python26CompatTestCase): "ethtool": ETHTOOL_DEFAULTS, "force_state_change": None, "ignore_errors": None, - "infiniband": {"p_key": -1, "transport_mode": "datagram"}, + "infiniband": {"p_key": None, "transport_mode": "datagram"}, "interface_name": None, "ip": { "address": [], @@ -2357,7 +2357,7 @@ class TestValidator(Python26CompatTestCase): "check_iface_exists": True, "ethtool": ETHTOOL_DEFAULTS, "ignore_errors": None, - "infiniband": {"p_key": -1, "transport_mode": "datagram"}, + "infiniband": {"p_key": None, "transport_mode": "datagram"}, "interface_name": "ib0", "ip": { "address": [],