cloud-init: add azure related change

Azure on cloud-init doesn't require to copy
the dhclient library. adding a patch to remove it

BUG=b/172000899
TEST=presubmit
RELEASE_NOTE=None

Change-Id: I2d9b6ec84d0b4b94b576b74db5b1f7f8c768c9b1
Reviewed-on: https://cos-review.googlesource.com/c/cos/overlays/board-overlays/+/8801
Reviewed-by: Roy Yang <royyang@google.com>
Tested-by: Varsha Teratipally <teratipally@google.com>
diff --git a/project-lakitu/app-emulation/cloud-init/cloud-init-20.1-r4.ebuild b/project-lakitu/app-emulation/cloud-init/cloud-init-20.1-r5.ebuild
similarity index 100%
rename from project-lakitu/app-emulation/cloud-init/cloud-init-20.1-r4.ebuild
rename to project-lakitu/app-emulation/cloud-init/cloud-init-20.1-r5.ebuild
diff --git a/project-lakitu/app-emulation/cloud-init/cloud-init-20.1.ebuild b/project-lakitu/app-emulation/cloud-init/cloud-init-20.1.ebuild
index 263c5fe..1621c6d 100644
--- a/project-lakitu/app-emulation/cloud-init/cloud-init-20.1.ebuild
+++ b/project-lakitu/app-emulation/cloud-init/cloud-init-20.1.ebuild
@@ -19,7 +19,7 @@
 
 LICENSE="GPL-3"
 SLOT="0"
-IUSE="test configure_network"
+IUSE="test configure_network platform_azure"
 RESTRICT="!test? ( test )"
 
 CDEPEND="
@@ -75,6 +75,10 @@
 		PATCHES+=("${FILESDIR}/${PV}-remove-sshd-dependency.patch")
 	fi
 
+	if use platform_azure; then
+		PATCHES+=("${FILESDIR}"/cloud-init-azure-remove-dhclient.patch)
+	fi
+
 	# Fix location of documentation installation
 	sed -i "s:USR + '/share/doc/cloud-init:USR + '/share/doc/${PF}:" setup.py || die
 	sed -i 's/version=get_version(),/version=9999,/g' setup.py || die
diff --git a/project-lakitu/app-emulation/cloud-init/files/cloud-init-azure-remove-dhclient.patch b/project-lakitu/app-emulation/cloud-init/files/cloud-init-azure-remove-dhclient.patch
new file mode 100644
index 0000000..c8cd45b
--- /dev/null
+++ b/project-lakitu/app-emulation/cloud-init/files/cloud-init-azure-remove-dhclient.patch
@@ -0,0 +1,52 @@
+Subject: cloud-init on azure required dhclient not to be 
+included in /tmp.
+
+diff --git a/cloudinit/net/dhcp.py b/cloudinit/net/dhcp.py
+index c033cc8..be60f6f 100644
+--- a/cloudinit/net/dhcp.py
++++ b/cloudinit/net/dhcp.py
+@@ -205,13 +205,9 @@ def dhcp_discovery(dhclient_cmd_path, interface, cleandir):
+     """
+     LOG.debug('Performing a dhcp discovery on %s', interface)
+ 
+-    # XXX We copy dhclient out of /sbin/dhclient to avoid dealing with strict
+-    # app armor profiles which disallow running dhclient -sf <our-script-file>.
+     # We want to avoid running /sbin/dhclient-script because of side-effects in
+     # /etc/resolv.conf any any other vendor specific scripts in
+     # /etc/dhcp/dhclient*hooks.d.
+-    sandbox_dhclient_cmd = os.path.join(cleandir, 'dhclient')
+-    util.copy(dhclient_cmd_path, sandbox_dhclient_cmd)
+     pid_file = os.path.join(cleandir, 'dhclient.pid')
+     lease_file = os.path.join(cleandir, 'dhcp.leases')
+ 
+@@ -220,7 +216,7 @@ def dhcp_discovery(dhclient_cmd_path, interface, cleandir):
+     # link up before attempting discovery. Since we are using -sf /bin/true,
+     # we need to do that "link up" ourselves first.
+     util.subp(['ip', 'link', 'set', 'dev', interface, 'up'], capture=True)
+-    cmd = [sandbox_dhclient_cmd, '-1', '-v', '-lf', lease_file,
++    cmd = ['dhclient', '-1', '-v', '-lf', lease_file,
+            '-pf', pid_file, interface, '-sf', '/bin/true']
+     util.subp(cmd, capture=True)
+ 
+diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py
+index fc76058..869d462 100755
+--- a/cloudinit/sources/helpers/azure.py
++++ b/cloudinit/sources/helpers/azure.py
+@@ -90,7 +90,7 @@ def get_boot_telemetry():
+         raise RuntimeError("Failed to determine kernel start timestamp")
+ 
+     try:
+-        out, _ = util.subp(['/bin/systemctl',
++        out, _ = util.subp(['systemctl',
+                             'show', '-p',
+                             'UserspaceTimestampMonotonic'],
+                            capture=True)
+@@ -112,7 +112,7 @@ def get_boot_telemetry():
+                            % e)
+ 
+     try:
+-        out, _ = util.subp(['/bin/systemctl', 'show',
++        out, _ = util.subp(['systemctl', 'show',
+                             'cloud-init-local', '-p',
+                             'InactiveExitTimestampMonotonic'],
+                            capture=True)