76dbdd
From 4ab5a61c0f8378889d2a6b78710f49b0fb71d3c9 Mon Sep 17 00:00:00 2001
76dbdd
From: Miroslav Rezanina <mrezanin@redhat.com>
76dbdd
Date: Fri, 22 Nov 2019 07:46:38 +0100
76dbdd
Subject: [PATCH 1/2] Fix for network configuration not persisting after reboot
76dbdd
76dbdd
RH-Author: Eduardo Otubo <otubo@redhat.com>
76dbdd
Message-id: <20190906121211.23172-1-otubo@redhat.com>
76dbdd
Patchwork-id: 90300
76dbdd
O-Subject: [RHEL-7.8/RHEL-8.1.0 cloud-init PATCH] Fix for network configuration not persisting after reboot
76dbdd
Bugzilla: 1706482
76dbdd
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
76dbdd
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
76dbdd
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
76dbdd
76dbdd
The reasons the configuration does not persist after reboot includes
76dbdd
different aspects and they're all fixed on this patch:
76dbdd
76dbdd
  1) The rpm package doesn't include the systemd-generator and
76dbdd
ds-identify. The systemd-generator is called early in the boot process
76dbdd
that calls ds-identify to check if there's any Data Source available in
76dbdd
the current boot. In the current use case, the Data Source is removed
76dbdd
from the VM on the second boot, this means cloud-init should disable
76dbdd
itself in order to keep the configuration it did in the first boot.
76dbdd
76dbdd
  2) Even after adding those scripts, cloud-init was still being
76dbdd
executed and the configurations were being lost. The reason for this is
76dbdd
that the cloud-init systemd units had a wrong dependency
76dbdd
76dbdd
     WantedBy: multi-user.target
76dbdd
76dbdd
     Which would start them every time no matter the return of
76dbdd
ds-identify. The fix is to replace the dependency by the systemd unit to
76dbdd
cloud-init.target, which is the main cloud-init target enabled - or in
76dbdd
this case, disabled by ds-identify. The file cloud-init.target was also
76dbdd
missing on rpm package.
76dbdd
76dbdd
After adding both scripts, the main cloud-init systemd target and
76dbdd
adjusting the systemd dependencies the configuration persists after
76dbdd
reboots and shutdowns.
76dbdd
76dbdd
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
76dbdd
---
76dbdd
 redhat/cloud-init.spec.template       | 15 +++++++++++++++
76dbdd
 rhel/systemd/cloud-config.service     |  2 +-
76dbdd
 rhel/systemd/cloud-final.service      |  2 +-
76dbdd
 rhel/systemd/cloud-init-local.service |  2 +-
76dbdd
 rhel/systemd/cloud-init.service       |  2 +-
76dbdd
 rhel/systemd/cloud-init.target        |  7 +++++++
76dbdd
 6 files changed, 26 insertions(+), 4 deletions(-)
76dbdd
 create mode 100644 rhel/systemd/cloud-init.target
76dbdd
76dbdd
diff --git a/rhel/systemd/cloud-config.service b/rhel/systemd/cloud-config.service
76dbdd
index 12ca9df..f3dcd4b 100644
76dbdd
--- a/rhel/systemd/cloud-config.service
76dbdd
+++ b/rhel/systemd/cloud-config.service
76dbdd
@@ -15,4 +15,4 @@ TimeoutSec=0
76dbdd
 StandardOutput=journal+console
76dbdd
 
76dbdd
 [Install]
76dbdd
-WantedBy=multi-user.target
76dbdd
+WantedBy=cloud-init.target
76dbdd
diff --git a/rhel/systemd/cloud-final.service b/rhel/systemd/cloud-final.service
76dbdd
index 32a83d8..739b7e3 100644
76dbdd
--- a/rhel/systemd/cloud-final.service
76dbdd
+++ b/rhel/systemd/cloud-final.service
76dbdd
@@ -16,4 +16,4 @@ KillMode=process
76dbdd
 StandardOutput=journal+console
76dbdd
 
76dbdd
 [Install]
76dbdd
-WantedBy=multi-user.target
76dbdd
+WantedBy=cloud-init.target
76dbdd
diff --git a/rhel/systemd/cloud-init-local.service b/rhel/systemd/cloud-init-local.service
76dbdd
index 656eddb..8f9f6c9 100644
76dbdd
--- a/rhel/systemd/cloud-init-local.service
76dbdd
+++ b/rhel/systemd/cloud-init-local.service
76dbdd
@@ -28,4 +28,4 @@ TimeoutSec=0
76dbdd
 StandardOutput=journal+console
76dbdd
 
76dbdd
 [Install]
76dbdd
-WantedBy=multi-user.target
76dbdd
+WantedBy=cloud-init.target
76dbdd
diff --git a/rhel/systemd/cloud-init.service b/rhel/systemd/cloud-init.service
76dbdd
index 68fc5f1..d0023a0 100644
76dbdd
--- a/rhel/systemd/cloud-init.service
76dbdd
+++ b/rhel/systemd/cloud-init.service
76dbdd
@@ -22,4 +22,4 @@ TimeoutSec=0
76dbdd
 StandardOutput=journal+console
76dbdd
 
76dbdd
 [Install]
76dbdd
-WantedBy=multi-user.target
76dbdd
+WantedBy=cloud-init.target
76dbdd
diff --git a/rhel/systemd/cloud-init.target b/rhel/systemd/cloud-init.target
76dbdd
new file mode 100644
76dbdd
index 0000000..083c3b6
76dbdd
--- /dev/null
76dbdd
+++ b/rhel/systemd/cloud-init.target
76dbdd
@@ -0,0 +1,7 @@
76dbdd
+# cloud-init target is enabled by cloud-init-generator
76dbdd
+# To disable it you can either:
76dbdd
+#  a.) boot with kernel cmdline of 'cloud-init=disabled'
76dbdd
+#  b.) touch a file /etc/cloud/cloud-init.disabled
76dbdd
+[Unit]
76dbdd
+Description=Cloud-init target
76dbdd
+After=multi-user.target
76dbdd
-- 
76dbdd
1.8.3.1
76dbdd