ea00c4
From a52c7b659c6569c78aad4b92303f289009da476c Mon Sep 17 00:00:00 2001
16d12a
From: Eduardo Otubo <otubo@redhat.com>
ea00c4
Date: Mon, 5 Oct 2020 13:51:50 +0200
16d12a
Subject: Remove race condition between cloud-init and NetworkManager
16d12a
16d12a
Message-id: <20200302104635.11648-1-otubo@redhat.com>
16d12a
Patchwork-id: 94098
16d12a
O-Subject: [RHEL-7.9/RHEL-8.2.0 cloud-init PATCH] Remove race condition between cloud-init and NetworkManager
16d12a
Bugzilla: 1807797
16d12a
RH-Acked-by: Cathy Avery <cavery@redhat.com>
16d12a
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
16d12a
16d12a
BZ: 1748015
16d12a
BRANCH: rhel7/master-18.5
16d12a
BREW: 26924611
16d12a
16d12a
BZ: 1807797
16d12a
BRANCH: rhel820/master-18.5
16d12a
BREW: 26924957
16d12a
16d12a
cloud-init service is set to start before NetworkManager service starts,
16d12a
but this does not avoid a race condition between them. NetworkManager
16d12a
starts before cloud-init can write `dns=none' to the file:
16d12a
/etc/NetworkManager/conf.d/99-cloud-init.conf. This way NetworkManager
16d12a
doesn't read the configuration and erases all resolv.conf values upon
16d12a
shutdown. On the next reboot neither cloud-init or NetworkManager will
16d12a
write anything to resolv.conf, leaving it blank.
16d12a
16d12a
This patch introduces a NM reload (try-restart) at the end of cloud-init
16d12a
start up so it won't erase resolv.conf upon first shutdown.
16d12a
16d12a
x-downstream-only: yes
16d12a
resolves: rhbz#1748015, rhbz#1807797 and rhbz#1804780
16d12a
ea00c4
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
16d12a
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ea00c4
ea00c4
This commit is a squash and also includes the folloowing commits:
ea00c4
ea00c4
commit 316a17b7c02a87fa9b2981535be0b20d165adc46
ea00c4
Author: Eduardo Otubo <otubo@redhat.com>
ea00c4
Date:   Mon Jun 1 11:58:06 2020 +0200
ea00c4
ea00c4
    Make cloud-init.service execute after network is up
ea00c4
ea00c4
    RH-Author: Eduardo Otubo <otubo@redhat.com>
ea00c4
    Message-id: <20200526090804.2047-1-otubo@redhat.com>
ea00c4
    Patchwork-id: 96809
ea00c4
    O-Subject: [RHEL-8.2.1 cloud-init PATCH] Make cloud-init.service execute after network is up
ea00c4
    Bugzilla: 1803928
ea00c4
    RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
ea00c4
    RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
ea00c4
ea00c4
    cloud-init.service needs to wait until network is fully up before
ea00c4
    continuing executing and configuring its service.
ea00c4
ea00c4
    Signed-off-by: Eduardo Otubo <otubo@redhat.com>
ea00c4
ea00c4
    x-downstream-only: yes
ea00c4
    Resolves: rhbz#1831646
ea00c4
    Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ea00c4
ea00c4
commit 0422ba0e773d1a8257a3f2bf3db05f3bc7917eb7
ea00c4
Author: Eduardo Otubo <otubo@redhat.com>
ea00c4
Date:   Thu May 28 08:44:08 2020 +0200
ea00c4
ea00c4
    Remove race condition between cloud-init and NetworkManager
ea00c4
ea00c4
    RH-Author: Eduardo Otubo <otubo@redhat.com>
ea00c4
    Message-id: <20200327121911.17699-1-otubo@redhat.com>
ea00c4
    Patchwork-id: 94453
ea00c4
    O-Subject: [RHEL-7.9/RHEL-8.2.0 cloud-init PATCHv2] Remove race condition between cloud-init and NetworkManager
ea00c4
    Bugzilla: 1840648
ea00c4
    RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
ea00c4
    RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
ea00c4
    RH-Acked-by: Cathy Avery <cavery@redhat.com>
ea00c4
ea00c4
    cloud-init service is set to start before NetworkManager service starts,
ea00c4
    but this does not avoid a race condition between them. NetworkManager
ea00c4
    starts before cloud-init can write `dns=none' to the file:
ea00c4
    /etc/NetworkManager/conf.d/99-cloud-init.conf. This way NetworkManager
ea00c4
    doesn't read the configuration and erases all resolv.conf values upon
ea00c4
    shutdown. On the next reboot neither cloud-init or NetworkManager will
ea00c4
    write anything to resolv.conf, leaving it blank.
ea00c4
ea00c4
    This patch introduces a NM reload (try-reload-or-restart) at the end of cloud-init
ea00c4
    start up so it won't erase resolv.conf upon first shutdown.
ea00c4
ea00c4
    x-downstream-only: yes
ea00c4
ea00c4
    Signed-off-by: Eduardo Otubo otubo@redhat.com
ea00c4
    Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ea00c4
ea00c4
commit e0b48a936433faea7f56dbc29dda35acf7d375f7
ea00c4
Author: Eduardo Otubo <otubo@redhat.com>
ea00c4
Date:   Thu May 28 08:44:06 2020 +0200
ea00c4
ea00c4
    Enable ssh_deletekeys by default
ea00c4
ea00c4
    RH-Author: Eduardo Otubo <otubo@redhat.com>
ea00c4
    Message-id: <20200317091705.15715-1-otubo@redhat.com>
ea00c4
    Patchwork-id: 94365
ea00c4
    O-Subject: [RHEL-7.9/RHEL-8.2.0 cloud-init PATCH] Enable ssh_deletekeys by default
ea00c4
    Bugzilla: 1814152
ea00c4
    RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
ea00c4
    RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
ea00c4
ea00c4
    The configuration option ssh_deletekeys will trigger the generation
ea00c4
    of new ssh keys for every new instance deployed.
ea00c4
ea00c4
    x-downstream-only: yes
ea00c4
    resolves: rhbz#1814152
ea00c4
ea00c4
    Signed-off-by: Eduardo Otubo <otubo@redhat.com>
ea00c4
    Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
16d12a
---
ea00c4
 rhel/cloud.cfg                   | 2 +-
16d12a
 rhel/systemd/cloud-final.service | 2 ++
ea00c4
 rhel/systemd/cloud-init.service  | 1 +
ea00c4
 3 files changed, 4 insertions(+), 1 deletion(-)
16d12a
ea00c4
diff --git a/rhel/cloud.cfg b/rhel/cloud.cfg
ea00c4
index 82e8bf6..9ecba21 100644
ea00c4
--- a/rhel/cloud.cfg
ea00c4
+++ b/rhel/cloud.cfg
ea00c4
@@ -6,7 +6,7 @@ ssh_pwauth:   0
ea00c4
 
ea00c4
 mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service', '0', '2']
ea00c4
 resize_rootfs_tmp: /dev
ea00c4
-ssh_deletekeys:   0
ea00c4
+ssh_deletekeys:   1
ea00c4
 ssh_genkeytypes:  ~
ea00c4
 syslog_fix_perms: ~
ea00c4
 disable_vmware_customization: false
16d12a
diff --git a/rhel/systemd/cloud-final.service b/rhel/systemd/cloud-final.service
ea00c4
index 739b7e3..05add07 100644
16d12a
--- a/rhel/systemd/cloud-final.service
16d12a
+++ b/rhel/systemd/cloud-final.service
16d12a
@@ -11,6 +11,8 @@ ExecStart=/usr/bin/cloud-init modules --mode=final
16d12a
 RemainAfterExit=yes
16d12a
 TimeoutSec=0
16d12a
 KillMode=process
ea00c4
+ExecStartPost=/bin/echo "trying to reload or restart NetworkManager.service"
ea00c4
+ExecStartPost=/usr/bin/systemctl try-reload-or-restart NetworkManager.service
16d12a
 
16d12a
 # Output needs to appear in instance console output
16d12a
 StandardOutput=journal+console
ea00c4
diff --git a/rhel/systemd/cloud-init.service b/rhel/systemd/cloud-init.service
ea00c4
index d0023a0..0b3d796 100644
ea00c4
--- a/rhel/systemd/cloud-init.service
ea00c4
+++ b/rhel/systemd/cloud-init.service
ea00c4
@@ -5,6 +5,7 @@ Wants=sshd-keygen.service
ea00c4
 Wants=sshd.service
ea00c4
 After=cloud-init-local.service
ea00c4
 After=NetworkManager.service network.service
ea00c4
+After=NetworkManager-wait-online.service
ea00c4
 Before=network-online.target
ea00c4
 Before=sshd-keygen.service
ea00c4
 Before=sshd.service
16d12a
-- 
16d12a
1.8.3.1
16d12a