cloud-init/SOURCES/orabug29956753-DataSourceOracle-_is_iscsi_root-not-working-with-dra.patch
2025-05-08 10:17:39 +03:00

82 lines
3.0 KiB
Diff

From 8eff3fdfd9ed477bead953deec3599c93409a415 Mon Sep 17 00:00:00 2001
From: Darren Archibald <darren.archibald@oracle.com>
Date: Fri, 23 Feb 2024 05:33:05 -0800
Subject: [PATCH] DataSourceOracle: _is_iscsi_root() not working with dracut
based initramfs
The _is_iscsi_root() implementation in Oracle datasource today only works
with initramfs-tools on Debian/Ubuntu systems, where initramfs-tools specific
files e.g. /run/net{,6}-*.conf are examined to identify initramfs initiated
network configuration. This partial implementation works with OCI Oracle
Linux (OL) images by chance as the "network-config=..." option in the boot
line happens to satisfy the corresponding network-config conditional
branch (which itself is insufficient in checking disabled network-config) in
cmdline.read_kernel_cmdline_config, and eventually renders _is_iscsi_root()
return true for OL images all across. Apparently this shouldn't be the
case for VM instance with PV boot.
The fix involved is to identify dracut based initramfs config files for
network boot, and also ibft as how it does for initramfs-tools based
initramfs on Ubuntu.
Orabug: 29956753
Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
Signed-off-by: Darren Archibald <darren.archibald@oracle.com>
---
cloudinit/sources/DataSourceOracle.py | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/cloudinit/sources/DataSourceOracle.py b/cloudinit/sources/DataSourceOracle.py
index 07247d7..afae393 100644
--- a/cloudinit/sources/DataSourceOracle.py
+++ b/cloudinit/sources/DataSourceOracle.py
@@ -14,6 +14,8 @@ Notes:
"""
import base64
+import glob
+import os
import ipaddress
import logging
from collections import namedtuple
@@ -31,6 +33,11 @@ from cloudinit.url_helper import UrlError, readurl
LOG = logging.getLogger(__name__)
+DRACUT_TMP_PATH='/var/run/initramfs'
+DRACUT_OLDTMP_PATH='/dev/.initramfs'
+DRACUT_NET_IFACES='net.ifaces'
+DRACUT_IBFT_PATTERN='net.*.has_ibft_config'
+
BUILTIN_DS_CONFIG = {
# Don't use IMDS to configure secondary NICs by default
"configure_secondary_nics": False,
@@ -200,9 +207,22 @@ class DataSourceOracle(sources.DataSource):
def get_public_ssh_keys(self):
return sources.normalize_pubkey_data(self.metadata.get("public_keys"))
+ def _is_dracut_netconfig():
+ for net_ifaces_path in (
+ DRACUT_TMP_PATH + '/' + DRACUT_NET_IFACES,
+ DRACUT_OLDTMP_PATH + '/' + DRACUT_NET_IFACES):
+ if os.path.exists(net_ifaces_path):
+ return True
+
+ if glob.glob(DRACUT_TMP_PATH + '/' + DRACUT_IBFT_PATTERN) + \
+ glob.glob(DRACUT_OLDTMP_PATH + '/' + DRACUT_IBFT_PATTERN):
+ return True
+
+ return False
+
def _is_iscsi_root(self) -> bool:
"""Return whether we are on a iscsi machine."""
- return self._network_config_source.is_applicable()
+ return self._network_config_source.is_applicable() or _is_dracut_netconfig()
def _get_iscsi_config(self) -> dict:
return self._network_config_source.render_config()
--
2.31.1