← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~johnsonshi/cloud-init:rhel-centos-dhclient-lease-path into cloud-init:master

 

Johnson Shi has proposed merging ~johnsonshi/cloud-init:rhel-centos-dhclient-lease-path into cloud-init:master.

Commit message:
azure: Update to correct dhclient lease file for CentOS/RHEL

The lease file hard-coded in DataSourceAzure.py is
'/var/lib/dhcp/dhclient.eth0.leases', which is non-existent
for RHEL and CentOS. This causes 2 issues: crawling of
Azure Instance Metadata Service (IMDS) times out during
cloud-init-local stage, and get_metadata_from_fabric
fails (causing Azure fabric negotiation and communication
to fail).

During the cloud-init-local stage, an ephemeral network
is set up and an IPv4 address is obtained. A GET request
with a metadata header is then sent to the publicly
accessible metadata endpoint for Azure IMDS. Failure to
properly read the dhclient lease causes the ephemeral
network to be improperly set up, which causes the request
for IMDS instance metadata to time out successively and
be ignored.

During the cloud-init stage, Azure fabric negotiation and
getting of metadata from fabric fails because of failure
to properly read the dhclient lease file.

Both of these issues are indicated in the cloud-init logs
during deployment for CentOS and RHEL because the dhclient
lease file for CentOS/RHEL is in a different path. This
commit fixes that issue by adding two additional utility
functions to util.py that checks whether the distro
variant is "rhel" or "centos". Within DataSourceAzure.py,
if the variant is RHEL or CentOS, the LEASE_FILE is updated
to point to the correct path.


Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~johnsonshi/cloud-init/+git/cloud-init/+merge/361108
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~johnsonshi/cloud-init:rhel-centos-dhclient-lease-path into cloud-init:master.
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index 46efca4..c2bfc54 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -196,6 +196,10 @@ if util.is_FreeBSD():
     else:
         LOG.debug("resource disk is None")
 
+# update the CentOS/RHEL specific information
+if util.is_CentOS() or util.is_RHEL():
+    LEASE_FILE = '/var/lib/dhclient/dhclient-eth0.leases'
+
 BUILTIN_DS_CONFIG = {
     'agent_command': AGENT_START_BUILTIN,
     'data_dir': AGENT_SEED_DIR,
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 7800f7b..b216335 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -557,6 +557,14 @@ def is_FreeBSD():
     return system_info()['variant'] == "freebsd"
 
 
+def is_CentOS():
+    return system_info()['variant'] == "centos"
+
+
+def is_RHEL():
+    return system_info()['variant'] == "rhel"
+
+
 def get_cfg_option_bool(yobj, key, default=False):
     if key not in yobj:
         return default

Follow ups