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