From 33c11e1e9ca4eacea9ffb52e4b8a47bad42105b9 Mon Sep 17 00:00:00 2001
From: waleedm <waleedm@nvidia.com>
Date: Wed, 3 May 2023 11:34:02 +0000
Subject: [PATCH] Add nm-dhcp-ib-interfaces element

Currently, NetworkManager can't automatically create default
connection profiles for InfiniBand interfaces.

So, as a workaround, we are adding nm-dhcp-ib-interfaces element to
install NetworkManager-system-connections-infiniband.nmconnection
to NetworkManager to create a wildcard InfiniBand connection profile.

The content of NetworkManager-system-connections-infiniband.nmconnection
is generated by running this command:
`nmcli --offline connection add type infiniband connection.multi-connect multiple`

Closes-Bug: #2016965
Change-Id: Ic972b90e4df9c4aa36cfe3c8631db3e4533045f4
---
 .../elements/nm-dhcp-ib-interfaces/README.rst   |  9 +++++++++
 .../install.d/50-dhcp-ib-interfaces             | 16 ++++++++++++++++
 ...r-system-connections-infiniband.nmconnection | 17 +++++++++++++++++
 .../notes/bug-2016965-f3f35c919081f64c.yaml     |  7 +++++++
 4 files changed, 49 insertions(+)
 create mode 100644 diskimage_builder/elements/nm-dhcp-ib-interfaces/README.rst
 create mode 100755 diskimage_builder/elements/nm-dhcp-ib-interfaces/install.d/50-dhcp-ib-interfaces
 create mode 100644 diskimage_builder/elements/nm-dhcp-ib-interfaces/install.d/NetworkManager-system-connections-infiniband.nmconnection
 create mode 100644 releasenotes/notes/bug-2016965-f3f35c919081f64c.yaml

diff --git a/diskimage_builder/elements/nm-dhcp-ib-interfaces/README.rst b/diskimage_builder/elements/nm-dhcp-ib-interfaces/README.rst
new file mode 100644
index 000000000..7b061dba9
--- /dev/null
+++ b/diskimage_builder/elements/nm-dhcp-ib-interfaces/README.rst
@@ -0,0 +1,9 @@
+=====================
+nm-dhcp-ib-interfaces
+=====================
+Add InfiniBand connection profile to run DHCP for InfiniBand interfaces
+
+As it's not implemented yet to create default connection profiles for
+InfiniBand interfaces in NetworkManager, we are providing a wildcard
+InfiniBand connection profile to allow it to run DHCP for InfiniBand
+interfaces.
diff --git a/diskimage_builder/elements/nm-dhcp-ib-interfaces/install.d/50-dhcp-ib-interfaces b/diskimage_builder/elements/nm-dhcp-ib-interfaces/install.d/50-dhcp-ib-interfaces
new file mode 100755
index 000000000..5fa4e1cfc
--- /dev/null
+++ b/diskimage_builder/elements/nm-dhcp-ib-interfaces/install.d/50-dhcp-ib-interfaces
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then
+    set -x
+fi
+set -eu
+set -o pipefail
+
+SCRIPTDIR=$(dirname $0)
+
+# Because NetworkManager can't automatically create default connection
+# profiles for InfiniBand interfaces, we are installing
+# NetworkManager-system-connections-infiniband.nmconnection to
+# NetworkManager to create a wildcard InfiniBand connection profile
+install -D -g root -o root -m 0600 ${SCRIPTDIR}/NetworkManager-system-connections-infiniband.nmconnection /etc/NetworkManager/system-connections/infiniband.nmconnection
+exit 0
diff --git a/diskimage_builder/elements/nm-dhcp-ib-interfaces/install.d/NetworkManager-system-connections-infiniband.nmconnection b/diskimage_builder/elements/nm-dhcp-ib-interfaces/install.d/NetworkManager-system-connections-infiniband.nmconnection
new file mode 100644
index 000000000..d9d9a442c
--- /dev/null
+++ b/diskimage_builder/elements/nm-dhcp-ib-interfaces/install.d/NetworkManager-system-connections-infiniband.nmconnection
@@ -0,0 +1,17 @@
+[connection]
+id=infiniband
+type=infiniband
+multi-connect=3
+
+[infiniband]
+transport-mode=datagram
+
+[ipv4]
+method=auto
+
+[ipv6]
+addr-gen-mode=default
+method=auto
+
+[proxy]
+
diff --git a/releasenotes/notes/bug-2016965-f3f35c919081f64c.yaml b/releasenotes/notes/bug-2016965-f3f35c919081f64c.yaml
new file mode 100644
index 000000000..dbc7295b5
--- /dev/null
+++ b/releasenotes/notes/bug-2016965-f3f35c919081f64c.yaml
@@ -0,0 +1,7 @@
+---
+fixes:
+  - |
+    As NetworkManager can't automatically create default connection profiles
+    for InfiniBand interfaces, we are adding nm-dhcp-ib-interfaces element
+    to install NetworkManager-system-connections-infiniband.nmconnection to
+    NetworkManager to create a wildcard InfiniBand connection profile.