From 2d0f53b7b73b40184ce4a39de5db937bafc08d2b Mon Sep 17 00:00:00 2001 From: waleedm Date: Wed, 15 Feb 2023 08:29:16 +0000 Subject: [PATCH] Fix PKEY_ID value in ifcfg file of infiniband child interface In the current implementation of ifcfg file in os-net-config, the high bit of the PKEY_ID setting is not being set, while the high bit of the pkey in the DEVICE setting is being set. However, due to a change in NetworkManager [1], it is no longer necessary to set the high bit of the pkey in the DEVICE setting, but applying this change in os-net-config is causing compatibility issues with older versions of NetworkManager. To address this issue, this patch proposes setting the high bit for both the PKEY_ID and pkey in DEVICE settings in the ifcfg file. This approach would work for all versions of NetworkManager and maintain compatibility with older versions. [1] https://github.com/NetworkManager/NetworkManager/commit/33f2f82a0951c79a5e0363413c63f9067fd85340 Closes-Bug: #2007372 Change-Id: I7b4f063508c4d9518ca706e62cf1368fba2d069e (cherry picked from commit 3e73bd8c83325d11fbc4f2f13c7829ce07c2414f) --- os_net_config/impl_ifcfg.py | 2 +- os_net_config/objects.py | 4 ++-- os_net_config/tests/test_impl_ifcfg.py | 2 +- os_net_config/tests/test_objects.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py index f8e87ae4..75c64ae2 100644 --- a/os_net_config/impl_ifcfg.py +++ b/os_net_config/impl_ifcfg.py @@ -431,7 +431,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): data += "TYPE=Infiniband\n" data += "PKEY=yes\n" data += "PHYSDEV=%s\n" % base_opt.parent - data += "PKEY_ID=%d\n" % base_opt.pkey_id + data += "PKEY_ID=%s\n" % base_opt.pkey_id elif re.match(r'\w+\.\d+$', base_opt.name): data += "VLAN=yes\n" elif isinstance(base_opt, objects.Interface): diff --git a/os_net_config/objects.py b/os_net_config/objects.py index 9e5b99e4..fdaaf8ca 100644 --- a/os_net_config/objects.py +++ b/os_net_config/objects.py @@ -1269,9 +1269,9 @@ class IbChildInterface(_BaseOpts): routes = routes or [] rules = rules or [] dns_servers = dns_servers or [] - self.pkey_id = pkey_id - self.parent = parent full_pkey_id = 0x8000 | pkey_id + self.pkey_id = hex(full_pkey_id) + self.parent = parent name = "%s.%04x" % (parent, full_pkey_id) nm_controlled = True super(IbChildInterface, self).__init__(name, use_dhcp, use_dhcpv6, diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py index 6c861ab8..af21813c 100644 --- a/os_net_config/tests/test_impl_ifcfg.py +++ b/os_net_config/tests/test_impl_ifcfg.py @@ -191,7 +191,7 @@ PEERDNS=no TYPE=Infiniband PKEY=yes PHYSDEV=ib0 -PKEY_ID=1 +PKEY_ID=0x8001 BOOTPROTO=none """ diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py index b4a87fe6..00d54ff8 100644 --- a/os_net_config/tests/test_objects.py +++ b/os_net_config/tests/test_objects.py @@ -1622,14 +1622,14 @@ class TestIbChildInterface(base.TestCase): def test_ib_child_interface_pkey_id_valid(self): ib_child_interface = objects.IbChildInterface('foo', pkey_id=100) - self.assertEqual(100, ib_child_interface.pkey_id) + self.assertEqual("0x8064", ib_child_interface.pkey_id) def test_ib_child_interface_pkey_id_hexa(self): data = '{"type": "ib_child_interface", ' \ '"parent": "foo", "pkey_id": "0x64"}' ib_child_interface = \ objects.IbChildInterface.from_json(json.loads(data)) - self.assertEqual(100, ib_child_interface.pkey_id) + self.assertEqual("0x8064", ib_child_interface.pkey_id) def test_ib_child_interface_pkey_id_invalid_base(self): data = '{"type": "ib_child_interface", ' \