← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~chad.smith/cloud-init:dhclient-from-var-tmp into cloud-init:master

 

Chad Smith has proposed merging ~chad.smith/cloud-init:dhclient-from-var-tmp into cloud-init:master.

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

For more details, see:
https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/330875

ec2: Fix maybe_perform_dhcp_discovery to use /var/tmp as a tmpdir

/run/cloud-init/tmp is on a filesystem mounted noexec, so running
dchlient in Ec2Local during discovery breaks with 'Permission denied'.
This branch allows us to run from a different tmp dir so we have exec
rights.
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:dhclient-from-var-tmp into cloud-init:master.
diff --git a/cloudinit/net/dhcp.py b/cloudinit/net/dhcp.py
index c842c83..60eb078 100644
--- a/cloudinit/net/dhcp.py
+++ b/cloudinit/net/dhcp.py
@@ -48,8 +48,9 @@ def maybe_perform_dhcp_discovery(nic=None):
     if not dhclient_path:
         LOG.debug('Skip dhclient configuration: No dhclient command found.')
         return {}
-    with temp_utils.tempdir(prefix='cloud-init-dhcp-') as tmpdir:
-        return dhcp_discovery(dhclient_path, nic, tmpdir)
+    with temp_utils.tempdir(dir='/var/tmp', prefix='cloud-init-dhcp-') as tdir:
+        # Use /var/tmp because /run/cloud-init/tmp is mounted noexec
+        return dhcp_discovery(dhclient_path, nic, tdir)
 
 
 def parse_dhcp_lease_file(lease_file):
diff --git a/cloudinit/net/tests/test_dhcp.py b/cloudinit/net/tests/test_dhcp.py
index 4a37e98..2776ccc 100644
--- a/cloudinit/net/tests/test_dhcp.py
+++ b/cloudinit/net/tests/test_dhcp.py
@@ -105,7 +105,7 @@ class TestDHCPDiscoveryClean(CiTestCase):
         call = m_dhcp.call_args_list[0]
         self.assertEqual('/sbin/dhclient', call[0][0])
         self.assertEqual('eth9', call[0][1])
-        self.assertIn('/tmp/cloud-init-dhcp-', call[0][2])
+        self.assertIn('/var/tmp/cloud-init-dhcp-', call[0][2])
 
     @mock.patch('cloudinit.net.dhcp.util.subp')
     def test_dhcp_discovery_run_in_sandbox(self, m_subp):

Follow ups